test_popup_initial_state.js (2754B)
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 /** 7 * Tests the initial state of the background script for the popup. 8 */ 9 10 add_task(function test() { 11 info("Test that we get the default preference values from the browser."); 12 const preferences = PrefsPresets.getRecordingSettings( 13 "aboutprofiling", 14 Services.profiler.GetFeatures() 15 ); 16 17 Assert.notEqual( 18 preferences.entries, 19 undefined, 20 "The initial state has the default entries." 21 ); 22 Assert.notEqual( 23 preferences.interval, 24 undefined, 25 "The initial state has the default interval." 26 ); 27 Assert.notEqual( 28 preferences.features, 29 undefined, 30 "The initial state has the default features." 31 ); 32 Assert.equal( 33 preferences.features.includes("js"), 34 true, 35 "The js feature is initialized to the default." 36 ); 37 Assert.notEqual( 38 preferences.threads, 39 undefined, 40 "The initial state has the default threads." 41 ); 42 Assert.equal( 43 preferences.threads.includes("GeckoMain"), 44 true, 45 "The GeckoMain thread is initialized to the default." 46 ); 47 Assert.notEqual( 48 preferences.objdirs, 49 undefined, 50 "The initial state has the default objdirs." 51 ); 52 Assert.notEqual( 53 preferences.duration, 54 undefined, 55 "The duration is initialized to the duration." 56 ); 57 }); 58 59 add_task(function test() { 60 info( 61 "Test that the state and features are properly validated. This ensures that as " + 62 "we add and remove features, the stored preferences do not cause the Gecko " + 63 "Profiler interface to crash with invalid values." 64 ); 65 const { getRecordingSettings, setRecordingSettings, changePreset } = 66 PrefsPresets; 67 68 const supportedFeatures = Services.profiler.GetFeatures(); 69 70 changePreset("aboutprofiling", "custom", supportedFeatures); 71 72 Assert.ok( 73 getRecordingSettings("aboutprofiling", supportedFeatures).features.includes( 74 "js" 75 ), 76 "The js preference is present initially." 77 ); 78 79 const settings = getRecordingSettings("aboutprofiling", supportedFeatures); 80 settings.features = settings.features.filter(feature => feature !== "js"); 81 settings.features.push("UNKNOWN_FEATURE_FOR_TESTS"); 82 setRecordingSettings("aboutprofiling", settings); 83 84 Assert.ok( 85 !getRecordingSettings( 86 "aboutprofiling", 87 supportedFeatures 88 ).features.includes("UNKNOWN_FEATURE_FOR_TESTS"), 89 "The unknown feature is removed." 90 ); 91 Assert.ok( 92 !getRecordingSettings( 93 "aboutprofiling", 94 supportedFeatures 95 ).features.includes("js"), 96 "The js preference is still flipped from the default." 97 ); 98 });