1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/browser/base/content/test/plugins/browser_CTP_hide_overlay.js Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,76 @@ 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 + let 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_DISABLED); 1.29 + 1.30 + prepareTest(runAfterPluginBindingAttached(test1), gHttpTestRoot + "plugin_test.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 +// Tests that the overlay can be hidded for disabled plugins using the close icon. 1.69 +function test1() { 1.70 + var doc = gTestBrowser.contentDocument; 1.71 + var plugin = doc.getElementById("test"); 1.72 + ok(plugin, "Test 1, Found plugin in page"); 1.73 + var overlay = doc.getAnonymousElementByAttribute(plugin, "anonid", "main"); 1.74 + ok(overlay.classList.contains("visible"), "Test 1, Plugin overlay should exist, not be hidden"); 1.75 + var closeIcon = doc.getAnonymousElementByAttribute(plugin, "anonid", "closeIcon") 1.76 + EventUtils.synthesizeMouseAtCenter(closeIcon, {}, gTestBrowser.contentWindow); 1.77 + var condition = function() !overlay.classList.contains("visible"); 1.78 + waitForCondition(condition, finishTest, "Test 1, Waited too long for the overlay to become invisible."); 1.79 +}