browser/base/content/test/plugins/browser_CTP_resize.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_resize.js	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,116 @@
     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 +
    1.30 +  prepareTest(runAfterPluginBindingAttached(test1), gHttpTestRoot + "plugin_small.html");
    1.31 +}
    1.32 +
    1.33 +function finishTest() {
    1.34 +  clearAllPluginPermissions();
    1.35 +  gTestBrowser.removeEventListener("load", pageLoad, true);
    1.36 +  gBrowser.removeCurrentTab();
    1.37 +  window.focus();
    1.38 +  finish();
    1.39 +}
    1.40 +
    1.41 +function pageLoad() {
    1.42 +  // The plugin events are async dispatched and can come after the load event
    1.43 +  // This just allows the events to fire before we then go on to test the states
    1.44 +  executeSoon(gNextTest);
    1.45 +}
    1.46 +
    1.47 +function prepareTest(nextTest, url) {
    1.48 +  gNextTest = nextTest;
    1.49 +  gTestBrowser.contentWindow.location = url;
    1.50 +}
    1.51 +
    1.52 +// Due to layout being async, "PluginBindAttached" may trigger later.
    1.53 +// This wraps a function to force a layout flush, thus triggering it,
    1.54 +// and schedules the function execution so they're definitely executed
    1.55 +// afterwards.
    1.56 +function runAfterPluginBindingAttached(func) {
    1.57 +  return function() {
    1.58 +    let doc = gTestBrowser.contentDocument;
    1.59 +    let elems = doc.getElementsByTagName('embed');
    1.60 +    if (elems.length < 1) {
    1.61 +      elems = doc.getElementsByTagName('object');
    1.62 +    }
    1.63 +    elems[0].clientTop;
    1.64 +    executeSoon(func);
    1.65 +  };
    1.66 +}
    1.67 +
    1.68 +// Test that the overlay is hidden for "small" plugin elements and is shown
    1.69 +// once they are resized to a size that can hold the overlay
    1.70 +
    1.71 +function test1() {
    1.72 +  let popupNotification = PopupNotifications.getNotification("click-to-play-plugins", gTestBrowser);
    1.73 +  ok(popupNotification, "Test 1, Should have a click-to-play notification");
    1.74 +
    1.75 +  let plugin = gTestBrowser.contentDocument.getElementById("test");
    1.76 +  let doc = gTestBrowser.contentDocument;
    1.77 +  let overlay = doc.getAnonymousElementByAttribute(plugin, "anonid", "main");
    1.78 +  ok(overlay, "Test 1, Should have an overlay.");
    1.79 +  ok(!overlay.classList.contains("visible"), "Test 1, Overlay should be hidden");
    1.80 +
    1.81 +  plugin.style.width = '300px';
    1.82 +  executeSoon(test2);
    1.83 +}
    1.84 +
    1.85 +function test2() {
    1.86 +  let plugin = gTestBrowser.contentDocument.getElementById("test");
    1.87 +  let doc = gTestBrowser.contentDocument;
    1.88 +  let overlay = doc.getAnonymousElementByAttribute(plugin, "anonid", "main");
    1.89 +  ok(overlay, "Test 2, Should have an overlay.");
    1.90 +  ok(!overlay.classList.contains("visible"), "Test 2, Overlay should be hidden");
    1.91 +
    1.92 +  plugin.style.height = '300px';
    1.93 +  let condition = () => overlay.classList.contains("visible");
    1.94 +  waitForCondition(condition, test3, "Test 2, Waited too long for overlay to become visible");
    1.95 +}
    1.96 +
    1.97 +function test3() {
    1.98 +  let plugin = gTestBrowser.contentDocument.getElementById("test");
    1.99 +  let doc = gTestBrowser.contentDocument;
   1.100 +  let overlay = doc.getAnonymousElementByAttribute(plugin, "anonid", "main");
   1.101 +  ok(overlay, "Test 3, Should have an overlay.");
   1.102 +  ok(overlay.classList.contains("visible"), "Test 3, Overlay should be visible");
   1.103 +
   1.104 +  plugin.style.width = '10px';
   1.105 +  plugin.style.height = '10px';
   1.106 +  let condition = () => !overlay.classList.contains("visible");
   1.107 +  waitForCondition(condition, test4, "Test 3, Waited too long for overlay to become hidden");
   1.108 +}
   1.109 +
   1.110 +function test4() {
   1.111 +  let plugin = gTestBrowser.contentDocument.getElementById("test");
   1.112 +  let doc = gTestBrowser.contentDocument;
   1.113 +  let overlay = doc.getAnonymousElementByAttribute(plugin, "anonid", "main");
   1.114 +  ok(overlay, "Test 4, Should have an overlay.");
   1.115 +  ok(!overlay.classList.contains("visible"), "Test 4, Overlay should be hidden");
   1.116 +
   1.117 +  clearAllPluginPermissions();
   1.118 +  finishTest();
   1.119 +}

mercurial