dom/plugins/test/unit/test_nice_plugin_name.js

Thu, 22 Jan 2015 13:21:57 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 22 Jan 2015 13:21:57 +0100
branch
TOR_BUG_9701
changeset 15
b8a032363ba2
permissions
-rw-r--r--

Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6

     1 /* This Source Code Form is subject to the terms of the Mozilla Public
     2  * License, v. 2.0. If a copy of the MPL was not distributed with this
     3  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
     4  */
     6 const XULAPPINFO_CONTRACTID = "@mozilla.org/xre/app-info;1";
     7 const XULAPPINFO_CID = Components.ID("{c763b610-9d49-455a-bbd2-ede71682a1ac}");
     9 Components.utils.import("resource://gre/modules/XPCOMUtils.jsm");
    10 Components.utils.import("resource://gre/modules/Services.jsm");
    12 let gAppInfo = null;
    14 function createAppInfo(id, name, version, platformVersion) {
    15   gAppInfo = {
    16     // nsIXULAppInfo
    17     vendor: "Mozilla",
    18     name: name,
    19     ID: id,
    20     version: version,
    21     appBuildID: "2007010101",
    22     platformVersion: platformVersion ? platformVersion : "1.0",
    23     platformBuildID: "2007010101",
    25     // nsIXULRuntime
    26     inSafeMode: false,
    27     logConsoleErrors: true,
    28     OS: "XPCShell",
    29     XPCOMABI: "noarch-spidermonkey",
    30     invalidateCachesOnRestart: function invalidateCachesOnRestart() {
    31       // Do nothing
    32     },
    34     // nsICrashReporter
    35     annotations: {},
    37     annotateCrashReport: function(key, data) {
    38       this.annotations[key] = data;
    39     },
    41     QueryInterface: XPCOMUtils.generateQI([Ci.nsIXULAppInfo,
    42                                            Ci.nsIXULRuntime,
    43                                            Ci.nsICrashReporter,
    44                                            Ci.nsISupports])
    45   };
    47   let XULAppInfoFactory = {
    48     createInstance: function (outer, iid) {
    49       if (outer != null)
    50         throw Components.results.NS_ERROR_NO_AGGREGATION;
    51       return gAppInfo.QueryInterface(iid);
    52     }
    53   };
    54   let registrar = Components.manager.QueryInterface(Ci.nsIComponentRegistrar);
    55   registrar.registerFactory(XULAPPINFO_CID, "XULAppInfo",
    56                             XULAPPINFO_CONTRACTID, XULAppInfoFactory);
    57 }
    59 let gDirSvc = Cc["@mozilla.org/file/directory_service;1"]
    60                 .getService(Ci.nsIProperties);
    62 let gPluginHost = null;
    64 function test_expected_permission_string(aPermString) {
    65   gPluginHost.reloadPlugins(false);
    66   let plugin = get_test_plugintag();
    67   do_check_false(plugin == null);
    68   do_check_eq(gPluginHost.getPermissionStringForType("application/x-test"),
    69               aPermString);
    70 }
    72 function run_test() {
    73   do_check_true(gIsWindows || gIsOSX || gIsLinux);
    74   do_check_true(!(gIsWindows && gIsOSX) && !(gIsWindows && gIsLinux) &&
    75                 !(gIsOSX && gIsLinux));
    77   createAppInfo("xpcshell@tests.mozilla.org", "XPCShell", "1", "1.9");
    78   gPluginHost = Cc["@mozilla.org/plugin/host;1"].getService(Ci.nsIPluginHost);
    80   let expectedDefaultPermissionString = null;
    81   if (gIsWindows) expectedDefaultPermissionString = "plugin:nptest";
    82   if (gIsOSX) expectedDefaultPermissionString = "plugin:test";
    83   if (gIsLinux) expectedDefaultPermissionString = "plugin:libnptest";
    84   test_expected_permission_string(expectedDefaultPermissionString);
    86   let suffix = get_platform_specific_plugin_suffix();
    87   let pluginFile = get_test_plugin_no_symlink();
    88   let pluginDir = pluginFile.parent;
    89   pluginFile.copyTo(null, "npblah235" + suffix);
    90   let pluginCopy = pluginDir.clone();
    91   pluginCopy.append("npblah235" + suffix);
    92   let tempDir = do_get_tempdir();
    93   pluginFile.moveTo(tempDir, null);
    94   test_expected_permission_string("plugin:npblah");
    96   pluginCopy.moveTo(null, "npasdf-3.2.2" + suffix);
    97   test_expected_permission_string("plugin:npasdf");
    99   pluginCopy.moveTo(null, "npasdf_##29387!{}{[][" + suffix);
   100   test_expected_permission_string("plugin:npasdf");
   102   pluginCopy.moveTo(null, "npqtplugin7" + suffix);
   103   test_expected_permission_string("plugin:npqtplugin");
   105   pluginCopy.moveTo(null, "npFoo3d" + suffix);
   106   test_expected_permission_string("plugin:npfoo3d");
   108   pluginCopy.moveTo(null, "NPSWF32_11_5_502_146" + suffix);
   109   test_expected_permission_string("plugin:npswf");
   111   pluginCopy.remove(true);
   112   pluginFile.moveTo(pluginDir, null);
   113   test_expected_permission_string(expectedDefaultPermissionString);
   115   // Clean up
   116   Services.prefs.clearUserPref("plugin.importedState");
   117 }

mercurial