gecko/browser/modules/test/browser_UITour_availableTargets.js
Blair McBride 1096696388 Bug 1068284 - UI Tour: Add ability to highlight search provider in search menu. r=MattN
--HG--
extra : transplant_source : %AA%DA%ED%B6%24F%92%F0%D3k%F6%D34%2054%C4%23%D8%F0
2014-10-15 13:48:49 +13:00

122 lines
3.5 KiB
JavaScript

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