browser_devtools-previously-started.js (1851B)
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 what happens if the profiler was previously started by another tool." 10 ); 11 12 const { startProfiler } = ChromeUtils.importESModule( 13 "resource://devtools/client/performance-new/shared/background.sys.mjs" 14 ); 15 16 info("Start the profiler before DevTools is loaded."); 17 startProfiler("aboutprofiling"); 18 19 await withDevToolsPanel(async document => { 20 const getRecordingState = setupGetRecordingState(document); 21 22 // The initial state of the profiler UI is racy, as it calls out to the PerfFront 23 // to get the status of the profiler. This can race with the initialization of 24 // the test. Most of the the time the result is "not-yet-known", but rarely 25 // the PerfFront will win this race. Allow for both outcomes of the race in this 26 // test. 27 ok( 28 getRecordingState() === "not-yet-known" || 29 getRecordingState() === "recording", 30 "The component starts out in an unknown state or in a recording state." 31 ); 32 33 const cancelRecording = await getActiveButtonFromText( 34 document, 35 "Cancel recording" 36 ); 37 38 is( 39 getRecordingState(), 40 "recording", 41 "The profiler is reflecting the recording state." 42 ); 43 44 info("Click the button to cancel the recording"); 45 cancelRecording.click(); 46 47 is( 48 getRecordingState(), 49 "request-to-stop-profiler", 50 "We can request to stop the profiler." 51 ); 52 53 await getActiveButtonFromText(document, "Start recording"); 54 55 is( 56 getRecordingState(), 57 "available-to-record", 58 "The profiler is now available to record." 59 ); 60 }); 61 });