browser_popup-profiler-states.js (2668B)
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 5 "use strict"; 6 7 add_task(async function test() { 8 info( 9 "Test the states of the profiler button, e.g. inactive, active, and capturing." 10 ); 11 await setProfilerFrontendUrl( 12 "https://example.com", 13 "/browser/devtools/client/performance-new/test/browser/fake-frontend.html" 14 ); 15 await makeSureProfilerPopupIsEnabled(); 16 17 const { toggleProfiler, captureProfile } = ChromeUtils.importESModule( 18 "resource://devtools/client/performance-new/shared/background.sys.mjs" 19 ); 20 21 const button = document.getElementById("profiler-button-button"); 22 if (!button) { 23 throw new Error("Could not find the profiler button."); 24 } 25 26 info("The profiler button starts out inactive"); 27 await checkButtonState(button, { 28 tooltip: "Record a performance profile", 29 active: false, 30 paused: false, 31 }); 32 33 info("Toggling the profiler turns on the active state"); 34 toggleProfiler("aboutprofiling"); 35 await checkButtonState(button, { 36 tooltip: "The profiler is recording a profile", 37 active: true, 38 paused: false, 39 }); 40 41 info("Capturing a profile makes the button paused"); 42 captureProfile("aboutprofiling"); 43 44 // The state "capturing" can be very quick, so waiting for the tooltip 45 // translation is racy. Let's only check the button's states. 46 await checkButtonState(button, { 47 active: false, 48 paused: true, 49 }); 50 51 await waitUntil( 52 () => !button.classList.contains("profiler-paused"), 53 "Waiting until the profiler is no longer paused" 54 ); 55 56 await checkButtonState(button, { 57 tooltip: "Record a performance profile", 58 active: false, 59 paused: false, 60 }); 61 62 await checkTabLoadedProfile({ 63 initialTitle: "Waiting on the profile", 64 successTitle: "Profile received", 65 errorTitle: "Error", 66 }); 67 }); 68 69 /** 70 * This check dives into the implementation details of the button, mainly 71 * because it's hard to provide a user-focused interpretation of button 72 * stylings. 73 */ 74 async function checkButtonState(button, { tooltip, active, paused }) { 75 is( 76 button.classList.contains("profiler-active"), 77 active, 78 `The expected profiler button active state is: ${active}` 79 ); 80 is( 81 button.classList.contains("profiler-paused"), 82 paused, 83 `The expected profiler button paused state is: ${paused}` 84 ); 85 86 if (tooltip) { 87 // Let's also check the tooltip, but because the translation happens 88 // asynchronously, we need a waiting mechanism. 89 await getElementByTooltip(document, tooltip); 90 } 91 }