Source code
Revision control
Copy as Markdown
Other Tools
<?xml version="1.0"?>
<window id="303267Test"
        width="600"
        height="600"
        onload="setTimeout(runTests, 0);"
  <script type="application/javascript" src="docshell_helpers.js" />
  <script type="application/javascript"><![CDATA[
    ////
    // remain intact from the page's initial load.
    //
    async function runTests()
    {
      // Load an initial test page which should be saved in the bfcache.
      var navData = {
        eventsToListenFor: ["pageshow"],
      };
      await promisePageNavigation(navData);
      // Save the HTML of the test page for later comparison.
      var originalHTML = await getInnerHTMLById("div1");
      // Load a second test page.  The first test page's pagehide event should
      // have the .persisted property set to true, indicating that it was 
      // stored in the bfcache.
      navData = {
        uri: "data:text/html,<html><head><title>page2</title></head>" +
        eventsToListenFor: ["pageshow", "pagehide"],
        expectedEvents: [ {type: "pagehide", 
                           persisted: true},
                          {type: "pageshow", 
                           title: "page2"} ],
      };
      await promisePageNavigation(navData);
      // Go back.  Verify that the pageshow event for the original test page
      // had a .persisted property of true, indicating that it came from the 
      // bfcache.
      navData = {
        back: true,
        eventsToListenFor: ["pageshow", "pagehide"],
        expectedEvents: [ {type: "pagehide", 
                           title: "page2"},
                          {type: "pageshow", 
                           persisted: true} ],
      };
      await promisePageNavigation(navData);
      // After going back, if showpagecount() could access a global variable
      // and change the test div's innerHTML, then we pass.  Otherwise, it
      // threw an exception and the following test will fail.
      var newHTML = await getInnerHTMLById("div1");
      isnot(originalHTML, 
        newHTML, "HTML not updated on pageshow; javascript broken?");
      // Tell the framework the test is finished.
      finish();
    }
    ////
    // Return the innerHTML of a particular element in the content document.
    //
    function getInnerHTMLById(id) {
      return SpecialPowers.spawn(TestWindow.getBrowser(), [id], (id) => {
        return content.document.getElementById(id).innerHTML;
      });
    }
    
  ]]></script>
  <browser type="content" primary="true" flex="1" id="content" remote="true" maychangeremoteness="true" />
</window>