summaryrefslogtreecommitdiffstats
path: root/dom/plugins/test/mochitest/test_bug1165981.html
blob: 360d9312ad223b5b69a9853f0560d13974b0117c (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
74
75
76
77
78
79
80
81
<html>
  <head>
     <title>Bug 1165981 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>
    <script class="testbody" type="application/javascript">
      "use strict";

      SimpleTest.waitForExplicitFinish();
      ok(SpecialPowers.setTestPluginEnabledState(SpecialPowers.Ci.nsIPluginTag.STATE_ENABLED, "Shockwave Flash"), "Should find allowed test flash plugin");
      ok(SpecialPowers.setTestPluginEnabledState(SpecialPowers.Ci.nsIPluginTag.STATE_ENABLED, "Silverlight Test Plug-in"), "Should find allowed test silverlight plugin");
      ok(!SpecialPowers.setTestPluginEnabledState(SpecialPowers.Ci.nsIPluginTag.STATE_ENABLED, "Third Test Plug-in"), "Should not find disallowed plugin");

      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 createNode(id, type) {
          let obj = document.createElement("object");
          obj.type = type;
          obj.id = id;
          obj.width = 200;
          obj.height = 200;
          document.body.appendChild(obj);
      }

      function run() {
        createNode("plugin-flash", "application/x-shockwave-flash-test");
        createNode("plugin-silverlight", "application/x-silverlight-test");
        createNode("disallowedPlugin", "application/x-third-test");
        var pluginElement = document.getElementById("plugin-flash");
        is(pluginElement.identifierToStringTest("foo"), "foo", "Should be able to call a function provided by the plugin");

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

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

        ok(navigator.plugins["Shockwave Flash"], "Should have queried a plugin named 'Shockwave Flash'");
        ok(navigator.plugins["Silverlight Test Plug-in"], "Should have queried a plugin named 'Silverlight Test Plug-in'");
        ok(!navigator.plugins["Third Test Plug-in"], "Should NOT have queried a disallowed plugin named 'Third Test Plug-in'");

        ok(findPlugin("Shockwave Flash"), "Should have found a plugin named 'Shockwave Flash'");
        ok(findPlugin("Silverlight Test Plug-in"), "Should have found a plugin named 'Silverlight Test Plug-in'");
        ok(!findPlugin("Third Test Plug-in"), "Should NOT found a disallowed plugin named 'Third Test Plug-in'");

        ok(navigator.mimeTypes["application/x-shockwave-flash-test"], "Should have queried a MIME type named 'application/x-shockwave-flash-test'");
        ok(navigator.mimeTypes["application/x-silverlight-test"], "Should have queried a MIME type named 'application/x-silverlight-test'");
        ok(!navigator.mimeTypes["application/x-third-test"], "Should NOT have queried a disallowed type named 'application/x-third-test'");

        ok(findMimeType("application/x-shockwave-flash-test"), "Should have found a MIME type named 'application/x-shockwave-flash-test'");
        ok(findMimeType("application/x-silverlight-test"), "Should have found a MIME type named 'application/x-silverlight-test'");
        ok(!findMimeType("application/x-third-test"), "Should NOT have found a disallowed MIME type named 'application/x-third-test'");

        SimpleTest.finish();
      }
    </script>

  <body onload="run()">
  </body>
</html>