browser/base/content/test/plugins/browser_CTP_hide_overlay.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.

michael@0 1 var rootDir = getRootDirectory(gTestPath);
michael@0 2 const gTestRoot = rootDir;
michael@0 3 const gHttpTestRoot = rootDir.replace("chrome://mochitests/content/", "http://127.0.0.1:8888/");
michael@0 4
michael@0 5 var gTestBrowser = null;
michael@0 6 var gNextTest = null;
michael@0 7 var gPluginHost = Components.classes["@mozilla.org/plugin/host;1"].getService(Components.interfaces.nsIPluginHost);
michael@0 8
michael@0 9 Components.utils.import("resource://gre/modules/Services.jsm");
michael@0 10
michael@0 11 function test() {
michael@0 12 waitForExplicitFinish();
michael@0 13 registerCleanupFunction(function() {
michael@0 14 clearAllPluginPermissions();
michael@0 15 Services.prefs.clearUserPref("extensions.blocklist.suppressUI");
michael@0 16 });
michael@0 17 Services.prefs.setBoolPref("extensions.blocklist.suppressUI", true);
michael@0 18
michael@0 19 let newTab = gBrowser.addTab();
michael@0 20 gBrowser.selectedTab = newTab;
michael@0 21 gTestBrowser = gBrowser.selectedBrowser;
michael@0 22 gTestBrowser.addEventListener("load", pageLoad, true);
michael@0 23
michael@0 24 Services.prefs.setBoolPref("plugins.click_to_play", true);
michael@0 25 setTestPluginEnabledState(Ci.nsIPluginTag.STATE_DISABLED);
michael@0 26
michael@0 27 prepareTest(runAfterPluginBindingAttached(test1), gHttpTestRoot + "plugin_test.html");
michael@0 28 }
michael@0 29
michael@0 30 function finishTest() {
michael@0 31 clearAllPluginPermissions();
michael@0 32 gTestBrowser.removeEventListener("load", pageLoad, true);
michael@0 33 gBrowser.removeCurrentTab();
michael@0 34 window.focus();
michael@0 35 finish();
michael@0 36 }
michael@0 37
michael@0 38 function pageLoad() {
michael@0 39 // The plugin events are async dispatched and can come after the load event
michael@0 40 // This just allows the events to fire before we then go on to test the states
michael@0 41 executeSoon(gNextTest);
michael@0 42 }
michael@0 43
michael@0 44 function prepareTest(nextTest, url) {
michael@0 45 gNextTest = nextTest;
michael@0 46 gTestBrowser.contentWindow.location = url;
michael@0 47 }
michael@0 48
michael@0 49 // Due to layout being async, "PluginBindAttached" may trigger later.
michael@0 50 // This wraps a function to force a layout flush, thus triggering it,
michael@0 51 // and schedules the function execution so they're definitely executed
michael@0 52 // afterwards.
michael@0 53 function runAfterPluginBindingAttached(func) {
michael@0 54 return function() {
michael@0 55 let doc = gTestBrowser.contentDocument;
michael@0 56 let elems = doc.getElementsByTagName('embed');
michael@0 57 if (elems.length < 1) {
michael@0 58 elems = doc.getElementsByTagName('object');
michael@0 59 }
michael@0 60 elems[0].clientTop;
michael@0 61 executeSoon(func);
michael@0 62 };
michael@0 63 }
michael@0 64
michael@0 65 // Tests that the overlay can be hidded for disabled plugins using the close icon.
michael@0 66 function test1() {
michael@0 67 var doc = gTestBrowser.contentDocument;
michael@0 68 var plugin = doc.getElementById("test");
michael@0 69 ok(plugin, "Test 1, Found plugin in page");
michael@0 70 var overlay = doc.getAnonymousElementByAttribute(plugin, "anonid", "main");
michael@0 71 ok(overlay.classList.contains("visible"), "Test 1, Plugin overlay should exist, not be hidden");
michael@0 72 var closeIcon = doc.getAnonymousElementByAttribute(plugin, "anonid", "closeIcon")
michael@0 73 EventUtils.synthesizeMouseAtCenter(closeIcon, {}, gTestBrowser.contentWindow);
michael@0 74 var condition = function() !overlay.classList.contains("visible");
michael@0 75 waitForCondition(condition, finishTest, "Test 1, Waited too long for the overlay to become invisible.");
michael@0 76 }

mercurial