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