docshell/test/chrome/bug360511_window.xul

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/docshell/test/chrome/bug360511_window.xul	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,134 @@
     1.4 +<?xml version="1.0"?>
     1.5 +<?xml-stylesheet href="chrome://global/skin" type="text/css"?>
     1.6 +
     1.7 +<window id="360511Test"
     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 360511 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 360511:  
    1.30 +    // Fragment uri's in session history should be restored correctly
    1.31 +    // upon back navigation.
    1.32 +    //
    1.33 +    function testIterator()
    1.34 +    {
    1.35 +      // Case 1: load a page containing a fragment link; the page should be 
    1.36 +      // stored in the bfcache.
    1.37 +      // Case 2: load a page containing a fragment link; the page should NOT 
    1.38 +      // be stored in the bfcache.
    1.39 +      for (var i = 1; i < 3; i++)
    1.40 +      {
    1.41 +        var url = "bug360511_case" + i + ".html";
    1.42 +        doPageNavigation( {
    1.43 +          uri: getHttpUrl(url),
    1.44 +          onNavComplete: nextTest,
    1.45 +          preventBFCache: i != 1
    1.46 +        } );
    1.47 +        yield undefined;
    1.48 +      
    1.49 +        // Store the original url for later comparison.
    1.50 +        var originalUrl = TestWindow.getBrowser().currentURI.spec;
    1.51 +        var originalDocLocation = TestWindow.getDocument().location.href;
    1.52 +        
    1.53 +        // Verify we're at the top of the page.
    1.54 +        is(TestWindow.getWindow().scrollY, 0, 
    1.55 +          "Page initially has a non-zero scrollY property");
    1.56 +      
    1.57 +        // Click the on the fragment link in the browser, and use setTimeout 
    1.58 +        // to give the event a chance to be processed.
    1.59 +        var event = TestWindow.getDocument().createEvent('MouseEvent');
    1.60 +        event.initMouseEvent("click", true, true, TestWindow.getWindow(), 0,
    1.61 +          0, 0, 0, 0,
    1.62 +          false, false, false, false, 0, null);
    1.63 +        TestWindow.getDocument().getElementById("link1").dispatchEvent(event);
    1.64 +        setTimeout(nextTest, 0);
    1.65 +        yield undefined;
    1.66 +
    1.67 +        // Store the fragment url for later comparison.
    1.68 +        var fragmentUrl = TestWindow.getBrowser().currentURI.spec;
    1.69 +        var fragDocLocation = TestWindow.getDocument().location.href;
    1.70 +        
    1.71 +        // Verify we're no longer at the top of the page.
    1.72 +        ok(TestWindow.getWindow().scrollY > 0,
    1.73 +          "We're at the top of the page but we should be at the bottom");
    1.74 +      
    1.75 +        // Now navigate to any other page
    1.76 +        var expectedPageTitle = "bug360511 case " + i;
    1.77 +        doPageNavigation( {
    1.78 +          uri: getHttpUrl("generic.html"),
    1.79 +          eventsToListenFor: ["pagehide", "pageshow"],
    1.80 +          expectedEvents: [ {type: "pagehide", title: expectedPageTitle,
    1.81 +                             persisted: i == 1},
    1.82 +                            {type: "pageshow"} ],
    1.83 +          onNavComplete: nextTest
    1.84 +        } );
    1.85 +        yield undefined;
    1.86 +      
    1.87 +        // Go back
    1.88 +        doPageNavigation( {
    1.89 +          back: true,
    1.90 +          eventsToListenFor: ["pageshow"],
    1.91 +          expectedEvents: [ {type: "pageshow", title: expectedPageTitle, 
    1.92 +                             persisted: i == 1} ],
    1.93 +          onNavComplete: nextTest
    1.94 +        } );
    1.95 +        yield undefined;
    1.96 +      
    1.97 +        // Verify the current url is the fragment url
    1.98 +        is(TestWindow.getBrowser().currentURI.spec, fragmentUrl, 
    1.99 +          "current url is not the previous fragment url");
   1.100 +        is(TestWindow.getDocument().location.href, fragDocLocation,
   1.101 +          "document.location is not the previous fragment url");
   1.102 +        
   1.103 +        // Go back again.  Since we're just going from a fragment url to 
   1.104 +        // parent url, no pageshow event is fired, so don't wait for any 
   1.105 +        // events.  Rather, just wait for the page's scrollY property to 
   1.106 +        // change.
   1.107 +        var originalScrollY = TestWindow.getWindow().scrollY;
   1.108 +        doPageNavigation( {
   1.109 +          back: true,
   1.110 +          eventsToListenFor: []
   1.111 +        } );
   1.112 +        waitForTrue( 
   1.113 +          function() {
   1.114 +            return (TestWindow.getWindow().scrollY != originalScrollY);
   1.115 +          }, 
   1.116 +          function() {
   1.117 +            setTimeout(nextTest, 0);
   1.118 +          }, 20);      
   1.119 +        yield undefined;
   1.120 +      
   1.121 +        // Verify the current url is the original url without fragment
   1.122 +        is(TestWindow.getBrowser().currentURI.spec, originalUrl, 
   1.123 +          "current url is not the original url");
   1.124 +        is(TestWindow.getDocument().location.href, originalDocLocation,
   1.125 +          "document.location is not the original url");
   1.126 +      }
   1.127 +                      
   1.128 +      // Tell the framework the test is finished.  Include the final 'yield' 
   1.129 +      // statement to prevent a StopIteration exception from being thrown.
   1.130 +      finish();
   1.131 +      yield undefined;
   1.132 +    }
   1.133 +    
   1.134 +  ]]></script>
   1.135 +
   1.136 +  <browser type="content-primary" flex="1" id="content" src="about:blank"/>
   1.137 +</window>

mercurial