dom/plugins/test/unit/test_bug455213.js

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/dom/plugins/test/unit/test_bug455213.js	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,90 @@
     1.4 +/* This Source Code Form is subject to the terms of the Mozilla Public
     1.5 + * License, v. 2.0. If a copy of the MPL was not distributed with this
     1.6 + * file, You can obtain one at http://mozilla.org/MPL/2.0/.
     1.7 + */
     1.8 +
     1.9 +Components.utils.import("resource://gre/modules/Services.jsm");
    1.10 +
    1.11 +// Plugin registry uses different field delimeters on different platforms
    1.12 +var DELIM = ":";
    1.13 +if ("@mozilla.org/windows-registry-key;1" in Components.classes)
    1.14 +  DELIM = "|";
    1.15 +
    1.16 +var gProfD = do_get_profile_startup();
    1.17 +var gDirSvc = Cc["@mozilla.org/file/directory_service;1"].
    1.18 +             getService(Ci.nsIProperties);
    1.19 +
    1.20 +// Writes out some plugin registry to the profile
    1.21 +function write_registry(version, info) {
    1.22 +  var header = "Generated File. Do not edit.\n\n";
    1.23 +  header += "[HEADER]\n";
    1.24 +  header += "Version" + DELIM + version + DELIM + "$\n\n";
    1.25 +  header += "[PLUGINS]\n";
    1.26 +
    1.27 +  var registry = gProfD.clone();
    1.28 +  registry.append("pluginreg.dat");
    1.29 +  var foStream = Components.classes["@mozilla.org/network/file-output-stream;1"]
    1.30 +                           .createInstance(Components.interfaces.nsIFileOutputStream);
    1.31 +  // write, create, truncate
    1.32 +  foStream.init(registry, 0x02 | 0x08 | 0x20, 0666, 0);
    1.33 +
    1.34 +  var charset = "UTF-8"; // Can be any character encoding name that Mozilla supports
    1.35 +  var os = Cc["@mozilla.org/intl/converter-output-stream;1"].
    1.36 +           createInstance(Ci.nsIConverterOutputStream);
    1.37 +  os.init(foStream, charset, 0, 0x0000);
    1.38 +
    1.39 +  os.writeString(header);
    1.40 +  os.writeString(info);
    1.41 +  os.close();
    1.42 +}
    1.43 +
    1.44 +function run_test() {
    1.45 +  var plugin = get_test_plugintag();
    1.46 +  do_check_true(plugin == null);
    1.47 +
    1.48 +  var file = get_test_plugin();
    1.49 +  if (!file)
    1.50 +    do_throw("Plugin library not found");
    1.51 +
    1.52 +  // Write out a 0.9 version registry that marks the test plugin as disabled
    1.53 +  var registry = "";
    1.54 +  if (gIsOSX) {
    1.55 +    registry += file.leafName + DELIM + "$\n";
    1.56 +    registry += file.path + DELIM + "$\n";
    1.57 +  } else {
    1.58 +    registry += file.path + DELIM + "$\n";
    1.59 +    registry += DELIM + "$\n";
    1.60 +  }
    1.61 +  registry += file.lastModifiedTime + DELIM + "0" + DELIM + "0" + DELIM + "$\n";
    1.62 +  registry += "Plug-in for testing purposes.\u2122 " + 
    1.63 +                "(\u0939\u093f\u0928\u094d\u0926\u0940 " + 
    1.64 +                "\u4e2d\u6587 " +
    1.65 +                "\u0627\u0644\u0639\u0631\u0628\u064a\u0629)" +
    1.66 +                DELIM + "$\n";
    1.67 +  registry += "Test Plug-in" + DELIM + "$\n";
    1.68 +  registry += "1\n";
    1.69 +  registry += "0" + DELIM + "application/x-test" + DELIM + "Test mimetype" +
    1.70 +              DELIM + "tst" + DELIM + "$\n";
    1.71 +  write_registry("0.9", registry);
    1.72 +
    1.73 +  // Initialise profile folder
    1.74 +  do_get_profile();
    1.75 +
    1.76 +  plugin = get_test_plugintag();
    1.77 +  if (!plugin)
    1.78 +    do_throw("Plugin tag not found");
    1.79 +
    1.80 +  // If the plugin was not rescanned then this version will not be correct
    1.81 +  do_check_eq(plugin.version, "1.0.0.0");
    1.82 +  do_check_eq(plugin.description,
    1.83 +              "Plug-in for testing purposes.\u2122 " + 
    1.84 +                "(\u0939\u093f\u0928\u094d\u0926\u0940 " + 
    1.85 +                "\u4e2d\u6587 " +
    1.86 +                "\u0627\u0644\u0639\u0631\u0628\u064a\u0629)");
    1.87 +  // If the plugin registry was not read then the plugin will not be disabled
    1.88 +  do_check_true(plugin.disabled);
    1.89 +  do_check_false(plugin.blocklisted);
    1.90 +
    1.91 +  // Clean up
    1.92 +  Services.prefs.clearUserPref("plugin.importedState");
    1.93 +}

mercurial