browser/modules/test/browser_UITour3.js

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/browser/modules/test/browser_UITour3.js	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,165 @@
     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 +requestLongerTimeout(2);
    1.16 +
    1.17 +function test() {
    1.18 +  UITourTest();
    1.19 +}
    1.20 +
    1.21 +let tests = [
    1.22 +  function test_info_icon(done) {
    1.23 +    let popup = document.getElementById("UITourTooltip");
    1.24 +    let title = document.getElementById("UITourTooltipTitle");
    1.25 +    let desc = document.getElementById("UITourTooltipDescription");
    1.26 +    let icon = document.getElementById("UITourTooltipIcon");
    1.27 +    let buttons = document.getElementById("UITourTooltipButtons");
    1.28 +
    1.29 +    // Disable the animation to prevent the mouse clicks from hitting the main
    1.30 +    // window during the transition instead of the buttons in the popup.
    1.31 +    popup.setAttribute("animate", "false");
    1.32 +
    1.33 +    popup.addEventListener("popupshown", function onPopupShown() {
    1.34 +      popup.removeEventListener("popupshown", onPopupShown);
    1.35 +
    1.36 +      is(title.textContent, "a title", "Popup should have correct title");
    1.37 +      is(desc.textContent, "some text", "Popup should have correct description text");
    1.38 +
    1.39 +      let imageURL = getRootDirectory(gTestPath) + "image.png";
    1.40 +      imageURL = imageURL.replace("chrome://mochitests/content/", "https://example.com/");
    1.41 +      is(icon.src, imageURL,  "Popup should have correct icon shown");
    1.42 +
    1.43 +      is(buttons.hasChildNodes(), false, "Popup should have no buttons");
    1.44 +
    1.45 +      done();
    1.46 +    });
    1.47 +
    1.48 +    gContentAPI.showInfo("urlbar", "a title", "some text", "image.png");
    1.49 +  },
    1.50 +  function test_info_buttons_1(done) {
    1.51 +    let popup = document.getElementById("UITourTooltip");
    1.52 +    let title = document.getElementById("UITourTooltipTitle");
    1.53 +    let desc = document.getElementById("UITourTooltipDescription");
    1.54 +    let icon = document.getElementById("UITourTooltipIcon");
    1.55 +
    1.56 +    popup.addEventListener("popupshown", function onPopupShown() {
    1.57 +      popup.removeEventListener("popupshown", onPopupShown);
    1.58 +
    1.59 +      is(title.textContent, "another title", "Popup should have correct title");
    1.60 +      is(desc.textContent, "moar text", "Popup should have correct description text");
    1.61 +
    1.62 +      let imageURL = getRootDirectory(gTestPath) + "image.png";
    1.63 +      imageURL = imageURL.replace("chrome://mochitests/content/", "https://example.com/");
    1.64 +      is(icon.src, imageURL,  "Popup should have correct icon shown");
    1.65 +
    1.66 +      let buttons = document.getElementById("UITourTooltipButtons");
    1.67 +      is(buttons.childElementCount, 2, "Popup should have two buttons");
    1.68 +
    1.69 +      is(buttons.childNodes[0].getAttribute("label"), "Button 1", "First button should have correct label");
    1.70 +      is(buttons.childNodes[0].getAttribute("image"), "", "First button should have no image");
    1.71 +
    1.72 +      is(buttons.childNodes[1].getAttribute("label"), "Button 2", "Second button should have correct label");
    1.73 +      is(buttons.childNodes[1].getAttribute("image"), imageURL, "Second button should have correct image");
    1.74 +
    1.75 +      popup.addEventListener("popuphidden", function onPopupHidden() {
    1.76 +        popup.removeEventListener("popuphidden", onPopupHidden);
    1.77 +        ok(true, "Popup should close automatically");
    1.78 +
    1.79 +        executeSoon(function() {
    1.80 +          is(gContentWindow.callbackResult, "button1", "Correct callback should have been called");
    1.81 +
    1.82 +          done();
    1.83 +        });
    1.84 +      });
    1.85 +
    1.86 +      EventUtils.synthesizeMouseAtCenter(buttons.childNodes[0], {}, window);
    1.87 +    });
    1.88 +
    1.89 +    let buttons = gContentWindow.makeButtons();
    1.90 +    gContentAPI.showInfo("urlbar", "another title", "moar text", "./image.png", buttons);
    1.91 +  },
    1.92 +  function test_info_buttons_2(done) {
    1.93 +    let popup = document.getElementById("UITourTooltip");
    1.94 +    let title = document.getElementById("UITourTooltipTitle");
    1.95 +    let desc = document.getElementById("UITourTooltipDescription");
    1.96 +    let icon = document.getElementById("UITourTooltipIcon");
    1.97 +
    1.98 +    popup.addEventListener("popupshown", function onPopupShown() {
    1.99 +      popup.removeEventListener("popupshown", onPopupShown);
   1.100 +
   1.101 +      is(title.textContent, "another title", "Popup should have correct title");
   1.102 +      is(desc.textContent, "moar text", "Popup should have correct description text");
   1.103 +
   1.104 +      let imageURL = getRootDirectory(gTestPath) + "image.png";
   1.105 +      imageURL = imageURL.replace("chrome://mochitests/content/", "https://example.com/");
   1.106 +      is(icon.src, imageURL,  "Popup should have correct icon shown");
   1.107 +
   1.108 +      let buttons = document.getElementById("UITourTooltipButtons");
   1.109 +      is(buttons.childElementCount, 2, "Popup should have two buttons");
   1.110 +
   1.111 +      is(buttons.childNodes[0].getAttribute("label"), "Button 1", "First button should have correct label");
   1.112 +      is(buttons.childNodes[0].getAttribute("image"), "", "First button should have no image");
   1.113 +
   1.114 +      is(buttons.childNodes[1].getAttribute("label"), "Button 2", "Second button should have correct label");
   1.115 +      is(buttons.childNodes[1].getAttribute("image"), imageURL, "Second button should have correct image");
   1.116 +
   1.117 +      popup.addEventListener("popuphidden", function onPopupHidden() {
   1.118 +        popup.removeEventListener("popuphidden", onPopupHidden);
   1.119 +        ok(true, "Popup should close automatically");
   1.120 +
   1.121 +        executeSoon(function() {
   1.122 +          is(gContentWindow.callbackResult, "button2", "Correct callback should have been called");
   1.123 +
   1.124 +          done();
   1.125 +        });
   1.126 +      });
   1.127 +
   1.128 +      EventUtils.synthesizeMouseAtCenter(buttons.childNodes[1], {}, window);
   1.129 +    });
   1.130 +
   1.131 +    let buttons = gContentWindow.makeButtons();
   1.132 +    gContentAPI.showInfo("urlbar", "another title", "moar text", "./image.png", buttons);
   1.133 +  },
   1.134 +
   1.135 +  function test_info_close_button(done) {
   1.136 +    let popup = document.getElementById("UITourTooltip");
   1.137 +    let closeButton = document.getElementById("UITourTooltipClose");
   1.138 +
   1.139 +    popup.addEventListener("popupshown", function onPopupShown() {
   1.140 +      popup.removeEventListener("popupshown", onPopupShown);
   1.141 +      EventUtils.synthesizeMouseAtCenter(closeButton, {}, window);
   1.142 +      executeSoon(function() {
   1.143 +        is(gContentWindow.callbackResult, "closeButton", "Close button callback called");
   1.144 +        done();
   1.145 +      });
   1.146 +    });
   1.147 +
   1.148 +    let infoOptions = gContentWindow.makeInfoOptions();
   1.149 +    gContentAPI.showInfo("urlbar", "Close me", "X marks the spot", null, null, infoOptions);
   1.150 +  },
   1.151 +
   1.152 +  function test_info_target_callback(done) {
   1.153 +    let popup = document.getElementById("UITourTooltip");
   1.154 +    popup.addEventListener("popupshown", function onPopupShown() {
   1.155 +      popup.removeEventListener("popupshown", onPopupShown);
   1.156 +      PanelUI.show().then(() => {
   1.157 +        is(gContentWindow.callbackResult, "target", "target callback called");
   1.158 +        is(gContentWindow.callbackData.target, "appMenu", "target callback was from the appMenu");
   1.159 +        is(gContentWindow.callbackData.type, "popupshown", "target callback was from the mousedown");
   1.160 +        popup.removeAttribute("animate");
   1.161 +        done();
   1.162 +      });
   1.163 +    });
   1.164 +
   1.165 +    let infoOptions = gContentWindow.makeInfoOptions();
   1.166 +    gContentAPI.showInfo("appMenu", "I want to know when the target is clicked", "*click*", null, null, infoOptions);
   1.167 +  },
   1.168 +];

mercurial