merge 3ec83fde43f2e1ba1dc583df0c722033c63ab7b7 into stylo upstream draft
authorVCS Sync <vcs-sync@mozilla.com>
Tue, 06 Dec 2016 14:48:56 +0000
changeset 457973 7be87e2c099eda26d48a7549191cf2312e988c7c
parent 457972 57155f04277bb64b309f2cc6272b2d6df18132dd (current diff)
parent 447614 3ec83fde43f2e1ba1dc583df0c722033c63ab7b7 (diff)
child 457974 f4f3111ef6877bafe0903f0f056c688d38a2c2f8
push id40933
push userbmo:slyu@mozilla.com
push dateTue, 10 Jan 2017 06:53:24 +0000
milestone53.0a1
merge 3ec83fde43f2e1ba1dc583df0c722033c63ab7b7 into stylo upstream
--- a/browser/base/content/test/plugins/browser.ini
+++ b/browser/base/content/test/plugins/browser.ini
@@ -57,16 +57,17 @@ skip-if = !crashreporter
 [browser_CTP_multi_allow.js]
 [browser_CTP_nonplugins.js]
 [browser_CTP_notificationBar.js]
 [browser_CTP_outsideScrollArea.js]
 [browser_CTP_remove_navigate.js]
 [browser_CTP_resize.js]
 [browser_CTP_zoom.js]
 [browser_blocking.js]
+[browser_iterate_hidden_plugins.js]
 [browser_plugins_added_dynamically.js]
 [browser_pluginnotification.js]
 [browser_plugin_reloading.js]
 [browser_blocklist_content.js]
 skip-if = !e10s
 [browser_globalplugin_crashinfobar.js]
 skip-if = !crashreporter
 [browser_pluginCrashCommentAndURL.js]
new file mode 100644
--- /dev/null
+++ b/browser/base/content/test/plugins/browser_iterate_hidden_plugins.js
@@ -0,0 +1,125 @@
+"use strict";
+
+const TEST_PLUGIN_NAME = "Test Plug-in";
+const HIDDEN_CTP_PLUGIN_PREF = "plugins.navigator.hidden_ctp_plugin";
+
+/**
+ * If a plugin is click-to-play and named in HIDDEN_CTP_PLUGIN_PREF,
+ * then the plugin should be hidden in the navigator.plugins list by default
+ * when iterating. If, however, JS attempts to access the plugin via
+ * navigator.plugins[NAME] directly, we should show the "Hidden Plugin"
+ * notification bar.
+ */
+
+add_task(function* setup() {
+  // We'll make the Test Plugin click-to-play.
+  let originalPluginState = getTestPluginEnabledState();
+  setTestPluginEnabledState(Ci.nsIPluginTag.STATE_CLICKTOPLAY);
+  registerCleanupFunction(() => {
+    setTestPluginEnabledState(originalPluginState);
+  });
+
+  // And then make the plugin hidden.
+  yield SpecialPowers.pushPrefEnv({
+    set: [[HIDDEN_CTP_PLUGIN_PREF, TEST_PLUGIN_NAME]],
+  })
+});
+
+/**
+ * Tests that if a plugin is click-to-play and in the
+ * HIDDEN_CTP_PLUGIN_PREF list, then it shouldn't be visible
+ * when iterating navigator.plugins.
+ */
+add_task(function* test_plugin_is_hidden_on_iteration() {
+  // The plugin should not be visible when we iterate
+  // navigator.plugins.
+  yield BrowserTestUtils.withNewTab({
+    gBrowser,
+    url: "http://example.com"
+  }, function*(browser) {
+    yield ContentTask.spawn(browser, TEST_PLUGIN_NAME, function*(pluginName) {
+      let plugins = Array.from(content.navigator.plugins);
+      Assert.ok(plugins.every(p => p.name != pluginName),
+                "Should not find Test Plugin");
+    });
+  });
+
+  // Now clear the HIDDEN_CTP_PLUGIN_PREF temporarily and
+  // make sure we can see the plugin again.
+  yield SpecialPowers.pushPrefEnv({
+    set: [[HIDDEN_CTP_PLUGIN_PREF, ""]],
+  });
+
+  // Note that I have to do this in a new tab since navigator
+  // caches navigator.plugins after an initial read.
+  yield BrowserTestUtils.withNewTab({
+    gBrowser,
+    url: "http://example.com"
+  }, function*(browser) {
+    yield ContentTask.spawn(browser, TEST_PLUGIN_NAME, function*(pluginName) {
+      let plugins = Array.from(content.navigator.plugins);
+      Assert.ok(plugins.some(p => p.name == pluginName),
+                "Should have found the Test Plugin");
+    });
+  });
+
+  yield SpecialPowers.popPrefEnv();
+});
+
+/**
+ * Tests that if a click-to-play plugin is hidden, that we show the
+ * Hidden Plugin notification bar when accessed directly by name
+ * via navigator.plugins.
+ */
+add_task(function* test_plugin_shows_hidden_notification_on_access() {
+  yield BrowserTestUtils.withNewTab({
+    gBrowser,
+    url: "http://example.com"
+  }, function*(browser) {
+    let notificationPromise = waitForNotificationBar("plugin-hidden", gBrowser.selectedBrowser);
+
+    yield ContentTask.spawn(browser, TEST_PLUGIN_NAME, function*(pluginName) {
+      let plugins = content.navigator.plugins;
+      // Just accessing the plugin should be enough to trigger the notification.
+      // We'll also do a sanity check and make sure that the HiddenPlugin event
+      // is firing (which is the event that triggers the notification bar).
+      let sawEvent = false;
+      addEventListener("HiddenPlugin", function onHiddenPlugin(e) {
+        sawEvent = true;
+        removeEventListener("HiddenPlugin", onHiddenPlugin, true);
+      }, true);
+      plugins[pluginName];
+      Assert.ok(sawEvent, "Should have seen the HiddenPlugin event.");
+    });
+
+    let notification = yield notificationPromise;
+    notification.close();
+  });
+
+  // Make sure that if the plugin wasn't hidden that touching it
+  // does _NOT_ show the notification bar.
+  yield SpecialPowers.pushPrefEnv({
+    set: [[HIDDEN_CTP_PLUGIN_PREF, ""]],
+  });
+
+  yield BrowserTestUtils.withNewTab({
+    gBrowser,
+    url: "http://example.com"
+  }, function*(browser) {
+    yield ContentTask.spawn(browser, TEST_PLUGIN_NAME, function*(pluginName) {
+      let plugins = content.navigator.plugins;
+      // Instead of waiting for a notification bar that should never come,
+      // we'll make sure that the HiddenPlugin event never fires in content
+      // (which is the event that triggers the notification bar).
+      let sawEvent = false;
+      addEventListener("HiddenPlugin", function onHiddenPlugin(e) {
+        sawEvent = true;
+        removeEventListener("HiddenPlugin", onHiddenPlugin, true);
+      }, true);
+      plugins[pluginName];
+      Assert.ok(!sawEvent, "Should not have seen the HiddenPlugin event.");
+    });
+  });
+
+  yield SpecialPowers.popPrefEnv();
+});