docshell/test/chrome/bug360511_window.xul

Thu, 22 Jan 2015 13:21:57 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 22 Jan 2015 13:21:57 +0100
branch
TOR_BUG_9701
changeset 15
b8a032363ba2
permissions
-rwxr-xr-x

Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6

     1 <?xml version="1.0"?>
     2 <?xml-stylesheet href="chrome://global/skin" type="text/css"?>
     4 <window id="360511Test"
     5         xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
     6         width="600"
     7         height="600"
     8         onload="setTimeout(nextTest,0);"
     9         title="bug 360511 test">
    11   <script type="application/javascript" src= "chrome://mochikit/content/chrome-harness.js" />
    12   <script type="application/javascript" src="docshell_helpers.js" />
    13   <script type="application/javascript"><![CDATA[
    15     // Define the generator-iterator for the tests.
    16     var tests = testIterator();
    18     ////
    19     // Execute the next test in the generator function.
    20     //
    21     function nextTest() {
    22       tests.next();
    23     }
    25     ////
    26     // Generator function for test steps for bug 360511:  
    27     // Fragment uri's in session history should be restored correctly
    28     // upon back navigation.
    29     //
    30     function testIterator()
    31     {
    32       // Case 1: load a page containing a fragment link; the page should be 
    33       // stored in the bfcache.
    34       // Case 2: load a page containing a fragment link; the page should NOT 
    35       // be stored in the bfcache.
    36       for (var i = 1; i < 3; i++)
    37       {
    38         var url = "bug360511_case" + i + ".html";
    39         doPageNavigation( {
    40           uri: getHttpUrl(url),
    41           onNavComplete: nextTest,
    42           preventBFCache: i != 1
    43         } );
    44         yield undefined;
    46         // Store the original url for later comparison.
    47         var originalUrl = TestWindow.getBrowser().currentURI.spec;
    48         var originalDocLocation = TestWindow.getDocument().location.href;
    50         // Verify we're at the top of the page.
    51         is(TestWindow.getWindow().scrollY, 0, 
    52           "Page initially has a non-zero scrollY property");
    54         // Click the on the fragment link in the browser, and use setTimeout 
    55         // to give the event a chance to be processed.
    56         var event = TestWindow.getDocument().createEvent('MouseEvent');
    57         event.initMouseEvent("click", true, true, TestWindow.getWindow(), 0,
    58           0, 0, 0, 0,
    59           false, false, false, false, 0, null);
    60         TestWindow.getDocument().getElementById("link1").dispatchEvent(event);
    61         setTimeout(nextTest, 0);
    62         yield undefined;
    64         // Store the fragment url for later comparison.
    65         var fragmentUrl = TestWindow.getBrowser().currentURI.spec;
    66         var fragDocLocation = TestWindow.getDocument().location.href;
    68         // Verify we're no longer at the top of the page.
    69         ok(TestWindow.getWindow().scrollY > 0,
    70           "We're at the top of the page but we should be at the bottom");
    72         // Now navigate to any other page
    73         var expectedPageTitle = "bug360511 case " + i;
    74         doPageNavigation( {
    75           uri: getHttpUrl("generic.html"),
    76           eventsToListenFor: ["pagehide", "pageshow"],
    77           expectedEvents: [ {type: "pagehide", title: expectedPageTitle,
    78                              persisted: i == 1},
    79                             {type: "pageshow"} ],
    80           onNavComplete: nextTest
    81         } );
    82         yield undefined;
    84         // Go back
    85         doPageNavigation( {
    86           back: true,
    87           eventsToListenFor: ["pageshow"],
    88           expectedEvents: [ {type: "pageshow", title: expectedPageTitle, 
    89                              persisted: i == 1} ],
    90           onNavComplete: nextTest
    91         } );
    92         yield undefined;
    94         // Verify the current url is the fragment url
    95         is(TestWindow.getBrowser().currentURI.spec, fragmentUrl, 
    96           "current url is not the previous fragment url");
    97         is(TestWindow.getDocument().location.href, fragDocLocation,
    98           "document.location is not the previous fragment url");
   100         // Go back again.  Since we're just going from a fragment url to 
   101         // parent url, no pageshow event is fired, so don't wait for any 
   102         // events.  Rather, just wait for the page's scrollY property to 
   103         // change.
   104         var originalScrollY = TestWindow.getWindow().scrollY;
   105         doPageNavigation( {
   106           back: true,
   107           eventsToListenFor: []
   108         } );
   109         waitForTrue( 
   110           function() {
   111             return (TestWindow.getWindow().scrollY != originalScrollY);
   112           }, 
   113           function() {
   114             setTimeout(nextTest, 0);
   115           }, 20);      
   116         yield undefined;
   118         // Verify the current url is the original url without fragment
   119         is(TestWindow.getBrowser().currentURI.spec, originalUrl, 
   120           "current url is not the original url");
   121         is(TestWindow.getDocument().location.href, originalDocLocation,
   122           "document.location is not the original url");
   123       }
   125       // Tell the framework the test is finished.  Include the final 'yield' 
   126       // statement to prevent a StopIteration exception from being thrown.
   127       finish();
   128       yield undefined;
   129     }
   131   ]]></script>
   133   <browser type="content-primary" flex="1" id="content" src="about:blank"/>
   134 </window>

mercurial