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.
1 var rootDir = getRootDirectory(gTestPath);
2 const gTestRoot = rootDir;
3 const gHttpTestRoot = rootDir.replace("chrome://mochitests/content/", "http://127.0.0.1:8888/");
5 var gTestBrowser = null;
6 var gNextTest = null;
7 var gPluginHost = Components.classes["@mozilla.org/plugin/host;1"].getService(Components.interfaces.nsIPluginHost);
8 var gRunNextTestAfterPluginRemoved = false;
10 Components.utils.import("resource://gre/modules/Services.jsm");
12 function test() {
13 waitForExplicitFinish();
14 registerCleanupFunction(function() {
15 clearAllPluginPermissions();
16 Services.prefs.clearUserPref("extensions.blocklist.suppressUI");
17 });
18 Services.prefs.setBoolPref("extensions.blocklist.suppressUI", true);
20 var newTab = gBrowser.addTab();
21 gBrowser.selectedTab = newTab;
22 gTestBrowser = gBrowser.selectedBrowser;
23 gTestBrowser.addEventListener("load", pageLoad, true);
25 Services.prefs.setBoolPref("plugins.click_to_play", true);
26 setTestPluginEnabledState(Ci.nsIPluginTag.STATE_CLICKTOPLAY);
28 prepareTest(test1, gHttpTestRoot + "plugin_outsideScrollArea.html");
29 }
31 function finishTest() {
32 clearAllPluginPermissions();
33 gTestBrowser.removeEventListener("load", pageLoad, true);
34 gBrowser.removeCurrentTab();
35 window.focus();
36 finish();
37 }
39 function pageLoad() {
40 // The plugin events are async dispatched and can come after the load event
41 // This just allows the events to fire before we then go on to test the states
42 executeSoon(gNextTest);
43 }
45 function prepareTest(nextTest, url) {
46 gNextTest = nextTest;
47 gTestBrowser.contentWindow.location = url;
48 }
50 // Due to layout being async, "PluginBindAttached" may trigger later.
51 // This wraps a function to force a layout flush, thus triggering it,
52 // and schedules the function execution so they're definitely executed
53 // afterwards.
54 function runAfterPluginBindingAttached(func) {
55 return function() {
56 let doc = gTestBrowser.contentDocument;
57 let elems = doc.getElementsByTagName('embed');
58 if (elems.length < 1) {
59 elems = doc.getElementsByTagName('object');
60 }
61 elems[0].clientTop;
62 executeSoon(func);
63 };
64 }
66 // Add plugin relative to bottom-left corner of #container.
67 function addPlugin(x, y) {
68 let doc = gTestBrowser.contentDocument;
69 let p = doc.createElement('embed');
71 p.setAttribute('id', 'test');
72 p.setAttribute('type', 'application/x-test');
73 p.style.left = x.toString() + 'px';
74 p.style.bottom = y.toString() + 'px';
76 doc.getElementById('container').appendChild(p);
77 }
79 // Test that the click-to-play overlay is not hidden for elements
80 // partially or fully outside the viewport.
82 function test1() {
83 addPlugin(0, -200);
84 executeSoon(runAfterPluginBindingAttached(test2));
85 }
87 function test2() {
88 let doc = gTestBrowser.contentDocument;
89 let plugin = doc.getElementById("test");
90 let overlay = doc.getAnonymousElementByAttribute(plugin, "anonid", "main");
91 ok(overlay, "Test 2, Should have an overlay.");
92 ok(overlay.classList.contains("visible"), "Test 2, Overlay should be visible");
94 prepareTest(test3, gHttpTestRoot + "plugin_outsideScrollArea.html");
95 }
97 function test3() {
98 addPlugin(0, -410);
99 executeSoon(runAfterPluginBindingAttached(test4));
100 }
102 function test4() {
103 let doc = gTestBrowser.contentDocument;
104 let plugin = doc.getElementById("test");
105 let overlay = doc.getAnonymousElementByAttribute(plugin, "anonid", "main");
106 ok(overlay, "Test 4, Should have an overlay.");
107 ok(overlay.classList.contains("visible"), "Test 4, Overlay should be visible");
109 prepareTest(test5, gHttpTestRoot + "plugin_outsideScrollArea.html");
110 }
112 function test5() {
113 addPlugin(-600, 0);
114 executeSoon(runAfterPluginBindingAttached(test6));
115 }
117 function test6() {
118 let doc = gTestBrowser.contentDocument;
119 let plugin = doc.getElementById("test");
120 let overlay = doc.getAnonymousElementByAttribute(plugin, "anonid", "main");
121 ok(overlay, "Test 6, Should have an overlay.");
122 ok(!overlay.classList.contains("visible"), "Test 6, Overlay should be hidden");
124 finishTest();
125 }