browser_backgroundTab.js (1755B)
1 "use strict"; 2 3 var gTestTab; 4 var gContentAPI; 5 6 requestLongerTimeout(2); 7 add_task(setup_UITourTest); 8 9 add_UITour_task(async function test_bg_getConfiguration() { 10 info("getConfiguration is on the allowed list so should work"); 11 await loadForegroundTab(); 12 let data = await getConfigurationPromise("availableTargets"); 13 ok(data, "Got data from getConfiguration"); 14 BrowserTestUtils.removeTab(gBrowser.selectedTab); 15 }); 16 17 add_UITour_task(async function test_bg_showInfo() { 18 info("showInfo isn't on the allowed action list so should be denied"); 19 await loadForegroundTab(); 20 21 await showInfoPromise( 22 "appMenu", 23 "Hello from the background", 24 "Surprise!" 25 ).then( 26 () => ok(false, "panel shouldn't have shown from a background tab"), 27 () => ok(true, "panel wasn't shown from a background tab") 28 ); 29 30 BrowserTestUtils.removeTab(gBrowser.selectedTab); 31 }); 32 33 async function loadForegroundTab() { 34 // Spawn a content task that resolves once we're sure the visibilityState was 35 // changed. This state is what the tests in this file rely on. 36 let promise = SpecialPowers.spawn( 37 gBrowser.selectedTab.linkedBrowser, 38 [], 39 async function () { 40 return new Promise(resolve => { 41 let document = content.document; 42 document.addEventListener("visibilitychange", function onStateChange() { 43 Assert.equal( 44 document.visibilityState, 45 "hidden", 46 "UITour page should be hidden now." 47 ); 48 document.removeEventListener("visibilitychange", onStateChange); 49 resolve(); 50 }); 51 }); 52 } 53 ); 54 await BrowserTestUtils.openNewForegroundTab(gBrowser); 55 await promise; 56 isnot(gBrowser.selectedTab, gTestTab, "Make sure tour tab isn't selected"); 57 }