michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. michael@0: */ michael@0: michael@0: Components.utils.import("resource://gre/modules/Services.jsm"); michael@0: michael@0: // Plugin registry uses different field delimeters on different platforms michael@0: var DELIM = ":"; michael@0: if ("@mozilla.org/windows-registry-key;1" in Components.classes) michael@0: DELIM = "|"; michael@0: michael@0: var gProfD = do_get_profile_startup(); michael@0: var gDirSvc = Cc["@mozilla.org/file/directory_service;1"]. michael@0: getService(Ci.nsIProperties); michael@0: michael@0: // Writes out some plugin registry to the profile michael@0: function write_registry(version, info) { michael@0: let runtime = Cc["@mozilla.org/xre/runtime;1"].getService(Ci.nsIXULRuntime); michael@0: michael@0: var header = "Generated File. Do not edit.\n\n"; michael@0: header += "[HEADER]\n"; michael@0: header += "Version" + DELIM + version + DELIM + "$\n"; michael@0: header += "Arch" + DELIM + runtime.XPCOMABI + DELIM + "$\n"; michael@0: header += "\n"; michael@0: header += "[PLUGINS]\n"; michael@0: michael@0: var registry = gProfD.clone(); michael@0: registry.append("pluginreg.dat"); michael@0: var foStream = Components.classes["@mozilla.org/network/file-output-stream;1"] michael@0: .createInstance(Components.interfaces.nsIFileOutputStream); michael@0: // write, create, truncate michael@0: foStream.init(registry, 0x02 | 0x08 | 0x20, 0666, 0); michael@0: michael@0: var charset = "UTF-8"; // Can be any character encoding name that Mozilla supports michael@0: var os = Cc["@mozilla.org/intl/converter-output-stream;1"]. michael@0: createInstance(Ci.nsIConverterOutputStream); michael@0: os.init(foStream, charset, 0, 0x0000); michael@0: michael@0: os.writeString(header); michael@0: os.writeString(info); michael@0: os.close(); michael@0: } michael@0: michael@0: function run_test() { michael@0: var plugin = get_test_plugintag(); michael@0: do_check_true(plugin == null); michael@0: michael@0: var file = get_test_plugin(); michael@0: if (!file) { michael@0: do_throw("Plugin library not found"); michael@0: } michael@0: michael@0: // write plugin registry data michael@0: let registry = ""; michael@0: michael@0: if (gIsOSX) { michael@0: registry += file.leafName + DELIM + "$\n"; michael@0: registry += file.path + DELIM + "$\n"; michael@0: } else { michael@0: registry += file.path + DELIM + "$\n"; michael@0: registry += DELIM + "$\n"; michael@0: } michael@0: registry += "0.0.0.0" + DELIM + "$\n"; michael@0: registry += "16725225600" + DELIM + "0" + DELIM + "5" + DELIM + "$\n"; michael@0: registry += "Plug-in for testing purposes." + DELIM + "$\n"; michael@0: registry += "Test Plug-in" + DELIM + "$\n"; michael@0: registry += "999999999999999999999999999999999999999999999999|0|5|$\n"; michael@0: registry += "0" + DELIM + "application/x-test" + DELIM + "Test mimetype" + michael@0: DELIM + "tst" + DELIM + "$\n"; michael@0: michael@0: registry += "\n"; michael@0: registry += "[INVALID]\n"; michael@0: registry += "\n"; michael@0: write_registry("0.15", registry); michael@0: michael@0: // Initialise profile folder michael@0: do_get_profile(); michael@0: michael@0: var plugin = get_test_plugintag(); michael@0: if (!plugin) michael@0: do_throw("Plugin tag not found"); michael@0: michael@0: // The plugin registry should have been rejected. michael@0: // If not, the test plugin version would be 0.0.0.0 michael@0: do_check_eq(plugin.version, "1.0.0.0"); michael@0: michael@0: // Clean up michael@0: Services.prefs.clearUserPref("plugin.importedState"); michael@0: }