browser/base/content/test/plugins/browser_CTP_iframe.js

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

mercurial