michael@0: /* Any copyright is dedicated to the Public Domain. michael@0: * http://creativecommons.org/publicdomain/zero/1.0/ */ michael@0: michael@0: "use strict"; michael@0: michael@0: let gTestTab; michael@0: let gContentAPI; michael@0: let gContentWindow; michael@0: michael@0: Components.utils.import("resource:///modules/UITour.jsm"); michael@0: michael@0: requestLongerTimeout(2); michael@0: michael@0: function test() { michael@0: UITourTest(); michael@0: } michael@0: michael@0: let tests = [ michael@0: function test_info_icon(done) { michael@0: let popup = document.getElementById("UITourTooltip"); michael@0: let title = document.getElementById("UITourTooltipTitle"); michael@0: let desc = document.getElementById("UITourTooltipDescription"); michael@0: let icon = document.getElementById("UITourTooltipIcon"); michael@0: let buttons = document.getElementById("UITourTooltipButtons"); michael@0: michael@0: // Disable the animation to prevent the mouse clicks from hitting the main michael@0: // window during the transition instead of the buttons in the popup. michael@0: popup.setAttribute("animate", "false"); michael@0: michael@0: popup.addEventListener("popupshown", function onPopupShown() { michael@0: popup.removeEventListener("popupshown", onPopupShown); michael@0: michael@0: is(title.textContent, "a title", "Popup should have correct title"); michael@0: is(desc.textContent, "some text", "Popup should have correct description text"); michael@0: michael@0: let imageURL = getRootDirectory(gTestPath) + "image.png"; michael@0: imageURL = imageURL.replace("chrome://mochitests/content/", "https://example.com/"); michael@0: is(icon.src, imageURL, "Popup should have correct icon shown"); michael@0: michael@0: is(buttons.hasChildNodes(), false, "Popup should have no buttons"); michael@0: michael@0: done(); michael@0: }); michael@0: michael@0: gContentAPI.showInfo("urlbar", "a title", "some text", "image.png"); michael@0: }, michael@0: function test_info_buttons_1(done) { michael@0: let popup = document.getElementById("UITourTooltip"); michael@0: let title = document.getElementById("UITourTooltipTitle"); michael@0: let desc = document.getElementById("UITourTooltipDescription"); michael@0: let icon = document.getElementById("UITourTooltipIcon"); michael@0: michael@0: popup.addEventListener("popupshown", function onPopupShown() { michael@0: popup.removeEventListener("popupshown", onPopupShown); michael@0: michael@0: is(title.textContent, "another title", "Popup should have correct title"); michael@0: is(desc.textContent, "moar text", "Popup should have correct description text"); michael@0: michael@0: let imageURL = getRootDirectory(gTestPath) + "image.png"; michael@0: imageURL = imageURL.replace("chrome://mochitests/content/", "https://example.com/"); michael@0: is(icon.src, imageURL, "Popup should have correct icon shown"); michael@0: michael@0: let buttons = document.getElementById("UITourTooltipButtons"); michael@0: is(buttons.childElementCount, 2, "Popup should have two buttons"); michael@0: michael@0: is(buttons.childNodes[0].getAttribute("label"), "Button 1", "First button should have correct label"); michael@0: is(buttons.childNodes[0].getAttribute("image"), "", "First button should have no image"); michael@0: michael@0: is(buttons.childNodes[1].getAttribute("label"), "Button 2", "Second button should have correct label"); michael@0: is(buttons.childNodes[1].getAttribute("image"), imageURL, "Second button should have correct image"); michael@0: michael@0: popup.addEventListener("popuphidden", function onPopupHidden() { michael@0: popup.removeEventListener("popuphidden", onPopupHidden); michael@0: ok(true, "Popup should close automatically"); michael@0: michael@0: executeSoon(function() { michael@0: is(gContentWindow.callbackResult, "button1", "Correct callback should have been called"); michael@0: michael@0: done(); michael@0: }); michael@0: }); michael@0: michael@0: EventUtils.synthesizeMouseAtCenter(buttons.childNodes[0], {}, window); michael@0: }); michael@0: michael@0: let buttons = gContentWindow.makeButtons(); michael@0: gContentAPI.showInfo("urlbar", "another title", "moar text", "./image.png", buttons); michael@0: }, michael@0: function test_info_buttons_2(done) { michael@0: let popup = document.getElementById("UITourTooltip"); michael@0: let title = document.getElementById("UITourTooltipTitle"); michael@0: let desc = document.getElementById("UITourTooltipDescription"); michael@0: let icon = document.getElementById("UITourTooltipIcon"); michael@0: michael@0: popup.addEventListener("popupshown", function onPopupShown() { michael@0: popup.removeEventListener("popupshown", onPopupShown); michael@0: michael@0: is(title.textContent, "another title", "Popup should have correct title"); michael@0: is(desc.textContent, "moar text", "Popup should have correct description text"); michael@0: michael@0: let imageURL = getRootDirectory(gTestPath) + "image.png"; michael@0: imageURL = imageURL.replace("chrome://mochitests/content/", "https://example.com/"); michael@0: is(icon.src, imageURL, "Popup should have correct icon shown"); michael@0: michael@0: let buttons = document.getElementById("UITourTooltipButtons"); michael@0: is(buttons.childElementCount, 2, "Popup should have two buttons"); michael@0: michael@0: is(buttons.childNodes[0].getAttribute("label"), "Button 1", "First button should have correct label"); michael@0: is(buttons.childNodes[0].getAttribute("image"), "", "First button should have no image"); michael@0: michael@0: is(buttons.childNodes[1].getAttribute("label"), "Button 2", "Second button should have correct label"); michael@0: is(buttons.childNodes[1].getAttribute("image"), imageURL, "Second button should have correct image"); michael@0: michael@0: popup.addEventListener("popuphidden", function onPopupHidden() { michael@0: popup.removeEventListener("popuphidden", onPopupHidden); michael@0: ok(true, "Popup should close automatically"); michael@0: michael@0: executeSoon(function() { michael@0: is(gContentWindow.callbackResult, "button2", "Correct callback should have been called"); michael@0: michael@0: done(); michael@0: }); michael@0: }); michael@0: michael@0: EventUtils.synthesizeMouseAtCenter(buttons.childNodes[1], {}, window); michael@0: }); michael@0: michael@0: let buttons = gContentWindow.makeButtons(); michael@0: gContentAPI.showInfo("urlbar", "another title", "moar text", "./image.png", buttons); michael@0: }, michael@0: michael@0: function test_info_close_button(done) { michael@0: let popup = document.getElementById("UITourTooltip"); michael@0: let closeButton = document.getElementById("UITourTooltipClose"); michael@0: michael@0: popup.addEventListener("popupshown", function onPopupShown() { michael@0: popup.removeEventListener("popupshown", onPopupShown); michael@0: EventUtils.synthesizeMouseAtCenter(closeButton, {}, window); michael@0: executeSoon(function() { michael@0: is(gContentWindow.callbackResult, "closeButton", "Close button callback called"); michael@0: done(); michael@0: }); michael@0: }); michael@0: michael@0: let infoOptions = gContentWindow.makeInfoOptions(); michael@0: gContentAPI.showInfo("urlbar", "Close me", "X marks the spot", null, null, infoOptions); michael@0: }, michael@0: michael@0: function test_info_target_callback(done) { michael@0: let popup = document.getElementById("UITourTooltip"); michael@0: popup.addEventListener("popupshown", function onPopupShown() { michael@0: popup.removeEventListener("popupshown", onPopupShown); michael@0: PanelUI.show().then(() => { michael@0: is(gContentWindow.callbackResult, "target", "target callback called"); michael@0: is(gContentWindow.callbackData.target, "appMenu", "target callback was from the appMenu"); michael@0: is(gContentWindow.callbackData.type, "popupshown", "target callback was from the mousedown"); michael@0: popup.removeAttribute("animate"); michael@0: done(); michael@0: }); michael@0: }); michael@0: michael@0: let infoOptions = gContentWindow.makeInfoOptions(); michael@0: gContentAPI.showInfo("appMenu", "I want to know when the target is clicked", "*click*", null, null, infoOptions); michael@0: }, michael@0: ];