browser/modules/test/browser_UITour_availableTargets.js

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/browser/modules/test/browser_UITour_availableTargets.js	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,108 @@
     1.4 +/* Any copyright is dedicated to the Public Domain.
     1.5 + * http://creativecommons.org/publicdomain/zero/1.0/ */
     1.6 +
     1.7 +"use strict";
     1.8 +
     1.9 +let gTestTab;
    1.10 +let gContentAPI;
    1.11 +let gContentWindow;
    1.12 +
    1.13 +Components.utils.import("resource:///modules/UITour.jsm");
    1.14 +
    1.15 +function test() {
    1.16 +  requestLongerTimeout(2);
    1.17 +  UITourTest();
    1.18 +}
    1.19 +
    1.20 +let tests = [
    1.21 +  function test_availableTargets(done) {
    1.22 +    gContentAPI.getConfiguration("availableTargets", (data) => {
    1.23 +      ok_targets(data, [
    1.24 +        "accountStatus",
    1.25 +        "addons",
    1.26 +        "appMenu",
    1.27 +        "backForward",
    1.28 +        "bookmarks",
    1.29 +        "customize",
    1.30 +        "help",
    1.31 +        "home",
    1.32 +        "pinnedTab",
    1.33 +        "quit",
    1.34 +        "search",
    1.35 +        "searchProvider",
    1.36 +        "urlbar",
    1.37 +      ]);
    1.38 +      ok(UITour.availableTargetsCache.has(window),
    1.39 +         "Targets should now be cached");
    1.40 +      done();
    1.41 +    });
    1.42 +  },
    1.43 +
    1.44 +  function test_availableTargets_changeWidgets(done) {
    1.45 +    CustomizableUI.removeWidgetFromArea("bookmarks-menu-button");
    1.46 +    ok(!UITour.availableTargetsCache.has(window),
    1.47 +       "Targets should be evicted from cache after widget change");
    1.48 +    gContentAPI.getConfiguration("availableTargets", (data) => {
    1.49 +      ok_targets(data, [
    1.50 +        "accountStatus",
    1.51 +        "addons",
    1.52 +        "appMenu",
    1.53 +        "backForward",
    1.54 +        "customize",
    1.55 +        "help",
    1.56 +        "home",
    1.57 +        "pinnedTab",
    1.58 +        "quit",
    1.59 +        "search",
    1.60 +        "searchProvider",
    1.61 +        "urlbar",
    1.62 +      ]);
    1.63 +      ok(UITour.availableTargetsCache.has(window),
    1.64 +         "Targets should now be cached again");
    1.65 +      CustomizableUI.reset();
    1.66 +      ok(!UITour.availableTargetsCache.has(window),
    1.67 +         "Targets should not be cached after reset");
    1.68 +      done();
    1.69 +    });
    1.70 +  },
    1.71 +
    1.72 +  function test_availableTargets_exceptionFromGetTarget(done) {
    1.73 +    // The query function for the "search" target will throw if it's not found.
    1.74 +    // Make sure the callback still fires with the other available targets.
    1.75 +    CustomizableUI.removeWidgetFromArea("search-container");
    1.76 +    gContentAPI.getConfiguration("availableTargets", (data) => {
    1.77 +      // Default minus "search" and "searchProvider"
    1.78 +      ok_targets(data, [
    1.79 +        "accountStatus",
    1.80 +        "addons",
    1.81 +        "appMenu",
    1.82 +        "backForward",
    1.83 +        "bookmarks",
    1.84 +        "customize",
    1.85 +        "help",
    1.86 +        "home",
    1.87 +        "pinnedTab",
    1.88 +        "quit",
    1.89 +        "urlbar",
    1.90 +      ]);
    1.91 +      CustomizableUI.reset();
    1.92 +      done();
    1.93 +    });
    1.94 +  },
    1.95 +];
    1.96 +
    1.97 +function ok_targets(actualData, expectedTargets) {
    1.98 +  // Depending on how soon after page load this is called, the selected tab icon
    1.99 +  // may or may not be showing the loading throbber.  Check for its presence and
   1.100 +  // insert it into expectedTargets if it's visible.
   1.101 +  let selectedTabIcon =
   1.102 +    document.getAnonymousElementByAttribute(gBrowser.selectedTab,
   1.103 +                                            "anonid",
   1.104 +                                            "tab-icon-image");
   1.105 +  if (selectedTabIcon && UITour.isElementVisible(selectedTabIcon))
   1.106 +    expectedTargets.push("selectedTabIcon");
   1.107 +
   1.108 +  ok(Array.isArray(actualData.targets), "data.targets should be an array");
   1.109 +  is(actualData.targets.sort().toString(), expectedTargets.sort().toString(),
   1.110 +     "Targets should be as expected");
   1.111 +}

mercurial