browser/base/content/test/plugins/browser_CTP_multi_allow.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_multi_allow.js	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,138 @@
     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 +var gPluginHost = Components.classes["@mozilla.org/plugin/host;1"].getService(Components.interfaces.nsIPluginHost);
    1.11 +
    1.12 +Components.utils.import("resource://gre/modules/Services.jsm");
    1.13 +
    1.14 +function test() {
    1.15 +  waitForExplicitFinish();
    1.16 +  registerCleanupFunction(function() {
    1.17 +    clearAllPluginPermissions();
    1.18 +    Services.prefs.clearUserPref("extensions.blocklist.suppressUI");
    1.19 +  });
    1.20 +  Services.prefs.setBoolPref("extensions.blocklist.suppressUI", true);
    1.21 +
    1.22 +  var newTab = gBrowser.addTab();
    1.23 +  gBrowser.selectedTab = newTab;
    1.24 +  gTestBrowser = gBrowser.selectedBrowser;
    1.25 +  gTestBrowser.addEventListener("load", pageLoad, true);
    1.26 +
    1.27 +  Services.prefs.setBoolPref("plugins.click_to_play", true);
    1.28 +  setTestPluginEnabledState(Ci.nsIPluginTag.STATE_CLICKTOPLAY);
    1.29 +  setTestPluginEnabledState(Ci.nsIPluginTag.STATE_CLICKTOPLAY, "Second Test Plug-in");
    1.30 +
    1.31 +  prepareTest(test1a, gHttpTestRoot + "plugin_two_types.html");
    1.32 +}
    1.33 +
    1.34 +function finishTest() {
    1.35 +  clearAllPluginPermissions();
    1.36 +  gTestBrowser.removeEventListener("load", pageLoad, true);
    1.37 +  gBrowser.removeCurrentTab();
    1.38 +  window.focus();
    1.39 +  finish();
    1.40 +}
    1.41 +
    1.42 +function pageLoad() {
    1.43 +  // The plugin events are async dispatched and can come after the load event
    1.44 +  // This just allows the events to fire before we then go on to test the states
    1.45 +  executeSoon(gNextTest);
    1.46 +}
    1.47 +
    1.48 +function prepareTest(nextTest, url) {
    1.49 +  gNextTest = nextTest;
    1.50 +  gTestBrowser.contentWindow.location = url;
    1.51 +}
    1.52 +
    1.53 +// Due to layout being async, "PluginBindAttached" may trigger later.
    1.54 +// This wraps a function to force a layout flush, thus triggering it,
    1.55 +// and schedules the function execution so they're definitely executed
    1.56 +// afterwards.
    1.57 +function runAfterPluginBindingAttached(func) {
    1.58 +  return function() {
    1.59 +    let doc = gTestBrowser.contentDocument;
    1.60 +    let elems = doc.getElementsByTagName('embed');
    1.61 +    if (elems.length < 1) {
    1.62 +      elems = doc.getElementsByTagName('object');
    1.63 +    }
    1.64 +    elems[0].clientTop;
    1.65 +    executeSoon(func);
    1.66 +  };
    1.67 +}
    1.68 +
    1.69 +// Test that the click-to-play doorhanger for multiple plugins shows the correct
    1.70 +// state when re-opening without reloads or navigation.
    1.71 +
    1.72 +function test1a() {
    1.73 +  let doc = gTestBrowser.contentDocument;
    1.74 +  let plugin = doc.getElementById("test");
    1.75 +  let objLoadingContent = plugin.QueryInterface(Ci.nsIObjectLoadingContent);
    1.76 +  ok(!objLoadingContent.activated, "Test1a, Plugin should not be activated");
    1.77 +
    1.78 +  let notification = PopupNotifications.getNotification("click-to-play-plugins", gTestBrowser);
    1.79 +  ok(notification, "Test 1a, Should have a click-to-play notification");
    1.80 +  notification.reshow();
    1.81 +
    1.82 +  is(notification.options.pluginData.size, 2,
    1.83 +     "Test 1a, Should have two types of plugin in the notification");
    1.84 +
    1.85 +  let pluginItem = null;
    1.86 +  for (let item of PopupNotifications.panel.firstChild.childNodes) {
    1.87 +    is(item.value, "block", "Test 1a, all plugins should start out blocked");
    1.88 +    if (item.action.pluginName == "Test") {
    1.89 +      pluginItem = item;
    1.90 +    }
    1.91 +  }
    1.92 +
    1.93 +  // Choose "Allow now" for the test plugin
    1.94 +  pluginItem.value = "allownow";
    1.95 +  PopupNotifications.panel.firstChild._primaryButton.click();
    1.96 +
    1.97 +  waitForCondition(() => objLoadingContent.activated, test1b,
    1.98 +                   "Test 1a, Waited too long for plugin to activate");
    1.99 +}
   1.100 +
   1.101 +function test1b() {
   1.102 +  let notification = PopupNotifications.getNotification("click-to-play-plugins", gTestBrowser);
   1.103 +  ok(notification, "Test 1b, Should have a click-to-play notification");
   1.104 +  notification.reshow();
   1.105 +
   1.106 +  let pluginItem = null;
   1.107 +  for (let item of PopupNotifications.panel.firstChild.childNodes) {
   1.108 +    if (item.action.pluginName == "Test") {
   1.109 +      is(item.value, "allownow", "Test 1b, Test plugin should now be set to 'Allow now'");
   1.110 +    } else {
   1.111 +      is(item.value, "block", "Test 1b, Second Test plugin should still be blocked");
   1.112 +      pluginItem = item;
   1.113 +    }
   1.114 +  }
   1.115 +
   1.116 +  // Choose "Allow and remember" for the Second Test plugin
   1.117 +  pluginItem.value = "allowalways";
   1.118 +  PopupNotifications.panel.firstChild._primaryButton.click();
   1.119 +
   1.120 +  let doc = gTestBrowser.contentDocument;
   1.121 +  let plugin = doc.getElementById("secondtestA");
   1.122 +  let objLoadingContent = plugin.QueryInterface(Ci.nsIObjectLoadingContent);
   1.123 +  waitForCondition(() => objLoadingContent.activated, test1c,
   1.124 +                   "Test 1b, Waited too long for plugin to activate");
   1.125 +}
   1.126 +
   1.127 +function test1c() {
   1.128 +  let notification = PopupNotifications.getNotification("click-to-play-plugins", gTestBrowser);
   1.129 +  ok(notification, "Test 1c, Should have a click-to-play notification");
   1.130 +  notification.reshow();
   1.131 +
   1.132 +  for (let item of PopupNotifications.panel.firstChild.childNodes) {
   1.133 +    if (item.action.pluginName == "Test") {
   1.134 +      is(item.value, "allownow", "Test 1c, Test plugin should be set to 'Allow now'");
   1.135 +    } else {
   1.136 +      is(item.value, "allowalways", "Test 1c, Second Test plugin should be set to 'Allow always'");
   1.137 +    }
   1.138 +  }
   1.139 +
   1.140 +  finishTest();
   1.141 +}

mercurial