dom/plugins/test/unit/test_nice_plugin_name.js

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

mercurial