test_bug529119-1.html (3308B)
1 <!DOCTYPE HTML> 2 <html> 3 <head> 4 <title>Test bug 529119</title> 5 <script src="/tests/SimpleTest/SimpleTest.js"></script> 6 <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" /> 7 8 <script class="testbody" type="text/javascript"> 9 10 SimpleTest.waitForExplicitFinish(); 11 SimpleTest.requestFlakyTimeout("untriaged"); 12 13 var workingURL = "http://mochi.test:8888/tests/docshell/test/mochitest/bug529119-window.html"; 14 var faultyURL = "https://www.some-nonexistent-domain-27489274c892748217cn2384.test/"; 15 16 var w = null; 17 var phase = 0; 18 var gotWrongPageOnTryAgainClick = false; 19 // Token that represents which page we currently have loaded. 20 var token = 0; 21 22 function delay(msec) { 23 return new Promise(resolve => setTimeout(resolve, msec)); 24 } 25 26 async function assignToken(tokenToAssign) { 27 await SpecialPowers.spawn(w, [tokenToAssign], 28 newToken => { this.content.token = newToken }); 29 } 30 31 async function pollForPage() { 32 while (true) { 33 try { 34 // When we do our navigation, there may be an interstitial about:blank 35 // page if the navigation involves a process switch. That about:blank 36 // will exist between the new process's docshell being created and the 37 // actual page that's being loaded loading (which can happen async from 38 // the docshell creation). We want to avoid treating the initial 39 // about:blank as a new page. 40 // 41 // We could conceivably expose Document::IsInitialDocument() as a 42 // ChromeOnly thing and use it here, but let's just filter out all 43 // about:blank, since we don't expect any in this test. 44 var haveNewPage = await SpecialPowers.spawn(w, [token], 45 currentToken => this.content.token != currentToken && 46 this.content.location.href != "about:blank"); 47 48 if (haveNewPage) { 49 ++token; 50 assignToken(token); 51 break; 52 } 53 } catch (e) { 54 // Something went wrong; just keep waiting. 55 } 56 57 await delay(100); 58 } 59 } 60 61 async function windowLoaded() { 62 switch (phase) { 63 case 0: 64 assignToken(token); 65 66 /* 2. We have succeededfully loaded a page, now go to a faulty URL */ 67 window.setTimeout(function() { 68 w.location.href = faultyURL; 69 }, 0); 70 71 phase = 1; 72 73 await pollForPage(w); 74 is(await SpecialPowers.spawn(w, [], () => this.content.location.href), 75 faultyURL, 76 "Is on an error page initially"); 77 78 /* 3. now, while we are on the error page, try to reload it, actually 79 click the "Try Again" button */ 80 SpecialPowers.spawn(w, [], () => this.content.location.reload()); 81 82 await pollForPage(w); 83 84 /* 4-finish, check we are still on the error page */ 85 is(await SpecialPowers.spawn(w, [], () => this.content.location.href), 86 faultyURL, 87 "Is on an error page"); 88 is(gotWrongPageOnTryAgainClick, false, 89 "Must not get www.example.com page on reload of an error page"); 90 w.close(); 91 SimpleTest.finish(); 92 break; 93 94 case 1: 95 /* 4-check, we must not get here! */ 96 gotWrongPageOnTryAgainClick = true; 97 break; 98 } 99 } 100 101 function startTest() { 102 /* 1. load a URL that leads to an error page */ 103 w = window.open(workingURL); 104 } 105 106 </script> 107 </head> 108 <body onload="startTest();"> 109 </body> 110 </html>