browser/modules/test/browser_UITour3.js

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

     1 /* Any copyright is dedicated to the Public Domain.
     2  * http://creativecommons.org/publicdomain/zero/1.0/ */
     4 "use strict";
     6 let gTestTab;
     7 let gContentAPI;
     8 let gContentWindow;
    10 Components.utils.import("resource:///modules/UITour.jsm");
    12 requestLongerTimeout(2);
    14 function test() {
    15   UITourTest();
    16 }
    18 let tests = [
    19   function test_info_icon(done) {
    20     let popup = document.getElementById("UITourTooltip");
    21     let title = document.getElementById("UITourTooltipTitle");
    22     let desc = document.getElementById("UITourTooltipDescription");
    23     let icon = document.getElementById("UITourTooltipIcon");
    24     let buttons = document.getElementById("UITourTooltipButtons");
    26     // Disable the animation to prevent the mouse clicks from hitting the main
    27     // window during the transition instead of the buttons in the popup.
    28     popup.setAttribute("animate", "false");
    30     popup.addEventListener("popupshown", function onPopupShown() {
    31       popup.removeEventListener("popupshown", onPopupShown);
    33       is(title.textContent, "a title", "Popup should have correct title");
    34       is(desc.textContent, "some text", "Popup should have correct description text");
    36       let imageURL = getRootDirectory(gTestPath) + "image.png";
    37       imageURL = imageURL.replace("chrome://mochitests/content/", "https://example.com/");
    38       is(icon.src, imageURL,  "Popup should have correct icon shown");
    40       is(buttons.hasChildNodes(), false, "Popup should have no buttons");
    42       done();
    43     });
    45     gContentAPI.showInfo("urlbar", "a title", "some text", "image.png");
    46   },
    47   function test_info_buttons_1(done) {
    48     let popup = document.getElementById("UITourTooltip");
    49     let title = document.getElementById("UITourTooltipTitle");
    50     let desc = document.getElementById("UITourTooltipDescription");
    51     let icon = document.getElementById("UITourTooltipIcon");
    53     popup.addEventListener("popupshown", function onPopupShown() {
    54       popup.removeEventListener("popupshown", onPopupShown);
    56       is(title.textContent, "another title", "Popup should have correct title");
    57       is(desc.textContent, "moar text", "Popup should have correct description text");
    59       let imageURL = getRootDirectory(gTestPath) + "image.png";
    60       imageURL = imageURL.replace("chrome://mochitests/content/", "https://example.com/");
    61       is(icon.src, imageURL,  "Popup should have correct icon shown");
    63       let buttons = document.getElementById("UITourTooltipButtons");
    64       is(buttons.childElementCount, 2, "Popup should have two buttons");
    66       is(buttons.childNodes[0].getAttribute("label"), "Button 1", "First button should have correct label");
    67       is(buttons.childNodes[0].getAttribute("image"), "", "First button should have no image");
    69       is(buttons.childNodes[1].getAttribute("label"), "Button 2", "Second button should have correct label");
    70       is(buttons.childNodes[1].getAttribute("image"), imageURL, "Second button should have correct image");
    72       popup.addEventListener("popuphidden", function onPopupHidden() {
    73         popup.removeEventListener("popuphidden", onPopupHidden);
    74         ok(true, "Popup should close automatically");
    76         executeSoon(function() {
    77           is(gContentWindow.callbackResult, "button1", "Correct callback should have been called");
    79           done();
    80         });
    81       });
    83       EventUtils.synthesizeMouseAtCenter(buttons.childNodes[0], {}, window);
    84     });
    86     let buttons = gContentWindow.makeButtons();
    87     gContentAPI.showInfo("urlbar", "another title", "moar text", "./image.png", buttons);
    88   },
    89   function test_info_buttons_2(done) {
    90     let popup = document.getElementById("UITourTooltip");
    91     let title = document.getElementById("UITourTooltipTitle");
    92     let desc = document.getElementById("UITourTooltipDescription");
    93     let icon = document.getElementById("UITourTooltipIcon");
    95     popup.addEventListener("popupshown", function onPopupShown() {
    96       popup.removeEventListener("popupshown", onPopupShown);
    98       is(title.textContent, "another title", "Popup should have correct title");
    99       is(desc.textContent, "moar text", "Popup should have correct description text");
   101       let imageURL = getRootDirectory(gTestPath) + "image.png";
   102       imageURL = imageURL.replace("chrome://mochitests/content/", "https://example.com/");
   103       is(icon.src, imageURL,  "Popup should have correct icon shown");
   105       let buttons = document.getElementById("UITourTooltipButtons");
   106       is(buttons.childElementCount, 2, "Popup should have two buttons");
   108       is(buttons.childNodes[0].getAttribute("label"), "Button 1", "First button should have correct label");
   109       is(buttons.childNodes[0].getAttribute("image"), "", "First button should have no image");
   111       is(buttons.childNodes[1].getAttribute("label"), "Button 2", "Second button should have correct label");
   112       is(buttons.childNodes[1].getAttribute("image"), imageURL, "Second button should have correct image");
   114       popup.addEventListener("popuphidden", function onPopupHidden() {
   115         popup.removeEventListener("popuphidden", onPopupHidden);
   116         ok(true, "Popup should close automatically");
   118         executeSoon(function() {
   119           is(gContentWindow.callbackResult, "button2", "Correct callback should have been called");
   121           done();
   122         });
   123       });
   125       EventUtils.synthesizeMouseAtCenter(buttons.childNodes[1], {}, window);
   126     });
   128     let buttons = gContentWindow.makeButtons();
   129     gContentAPI.showInfo("urlbar", "another title", "moar text", "./image.png", buttons);
   130   },
   132   function test_info_close_button(done) {
   133     let popup = document.getElementById("UITourTooltip");
   134     let closeButton = document.getElementById("UITourTooltipClose");
   136     popup.addEventListener("popupshown", function onPopupShown() {
   137       popup.removeEventListener("popupshown", onPopupShown);
   138       EventUtils.synthesizeMouseAtCenter(closeButton, {}, window);
   139       executeSoon(function() {
   140         is(gContentWindow.callbackResult, "closeButton", "Close button callback called");
   141         done();
   142       });
   143     });
   145     let infoOptions = gContentWindow.makeInfoOptions();
   146     gContentAPI.showInfo("urlbar", "Close me", "X marks the spot", null, null, infoOptions);
   147   },
   149   function test_info_target_callback(done) {
   150     let popup = document.getElementById("UITourTooltip");
   151     popup.addEventListener("popupshown", function onPopupShown() {
   152       popup.removeEventListener("popupshown", onPopupShown);
   153       PanelUI.show().then(() => {
   154         is(gContentWindow.callbackResult, "target", "target callback called");
   155         is(gContentWindow.callbackData.target, "appMenu", "target callback was from the appMenu");
   156         is(gContentWindow.callbackData.type, "popupshown", "target callback was from the mousedown");
   157         popup.removeAttribute("animate");
   158         done();
   159       });
   160     });
   162     let infoOptions = gContentWindow.makeInfoOptions();
   163     gContentAPI.showInfo("appMenu", "I want to know when the target is clicked", "*click*", null, null, infoOptions);
   164   },
   165 ];

mercurial