browser/base/content/test/plugins/browser_CTP_outsideScrollArea.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_outsideScrollArea.js	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,125 @@
     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 +var gRunNextTestAfterPluginRemoved = false;
    1.12 +
    1.13 +Components.utils.import("resource://gre/modules/Services.jsm");
    1.14 +
    1.15 +function test() {
    1.16 +  waitForExplicitFinish();
    1.17 +  registerCleanupFunction(function() {
    1.18 +    clearAllPluginPermissions();
    1.19 +    Services.prefs.clearUserPref("extensions.blocklist.suppressUI");
    1.20 +  });
    1.21 +  Services.prefs.setBoolPref("extensions.blocklist.suppressUI", true);
    1.22 +
    1.23 +  var newTab = gBrowser.addTab();
    1.24 +  gBrowser.selectedTab = newTab;
    1.25 +  gTestBrowser = gBrowser.selectedBrowser;
    1.26 +  gTestBrowser.addEventListener("load", pageLoad, true);
    1.27 +
    1.28 +  Services.prefs.setBoolPref("plugins.click_to_play", true);
    1.29 +  setTestPluginEnabledState(Ci.nsIPluginTag.STATE_CLICKTOPLAY);
    1.30 +
    1.31 +  prepareTest(test1, gHttpTestRoot + "plugin_outsideScrollArea.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 +// Add plugin relative to bottom-left corner of #container.
    1.70 +function addPlugin(x, y) {
    1.71 +  let doc = gTestBrowser.contentDocument;
    1.72 +  let p = doc.createElement('embed');
    1.73 +
    1.74 +  p.setAttribute('id', 'test');
    1.75 +  p.setAttribute('type', 'application/x-test');
    1.76 +  p.style.left = x.toString() + 'px';
    1.77 +  p.style.bottom = y.toString() + 'px';
    1.78 +
    1.79 +  doc.getElementById('container').appendChild(p);
    1.80 +}
    1.81 +
    1.82 +// Test that the click-to-play overlay is not hidden for elements
    1.83 +// partially or fully outside the viewport.
    1.84 +
    1.85 +function test1() {
    1.86 +  addPlugin(0, -200);
    1.87 +  executeSoon(runAfterPluginBindingAttached(test2));
    1.88 +}
    1.89 +
    1.90 +function test2() {
    1.91 +  let doc = gTestBrowser.contentDocument;
    1.92 +  let plugin = doc.getElementById("test");
    1.93 +  let overlay = doc.getAnonymousElementByAttribute(plugin, "anonid", "main");
    1.94 +  ok(overlay, "Test 2, Should have an overlay.");
    1.95 +  ok(overlay.classList.contains("visible"), "Test 2, Overlay should be visible");
    1.96 +
    1.97 +  prepareTest(test3, gHttpTestRoot + "plugin_outsideScrollArea.html");
    1.98 +}
    1.99 +
   1.100 +function test3() {
   1.101 +  addPlugin(0, -410);
   1.102 +  executeSoon(runAfterPluginBindingAttached(test4));
   1.103 +}
   1.104 +
   1.105 +function test4() {
   1.106 +  let doc = gTestBrowser.contentDocument;
   1.107 +  let plugin = doc.getElementById("test");
   1.108 +  let overlay = doc.getAnonymousElementByAttribute(plugin, "anonid", "main");
   1.109 +  ok(overlay, "Test 4, Should have an overlay.");
   1.110 +  ok(overlay.classList.contains("visible"), "Test 4, Overlay should be visible");
   1.111 +
   1.112 +  prepareTest(test5, gHttpTestRoot + "plugin_outsideScrollArea.html");
   1.113 +}
   1.114 +
   1.115 +function test5() {
   1.116 +  addPlugin(-600, 0);
   1.117 +  executeSoon(runAfterPluginBindingAttached(test6));
   1.118 +}
   1.119 +
   1.120 +function test6() {
   1.121 +  let doc = gTestBrowser.contentDocument;
   1.122 +  let plugin = doc.getElementById("test");
   1.123 +  let overlay = doc.getAnonymousElementByAttribute(plugin, "anonid", "main");
   1.124 +  ok(overlay, "Test 6, Should have an overlay.");
   1.125 +  ok(!overlay.classList.contains("visible"), "Test 6, Overlay should be hidden");
   1.126 +
   1.127 +  finishTest();
   1.128 +}

mercurial