dom/plugins/test/unit/test_nice_plugin_name.js

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/dom/plugins/test/unit/test_nice_plugin_name.js	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,117 @@
     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 +const XULAPPINFO_CONTRACTID = "@mozilla.org/xre/app-info;1";
    1.10 +const XULAPPINFO_CID = Components.ID("{c763b610-9d49-455a-bbd2-ede71682a1ac}");
    1.11 +
    1.12 +Components.utils.import("resource://gre/modules/XPCOMUtils.jsm");
    1.13 +Components.utils.import("resource://gre/modules/Services.jsm");
    1.14 +
    1.15 +let gAppInfo = null;
    1.16 +
    1.17 +function createAppInfo(id, name, version, platformVersion) {
    1.18 +  gAppInfo = {
    1.19 +    // nsIXULAppInfo
    1.20 +    vendor: "Mozilla",
    1.21 +    name: name,
    1.22 +    ID: id,
    1.23 +    version: version,
    1.24 +    appBuildID: "2007010101",
    1.25 +    platformVersion: platformVersion ? platformVersion : "1.0",
    1.26 +    platformBuildID: "2007010101",
    1.27 +
    1.28 +    // nsIXULRuntime
    1.29 +    inSafeMode: false,
    1.30 +    logConsoleErrors: true,
    1.31 +    OS: "XPCShell",
    1.32 +    XPCOMABI: "noarch-spidermonkey",
    1.33 +    invalidateCachesOnRestart: function invalidateCachesOnRestart() {
    1.34 +      // Do nothing
    1.35 +    },
    1.36 +
    1.37 +    // nsICrashReporter
    1.38 +    annotations: {},
    1.39 +
    1.40 +    annotateCrashReport: function(key, data) {
    1.41 +      this.annotations[key] = data;
    1.42 +    },
    1.43 +
    1.44 +    QueryInterface: XPCOMUtils.generateQI([Ci.nsIXULAppInfo,
    1.45 +                                           Ci.nsIXULRuntime,
    1.46 +                                           Ci.nsICrashReporter,
    1.47 +                                           Ci.nsISupports])
    1.48 +  };
    1.49 +
    1.50 +  let XULAppInfoFactory = {
    1.51 +    createInstance: function (outer, iid) {
    1.52 +      if (outer != null)
    1.53 +        throw Components.results.NS_ERROR_NO_AGGREGATION;
    1.54 +      return gAppInfo.QueryInterface(iid);
    1.55 +    }
    1.56 +  };
    1.57 +  let registrar = Components.manager.QueryInterface(Ci.nsIComponentRegistrar);
    1.58 +  registrar.registerFactory(XULAPPINFO_CID, "XULAppInfo",
    1.59 +                            XULAPPINFO_CONTRACTID, XULAppInfoFactory);
    1.60 +}
    1.61 +
    1.62 +let gDirSvc = Cc["@mozilla.org/file/directory_service;1"]
    1.63 +                .getService(Ci.nsIProperties);
    1.64 +
    1.65 +let gPluginHost = null;
    1.66 +
    1.67 +function test_expected_permission_string(aPermString) {
    1.68 +  gPluginHost.reloadPlugins(false);
    1.69 +  let plugin = get_test_plugintag();
    1.70 +  do_check_false(plugin == null);
    1.71 +  do_check_eq(gPluginHost.getPermissionStringForType("application/x-test"),
    1.72 +              aPermString);
    1.73 +}
    1.74 +
    1.75 +function run_test() {
    1.76 +  do_check_true(gIsWindows || gIsOSX || gIsLinux);
    1.77 +  do_check_true(!(gIsWindows && gIsOSX) && !(gIsWindows && gIsLinux) &&
    1.78 +                !(gIsOSX && gIsLinux));
    1.79 +
    1.80 +  createAppInfo("xpcshell@tests.mozilla.org", "XPCShell", "1", "1.9");
    1.81 +  gPluginHost = Cc["@mozilla.org/plugin/host;1"].getService(Ci.nsIPluginHost);
    1.82 +
    1.83 +  let expectedDefaultPermissionString = null;
    1.84 +  if (gIsWindows) expectedDefaultPermissionString = "plugin:nptest";
    1.85 +  if (gIsOSX) expectedDefaultPermissionString = "plugin:test";
    1.86 +  if (gIsLinux) expectedDefaultPermissionString = "plugin:libnptest";
    1.87 +  test_expected_permission_string(expectedDefaultPermissionString);
    1.88 +
    1.89 +  let suffix = get_platform_specific_plugin_suffix();
    1.90 +  let pluginFile = get_test_plugin_no_symlink();
    1.91 +  let pluginDir = pluginFile.parent;
    1.92 +  pluginFile.copyTo(null, "npblah235" + suffix);
    1.93 +  let pluginCopy = pluginDir.clone();
    1.94 +  pluginCopy.append("npblah235" + suffix);
    1.95 +  let tempDir = do_get_tempdir();
    1.96 +  pluginFile.moveTo(tempDir, null);
    1.97 +  test_expected_permission_string("plugin:npblah");
    1.98 +
    1.99 +  pluginCopy.moveTo(null, "npasdf-3.2.2" + suffix);
   1.100 +  test_expected_permission_string("plugin:npasdf");
   1.101 +
   1.102 +  pluginCopy.moveTo(null, "npasdf_##29387!{}{[][" + suffix);
   1.103 +  test_expected_permission_string("plugin:npasdf");
   1.104 +
   1.105 +  pluginCopy.moveTo(null, "npqtplugin7" + suffix);
   1.106 +  test_expected_permission_string("plugin:npqtplugin");
   1.107 +
   1.108 +  pluginCopy.moveTo(null, "npFoo3d" + suffix);
   1.109 +  test_expected_permission_string("plugin:npfoo3d");
   1.110 +
   1.111 +  pluginCopy.moveTo(null, "NPSWF32_11_5_502_146" + suffix);
   1.112 +  test_expected_permission_string("plugin:npswf");
   1.113 +
   1.114 +  pluginCopy.remove(true);
   1.115 +  pluginFile.moveTo(pluginDir, null);
   1.116 +  test_expected_permission_string(expectedDefaultPermissionString);
   1.117 +
   1.118 +  // Clean up
   1.119 +  Services.prefs.clearUserPref("plugin.importedState");
   1.120 +}

mercurial