browser/base/content/test/plugins/browser_CTP_iframe.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 let rootDir = getRootDirectory(gTestPath);
     2 const gTestRoot = rootDir;
     3 const gHttpTestRoot = rootDir.replace("chrome://mochitests/content/", "http://127.0.0.1:8888/");
     5 let gTestBrowser = null;
     6 let gNextTest = null;
     8 Components.utils.import("resource://gre/modules/Services.jsm");
    10 function test() {
    11   waitForExplicitFinish();
    12   registerCleanupFunction(function() {
    13     clearAllPluginPermissions();
    14     Services.prefs.clearUserPref("extensions.blocklist.suppressUI");
    15   });
    16   Services.prefs.setBoolPref("extensions.blocklist.suppressUI", true);
    18   let newTab = gBrowser.addTab();
    19   gBrowser.selectedTab = newTab;
    20   gTestBrowser = gBrowser.selectedBrowser;
    21   gTestBrowser.addEventListener("load", pageLoad, true);
    23   Services.prefs.setBoolPref("plugins.click_to_play", true);
    24   setTestPluginEnabledState(Ci.nsIPluginTag.STATE_CLICKTOPLAY);
    26   prepareTest(delayTest(runAfterPluginBindingAttached(test1)), gHttpTestRoot + "plugin_iframe.html");
    27 }
    29 function finishTest() {
    30   clearAllPluginPermissions();
    31   gTestBrowser.removeEventListener("load", pageLoad, true);
    32   gBrowser.removeCurrentTab();
    33   window.focus();
    34   finish();
    35 }
    37 function pageLoad() {
    38   gNextTest();
    39 }
    41 function prepareTest(nextTest, url) {
    42   gNextTest = nextTest;
    43   gTestBrowser.contentWindow.location = url;
    44 }
    46 // Delay executing a test for one load event to wait for frame loads.
    47 function delayTest(nextTest) {
    48   return () => {
    49     gNextTest = nextTest;
    50   }
    51 }
    53 // Due to layout being async, "PluginBindAttached" may trigger later.
    54 // This wraps a function to force a layout flush, thus triggering it,
    55 // and schedules the function execution so they're definitely executed
    56 // afterwards.
    57 function runAfterPluginBindingAttached(func) {
    58   return () => {
    59     let frame = gTestBrowser.contentDocument.getElementById("frame");
    60     let doc = frame.contentDocument;
    61     let elems = doc.getElementsByTagName('embed');
    62     if (elems.length < 1) {
    63       elems = doc.getElementsByTagName('object');
    64     }
    65     elems[0].clientTop;
    66     executeSoon(func);
    67   };
    68 }
    70 // Tests that the overlays are visible and actionable if the plugin is in an iframe.
    71 function test1() {
    72   let frame = gTestBrowser.contentDocument.getElementById("frame");
    73   let doc = frame.contentDocument;
    74   let plugin = doc.getElementById("test");
    75   ok(plugin, "Test 1, Found plugin in page");
    77   let overlay = doc.getAnonymousElementByAttribute(plugin, "anonid", "main");
    78   ok(overlay.classList.contains("visible"), "Test 1, Plugin overlay should exist, not be hidden");
    79   let closeIcon = doc.getAnonymousElementByAttribute(plugin, "anonid", "closeIcon")
    81   EventUtils.synthesizeMouseAtCenter(closeIcon, {}, frame.contentWindow);
    82   let condition = () => !overlay.classList.contains("visible");
    83   waitForCondition(condition, test2, "Test 1, Waited too long for the overlay to become invisible.");
    84 }
    86 function test2() {
    87   prepareTest(delayTest(runAfterPluginBindingAttached(test3)), gHttpTestRoot + "plugin_iframe.html");
    88 }
    90 function test3() {
    91   let frame = gTestBrowser.contentDocument.getElementById("frame");
    92   let doc = frame.contentDocument;
    93   let plugin = doc.getElementById("test");
    94   ok(plugin, "Test 3, Found plugin in page");
    96   let overlay = doc.getAnonymousElementByAttribute(plugin, "anonid", "main");
    97   ok(overlay.classList.contains("visible"), "Test 3, Plugin overlay should exist, not be hidden");
    99   EventUtils.synthesizeMouseAtCenter(plugin, {}, frame.contentWindow);
   100   let condition = () => PopupNotifications.getNotification("click-to-play-plugins", gTestBrowser);
   101   waitForCondition(condition, finishTest, "Test 3, Waited too long for the doorhanger to pop up.");
   102 }

mercurial