michael@0: let rootDir = getRootDirectory(gTestPath); michael@0: const gTestRoot = rootDir; michael@0: const gHttpTestRoot = rootDir.replace("chrome://mochitests/content/", "http://127.0.0.1:8888/"); michael@0: michael@0: let gTestBrowser = null; michael@0: let gNextTest = null; michael@0: michael@0: Components.utils.import("resource://gre/modules/Services.jsm"); michael@0: michael@0: function test() { michael@0: waitForExplicitFinish(); michael@0: registerCleanupFunction(function() { michael@0: clearAllPluginPermissions(); michael@0: Services.prefs.clearUserPref("extensions.blocklist.suppressUI"); michael@0: }); michael@0: Services.prefs.setBoolPref("extensions.blocklist.suppressUI", true); michael@0: michael@0: let newTab = gBrowser.addTab(); michael@0: gBrowser.selectedTab = newTab; michael@0: gTestBrowser = gBrowser.selectedBrowser; michael@0: gTestBrowser.addEventListener("load", pageLoad, true); michael@0: michael@0: Services.prefs.setBoolPref("plugins.click_to_play", true); michael@0: setTestPluginEnabledState(Ci.nsIPluginTag.STATE_CLICKTOPLAY); michael@0: michael@0: prepareTest(delayTest(runAfterPluginBindingAttached(test1)), gHttpTestRoot + "plugin_iframe.html"); michael@0: } michael@0: michael@0: function finishTest() { michael@0: clearAllPluginPermissions(); michael@0: gTestBrowser.removeEventListener("load", pageLoad, true); michael@0: gBrowser.removeCurrentTab(); michael@0: window.focus(); michael@0: finish(); michael@0: } michael@0: michael@0: function pageLoad() { michael@0: gNextTest(); michael@0: } michael@0: michael@0: function prepareTest(nextTest, url) { michael@0: gNextTest = nextTest; michael@0: gTestBrowser.contentWindow.location = url; michael@0: } michael@0: michael@0: // Delay executing a test for one load event to wait for frame loads. michael@0: function delayTest(nextTest) { michael@0: return () => { michael@0: gNextTest = nextTest; michael@0: } michael@0: } michael@0: michael@0: // Due to layout being async, "PluginBindAttached" may trigger later. michael@0: // This wraps a function to force a layout flush, thus triggering it, michael@0: // and schedules the function execution so they're definitely executed michael@0: // afterwards. michael@0: function runAfterPluginBindingAttached(func) { michael@0: return () => { michael@0: let frame = gTestBrowser.contentDocument.getElementById("frame"); michael@0: let doc = frame.contentDocument; michael@0: let elems = doc.getElementsByTagName('embed'); michael@0: if (elems.length < 1) { michael@0: elems = doc.getElementsByTagName('object'); michael@0: } michael@0: elems[0].clientTop; michael@0: executeSoon(func); michael@0: }; michael@0: } michael@0: michael@0: // Tests that the overlays are visible and actionable if the plugin is in an iframe. michael@0: function test1() { michael@0: let frame = gTestBrowser.contentDocument.getElementById("frame"); michael@0: let doc = frame.contentDocument; michael@0: let plugin = doc.getElementById("test"); michael@0: ok(plugin, "Test 1, Found plugin in page"); michael@0: michael@0: let overlay = doc.getAnonymousElementByAttribute(plugin, "anonid", "main"); michael@0: ok(overlay.classList.contains("visible"), "Test 1, Plugin overlay should exist, not be hidden"); michael@0: let closeIcon = doc.getAnonymousElementByAttribute(plugin, "anonid", "closeIcon") michael@0: michael@0: EventUtils.synthesizeMouseAtCenter(closeIcon, {}, frame.contentWindow); michael@0: let condition = () => !overlay.classList.contains("visible"); michael@0: waitForCondition(condition, test2, "Test 1, Waited too long for the overlay to become invisible."); michael@0: } michael@0: michael@0: function test2() { michael@0: prepareTest(delayTest(runAfterPluginBindingAttached(test3)), gHttpTestRoot + "plugin_iframe.html"); michael@0: } michael@0: michael@0: function test3() { michael@0: let frame = gTestBrowser.contentDocument.getElementById("frame"); michael@0: let doc = frame.contentDocument; michael@0: let plugin = doc.getElementById("test"); michael@0: ok(plugin, "Test 3, Found plugin in page"); michael@0: michael@0: let overlay = doc.getAnonymousElementByAttribute(plugin, "anonid", "main"); michael@0: ok(overlay.classList.contains("visible"), "Test 3, Plugin overlay should exist, not be hidden"); michael@0: michael@0: EventUtils.synthesizeMouseAtCenter(plugin, {}, frame.contentWindow); michael@0: let condition = () => PopupNotifications.getNotification("click-to-play-plugins", gTestBrowser); michael@0: waitForCondition(condition, finishTest, "Test 3, Waited too long for the doorhanger to pop up."); michael@0: }