Thu, 22 Jan 2015 13:21:57 +0100
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 | let DELIM = ":"; |
michael@0 | 10 | if ("@mozilla.org/windows-registry-key;1" in Components.classes) |
michael@0 | 11 | DELIM = "|"; |
michael@0 | 12 | |
michael@0 | 13 | let gProfD = do_get_profile_startup(); |
michael@0 | 14 | let 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 | let 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 | let registry = gProfD.clone(); |
michael@0 | 29 | registry.append("pluginreg.dat"); |
michael@0 | 30 | let 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 | let charset = "UTF-8"; // Can be any character encoding name that Mozilla supports |
michael@0 | 36 | let 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 | do_check_true(gIsWindows || gIsOSX || gIsLinux); |
michael@0 | 47 | |
michael@0 | 48 | let file = get_test_plugin_no_symlink(); |
michael@0 | 49 | if (!file) |
michael@0 | 50 | do_throw("Plugin library not found"); |
michael@0 | 51 | |
michael@0 | 52 | const pluginDir = file.parent; |
michael@0 | 53 | const tempDir = do_get_tempdir(); |
michael@0 | 54 | const suffix = get_platform_specific_plugin_suffix(); |
michael@0 | 55 | const pluginName = file.leafName.substring(0, file.leafName.length - suffix.length).toLowerCase(); |
michael@0 | 56 | const pluginHost = Cc["@mozilla.org/plugin/host;1"].getService(Ci.nsIPluginHost); |
michael@0 | 57 | const statePref = "plugin.state." + pluginName; |
michael@0 | 58 | |
michael@0 | 59 | // write plugin registry data |
michael@0 | 60 | let registry = ""; |
michael@0 | 61 | |
michael@0 | 62 | registry += file.leafName + DELIM + "$\n"; |
michael@0 | 63 | registry += file.path + DELIM + "$\n"; |
michael@0 | 64 | registry += "1.0.0.0" + DELIM + "$\n"; |
michael@0 | 65 | registry += file.lastModifiedTime + DELIM + "0" + DELIM + "0" + 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 += "1\n"; |
michael@0 | 69 | registry += "0" + DELIM + "application/x-test" + DELIM + "Test mimetype" + DELIM + "tst" + DELIM + "$\n"; |
michael@0 | 70 | |
michael@0 | 71 | registry += "\n"; |
michael@0 | 72 | registry += "[INVALID]\n"; |
michael@0 | 73 | registry += "\n"; |
michael@0 | 74 | write_registry("0.15", registry); |
michael@0 | 75 | |
michael@0 | 76 | // Initialise profile folder |
michael@0 | 77 | do_get_profile(); |
michael@0 | 78 | |
michael@0 | 79 | let plugin = get_test_plugintag(); |
michael@0 | 80 | if (!plugin) |
michael@0 | 81 | do_throw("Plugin tag not found"); |
michael@0 | 82 | |
michael@0 | 83 | // check that the expected plugin state was loaded correctly from the registry |
michael@0 | 84 | do_check_true(plugin.disabled); |
michael@0 | 85 | do_check_false(plugin.clicktoplay); |
michael@0 | 86 | // ... and imported into prefs, with 0 being the disabled state |
michael@0 | 87 | do_check_eq(0, Services.prefs.getIntPref(statePref)); |
michael@0 | 88 | |
michael@0 | 89 | // prepare a copy of the plugin and backup the original |
michael@0 | 90 | file.copyTo(null, "nptestcopy" + suffix); |
michael@0 | 91 | let copy = pluginDir.clone(); |
michael@0 | 92 | copy.append("nptestcopy" + suffix); |
michael@0 | 93 | file.moveTo(tempDir, null); |
michael@0 | 94 | |
michael@0 | 95 | // test that the settings persist through a few variations of test-plugin names |
michael@0 | 96 | let testNames = [ |
michael@0 | 97 | pluginName + "2", |
michael@0 | 98 | pluginName.toUpperCase() + "_11_5_42_2323", |
michael@0 | 99 | pluginName + "-5.2.7" |
michael@0 | 100 | ]; |
michael@0 | 101 | testNames.forEach(function(leafName) { |
michael@0 | 102 | dump("Checking " + leafName + ".\n"); |
michael@0 | 103 | copy.moveTo(null, leafName + suffix); |
michael@0 | 104 | pluginHost.reloadPlugins(false); |
michael@0 | 105 | plugin = get_test_plugintag(); |
michael@0 | 106 | do_check_false(plugin == null); |
michael@0 | 107 | do_check_true(plugin.disabled); |
michael@0 | 108 | do_check_false(plugin.clicktoplay); |
michael@0 | 109 | }); |
michael@0 | 110 | |
michael@0 | 111 | // check that the state persists even if the plugin is not always present |
michael@0 | 112 | copy.moveTo(tempDir, null); |
michael@0 | 113 | pluginHost.reloadPlugins(false); |
michael@0 | 114 | copy.moveTo(pluginDir, null); |
michael@0 | 115 | pluginHost.reloadPlugins(false); |
michael@0 | 116 | |
michael@0 | 117 | plugin = get_test_plugintag(); |
michael@0 | 118 | do_check_false(plugin == null); |
michael@0 | 119 | do_check_true(plugin.disabled); |
michael@0 | 120 | do_check_false(plugin.clicktoplay); |
michael@0 | 121 | |
michael@0 | 122 | // clean up |
michael@0 | 123 | Services.prefs.clearUserPref(statePref); |
michael@0 | 124 | Services.prefs.clearUserPref("plugin.importedState"); |
michael@0 | 125 | copy.remove(true); |
michael@0 | 126 | file.moveTo(pluginDir, null); |
michael@0 | 127 | } |