fune/dom/plugins/test/unit/test_plugin_default_state.js
Kris Maglione 918ed6c474 Bug 1431533: Part 5a - Auto-rewrite code to use ChromeUtils import methods. r=florian
This was done using the following script:
37e3803c7a/processors/chromeutils-import.jsm

MozReview-Commit-ID: 1Nc3XDu0wGl

--HG--
extra : source : 12fc4dee861c812fd2bd032c63ef17af61800c70
extra : intermediate-source : 34c999fa006bffe8705cf50c54708aa21a962e62
extra : histedit_source : b2be2c5e5d226e6c347312456a6ae339c1e634b0
2018-01-29 15:20:18 -08:00

31 lines
1.5 KiB
JavaScript

ChromeUtils.import("resource://gre/modules/Services.jsm");
function run_test() {
allow_all_plugins();
let pluginDefaultState = Services.prefs.getIntPref("plugin.default.state");
// if this fails, we just have to switch around the values we're testing
Assert.notEqual(pluginDefaultState, Ci.nsIPluginTag.STATE_DISABLED);
let nonDefaultState = (pluginDefaultState != Ci.nsIPluginTag.STATE_ENABLED ?
Ci.nsIPluginTag.STATE_ENABLED :
Ci.nsIPluginTag.STATE_CLICKTOPLAY);
let ph = Cc["@mozilla.org/plugin/host;1"].getService(Ci.nsIPluginHost);
let testPlugin = get_test_plugintag();
// the test plugin should have the default enabledState
Assert.equal(testPlugin.enabledState, pluginDefaultState);
let secondTestPlugin = get_test_plugintag("Second Test Plug-in");
// set an enabledState for the second test plugin
secondTestPlugin.enabledState = Ci.nsIPluginTag.STATE_DISABLED;
// change what the default enabledState is
Services.prefs.setIntPref("plugin.default.state", nonDefaultState);
// the test plugin should follow the default (it has no individual pref yet)
Assert.equal(testPlugin.enabledState, nonDefaultState);
// the second test plugin should retain its preferred state
Assert.equal(secondTestPlugin.enabledState, Ci.nsIPluginTag.STATE_DISABLED);
// clean up
testPlugin.enabledState = pluginDefaultState;
secondTestPlugin.enabledState = pluginDefaultState;
Services.prefs.clearUserPref("plugin.default.state");
Services.prefs.clearUserPref("plugin.importedState");
}