dom/plugins/test/mochitest/test_secondPlugin.html

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/dom/plugins/test/mochitest/test_secondPlugin.html	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,72 @@
     1.4 +<html>
     1.5 +  <head>
     1.6 +     <title>Second Test Plug-in Test</title>
     1.7 +
     1.8 +    <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
     1.9 +    <script type="text/javascript" src="utils.js"></script>
    1.10 +    <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
    1.11 +  </head>
    1.12 +
    1.13 +  <body onload="run()">
    1.14 +    <script class="testbody" type="application/javascript">
    1.15 +      "use strict";
    1.16 +
    1.17 +      SimpleTest.waitForExplicitFinish();
    1.18 +      setTestPluginEnabledState(SpecialPowers.Ci.nsIPluginTag.STATE_ENABLED);
    1.19 +      setTestPluginEnabledState(SpecialPowers.Ci.nsIPluginTag.STATE_ENABLED, "Second Test Plug-in");
    1.20 +
    1.21 +      function findPlugin(pluginName) {
    1.22 +          for (var i = 0; i < navigator.plugins.length; i++) {
    1.23 +            var plugin = navigator.plugins[i];
    1.24 +            if (plugin.name === pluginName) {
    1.25 +              return plugin;
    1.26 +            }
    1.27 +          }
    1.28 +          return null;
    1.29 +      }
    1.30 +
    1.31 +      function findMimeType(mimeTypeType) {
    1.32 +          for (var i = 0; i < navigator.mimeTypes.length; i++) {
    1.33 +            var mimeType = navigator.mimeTypes[i];
    1.34 +            if (mimeType.type === mimeTypeType) {
    1.35 +              return mimeType;
    1.36 +            }
    1.37 +          }
    1.38 +          return null;
    1.39 +      }
    1.40 +
    1.41 +      function run() {
    1.42 +        // Add "Test Plug-in" (but not "Second Test Plug-in") to the list of
    1.43 +        // unhidden plugins. This test must modify the "plugins.enumerable_names"
    1.44 +        // pref BEFORE accessing the navigator.plugins or navigator.mimeTypes
    1.45 +        // arrays because they only read the pref when they first initialize
    1.46 +        // their internal arrays!
    1.47 +        var prefs = SpecialPowers.Cc["@mozilla.org/preferences-service;1"].getService(SpecialPowers.Ci.nsIPrefBranch);
    1.48 +        var defaultEnumerableNamesPref = prefs.getCharPref("plugins.enumerable_names");
    1.49 +        prefs.setCharPref("plugins.enumerable_names", defaultEnumerableNamesPref + ",Test Plug-in");
    1.50 +
    1.51 +        var pluginElement = document.getElementById("plugin");
    1.52 +        is(pluginElement.identifierToStringTest("foo"), "foo", "Should be able to call a function provided by the plugin");
    1.53 +
    1.54 +        ok(navigator.plugins["Test Plug-in"], "Should have queried a non-hidden plugin named 'Test Plug-in'");
    1.55 +        ok(navigator.plugins["Second Test Plug-in"], "Should have queried a hidden plugin named 'Test Plug-in'");
    1.56 +
    1.57 +        ok(findPlugin("Test Plug-in"), "Should have found a non-hidden plugin named 'Test Plug-in'");
    1.58 +        ok(!findPlugin("Second Test Plug-in"), "Should NOT found a hidden plugin named 'Test Plug-in'");
    1.59 +
    1.60 +        ok(navigator.mimeTypes["application/x-test"], "Should have queried a non-hidden MIME type named 'application/x-test'");
    1.61 +        ok(navigator.mimeTypes["application/x-second-test"], "Should have queried a MIME type named 'application/x-second-test'");
    1.62 +
    1.63 +        ok(findMimeType("application/x-test"), "Should have found a non-hidden MIME type named 'application/x-test'");
    1.64 +        ok(!findMimeType("application/x-second-test"), "Should NOT have found a MIME type named 'application/x-second-test'");
    1.65 +
    1.66 +        // Restore original pref to hide "Test Plug-in" and "Second Test Plug-in".
    1.67 +        prefs.setCharPref("plugins.enumerable_names", defaultEnumerableNamesPref);
    1.68 +
    1.69 +        SimpleTest.finish();
    1.70 +      }
    1.71 +    </script>
    1.72 +
    1.73 +    <object id="plugin" type="application/x-second-test" width=200 height=200></object>
    1.74 +  </body>
    1.75 +</html>

mercurial