browser/modules/test/browser_UITour.js

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/browser/modules/test/browser_UITour.js	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,274 @@
     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 +  UITourTest();
    1.17 +}
    1.18 +
    1.19 +let tests = [
    1.20 +  function test_untrusted_host(done) {
    1.21 +    loadUITourTestPage(function() {
    1.22 +      let bookmarksMenu = document.getElementById("bookmarks-menu-button");
    1.23 +      ise(bookmarksMenu.open, false, "Bookmark menu should initially be closed");
    1.24 +
    1.25 +      gContentAPI.showMenu("bookmarks");
    1.26 +      ise(bookmarksMenu.open, false, "Bookmark menu should not open on a untrusted host");
    1.27 +
    1.28 +      done();
    1.29 +    }, "http://mochi.test:8888/");
    1.30 +  },
    1.31 +  function test_unsecure_host(done) {
    1.32 +    loadUITourTestPage(function() {
    1.33 +      let bookmarksMenu = document.getElementById("bookmarks-menu-button");
    1.34 +      ise(bookmarksMenu.open, false, "Bookmark menu should initially be closed");
    1.35 +
    1.36 +      gContentAPI.showMenu("bookmarks");
    1.37 +      ise(bookmarksMenu.open, false, "Bookmark menu should not open on a unsecure host");
    1.38 +
    1.39 +      done();
    1.40 +    }, "http://example.com/");
    1.41 +  },
    1.42 +  function test_unsecure_host_override(done) {
    1.43 +    Services.prefs.setBoolPref("browser.uitour.requireSecure", false);
    1.44 +    loadUITourTestPage(function() {
    1.45 +      let highlight = document.getElementById("UITourHighlight");
    1.46 +      is_element_hidden(highlight, "Highlight should initially be hidden");
    1.47 +
    1.48 +      gContentAPI.showHighlight("urlbar");
    1.49 +      waitForElementToBeVisible(highlight, done, "Highlight should be shown on a unsecure host when override pref is set");
    1.50 +
    1.51 +      Services.prefs.setBoolPref("browser.uitour.requireSecure", true);
    1.52 +    }, "http://example.com/");
    1.53 +  },
    1.54 +  function test_disabled(done) {
    1.55 +    Services.prefs.setBoolPref("browser.uitour.enabled", false);
    1.56 +
    1.57 +    let bookmarksMenu = document.getElementById("bookmarks-menu-button");
    1.58 +    ise(bookmarksMenu.open, false, "Bookmark menu should initially be closed");
    1.59 +
    1.60 +    gContentAPI.showMenu("bookmarks");
    1.61 +    ise(bookmarksMenu.open, false, "Bookmark menu should not open when feature is disabled");
    1.62 +
    1.63 +    Services.prefs.setBoolPref("browser.uitour.enabled", true);
    1.64 +    done();
    1.65 +  },
    1.66 +  function test_highlight(done) {
    1.67 +    function test_highlight_2() {
    1.68 +      let highlight = document.getElementById("UITourHighlight");
    1.69 +      gContentAPI.hideHighlight();
    1.70 +      is_element_hidden(highlight, "Highlight should be hidden after hideHighlight()");
    1.71 +
    1.72 +      gContentAPI.showHighlight("urlbar");
    1.73 +      waitForElementToBeVisible(highlight, test_highlight_3, "Highlight should be shown after showHighlight()");
    1.74 +    }
    1.75 +    function test_highlight_3() {
    1.76 +      let highlight = document.getElementById("UITourHighlight");
    1.77 +      gContentAPI.showHighlight("backForward");
    1.78 +      waitForElementToBeVisible(highlight, done, "Highlight should be shown after showHighlight()");
    1.79 +    }
    1.80 +
    1.81 +    let highlight = document.getElementById("UITourHighlight");
    1.82 +    is_element_hidden(highlight, "Highlight should initially be hidden");
    1.83 +
    1.84 +    gContentAPI.showHighlight("urlbar");
    1.85 +    waitForElementToBeVisible(highlight, test_highlight_2, "Highlight should be shown after showHighlight()");
    1.86 +  },
    1.87 +  function test_highlight_circle(done) {
    1.88 +    function check_highlight_size() {
    1.89 +      let panel = highlight.parentElement;
    1.90 +      let anchor = panel.anchorNode;
    1.91 +      let anchorRect = anchor.getBoundingClientRect();
    1.92 +      info("addons target: width: " + anchorRect.width + " height: " + anchorRect.height);
    1.93 +      let maxDimension = Math.round(Math.max(anchorRect.width, anchorRect.height));
    1.94 +      let highlightRect = highlight.getBoundingClientRect();
    1.95 +      info("highlight: width: " + highlightRect.width + " height: " + highlightRect.height);
    1.96 +      is(Math.round(highlightRect.width), maxDimension, "The width of the highlight should be equal to the largest dimension of the target");
    1.97 +      is(Math.round(highlightRect.height), maxDimension, "The height of the highlight should be equal to the largest dimension of the target");
    1.98 +      is(Math.round(highlightRect.height), Math.round(highlightRect.width), "The height and width of the highlight should be the same to create a circle");
    1.99 +      is(highlight.style.borderRadius, "100%", "The border-radius should be 100% to create a circle");
   1.100 +      done();
   1.101 +    }
   1.102 +    let highlight = document.getElementById("UITourHighlight");
   1.103 +    is_element_hidden(highlight, "Highlight should initially be hidden");
   1.104 +
   1.105 +    gContentAPI.showHighlight("addons");
   1.106 +    waitForElementToBeVisible(highlight, check_highlight_size, "Highlight should be shown after showHighlight()");
   1.107 +  },
   1.108 +  function test_highlight_customize_auto_open_close(done) {
   1.109 +    let highlight = document.getElementById("UITourHighlight");
   1.110 +    gContentAPI.showHighlight("customize");
   1.111 +    waitForElementToBeVisible(highlight, function checkPanelIsOpen() {
   1.112 +      isnot(PanelUI.panel.state, "closed", "Panel should have opened");
   1.113 +
   1.114 +      // Move the highlight outside which should close the app menu.
   1.115 +      gContentAPI.showHighlight("appMenu");
   1.116 +      waitForElementToBeVisible(highlight, function checkPanelIsClosed() {
   1.117 +        isnot(PanelUI.panel.state, "open",
   1.118 +              "Panel should have closed after the highlight moved elsewhere.");
   1.119 +        done();
   1.120 +      }, "Highlight should move to the appMenu button");
   1.121 +    }, "Highlight should be shown after showHighlight() for fixed panel items");
   1.122 +  },
   1.123 +  function test_highlight_customize_manual_open_close(done) {
   1.124 +    let highlight = document.getElementById("UITourHighlight");
   1.125 +    // Manually open the app menu then show a highlight there. The menu should remain open.
   1.126 +    let shownPromise = promisePanelShown(window);
   1.127 +    gContentAPI.showMenu("appMenu");
   1.128 +    shownPromise.then(() => {
   1.129 +      isnot(PanelUI.panel.state, "closed", "Panel should have opened");
   1.130 +      gContentAPI.showHighlight("customize");
   1.131 +
   1.132 +      waitForElementToBeVisible(highlight, function checkPanelIsStillOpen() {
   1.133 +        isnot(PanelUI.panel.state, "closed", "Panel should still be open");
   1.134 +
   1.135 +        // Move the highlight outside which shouldn't close the app menu since it was manually opened.
   1.136 +        gContentAPI.showHighlight("appMenu");
   1.137 +        waitForElementToBeVisible(highlight, function () {
   1.138 +          isnot(PanelUI.panel.state, "closed",
   1.139 +                "Panel should remain open since UITour didn't open it in the first place");
   1.140 +          gContentAPI.hideMenu("appMenu");
   1.141 +          done();
   1.142 +        }, "Highlight should move to the appMenu button");
   1.143 +      }, "Highlight should be shown after showHighlight() for fixed panel items");
   1.144 +    }).then(null, Components.utils.reportError);
   1.145 +  },
   1.146 +  function test_highlight_effect(done) {
   1.147 +    function waitForHighlightWithEffect(highlightEl, effect, next, error) {
   1.148 +      return waitForCondition(() => highlightEl.getAttribute("active") == effect,
   1.149 +                              next,
   1.150 +                              error);
   1.151 +    }
   1.152 +    function checkDefaultEffect() {
   1.153 +      is(highlight.getAttribute("active"), "none", "The default should be no effect");
   1.154 +
   1.155 +      gContentAPI.showHighlight("urlbar", "none");
   1.156 +      waitForHighlightWithEffect(highlight, "none", checkZoomEffect, "There should be no effect");
   1.157 +    }
   1.158 +    function checkZoomEffect() {
   1.159 +      gContentAPI.showHighlight("urlbar", "zoom");
   1.160 +      waitForHighlightWithEffect(highlight, "zoom", () => {
   1.161 +        let style = window.getComputedStyle(highlight);
   1.162 +        is(style.animationName, "uitour-zoom", "The animation-name should be uitour-zoom");
   1.163 +        checkSameEffectOnDifferentTarget();
   1.164 +      }, "There should be a zoom effect");
   1.165 +    }
   1.166 +    function checkSameEffectOnDifferentTarget() {
   1.167 +      gContentAPI.showHighlight("appMenu", "wobble");
   1.168 +      waitForHighlightWithEffect(highlight, "wobble", () => {
   1.169 +        highlight.addEventListener("animationstart", function onAnimationStart(aEvent) {
   1.170 +          highlight.removeEventListener("animationstart", onAnimationStart);
   1.171 +          ok(true, "Animation occurred again even though the effect was the same");
   1.172 +          checkRandomEffect();
   1.173 +        });
   1.174 +        gContentAPI.showHighlight("backForward", "wobble");
   1.175 +      }, "There should be a wobble effect");
   1.176 +    }
   1.177 +    function checkRandomEffect() {
   1.178 +      function waitForActiveHighlight(highlightEl, next, error) {
   1.179 +        return waitForCondition(() => highlightEl.hasAttribute("active"),
   1.180 +                                next,
   1.181 +                                error);
   1.182 +      }
   1.183 +
   1.184 +      gContentAPI.hideHighlight();
   1.185 +      gContentAPI.showHighlight("urlbar", "random");
   1.186 +      waitForActiveHighlight(highlight, () => {
   1.187 +        ok(highlight.hasAttribute("active"), "The highlight should be active");
   1.188 +        isnot(highlight.getAttribute("active"), "none", "A random effect other than none should have been chosen");
   1.189 +        isnot(highlight.getAttribute("active"), "random", "The random effect shouldn't be 'random'");
   1.190 +        isnot(UITour.highlightEffects.indexOf(highlight.getAttribute("active")), -1, "Check that a supported effect was randomly chosen");
   1.191 +        done();
   1.192 +      }, "There should be an active highlight with a random effect");
   1.193 +    }
   1.194 +
   1.195 +    let highlight = document.getElementById("UITourHighlight");
   1.196 +    is_element_hidden(highlight, "Highlight should initially be hidden");
   1.197 +
   1.198 +    gContentAPI.showHighlight("urlbar");
   1.199 +    waitForElementToBeVisible(highlight, checkDefaultEffect, "Highlight should be shown after showHighlight()");
   1.200 +  },
   1.201 +  function test_highlight_effect_unsupported(done) {
   1.202 +    function checkUnsupportedEffect() {
   1.203 +      is(highlight.getAttribute("active"), "none", "No effect should be used when an unsupported effect is requested");
   1.204 +      done();
   1.205 +    }
   1.206 +
   1.207 +    let highlight = document.getElementById("UITourHighlight");
   1.208 +    is_element_hidden(highlight, "Highlight should initially be hidden");
   1.209 +
   1.210 +    gContentAPI.showHighlight("urlbar", "__UNSUPPORTED__");
   1.211 +    waitForElementToBeVisible(highlight, checkUnsupportedEffect, "Highlight should be shown after showHighlight()");
   1.212 +  },
   1.213 +  function test_info_1(done) {
   1.214 +    let popup = document.getElementById("UITourTooltip");
   1.215 +    let title = document.getElementById("UITourTooltipTitle");
   1.216 +    let desc = document.getElementById("UITourTooltipDescription");
   1.217 +    let icon = document.getElementById("UITourTooltipIcon");
   1.218 +    let buttons = document.getElementById("UITourTooltipButtons");
   1.219 +
   1.220 +    popup.addEventListener("popupshown", function onPopupShown() {
   1.221 +      popup.removeEventListener("popupshown", onPopupShown);
   1.222 +      is(popup.popupBoxObject.anchorNode, document.getElementById("urlbar"), "Popup should be anchored to the urlbar");
   1.223 +      is(title.textContent, "test title", "Popup should have correct title");
   1.224 +      is(desc.textContent, "test text", "Popup should have correct description text");
   1.225 +      is(icon.src, "", "Popup should have no icon");
   1.226 +      is(buttons.hasChildNodes(), false, "Popup should have no buttons");
   1.227 +
   1.228 +      popup.addEventListener("popuphidden", function onPopupHidden() {
   1.229 +        popup.removeEventListener("popuphidden", onPopupHidden);
   1.230 +
   1.231 +        popup.addEventListener("popupshown", function onPopupShown() {
   1.232 +          popup.removeEventListener("popupshown", onPopupShown);
   1.233 +          done();
   1.234 +        });
   1.235 +
   1.236 +        gContentAPI.showInfo("urlbar", "test title", "test text");
   1.237 +
   1.238 +      });
   1.239 +      gContentAPI.hideInfo();
   1.240 +    });
   1.241 +
   1.242 +    gContentAPI.showInfo("urlbar", "test title", "test text");
   1.243 +  },
   1.244 +  function test_info_2(done) {
   1.245 +    let popup = document.getElementById("UITourTooltip");
   1.246 +    let title = document.getElementById("UITourTooltipTitle");
   1.247 +    let desc = document.getElementById("UITourTooltipDescription");
   1.248 +    let icon = document.getElementById("UITourTooltipIcon");
   1.249 +    let buttons = document.getElementById("UITourTooltipButtons");
   1.250 +
   1.251 +    popup.addEventListener("popupshown", function onPopupShown() {
   1.252 +      popup.removeEventListener("popupshown", onPopupShown);
   1.253 +      is(popup.popupBoxObject.anchorNode, document.getElementById("urlbar"), "Popup should be anchored to the urlbar");
   1.254 +      is(title.textContent, "urlbar title", "Popup should have correct title");
   1.255 +      is(desc.textContent, "urlbar text", "Popup should have correct description text");
   1.256 +      is(icon.src, "", "Popup should have no icon");
   1.257 +      is(buttons.hasChildNodes(), false, "Popup should have no buttons");
   1.258 +
   1.259 +      gContentAPI.showInfo("search", "search title", "search text");
   1.260 +      executeSoon(function() {
   1.261 +        is(popup.popupBoxObject.anchorNode, document.getElementById("searchbar"), "Popup should be anchored to the searchbar");
   1.262 +        is(title.textContent, "search title", "Popup should have correct title");
   1.263 +        is(desc.textContent, "search text", "Popup should have correct description text");
   1.264 +
   1.265 +        done();
   1.266 +      });
   1.267 +    });
   1.268 +
   1.269 +    gContentAPI.showInfo("urlbar", "urlbar title", "urlbar text");
   1.270 +  },
   1.271 +
   1.272 +  // Make sure this test is last in the file so the appMenu gets left open and done will confirm it got tore down.
   1.273 +  function cleanupMenus(done) {
   1.274 +    gContentAPI.showMenu("appMenu");
   1.275 +    done();
   1.276 +  },
   1.277 +];

mercurial