1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/browser/base/content/test/plugins/browser_pageInfo_plugins.js Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,192 @@ 1.4 +let gHttpTestRoot = getRootDirectory(gTestPath).replace("chrome://mochitests/content/", "http://127.0.0.1:8888/"); 1.5 +let gPageInfo = null; 1.6 +let gNextTest = null; 1.7 +let gTestBrowser = null; 1.8 +let gPluginHost = Components.classes["@mozilla.org/plugin/host;1"] 1.9 + .getService(Components.interfaces.nsIPluginHost); 1.10 +let gPermissionManager = Components.classes["@mozilla.org/permissionmanager;1"] 1.11 + .getService(Components.interfaces.nsIPermissionManager); 1.12 +let gTestPermissionString = gPluginHost.getPermissionStringForType("application/x-test"); 1.13 +let gSecondTestPermissionString = gPluginHost.getPermissionStringForType("application/x-second-test"); 1.14 + 1.15 +function doOnPageLoad(url, continuation) { 1.16 + gNextTest = continuation; 1.17 + gTestBrowser.addEventListener("load", pageLoad, true); 1.18 + gTestBrowser.contentWindow.location = url; 1.19 +} 1.20 + 1.21 +function pageLoad() { 1.22 + gTestBrowser.removeEventListener("load", pageLoad); 1.23 + // The plugin events are async dispatched and can come after the load event 1.24 + // This just allows the events to fire before we then go on to test the states 1.25 + executeSoon(gNextTest); 1.26 +} 1.27 + 1.28 +function doOnOpenPageInfo(continuation) { 1.29 + Services.obs.addObserver(pageInfoObserve, "page-info-dialog-loaded", false); 1.30 + gNextTest = continuation; 1.31 + // An explanation: it looks like the test harness complains about leaked 1.32 + // windows if we don't keep a reference to every window we've opened. 1.33 + // So, don't reuse pointers to opened Page Info windows - simply append 1.34 + // to this list. 1.35 + gPageInfo = BrowserPageInfo(null, "permTab"); 1.36 +} 1.37 + 1.38 +function pageInfoObserve(win, topic, data) { 1.39 + Services.obs.removeObserver(pageInfoObserve, "page-info-dialog-loaded"); 1.40 + executeSoon(gNextTest); 1.41 +} 1.42 + 1.43 +function finishTest() { 1.44 + gPermissionManager.remove("127.0.0.1:8888", gTestPermissionString); 1.45 + gPermissionManager.remove("127.0.0.1:8888", gSecondTestPermissionString); 1.46 + Services.prefs.clearUserPref("plugins.click_to_play"); 1.47 + gBrowser.removeCurrentTab(); 1.48 + 1.49 + gPageInfo = null; 1.50 + gNextTest = null; 1.51 + gTestBrowser = null; 1.52 + gPluginHost = null; 1.53 + gPermissionManager = null; 1.54 + 1.55 + executeSoon(finish); 1.56 +} 1.57 + 1.58 +function test() { 1.59 + waitForExplicitFinish(); 1.60 + Services.prefs.setBoolPref("plugins.click_to_play", true); 1.61 + setTestPluginEnabledState(Ci.nsIPluginTag.STATE_CLICKTOPLAY); 1.62 + setTestPluginEnabledState(Ci.nsIPluginTag.STATE_ENABLED, "Second Test Plug-in"); 1.63 + gBrowser.selectedTab = gBrowser.addTab(); 1.64 + gTestBrowser = gBrowser.selectedBrowser; 1.65 + gPermissionManager.remove("127.0.0.1:8888", gTestPermissionString); 1.66 + gPermissionManager.remove("127.0.0.1:8888", gSecondTestPermissionString); 1.67 + doOnPageLoad(gHttpTestRoot + "plugin_two_types.html", testPart1a); 1.68 +} 1.69 + 1.70 +// The first test plugin is CtP and the second test plugin is enabled. 1.71 +function testPart1a() { 1.72 + let test = gTestBrowser.contentDocument.getElementById("test"); 1.73 + let objLoadingContent = test.QueryInterface(Ci.nsIObjectLoadingContent); 1.74 + ok(!objLoadingContent.activated, "part 1a: Test plugin should not be activated"); 1.75 + let secondtest = gTestBrowser.contentDocument.getElementById("secondtestA"); 1.76 + let objLoadingContent = secondtest.QueryInterface(Ci.nsIObjectLoadingContent); 1.77 + ok(objLoadingContent.activated, "part 1a: Second Test plugin should be activated"); 1.78 + 1.79 + doOnOpenPageInfo(testPart1b); 1.80 +} 1.81 + 1.82 +function testPart1b() { 1.83 + let testRadioGroup = gPageInfo.document.getElementById(gTestPermissionString + "RadioGroup"); 1.84 + let testRadioDefault = gPageInfo.document.getElementById(gTestPermissionString + "#0"); 1.85 + 1.86 + var qString = "#" + gTestPermissionString.replace(':', '\\:') + "\\#0"; 1.87 + is(testRadioGroup.selectedItem, testRadioDefault, "part 1b: Test radio group should be set to 'Default'"); 1.88 + let testRadioAllow = gPageInfo.document.getElementById(gTestPermissionString + "#1"); 1.89 + testRadioGroup.selectedItem = testRadioAllow; 1.90 + testRadioAllow.doCommand(); 1.91 + 1.92 + let secondtestRadioGroup = gPageInfo.document.getElementById(gSecondTestPermissionString + "RadioGroup"); 1.93 + let secondtestRadioDefault = gPageInfo.document.getElementById(gSecondTestPermissionString + "#0"); 1.94 + is(secondtestRadioGroup.selectedItem, secondtestRadioDefault, "part 1b: Second Test radio group should be set to 'Default'"); 1.95 + let secondtestRadioAsk = gPageInfo.document.getElementById(gSecondTestPermissionString + "#3"); 1.96 + secondtestRadioGroup.selectedItem = secondtestRadioAsk; 1.97 + secondtestRadioAsk.doCommand(); 1.98 + 1.99 + doOnPageLoad(gHttpTestRoot + "plugin_two_types.html", testPart2); 1.100 +} 1.101 + 1.102 +// Now, the Test plugin should be allowed, and the Test2 plugin should be CtP 1.103 +function testPart2() { 1.104 + let test = gTestBrowser.contentDocument.getElementById("test"). 1.105 + QueryInterface(Ci.nsIObjectLoadingContent); 1.106 + ok(test.activated, "part 2: Test plugin should be activated"); 1.107 + 1.108 + let secondtest = gTestBrowser.contentDocument.getElementById("secondtestA"). 1.109 + QueryInterface(Ci.nsIObjectLoadingContent); 1.110 + ok(!secondtest.activated, "part 2: Second Test plugin should not be activated"); 1.111 + is(secondtest.pluginFallbackType, Ci.nsIObjectLoadingContent.PLUGIN_CLICK_TO_PLAY, 1.112 + "part 2: Second test plugin should be click-to-play."); 1.113 + 1.114 + let testRadioGroup = gPageInfo.document.getElementById(gTestPermissionString + "RadioGroup"); 1.115 + let testRadioAllow = gPageInfo.document.getElementById(gTestPermissionString + "#1"); 1.116 + is(testRadioGroup.selectedItem, testRadioAllow, "part 2: Test radio group should be set to 'Allow'"); 1.117 + let testRadioBlock = gPageInfo.document.getElementById(gTestPermissionString + "#2"); 1.118 + testRadioGroup.selectedItem = testRadioBlock; 1.119 + testRadioBlock.doCommand(); 1.120 + 1.121 + let secondtestRadioGroup = gPageInfo.document.getElementById(gSecondTestPermissionString + "RadioGroup"); 1.122 + let secondtestRadioAsk = gPageInfo.document.getElementById(gSecondTestPermissionString + "#3"); 1.123 + is(secondtestRadioGroup.selectedItem, secondtestRadioAsk, "part 2: Second Test radio group should be set to 'Always Ask'"); 1.124 + let secondtestRadioBlock = gPageInfo.document.getElementById(gSecondTestPermissionString + "#2"); 1.125 + secondtestRadioGroup.selectedItem = secondtestRadioBlock; 1.126 + secondtestRadioBlock.doCommand(); 1.127 + 1.128 + doOnPageLoad(gHttpTestRoot + "plugin_two_types.html", testPart3); 1.129 +} 1.130 + 1.131 +// Now, all the things should be blocked 1.132 +function testPart3() { 1.133 + let test = gTestBrowser.contentDocument.getElementById("test"). 1.134 + QueryInterface(Ci.nsIObjectLoadingContent); 1.135 + ok(!test.activated, "part 3: Test plugin should not be activated"); 1.136 + is(test.pluginFallbackType, Ci.nsIObjectLoadingContent.PLUGIN_DISABLED, 1.137 + "part 3: Test plugin should be marked as PLUGIN_DISABLED"); 1.138 + 1.139 + let secondtest = gTestBrowser.contentDocument.getElementById("secondtestA"). 1.140 + QueryInterface(Ci.nsIObjectLoadingContent); 1.141 + 1.142 + ok(!secondtest.activated, "part 3: Second Test plugin should not be activated"); 1.143 + is(secondtest.pluginFallbackType, Ci.nsIObjectLoadingContent.PLUGIN_DISABLED, 1.144 + "part 3: Second test plugin should be marked as PLUGIN_DISABLED"); 1.145 + 1.146 + // reset permissions 1.147 + gPermissionManager.remove("127.0.0.1:8888", gTestPermissionString); 1.148 + gPermissionManager.remove("127.0.0.1:8888", gSecondTestPermissionString); 1.149 + // check that changing the permissions affects the radio state in the 1.150 + // open Page Info window 1.151 + let testRadioGroup = gPageInfo.document.getElementById(gTestPermissionString + "RadioGroup"); 1.152 + let testRadioDefault = gPageInfo.document.getElementById(gTestPermissionString + "#0"); 1.153 + is(testRadioGroup.selectedItem, testRadioDefault, "part 3: Test radio group should be set to 'Default'"); 1.154 + let secondtestRadioGroup = gPageInfo.document.getElementById(gSecondTestPermissionString + "RadioGroup"); 1.155 + let secondtestRadioDefault = gPageInfo.document.getElementById(gSecondTestPermissionString + "#0"); 1.156 + is(secondtestRadioGroup.selectedItem, secondtestRadioDefault, "part 3: Second Test radio group should be set to 'Default'"); 1.157 + 1.158 + doOnPageLoad(gHttpTestRoot + "plugin_two_types.html", testPart4a); 1.159 +} 1.160 + 1.161 +// Now test that setting permission directly (as from the popup notification) 1.162 +// immediately influences Page Info. 1.163 +function testPart4a() { 1.164 + // simulate "allow" from the doorhanger 1.165 + gPermissionManager.add(gTestBrowser.currentURI, gTestPermissionString, Ci.nsIPermissionManager.ALLOW_ACTION); 1.166 + gPermissionManager.add(gTestBrowser.currentURI, gSecondTestPermissionString, Ci.nsIPermissionManager.ALLOW_ACTION); 1.167 + 1.168 + // check (again) that changing the permissions affects the radio state in the 1.169 + // open Page Info window 1.170 + let testRadioGroup = gPageInfo.document.getElementById(gTestPermissionString + "RadioGroup"); 1.171 + let testRadioAllow = gPageInfo.document.getElementById(gTestPermissionString + "#1"); 1.172 + is(testRadioGroup.selectedItem, testRadioAllow, "part 4a: Test radio group should be set to 'Allow'"); 1.173 + let secondtestRadioGroup = gPageInfo.document.getElementById(gSecondTestPermissionString + "RadioGroup"); 1.174 + let secondtestRadioAllow = gPageInfo.document.getElementById(gSecondTestPermissionString + "#1"); 1.175 + is(secondtestRadioGroup.selectedItem, secondtestRadioAllow, "part 4a: Second Test radio group should be set to 'Always Allow'"); 1.176 + 1.177 + // now close Page Info and see that it opens with the right settings 1.178 + gPageInfo.close(); 1.179 + doOnOpenPageInfo(testPart4b); 1.180 +} 1.181 + 1.182 +// check that "always allow" resulted in the radio buttons getting set to allow 1.183 +function testPart4b() { 1.184 + let testRadioGroup = gPageInfo.document.getElementById(gTestPermissionString + "RadioGroup"); 1.185 + let testRadioAllow = gPageInfo.document.getElementById(gTestPermissionString + "#1"); 1.186 + is(testRadioGroup.selectedItem, testRadioAllow, "part 4b: Test radio group should be set to 'Allow'"); 1.187 + 1.188 + let secondtestRadioGroup = gPageInfo.document.getElementById(gSecondTestPermissionString + "RadioGroup"); 1.189 + let secondtestRadioAllow = gPageInfo.document.getElementById(gSecondTestPermissionString + "#1"); 1.190 + is(secondtestRadioGroup.selectedItem, secondtestRadioAllow, "part 4b: Second Test radio group should be set to 'Allow'"); 1.191 + 1.192 + Services.prefs.setBoolPref("plugins.click_to_play", false); 1.193 + gPageInfo.close(); 1.194 + finishTest(); 1.195 +}