dom/plugins/test/unit/test_nice_plugin_name.js

Thu, 22 Jan 2015 13:21:57 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 22 Jan 2015 13:21:57 +0100
branch
TOR_BUG_9701
changeset 15
b8a032363ba2
permissions
-rw-r--r--

Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6

michael@0 1 /* This Source Code Form is subject to the terms of the Mozilla Public
michael@0 2 * License, v. 2.0. If a copy of the MPL was not distributed with this
michael@0 3 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
michael@0 4 */
michael@0 5
michael@0 6 const XULAPPINFO_CONTRACTID = "@mozilla.org/xre/app-info;1";
michael@0 7 const XULAPPINFO_CID = Components.ID("{c763b610-9d49-455a-bbd2-ede71682a1ac}");
michael@0 8
michael@0 9 Components.utils.import("resource://gre/modules/XPCOMUtils.jsm");
michael@0 10 Components.utils.import("resource://gre/modules/Services.jsm");
michael@0 11
michael@0 12 let gAppInfo = null;
michael@0 13
michael@0 14 function createAppInfo(id, name, version, platformVersion) {
michael@0 15 gAppInfo = {
michael@0 16 // nsIXULAppInfo
michael@0 17 vendor: "Mozilla",
michael@0 18 name: name,
michael@0 19 ID: id,
michael@0 20 version: version,
michael@0 21 appBuildID: "2007010101",
michael@0 22 platformVersion: platformVersion ? platformVersion : "1.0",
michael@0 23 platformBuildID: "2007010101",
michael@0 24
michael@0 25 // nsIXULRuntime
michael@0 26 inSafeMode: false,
michael@0 27 logConsoleErrors: true,
michael@0 28 OS: "XPCShell",
michael@0 29 XPCOMABI: "noarch-spidermonkey",
michael@0 30 invalidateCachesOnRestart: function invalidateCachesOnRestart() {
michael@0 31 // Do nothing
michael@0 32 },
michael@0 33
michael@0 34 // nsICrashReporter
michael@0 35 annotations: {},
michael@0 36
michael@0 37 annotateCrashReport: function(key, data) {
michael@0 38 this.annotations[key] = data;
michael@0 39 },
michael@0 40
michael@0 41 QueryInterface: XPCOMUtils.generateQI([Ci.nsIXULAppInfo,
michael@0 42 Ci.nsIXULRuntime,
michael@0 43 Ci.nsICrashReporter,
michael@0 44 Ci.nsISupports])
michael@0 45 };
michael@0 46
michael@0 47 let XULAppInfoFactory = {
michael@0 48 createInstance: function (outer, iid) {
michael@0 49 if (outer != null)
michael@0 50 throw Components.results.NS_ERROR_NO_AGGREGATION;
michael@0 51 return gAppInfo.QueryInterface(iid);
michael@0 52 }
michael@0 53 };
michael@0 54 let registrar = Components.manager.QueryInterface(Ci.nsIComponentRegistrar);
michael@0 55 registrar.registerFactory(XULAPPINFO_CID, "XULAppInfo",
michael@0 56 XULAPPINFO_CONTRACTID, XULAppInfoFactory);
michael@0 57 }
michael@0 58
michael@0 59 let gDirSvc = Cc["@mozilla.org/file/directory_service;1"]
michael@0 60 .getService(Ci.nsIProperties);
michael@0 61
michael@0 62 let gPluginHost = null;
michael@0 63
michael@0 64 function test_expected_permission_string(aPermString) {
michael@0 65 gPluginHost.reloadPlugins(false);
michael@0 66 let plugin = get_test_plugintag();
michael@0 67 do_check_false(plugin == null);
michael@0 68 do_check_eq(gPluginHost.getPermissionStringForType("application/x-test"),
michael@0 69 aPermString);
michael@0 70 }
michael@0 71
michael@0 72 function run_test() {
michael@0 73 do_check_true(gIsWindows || gIsOSX || gIsLinux);
michael@0 74 do_check_true(!(gIsWindows && gIsOSX) && !(gIsWindows && gIsLinux) &&
michael@0 75 !(gIsOSX && gIsLinux));
michael@0 76
michael@0 77 createAppInfo("xpcshell@tests.mozilla.org", "XPCShell", "1", "1.9");
michael@0 78 gPluginHost = Cc["@mozilla.org/plugin/host;1"].getService(Ci.nsIPluginHost);
michael@0 79
michael@0 80 let expectedDefaultPermissionString = null;
michael@0 81 if (gIsWindows) expectedDefaultPermissionString = "plugin:nptest";
michael@0 82 if (gIsOSX) expectedDefaultPermissionString = "plugin:test";
michael@0 83 if (gIsLinux) expectedDefaultPermissionString = "plugin:libnptest";
michael@0 84 test_expected_permission_string(expectedDefaultPermissionString);
michael@0 85
michael@0 86 let suffix = get_platform_specific_plugin_suffix();
michael@0 87 let pluginFile = get_test_plugin_no_symlink();
michael@0 88 let pluginDir = pluginFile.parent;
michael@0 89 pluginFile.copyTo(null, "npblah235" + suffix);
michael@0 90 let pluginCopy = pluginDir.clone();
michael@0 91 pluginCopy.append("npblah235" + suffix);
michael@0 92 let tempDir = do_get_tempdir();
michael@0 93 pluginFile.moveTo(tempDir, null);
michael@0 94 test_expected_permission_string("plugin:npblah");
michael@0 95
michael@0 96 pluginCopy.moveTo(null, "npasdf-3.2.2" + suffix);
michael@0 97 test_expected_permission_string("plugin:npasdf");
michael@0 98
michael@0 99 pluginCopy.moveTo(null, "npasdf_##29387!{}{[][" + suffix);
michael@0 100 test_expected_permission_string("plugin:npasdf");
michael@0 101
michael@0 102 pluginCopy.moveTo(null, "npqtplugin7" + suffix);
michael@0 103 test_expected_permission_string("plugin:npqtplugin");
michael@0 104
michael@0 105 pluginCopy.moveTo(null, "npFoo3d" + suffix);
michael@0 106 test_expected_permission_string("plugin:npfoo3d");
michael@0 107
michael@0 108 pluginCopy.moveTo(null, "NPSWF32_11_5_502_146" + suffix);
michael@0 109 test_expected_permission_string("plugin:npswf");
michael@0 110
michael@0 111 pluginCopy.remove(true);
michael@0 112 pluginFile.moveTo(pluginDir, null);
michael@0 113 test_expected_permission_string(expectedDefaultPermissionString);
michael@0 114
michael@0 115 // Clean up
michael@0 116 Services.prefs.clearUserPref("plugin.importedState");
michael@0 117 }

mercurial