browser_aboutprofiling-more-actions-menu.js (5700B)
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 async function waitForClipboard() { 8 return waitUntil(() => navigator.clipboard.readText()); 9 } 10 11 // Before starting the test, let's find out which features are selected from the 12 // Graphics preset. 13 const supportedFeatures = Services.profiler.GetFeatures(); 14 const { presets } = ChromeUtils.importESModule( 15 "resource://devtools/shared/performance-new/prefs-presets.sys.mjs" 16 ); 17 // Depending on the environment, not all features are present. So that the test 18 // works for all environments, we need to compute this value instead of 19 // hardcoding it. 20 const featuresForGraphicsPreset = presets.graphics.features.filter(feature => 21 supportedFeatures.includes(feature) 22 ); 23 const featuresForGraphicsPresetAsString = featuresForGraphicsPreset.join(","); 24 25 // For convenience, we also compute the expected value for threads. 26 const threadsForGraphicsPresetsAsString = presets.graphics.threads.join(","); 27 28 add_task(async function test() { 29 info("Test the more actions button in about:profiling."); 30 info( 31 "Set the preference devtools.performance.aboutprofiling.has-developer-options to true" 32 ); 33 await SpecialPowers.pushPrefEnv({ 34 set: [["devtools.performance.aboutprofiling.has-developer-options", true]], 35 }); 36 37 await withAboutProfiling(async (document, browser) => { 38 info("Make sure the preset 'Graphics' is checked for consistency."); 39 const graphicsPresetLabel = await getElementFromDocumentByText( 40 document, 41 "Graphics" 42 ); 43 EventUtils.synthesizeMouseAtCenter( 44 graphicsPresetLabel, 45 {}, 46 browser.contentWindow 47 ); 48 is( 49 Services.prefs.getCharPref("devtools.performance.recording.preset", ""), 50 "graphics", 51 'The preset "graphics" is selected.' 52 ); 53 54 info("Test that there is a button to show a menu with more actions."); 55 const moreActionsButton = document.querySelector("moz-button"); 56 ok(moreActionsButton, "There is a button."); 57 ok(moreActionsButton.shadowRoot, "The button contains a shadowDom."); 58 59 // Make sure we have an accessible name 60 is( 61 moreActionsButton.shadowRoot.querySelector("button").title, 62 "More actions", 63 "Test that the more actions button has a title" 64 ); 65 66 info("Test that the button is clickable"); 67 // The second argument is the event object. By passing an empty object, this 68 // tells the utility function to generate a mousedown then a mouseup, that 69 // is a click. 70 EventUtils.synthesizeMouseAtCenter( 71 moreActionsButton, 72 {}, 73 browser.contentWindow 74 ); 75 let item = await getElementFromDocumentByText( 76 document, 77 "with startup profiling" 78 ); 79 ok(item, "The item to restart with startup profiling has been displayed"); 80 // Skipping clicking on the item, we don't want to actually restart firefox 81 // during the test. But most of the code is common with the below use case 82 // "copy environment variables". 83 84 info("Will copy environment variables for startup profiling"); 85 SpecialPowers.cleanupAllClipboard(); 86 item = await getElementFromDocumentByText( 87 document, 88 "Copy environment variables" 89 ); 90 ok( 91 item, 92 "The item to copy environment variables for startup profiling is present in the menu" 93 ); 94 95 EventUtils.synthesizeMouseAtCenter(item, {}, browser.contentWindow); 96 is( 97 await waitForClipboard(), 98 `MOZ_PROFILER_STARTUP='1' MOZ_PROFILER_STARTUP_INTERVAL='1' MOZ_PROFILER_STARTUP_ENTRIES='134217728' MOZ_PROFILER_STARTUP_FEATURES='${featuresForGraphicsPresetAsString}' MOZ_PROFILER_STARTUP_FILTERS='${threadsForGraphicsPresetsAsString}'`, 99 "The clipboard contains the environment variables suitable for startup profiling." 100 ); 101 102 info("Will copy parameters for performance tests profiling"); 103 SpecialPowers.cleanupAllClipboard(); 104 EventUtils.synthesizeMouseAtCenter( 105 moreActionsButton, 106 {}, 107 browser.contentWindow 108 ); 109 item = await getElementFromDocumentByText(document, "performance tests"); 110 ok( 111 item, 112 "The item to copy the parameters to performance tests is present in the menu" 113 ); 114 EventUtils.synthesizeMouseAtCenter(item, {}, browser.contentWindow); 115 116 is( 117 await waitForClipboard(), 118 `--gecko-profile --gecko-profile-interval 1 --gecko-profile-entries 134217728 --gecko-profile-features '${featuresForGraphicsPresetAsString}' --gecko-profile-threads '${threadsForGraphicsPresetsAsString}'`, 119 "The clipboard contains the parameters suitable for performance tests." 120 ); 121 SpecialPowers.cleanupAllClipboard(); 122 123 // With the preference set to false, the items aren't present 124 info( 125 "Set the preference devtools.performance.aboutprofiling.has-developer-options to false" 126 ); 127 await SpecialPowers.pushPrefEnv({ 128 set: [ 129 ["devtools.performance.aboutprofiling.has-developer-options", false], 130 ], 131 }); 132 EventUtils.synthesizeMouseAtCenter( 133 moreActionsButton, 134 {}, 135 browser.contentWindow 136 ); 137 await getElementFromDocumentByText(document, "with startup profiling"); 138 // The item that's always present is now displayed 139 ok( 140 !maybeGetElementFromDocumentByText( 141 document, 142 "Copy environment variables" 143 ), 144 "The item to copy environment variables is not present." 145 ); 146 ok( 147 !maybeGetElementFromDocumentByText(document, "performance tests"), 148 "the item to copy the parameters for performance tests is not present." 149 ); 150 }); 151 });