browser/modules/test/browser_UITour_availableTargets.js

Fri, 16 Jan 2015 18:13:44 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Fri, 16 Jan 2015 18:13:44 +0100
branch
TOR_BUG_9701
changeset 14
925c144e1f1f
permissions
-rw-r--r--

Integrate suggestion from review to improve consistency with existing code.

michael@0 1 /* Any copyright is dedicated to the Public Domain.
michael@0 2 * http://creativecommons.org/publicdomain/zero/1.0/ */
michael@0 3
michael@0 4 "use strict";
michael@0 5
michael@0 6 let gTestTab;
michael@0 7 let gContentAPI;
michael@0 8 let gContentWindow;
michael@0 9
michael@0 10 Components.utils.import("resource:///modules/UITour.jsm");
michael@0 11
michael@0 12 function test() {
michael@0 13 requestLongerTimeout(2);
michael@0 14 UITourTest();
michael@0 15 }
michael@0 16
michael@0 17 let tests = [
michael@0 18 function test_availableTargets(done) {
michael@0 19 gContentAPI.getConfiguration("availableTargets", (data) => {
michael@0 20 ok_targets(data, [
michael@0 21 "accountStatus",
michael@0 22 "addons",
michael@0 23 "appMenu",
michael@0 24 "backForward",
michael@0 25 "bookmarks",
michael@0 26 "customize",
michael@0 27 "help",
michael@0 28 "home",
michael@0 29 "pinnedTab",
michael@0 30 "quit",
michael@0 31 "search",
michael@0 32 "searchProvider",
michael@0 33 "urlbar",
michael@0 34 ]);
michael@0 35 ok(UITour.availableTargetsCache.has(window),
michael@0 36 "Targets should now be cached");
michael@0 37 done();
michael@0 38 });
michael@0 39 },
michael@0 40
michael@0 41 function test_availableTargets_changeWidgets(done) {
michael@0 42 CustomizableUI.removeWidgetFromArea("bookmarks-menu-button");
michael@0 43 ok(!UITour.availableTargetsCache.has(window),
michael@0 44 "Targets should be evicted from cache after widget change");
michael@0 45 gContentAPI.getConfiguration("availableTargets", (data) => {
michael@0 46 ok_targets(data, [
michael@0 47 "accountStatus",
michael@0 48 "addons",
michael@0 49 "appMenu",
michael@0 50 "backForward",
michael@0 51 "customize",
michael@0 52 "help",
michael@0 53 "home",
michael@0 54 "pinnedTab",
michael@0 55 "quit",
michael@0 56 "search",
michael@0 57 "searchProvider",
michael@0 58 "urlbar",
michael@0 59 ]);
michael@0 60 ok(UITour.availableTargetsCache.has(window),
michael@0 61 "Targets should now be cached again");
michael@0 62 CustomizableUI.reset();
michael@0 63 ok(!UITour.availableTargetsCache.has(window),
michael@0 64 "Targets should not be cached after reset");
michael@0 65 done();
michael@0 66 });
michael@0 67 },
michael@0 68
michael@0 69 function test_availableTargets_exceptionFromGetTarget(done) {
michael@0 70 // The query function for the "search" target will throw if it's not found.
michael@0 71 // Make sure the callback still fires with the other available targets.
michael@0 72 CustomizableUI.removeWidgetFromArea("search-container");
michael@0 73 gContentAPI.getConfiguration("availableTargets", (data) => {
michael@0 74 // Default minus "search" and "searchProvider"
michael@0 75 ok_targets(data, [
michael@0 76 "accountStatus",
michael@0 77 "addons",
michael@0 78 "appMenu",
michael@0 79 "backForward",
michael@0 80 "bookmarks",
michael@0 81 "customize",
michael@0 82 "help",
michael@0 83 "home",
michael@0 84 "pinnedTab",
michael@0 85 "quit",
michael@0 86 "urlbar",
michael@0 87 ]);
michael@0 88 CustomizableUI.reset();
michael@0 89 done();
michael@0 90 });
michael@0 91 },
michael@0 92 ];
michael@0 93
michael@0 94 function ok_targets(actualData, expectedTargets) {
michael@0 95 // Depending on how soon after page load this is called, the selected tab icon
michael@0 96 // may or may not be showing the loading throbber. Check for its presence and
michael@0 97 // insert it into expectedTargets if it's visible.
michael@0 98 let selectedTabIcon =
michael@0 99 document.getAnonymousElementByAttribute(gBrowser.selectedTab,
michael@0 100 "anonid",
michael@0 101 "tab-icon-image");
michael@0 102 if (selectedTabIcon && UITour.isElementVisible(selectedTabIcon))
michael@0 103 expectedTargets.push("selectedTabIcon");
michael@0 104
michael@0 105 ok(Array.isArray(actualData.targets), "data.targets should be an array");
michael@0 106 is(actualData.targets.sort().toString(), expectedTargets.sort().toString(),
michael@0 107 "Targets should be as expected");
michael@0 108 }

mercurial