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: let DELIM = ":"; michael@0: if ("@mozilla.org/windows-registry-key;1" in Components.classes) michael@0: DELIM = "|"; michael@0: michael@0: let gProfD = do_get_profile_startup(); michael@0: let 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: let 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: let registry = gProfD.clone(); michael@0: registry.append("pluginreg.dat"); michael@0: let 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: let charset = "UTF-8"; // Can be any character encoding name that Mozilla supports michael@0: let 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: do_check_true(gIsWindows || gIsOSX || gIsLinux); michael@0: michael@0: let file = get_test_plugin_no_symlink(); michael@0: if (!file) michael@0: do_throw("Plugin library not found"); michael@0: michael@0: const pluginDir = file.parent; michael@0: const tempDir = do_get_tempdir(); michael@0: const suffix = get_platform_specific_plugin_suffix(); michael@0: const pluginName = file.leafName.substring(0, file.leafName.length - suffix.length).toLowerCase(); michael@0: const pluginHost = Cc["@mozilla.org/plugin/host;1"].getService(Ci.nsIPluginHost); michael@0: const statePref = "plugin.state." + pluginName; michael@0: michael@0: // write plugin registry data michael@0: let registry = ""; michael@0: michael@0: registry += file.leafName + DELIM + "$\n"; michael@0: registry += file.path + DELIM + "$\n"; michael@0: registry += "1.0.0.0" + DELIM + "$\n"; michael@0: registry += file.lastModifiedTime + DELIM + "0" + DELIM + "0" + DELIM + "$\n"; michael@0: registry += "Plug-in for testing purposes." + DELIM + "$\n"; michael@0: registry += "Test Plug-in" + DELIM + "$\n"; michael@0: registry += "1\n"; michael@0: registry += "0" + DELIM + "application/x-test" + DELIM + "Test mimetype" + 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: let plugin = get_test_plugintag(); michael@0: if (!plugin) michael@0: do_throw("Plugin tag not found"); michael@0: michael@0: // check that the expected plugin state was loaded correctly from the registry michael@0: do_check_true(plugin.disabled); michael@0: do_check_false(plugin.clicktoplay); michael@0: // ... and imported into prefs, with 0 being the disabled state michael@0: do_check_eq(0, Services.prefs.getIntPref(statePref)); michael@0: michael@0: // prepare a copy of the plugin and backup the original michael@0: file.copyTo(null, "nptestcopy" + suffix); michael@0: let copy = pluginDir.clone(); michael@0: copy.append("nptestcopy" + suffix); michael@0: file.moveTo(tempDir, null); michael@0: michael@0: // test that the settings persist through a few variations of test-plugin names michael@0: let testNames = [ michael@0: pluginName + "2", michael@0: pluginName.toUpperCase() + "_11_5_42_2323", michael@0: pluginName + "-5.2.7" michael@0: ]; michael@0: testNames.forEach(function(leafName) { michael@0: dump("Checking " + leafName + ".\n"); michael@0: copy.moveTo(null, leafName + suffix); michael@0: pluginHost.reloadPlugins(false); michael@0: plugin = get_test_plugintag(); michael@0: do_check_false(plugin == null); michael@0: do_check_true(plugin.disabled); michael@0: do_check_false(plugin.clicktoplay); michael@0: }); michael@0: michael@0: // check that the state persists even if the plugin is not always present michael@0: copy.moveTo(tempDir, null); michael@0: pluginHost.reloadPlugins(false); michael@0: copy.moveTo(pluginDir, null); michael@0: pluginHost.reloadPlugins(false); michael@0: michael@0: plugin = get_test_plugintag(); michael@0: do_check_false(plugin == null); michael@0: do_check_true(plugin.disabled); michael@0: do_check_false(plugin.clicktoplay); michael@0: michael@0: // clean up michael@0: Services.prefs.clearUserPref(statePref); michael@0: Services.prefs.clearUserPref("plugin.importedState"); michael@0: copy.remove(true); michael@0: file.moveTo(pluginDir, null); michael@0: }