1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/browser/base/content/test/plugins/browser_CTP_iframe.js Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,102 @@ 1.4 +let 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 +let gTestBrowser = null; 1.9 +let gNextTest = null; 1.10 + 1.11 +Components.utils.import("resource://gre/modules/Services.jsm"); 1.12 + 1.13 +function test() { 1.14 + waitForExplicitFinish(); 1.15 + registerCleanupFunction(function() { 1.16 + clearAllPluginPermissions(); 1.17 + Services.prefs.clearUserPref("extensions.blocklist.suppressUI"); 1.18 + }); 1.19 + Services.prefs.setBoolPref("extensions.blocklist.suppressUI", true); 1.20 + 1.21 + let newTab = gBrowser.addTab(); 1.22 + gBrowser.selectedTab = newTab; 1.23 + gTestBrowser = gBrowser.selectedBrowser; 1.24 + gTestBrowser.addEventListener("load", pageLoad, true); 1.25 + 1.26 + Services.prefs.setBoolPref("plugins.click_to_play", true); 1.27 + setTestPluginEnabledState(Ci.nsIPluginTag.STATE_CLICKTOPLAY); 1.28 + 1.29 + prepareTest(delayTest(runAfterPluginBindingAttached(test1)), gHttpTestRoot + "plugin_iframe.html"); 1.30 +} 1.31 + 1.32 +function finishTest() { 1.33 + clearAllPluginPermissions(); 1.34 + gTestBrowser.removeEventListener("load", pageLoad, true); 1.35 + gBrowser.removeCurrentTab(); 1.36 + window.focus(); 1.37 + finish(); 1.38 +} 1.39 + 1.40 +function pageLoad() { 1.41 + gNextTest(); 1.42 +} 1.43 + 1.44 +function prepareTest(nextTest, url) { 1.45 + gNextTest = nextTest; 1.46 + gTestBrowser.contentWindow.location = url; 1.47 +} 1.48 + 1.49 +// Delay executing a test for one load event to wait for frame loads. 1.50 +function delayTest(nextTest) { 1.51 + return () => { 1.52 + gNextTest = nextTest; 1.53 + } 1.54 +} 1.55 + 1.56 +// Due to layout being async, "PluginBindAttached" may trigger later. 1.57 +// This wraps a function to force a layout flush, thus triggering it, 1.58 +// and schedules the function execution so they're definitely executed 1.59 +// afterwards. 1.60 +function runAfterPluginBindingAttached(func) { 1.61 + return () => { 1.62 + let frame = gTestBrowser.contentDocument.getElementById("frame"); 1.63 + let doc = frame.contentDocument; 1.64 + let elems = doc.getElementsByTagName('embed'); 1.65 + if (elems.length < 1) { 1.66 + elems = doc.getElementsByTagName('object'); 1.67 + } 1.68 + elems[0].clientTop; 1.69 + executeSoon(func); 1.70 + }; 1.71 +} 1.72 + 1.73 +// Tests that the overlays are visible and actionable if the plugin is in an iframe. 1.74 +function test1() { 1.75 + let frame = gTestBrowser.contentDocument.getElementById("frame"); 1.76 + let doc = frame.contentDocument; 1.77 + let plugin = doc.getElementById("test"); 1.78 + ok(plugin, "Test 1, Found plugin in page"); 1.79 + 1.80 + let overlay = doc.getAnonymousElementByAttribute(plugin, "anonid", "main"); 1.81 + ok(overlay.classList.contains("visible"), "Test 1, Plugin overlay should exist, not be hidden"); 1.82 + let closeIcon = doc.getAnonymousElementByAttribute(plugin, "anonid", "closeIcon") 1.83 + 1.84 + EventUtils.synthesizeMouseAtCenter(closeIcon, {}, frame.contentWindow); 1.85 + let condition = () => !overlay.classList.contains("visible"); 1.86 + waitForCondition(condition, test2, "Test 1, Waited too long for the overlay to become invisible."); 1.87 +} 1.88 + 1.89 +function test2() { 1.90 + prepareTest(delayTest(runAfterPluginBindingAttached(test3)), gHttpTestRoot + "plugin_iframe.html"); 1.91 +} 1.92 + 1.93 +function test3() { 1.94 + let frame = gTestBrowser.contentDocument.getElementById("frame"); 1.95 + let doc = frame.contentDocument; 1.96 + let plugin = doc.getElementById("test"); 1.97 + ok(plugin, "Test 3, Found plugin in page"); 1.98 + 1.99 + let overlay = doc.getAnonymousElementByAttribute(plugin, "anonid", "main"); 1.100 + ok(overlay.classList.contains("visible"), "Test 3, Plugin overlay should exist, not be hidden"); 1.101 + 1.102 + EventUtils.synthesizeMouseAtCenter(plugin, {}, frame.contentWindow); 1.103 + let condition = () => PopupNotifications.getNotification("click-to-play-plugins", gTestBrowser); 1.104 + waitForCondition(condition, finishTest, "Test 3, Waited too long for the doorhanger to pop up."); 1.105 +}