dom/plugins/test/unit/test_bug813245.js

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/dom/plugins/test/unit/test_bug813245.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 +  let runtime = Cc["@mozilla.org/xre/runtime;1"].getService(Ci.nsIXULRuntime);
    1.23 +
    1.24 +  var header = "Generated File. Do not edit.\n\n";
    1.25 +  header += "[HEADER]\n";
    1.26 +  header += "Version" + DELIM + version + DELIM + "$\n";
    1.27 +  header += "Arch" + DELIM + runtime.XPCOMABI + DELIM + "$\n";
    1.28 +  header += "\n";
    1.29 +  header += "[PLUGINS]\n";
    1.30 +
    1.31 +  var registry = gProfD.clone();
    1.32 +  registry.append("pluginreg.dat");
    1.33 +  var foStream = Components.classes["@mozilla.org/network/file-output-stream;1"]
    1.34 +                           .createInstance(Components.interfaces.nsIFileOutputStream);
    1.35 +  // write, create, truncate
    1.36 +  foStream.init(registry, 0x02 | 0x08 | 0x20, 0666, 0);
    1.37 +
    1.38 +  var charset = "UTF-8"; // Can be any character encoding name that Mozilla supports
    1.39 +  var os = Cc["@mozilla.org/intl/converter-output-stream;1"].
    1.40 +           createInstance(Ci.nsIConverterOutputStream);
    1.41 +  os.init(foStream, charset, 0, 0x0000);
    1.42 +
    1.43 +  os.writeString(header);
    1.44 +  os.writeString(info);
    1.45 +  os.close();
    1.46 +}
    1.47 +
    1.48 +function run_test() {
    1.49 +  var plugin = get_test_plugintag();
    1.50 +  do_check_true(plugin == null);
    1.51 +
    1.52 +  var file = get_test_plugin();
    1.53 +  if (!file) {
    1.54 +    do_throw("Plugin library not found");
    1.55 +  }
    1.56 +
    1.57 +  // write plugin registry data
    1.58 +  let registry = "";
    1.59 +
    1.60 +  if (gIsOSX) {
    1.61 +    registry += file.leafName + DELIM + "$\n";
    1.62 +    registry += file.path + DELIM + "$\n";
    1.63 +  } else {
    1.64 +    registry += file.path + DELIM + "$\n";
    1.65 +    registry += DELIM + "$\n";
    1.66 +  }
    1.67 +  registry += "0.0.0.0" + DELIM + "$\n";
    1.68 +  registry += "16725225600" + DELIM + "0" + DELIM + "5" + DELIM + "$\n";
    1.69 +  registry += "Plug-in for testing purposes." + DELIM + "$\n";
    1.70 +  registry += "Test Plug-in" + DELIM + "$\n";
    1.71 +  registry += "999999999999999999999999999999999999999999999999|0|5|$\n";
    1.72 +  registry += "0" + DELIM + "application/x-test" + DELIM + "Test mimetype" +
    1.73 +              DELIM + "tst" + DELIM + "$\n";
    1.74 +
    1.75 +  registry += "\n";
    1.76 +  registry += "[INVALID]\n";
    1.77 +  registry += "\n";
    1.78 +  write_registry("0.15", registry);
    1.79 +
    1.80 +  // Initialise profile folder
    1.81 +  do_get_profile();
    1.82 +
    1.83 +  var plugin = get_test_plugintag();
    1.84 +  if (!plugin)
    1.85 +    do_throw("Plugin tag not found");
    1.86 +
    1.87 +  // The plugin registry should have been rejected.
    1.88 +  // If not, the test plugin version would be 0.0.0.0
    1.89 +  do_check_eq(plugin.version, "1.0.0.0");
    1.90 +
    1.91 +  // Clean up
    1.92 +  Services.prefs.clearUserPref("plugin.importedState");
    1.93 +}

mercurial