summaryrefslogtreecommitdiffstats
path: root/dom/plugins/test/mochitest/test_secondPlugin.html
blob: 4c1f051ca3f599d95305ef66c3e81edede4952c5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
<html>
  <head>
     <title>Second Test Plug-in Test</title>

    <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
    <script type="text/javascript" src="plugin-utils.js"></script>
    <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
  </head>

  <body onload="run()">
    <script class="testbody" type="application/javascript">
      "use strict";

      SimpleTest.waitForExplicitFinish();
      setTestPluginEnabledState(SpecialPowers.Ci.nsIPluginTag.STATE_ENABLED);
      setTestPluginEnabledState(SpecialPowers.Ci.nsIPluginTag.STATE_DISABLED, "Second Test Plug-in");
      setTestPluginEnabledState(SpecialPowers.Ci.nsIPluginTag.STATE_CLICKTOPLAY, "Java Test Plug-in");

      function findPlugin(pluginName) {
          for (var i = 0; i < navigator.plugins.length; i++) {
            var plugin = navigator.plugins[i];
            if (plugin.name === pluginName) {
              return plugin;
            }
          }
          return null;
      }

      function findMimeType(mimeTypeType) {
          for (var i = 0; i < navigator.mimeTypes.length; i++) {
            var mimeType = navigator.mimeTypes[i];
            if (mimeType.type === mimeTypeType) {
              return mimeType;
            }
          }
          return null;
      }

      function run() {
        var pluginElement = document.getElementById("plugin");
        is(pluginElement.identifierToStringTest("foo"), "foo", "Should be able to call a function provided by the plugin");

        pluginElement = document.getElementById("disabledPlugin");
        is(typeof pluginElement.identifierToStringTest, "undefined", "Should NOT be able to call a function on a disabled plugin");

        pluginElement = document.getElementById("clickToPlayPlugin");
        is(typeof pluginElement.identifierToStringTest, "undefined", "Should NOT be able to call a function on a click-to-play plugin");

        ok(navigator.plugins["Test Plug-in"], "Should have queried a plugin named 'Test Plug-in'");
        ok(!navigator.plugins["Second Test Plug-in"], "Should NOT have queried a disabled plugin named 'Second Test Plug-in'");
        ok(navigator.plugins["Java Test Plug-in"], "Should have queried a click-to-play plugin named 'Java Test Plug-in'");

        ok(findPlugin("Test Plug-in"), "Should have found a plugin named 'Test Plug-in'");
        ok(!findPlugin("Second Test Plug-in"), "Should NOT found a disabled plugin named 'Second Test Plug-in'");
        ok(findPlugin("Java Test Plug-in"), "Should have found a click-to-play plugin named 'Java Test Plug-in'");

        ok(navigator.mimeTypes["application/x-test"], "Should have queried a MIME type named 'application/x-test'");
        ok(!navigator.mimeTypes["application/x-second-test"], "Should NOT have queried a disabled type named 'application/x-second-test'");
        ok(navigator.mimeTypes["application/x-java-test"], "Should have queried a click-to-play MIME type named 'application/x-java-test'");

        ok(findMimeType("application/x-test"), "Should have found a MIME type named 'application/x-test'");
        ok(!findMimeType("application/x-second-test"), "Should NOT have found a disabled MIME type named 'application/x-second-test'");
        ok(findMimeType("application/x-java-test"), "Should have found a click-to-play MIME type named 'application/x-java-test'");

        SimpleTest.finish();
      }
    </script>

    <object id="plugin" type="application/x-test" width=200 height=200></object>
    <object id="disabledPlugin" type="application/x-second-test" width=200 height=200></object>
    <object id="clickToPlayPlugin" type="application/x-java-test" width=200 height=200></object>
  </body>
</html>