browser_restoreTabContainer.js (2336B)
1 /* This Source Code Form is subject to the terms of the Mozilla Public 2 * License, v. 2.0. If a copy of the MPL was not distributed with this 3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 4 5 "use strict"; 6 7 const TEST_PATH = getRootDirectory(gTestPath).replace( 8 "chrome://mochitests/content", 9 "https://example.com" 10 ); 11 12 add_task(async function () { 13 const testUserContextId = 2; 14 const testCases = [ 15 { 16 url: `${TEST_PATH}empty.html`, 17 crossOriginIsolated: false, 18 }, 19 { 20 url: `${TEST_PATH}coop_coep.html`, 21 crossOriginIsolated: true, 22 }, 23 ]; 24 25 for (const testCase of testCases) { 26 let tab = BrowserTestUtils.addTab(gBrowser, testCase.url, { 27 userContextId: testUserContextId, 28 }); 29 await promiseBrowserLoaded(tab.linkedBrowser); 30 31 is( 32 tab.userContextId, 33 testUserContextId, 34 `The tab was opened with the expected userContextId` 35 ); 36 37 await SpecialPowers.spawn( 38 tab.linkedBrowser, 39 [testCase.crossOriginIsolated], 40 async expectedCrossOriginIsolated => { 41 is( 42 content.window.crossOriginIsolated, 43 expectedCrossOriginIsolated, 44 `The tab was opened in the expected crossOriginIsolated environment` 45 ); 46 } 47 ); 48 49 let sessionPromise = BrowserTestUtils.waitForSessionStoreUpdate(tab); 50 BrowserTestUtils.removeTab(tab); 51 await sessionPromise; 52 53 let restoredTab = SessionStore.undoCloseTab(window, 0); 54 55 // TODO: also check that `promiseTabRestored` is fulfilled. This currently 56 // doesn't happen correctly in some cases, as the content restore is aborted 57 // when the process switch occurs to load a cross-origin-isolated document 58 // into a different process. 59 await promiseBrowserLoaded(restoredTab.linkedBrowser); 60 61 is( 62 restoredTab.userContextId, 63 testUserContextId, 64 `The tab was restored with the expected userContextId` 65 ); 66 67 await SpecialPowers.spawn( 68 restoredTab.linkedBrowser, 69 [testCase.crossOriginIsolated], 70 async expectedCrossOriginIsolated => { 71 is( 72 content.window.crossOriginIsolated, 73 expectedCrossOriginIsolated, 74 `The tab was restored in the expected crossOriginIsolated environment` 75 ); 76 } 77 ); 78 79 BrowserTestUtils.removeTab(restoredTab); 80 } 81 });