browser_bug1646088.js (2933B)
1 let dir = getChromeDir(getResolvedURI(gTestPath)); 2 dir.append("file_dummy.html"); 3 const uriString = Services.io.newFileURI(dir).spec; 4 5 add_task(async function () { 6 await BrowserTestUtils.withNewTab( 7 "https://example.com", 8 async function (browser) { 9 // Override the browser's `prepareToChangeRemoteness` so that we can delay 10 // the process switch for an indefinite amount of time. This will allow us 11 // to control the timing of the resolve call to trigger the bug. 12 let prepareToChangeCalled = Promise.withResolvers(); 13 let finishSwitch = Promise.withResolvers(); 14 let oldPrepare = browser.prepareToChangeRemoteness; 15 browser.prepareToChangeRemoteness = async () => { 16 prepareToChangeCalled.resolve(); 17 await oldPrepare.call(browser); 18 await finishSwitch.promise; 19 }; 20 21 // Begin a process switch, which should cause `prepareToChangeRemoteness` to 22 // be called. 23 // NOTE: This used to avoid BrowserTestUtils.loadURI, as that call would 24 // previously eagerly perform a process switch meaning that the interesting 25 // codepath wouldn't be triggered. Nowadays the process switch codepath 26 // always happens during navigation as required by this test. 27 info("Beginning process switch into file URI process"); 28 let browserLoaded = BrowserTestUtils.browserLoaded(browser); 29 BrowserTestUtils.startLoadingURIString(browser, uriString); 30 await prepareToChangeCalled.promise; 31 32 // The tab we opened is now midway through process switching. Open another 33 // browser within the same tab, and immediately close it after the load 34 // finishes. 35 info("Creating new tab loaded in file URI process"); 36 let fileProcess; 37 let browserParentDestroyed = Promise.withResolvers(); 38 await BrowserTestUtils.withNewTab( 39 uriString, 40 async function (otherBrowser) { 41 let remoteTab = otherBrowser.frameLoader.remoteTab; 42 fileProcess = remoteTab.contentProcessId; 43 info("Loaded test URI in pid: " + fileProcess); 44 45 browserParentDestroyed.resolve( 46 TestUtils.topicObserved( 47 "ipc:browser-destroyed", 48 subject => subject === remoteTab 49 ) 50 ); 51 } 52 ); 53 await browserParentDestroyed.promise; 54 55 // This browser has now been closed, which could cause the file content 56 // process to begin shutting down, despite us process switching into it. 57 // We can now allow the process switch to finish, and wait for the load to 58 // finish as well. 59 info("BrowserParent has been destroyed, finishing process switch"); 60 finishSwitch.resolve(); 61 await browserLoaded; 62 63 info("Load complete"); 64 is( 65 browser.frameLoader.remoteTab.contentProcessId, 66 fileProcess, 67 "Should have loaded in the same file URI process" 68 ); 69 } 70 ); 71 });