mirror of
https://repo.dactyloidae.xyz/Dactyloidae/UXP.git
synced 2026-10-12 10:17:31 +09:00
import FIREFOX_52_6_0esr_RELEASE from mozilla-esr52 hg repo
This commit is contained in:
commit
dcd9973243
150858 changed files with 23884658 additions and 0 deletions
195
dom/plugins/test/unit/head_plugins.js
Normal file
195
dom/plugins/test/unit/head_plugins.js
Normal file
|
|
@ -0,0 +1,195 @@
|
|||
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
||||
*/
|
||||
|
||||
var {classes: Cc, interfaces: Ci, utils: Cu, results: Cr} = Components;
|
||||
|
||||
Cu.import("resource://gre/modules/Promise.jsm");
|
||||
Cu.import("resource://gre/modules/Services.jsm");
|
||||
|
||||
const gIsWindows = mozinfo.os == "win";
|
||||
const gIsOSX = mozinfo.os == "mac";
|
||||
const gIsLinux = mozinfo.os == "linux";
|
||||
const gDirSvc = Cc["@mozilla.org/file/directory_service;1"].getService(Ci.nsIProperties);
|
||||
|
||||
function allow_all_plugins() {
|
||||
Services.prefs.setBoolPref("plugin.load_flash_only", false);
|
||||
}
|
||||
|
||||
// Finds the test plugin library
|
||||
function get_test_plugin(secondplugin=false) {
|
||||
var pluginEnum = gDirSvc.get("APluginsDL", Ci.nsISimpleEnumerator);
|
||||
while (pluginEnum.hasMoreElements()) {
|
||||
let dir = pluginEnum.getNext().QueryInterface(Ci.nsILocalFile);
|
||||
let name = get_platform_specific_plugin_name(secondplugin);
|
||||
let plugin = dir.clone();
|
||||
plugin.append(name);
|
||||
if (plugin.exists()) {
|
||||
plugin.normalize();
|
||||
return plugin;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
// Finds the test nsIPluginTag
|
||||
function get_test_plugintag(aName="Test Plug-in") {
|
||||
const Cc = Components.classes;
|
||||
const Ci = Components.interfaces;
|
||||
|
||||
var name = aName || "Test Plug-in";
|
||||
var host = Cc["@mozilla.org/plugin/host;1"].
|
||||
getService(Ci.nsIPluginHost);
|
||||
var tags = host.getPluginTags();
|
||||
|
||||
for (var i = 0; i < tags.length; i++) {
|
||||
if (tags[i].name == name)
|
||||
return tags[i];
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
// Creates a fake ProfDS directory key, copied from do_get_profile
|
||||
function do_get_profile_startup() {
|
||||
let env = Components.classes["@mozilla.org/process/environment;1"]
|
||||
.getService(Components.interfaces.nsIEnvironment);
|
||||
// the python harness sets this in the environment for us
|
||||
let profd = env.get("XPCSHELL_TEST_PROFILE_DIR");
|
||||
let file = Components.classes["@mozilla.org/file/local;1"]
|
||||
.createInstance(Components.interfaces.nsILocalFile);
|
||||
file.initWithPath(profd);
|
||||
|
||||
let dirSvc = Components.classes["@mozilla.org/file/directory_service;1"]
|
||||
.getService(Components.interfaces.nsIProperties);
|
||||
let provider = {
|
||||
getFile: function(prop, persistent) {
|
||||
persistent.value = true;
|
||||
if (prop == "ProfDS") {
|
||||
return file.clone();
|
||||
}
|
||||
throw Components.results.NS_ERROR_FAILURE;
|
||||
},
|
||||
QueryInterface: function(iid) {
|
||||
if (iid.equals(Components.interfaces.nsIDirectoryServiceProvider) ||
|
||||
iid.equals(Components.interfaces.nsISupports)) {
|
||||
return this;
|
||||
}
|
||||
throw Components.results.NS_ERROR_NO_INTERFACE;
|
||||
}
|
||||
};
|
||||
dirSvc.QueryInterface(Components.interfaces.nsIDirectoryService)
|
||||
.registerProvider(provider);
|
||||
return file.clone();
|
||||
}
|
||||
|
||||
function get_platform_specific_plugin_name(secondplugin=false) {
|
||||
if (secondplugin) {
|
||||
if (gIsWindows) return "npsecondtest.dll";
|
||||
if (gIsOSX) return "SecondTest.plugin";
|
||||
if (gIsLinux) return "libnpsecondtest.so";
|
||||
} else {
|
||||
if (gIsWindows) return "nptest.dll";
|
||||
if (gIsOSX) return "Test.plugin";
|
||||
if (gIsLinux) return "libnptest.so";
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
function get_platform_specific_plugin_suffix() {
|
||||
if (gIsWindows) return ".dll";
|
||||
else if (gIsOSX) return ".plugin";
|
||||
else if (gIsLinux) return ".so";
|
||||
else return null;
|
||||
}
|
||||
|
||||
function get_test_plugin_no_symlink() {
|
||||
let dirSvc = Cc["@mozilla.org/file/directory_service;1"]
|
||||
.getService(Ci.nsIProperties);
|
||||
let pluginEnum = dirSvc.get("APluginsDL", Ci.nsISimpleEnumerator);
|
||||
while (pluginEnum.hasMoreElements()) {
|
||||
let dir = pluginEnum.getNext().QueryInterface(Ci.nsILocalFile);
|
||||
let plugin = dir.clone();
|
||||
plugin.append(get_platform_specific_plugin_name());
|
||||
if (plugin.exists()) {
|
||||
return plugin;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
var gGlobalScope = this;
|
||||
function loadAddonManager() {
|
||||
let ns = {};
|
||||
Cu.import("resource://gre/modules/Services.jsm", ns);
|
||||
let head = "../../../../toolkit/mozapps/extensions/test/xpcshell/head_addons.js";
|
||||
let file = do_get_file(head);
|
||||
let uri = ns.Services.io.newFileURI(file);
|
||||
ns.Services.scriptloader.loadSubScript(uri.spec, gGlobalScope);
|
||||
createAppInfo("xpcshell@tests.mozilla.org", "XPCShell", "1", "1.9.2");
|
||||
startupManager();
|
||||
}
|
||||
|
||||
// Install addon and return a Promise<boolean> that is
|
||||
// resolve with true on success, false otherwise.
|
||||
function installAddon(relativePath) {
|
||||
let deferred = Promise.defer();
|
||||
let success = () => deferred.resolve(true);
|
||||
let fail = () => deferred.resolve(false);
|
||||
let listener = {
|
||||
onDownloadCancelled: fail,
|
||||
onDownloadFailed: fail,
|
||||
onInstallCancelled: fail,
|
||||
onInstallFailed: fail,
|
||||
onInstallEnded: success,
|
||||
};
|
||||
|
||||
let installCallback = install => {
|
||||
install.addListener(listener);
|
||||
install.install();
|
||||
};
|
||||
|
||||
let file = do_get_file(relativePath, false);
|
||||
AddonManager.getInstallForFile(file, installCallback,
|
||||
"application/x-xpinstall");
|
||||
|
||||
return deferred.promise;
|
||||
}
|
||||
|
||||
// Uninstall addon and return a Promise<boolean> that is
|
||||
// resolve with true on success, false otherwise.
|
||||
function uninstallAddon(id) {
|
||||
let deferred = Promise.defer();
|
||||
|
||||
AddonManager.getAddonByID(id, addon => {
|
||||
if (!addon) {
|
||||
deferred.resolve(false);
|
||||
}
|
||||
|
||||
let listener = {};
|
||||
let handler = addon => {
|
||||
if (addon.id !== id) {
|
||||
return;
|
||||
}
|
||||
|
||||
AddonManager.removeAddonListener(listener);
|
||||
deferred.resolve(true);
|
||||
};
|
||||
|
||||
listener.onUninstalled = handler;
|
||||
listener.onDisabled = handler;
|
||||
|
||||
AddonManager.addAddonListener(listener);
|
||||
addon.uninstall();
|
||||
});
|
||||
|
||||
return deferred.promise;
|
||||
}
|
||||
|
||||
// Returns a Promise<Addon> that is resolved with
|
||||
// the corresponding addon or rejected.
|
||||
function getAddonByID(id) {
|
||||
let deferred = Promise.defer();
|
||||
AddonManager.getAddonByID(id, addon => deferred.resolve(addon));
|
||||
return deferred.promise;
|
||||
}
|
||||
142
dom/plugins/test/unit/test_allowed_types.js
Normal file
142
dom/plugins/test/unit/test_allowed_types.js
Normal file
|
|
@ -0,0 +1,142 @@
|
|||
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
||||
*/
|
||||
|
||||
Components.utils.import("resource://gre/modules/Services.jsm");
|
||||
|
||||
function run_test() {
|
||||
const pluginHost = Cc["@mozilla.org/plugin/host;1"].getService(Ci.nsIPluginHost);
|
||||
const pluginDefaultState = Services.prefs.getIntPref("plugin.default.state");
|
||||
|
||||
Services.prefs.setBoolPref("plugin.load_flash_only", false);
|
||||
|
||||
function reload_plugins_with_allowed_types(allowed_types) {
|
||||
if (typeof allowed_types === "undefined") {
|
||||
// If we didn't get an allowed_types string, then unset the pref,
|
||||
// so the caller can test the behavior when the pref isn't set.
|
||||
Services.prefs.clearUserPref("plugin.allowed_types");
|
||||
} else {
|
||||
Services.prefs.setCharPref("plugin.allowed_types", allowed_types);
|
||||
}
|
||||
pluginHost.reloadPlugins();
|
||||
}
|
||||
|
||||
function get_status_for_type(type) {
|
||||
try {
|
||||
return pluginHost.getStateForType(type);
|
||||
} catch(ex) {
|
||||
// If the type is not allowed, then nsIPluginHost.getStateForType throws
|
||||
// NS_ERROR_NOT_AVAILABLE, for which we return undefined to make it easier
|
||||
// to write assertions about the API.
|
||||
if (ex.result === Cr.NS_ERROR_NOT_AVAILABLE) {
|
||||
return undefined;
|
||||
}
|
||||
throw ex;
|
||||
}
|
||||
}
|
||||
|
||||
// If allowed_types isn't set, then all plugin types are enabled.
|
||||
reload_plugins_with_allowed_types();
|
||||
do_check_eq(get_status_for_type("application/x-test"), pluginDefaultState);
|
||||
do_check_eq(get_status_for_type("application/x-Second-Test"), pluginDefaultState);
|
||||
do_check_eq(get_status_for_type("application/x-nonexistent"), undefined);
|
||||
|
||||
// If allowed_types is set to the empty string, then all plugin types are enabled.
|
||||
reload_plugins_with_allowed_types("");
|
||||
do_check_eq(get_status_for_type("application/x-test"), pluginDefaultState);
|
||||
do_check_eq(get_status_for_type("application/x-Second-Test"), pluginDefaultState);
|
||||
do_check_eq(get_status_for_type("application/x-nonexistent"), undefined);
|
||||
|
||||
// If allowed_types is set to anything other than the empty string,
|
||||
// then only types that exactly match its comma-separated entries are enabled,
|
||||
// so a single space disables all types.
|
||||
reload_plugins_with_allowed_types(" ");
|
||||
do_check_eq(get_status_for_type("application/x-test"), undefined);
|
||||
do_check_eq(get_status_for_type("application/x-Second-Test"), undefined);
|
||||
do_check_eq(get_status_for_type("application/x-nonexistent"), undefined);
|
||||
|
||||
// The rest of the assertions test various values of allowed_types to ensure
|
||||
// that the correct types are enabled.
|
||||
|
||||
reload_plugins_with_allowed_types("application/x-test");
|
||||
do_check_eq(get_status_for_type("application/x-test"), pluginDefaultState);
|
||||
do_check_eq(get_status_for_type("application/x-Second-Test"), undefined);
|
||||
do_check_eq(get_status_for_type("application/x-nonexistent"), undefined);
|
||||
|
||||
reload_plugins_with_allowed_types("application/x-Second-Test");
|
||||
do_check_eq(get_status_for_type("application/x-test"), undefined);
|
||||
do_check_eq(get_status_for_type("application/x-Second-Test"), pluginDefaultState);
|
||||
do_check_eq(get_status_for_type("application/x-nonexistent"), undefined);
|
||||
|
||||
reload_plugins_with_allowed_types("application/x-nonexistent");
|
||||
do_check_eq(get_status_for_type("application/x-test"), undefined);
|
||||
do_check_eq(get_status_for_type("application/x-Second-Test"), undefined);
|
||||
do_check_eq(get_status_for_type("application/x-nonexistent"), undefined);
|
||||
|
||||
reload_plugins_with_allowed_types("application/x-test,application/x-Second-Test");
|
||||
do_check_eq(get_status_for_type("application/x-test"), pluginDefaultState);
|
||||
do_check_eq(get_status_for_type("application/x-Second-Test"), pluginDefaultState);
|
||||
do_check_eq(get_status_for_type("application/x-nonexistent"), undefined);
|
||||
|
||||
reload_plugins_with_allowed_types("application/x-Second-Test,application/x-test");
|
||||
do_check_eq(get_status_for_type("application/x-test"), pluginDefaultState);
|
||||
do_check_eq(get_status_for_type("application/x-Second-Test"), pluginDefaultState);
|
||||
do_check_eq(get_status_for_type("application/x-nonexistent"), undefined);
|
||||
|
||||
reload_plugins_with_allowed_types("application/x-test,application/x-nonexistent");
|
||||
do_check_eq(get_status_for_type("application/x-test"), pluginDefaultState);
|
||||
do_check_eq(get_status_for_type("application/x-Second-Test"), undefined);
|
||||
do_check_eq(get_status_for_type("application/x-nonexistent"), undefined);
|
||||
|
||||
reload_plugins_with_allowed_types("application/x-nonexistent,application/x-test");
|
||||
do_check_eq(get_status_for_type("application/x-test"), pluginDefaultState);
|
||||
do_check_eq(get_status_for_type("application/x-Second-Test"), undefined);
|
||||
do_check_eq(get_status_for_type("application/x-nonexistent"), undefined);
|
||||
|
||||
reload_plugins_with_allowed_types("application/x-test,application/x-Second-Test,application/x-nonexistent");
|
||||
do_check_eq(get_status_for_type("application/x-test"), pluginDefaultState);
|
||||
do_check_eq(get_status_for_type("application/x-Second-Test"), pluginDefaultState);
|
||||
do_check_eq(get_status_for_type("application/x-nonexistent"), undefined);
|
||||
|
||||
reload_plugins_with_allowed_types("application/x-test,application/x-nonexistent,application/x-Second-Test");
|
||||
do_check_eq(get_status_for_type("application/x-test"), pluginDefaultState);
|
||||
do_check_eq(get_status_for_type("application/x-Second-Test"), pluginDefaultState);
|
||||
do_check_eq(get_status_for_type("application/x-nonexistent"), undefined);
|
||||
|
||||
reload_plugins_with_allowed_types("application/x-Second-Test,application/x-test,application/x-nonexistent");
|
||||
do_check_eq(get_status_for_type("application/x-test"), pluginDefaultState);
|
||||
do_check_eq(get_status_for_type("application/x-Second-Test"), pluginDefaultState);
|
||||
do_check_eq(get_status_for_type("application/x-nonexistent"), undefined);
|
||||
|
||||
reload_plugins_with_allowed_types("application/x-Second-Test,application/x-nonexistent,application/x-test");
|
||||
do_check_eq(get_status_for_type("application/x-test"), pluginDefaultState);
|
||||
do_check_eq(get_status_for_type("application/x-Second-Test"), pluginDefaultState);
|
||||
do_check_eq(get_status_for_type("application/x-nonexistent"), undefined);
|
||||
|
||||
reload_plugins_with_allowed_types("application/x-nonexistent,application/x-test,application/x-Second-Test");
|
||||
do_check_eq(get_status_for_type("application/x-test"), pluginDefaultState);
|
||||
do_check_eq(get_status_for_type("application/x-Second-Test"), pluginDefaultState);
|
||||
do_check_eq(get_status_for_type("application/x-nonexistent"), undefined);
|
||||
|
||||
reload_plugins_with_allowed_types("application/x-nonexistent,application/x-Second-Test,application/x-test");
|
||||
do_check_eq(get_status_for_type("application/x-test"), pluginDefaultState);
|
||||
do_check_eq(get_status_for_type("application/x-Second-Test"), pluginDefaultState);
|
||||
do_check_eq(get_status_for_type("application/x-nonexistent"), undefined);
|
||||
|
||||
// Plugin types are case-insensitive, so matching should be too.
|
||||
reload_plugins_with_allowed_types("APPLICATION/X-TEST");
|
||||
do_check_eq(get_status_for_type("application/x-test"), pluginDefaultState);
|
||||
reload_plugins_with_allowed_types("application/x-test");
|
||||
do_check_eq(get_status_for_type("APPLICATION/X-TEST"), pluginDefaultState);
|
||||
|
||||
// Types must match exactly, so supersets should not enable subset types.
|
||||
reload_plugins_with_allowed_types("application/x-test-superset");
|
||||
do_check_eq(get_status_for_type("application/x-test"), undefined);
|
||||
reload_plugins_with_allowed_types("superset-application/x-test");
|
||||
do_check_eq(get_status_for_type("application/x-test"), undefined);
|
||||
|
||||
// Clean up.
|
||||
Services.prefs.clearUserPref("plugin.allowed_types");
|
||||
Services.prefs.clearUserPref("plugin.importedState");
|
||||
}
|
||||
23
dom/plugins/test/unit/test_bug471245.js
Normal file
23
dom/plugins/test/unit/test_bug471245.js
Normal file
|
|
@ -0,0 +1,23 @@
|
|||
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
||||
*/
|
||||
|
||||
Components.utils.import("resource://gre/modules/Services.jsm");
|
||||
|
||||
function run_test() {
|
||||
allow_all_plugins();
|
||||
do_get_profile_startup();
|
||||
|
||||
var plugin = get_test_plugintag();
|
||||
do_check_true(plugin == null);
|
||||
|
||||
// Initialises a profile folder
|
||||
do_get_profile();
|
||||
|
||||
var plugin = get_test_plugintag();
|
||||
do_check_false(plugin == null);
|
||||
|
||||
// Clean up
|
||||
Services.prefs.clearUserPref("plugin.importedState");
|
||||
}
|
||||
87
dom/plugins/test/unit/test_bug813245.js
Normal file
87
dom/plugins/test/unit/test_bug813245.js
Normal file
|
|
@ -0,0 +1,87 @@
|
|||
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
||||
*/
|
||||
|
||||
Components.utils.import("resource://gre/modules/Services.jsm");
|
||||
|
||||
// Plugin registry uses different field delimeters on different platforms
|
||||
var DELIM = mozinfo.os == "win" ? "|" : ":";
|
||||
|
||||
var gProfD = do_get_profile_startup();
|
||||
|
||||
// Writes out some plugin registry to the profile
|
||||
function write_registry(version, info) {
|
||||
let runtime = Cc["@mozilla.org/xre/runtime;1"].getService(Ci.nsIXULRuntime);
|
||||
|
||||
var header = "Generated File. Do not edit.\n\n";
|
||||
header += "[HEADER]\n";
|
||||
header += "Version" + DELIM + version + DELIM + "$\n";
|
||||
header += "Arch" + DELIM + runtime.XPCOMABI + DELIM + "$\n";
|
||||
header += "\n";
|
||||
header += "[PLUGINS]\n";
|
||||
|
||||
var registry = gProfD.clone();
|
||||
registry.append("pluginreg.dat");
|
||||
var foStream = Components.classes["@mozilla.org/network/file-output-stream;1"]
|
||||
.createInstance(Components.interfaces.nsIFileOutputStream);
|
||||
// write, create, truncate
|
||||
foStream.init(registry, 0x02 | 0x08 | 0x20, 0o666, 0);
|
||||
|
||||
var charset = "UTF-8"; // Can be any character encoding name that Mozilla supports
|
||||
var os = Cc["@mozilla.org/intl/converter-output-stream;1"].
|
||||
createInstance(Ci.nsIConverterOutputStream);
|
||||
os.init(foStream, charset, 0, 0x0000);
|
||||
|
||||
os.writeString(header);
|
||||
os.writeString(info);
|
||||
os.close();
|
||||
}
|
||||
|
||||
function run_test() {
|
||||
allow_all_plugins();
|
||||
var plugin = get_test_plugintag();
|
||||
do_check_true(plugin == null);
|
||||
|
||||
var file = get_test_plugin();
|
||||
if (!file) {
|
||||
do_throw("Plugin library not found");
|
||||
}
|
||||
|
||||
// write plugin registry data
|
||||
let registry = "";
|
||||
|
||||
if (gIsOSX) {
|
||||
registry += file.leafName + DELIM + "$\n";
|
||||
registry += file.path + DELIM + "$\n";
|
||||
} else {
|
||||
registry += file.path + DELIM + "$\n";
|
||||
registry += DELIM + "$\n";
|
||||
}
|
||||
registry += "0.0.0.0" + DELIM + "$\n";
|
||||
registry += "16725225600" + DELIM + "0" + DELIM + "5" + DELIM + "$\n";
|
||||
registry += "Plug-in for testing purposes." + DELIM + "$\n";
|
||||
registry += "Test Plug-in" + DELIM + "$\n";
|
||||
registry += "999999999999999999999999999999999999999999999999|0|5|$\n";
|
||||
registry += "0" + DELIM + "application/x-test" + DELIM + "Test mimetype" +
|
||||
DELIM + "tst" + DELIM + "$\n";
|
||||
|
||||
registry += "\n";
|
||||
registry += "[INVALID]\n";
|
||||
registry += "\n";
|
||||
write_registry("0.15", registry);
|
||||
|
||||
// Initialise profile folder
|
||||
do_get_profile();
|
||||
|
||||
var plugin = get_test_plugintag();
|
||||
if (!plugin)
|
||||
do_throw("Plugin tag not found");
|
||||
|
||||
// The plugin registry should have been rejected.
|
||||
// If not, the test plugin version would be 0.0.0.0
|
||||
do_check_eq(plugin.version, "1.0.0.0");
|
||||
|
||||
// Clean up
|
||||
Services.prefs.clearUserPref("plugin.importedState");
|
||||
}
|
||||
40
dom/plugins/test/unit/test_bug854467.js
Normal file
40
dom/plugins/test/unit/test_bug854467.js
Normal file
|
|
@ -0,0 +1,40 @@
|
|||
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
||||
*/
|
||||
|
||||
function check_state(aTag, aExpectedClicktoplay, aExpectedDisabled) {
|
||||
do_check_eq(aTag.clicktoplay, aExpectedClicktoplay);
|
||||
do_check_eq(aTag.disabled, aExpectedDisabled);
|
||||
}
|
||||
|
||||
function run_test() {
|
||||
allow_all_plugins();
|
||||
let tag = get_test_plugintag();
|
||||
tag.enabledState = Ci.nsIPluginTag.STATE_ENABLED;
|
||||
check_state(tag, false, false);
|
||||
|
||||
/* test going to click-to-play from always enabled and back */
|
||||
tag.enabledState = Ci.nsIPluginTag.STATE_CLICKTOPLAY;
|
||||
check_state(tag, true, false);
|
||||
tag.enabledState = Ci.nsIPluginTag.STATE_ENABLED;
|
||||
check_state(tag, false, false);
|
||||
|
||||
/* test going to disabled from always enabled and back */
|
||||
tag.enabledState = Ci.nsIPluginTag.STATE_DISABLED;
|
||||
check_state(tag, false, true);
|
||||
tag.enabledState = Ci.nsIPluginTag.STATE_ENABLED;
|
||||
check_state(tag, false, false);
|
||||
|
||||
/* test going to click-to-play from disabled and back */
|
||||
tag.enabledState = Ci.nsIPluginTag.STATE_DISABLED;
|
||||
check_state(tag, false, true);
|
||||
tag.enabledState = Ci.nsIPluginTag.STATE_CLICKTOPLAY;
|
||||
check_state(tag, true, false);
|
||||
tag.enabledState = Ci.nsIPluginTag.STATE_DISABLED;
|
||||
check_state(tag, false, true);
|
||||
|
||||
/* put everything back to normal and check that that succeeded */
|
||||
tag.enabledState = Ci.nsIPluginTag.STATE_ENABLED;
|
||||
check_state(tag, false, false);
|
||||
}
|
||||
80
dom/plugins/test/unit/test_nice_plugin_name.js
Normal file
80
dom/plugins/test/unit/test_nice_plugin_name.js
Normal file
|
|
@ -0,0 +1,80 @@
|
|||
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
||||
*/
|
||||
|
||||
const XULAPPINFO_CONTRACTID = "@mozilla.org/xre/app-info;1";
|
||||
const XULAPPINFO_CID = Components.ID("{c763b610-9d49-455a-bbd2-ede71682a1ac}");
|
||||
|
||||
Components.utils.import("resource://gre/modules/XPCOMUtils.jsm");
|
||||
Components.utils.import("resource://gre/modules/Services.jsm");
|
||||
|
||||
var gAppInfo = null;
|
||||
|
||||
function createAppInfo(ID, name, version, platformVersion="1.0") {
|
||||
let tmp = {};
|
||||
Cu.import("resource://testing-common/AppInfo.jsm", tmp);
|
||||
tmp.updateAppInfo({
|
||||
ID, name, version, platformVersion,
|
||||
crashReporter: true
|
||||
});
|
||||
gAppInfo = tmp.getAppInfo();
|
||||
}
|
||||
|
||||
var gPluginHost = null;
|
||||
|
||||
function test_expected_permission_string(aPermString) {
|
||||
gPluginHost.reloadPlugins(false);
|
||||
let plugin = get_test_plugintag();
|
||||
do_check_false(plugin == null);
|
||||
do_check_eq(gPluginHost.getPermissionStringForType("application/x-test"),
|
||||
aPermString);
|
||||
}
|
||||
|
||||
function run_test() {
|
||||
allow_all_plugins();
|
||||
do_check_true(gIsWindows || gIsOSX || gIsLinux);
|
||||
do_check_true(!(gIsWindows && gIsOSX) && !(gIsWindows && gIsLinux) &&
|
||||
!(gIsOSX && gIsLinux));
|
||||
|
||||
createAppInfo("xpcshell@tests.mozilla.org", "XPCShell", "1", "1.9");
|
||||
gPluginHost = Cc["@mozilla.org/plugin/host;1"].getService(Ci.nsIPluginHost);
|
||||
|
||||
let expectedDefaultPermissionString = null;
|
||||
if (gIsWindows) expectedDefaultPermissionString = "plugin:nptest";
|
||||
if (gIsOSX) expectedDefaultPermissionString = "plugin:test";
|
||||
if (gIsLinux) expectedDefaultPermissionString = "plugin:libnptest";
|
||||
test_expected_permission_string(expectedDefaultPermissionString);
|
||||
|
||||
let suffix = get_platform_specific_plugin_suffix();
|
||||
let pluginFile = get_test_plugin_no_symlink();
|
||||
let pluginDir = pluginFile.parent;
|
||||
pluginFile.copyTo(null, "npblah235" + suffix);
|
||||
let pluginCopy = pluginDir.clone();
|
||||
pluginCopy.append("npblah235" + suffix);
|
||||
let tempDir = do_get_tempdir();
|
||||
pluginFile.moveTo(tempDir, null);
|
||||
test_expected_permission_string("plugin:npblah");
|
||||
|
||||
pluginCopy.moveTo(null, "npasdf-3.2.2" + suffix);
|
||||
test_expected_permission_string("plugin:npasdf");
|
||||
|
||||
pluginCopy.moveTo(null, "npasdf_##29387!{}{[][" + suffix);
|
||||
test_expected_permission_string("plugin:npasdf");
|
||||
|
||||
pluginCopy.moveTo(null, "npqtplugin7" + suffix);
|
||||
test_expected_permission_string("plugin:npqtplugin");
|
||||
|
||||
pluginCopy.moveTo(null, "npFoo3d" + suffix);
|
||||
test_expected_permission_string("plugin:npfoo3d");
|
||||
|
||||
pluginCopy.moveTo(null, "NPSWF32_11_5_502_146" + suffix);
|
||||
test_expected_permission_string("plugin:npswf");
|
||||
|
||||
pluginCopy.remove(true);
|
||||
pluginFile.moveTo(pluginDir, null);
|
||||
test_expected_permission_string(expectedDefaultPermissionString);
|
||||
|
||||
// Clean up
|
||||
Services.prefs.clearUserPref("plugin.importedState");
|
||||
}
|
||||
76
dom/plugins/test/unit/test_persist_in_prefs.js
Normal file
76
dom/plugins/test/unit/test_persist_in_prefs.js
Normal file
|
|
@ -0,0 +1,76 @@
|
|||
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
||||
*/
|
||||
|
||||
Components.utils.import("resource://gre/modules/Services.jsm");
|
||||
|
||||
// Plugin registry uses different field delimeters on different platforms
|
||||
var DELIM = mozinfo.os == "win" ? "|" : ":";
|
||||
|
||||
var gProfD = do_get_profile_startup();
|
||||
|
||||
function run_test() {
|
||||
allow_all_plugins();
|
||||
|
||||
do_check_true(gIsWindows || gIsOSX || gIsLinux);
|
||||
|
||||
let file = get_test_plugin_no_symlink();
|
||||
if (!file)
|
||||
do_throw("Plugin library not found");
|
||||
|
||||
const pluginDir = file.parent;
|
||||
const tempDir = do_get_tempdir();
|
||||
const suffix = get_platform_specific_plugin_suffix();
|
||||
const pluginName = file.leafName.substring(0, file.leafName.length - suffix.length).toLowerCase();
|
||||
const pluginHost = Cc["@mozilla.org/plugin/host;1"].getService(Ci.nsIPluginHost);
|
||||
const statePref = "plugin.state." + pluginName;
|
||||
|
||||
// Initialise profile folder
|
||||
do_get_profile();
|
||||
|
||||
let plugin = get_test_plugintag();
|
||||
if (!plugin)
|
||||
do_throw("Plugin tag not found");
|
||||
|
||||
plugin.enabledState = Ci.nsIPluginTag.STATE_DISABLED;
|
||||
|
||||
// prepare a copy of the plugin and backup the original
|
||||
file.copyTo(null, "nptestcopy" + suffix);
|
||||
let copy = pluginDir.clone();
|
||||
copy.append("nptestcopy" + suffix);
|
||||
file.moveTo(tempDir, null);
|
||||
|
||||
// test that the settings persist through a few variations of test-plugin names
|
||||
let testNames = [
|
||||
pluginName + "2",
|
||||
pluginName.toUpperCase() + "_11_5_42_2323",
|
||||
pluginName + "-5.2.7"
|
||||
];
|
||||
testNames.forEach(function(leafName) {
|
||||
dump("Checking " + leafName + ".\n");
|
||||
copy.moveTo(null, leafName + suffix);
|
||||
pluginHost.reloadPlugins(false);
|
||||
plugin = get_test_plugintag();
|
||||
do_check_false(plugin == null);
|
||||
do_check_true(plugin.disabled);
|
||||
do_check_false(plugin.clicktoplay);
|
||||
});
|
||||
|
||||
// check that the state persists even if the plugin is not always present
|
||||
copy.moveTo(tempDir, null);
|
||||
pluginHost.reloadPlugins(false);
|
||||
copy.moveTo(pluginDir, null);
|
||||
pluginHost.reloadPlugins(false);
|
||||
|
||||
plugin = get_test_plugintag();
|
||||
do_check_false(plugin == null);
|
||||
do_check_true(plugin.disabled);
|
||||
do_check_false(plugin.clicktoplay);
|
||||
|
||||
// clean up
|
||||
Services.prefs.clearUserPref(statePref);
|
||||
Services.prefs.clearUserPref("plugin.importedState");
|
||||
copy.remove(true);
|
||||
file.moveTo(pluginDir, null);
|
||||
}
|
||||
31
dom/plugins/test/unit/test_plugin_default_state.js
Normal file
31
dom/plugins/test/unit/test_plugin_default_state.js
Normal file
|
|
@ -0,0 +1,31 @@
|
|||
Components.utils.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
|
||||
do_check_neq(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
|
||||
do_check_eq(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)
|
||||
do_check_eq(testPlugin.enabledState, nonDefaultState);
|
||||
// the second test plugin should retain its preferred state
|
||||
do_check_eq(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");
|
||||
}
|
||||
118
dom/plugins/test/unit/test_plugin_default_state_xpi.js
Normal file
118
dom/plugins/test/unit/test_plugin_default_state_xpi.js
Normal file
|
|
@ -0,0 +1,118 @@
|
|||
/* Any copyright is dedicated to the Public Domain.
|
||||
* http://creativecommons.org/publicdomain/zero/1.0/
|
||||
*/
|
||||
|
||||
Cu.import("resource://gre/modules/Services.jsm");
|
||||
Cu.import("resource://gre/modules/Promise.jsm");
|
||||
|
||||
const ADDON_ID = "test-plugin-from-xpi@tests.mozilla.org";
|
||||
const XRE_EXTENSIONS_DIR_LIST = "XREExtDL";
|
||||
const NS_APP_PLUGINS_DIR_LIST = "APluginsDL";
|
||||
|
||||
const gPluginHost = Cc["@mozilla.org/plugin/host;1"].getService(Ci.nsIPluginHost);
|
||||
const gXPCOMABI = Cc["@mozilla.org/xre/app-info;1"].getService(Ci.nsIXULRuntime).XPCOMABI;
|
||||
var gProfileDir = null;
|
||||
|
||||
function getAddonRoot(profileDir, id) {
|
||||
let dir = profileDir.clone();
|
||||
dir.append("extensions");
|
||||
Assert.ok(dir.exists(), "Extensions dir should exist: " + dir.path);
|
||||
dir.append(id);
|
||||
return dir;
|
||||
}
|
||||
|
||||
function getTestaddonFilename() {
|
||||
let abiPart = "";
|
||||
if (gIsOSX) {
|
||||
abiPart = "_" + gXPCOMABI;
|
||||
}
|
||||
return "testaddon" + abiPart + ".xpi";
|
||||
}
|
||||
|
||||
function run_test() {
|
||||
allow_all_plugins();
|
||||
loadAddonManager();
|
||||
gProfileDir = do_get_profile();
|
||||
do_register_cleanup(() => shutdownManager());
|
||||
run_next_test();
|
||||
}
|
||||
|
||||
add_task(function* test_state() {
|
||||
// Remove test so we will have only one "Test Plug-in" registered.
|
||||
// xpcshell tests have plugins in per-test profiles, so that's fine.
|
||||
let file = get_test_plugin();
|
||||
file.remove(true);
|
||||
file = get_test_plugin(true);
|
||||
file.remove(true);
|
||||
|
||||
Services.prefs.setIntPref("plugin.default.state", Ci.nsIPluginTag.STATE_CLICKTOPLAY);
|
||||
Services.prefs.setIntPref("plugin.defaultXpi.state", Ci.nsIPluginTag.STATE_ENABLED);
|
||||
|
||||
let success = yield installAddon(getTestaddonFilename());
|
||||
Assert.ok(success, "Should have installed addon.");
|
||||
let addonDir = getAddonRoot(gProfileDir, ADDON_ID);
|
||||
|
||||
let provider = {
|
||||
classID: Components.ID("{0af6b2d7-a06c-49b7-babc-636d292b0dbb}"),
|
||||
QueryInterface: XPCOMUtils.generateQI([Ci.nsIDirectoryServiceProvider,
|
||||
Ci.nsIDirectoryServiceProvider2]),
|
||||
|
||||
getFile: function (prop, persistant) {
|
||||
throw Cr.NS_ERROR_FAILURE;
|
||||
},
|
||||
|
||||
getFiles: function (prop) {
|
||||
let result = [];
|
||||
|
||||
switch (prop) {
|
||||
case XRE_EXTENSIONS_DIR_LIST:
|
||||
result.push(addonDir);
|
||||
break;
|
||||
case NS_APP_PLUGINS_DIR_LIST:
|
||||
let pluginDir = addonDir.clone();
|
||||
pluginDir.append("plugins");
|
||||
result.push(pluginDir);
|
||||
break;
|
||||
default:
|
||||
throw Cr.NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
return {
|
||||
QueryInterface: XPCOMUtils.generateQI([Ci.nsISimpleEnumerator]),
|
||||
hasMoreElements: () => result.length > 0,
|
||||
getNext: () => result.shift(),
|
||||
};
|
||||
},
|
||||
};
|
||||
|
||||
let dirSvc = Cc["@mozilla.org/file/directory_service;1"].getService(Ci.nsIProperties);
|
||||
dirSvc.QueryInterface(Ci.nsIDirectoryService).registerProvider(provider);
|
||||
|
||||
// We installed a non-restartless addon, need to restart the manager.
|
||||
restartManager();
|
||||
gPluginHost.reloadPlugins();
|
||||
|
||||
Assert.ok(addonDir.exists(), "Addon path should exist: " + addonDir.path);
|
||||
Assert.ok(addonDir.isDirectory(), "Addon path should be a directory: " + addonDir.path);
|
||||
let pluginDir = addonDir.clone();
|
||||
pluginDir.append("plugins");
|
||||
Assert.ok(pluginDir.exists(), "Addon plugins path should exist: " + pluginDir.path);
|
||||
Assert.ok(pluginDir.isDirectory(), "Addon plugins path should be a directory: " + pluginDir.path);
|
||||
|
||||
let addon = yield getAddonByID(ADDON_ID);
|
||||
Assert.ok(!addon.appDisabled, "Addon should not be appDisabled");
|
||||
Assert.ok(addon.isActive, "Addon should be active");
|
||||
Assert.ok(addon.isCompatible, "Addon should be compatible");
|
||||
Assert.ok(!addon.userDisabled, "Addon should not be user disabled");
|
||||
|
||||
let testPlugin = get_test_plugintag();
|
||||
Assert.notEqual(testPlugin, null, "Test plugin should have been found");
|
||||
Assert.equal(testPlugin.enabledState, Ci.nsIPluginTag.STATE_ENABLED, "Test plugin from addon should have state enabled");
|
||||
|
||||
pluginDir.append(testPlugin.filename);
|
||||
Assert.ok(pluginDir.exists(), "Plugin file should exist in addon directory: " + pluginDir.path);
|
||||
|
||||
testPlugin = get_test_plugintag("Second Test Plug-in");
|
||||
Assert.notEqual(testPlugin, null, "Second test plugin should have been found");
|
||||
Assert.equal(testPlugin.enabledState, Ci.nsIPluginTag.STATE_ENABLED, "Second test plugin from addon should have state enabled");
|
||||
});
|
||||
29
dom/plugins/test/unit/xpcshell.ini
Normal file
29
dom/plugins/test/unit/xpcshell.ini
Normal file
|
|
@ -0,0 +1,29 @@
|
|||
[DEFAULT]
|
||||
skip-if = toolkit == 'android'
|
||||
head = head_plugins.js
|
||||
tail =
|
||||
tags = addons
|
||||
firefox-appdir = browser
|
||||
support-files =
|
||||
!/toolkit/mozapps/extensions/test/xpcshell/head_addons.js
|
||||
|
||||
[test_allowed_types.js]
|
||||
skip-if = appname == "thunderbird"
|
||||
reason = plugins are disabled by default in Thunderbird
|
||||
[test_bug471245.js]
|
||||
# Bug 676953: test fails consistently on Android
|
||||
fail-if = os == "android"
|
||||
[test_bug813245.js]
|
||||
# Bug 676953: test fails consistently on Android
|
||||
fail-if = os == "android"
|
||||
[test_nice_plugin_name.js]
|
||||
# Bug 676953: test fails consistently on Android
|
||||
fail-if = os == "android"
|
||||
[test_persist_in_prefs.js]
|
||||
skip-if = appname == "thunderbird"
|
||||
reason = plugins are disabled by default in Thunderbird
|
||||
[test_bug854467.js]
|
||||
[test_plugin_default_state.js]
|
||||
skip-if = appname == "thunderbird"
|
||||
reason = plugins are disabled by default in Thunderbird
|
||||
[test_plugin_default_state_xpi.js]
|
||||
Loading…
Add table
Add a link
Reference in a new issue