|
1 var rootDir = getRootDirectory(gTestPath); |
|
2 const gTestRoot = rootDir.replace("chrome://mochitests/content/", "http://mochi.test:8888/"); |
|
3 |
|
4 var gTestBrowser = null; |
|
5 var gNextTest = null; |
|
6 |
|
7 Components.utils.import("resource://gre/modules/Services.jsm"); |
|
8 |
|
9 function test() { |
|
10 waitForExplicitFinish(); |
|
11 registerCleanupFunction(function() { |
|
12 clearAllPluginPermissions(); |
|
13 Services.prefs.clearUserPref("plugins.click_to_play"); |
|
14 }); |
|
15 Services.prefs.setBoolPref("plugins.click_to_play", true); |
|
16 setTestPluginEnabledState(Ci.nsIPluginTag.STATE_CLICKTOPLAY); |
|
17 |
|
18 var newTab = gBrowser.addTab(); |
|
19 gBrowser.selectedTab = newTab; |
|
20 gTestBrowser = gBrowser.selectedBrowser; |
|
21 gTestBrowser.addEventListener("load", pageLoad, true); |
|
22 prepareTest(test1a, gTestRoot + "plugin_add_dynamically.html"); |
|
23 } |
|
24 |
|
25 function finishTest() { |
|
26 gTestBrowser.removeEventListener("load", pageLoad, true); |
|
27 gBrowser.removeCurrentTab(); |
|
28 window.focus(); |
|
29 finish(); |
|
30 } |
|
31 |
|
32 function pageLoad() { |
|
33 // The plugin events are async dispatched and can come after the load event |
|
34 // This just allows the events to fire before we then go on to test the states |
|
35 executeSoon(gNextTest); |
|
36 } |
|
37 |
|
38 function prepareTest(nextTest, url) { |
|
39 gNextTest = nextTest; |
|
40 gTestBrowser.contentWindow.location = url; |
|
41 } |
|
42 |
|
43 // Tests that navigation within the page and the window.history API doesn't break click-to-play state. |
|
44 function test1a() { |
|
45 var popupNotification = PopupNotifications.getNotification("click-to-play-plugins", gTestBrowser); |
|
46 ok(!popupNotification, "Test 1a, Should not have a click-to-play notification"); |
|
47 var plugin = new XPCNativeWrapper(XPCNativeWrapper.unwrap(gTestBrowser.contentWindow).addPlugin()); |
|
48 |
|
49 var condition = function() PopupNotifications.getNotification("click-to-play-plugins", gTestBrowser); |
|
50 waitForCondition(condition, test1b, "Test 1a, Waited too long for plugin notification"); |
|
51 } |
|
52 |
|
53 function test1b() { |
|
54 var popupNotification = PopupNotifications.getNotification("click-to-play-plugins", gTestBrowser); |
|
55 ok(popupNotification, "Test 1b, Should have a click-to-play notification"); |
|
56 var plugin = gTestBrowser.contentDocument.getElementsByTagName("embed")[0]; |
|
57 var objLoadingContent = plugin.QueryInterface(Ci.nsIObjectLoadingContent); |
|
58 ok(!objLoadingContent.activated, "Test 1b, Plugin should not be activated"); |
|
59 |
|
60 // Click the activate button on doorhanger to make sure it works |
|
61 popupNotification.reshow(); |
|
62 PopupNotifications.panel.firstChild._primaryButton.click(); |
|
63 |
|
64 ok(objLoadingContent.activated, "Test 1b, Doorhanger should activate plugin"); |
|
65 |
|
66 test1c(); |
|
67 } |
|
68 |
|
69 function test1c() { |
|
70 var popupNotification = PopupNotifications.getNotification("click-to-play-plugins", gTestBrowser); |
|
71 ok(popupNotification, "Test 1c, Should still have a click-to-play notification"); |
|
72 var plugin = new XPCNativeWrapper(XPCNativeWrapper.unwrap(gTestBrowser.contentWindow).addPlugin()); |
|
73 |
|
74 var objLoadingContent = plugin.QueryInterface(Ci.nsIObjectLoadingContent); |
|
75 var condition = function() objLoadingContent.activated; |
|
76 waitForCondition(condition, test1d, "Test 1c, Waited too long for plugin activation"); |
|
77 } |
|
78 |
|
79 function test1d() { |
|
80 var plugin = gTestBrowser.contentDocument.getElementsByTagName("embed")[1]; |
|
81 var objLoadingContent = plugin.QueryInterface(Ci.nsIObjectLoadingContent); |
|
82 ok(objLoadingContent.activated, "Test 1d, Plugin should be activated"); |
|
83 |
|
84 gNextTest = test1e; |
|
85 gTestBrowser.contentWindow.addEventListener("hashchange", test1e, false); |
|
86 gTestBrowser.contentWindow.location += "#anchorNavigation"; |
|
87 } |
|
88 |
|
89 function test1e() { |
|
90 gTestBrowser.contentWindow.removeEventListener("hashchange", test1e, false); |
|
91 |
|
92 var plugin = new XPCNativeWrapper(XPCNativeWrapper.unwrap(gTestBrowser.contentWindow).addPlugin()); |
|
93 |
|
94 var objLoadingContent = plugin.QueryInterface(Ci.nsIObjectLoadingContent); |
|
95 var condition = function() objLoadingContent.activated; |
|
96 waitForCondition(condition, test1f, "Test 1e, Waited too long for plugin activation"); |
|
97 } |
|
98 |
|
99 function test1f() { |
|
100 var plugin = gTestBrowser.contentDocument.getElementsByTagName("embed")[2]; |
|
101 var objLoadingContent = plugin.QueryInterface(Ci.nsIObjectLoadingContent); |
|
102 ok(objLoadingContent.activated, "Test 1f, Plugin should be activated"); |
|
103 |
|
104 gTestBrowser.contentWindow.history.replaceState({}, "", "replacedState"); |
|
105 var plugin = new XPCNativeWrapper(XPCNativeWrapper.unwrap(gTestBrowser.contentWindow).addPlugin()); |
|
106 var objLoadingContent = plugin.QueryInterface(Ci.nsIObjectLoadingContent); |
|
107 var condition = function() objLoadingContent.activated; |
|
108 waitForCondition(condition, test1g, "Test 1f, Waited too long for plugin activation"); |
|
109 } |
|
110 |
|
111 function test1g() { |
|
112 var plugin = gTestBrowser.contentDocument.getElementsByTagName("embed")[3]; |
|
113 var objLoadingContent2 = plugin.QueryInterface(Ci.nsIObjectLoadingContent); |
|
114 ok(objLoadingContent2.activated, "Test 1g, Plugin should be activated"); |
|
115 finishTest(); |
|
116 } |