1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/docshell/test/test_bug590573.html Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,236 @@ 1.4 +<!DOCTYPE HTML> 1.5 +<html> 1.6 +<!-- 1.7 +https://bugzilla.mozilla.org/show_bug.cgi?id=590573 1.8 +--> 1.9 +<head> 1.10 + <title>Test for Bug 590573</title> 1.11 + <script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script> 1.12 + <script type="application/javascript" src="/tests/SimpleTest/EventUtils.js"></script> 1.13 + <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/> 1.14 +</head> 1.15 +<body> 1.16 +<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=590573">Mozilla Bug 590573</a> 1.17 + 1.18 +<script type='application/javascript;version=1.7'> 1.19 +SimpleTest.waitForExplicitFinish(); 1.20 + 1.21 +// Listen to the first callback, since this indicates that the page loaded. 1.22 +var page1LoadCallbackEnabled = true; 1.23 +function page1Load() 1.24 +{ 1.25 + if (page1LoadCallbackEnabled) { 1.26 + page1LoadCallbackEnabled = false; 1.27 + dump('Got page1 load.\n'); 1.28 + pageLoad(); 1.29 + } 1.30 + else { 1.31 + dump('Ignoring page1 load.\n'); 1.32 + } 1.33 +} 1.34 + 1.35 +var page1PopstateCallbackEnabled = false; 1.36 +function page1Popstate() 1.37 +{ 1.38 + if (page1PopstateCallbackEnabled) { 1.39 + page1PopstateCallbackEnabled = false; 1.40 + dump('Got page1 popstate.\n'); 1.41 + pageLoad(); 1.42 + } 1.43 + else { 1.44 + dump('Ignoring page1 popstate.\n'); 1.45 + } 1.46 +} 1.47 + 1.48 +var page1PageShowCallbackEnabled = false; 1.49 +function page1PageShow() 1.50 +{ 1.51 + if (page1PageShowCallbackEnabled) { 1.52 + page1PageShowCallbackEnabled = false; 1.53 + dump('Got page1 pageshow.\n'); 1.54 + pageLoad(); 1.55 + } 1.56 + else { 1.57 + dump('Ignoring page1 pageshow.\n'); 1.58 + } 1.59 +} 1.60 + 1.61 +var page2LoadCallbackEnabled = false; 1.62 +function page2Load() 1.63 +{ 1.64 + if (page2LoadCallbackEnabled) { 1.65 + page2LoadCallbackEnabled = false; 1.66 + dump('Got page2 popstate.\n'); 1.67 + pageLoad(); 1.68 + } 1.69 + else { 1.70 + dump('Ignoring page2 popstate.\n'); 1.71 + } 1.72 +} 1.73 + 1.74 +var page2PopstateCallbackEnabled = false; 1.75 +function page2Popstate() 1.76 +{ 1.77 + if (page2PopstateCallbackEnabled) { 1.78 + page2PopstateCallbackEnabled = false; 1.79 + dump('Got page2 popstate.\n'); 1.80 + pageLoad(); 1.81 + } 1.82 + else { 1.83 + dump('Ignoring page2 popstate.\n'); 1.84 + } 1.85 +} 1.86 + 1.87 +var page2PageShowCallbackEnabled = false; 1.88 +function page2PageShow() 1.89 +{ 1.90 + if (page2PageShowCallbackEnabled) { 1.91 + page2PageShowCallbackEnabled = false; 1.92 + dump('Got page2 pageshow.\n'); 1.93 + pageLoad(); 1.94 + } 1.95 + else { 1.96 + dump('Ignoring page2 pageshow.\n'); 1.97 + } 1.98 +} 1.99 + 1.100 +function dumpSHistory(theWindow) 1.101 +{ 1.102 + let sh = SpecialPowers.wrap(theWindow).QueryInterface(SpecialPowers.Ci.nsIInterfaceRequestor) 1.103 + .getInterface(SpecialPowers.Ci.nsIWebNavigation) 1.104 + .sessionHistory; 1.105 + if (!sh) { 1.106 + dump(" window has no shistory.\n"); 1.107 + return; 1.108 + } 1.109 + 1.110 + dump(" count: " + sh.count + "\n"); 1.111 + dump(" index: " + sh.index + "\n"); 1.112 + dump(" requestedIndex: " + sh.requestedIndex + "\n"); 1.113 + 1.114 + for (let i = 0; i < sh.count; i++) { 1.115 + let shentry = sh.getEntryAtIndex(i, false); 1.116 + dump(" " + i + ": " + shentry.URI.spec + '\n'); 1.117 + shentry.QueryInterface(SpecialPowers.Ci.nsISHContainer); 1.118 + for (let j = 0; j < shentry.childCount; j++) { 1.119 + let child = shentry.GetChildAt(j); 1.120 + dump(" child " + j + ": " + child.URI.spec + '\n'); 1.121 + } 1.122 + } 1.123 + 1.124 + return sh; 1.125 +} 1.126 + 1.127 +var popup = window.open('file_bug590573_1.html'); 1.128 + 1.129 +var loads = 0; 1.130 +function pageLoad() 1.131 +{ 1.132 + loads++; 1.133 + dump('pageLoad(loads=' + loads + ', page location=' + popup.location + ')\n'); 1.134 + 1.135 + dumpSHistory(window); 1.136 + 1.137 + if (loads == 1) { 1.138 + is(popup.scrollY, 0, "test 1"); 1.139 + popup.scroll(0, 100); 1.140 + 1.141 + popup.history.pushState('', '', '?pushed'); 1.142 + is(popup.scrollY, 100, "test 2"); 1.143 + popup.scroll(0, 200); // set state-2's position to 200 1.144 + 1.145 + popup.history.back(); 1.146 + is(popup.scrollY, 100, "test 3"); 1.147 + popup.scroll(0, 150); // set original page's position to 150 1.148 + 1.149 + popup.history.forward(); 1.150 + is(popup.scrollY, 200, "test 4"); 1.151 + 1.152 + popup.history.back(); 1.153 + is(popup.scrollY, 150, "test 5"); 1.154 + 1.155 + popup.history.forward(); 1.156 + is(popup.scrollY, 200, "test 6"); 1.157 + 1.158 + // At this point, the history looks like: 1.159 + // PATH POSITION 1.160 + // file_bug590573_1.html 150 <-- oldest 1.161 + // file_bug590573_1.html?pushed 200 <-- newest, current 1.162 + 1.163 + // Now test that the scroll position is persisted when we have real 1.164 + // navigations involved. First, we need to spin the event loop so that the 1.165 + // navigation doesn't replace our current history entry. 1.166 + 1.167 + setTimeout(pageLoad, 0); 1.168 + } 1.169 + else if (loads == 2) { 1.170 + page2LoadCallbackEnabled = true; 1.171 + popup.location = 'file_bug590573_2.html'; 1.172 + } 1.173 + else if (loads == 3) { 1.174 + ok(popup.location.href.match('file_bug590573_2.html$'), 1.175 + "Location was " + popup.location + 1.176 + " but should end with file_bug590573_2.html"); 1.177 + 1.178 + is(popup.scrollY, 0, "test 7"); 1.179 + popup.scroll(0, 300); 1.180 + 1.181 + // We need to spin the event loop again before we go back, otherwise the 1.182 + // scroll positions don't get updated properly. 1.183 + setTimeout(pageLoad, 0); 1.184 + } 1.185 + else if (loads == 4) { 1.186 + page1PageShowCallbackEnabled = true; 1.187 + popup.history.back(); 1.188 + } 1.189 + else if (loads == 5) { 1.190 + // Spin the event loop again so that we get the right scroll positions. 1.191 + setTimeout(pageLoad, 0); 1.192 + } 1.193 + else if (loads == 6) { 1.194 + is(popup.location.search, "?pushed"); 1.195 + ok(popup.document.getElementById('div1'), 'page should have div1.'); 1.196 + 1.197 + // Bug 821821, on android 4.0.4 on panda we get 199 instead of 200 1.198 + if (popup.scrollY >= 199 && popup.scrollY <= 200) { 1.199 + is(1, 1, "test 8"); 1.200 + } else { 1.201 + is(1, 0, "test 8, got " + popup.scrollY + " for popup.scrollY instead of 199|200"); 1.202 + } 1.203 + 1.204 + popup.history.back(); 1.205 + is(popup.scrollY, 150, "test 9"); 1.206 + popup.history.forward(); 1.207 + 1.208 + // Bug 821821, on android 4.0.4 on panda we get 199 instead of 200 1.209 + if (popup.scrollY >= 199 && popup.scrollY <= 200) { 1.210 + is(1, 1, "test 10"); 1.211 + } else { 1.212 + is(1, 0, "test 10, got " + popup.scrollY + " for popup.scrollY instead of 199|200"); 1.213 + } 1.214 + 1.215 + // Spin one last time... 1.216 + setTimeout(pageLoad, 0); 1.217 + } 1.218 + else if (loads == 7) { 1.219 + page2PageShowCallbackEnabled = true; 1.220 + popup.history.forward(); 1.221 + } 1.222 + else if (loads == 8) { 1.223 + // Bug 821821, on Android tegras we get 299 instead of 300 sometimes 1.224 + if (popup.scrollY >= 299 && popup.scrollY <= 300) { 1.225 + is(1, 1, "test 11"); 1.226 + } else { 1.227 + is(1, 0, "test 11, got " + popup.scrollY + " for popup.scrollY instead of 299|300"); 1.228 + } 1.229 + popup.close(); 1.230 + SimpleTest.finish(); 1.231 + } 1.232 + else { 1.233 + ok(false, "Got extra load!"); 1.234 + } 1.235 +} 1.236 +</script> 1.237 + 1.238 +</body> 1.239 +</html>