michael@0: /* Any copyright is dedicated to the Public Domain. michael@0: * http://creativecommons.org/publicdomain/zero/1.0/ */ michael@0: michael@0: "use strict"; michael@0: michael@0: let gTestTab; michael@0: let gContentAPI; michael@0: let gContentWindow; michael@0: michael@0: Components.utils.import("resource:///modules/UITour.jsm"); michael@0: michael@0: function test() { michael@0: requestLongerTimeout(2); michael@0: UITourTest(); michael@0: } michael@0: michael@0: let tests = [ michael@0: function test_availableTargets(done) { michael@0: gContentAPI.getConfiguration("availableTargets", (data) => { michael@0: ok_targets(data, [ michael@0: "accountStatus", michael@0: "addons", michael@0: "appMenu", michael@0: "backForward", michael@0: "bookmarks", michael@0: "customize", michael@0: "help", michael@0: "home", michael@0: "pinnedTab", michael@0: "quit", michael@0: "search", michael@0: "searchProvider", michael@0: "urlbar", michael@0: ]); michael@0: ok(UITour.availableTargetsCache.has(window), michael@0: "Targets should now be cached"); michael@0: done(); michael@0: }); michael@0: }, michael@0: michael@0: function test_availableTargets_changeWidgets(done) { michael@0: CustomizableUI.removeWidgetFromArea("bookmarks-menu-button"); michael@0: ok(!UITour.availableTargetsCache.has(window), michael@0: "Targets should be evicted from cache after widget change"); michael@0: gContentAPI.getConfiguration("availableTargets", (data) => { michael@0: ok_targets(data, [ michael@0: "accountStatus", michael@0: "addons", michael@0: "appMenu", michael@0: "backForward", michael@0: "customize", michael@0: "help", michael@0: "home", michael@0: "pinnedTab", michael@0: "quit", michael@0: "search", michael@0: "searchProvider", michael@0: "urlbar", michael@0: ]); michael@0: ok(UITour.availableTargetsCache.has(window), michael@0: "Targets should now be cached again"); michael@0: CustomizableUI.reset(); michael@0: ok(!UITour.availableTargetsCache.has(window), michael@0: "Targets should not be cached after reset"); michael@0: done(); michael@0: }); michael@0: }, michael@0: michael@0: function test_availableTargets_exceptionFromGetTarget(done) { michael@0: // The query function for the "search" target will throw if it's not found. michael@0: // Make sure the callback still fires with the other available targets. michael@0: CustomizableUI.removeWidgetFromArea("search-container"); michael@0: gContentAPI.getConfiguration("availableTargets", (data) => { michael@0: // Default minus "search" and "searchProvider" michael@0: ok_targets(data, [ michael@0: "accountStatus", michael@0: "addons", michael@0: "appMenu", michael@0: "backForward", michael@0: "bookmarks", michael@0: "customize", michael@0: "help", michael@0: "home", michael@0: "pinnedTab", michael@0: "quit", michael@0: "urlbar", michael@0: ]); michael@0: CustomizableUI.reset(); michael@0: done(); michael@0: }); michael@0: }, michael@0: ]; michael@0: michael@0: function ok_targets(actualData, expectedTargets) { michael@0: // Depending on how soon after page load this is called, the selected tab icon michael@0: // may or may not be showing the loading throbber. Check for its presence and michael@0: // insert it into expectedTargets if it's visible. michael@0: let selectedTabIcon = michael@0: document.getAnonymousElementByAttribute(gBrowser.selectedTab, michael@0: "anonid", michael@0: "tab-icon-image"); michael@0: if (selectedTabIcon && UITour.isElementVisible(selectedTabIcon)) michael@0: expectedTargets.push("selectedTabIcon"); michael@0: michael@0: ok(Array.isArray(actualData.targets), "data.targets should be an array"); michael@0: is(actualData.targets.sort().toString(), expectedTargets.sort().toString(), michael@0: "Targets should be as expected"); michael@0: }