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