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

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

mercurial