michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. michael@0: */ michael@0: michael@0: const XULAPPINFO_CONTRACTID = "@mozilla.org/xre/app-info;1"; michael@0: const XULAPPINFO_CID = Components.ID("{c763b610-9d49-455a-bbd2-ede71682a1ac}"); michael@0: michael@0: Components.utils.import("resource://gre/modules/XPCOMUtils.jsm"); michael@0: Components.utils.import("resource://gre/modules/Services.jsm"); michael@0: michael@0: let gAppInfo = null; michael@0: michael@0: function createAppInfo(id, name, version, platformVersion) { michael@0: gAppInfo = { michael@0: // nsIXULAppInfo michael@0: vendor: "Mozilla", michael@0: name: name, michael@0: ID: id, michael@0: version: version, michael@0: appBuildID: "2007010101", michael@0: platformVersion: platformVersion ? platformVersion : "1.0", michael@0: platformBuildID: "2007010101", michael@0: michael@0: // nsIXULRuntime michael@0: inSafeMode: false, michael@0: logConsoleErrors: true, michael@0: OS: "XPCShell", michael@0: XPCOMABI: "noarch-spidermonkey", michael@0: invalidateCachesOnRestart: function invalidateCachesOnRestart() { michael@0: // Do nothing michael@0: }, michael@0: michael@0: // nsICrashReporter michael@0: annotations: {}, michael@0: michael@0: annotateCrashReport: function(key, data) { michael@0: this.annotations[key] = data; michael@0: }, michael@0: michael@0: QueryInterface: XPCOMUtils.generateQI([Ci.nsIXULAppInfo, michael@0: Ci.nsIXULRuntime, michael@0: Ci.nsICrashReporter, michael@0: Ci.nsISupports]) michael@0: }; michael@0: michael@0: let XULAppInfoFactory = { michael@0: createInstance: function (outer, iid) { michael@0: if (outer != null) michael@0: throw Components.results.NS_ERROR_NO_AGGREGATION; michael@0: return gAppInfo.QueryInterface(iid); michael@0: } michael@0: }; michael@0: let registrar = Components.manager.QueryInterface(Ci.nsIComponentRegistrar); michael@0: registrar.registerFactory(XULAPPINFO_CID, "XULAppInfo", michael@0: XULAPPINFO_CONTRACTID, XULAppInfoFactory); michael@0: } michael@0: michael@0: let gDirSvc = Cc["@mozilla.org/file/directory_service;1"] michael@0: .getService(Ci.nsIProperties); michael@0: michael@0: let gPluginHost = null; michael@0: michael@0: function test_expected_permission_string(aPermString) { michael@0: gPluginHost.reloadPlugins(false); michael@0: let plugin = get_test_plugintag(); michael@0: do_check_false(plugin == null); michael@0: do_check_eq(gPluginHost.getPermissionStringForType("application/x-test"), michael@0: aPermString); michael@0: } michael@0: michael@0: function run_test() { michael@0: do_check_true(gIsWindows || gIsOSX || gIsLinux); michael@0: do_check_true(!(gIsWindows && gIsOSX) && !(gIsWindows && gIsLinux) && michael@0: !(gIsOSX && gIsLinux)); michael@0: michael@0: createAppInfo("xpcshell@tests.mozilla.org", "XPCShell", "1", "1.9"); michael@0: gPluginHost = Cc["@mozilla.org/plugin/host;1"].getService(Ci.nsIPluginHost); michael@0: michael@0: let expectedDefaultPermissionString = null; michael@0: if (gIsWindows) expectedDefaultPermissionString = "plugin:nptest"; michael@0: if (gIsOSX) expectedDefaultPermissionString = "plugin:test"; michael@0: if (gIsLinux) expectedDefaultPermissionString = "plugin:libnptest"; michael@0: test_expected_permission_string(expectedDefaultPermissionString); michael@0: michael@0: let suffix = get_platform_specific_plugin_suffix(); michael@0: let pluginFile = get_test_plugin_no_symlink(); michael@0: let pluginDir = pluginFile.parent; michael@0: pluginFile.copyTo(null, "npblah235" + suffix); michael@0: let pluginCopy = pluginDir.clone(); michael@0: pluginCopy.append("npblah235" + suffix); michael@0: let tempDir = do_get_tempdir(); michael@0: pluginFile.moveTo(tempDir, null); michael@0: test_expected_permission_string("plugin:npblah"); michael@0: michael@0: pluginCopy.moveTo(null, "npasdf-3.2.2" + suffix); michael@0: test_expected_permission_string("plugin:npasdf"); michael@0: michael@0: pluginCopy.moveTo(null, "npasdf_##29387!{}{[][" + suffix); michael@0: test_expected_permission_string("plugin:npasdf"); michael@0: michael@0: pluginCopy.moveTo(null, "npqtplugin7" + suffix); michael@0: test_expected_permission_string("plugin:npqtplugin"); michael@0: michael@0: pluginCopy.moveTo(null, "npFoo3d" + suffix); michael@0: test_expected_permission_string("plugin:npfoo3d"); michael@0: michael@0: pluginCopy.moveTo(null, "NPSWF32_11_5_502_146" + suffix); michael@0: test_expected_permission_string("plugin:npswf"); michael@0: michael@0: pluginCopy.remove(true); michael@0: pluginFile.moveTo(pluginDir, null); michael@0: test_expected_permission_string(expectedDefaultPermissionString); michael@0: michael@0: // Clean up michael@0: Services.prefs.clearUserPref("plugin.importedState"); michael@0: }