browser_UITour3.js (8715B)
1 "use strict"; 2 3 const { CustomizableUITestUtils } = ChromeUtils.importESModule( 4 "resource://testing-common/CustomizableUITestUtils.sys.mjs" 5 ); 6 let gCUITestUtils = new CustomizableUITestUtils(window); 7 8 var gTestTab; 9 var gContentAPI; 10 11 requestLongerTimeout(2); 12 13 add_task(setup_UITourTest); 14 15 add_UITour_task(async function test_info_icon() { 16 let popup = document.getElementById("UITourTooltip"); 17 let title = document.getElementById("UITourTooltipTitle"); 18 let desc = document.getElementById("UITourTooltipDescription"); 19 let icon = document.getElementById("UITourTooltipIcon"); 20 let buttons = document.getElementById("UITourTooltipButtons"); 21 22 // Disable the animation to prevent the mouse clicks from hitting the main 23 // window during the transition instead of the buttons in the popup. 24 popup.setAttribute("animate", "false"); 25 26 await showInfoPromise("urlbar", "a title", "some text", "image.png"); 27 28 is(title.textContent, "a title", "Popup should have correct title"); 29 is( 30 desc.textContent, 31 "some text", 32 "Popup should have correct description text" 33 ); 34 35 let imageURL = getRootDirectory(gTestPath) + "image.png"; 36 imageURL = imageURL.replace( 37 "chrome://mochitests/content/", 38 "https://example.org/" 39 ); 40 is(icon.src, imageURL, "Popup should have correct icon shown"); 41 42 is(buttons.hasChildNodes(), false, "Popup should have no buttons"); 43 }); 44 45 add_UITour_task(async function test_info_buttons_1() { 46 let popup = document.getElementById("UITourTooltip"); 47 let title = document.getElementById("UITourTooltipTitle"); 48 let desc = document.getElementById("UITourTooltipDescription"); 49 let icon = document.getElementById("UITourTooltipIcon"); 50 51 await showInfoPromise( 52 "urlbar", 53 "another title", 54 "moar text", 55 "./image.png", 56 "makeButtons" 57 ); 58 59 is(title.textContent, "another title", "Popup should have correct title"); 60 is( 61 desc.textContent, 62 "moar text", 63 "Popup should have correct description text" 64 ); 65 66 let imageURL = getRootDirectory(gTestPath) + "image.png"; 67 imageURL = imageURL.replace( 68 "chrome://mochitests/content/", 69 "https://example.org/" 70 ); 71 is(icon.src, imageURL, "Popup should have correct icon shown"); 72 73 let buttons = document.getElementById("UITourTooltipButtons"); 74 is(buttons.childElementCount, 4, "Popup should have four buttons"); 75 76 is(buttons.children[0].nodeName, "label", "Text label should be a <label>"); 77 is( 78 buttons.children[0].getAttribute("value"), 79 "Regular text", 80 "Text label should have correct value" 81 ); 82 is( 83 buttons.children[0].getAttribute("image"), 84 null, 85 "Text should have no image" 86 ); 87 is(buttons.children[0].className, "", "Text should have no class"); 88 89 is(buttons.children[1].nodeName, "button", "Link should be a <button>"); 90 is( 91 buttons.children[1].getAttribute("label"), 92 "Link", 93 "Link should have correct label" 94 ); 95 is( 96 buttons.children[1].getAttribute("image"), 97 null, 98 "Link should have no image" 99 ); 100 is(buttons.children[1].className, "button-link", "Check link class"); 101 102 is(buttons.children[2].nodeName, "button", "Button 1 should be a <button>"); 103 is( 104 buttons.children[2].getAttribute("label"), 105 "Button 1", 106 "First button should have correct label" 107 ); 108 is( 109 buttons.children[2].getAttribute("image"), 110 null, 111 "First button should have no image" 112 ); 113 is(buttons.children[2].className, "", "Button 1 should have no class"); 114 115 is(buttons.children[3].nodeName, "button", "Button 2 should be a <button>"); 116 is( 117 buttons.children[3].getAttribute("label"), 118 "Button 2", 119 "Second button should have correct label" 120 ); 121 is( 122 buttons.children[3].getAttribute("image"), 123 imageURL, 124 "Second button should have correct image" 125 ); 126 is(buttons.children[3].className, "button-primary", "Check button 2 class"); 127 128 let promiseHidden = promisePanelElementHidden(window, popup); 129 EventUtils.synthesizeMouseAtCenter(buttons.children[2], {}, window); 130 await promiseHidden; 131 132 ok(true, "Popup should close automatically"); 133 134 let returnValue = await waitForCallbackResultPromise(); 135 is(returnValue.result, "button1", "Correct callback should have been called"); 136 }); 137 138 add_UITour_task(async function test_info_buttons_2() { 139 let popup = document.getElementById("UITourTooltip"); 140 let title = document.getElementById("UITourTooltipTitle"); 141 let desc = document.getElementById("UITourTooltipDescription"); 142 let icon = document.getElementById("UITourTooltipIcon"); 143 144 await showInfoPromise( 145 "urlbar", 146 "another title", 147 "moar text", 148 "./image.png", 149 "makeButtons" 150 ); 151 152 is(title.textContent, "another title", "Popup should have correct title"); 153 is( 154 desc.textContent, 155 "moar text", 156 "Popup should have correct description text" 157 ); 158 159 let imageURL = getRootDirectory(gTestPath) + "image.png"; 160 imageURL = imageURL.replace( 161 "chrome://mochitests/content/", 162 "https://example.org/" 163 ); 164 is(icon.src, imageURL, "Popup should have correct icon shown"); 165 166 let buttons = document.getElementById("UITourTooltipButtons"); 167 is(buttons.childElementCount, 4, "Popup should have four buttons"); 168 169 is( 170 buttons.children[1].getAttribute("label"), 171 "Link", 172 "Link should have correct label" 173 ); 174 is( 175 buttons.children[1].getAttribute("image"), 176 null, 177 "Link should have no image" 178 ); 179 ok( 180 buttons.children[1].classList.contains("button-link"), 181 "Link should have button-link class" 182 ); 183 184 is( 185 buttons.children[2].getAttribute("label"), 186 "Button 1", 187 "First button should have correct label" 188 ); 189 is( 190 buttons.children[2].getAttribute("image"), 191 null, 192 "First button should have no image" 193 ); 194 195 is( 196 buttons.children[3].getAttribute("label"), 197 "Button 2", 198 "Second button should have correct label" 199 ); 200 is( 201 buttons.children[3].getAttribute("image"), 202 imageURL, 203 "Second button should have correct image" 204 ); 205 206 let promiseHidden = promisePanelElementHidden(window, popup); 207 EventUtils.synthesizeMouseAtCenter(buttons.children[3], {}, window); 208 await promiseHidden; 209 210 ok(true, "Popup should close automatically"); 211 212 let returnValue = await waitForCallbackResultPromise(); 213 214 is(returnValue.result, "button2", "Correct callback should have been called"); 215 }); 216 217 add_UITour_task(async function test_info_close_button() { 218 let closeButton = document.getElementById("UITourTooltipClose"); 219 220 await showInfoPromise( 221 "urlbar", 222 "Close me", 223 "X marks the spot", 224 null, 225 null, 226 "makeInfoOptions" 227 ); 228 229 EventUtils.synthesizeMouseAtCenter(closeButton, {}, window); 230 231 let returnValue = await waitForCallbackResultPromise(); 232 233 is(returnValue.result, "closeButton", "Close button callback called"); 234 }); 235 236 add_UITour_task(async function test_info_target_callback() { 237 let popup = document.getElementById("UITourTooltip"); 238 239 await showInfoPromise( 240 "appMenu", 241 "I want to know when the target is clicked", 242 "*click*", 243 null, 244 null, 245 "makeInfoOptions" 246 ); 247 248 await gCUITestUtils.openMainMenu(); 249 250 let returnValue = await waitForCallbackResultPromise(); 251 252 is(returnValue.result, "target", "target callback called"); 253 is( 254 returnValue.data.target, 255 "appMenu", 256 "target callback was from the appMenu" 257 ); 258 is( 259 returnValue.data.type, 260 "popupshown", 261 "target callback was from the mousedown" 262 ); 263 264 // Cleanup. 265 await hideInfoPromise(); 266 267 popup.removeAttribute("animate"); 268 }); 269 270 add_UITour_task(async function test_getConfiguration_selectedSearchEngine() { 271 let engine = await Services.search.getDefault(); 272 let data = await getConfigurationPromise("selectedSearchEngine"); 273 is(data.searchEngineIdentifier, engine.id, "Correct engine identifier"); 274 }); 275 276 add_UITour_task(async function test_setSearchTerm() { 277 // Place the search bar in the navigation toolbar temporarily. 278 let searchbar = await gCUITestUtils.addSearchBar(); 279 280 const TERM = "UITour Search Term"; 281 await gContentAPI.setSearchTerm(TERM); 282 283 // The UITour gets to the searchbar element through a promise, so the value setting 284 // only happens after a tick. 285 await waitForConditionPromise( 286 () => searchbar.value == TERM, 287 "Correct term set" 288 ); 289 290 gCUITestUtils.removeSearchBar(); 291 }); 292 293 add_UITour_task(async function test_clearSearchTerm() { 294 // Place the search bar in the navigation toolbar temporarily. 295 let searchbar = await gCUITestUtils.addSearchBar(); 296 297 await gContentAPI.setSearchTerm(""); 298 299 // The UITour gets to the searchbar element through a promise, so the value setting 300 // only happens after a tick. 301 await waitForConditionPromise( 302 () => searchbar.value == "", 303 "Search term cleared" 304 ); 305 306 gCUITestUtils.removeSearchBar(); 307 });