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