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

changeset 0
6474c204b198
equal deleted inserted replaced
-1:000000000000 0:807eea891349
1 var rootDir = getRootDirectory(gTestPath);
2 const gTestRoot = rootDir;
3 const gHttpTestRoot = rootDir.replace("chrome://mochitests/content/", "http://127.0.0.1:8888/");
4
5 var gTestBrowser = null;
6 var gNextTest = null;
7 var gPluginHost = Components.classes["@mozilla.org/plugin/host;1"].getService(Components.interfaces.nsIPluginHost);
8
9 Components.utils.import("resource://gre/modules/Services.jsm");
10
11 function test() {
12 waitForExplicitFinish();
13 registerCleanupFunction(function() {
14 clearAllPluginPermissions();
15 Services.prefs.clearUserPref("extensions.blocklist.suppressUI");
16 });
17 Services.prefs.setBoolPref("extensions.blocklist.suppressUI", true);
18
19 let newTab = gBrowser.addTab();
20 gBrowser.selectedTab = newTab;
21 gTestBrowser = gBrowser.selectedBrowser;
22 gTestBrowser.addEventListener("load", pageLoad, true);
23
24 Services.prefs.setBoolPref("plugins.click_to_play", true);
25 setTestPluginEnabledState(Ci.nsIPluginTag.STATE_DISABLED);
26
27 prepareTest(runAfterPluginBindingAttached(test1), gHttpTestRoot + "plugin_test.html");
28 }
29
30 function finishTest() {
31 clearAllPluginPermissions();
32 gTestBrowser.removeEventListener("load", pageLoad, true);
33 gBrowser.removeCurrentTab();
34 window.focus();
35 finish();
36 }
37
38 function pageLoad() {
39 // The plugin events are async dispatched and can come after the load event
40 // This just allows the events to fire before we then go on to test the states
41 executeSoon(gNextTest);
42 }
43
44 function prepareTest(nextTest, url) {
45 gNextTest = nextTest;
46 gTestBrowser.contentWindow.location = url;
47 }
48
49 // Due to layout being async, "PluginBindAttached" may trigger later.
50 // This wraps a function to force a layout flush, thus triggering it,
51 // and schedules the function execution so they're definitely executed
52 // afterwards.
53 function runAfterPluginBindingAttached(func) {
54 return function() {
55 let doc = gTestBrowser.contentDocument;
56 let elems = doc.getElementsByTagName('embed');
57 if (elems.length < 1) {
58 elems = doc.getElementsByTagName('object');
59 }
60 elems[0].clientTop;
61 executeSoon(func);
62 };
63 }
64
65 // Tests that the overlay can be hidded for disabled plugins using the close icon.
66 function test1() {
67 var doc = gTestBrowser.contentDocument;
68 var plugin = doc.getElementById("test");
69 ok(plugin, "Test 1, Found plugin in page");
70 var overlay = doc.getAnonymousElementByAttribute(plugin, "anonid", "main");
71 ok(overlay.classList.contains("visible"), "Test 1, Plugin overlay should exist, not be hidden");
72 var closeIcon = doc.getAnonymousElementByAttribute(plugin, "anonid", "closeIcon")
73 EventUtils.synthesizeMouseAtCenter(closeIcon, {}, gTestBrowser.contentWindow);
74 var condition = function() !overlay.classList.contains("visible");
75 waitForCondition(condition, finishTest, "Test 1, Waited too long for the overlay to become invisible.");
76 }

mercurial