browser_bug1685807.js (2406B)
1 /** 2 * Bug 1685807 - Testing that the window.name won't be reset when loading an 3 * about:blank page to a window which had loaded non-about:blank 4 * page. And other case that window.name should be reset if 5 * the document.domain has changed. 6 */ 7 8 "use strict"; 9 10 const EMPTY_URI = 11 "https://test1.example.com/browser/dom/tests/browser/file_empty.html"; 12 const TEST_URI = 13 "https://test1.example.com/browser/dom/tests/browser/file_bug1685807.html"; 14 15 add_setup(async function () { 16 await SpecialPowers.pushPrefEnv({ 17 set: [["privacy.window.name.update.enabled", true]], 18 }); 19 }); 20 21 add_task(async function doTests() { 22 for (let testDocDomain of [false, true]) { 23 // Open an empty tab. 24 let tab = await BrowserTestUtils.openNewForegroundTab(gBrowser, EMPTY_URI); 25 let browser = tab.linkedBrowser; 26 27 // Create a promise in order to wait loading of the about:blank page. 28 let loadedPromise = BrowserTestUtils.browserLoaded( 29 browser, 30 false, 31 "about:blank" 32 ); 33 34 // Set the window.name and document.domain. 35 SpecialPowers.spawn( 36 browser, 37 [TEST_URI, testDocDomain], 38 (aTestURI, aTestDocDomain) => { 39 // Mark the first entry as having been interacted with. 40 content.document.notifyUserGestureActivation(); 41 42 content.name = "Test"; 43 44 if (aTestDocDomain) { 45 content.document.domain = "example.com"; 46 } 47 48 // Open the page which will trigger the loading of the about:blank page. 49 content.open(aTestURI); 50 } 51 ); 52 53 // Wait until the about:blank page is loaded. 54 await loadedPromise; 55 56 // Check the window.name. 57 await SpecialPowers.spawn(browser, [testDocDomain], aTestDocDomain => { 58 if (aTestDocDomain) { 59 // The window.name should be reset if the document.domain was set to a 60 // cross-origin. 61 is(content.name, "", "The window.name should be reset."); 62 } else { 63 is(content.name, "Test", "The window.name shouldn't be reset."); 64 } 65 }); 66 67 let awaitPageShow = BrowserTestUtils.waitForContentEvent( 68 browser, 69 "pageshow" 70 ); 71 browser.goBack(false); 72 await awaitPageShow; 73 74 // Check the window.name. 75 await SpecialPowers.spawn(browser, [], () => { 76 is(content.name, "Test", "The window.name is correct."); 77 }); 78 79 BrowserTestUtils.removeTab(tab); 80 } 81 });