browser_aboutprofiling-threads-behavior.js (4014B)
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 "use strict"; 5 6 add_task(async function test() { 7 info( 8 "Test the behavior of thread toggling and the text summary works as expected." 9 ); 10 11 // This test assumes that the Web Developer preset is set by default, which is 12 // not the case on Nightly and custom builds. 13 PrefsPresets.changePreset( 14 "aboutprofiling", 15 "web-developer", 16 Services.profiler.GetFeatures() 17 ); 18 19 await withAboutProfiling(async document => { 20 const threadTextEl = await getNearestInputFromText( 21 document, 22 "Add custom threads by name:" 23 ); 24 25 is( 26 getActiveConfiguration().threads.join(","), 27 "GeckoMain,Compositor,Renderer,DOM Worker", 28 "The threads starts out with the default" 29 ); 30 is( 31 threadTextEl.value, 32 "GeckoMain,Compositor,Renderer,DOM Worker", 33 "The threads starts out with the default in the thread text input" 34 ); 35 36 await clickThreadCheckbox(document, "Compositor", "Toggle off"); 37 38 is( 39 getActiveConfiguration().threads.join(","), 40 "GeckoMain,Renderer,DOM Worker", 41 "The threads have been updated" 42 ); 43 is( 44 threadTextEl.value, 45 "GeckoMain,Renderer,DOM Worker", 46 "The threads have been updated in the thread text input" 47 ); 48 49 await clickThreadCheckbox(document, "DNS Resolver", "Toggle on"); 50 51 is( 52 getActiveConfiguration().threads.join(","), 53 "GeckoMain,Renderer,DOM Worker,DNS Resolver", 54 "Another thread was added" 55 ); 56 is( 57 threadTextEl.value, 58 "GeckoMain,Renderer,DOM Worker,DNS Resolver", 59 "Another thread was in the thread text input" 60 ); 61 62 const styleThreadCheckbox = await getNearestInputFromText( 63 document, 64 "StyleThread" 65 ); 66 ok(!styleThreadCheckbox.checked, "The style thread is not checked."); 67 68 // Set the input box directly 69 setReactFriendlyInputValue( 70 threadTextEl, 71 "GeckoMain,DOM Worker,DNS Resolver,StyleThread" 72 ); 73 threadTextEl.dispatchEvent(new Event("blur", { bubbles: true })); 74 75 ok(styleThreadCheckbox.checked, "The style thread is now checked."); 76 is( 77 getActiveConfiguration().threads.join(","), 78 "GeckoMain,DOM Worker,DNS Resolver,StyleThread", 79 "Another thread was added" 80 ); 81 is( 82 threadTextEl.value, 83 "GeckoMain,DOM Worker,DNS Resolver,StyleThread", 84 "Another thread was in the thread text input" 85 ); 86 87 // The all threads checkbox has nested text elements, so it's not easy to select 88 // by its label value. Select it by ID. 89 const allThreadsCheckbox = document.querySelector( 90 "#perf-settings-thread-checkbox-all-threads" 91 ); 92 info(`Turning on "All Threads" by clicking it."`); 93 allThreadsCheckbox.click(); 94 95 is( 96 getActiveConfiguration().threads.join(","), 97 "GeckoMain,DOM Worker,DNS Resolver,StyleThread,*", 98 "Asterisk was added" 99 ); 100 is( 101 threadTextEl.value, 102 "GeckoMain,DOM Worker,DNS Resolver,StyleThread,*", 103 "Asterisk was in the thread text input" 104 ); 105 106 is(styleThreadCheckbox.disabled, true, "The Style Thread is now disabled."); 107 108 // Remove the asterisk 109 setReactFriendlyInputValue( 110 threadTextEl, 111 "GeckoMain,DOM Worker,DNS Resolver,StyleThread" 112 ); 113 threadTextEl.dispatchEvent(new Event("blur", { bubbles: true })); 114 115 ok(!allThreadsCheckbox.checked, "The all threads checkbox is not checked."); 116 is(styleThreadCheckbox.disabled, false, "The Style Thread is now enabled."); 117 }); 118 }); 119 120 /** 121 * @param {Document} document 122 * @param {string} threadName 123 * @param {string} action - This is the intent of the click. 124 */ 125 async function clickThreadCheckbox(document, threadName, action) { 126 info(`${action} "${threadName}" by clicking it.`); 127 const checkbox = await getNearestInputFromText(document, threadName); 128 checkbox.click(); 129 }