browser_parentProcessRestoreHash.js (3159B)
1 "use strict"; 2 3 const SELFCHROMEURL = 4 "chrome://mochitests/content/browser/browser/" + 5 "components/sessionstore/test/browser_parentProcessRestoreHash.js"; 6 7 const Cm = Components.manager; 8 9 const TESTCLASSID = "78742c04-3630-448c-9be3-6c5070f062de"; 10 11 const TESTURL = "about:testpageforsessionrestore#foo"; 12 13 let TestAboutPage = { 14 QueryInterface: ChromeUtils.generateQI(["nsIAboutModule"]), 15 getURIFlags() { 16 // No CAN_ or MUST_LOAD_IN_CHILD means this loads in the parent: 17 return ( 18 Ci.nsIAboutModule.ALLOW_SCRIPT | 19 Ci.nsIAboutModule.URI_SAFE_FOR_UNTRUSTED_CONTENT | 20 Ci.nsIAboutModule.HIDE_FROM_ABOUTABOUT 21 ); 22 }, 23 24 newChannel(aURI, aLoadInfo) { 25 // about: page inception! 26 let newURI = Services.io.newURI(SELFCHROMEURL); 27 let channel = Services.io.newChannelFromURIWithLoadInfo(newURI, aLoadInfo); 28 channel.originalURI = aURI; 29 return channel; 30 }, 31 32 createInstance(iid) { 33 return this.QueryInterface(iid); 34 }, 35 36 register() { 37 Cm.QueryInterface(Ci.nsIComponentRegistrar).registerFactory( 38 Components.ID(TESTCLASSID), 39 "Only here for a test", 40 "@mozilla.org/network/protocol/about;1?what=testpageforsessionrestore", 41 this 42 ); 43 }, 44 45 unregister() { 46 Cm.QueryInterface(Ci.nsIComponentRegistrar).unregisterFactory( 47 Components.ID(TESTCLASSID), 48 this 49 ); 50 }, 51 }; 52 53 /** 54 * Test that switching from a remote to a parent process browser 55 * correctly clears the userTypedValue 56 */ 57 add_task(async function () { 58 await SpecialPowers.pushPrefEnv({ 59 set: [["dom.security.skip_about_page_has_csp_assert", true]], 60 }); 61 62 TestAboutPage.register(); 63 let tab = await BrowserTestUtils.openNewForegroundTab( 64 gBrowser, 65 "http://example.com/", 66 true, 67 true 68 ); 69 ok(tab.linkedBrowser.isRemoteBrowser, "Browser should be remote"); 70 71 let resolveLocationChangePromise; 72 let locationChangePromise = new Promise( 73 r => (resolveLocationChangePromise = r) 74 ); 75 let wpl = { 76 onStateChange(listener, request, state, _status) { 77 let location = request.QueryInterface(Ci.nsIChannel).originalURI; 78 // Ignore about:blank loads. 79 let docStop = 80 Ci.nsIWebProgressListener.STATE_STOP | 81 Ci.nsIWebProgressListener.STATE_IS_NETWORK; 82 if (location.spec == "about:blank" || (state & docStop) != docStop) { 83 return; 84 } 85 is(location.spec, TESTURL, "Got the expected URL"); 86 resolveLocationChangePromise(); 87 }, 88 }; 89 gBrowser.addProgressListener(wpl); 90 91 gURLBar.value = TESTURL; 92 gURLBar.select(); 93 EventUtils.sendKey("return"); 94 95 await locationChangePromise; 96 97 ok(!tab.linkedBrowser.isRemoteBrowser, "Browser should no longer be remote"); 98 99 is(gURLBar.value, TESTURL, "URL bar visible value should be correct."); 100 is(gURLBar.untrimmedValue, TESTURL, "URL bar value should be correct."); 101 is( 102 gURLBar.getAttribute("pageproxystate"), 103 "valid", 104 "URL bar is in valid page proxy state" 105 ); 106 107 ok( 108 !tab.linkedBrowser.userTypedValue, 109 "No userTypedValue should be on the browser." 110 ); 111 112 BrowserTestUtils.removeTab(tab); 113 gBrowser.removeProgressListener(wpl); 114 TestAboutPage.unregister(); 115 });