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

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

     1 var rootDir = getRootDirectory(gTestPath);
     2 const gTestRoot = rootDir;
     3 const gHttpTestRoot = rootDir.replace("chrome://mochitests/content/", "http://127.0.0.1:8888/");
     5 var gTestBrowser = null;
     6 var gNextTest = null;
     7 var gPluginHost = Components.classes["@mozilla.org/plugin/host;1"].getService(Components.interfaces.nsIPluginHost);
     9 Components.utils.import("resource://gre/modules/Services.jsm");
    11 function test() {
    12   waitForExplicitFinish();
    13   registerCleanupFunction(function() {
    14     clearAllPluginPermissions();
    15     Services.prefs.clearUserPref("extensions.blocklist.suppressUI");
    16   });
    17   Services.prefs.setBoolPref("extensions.blocklist.suppressUI", true);
    19   var newTab = gBrowser.addTab();
    20   gBrowser.selectedTab = newTab;
    21   gTestBrowser = gBrowser.selectedBrowser;
    22   gTestBrowser.addEventListener("load", pageLoad, true);
    24   Services.prefs.setBoolPref("plugins.click_to_play", true);
    25   setTestPluginEnabledState(Ci.nsIPluginTag.STATE_CLICKTOPLAY);
    27   prepareTest(runAfterPluginBindingAttached(test1), gHttpTestRoot + "plugin_small.html");
    28 }
    30 function finishTest() {
    31   clearAllPluginPermissions();
    32   gTestBrowser.removeEventListener("load", pageLoad, true);
    33   gBrowser.removeCurrentTab();
    34   window.focus();
    35   finish();
    36 }
    38 function pageLoad() {
    39   // The plugin events are async dispatched and can come after the load event
    40   // This just allows the events to fire before we then go on to test the states
    41   executeSoon(gNextTest);
    42 }
    44 function prepareTest(nextTest, url) {
    45   gNextTest = nextTest;
    46   gTestBrowser.contentWindow.location = url;
    47 }
    49 // Due to layout being async, "PluginBindAttached" may trigger later.
    50 // This wraps a function to force a layout flush, thus triggering it,
    51 // and schedules the function execution so they're definitely executed
    52 // afterwards.
    53 function runAfterPluginBindingAttached(func) {
    54   return function() {
    55     let doc = gTestBrowser.contentDocument;
    56     let elems = doc.getElementsByTagName('embed');
    57     if (elems.length < 1) {
    58       elems = doc.getElementsByTagName('object');
    59     }
    60     elems[0].clientTop;
    61     executeSoon(func);
    62   };
    63 }
    65 // Test that the overlay is hidden for "small" plugin elements and is shown
    66 // once they are resized to a size that can hold the overlay
    68 function test1() {
    69   let popupNotification = PopupNotifications.getNotification("click-to-play-plugins", gTestBrowser);
    70   ok(popupNotification, "Test 1, Should have a click-to-play notification");
    72   let plugin = gTestBrowser.contentDocument.getElementById("test");
    73   let doc = gTestBrowser.contentDocument;
    74   let overlay = doc.getAnonymousElementByAttribute(plugin, "anonid", "main");
    75   ok(overlay, "Test 1, Should have an overlay.");
    76   ok(!overlay.classList.contains("visible"), "Test 1, Overlay should be hidden");
    78   plugin.style.width = '300px';
    79   executeSoon(test2);
    80 }
    82 function test2() {
    83   let plugin = gTestBrowser.contentDocument.getElementById("test");
    84   let doc = gTestBrowser.contentDocument;
    85   let overlay = doc.getAnonymousElementByAttribute(plugin, "anonid", "main");
    86   ok(overlay, "Test 2, Should have an overlay.");
    87   ok(!overlay.classList.contains("visible"), "Test 2, Overlay should be hidden");
    89   plugin.style.height = '300px';
    90   let condition = () => overlay.classList.contains("visible");
    91   waitForCondition(condition, test3, "Test 2, Waited too long for overlay to become visible");
    92 }
    94 function test3() {
    95   let plugin = gTestBrowser.contentDocument.getElementById("test");
    96   let doc = gTestBrowser.contentDocument;
    97   let overlay = doc.getAnonymousElementByAttribute(plugin, "anonid", "main");
    98   ok(overlay, "Test 3, Should have an overlay.");
    99   ok(overlay.classList.contains("visible"), "Test 3, Overlay should be visible");
   101   plugin.style.width = '10px';
   102   plugin.style.height = '10px';
   103   let condition = () => !overlay.classList.contains("visible");
   104   waitForCondition(condition, test4, "Test 3, Waited too long for overlay to become hidden");
   105 }
   107 function test4() {
   108   let plugin = gTestBrowser.contentDocument.getElementById("test");
   109   let doc = gTestBrowser.contentDocument;
   110   let overlay = doc.getAnonymousElementByAttribute(plugin, "anonid", "main");
   111   ok(overlay, "Test 4, Should have an overlay.");
   112   ok(!overlay.classList.contains("visible"), "Test 4, Overlay should be hidden");
   114   clearAllPluginPermissions();
   115   finishTest();
   116 }

mercurial