browser_UITour_availableTargets.js (3772B)
1 "use strict"; 2 3 ChromeUtils.defineESModuleGetters(this, { 4 CustomizableUITestUtils: 5 "resource://testing-common/CustomizableUITestUtils.sys.mjs", 6 }); 7 let gCUITestUtils = new CustomizableUITestUtils(window); 8 9 var gTestTab; 10 var gContentAPI; 11 12 var hasQuit = AppConstants.platform != "macosx"; 13 14 requestLongerTimeout(2); 15 16 function getExpectedTargets() { 17 return [ 18 "accountStatus", 19 "addons", 20 "appMenu", 21 "backForward", 22 "help", 23 "logins", 24 "pageAction-bookmark", 25 "profilesAppMenuButton", 26 "privateWindow", 27 ...(hasQuit ? ["quit"] : []), 28 "readerMode-urlBar", 29 "urlbar", 30 ]; 31 } 32 33 add_task(setup_UITourTest); 34 35 add_UITour_task(async function test_availableTargets() { 36 let data = await getConfigurationPromise("availableTargets"); 37 let expecteds = getExpectedTargets(); 38 ok_targets(data, expecteds); 39 ok(UITour.availableTargetsCache.has(window), "Targets should now be cached"); 40 }); 41 42 add_UITour_task(async function test_availableTargets_changeWidgets() { 43 CustomizableUI.addWidgetToArea( 44 "bookmarks-menu-button", 45 CustomizableUI.AREA_NAVBAR, 46 0 47 ); 48 ok( 49 !UITour.availableTargetsCache.has(window), 50 "Targets should be evicted from cache after widget change" 51 ); 52 let data = await getConfigurationPromise("availableTargets"); 53 let expecteds = getExpectedTargets(); 54 expecteds = ["bookmarks", ...expecteds]; 55 ok_targets(data, expecteds); 56 57 ok( 58 UITour.availableTargetsCache.has(window), 59 "Targets should now be cached again" 60 ); 61 CustomizableUI.reset(); 62 ok( 63 !UITour.availableTargetsCache.has(window), 64 "Targets should not be cached after reset" 65 ); 66 }); 67 68 add_UITour_task(async function test_availableTargets_search() { 69 await gCUITestUtils.addSearchBar(); 70 try { 71 let data = await getConfigurationPromise("availableTargets"); 72 let expecteds = getExpectedTargets(); 73 expecteds = ["search", "searchIcon", ...expecteds]; 74 ok_targets(data, expecteds); 75 } finally { 76 gCUITestUtils.removeSearchBar(); 77 } 78 }); 79 80 function ok_targets(actualData, expectedTargets) { 81 // Depending on how soon after page load this is called, the selected tab icon 82 // may or may not be showing the loading throbber. We can't be sure whether 83 // it appears in the list of targets, so remove it. 84 let index = actualData.targets.indexOf("selectedTabIcon"); 85 if (index != -1) { 86 actualData.targets.splice(index, 1); 87 } 88 89 ok(Array.isArray(actualData.targets), "data.targets should be an array"); 90 actualData.targets.sort(); 91 expectedTargets.sort(); 92 Assert.deepEqual( 93 actualData.targets, 94 expectedTargets, 95 "Targets should be as expected" 96 ); 97 if (actualData.targets.toString() != expectedTargets.toString()) { 98 for (let actualItem of actualData.targets) { 99 if (!expectedTargets.includes(actualItem)) { 100 ok(false, `${actualItem} was an unexpected target.`); 101 } 102 } 103 for (let expectedItem of expectedTargets) { 104 if (!actualData.targets.includes(expectedItem)) { 105 ok(false, `${expectedItem} should have been a target.`); 106 } 107 } 108 } 109 } 110 111 async function assertTargetNode(targetName, expectedNodeId) { 112 let target = await UITour.getTarget(window, targetName); 113 is(target.node.id, expectedNodeId, "UITour should get the right target node"); 114 } 115 116 var pageActionsHelper = { 117 setActionsUrlbarState(inUrlbar) { 118 this._originalStates = []; 119 PageActions._actionsByID.forEach(action => { 120 this._originalStates.push([action, action.pinnedToUrlbar]); 121 action.pinnedToUrlbar = inUrlbar; 122 }); 123 }, 124 125 restoreActionsUrlbarState() { 126 if (!this._originalStates) { 127 return; 128 } 129 for (let [action, originalState] of this._originalStates) { 130 action.pinnedToUrlbar = originalState; 131 } 132 this._originalStates = null; 133 }, 134 };