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

mercurial