test_bug509055.html (3555B)
1 <!DOCTYPE HTML> 2 <html> 3 <!-- 4 https://bugzilla.mozilla.org/show_bug.cgi?id=509055 5 --> 6 <head> 7 <title>Test for Bug 509055</title> 8 <script src="/tests/SimpleTest/SimpleTest.js"></script> 9 <script src="/tests/SimpleTest/EventUtils.js"></script> 10 <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/> 11 </head> 12 <body> 13 <a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=509055">Mozilla Bug 509055</a> 14 <p id="display"></p> 15 <div id="status"></div> 16 <div id="content"> 17 </div> 18 <pre id="test"> 19 <script type="application/javascript"> 20 21 /** Test for Bug 509055 */ 22 23 SimpleTest.waitForExplicitFinish(); 24 25 var gGen; 26 27 function shortWait() { 28 setTimeout(function() { gGen.next(); }, 0, false); 29 } 30 31 function onChildHashchange() { 32 // gGen might be undefined when we refresh the page, so we have to check here 33 dump("onChildHashchange() called.\n"); 34 if (gGen) 35 gGen.next(); 36 } 37 38 function onChildLoad() { 39 if (gGen) 40 gGen.next(); 41 } 42 43 async function* runTest() { 44 var popup = window.open("file_bug509055.html", "popup 0", 45 "height=200,width=200,location=yes," + 46 "menubar=yes,status=yes,toolbar=yes,dependent=yes"); 47 popup.hashchangeCallback = onChildHashchange; 48 popup.onload = onChildLoad; 49 dump("Waiting for initial load.\n"); 50 yield undefined; 51 52 // Without this wait, the change to location.hash below doesn't create a 53 // SHEntry or enable the back button. 54 shortWait(); 55 dump("Got initial load. Spinning event loop.\n"); 56 yield undefined; 57 58 popup.location.hash = "#1"; 59 dump("Waiting for hashchange.\n"); 60 yield undefined; 61 62 popup.history.back(); 63 dump("Waiting for second hashchange.\n"); 64 yield undefined; // wait for hashchange 65 66 popup.document.title = "Changed"; 67 68 // Wait for listeners to be notified of the title change. 69 shortWait(); 70 dump("Got second hashchange. Spinning event loop.\n"); 71 yield undefined; 72 73 let sheTitle = ""; 74 if (!SpecialPowers.Services.appinfo.sessionHistoryInParent) { 75 var sh = SpecialPowers.wrap(popup) 76 .docShell 77 .QueryInterface(SpecialPowers.Ci.nsIWebNavigation) 78 .sessionHistory; 79 80 // Get the title of the inner popup's current SHEntry 81 sheTitle = sh.legacySHistory.getEntryAtIndex(sh.index).title; 82 } else { 83 let chromeScript = SpecialPowers.loadChromeScript(() => { 84 /* eslint-env mozilla/chrome-script */ 85 addMessageListener("getTitle", browsingContext => { 86 // eslint-disable-next-line no-shadow 87 let sh = browsingContext.sessionHistory; 88 let title = sh.getEntryAtIndex(sh.index).title; 89 sendAsyncMessage("title", title); 90 }); 91 }); 92 93 let p = chromeScript.promiseOneMessage("title"); 94 let browsingContext = SpecialPowers.wrap(popup) 95 .docShell.browsingContext; 96 chromeScript.sendAsyncMessage("getTitle", browsingContext); 97 sheTitle = await p; 98 chromeScript.destroy(); 99 } 100 is(sheTitle, "Changed", "SHEntry's title should change when we change."); 101 102 popup.close(); 103 104 SimpleTest.executeSoon(SimpleTest.finish); 105 } 106 107 window.addEventListener("load", function() { 108 gGen = runTest(); 109 gGen.next(); 110 }); 111 112 </script> 113 114 </body> 115 </html>