dom/plugins/test/mochitest/test_secondPlugin.html

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

michael@0 1 <html>
michael@0 2 <head>
michael@0 3 <title>Second Test Plug-in Test</title>
michael@0 4
michael@0 5 <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
michael@0 6 <script type="text/javascript" src="utils.js"></script>
michael@0 7 <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
michael@0 8 </head>
michael@0 9
michael@0 10 <body onload="run()">
michael@0 11 <script class="testbody" type="application/javascript">
michael@0 12 "use strict";
michael@0 13
michael@0 14 SimpleTest.waitForExplicitFinish();
michael@0 15 setTestPluginEnabledState(SpecialPowers.Ci.nsIPluginTag.STATE_ENABLED);
michael@0 16 setTestPluginEnabledState(SpecialPowers.Ci.nsIPluginTag.STATE_ENABLED, "Second Test Plug-in");
michael@0 17
michael@0 18 function findPlugin(pluginName) {
michael@0 19 for (var i = 0; i < navigator.plugins.length; i++) {
michael@0 20 var plugin = navigator.plugins[i];
michael@0 21 if (plugin.name === pluginName) {
michael@0 22 return plugin;
michael@0 23 }
michael@0 24 }
michael@0 25 return null;
michael@0 26 }
michael@0 27
michael@0 28 function findMimeType(mimeTypeType) {
michael@0 29 for (var i = 0; i < navigator.mimeTypes.length; i++) {
michael@0 30 var mimeType = navigator.mimeTypes[i];
michael@0 31 if (mimeType.type === mimeTypeType) {
michael@0 32 return mimeType;
michael@0 33 }
michael@0 34 }
michael@0 35 return null;
michael@0 36 }
michael@0 37
michael@0 38 function run() {
michael@0 39 // Add "Test Plug-in" (but not "Second Test Plug-in") to the list of
michael@0 40 // unhidden plugins. This test must modify the "plugins.enumerable_names"
michael@0 41 // pref BEFORE accessing the navigator.plugins or navigator.mimeTypes
michael@0 42 // arrays because they only read the pref when they first initialize
michael@0 43 // their internal arrays!
michael@0 44 var prefs = SpecialPowers.Cc["@mozilla.org/preferences-service;1"].getService(SpecialPowers.Ci.nsIPrefBranch);
michael@0 45 var defaultEnumerableNamesPref = prefs.getCharPref("plugins.enumerable_names");
michael@0 46 prefs.setCharPref("plugins.enumerable_names", defaultEnumerableNamesPref + ",Test Plug-in");
michael@0 47
michael@0 48 var pluginElement = document.getElementById("plugin");
michael@0 49 is(pluginElement.identifierToStringTest("foo"), "foo", "Should be able to call a function provided by the plugin");
michael@0 50
michael@0 51 ok(navigator.plugins["Test Plug-in"], "Should have queried a non-hidden plugin named 'Test Plug-in'");
michael@0 52 ok(navigator.plugins["Second Test Plug-in"], "Should have queried a hidden plugin named 'Test Plug-in'");
michael@0 53
michael@0 54 ok(findPlugin("Test Plug-in"), "Should have found a non-hidden plugin named 'Test Plug-in'");
michael@0 55 ok(!findPlugin("Second Test Plug-in"), "Should NOT found a hidden plugin named 'Test Plug-in'");
michael@0 56
michael@0 57 ok(navigator.mimeTypes["application/x-test"], "Should have queried a non-hidden MIME type named 'application/x-test'");
michael@0 58 ok(navigator.mimeTypes["application/x-second-test"], "Should have queried a MIME type named 'application/x-second-test'");
michael@0 59
michael@0 60 ok(findMimeType("application/x-test"), "Should have found a non-hidden MIME type named 'application/x-test'");
michael@0 61 ok(!findMimeType("application/x-second-test"), "Should NOT have found a MIME type named 'application/x-second-test'");
michael@0 62
michael@0 63 // Restore original pref to hide "Test Plug-in" and "Second Test Plug-in".
michael@0 64 prefs.setCharPref("plugins.enumerable_names", defaultEnumerableNamesPref);
michael@0 65
michael@0 66 SimpleTest.finish();
michael@0 67 }
michael@0 68 </script>
michael@0 69
michael@0 70 <object id="plugin" type="application/x-second-test" width=200 height=200></object>
michael@0 71 </body>
michael@0 72 </html>

mercurial