dom/plugins/test/mochitest/test_refresh_navigator_plugins.html
author Sebastian Hengst <archaeopteryx@coole-files.de>
Fri, 14 Apr 2017 23:39:22 +0200
changeset 401420 d523c49136775a7187486dbc96858a2cb0383bfb
parent 401401 322fde2d53bf49266dbc293321e6b36a4c789c12
child 401430 56bf52d4ddeb1dc7019c4f9e23961670d0a31414
permissions -rw-r--r--
Backed out changeset 322fde2d53bf (bug 1356569) so bug 1355161 can be backed out. r=backout

<!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>