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