|
1 /* Any copyright is dedicated to the Public Domain. |
|
2 * http://creativecommons.org/publicdomain/zero/1.0/ */ |
|
3 |
|
4 "use strict"; |
|
5 |
|
6 let gTestTab; |
|
7 let gContentAPI; |
|
8 let gContentWindow; |
|
9 |
|
10 Components.utils.import("resource:///modules/UITour.jsm"); |
|
11 |
|
12 requestLongerTimeout(2); |
|
13 |
|
14 function test() { |
|
15 UITourTest(); |
|
16 } |
|
17 |
|
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"); |
|
25 |
|
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"); |
|
29 |
|
30 popup.addEventListener("popupshown", function onPopupShown() { |
|
31 popup.removeEventListener("popupshown", onPopupShown); |
|
32 |
|
33 is(title.textContent, "a title", "Popup should have correct title"); |
|
34 is(desc.textContent, "some text", "Popup should have correct description text"); |
|
35 |
|
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"); |
|
39 |
|
40 is(buttons.hasChildNodes(), false, "Popup should have no buttons"); |
|
41 |
|
42 done(); |
|
43 }); |
|
44 |
|
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"); |
|
52 |
|
53 popup.addEventListener("popupshown", function onPopupShown() { |
|
54 popup.removeEventListener("popupshown", onPopupShown); |
|
55 |
|
56 is(title.textContent, "another title", "Popup should have correct title"); |
|
57 is(desc.textContent, "moar text", "Popup should have correct description text"); |
|
58 |
|
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"); |
|
62 |
|
63 let buttons = document.getElementById("UITourTooltipButtons"); |
|
64 is(buttons.childElementCount, 2, "Popup should have two buttons"); |
|
65 |
|
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"); |
|
68 |
|
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"); |
|
71 |
|
72 popup.addEventListener("popuphidden", function onPopupHidden() { |
|
73 popup.removeEventListener("popuphidden", onPopupHidden); |
|
74 ok(true, "Popup should close automatically"); |
|
75 |
|
76 executeSoon(function() { |
|
77 is(gContentWindow.callbackResult, "button1", "Correct callback should have been called"); |
|
78 |
|
79 done(); |
|
80 }); |
|
81 }); |
|
82 |
|
83 EventUtils.synthesizeMouseAtCenter(buttons.childNodes[0], {}, window); |
|
84 }); |
|
85 |
|
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"); |
|
94 |
|
95 popup.addEventListener("popupshown", function onPopupShown() { |
|
96 popup.removeEventListener("popupshown", onPopupShown); |
|
97 |
|
98 is(title.textContent, "another title", "Popup should have correct title"); |
|
99 is(desc.textContent, "moar text", "Popup should have correct description text"); |
|
100 |
|
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"); |
|
104 |
|
105 let buttons = document.getElementById("UITourTooltipButtons"); |
|
106 is(buttons.childElementCount, 2, "Popup should have two buttons"); |
|
107 |
|
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"); |
|
110 |
|
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"); |
|
113 |
|
114 popup.addEventListener("popuphidden", function onPopupHidden() { |
|
115 popup.removeEventListener("popuphidden", onPopupHidden); |
|
116 ok(true, "Popup should close automatically"); |
|
117 |
|
118 executeSoon(function() { |
|
119 is(gContentWindow.callbackResult, "button2", "Correct callback should have been called"); |
|
120 |
|
121 done(); |
|
122 }); |
|
123 }); |
|
124 |
|
125 EventUtils.synthesizeMouseAtCenter(buttons.childNodes[1], {}, window); |
|
126 }); |
|
127 |
|
128 let buttons = gContentWindow.makeButtons(); |
|
129 gContentAPI.showInfo("urlbar", "another title", "moar text", "./image.png", buttons); |
|
130 }, |
|
131 |
|
132 function test_info_close_button(done) { |
|
133 let popup = document.getElementById("UITourTooltip"); |
|
134 let closeButton = document.getElementById("UITourTooltipClose"); |
|
135 |
|
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 }); |
|
144 |
|
145 let infoOptions = gContentWindow.makeInfoOptions(); |
|
146 gContentAPI.showInfo("urlbar", "Close me", "X marks the spot", null, null, infoOptions); |
|
147 }, |
|
148 |
|
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 }); |
|
161 |
|
162 let infoOptions = gContentWindow.makeInfoOptions(); |
|
163 gContentAPI.showInfo("appMenu", "I want to know when the target is clicked", "*click*", null, null, infoOptions); |
|
164 }, |
|
165 ]; |