browser_interaction-between-interfaces.js (13395B)
1 /* This Source Code Form is subject to the terms of the Mozilla Public 2 * License, v. 2.0. If a copy of the MPL was not distributed with this 3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 4 /* eslint-disable max-nested-callbacks */ 5 "use strict"; 6 7 add_task(async function test_change_in_popup() { 8 // This test assumes that the Web Developer preset is set by default, which is 9 // not the case on Nightly and custom builds. 10 PrefsPresets.changePreset( 11 "aboutprofiling", 12 "web-developer", 13 Services.profiler.GetFeatures() 14 ); 15 16 info( 17 "Test that changing settings in the popup changes settings in the devtools panel and about:profiling too." 18 ); 19 20 const browserWindow = window; 21 const browserDocument = document; 22 23 await makeSureProfilerPopupIsEnabled(); 24 await withDevToolsPanel( 25 "about:profiling", 26 async (devtoolsDocument, aboutProfilingDocument) => { 27 await withPopupOpen(browserWindow, async () => { 28 const presetsInPopup = browserDocument.getElementById( 29 "PanelUI-profiler-presets" 30 ); 31 32 const presetsInDevtools = await getNearestInputFromText( 33 devtoolsDocument, 34 "Settings" 35 ); 36 37 const webdev = await getNearestInputFromText( 38 aboutProfilingDocument, 39 "Web Developer" 40 ); 41 const graphics = await getNearestInputFromText( 42 aboutProfilingDocument, 43 "Graphics" 44 ); 45 const media = await getNearestInputFromText( 46 aboutProfilingDocument, 47 "Media" 48 ); 49 50 // Default situation 51 ok( 52 webdev.checked, 53 "By default the Web Developer preset is selected in the about:profiling interface." 54 ); 55 is( 56 presetsInDevtools.value, 57 "web-developer", 58 "The presets default to webdev mode in the devtools panel." 59 ); 60 is( 61 presetsInPopup.value, 62 "web-developer", 63 "The presets default to webdev mode in the popup." 64 ); 65 66 // Select "graphics" using the popup 67 ok(!graphics.checked, "The Graphics preset is not checked."); 68 69 presetsInPopup.menupopup.openPopup(); 70 presetsInPopup.menupopup.activateItem( 71 await getElementByLabel(presetsInPopup, "Graphics") 72 ); 73 74 await TestUtils.waitForCondition( 75 () => !webdev.checked, 76 "After selecting the preset in the popup, waiting until the Web Developer preset isn't selected anymore in the about:profiling interface." 77 ); 78 await TestUtils.waitForCondition( 79 () => graphics.checked, 80 "After selecting the preset in the popup, waiting until the Graphics preset is checked in the about:profiling interface." 81 ); 82 await TestUtils.waitForCondition( 83 () => presetsInDevtools.value === "graphics", 84 "After selecting the preset in the popup, waiting until the preset is changed to Graphics in the devtools panel too." 85 ); 86 await TestUtils.waitForCondition( 87 () => presetsInPopup.value === "graphics", 88 "After selecting the preset in the popup, waiting until the preset is changed to Graphics in the popup." 89 ); 90 91 // Select "firefox frontend" using the popup 92 ok(!media.checked, "The Media preset is not checked."); 93 94 presetsInPopup.menupopup.openPopup(); 95 presetsInPopup.menupopup.activateItem( 96 await getElementByLabel(presetsInPopup, "Media") 97 ); 98 99 await TestUtils.waitForCondition( 100 () => !graphics.checked, 101 "After selecting the preset in the popup, waiting until the Graphics preset is not checked anymore in the about:profiling interface." 102 ); 103 await TestUtils.waitForCondition( 104 () => media.checked, 105 "After selecting the preset in the popup, waiting until the Media preset is checked in the about:profiling interface." 106 ); 107 await TestUtils.waitForCondition( 108 () => presetsInDevtools.value === "media", 109 "After selecting the preset in the popup, waiting until the preset is changed to Firefox Front-end in the devtools panel." 110 ); 111 await TestUtils.waitForCondition( 112 () => presetsInPopup.value === "media", 113 "After selecting the preset in the popup, waiting until the preset is changed to Media in the popup." 114 ); 115 }); 116 } 117 ); 118 }); 119 120 // In the following tests we don't look at changes in the popup. Indeed because 121 // the popup rerenders each time it's open, we don't need to mirror it. 122 add_task(async function test_change_in_about_profiling() { 123 // This test assumes that the Web Developer preset is set by default, which is 124 // not the case on Nightly and custom builds, or after previous tests. 125 PrefsPresets.changePreset( 126 "aboutprofiling", 127 "web-developer", 128 Services.profiler.GetFeatures() 129 ); 130 131 info( 132 "Test that changing settings in about:profiling changes settings in the devtools panel too." 133 ); 134 135 await withDevToolsPanel( 136 "about:profiling", 137 async (devtoolsDocument, aboutProfilingDocument) => { 138 const presetsInDevtools = await getNearestInputFromText( 139 devtoolsDocument, 140 "Settings" 141 ); 142 143 const webdev = await getNearestInputFromText( 144 aboutProfilingDocument, 145 "Web Developer" 146 ); 147 const graphics = await getNearestInputFromText( 148 aboutProfilingDocument, 149 "Graphics" 150 ); 151 const media = await getNearestInputFromText( 152 aboutProfilingDocument, 153 "Media" 154 ); 155 const custom = await getNearestInputFromText( 156 aboutProfilingDocument, 157 "Custom" 158 ); 159 160 // Default values 161 ok( 162 webdev.checked, 163 "By default the Web Developer preset is selected in the about:profiling interface." 164 ); 165 is( 166 presetsInDevtools.value, 167 "web-developer", 168 "The presets default to webdev mode in the devtools panel." 169 ); 170 171 // Change the preset in about:profiling, check it changes also in the 172 // devtools panel. 173 ok(!graphics.checked, "The Graphics preset is not checked."); 174 graphics.click(); 175 ok( 176 graphics.checked, 177 "After clicking the input, the Graphics preset is now checked in about:profiling." 178 ); 179 await TestUtils.waitForCondition( 180 () => presetsInDevtools.value === "graphics", 181 "The preset was changed to Graphics in the devtools panel too." 182 ); 183 184 ok(!media.checked, "The Media preset is not checked."); 185 media.click(); 186 ok( 187 media.checked, 188 "After clicking the input, the Media preset is now checked in about:profiling." 189 ); 190 await TestUtils.waitForCondition( 191 () => presetsInDevtools.value === "media", 192 "The preset was changed to Media in the devtools panel too." 193 ); 194 195 // Now let's try to change some configuration! 196 info( 197 "Increase the interval by an arbitrary amount. The input range will " + 198 "scale that to the final value presented to the profiler." 199 ); 200 const intervalInput = await getNearestInputFromText( 201 aboutProfilingDocument, 202 "Sampling interval:" 203 ); 204 setReactFriendlyInputValue( 205 intervalInput, 206 Number(intervalInput.value) + 1 207 ); 208 ok( 209 custom.checked, 210 "After changing the interval, the Custom preset is now checked in about:profiling." 211 ); 212 await TestUtils.waitForCondition( 213 () => presetsInDevtools.value === "custom", 214 "The preset was changed to Custom in the devtools panel too." 215 ); 216 217 ok( 218 getDevtoolsCustomPresetContent(devtoolsDocument).includes( 219 "Interval: 2 ms" 220 ), 221 "The new interval should be in the custom preset description" 222 ); 223 224 // Let's check some thread as well 225 info("Change the threads values using the checkboxes"); 226 227 const styleThreadInput = await getNearestInputFromText( 228 aboutProfilingDocument, 229 "StyleThread" 230 ); 231 ok( 232 !styleThreadInput.checked, 233 "The StyleThread thread isn't checked by default." 234 ); 235 236 info("Click the StyleThread checkbox."); 237 styleThreadInput.click(); 238 239 // For some reason, it's not possible to directly match "StyleThread". 240 const threadsLine = ( 241 await getElementFromDocumentByText(devtoolsDocument, "Threads") 242 ).parentElement; 243 await TestUtils.waitForCondition( 244 () => threadsLine.textContent.includes("StyleThread"), 245 "Waiting that StyleThread is displayed in the devtools panel." 246 ); 247 ok( 248 getDevtoolsCustomPresetContent(devtoolsDocument).includes( 249 "StyleThread" 250 ), 251 "The StyleThread thread should be listed in the custom preset description" 252 ); 253 styleThreadInput.click(); 254 await TestUtils.waitForCondition( 255 () => !threadsLine.textContent.includes("StyleThread"), 256 "Waiting until the StyleThread disappears from the devtools panel." 257 ); 258 ok( 259 !getDevtoolsCustomPresetContent(devtoolsDocument).includes( 260 "StyleThread" 261 ), 262 "The StyleThread thread should no longer be listed in the custom preset description" 263 ); 264 265 info("Change the threads values using the input."); 266 const threadInput = await getNearestInputFromText( 267 aboutProfilingDocument, 268 "Add custom threads by name" 269 ); 270 271 function setThreadInputValue(newThreadValue) { 272 // Actually set the new value. 273 setReactFriendlyInputValue(threadInput, newThreadValue); 274 // The settings are actually changed on the blur event. 275 threadInput.dispatchEvent(new FocusEvent("blur")); 276 } 277 278 let newThreadValue = "GeckoMain,Foo"; 279 setThreadInputValue(newThreadValue); 280 await TestUtils.waitForCondition( 281 () => threadsLine.textContent.includes("Foo"), 282 "Waiting for Foo to be displayed in the devtools panel." 283 ); 284 285 // The code detecting changes to the thread list has a fast path 286 // to detect that the list of threads has changed if the 2 lists 287 // have different lengths. Exercise the slower code path by changing 288 // the list of threads to a list with the same number of threads. 289 info("Change the thread list again to a list of the same length"); 290 newThreadValue = "GeckoMain,Dummy"; 291 is( 292 threadInput.value.split(",").length, 293 newThreadValue.split(",").length, 294 "The new value should have the same count of threads as the old value, please double check the test code." 295 ); 296 setThreadInputValue(newThreadValue); 297 ok( 298 getDevtoolsCustomPresetContent(devtoolsDocument).includes( 299 "Threads: GeckoMain, Dummy\n" 300 ), 301 "Threads list should match the changed value" 302 ); 303 } 304 ); 305 }); 306 307 add_task(async function test_change_in_devtools_panel() { 308 // This test assumes that the Web Developer preset is set by default, which is 309 // not the case on Nightly and custom builds, or after previous tests. 310 PrefsPresets.changePreset( 311 "aboutprofiling", 312 "web-developer", 313 Services.profiler.GetFeatures() 314 ); 315 316 info( 317 "Test that changing settings in the devtools panel changes settings in about:profiling too." 318 ); 319 320 await withDevToolsPanel( 321 "about:profiling", 322 async (devtoolsDocument, aboutProfilingDocument) => { 323 const presetsInDevtools = await getNearestInputFromText( 324 devtoolsDocument, 325 "Settings" 326 ); 327 328 const webdev = await getNearestInputFromText( 329 aboutProfilingDocument, 330 "Web Developer" 331 ); 332 const graphics = await getNearestInputFromText( 333 aboutProfilingDocument, 334 "Graphics" 335 ); 336 const media = await getNearestInputFromText( 337 aboutProfilingDocument, 338 "Media" 339 ); 340 341 // Default values 342 ok( 343 webdev.checked, 344 "By default the Web Developer preset is selected in the about:profiling interface." 345 ); 346 is( 347 presetsInDevtools.value, 348 "web-developer", 349 "The presets default to webdev mode in the devtools panel." 350 ); 351 352 // Change the preset in devtools panel, check it changes also in 353 // about:profiling. 354 ok( 355 !graphics.checked, 356 "The Graphics preset is not checked in about:profiling." 357 ); 358 359 setReactFriendlyInputValue(presetsInDevtools, "graphics"); 360 await TestUtils.waitForCondition( 361 () => graphics.checked, 362 "After changing the preset in the devtools panel, the Graphics preset is now checked in about:profiling." 363 ); 364 await TestUtils.waitForCondition( 365 () => presetsInDevtools.value === "graphics", 366 "The preset was changed to Graphics in the devtools panel too." 367 ); 368 369 // Change another preset now 370 ok(!media.checked, "The Media preset is not checked."); 371 setReactFriendlyInputValue(presetsInDevtools, "media"); 372 await TestUtils.waitForCondition( 373 () => media.checked, 374 "After changing the preset in the devtools panel, the Media preset is now checked in about:profiling." 375 ); 376 await TestUtils.waitForCondition( 377 () => presetsInDevtools.value === "media", 378 "The preset was changed to Media in the devtools panel too." 379 ); 380 } 381 ); 382 });