|
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 Components.utils.import("resource://gre/modules/Services.jsm"); |
|
7 |
|
8 // Plugin registry uses different field delimeters on different platforms |
|
9 var DELIM = ":"; |
|
10 if ("@mozilla.org/windows-registry-key;1" in Components.classes) |
|
11 DELIM = "|"; |
|
12 |
|
13 var gProfD = do_get_profile_startup(); |
|
14 var gDirSvc = Cc["@mozilla.org/file/directory_service;1"]. |
|
15 getService(Ci.nsIProperties); |
|
16 |
|
17 // Writes out some plugin registry to the profile |
|
18 function write_registry(version, info) { |
|
19 var header = "Generated File. Do not edit.\n\n"; |
|
20 header += "[HEADER]\n"; |
|
21 header += "Version" + DELIM + version + DELIM + "$\n\n"; |
|
22 header += "[PLUGINS]\n"; |
|
23 |
|
24 var registry = gProfD.clone(); |
|
25 registry.append("pluginreg.dat"); |
|
26 var foStream = Components.classes["@mozilla.org/network/file-output-stream;1"] |
|
27 .createInstance(Components.interfaces.nsIFileOutputStream); |
|
28 // write, create, truncate |
|
29 foStream.init(registry, 0x02 | 0x08 | 0x20, 0666, 0); |
|
30 |
|
31 var charset = "UTF-8"; // Can be any character encoding name that Mozilla supports |
|
32 var os = Cc["@mozilla.org/intl/converter-output-stream;1"]. |
|
33 createInstance(Ci.nsIConverterOutputStream); |
|
34 os.init(foStream, charset, 0, 0x0000); |
|
35 |
|
36 os.writeString(header); |
|
37 os.writeString(info); |
|
38 os.close(); |
|
39 } |
|
40 |
|
41 function run_test() { |
|
42 var plugin = get_test_plugintag(); |
|
43 do_check_true(plugin == null); |
|
44 |
|
45 var file = get_test_plugin(); |
|
46 if (!file) |
|
47 do_throw("Plugin library not found"); |
|
48 |
|
49 // Write out a 0.9 version registry that marks the test plugin as disabled |
|
50 var registry = ""; |
|
51 if (gIsOSX) { |
|
52 registry += file.leafName + DELIM + "$\n"; |
|
53 registry += file.path + DELIM + "$\n"; |
|
54 } else { |
|
55 registry += file.path + DELIM + "$\n"; |
|
56 registry += DELIM + "$\n"; |
|
57 } |
|
58 registry += file.lastModifiedTime + DELIM + "0" + DELIM + "0" + DELIM + "$\n"; |
|
59 registry += "Plug-in for testing purposes.\u2122 " + |
|
60 "(\u0939\u093f\u0928\u094d\u0926\u0940 " + |
|
61 "\u4e2d\u6587 " + |
|
62 "\u0627\u0644\u0639\u0631\u0628\u064a\u0629)" + |
|
63 DELIM + "$\n"; |
|
64 registry += "Test Plug-in" + DELIM + "$\n"; |
|
65 registry += "1\n"; |
|
66 registry += "0" + DELIM + "application/x-test" + DELIM + "Test mimetype" + |
|
67 DELIM + "tst" + DELIM + "$\n"; |
|
68 write_registry("0.9", registry); |
|
69 |
|
70 // Initialise profile folder |
|
71 do_get_profile(); |
|
72 |
|
73 plugin = get_test_plugintag(); |
|
74 if (!plugin) |
|
75 do_throw("Plugin tag not found"); |
|
76 |
|
77 // If the plugin was not rescanned then this version will not be correct |
|
78 do_check_eq(plugin.version, "1.0.0.0"); |
|
79 do_check_eq(plugin.description, |
|
80 "Plug-in for testing purposes.\u2122 " + |
|
81 "(\u0939\u093f\u0928\u094d\u0926\u0940 " + |
|
82 "\u4e2d\u6587 " + |
|
83 "\u0627\u0644\u0639\u0631\u0628\u064a\u0629)"); |
|
84 // If the plugin registry was not read then the plugin will not be disabled |
|
85 do_check_true(plugin.disabled); |
|
86 do_check_false(plugin.blocklisted); |
|
87 |
|
88 // Clean up |
|
89 Services.prefs.clearUserPref("plugin.importedState"); |
|
90 } |