|
1 let gHttpTestRoot = getRootDirectory(gTestPath).replace("chrome://mochitests/content/", "http://127.0.0.1:8888/"); |
|
2 let gPageInfo = null; |
|
3 let gNextTest = null; |
|
4 let gTestBrowser = null; |
|
5 let gPluginHost = Components.classes["@mozilla.org/plugin/host;1"] |
|
6 .getService(Components.interfaces.nsIPluginHost); |
|
7 let gPermissionManager = Components.classes["@mozilla.org/permissionmanager;1"] |
|
8 .getService(Components.interfaces.nsIPermissionManager); |
|
9 let gTestPermissionString = gPluginHost.getPermissionStringForType("application/x-test"); |
|
10 let gSecondTestPermissionString = gPluginHost.getPermissionStringForType("application/x-second-test"); |
|
11 |
|
12 function doOnPageLoad(url, continuation) { |
|
13 gNextTest = continuation; |
|
14 gTestBrowser.addEventListener("load", pageLoad, true); |
|
15 gTestBrowser.contentWindow.location = url; |
|
16 } |
|
17 |
|
18 function pageLoad() { |
|
19 gTestBrowser.removeEventListener("load", pageLoad); |
|
20 // The plugin events are async dispatched and can come after the load event |
|
21 // This just allows the events to fire before we then go on to test the states |
|
22 executeSoon(gNextTest); |
|
23 } |
|
24 |
|
25 function doOnOpenPageInfo(continuation) { |
|
26 Services.obs.addObserver(pageInfoObserve, "page-info-dialog-loaded", false); |
|
27 gNextTest = continuation; |
|
28 // An explanation: it looks like the test harness complains about leaked |
|
29 // windows if we don't keep a reference to every window we've opened. |
|
30 // So, don't reuse pointers to opened Page Info windows - simply append |
|
31 // to this list. |
|
32 gPageInfo = BrowserPageInfo(null, "permTab"); |
|
33 } |
|
34 |
|
35 function pageInfoObserve(win, topic, data) { |
|
36 Services.obs.removeObserver(pageInfoObserve, "page-info-dialog-loaded"); |
|
37 executeSoon(gNextTest); |
|
38 } |
|
39 |
|
40 function finishTest() { |
|
41 gPermissionManager.remove("127.0.0.1:8888", gTestPermissionString); |
|
42 gPermissionManager.remove("127.0.0.1:8888", gSecondTestPermissionString); |
|
43 Services.prefs.clearUserPref("plugins.click_to_play"); |
|
44 gBrowser.removeCurrentTab(); |
|
45 |
|
46 gPageInfo = null; |
|
47 gNextTest = null; |
|
48 gTestBrowser = null; |
|
49 gPluginHost = null; |
|
50 gPermissionManager = null; |
|
51 |
|
52 executeSoon(finish); |
|
53 } |
|
54 |
|
55 function test() { |
|
56 waitForExplicitFinish(); |
|
57 Services.prefs.setBoolPref("plugins.click_to_play", true); |
|
58 setTestPluginEnabledState(Ci.nsIPluginTag.STATE_CLICKTOPLAY); |
|
59 setTestPluginEnabledState(Ci.nsIPluginTag.STATE_ENABLED, "Second Test Plug-in"); |
|
60 gBrowser.selectedTab = gBrowser.addTab(); |
|
61 gTestBrowser = gBrowser.selectedBrowser; |
|
62 gPermissionManager.remove("127.0.0.1:8888", gTestPermissionString); |
|
63 gPermissionManager.remove("127.0.0.1:8888", gSecondTestPermissionString); |
|
64 doOnPageLoad(gHttpTestRoot + "plugin_two_types.html", testPart1a); |
|
65 } |
|
66 |
|
67 // The first test plugin is CtP and the second test plugin is enabled. |
|
68 function testPart1a() { |
|
69 let test = gTestBrowser.contentDocument.getElementById("test"); |
|
70 let objLoadingContent = test.QueryInterface(Ci.nsIObjectLoadingContent); |
|
71 ok(!objLoadingContent.activated, "part 1a: Test plugin should not be activated"); |
|
72 let secondtest = gTestBrowser.contentDocument.getElementById("secondtestA"); |
|
73 let objLoadingContent = secondtest.QueryInterface(Ci.nsIObjectLoadingContent); |
|
74 ok(objLoadingContent.activated, "part 1a: Second Test plugin should be activated"); |
|
75 |
|
76 doOnOpenPageInfo(testPart1b); |
|
77 } |
|
78 |
|
79 function testPart1b() { |
|
80 let testRadioGroup = gPageInfo.document.getElementById(gTestPermissionString + "RadioGroup"); |
|
81 let testRadioDefault = gPageInfo.document.getElementById(gTestPermissionString + "#0"); |
|
82 |
|
83 var qString = "#" + gTestPermissionString.replace(':', '\\:') + "\\#0"; |
|
84 is(testRadioGroup.selectedItem, testRadioDefault, "part 1b: Test radio group should be set to 'Default'"); |
|
85 let testRadioAllow = gPageInfo.document.getElementById(gTestPermissionString + "#1"); |
|
86 testRadioGroup.selectedItem = testRadioAllow; |
|
87 testRadioAllow.doCommand(); |
|
88 |
|
89 let secondtestRadioGroup = gPageInfo.document.getElementById(gSecondTestPermissionString + "RadioGroup"); |
|
90 let secondtestRadioDefault = gPageInfo.document.getElementById(gSecondTestPermissionString + "#0"); |
|
91 is(secondtestRadioGroup.selectedItem, secondtestRadioDefault, "part 1b: Second Test radio group should be set to 'Default'"); |
|
92 let secondtestRadioAsk = gPageInfo.document.getElementById(gSecondTestPermissionString + "#3"); |
|
93 secondtestRadioGroup.selectedItem = secondtestRadioAsk; |
|
94 secondtestRadioAsk.doCommand(); |
|
95 |
|
96 doOnPageLoad(gHttpTestRoot + "plugin_two_types.html", testPart2); |
|
97 } |
|
98 |
|
99 // Now, the Test plugin should be allowed, and the Test2 plugin should be CtP |
|
100 function testPart2() { |
|
101 let test = gTestBrowser.contentDocument.getElementById("test"). |
|
102 QueryInterface(Ci.nsIObjectLoadingContent); |
|
103 ok(test.activated, "part 2: Test plugin should be activated"); |
|
104 |
|
105 let secondtest = gTestBrowser.contentDocument.getElementById("secondtestA"). |
|
106 QueryInterface(Ci.nsIObjectLoadingContent); |
|
107 ok(!secondtest.activated, "part 2: Second Test plugin should not be activated"); |
|
108 is(secondtest.pluginFallbackType, Ci.nsIObjectLoadingContent.PLUGIN_CLICK_TO_PLAY, |
|
109 "part 2: Second test plugin should be click-to-play."); |
|
110 |
|
111 let testRadioGroup = gPageInfo.document.getElementById(gTestPermissionString + "RadioGroup"); |
|
112 let testRadioAllow = gPageInfo.document.getElementById(gTestPermissionString + "#1"); |
|
113 is(testRadioGroup.selectedItem, testRadioAllow, "part 2: Test radio group should be set to 'Allow'"); |
|
114 let testRadioBlock = gPageInfo.document.getElementById(gTestPermissionString + "#2"); |
|
115 testRadioGroup.selectedItem = testRadioBlock; |
|
116 testRadioBlock.doCommand(); |
|
117 |
|
118 let secondtestRadioGroup = gPageInfo.document.getElementById(gSecondTestPermissionString + "RadioGroup"); |
|
119 let secondtestRadioAsk = gPageInfo.document.getElementById(gSecondTestPermissionString + "#3"); |
|
120 is(secondtestRadioGroup.selectedItem, secondtestRadioAsk, "part 2: Second Test radio group should be set to 'Always Ask'"); |
|
121 let secondtestRadioBlock = gPageInfo.document.getElementById(gSecondTestPermissionString + "#2"); |
|
122 secondtestRadioGroup.selectedItem = secondtestRadioBlock; |
|
123 secondtestRadioBlock.doCommand(); |
|
124 |
|
125 doOnPageLoad(gHttpTestRoot + "plugin_two_types.html", testPart3); |
|
126 } |
|
127 |
|
128 // Now, all the things should be blocked |
|
129 function testPart3() { |
|
130 let test = gTestBrowser.contentDocument.getElementById("test"). |
|
131 QueryInterface(Ci.nsIObjectLoadingContent); |
|
132 ok(!test.activated, "part 3: Test plugin should not be activated"); |
|
133 is(test.pluginFallbackType, Ci.nsIObjectLoadingContent.PLUGIN_DISABLED, |
|
134 "part 3: Test plugin should be marked as PLUGIN_DISABLED"); |
|
135 |
|
136 let secondtest = gTestBrowser.contentDocument.getElementById("secondtestA"). |
|
137 QueryInterface(Ci.nsIObjectLoadingContent); |
|
138 |
|
139 ok(!secondtest.activated, "part 3: Second Test plugin should not be activated"); |
|
140 is(secondtest.pluginFallbackType, Ci.nsIObjectLoadingContent.PLUGIN_DISABLED, |
|
141 "part 3: Second test plugin should be marked as PLUGIN_DISABLED"); |
|
142 |
|
143 // reset permissions |
|
144 gPermissionManager.remove("127.0.0.1:8888", gTestPermissionString); |
|
145 gPermissionManager.remove("127.0.0.1:8888", gSecondTestPermissionString); |
|
146 // check that changing the permissions affects the radio state in the |
|
147 // open Page Info window |
|
148 let testRadioGroup = gPageInfo.document.getElementById(gTestPermissionString + "RadioGroup"); |
|
149 let testRadioDefault = gPageInfo.document.getElementById(gTestPermissionString + "#0"); |
|
150 is(testRadioGroup.selectedItem, testRadioDefault, "part 3: Test radio group should be set to 'Default'"); |
|
151 let secondtestRadioGroup = gPageInfo.document.getElementById(gSecondTestPermissionString + "RadioGroup"); |
|
152 let secondtestRadioDefault = gPageInfo.document.getElementById(gSecondTestPermissionString + "#0"); |
|
153 is(secondtestRadioGroup.selectedItem, secondtestRadioDefault, "part 3: Second Test radio group should be set to 'Default'"); |
|
154 |
|
155 doOnPageLoad(gHttpTestRoot + "plugin_two_types.html", testPart4a); |
|
156 } |
|
157 |
|
158 // Now test that setting permission directly (as from the popup notification) |
|
159 // immediately influences Page Info. |
|
160 function testPart4a() { |
|
161 // simulate "allow" from the doorhanger |
|
162 gPermissionManager.add(gTestBrowser.currentURI, gTestPermissionString, Ci.nsIPermissionManager.ALLOW_ACTION); |
|
163 gPermissionManager.add(gTestBrowser.currentURI, gSecondTestPermissionString, Ci.nsIPermissionManager.ALLOW_ACTION); |
|
164 |
|
165 // check (again) that changing the permissions affects the radio state in the |
|
166 // open Page Info window |
|
167 let testRadioGroup = gPageInfo.document.getElementById(gTestPermissionString + "RadioGroup"); |
|
168 let testRadioAllow = gPageInfo.document.getElementById(gTestPermissionString + "#1"); |
|
169 is(testRadioGroup.selectedItem, testRadioAllow, "part 4a: Test radio group should be set to 'Allow'"); |
|
170 let secondtestRadioGroup = gPageInfo.document.getElementById(gSecondTestPermissionString + "RadioGroup"); |
|
171 let secondtestRadioAllow = gPageInfo.document.getElementById(gSecondTestPermissionString + "#1"); |
|
172 is(secondtestRadioGroup.selectedItem, secondtestRadioAllow, "part 4a: Second Test radio group should be set to 'Always Allow'"); |
|
173 |
|
174 // now close Page Info and see that it opens with the right settings |
|
175 gPageInfo.close(); |
|
176 doOnOpenPageInfo(testPart4b); |
|
177 } |
|
178 |
|
179 // check that "always allow" resulted in the radio buttons getting set to allow |
|
180 function testPart4b() { |
|
181 let testRadioGroup = gPageInfo.document.getElementById(gTestPermissionString + "RadioGroup"); |
|
182 let testRadioAllow = gPageInfo.document.getElementById(gTestPermissionString + "#1"); |
|
183 is(testRadioGroup.selectedItem, testRadioAllow, "part 4b: Test radio group should be set to 'Allow'"); |
|
184 |
|
185 let secondtestRadioGroup = gPageInfo.document.getElementById(gSecondTestPermissionString + "RadioGroup"); |
|
186 let secondtestRadioAllow = gPageInfo.document.getElementById(gSecondTestPermissionString + "#1"); |
|
187 is(secondtestRadioGroup.selectedItem, secondtestRadioAllow, "part 4b: Second Test radio group should be set to 'Allow'"); |
|
188 |
|
189 Services.prefs.setBoolPref("plugins.click_to_play", false); |
|
190 gPageInfo.close(); |
|
191 finishTest(); |
|
192 } |