docshell/test/chrome/bug303267_window.xul

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/docshell/test/chrome/bug303267_window.xul	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,101 @@
     1.4 +<?xml version="1.0"?>
     1.5 +<?xml-stylesheet href="chrome://global/skin" type="text/css"?>
     1.6 +
     1.7 +<window id="303267Test"
     1.8 +        xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
     1.9 +        width="600"
    1.10 +        height="600"
    1.11 +        onload="setTimeout(nextTest,0);"
    1.12 +        title="bug 303267 test">
    1.13 +
    1.14 +  <script type="application/javascript" src= "chrome://mochikit/content/chrome-harness.js" />
    1.15 +  <script type="application/javascript" src="docshell_helpers.js" />
    1.16 +  <script type="application/javascript"><![CDATA[
    1.17 +  
    1.18 +    // Define the generator-iterator for the tests.
    1.19 +    var tests = testIterator();
    1.20 +
    1.21 +    ////
    1.22 +    // Execute the next test in the generator function.
    1.23 +    //
    1.24 +    function nextTest() {
    1.25 +      tests.next();
    1.26 +    }
    1.27 +
    1.28 +    ////
    1.29 +    // Generator function for test steps for bug 303267:  When a page is 
    1.30 +    // displayed from the bfcache, the script globals should
    1.31 +    // remain intact from the page's initial load.
    1.32 +    //
    1.33 +    function testIterator()
    1.34 +    {
    1.35 +      // Load an initial test page which should be saved in the bfcache.
    1.36 +      var navData = {
    1.37 +        uri: getHttpUrl("bug303267.html"),
    1.38 +        eventsToListenFor: ["pageshow"],
    1.39 +        expectedEvents: [ {type: "pageshow", title: "bug303267.html"} ],
    1.40 +        onNavComplete: nextTest
    1.41 +      };
    1.42 +      doPageNavigation(navData);
    1.43 +      yield undefined;
    1.44 +      
    1.45 +      // Save the HTML of the test page for later comparison.
    1.46 +      var originalHTML = getInnerHTMLById("div1");
    1.47 +
    1.48 +      // Load a second test page.  The first test page's pagehide event should
    1.49 +      // have the .persisted property set to true, indicating that it was 
    1.50 +      // stored in the bfcache.
    1.51 +      navData = {
    1.52 +        uri: "data:text/html,<html><head><title>page2</title></head>" +
    1.53 +             "<body>bug303267, page2</body></html>",
    1.54 +        eventsToListenFor: ["pageshow", "pagehide"],
    1.55 +        expectedEvents: [ {type: "pagehide", 
    1.56 +                           title: "bug303267.html", 
    1.57 +                           persisted: true},
    1.58 +                          {type: "pageshow", 
    1.59 +                           title: "page2"} ],
    1.60 +        onNavComplete: nextTest
    1.61 +      };
    1.62 +      doPageNavigation(navData);
    1.63 +      yield undefined;
    1.64 +      
    1.65 +      // Go back.  Verify that the pageshow event for the original test page 
    1.66 +      // had a .persisted property of true, indicating that it came from the 
    1.67 +      // bfcache.
    1.68 +      navData = {
    1.69 +        back: true,
    1.70 +        eventsToListenFor: ["pageshow", "pagehide"],
    1.71 +        expectedEvents: [ {type: "pagehide", 
    1.72 +                           title: "page2"},
    1.73 +                          {type: "pageshow", 
    1.74 +                           title: "bug303267.html", 
    1.75 +                           persisted: true} ],
    1.76 +        onNavComplete: nextTest
    1.77 +      };
    1.78 +      doPageNavigation(navData);
    1.79 +      yield undefined;
    1.80 +      
    1.81 +      // After going back, if showpagecount() could access a global variable
    1.82 +      // and change the test div's innerHTML, then we pass.  Otherwise, it
    1.83 +      // threw an exception and the following test will fail.
    1.84 +      var newHTML = getInnerHTMLById("div1");
    1.85 +      isnot(originalHTML, 
    1.86 +        newHTML, "HTML not updated on pageshow; javascript broken?");
    1.87 +
    1.88 +      // Tell the framework the test is finished.  Include the final 'yield' 
    1.89 +      // statement to prevent a StopIteration exception from being thrown.
    1.90 +      finish();
    1.91 +      yield undefined;
    1.92 +    }
    1.93 +
    1.94 +    ////
    1.95 +    // Return the innerHTML of a particular element in the content document.
    1.96 +    //
    1.97 +    function getInnerHTMLById(id) {
    1.98 +      return TestWindow.getDocument().getElementById(id).innerHTML;
    1.99 +    }
   1.100 +    
   1.101 +  ]]></script>
   1.102 +
   1.103 +  <browser type="content-primary" flex="1" id="content" src="about:blank"/>
   1.104 +</window>

mercurial