|
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 let runtime = Cc["@mozilla.org/xre/runtime;1"].getService(Ci.nsIXULRuntime); |
|
20 |
|
21 var header = "Generated File. Do not edit.\n\n"; |
|
22 header += "[HEADER]\n"; |
|
23 header += "Version" + DELIM + version + DELIM + "$\n"; |
|
24 header += "Arch" + DELIM + runtime.XPCOMABI + DELIM + "$\n"; |
|
25 header += "\n"; |
|
26 header += "[PLUGINS]\n"; |
|
27 |
|
28 var registry = gProfD.clone(); |
|
29 registry.append("pluginreg.dat"); |
|
30 var foStream = Components.classes["@mozilla.org/network/file-output-stream;1"] |
|
31 .createInstance(Components.interfaces.nsIFileOutputStream); |
|
32 // write, create, truncate |
|
33 foStream.init(registry, 0x02 | 0x08 | 0x20, 0666, 0); |
|
34 |
|
35 var charset = "UTF-8"; // Can be any character encoding name that Mozilla supports |
|
36 var os = Cc["@mozilla.org/intl/converter-output-stream;1"]. |
|
37 createInstance(Ci.nsIConverterOutputStream); |
|
38 os.init(foStream, charset, 0, 0x0000); |
|
39 |
|
40 os.writeString(header); |
|
41 os.writeString(info); |
|
42 os.close(); |
|
43 } |
|
44 |
|
45 function run_test() { |
|
46 var plugin = get_test_plugintag(); |
|
47 do_check_true(plugin == null); |
|
48 |
|
49 var file = get_test_plugin(); |
|
50 if (!file) { |
|
51 do_throw("Plugin library not found"); |
|
52 } |
|
53 |
|
54 // write plugin registry data |
|
55 let registry = ""; |
|
56 |
|
57 if (gIsOSX) { |
|
58 registry += file.leafName + DELIM + "$\n"; |
|
59 registry += file.path + DELIM + "$\n"; |
|
60 } else { |
|
61 registry += file.path + DELIM + "$\n"; |
|
62 registry += DELIM + "$\n"; |
|
63 } |
|
64 registry += "0.0.0.0" + DELIM + "$\n"; |
|
65 registry += "16725225600" + DELIM + "0" + DELIM + "5" + DELIM + "$\n"; |
|
66 registry += "Plug-in for testing purposes." + DELIM + "$\n"; |
|
67 registry += "Test Plug-in" + DELIM + "$\n"; |
|
68 registry += "999999999999999999999999999999999999999999999999|0|5|$\n"; |
|
69 registry += "0" + DELIM + "application/x-test" + DELIM + "Test mimetype" + |
|
70 DELIM + "tst" + DELIM + "$\n"; |
|
71 |
|
72 registry += "\n"; |
|
73 registry += "[INVALID]\n"; |
|
74 registry += "\n"; |
|
75 write_registry("0.15", registry); |
|
76 |
|
77 // Initialise profile folder |
|
78 do_get_profile(); |
|
79 |
|
80 var plugin = get_test_plugintag(); |
|
81 if (!plugin) |
|
82 do_throw("Plugin tag not found"); |
|
83 |
|
84 // The plugin registry should have been rejected. |
|
85 // If not, the test plugin version would be 0.0.0.0 |
|
86 do_check_eq(plugin.version, "1.0.0.0"); |
|
87 |
|
88 // Clean up |
|
89 Services.prefs.clearUserPref("plugin.importedState"); |
|
90 } |