docshell/test/test_bug590573.html

Wed, 31 Dec 2014 13:27:57 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 13:27:57 +0100
branch
TOR_BUG_3246
changeset 6
8bccb770b82d
permissions
-rw-r--r--

Ignore runtime configuration files generated during quality assurance.

michael@0 1 <!DOCTYPE HTML>
michael@0 2 <html>
michael@0 3 <!--
michael@0 4 https://bugzilla.mozilla.org/show_bug.cgi?id=590573
michael@0 5 -->
michael@0 6 <head>
michael@0 7 <title>Test for Bug 590573</title>
michael@0 8 <script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
michael@0 9 <script type="application/javascript" src="/tests/SimpleTest/EventUtils.js"></script>
michael@0 10 <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
michael@0 11 </head>
michael@0 12 <body>
michael@0 13 <a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=590573">Mozilla Bug 590573</a>
michael@0 14
michael@0 15 <script type='application/javascript;version=1.7'>
michael@0 16 SimpleTest.waitForExplicitFinish();
michael@0 17
michael@0 18 // Listen to the first callback, since this indicates that the page loaded.
michael@0 19 var page1LoadCallbackEnabled = true;
michael@0 20 function page1Load()
michael@0 21 {
michael@0 22 if (page1LoadCallbackEnabled) {
michael@0 23 page1LoadCallbackEnabled = false;
michael@0 24 dump('Got page1 load.\n');
michael@0 25 pageLoad();
michael@0 26 }
michael@0 27 else {
michael@0 28 dump('Ignoring page1 load.\n');
michael@0 29 }
michael@0 30 }
michael@0 31
michael@0 32 var page1PopstateCallbackEnabled = false;
michael@0 33 function page1Popstate()
michael@0 34 {
michael@0 35 if (page1PopstateCallbackEnabled) {
michael@0 36 page1PopstateCallbackEnabled = false;
michael@0 37 dump('Got page1 popstate.\n');
michael@0 38 pageLoad();
michael@0 39 }
michael@0 40 else {
michael@0 41 dump('Ignoring page1 popstate.\n');
michael@0 42 }
michael@0 43 }
michael@0 44
michael@0 45 var page1PageShowCallbackEnabled = false;
michael@0 46 function page1PageShow()
michael@0 47 {
michael@0 48 if (page1PageShowCallbackEnabled) {
michael@0 49 page1PageShowCallbackEnabled = false;
michael@0 50 dump('Got page1 pageshow.\n');
michael@0 51 pageLoad();
michael@0 52 }
michael@0 53 else {
michael@0 54 dump('Ignoring page1 pageshow.\n');
michael@0 55 }
michael@0 56 }
michael@0 57
michael@0 58 var page2LoadCallbackEnabled = false;
michael@0 59 function page2Load()
michael@0 60 {
michael@0 61 if (page2LoadCallbackEnabled) {
michael@0 62 page2LoadCallbackEnabled = false;
michael@0 63 dump('Got page2 popstate.\n');
michael@0 64 pageLoad();
michael@0 65 }
michael@0 66 else {
michael@0 67 dump('Ignoring page2 popstate.\n');
michael@0 68 }
michael@0 69 }
michael@0 70
michael@0 71 var page2PopstateCallbackEnabled = false;
michael@0 72 function page2Popstate()
michael@0 73 {
michael@0 74 if (page2PopstateCallbackEnabled) {
michael@0 75 page2PopstateCallbackEnabled = false;
michael@0 76 dump('Got page2 popstate.\n');
michael@0 77 pageLoad();
michael@0 78 }
michael@0 79 else {
michael@0 80 dump('Ignoring page2 popstate.\n');
michael@0 81 }
michael@0 82 }
michael@0 83
michael@0 84 var page2PageShowCallbackEnabled = false;
michael@0 85 function page2PageShow()
michael@0 86 {
michael@0 87 if (page2PageShowCallbackEnabled) {
michael@0 88 page2PageShowCallbackEnabled = false;
michael@0 89 dump('Got page2 pageshow.\n');
michael@0 90 pageLoad();
michael@0 91 }
michael@0 92 else {
michael@0 93 dump('Ignoring page2 pageshow.\n');
michael@0 94 }
michael@0 95 }
michael@0 96
michael@0 97 function dumpSHistory(theWindow)
michael@0 98 {
michael@0 99 let sh = SpecialPowers.wrap(theWindow).QueryInterface(SpecialPowers.Ci.nsIInterfaceRequestor)
michael@0 100 .getInterface(SpecialPowers.Ci.nsIWebNavigation)
michael@0 101 .sessionHistory;
michael@0 102 if (!sh) {
michael@0 103 dump(" window has no shistory.\n");
michael@0 104 return;
michael@0 105 }
michael@0 106
michael@0 107 dump(" count: " + sh.count + "\n");
michael@0 108 dump(" index: " + sh.index + "\n");
michael@0 109 dump(" requestedIndex: " + sh.requestedIndex + "\n");
michael@0 110
michael@0 111 for (let i = 0; i < sh.count; i++) {
michael@0 112 let shentry = sh.getEntryAtIndex(i, false);
michael@0 113 dump(" " + i + ": " + shentry.URI.spec + '\n');
michael@0 114 shentry.QueryInterface(SpecialPowers.Ci.nsISHContainer);
michael@0 115 for (let j = 0; j < shentry.childCount; j++) {
michael@0 116 let child = shentry.GetChildAt(j);
michael@0 117 dump(" child " + j + ": " + child.URI.spec + '\n');
michael@0 118 }
michael@0 119 }
michael@0 120
michael@0 121 return sh;
michael@0 122 }
michael@0 123
michael@0 124 var popup = window.open('file_bug590573_1.html');
michael@0 125
michael@0 126 var loads = 0;
michael@0 127 function pageLoad()
michael@0 128 {
michael@0 129 loads++;
michael@0 130 dump('pageLoad(loads=' + loads + ', page location=' + popup.location + ')\n');
michael@0 131
michael@0 132 dumpSHistory(window);
michael@0 133
michael@0 134 if (loads == 1) {
michael@0 135 is(popup.scrollY, 0, "test 1");
michael@0 136 popup.scroll(0, 100);
michael@0 137
michael@0 138 popup.history.pushState('', '', '?pushed');
michael@0 139 is(popup.scrollY, 100, "test 2");
michael@0 140 popup.scroll(0, 200); // set state-2's position to 200
michael@0 141
michael@0 142 popup.history.back();
michael@0 143 is(popup.scrollY, 100, "test 3");
michael@0 144 popup.scroll(0, 150); // set original page's position to 150
michael@0 145
michael@0 146 popup.history.forward();
michael@0 147 is(popup.scrollY, 200, "test 4");
michael@0 148
michael@0 149 popup.history.back();
michael@0 150 is(popup.scrollY, 150, "test 5");
michael@0 151
michael@0 152 popup.history.forward();
michael@0 153 is(popup.scrollY, 200, "test 6");
michael@0 154
michael@0 155 // At this point, the history looks like:
michael@0 156 // PATH POSITION
michael@0 157 // file_bug590573_1.html 150 <-- oldest
michael@0 158 // file_bug590573_1.html?pushed 200 <-- newest, current
michael@0 159
michael@0 160 // Now test that the scroll position is persisted when we have real
michael@0 161 // navigations involved. First, we need to spin the event loop so that the
michael@0 162 // navigation doesn't replace our current history entry.
michael@0 163
michael@0 164 setTimeout(pageLoad, 0);
michael@0 165 }
michael@0 166 else if (loads == 2) {
michael@0 167 page2LoadCallbackEnabled = true;
michael@0 168 popup.location = 'file_bug590573_2.html';
michael@0 169 }
michael@0 170 else if (loads == 3) {
michael@0 171 ok(popup.location.href.match('file_bug590573_2.html$'),
michael@0 172 "Location was " + popup.location +
michael@0 173 " but should end with file_bug590573_2.html");
michael@0 174
michael@0 175 is(popup.scrollY, 0, "test 7");
michael@0 176 popup.scroll(0, 300);
michael@0 177
michael@0 178 // We need to spin the event loop again before we go back, otherwise the
michael@0 179 // scroll positions don't get updated properly.
michael@0 180 setTimeout(pageLoad, 0);
michael@0 181 }
michael@0 182 else if (loads == 4) {
michael@0 183 page1PageShowCallbackEnabled = true;
michael@0 184 popup.history.back();
michael@0 185 }
michael@0 186 else if (loads == 5) {
michael@0 187 // Spin the event loop again so that we get the right scroll positions.
michael@0 188 setTimeout(pageLoad, 0);
michael@0 189 }
michael@0 190 else if (loads == 6) {
michael@0 191 is(popup.location.search, "?pushed");
michael@0 192 ok(popup.document.getElementById('div1'), 'page should have div1.');
michael@0 193
michael@0 194 // Bug 821821, on android 4.0.4 on panda we get 199 instead of 200
michael@0 195 if (popup.scrollY >= 199 && popup.scrollY <= 200) {
michael@0 196 is(1, 1, "test 8");
michael@0 197 } else {
michael@0 198 is(1, 0, "test 8, got " + popup.scrollY + " for popup.scrollY instead of 199|200");
michael@0 199 }
michael@0 200
michael@0 201 popup.history.back();
michael@0 202 is(popup.scrollY, 150, "test 9");
michael@0 203 popup.history.forward();
michael@0 204
michael@0 205 // Bug 821821, on android 4.0.4 on panda we get 199 instead of 200
michael@0 206 if (popup.scrollY >= 199 && popup.scrollY <= 200) {
michael@0 207 is(1, 1, "test 10");
michael@0 208 } else {
michael@0 209 is(1, 0, "test 10, got " + popup.scrollY + " for popup.scrollY instead of 199|200");
michael@0 210 }
michael@0 211
michael@0 212 // Spin one last time...
michael@0 213 setTimeout(pageLoad, 0);
michael@0 214 }
michael@0 215 else if (loads == 7) {
michael@0 216 page2PageShowCallbackEnabled = true;
michael@0 217 popup.history.forward();
michael@0 218 }
michael@0 219 else if (loads == 8) {
michael@0 220 // Bug 821821, on Android tegras we get 299 instead of 300 sometimes
michael@0 221 if (popup.scrollY >= 299 && popup.scrollY <= 300) {
michael@0 222 is(1, 1, "test 11");
michael@0 223 } else {
michael@0 224 is(1, 0, "test 11, got " + popup.scrollY + " for popup.scrollY instead of 299|300");
michael@0 225 }
michael@0 226 popup.close();
michael@0 227 SimpleTest.finish();
michael@0 228 }
michael@0 229 else {
michael@0 230 ok(false, "Got extra load!");
michael@0 231 }
michael@0 232 }
michael@0 233 </script>
michael@0 234
michael@0 235 </body>
michael@0 236 </html>

mercurial