browser_bug1554070.js (1496B)
1 "use strict"; 2 3 const HTTPS_TEST_ROOT = getRootDirectory(gTestPath).replace( 4 "chrome://mochitests/content", 5 "https://example.com" 6 ); 7 8 const URL0 = HTTPS_TEST_ROOT + "file_bug1554070_1.html"; 9 const URL1 = HTTPS_TEST_ROOT + "file_bug1554070_2.html"; 10 const URL2 = "https://example.org/"; 11 12 add_task(async function () { 13 let tab = await BrowserTestUtils.openNewForegroundTab({ 14 gBrowser, 15 waitForLoad: true, 16 }); 17 18 let browser = tab.linkedBrowser; 19 20 function click() { 21 return SpecialPowers.spawn(browser, [], () => { 22 let anchor = content.document.querySelector("a"); 23 anchor.click(); 24 }); 25 } 26 27 // Load file_bug1554070_1.html. 28 BrowserTestUtils.startLoadingURIString(browser, URL0); 29 await BrowserTestUtils.browserLoaded(browser, false, URL0); 30 is(gBrowser.currentURI.spec, URL0, "loaded file_bug1554070_1.html"); 31 32 // Click the link in file_bug1554070_1.html. It should open 33 // file_bug1554070_2.html in the current tab. 34 await click(); 35 await BrowserTestUtils.browserLoaded(browser, false, URL1); 36 is(gBrowser.currentURI.spec, URL1, "loaded file_bug1554070_2.html"); 37 38 // Click the link in file_bug1554070_2.html. It should open example.org in 39 // a new tab. 40 await Promise.all([ 41 click(), 42 BrowserTestUtils.waitForNewTab(gBrowser, URL2, true), 43 ]); 44 is(gBrowser.tabs.length, 3, "got new tab"); 45 is(gBrowser.currentURI.spec, URL2, "loaded example.org"); 46 47 BrowserTestUtils.removeTab(gBrowser.selectedTab); 48 BrowserTestUtils.removeTab(tab); 49 });