browser/base/content/test/plugins/browser_CTP_notificationBar.js

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/browser/base/content/test/plugins/browser_CTP_notificationBar.js	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,179 @@
     1.4 +var rootDir = getRootDirectory(gTestPath);
     1.5 +const gTestRoot = rootDir;
     1.6 +const gHttpTestRoot = rootDir.replace("chrome://mochitests/content/", "http://127.0.0.1:8888/");
     1.7 +
     1.8 +var gTestBrowser = null;
     1.9 +var gNextTest = null;
    1.10 +
    1.11 +Components.utils.import("resource://gre/modules/Services.jsm");
    1.12 +
    1.13 +function test() {
    1.14 +  waitForExplicitFinish();
    1.15 +  registerCleanupFunction(function() {
    1.16 +    clearAllPluginPermissions();
    1.17 +    Services.prefs.clearUserPref("extensions.blocklist.suppressUI");
    1.18 +  });
    1.19 +  Services.prefs.setBoolPref("extensions.blocklist.suppressUI", true);
    1.20 +
    1.21 +  var newTab = gBrowser.addTab();
    1.22 +  gBrowser.selectedTab = newTab;
    1.23 +  gTestBrowser = gBrowser.selectedBrowser;
    1.24 +  gTestBrowser.addEventListener("load", pageLoad, true);
    1.25 +
    1.26 +  Services.prefs.setBoolPref("plugins.click_to_play", true);
    1.27 +  setTestPluginEnabledState(Ci.nsIPluginTag.STATE_CLICKTOPLAY);
    1.28 +
    1.29 +  prepareTest(runAfterPluginBindingAttached(test1), gHttpTestRoot + "plugin_small.html");
    1.30 +}
    1.31 +
    1.32 +function finishTest() {
    1.33 +  gTestBrowser.removeEventListener("load", pageLoad, true);
    1.34 +  gBrowser.removeCurrentTab();
    1.35 +  window.focus();
    1.36 +  finish();
    1.37 +}
    1.38 +
    1.39 +function pageLoad() {
    1.40 +  // The plugin events are async dispatched and can come after the load event
    1.41 +  // This just allows the events to fire before we then go on to test the states
    1.42 +  executeSoon(gNextTest);
    1.43 +}
    1.44 +
    1.45 +function prepareTest(nextTest, url) {
    1.46 +  gNextTest = nextTest;
    1.47 +  gTestBrowser.contentWindow.location = url;
    1.48 +}
    1.49 +
    1.50 +// Due to layout being async, "PluginBindAttached" may trigger later.
    1.51 +// This wraps a function to force a layout flush, thus triggering it,
    1.52 +// and schedules the function execution so they're definitely executed
    1.53 +// afterwards.
    1.54 +function runAfterPluginBindingAttached(func) {
    1.55 +  return function() {
    1.56 +    let doc = gTestBrowser.contentDocument;
    1.57 +    let elems = doc.getElementsByTagName('embed');
    1.58 +    if (elems.length < 1) {
    1.59 +      elems = doc.getElementsByTagName('object');
    1.60 +    }
    1.61 +    elems[0].clientTop;
    1.62 +    executeSoon(func);
    1.63 +  };
    1.64 +}
    1.65 +
    1.66 +// Tests for the notification bar for hidden plugins.
    1.67 +
    1.68 +function test1() {
    1.69 +  let notification = PopupNotifications.getNotification("click-to-play-plugins");
    1.70 +  ok(notification, "Test 1: There should be a plugin notification");
    1.71 +
    1.72 +  let notificationBox = gBrowser.getNotificationBox(gTestBrowser);
    1.73 +
    1.74 +  waitForCondition(() => notificationBox.getNotificationWithValue("plugin-hidden") !== null,
    1.75 +    () => {
    1.76 +      // Don't use setTestPluginEnabledState here because we already saved the
    1.77 +      // prior value
    1.78 +      getTestPlugin().enabledState = Ci.nsIPluginTag.STATE_ENABLED;
    1.79 +      prepareTest(test2, gTestRoot + "plugin_small.html");
    1.80 +    },
    1.81 +    "Test 1, expected to have a plugin notification bar");
    1.82 +}
    1.83 +
    1.84 +function test2() {
    1.85 +  let notification = PopupNotifications.getNotification("click-to-play-plugins");
    1.86 +  ok(notification, "Test 2: There should be a plugin notification");
    1.87 +
    1.88 +  let notificationBox = gBrowser.getNotificationBox(gTestBrowser);
    1.89 +
    1.90 +  waitForCondition(() => notificationBox.getNotificationWithValue("plugin-hidden") === null,
    1.91 +    () => {
    1.92 +      getTestPlugin().enabledState = Ci.nsIPluginTag.STATE_CLICKTOPLAY;
    1.93 +      prepareTest(test3, gTestRoot + "plugin_overlayed.html");
    1.94 +    },
    1.95 +    "Test 2, expected to not have a plugin notification bar");
    1.96 +}
    1.97 +
    1.98 +function test3() {
    1.99 +  let notification = PopupNotifications.getNotification("click-to-play-plugins");
   1.100 +  ok(notification, "Test 3: There should be a plugin notification");
   1.101 +
   1.102 +  let notificationBox = gBrowser.getNotificationBox(gTestBrowser);
   1.103 +  waitForCondition(() => notificationBox.getNotificationWithValue("plugin-hidden") !== null,
   1.104 +    test3b,
   1.105 +    "Test 3, expected the plugin infobar to be triggered when plugin was overlayed");
   1.106 +}
   1.107 +
   1.108 +function test3b()
   1.109 +{
   1.110 +  let doc = gTestBrowser.contentDocument;
   1.111 +  let plugin = doc.getElementById("test");
   1.112 +  ok(plugin, "Test 3b, Found plugin in page");
   1.113 +  plugin.QueryInterface(Ci.nsIObjectLoadingContent);
   1.114 +  is(plugin.pluginFallbackType, Ci.nsIObjectLoadingContent.PLUGIN_CLICK_TO_PLAY,
   1.115 +     "Test 3b, plugin fallback type should be PLUGIN_CLICK_TO_PLAY");
   1.116 +  ok(!plugin.activated, "Test 3b, Plugin should not be activated");
   1.117 +  let overlay = doc.getAnonymousElementByAttribute(plugin, "anonid", "main");
   1.118 +  ok(!overlay.classList.contains("visible"), "Test 3b, Plugin overlay should be hidden");
   1.119 +
   1.120 +  prepareTest(test4, gTestRoot + "plugin_positioned.html");
   1.121 +}
   1.122 +
   1.123 +function test4() {
   1.124 +  let notification = PopupNotifications.getNotification("click-to-play-plugins");
   1.125 +  ok(notification, "Test 4: There should be a plugin notification");
   1.126 +
   1.127 +  let notificationBox = gBrowser.getNotificationBox(gTestBrowser);
   1.128 +  waitForCondition(() => notificationBox.getNotificationWithValue("plugin-hidden") !== null,
   1.129 +    test4b,
   1.130 +    "Test 4, expected the plugin infobar to be triggered when plugin was overlayed");
   1.131 +}
   1.132 +
   1.133 +function test4b() {
   1.134 +  let doc = gTestBrowser.contentDocument;
   1.135 +  let plugin = doc.getElementById("test");
   1.136 +  ok(plugin, "Test 4b, Found plugin in page");
   1.137 +  plugin.QueryInterface(Ci.nsIObjectLoadingContent);
   1.138 +  is(plugin.pluginFallbackType, Ci.nsIObjectLoadingContent.PLUGIN_CLICK_TO_PLAY,
   1.139 +     "Test 4b, plugin fallback type should be PLUGIN_CLICK_TO_PLAY");
   1.140 +  ok(!plugin.activated, "Test 4b, Plugin should not be activated");
   1.141 +  let overlay = doc.getAnonymousElementByAttribute(plugin, "anonid", "main");
   1.142 +  ok(!overlay.classList.contains("visible"), "Test 4b, Plugin overlay should be hidden");
   1.143 +
   1.144 +  prepareTest(runAfterPluginBindingAttached(test5), gHttpTestRoot + "plugin_small.html");
   1.145 +}
   1.146 +
   1.147 +// Test that the notification bar is getting dismissed when directly activating plugins
   1.148 +// via the doorhanger.
   1.149 +
   1.150 +function test5() {
   1.151 +  let notificationBox = gBrowser.getNotificationBox(gTestBrowser);
   1.152 +  waitForCondition(() => notificationBox.getNotificationWithValue("plugin-hidden") !== null,
   1.153 +    test6,
   1.154 +    "Test 5, expected a notification bar for hidden plugins");
   1.155 +}
   1.156 +
   1.157 +function test6() {
   1.158 +  let notification = PopupNotifications.getNotification("click-to-play-plugins", gTestBrowser);
   1.159 +  ok(notification, "Test 6, Should have a click-to-play notification");
   1.160 +  let plugin = gTestBrowser.contentDocument.getElementById("test");
   1.161 +  ok(plugin, "Test 6, Found plugin in page");
   1.162 +  let objLoadingContent = plugin.QueryInterface(Ci.nsIObjectLoadingContent);
   1.163 +  is(objLoadingContent.pluginFallbackType, Ci.nsIObjectLoadingContent.PLUGIN_CLICK_TO_PLAY,
   1.164 +     "Test 6, Plugin should be click-to-play");
   1.165 +
   1.166 +  // simulate "always allow"
   1.167 +  notification.reshow();
   1.168 +  PopupNotifications.panel.firstChild._primaryButton.click();
   1.169 +
   1.170 +  let notificationBox = gBrowser.getNotificationBox(gTestBrowser);
   1.171 +  waitForCondition(() => notificationBox.getNotificationWithValue("plugin-hidden") === null,
   1.172 +    test7,
   1.173 +    "Test 6, expected the notification bar for hidden plugins to get dismissed");
   1.174 +}
   1.175 +
   1.176 +function test7() {
   1.177 +  let plugin = gTestBrowser.contentDocument.getElementById("test");
   1.178 +  ok(plugin, "Test 7, Found plugin in page");
   1.179 +  let objLoadingContent = plugin.QueryInterface(Ci.nsIObjectLoadingContent);
   1.180 +  waitForCondition(() => objLoadingContent.activated, finishTest,
   1.181 +    "Test 7, Waited too long for plugin to activate");
   1.182 +}

mercurial