summaryrefslogtreecommitdiffstats
path: root/dom/plugins/test/mochitest/test_refresh_navigator_plugins.html
blob: e39b3217a547a073d39f5e341c2b25d7a6cb51d6 (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
<!DOCTYPE html>
<!-- bug 820708 -->
<html>
  <head>
    <meta><charset="utf-8"/>
    <title>Test Refreshing navigator.plugins (bug 820708)</title>
    <script type="application/javascript" src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script>
    <script type="application/javascript" src="plugin-utils.js"></script>
  </head>
  <body>
    <script class="testbody" type="application/javascript">
      "use strict";

      SimpleTest.waitForExplicitFinish();
      setTestPluginEnabledState(SpecialPowers.Ci.nsIPluginTag.STATE_ENABLED);

      var pluginHost = Components.classes["@mozilla.org/plugin/host;1"]
                       .getService(Components.interfaces.nsIPluginHost);
      var pluginTags = pluginHost.getPluginTags();
      var nextTest = null;
      var obsService = Components.classes["@mozilla.org/observer-service;1"]
                       .getService(Components.interfaces.nsIObserverService);
      var observer = {
        observe: function(aSubject, aTopic, aData) {
          if (aTopic == "plugin-info-updated") {
            SimpleTest.executeSoon(nextTest);
          }
        }
      };
      obsService.addObserver(observer, "plugin-info-updated", false);

      var navTestPlugin1 = navigator.plugins.namedItem("Test Plug-in");
      ok(navTestPlugin1, "navigator.plugins should have Test Plug-in");
      var tagTestPlugin = null;
      for (var plugin of pluginTags) {
        if (plugin.name == navTestPlugin1.name) {
          tagTestPlugin = plugin;
          break;
        }
      }
      ok(tagTestPlugin, "plugin tags should have Test Plug-in");
      var mimeType = tagTestPlugin.getMimeTypes()[0];
      ok(mimeType, "should have a MIME type for Test Plug-in");
      ok(navigator.mimeTypes[mimeType], "navigator.mimeTypes should have an entry for '" + mimeType + "'");
      ok(!tagTestPlugin.disabled, "test plugin should not be disabled");

      nextTest = testPart2;
      tagTestPlugin.enabledState = Components.interfaces.nsIPluginTag.STATE_DISABLED;

      function testPart2() {
        var navTestPlugin2 = navigator.plugins.namedItem("Test Plug-in");
        ok(!navTestPlugin2, "now navigator.plugins should not have Test Plug-in");
        ok(!navigator.mimeTypes[mimeType], "now navigator.mimeTypes should not have an entry for '" + mimeType + "'");

        nextTest = testPart3;
        tagTestPlugin.enabledState = Components.interfaces.nsIPluginTag.STATE_ENABLED;
      }

      function testPart3() {
        var navTestPlugin3 = navigator.plugins.namedItem("Test Plug-in");
        ok(navTestPlugin3, "now navigator.plugins should have Test Plug-in again");
        ok(navigator.mimeTypes[mimeType], "now navigator.mimeTypes should have an entry for '" + mimeType + "' again");
        obsService.removeObserver(observer, "plugin-info-updated");
        SimpleTest.finish();
      }
    </script>
  </body>
</html>