michael@0: let gHttpTestRoot = getRootDirectory(gTestPath).replace("chrome://mochitests/content/", "http://127.0.0.1:8888/"); michael@0: let gPageInfo = null; michael@0: let gNextTest = null; michael@0: let gTestBrowser = null; michael@0: let gPluginHost = Components.classes["@mozilla.org/plugin/host;1"] michael@0: .getService(Components.interfaces.nsIPluginHost); michael@0: let gPermissionManager = Components.classes["@mozilla.org/permissionmanager;1"] michael@0: .getService(Components.interfaces.nsIPermissionManager); michael@0: let gTestPermissionString = gPluginHost.getPermissionStringForType("application/x-test"); michael@0: let gSecondTestPermissionString = gPluginHost.getPermissionStringForType("application/x-second-test"); michael@0: michael@0: function doOnPageLoad(url, continuation) { michael@0: gNextTest = continuation; michael@0: gTestBrowser.addEventListener("load", pageLoad, true); michael@0: gTestBrowser.contentWindow.location = url; michael@0: } michael@0: michael@0: function pageLoad() { michael@0: gTestBrowser.removeEventListener("load", pageLoad); michael@0: // The plugin events are async dispatched and can come after the load event michael@0: // This just allows the events to fire before we then go on to test the states michael@0: executeSoon(gNextTest); michael@0: } michael@0: michael@0: function doOnOpenPageInfo(continuation) { michael@0: Services.obs.addObserver(pageInfoObserve, "page-info-dialog-loaded", false); michael@0: gNextTest = continuation; michael@0: // An explanation: it looks like the test harness complains about leaked michael@0: // windows if we don't keep a reference to every window we've opened. michael@0: // So, don't reuse pointers to opened Page Info windows - simply append michael@0: // to this list. michael@0: gPageInfo = BrowserPageInfo(null, "permTab"); michael@0: } michael@0: michael@0: function pageInfoObserve(win, topic, data) { michael@0: Services.obs.removeObserver(pageInfoObserve, "page-info-dialog-loaded"); michael@0: executeSoon(gNextTest); michael@0: } michael@0: michael@0: function finishTest() { michael@0: gPermissionManager.remove("127.0.0.1:8888", gTestPermissionString); michael@0: gPermissionManager.remove("127.0.0.1:8888", gSecondTestPermissionString); michael@0: Services.prefs.clearUserPref("plugins.click_to_play"); michael@0: gBrowser.removeCurrentTab(); michael@0: michael@0: gPageInfo = null; michael@0: gNextTest = null; michael@0: gTestBrowser = null; michael@0: gPluginHost = null; michael@0: gPermissionManager = null; michael@0: michael@0: executeSoon(finish); michael@0: } michael@0: michael@0: function test() { michael@0: waitForExplicitFinish(); michael@0: Services.prefs.setBoolPref("plugins.click_to_play", true); michael@0: setTestPluginEnabledState(Ci.nsIPluginTag.STATE_CLICKTOPLAY); michael@0: setTestPluginEnabledState(Ci.nsIPluginTag.STATE_ENABLED, "Second Test Plug-in"); michael@0: gBrowser.selectedTab = gBrowser.addTab(); michael@0: gTestBrowser = gBrowser.selectedBrowser; michael@0: gPermissionManager.remove("127.0.0.1:8888", gTestPermissionString); michael@0: gPermissionManager.remove("127.0.0.1:8888", gSecondTestPermissionString); michael@0: doOnPageLoad(gHttpTestRoot + "plugin_two_types.html", testPart1a); michael@0: } michael@0: michael@0: // The first test plugin is CtP and the second test plugin is enabled. michael@0: function testPart1a() { michael@0: let test = gTestBrowser.contentDocument.getElementById("test"); michael@0: let objLoadingContent = test.QueryInterface(Ci.nsIObjectLoadingContent); michael@0: ok(!objLoadingContent.activated, "part 1a: Test plugin should not be activated"); michael@0: let secondtest = gTestBrowser.contentDocument.getElementById("secondtestA"); michael@0: let objLoadingContent = secondtest.QueryInterface(Ci.nsIObjectLoadingContent); michael@0: ok(objLoadingContent.activated, "part 1a: Second Test plugin should be activated"); michael@0: michael@0: doOnOpenPageInfo(testPart1b); michael@0: } michael@0: michael@0: function testPart1b() { michael@0: let testRadioGroup = gPageInfo.document.getElementById(gTestPermissionString + "RadioGroup"); michael@0: let testRadioDefault = gPageInfo.document.getElementById(gTestPermissionString + "#0"); michael@0: michael@0: var qString = "#" + gTestPermissionString.replace(':', '\\:') + "\\#0"; michael@0: is(testRadioGroup.selectedItem, testRadioDefault, "part 1b: Test radio group should be set to 'Default'"); michael@0: let testRadioAllow = gPageInfo.document.getElementById(gTestPermissionString + "#1"); michael@0: testRadioGroup.selectedItem = testRadioAllow; michael@0: testRadioAllow.doCommand(); michael@0: michael@0: let secondtestRadioGroup = gPageInfo.document.getElementById(gSecondTestPermissionString + "RadioGroup"); michael@0: let secondtestRadioDefault = gPageInfo.document.getElementById(gSecondTestPermissionString + "#0"); michael@0: is(secondtestRadioGroup.selectedItem, secondtestRadioDefault, "part 1b: Second Test radio group should be set to 'Default'"); michael@0: let secondtestRadioAsk = gPageInfo.document.getElementById(gSecondTestPermissionString + "#3"); michael@0: secondtestRadioGroup.selectedItem = secondtestRadioAsk; michael@0: secondtestRadioAsk.doCommand(); michael@0: michael@0: doOnPageLoad(gHttpTestRoot + "plugin_two_types.html", testPart2); michael@0: } michael@0: michael@0: // Now, the Test plugin should be allowed, and the Test2 plugin should be CtP michael@0: function testPart2() { michael@0: let test = gTestBrowser.contentDocument.getElementById("test"). michael@0: QueryInterface(Ci.nsIObjectLoadingContent); michael@0: ok(test.activated, "part 2: Test plugin should be activated"); michael@0: michael@0: let secondtest = gTestBrowser.contentDocument.getElementById("secondtestA"). michael@0: QueryInterface(Ci.nsIObjectLoadingContent); michael@0: ok(!secondtest.activated, "part 2: Second Test plugin should not be activated"); michael@0: is(secondtest.pluginFallbackType, Ci.nsIObjectLoadingContent.PLUGIN_CLICK_TO_PLAY, michael@0: "part 2: Second test plugin should be click-to-play."); michael@0: michael@0: let testRadioGroup = gPageInfo.document.getElementById(gTestPermissionString + "RadioGroup"); michael@0: let testRadioAllow = gPageInfo.document.getElementById(gTestPermissionString + "#1"); michael@0: is(testRadioGroup.selectedItem, testRadioAllow, "part 2: Test radio group should be set to 'Allow'"); michael@0: let testRadioBlock = gPageInfo.document.getElementById(gTestPermissionString + "#2"); michael@0: testRadioGroup.selectedItem = testRadioBlock; michael@0: testRadioBlock.doCommand(); michael@0: michael@0: let secondtestRadioGroup = gPageInfo.document.getElementById(gSecondTestPermissionString + "RadioGroup"); michael@0: let secondtestRadioAsk = gPageInfo.document.getElementById(gSecondTestPermissionString + "#3"); michael@0: is(secondtestRadioGroup.selectedItem, secondtestRadioAsk, "part 2: Second Test radio group should be set to 'Always Ask'"); michael@0: let secondtestRadioBlock = gPageInfo.document.getElementById(gSecondTestPermissionString + "#2"); michael@0: secondtestRadioGroup.selectedItem = secondtestRadioBlock; michael@0: secondtestRadioBlock.doCommand(); michael@0: michael@0: doOnPageLoad(gHttpTestRoot + "plugin_two_types.html", testPart3); michael@0: } michael@0: michael@0: // Now, all the things should be blocked michael@0: function testPart3() { michael@0: let test = gTestBrowser.contentDocument.getElementById("test"). michael@0: QueryInterface(Ci.nsIObjectLoadingContent); michael@0: ok(!test.activated, "part 3: Test plugin should not be activated"); michael@0: is(test.pluginFallbackType, Ci.nsIObjectLoadingContent.PLUGIN_DISABLED, michael@0: "part 3: Test plugin should be marked as PLUGIN_DISABLED"); michael@0: michael@0: let secondtest = gTestBrowser.contentDocument.getElementById("secondtestA"). michael@0: QueryInterface(Ci.nsIObjectLoadingContent); michael@0: michael@0: ok(!secondtest.activated, "part 3: Second Test plugin should not be activated"); michael@0: is(secondtest.pluginFallbackType, Ci.nsIObjectLoadingContent.PLUGIN_DISABLED, michael@0: "part 3: Second test plugin should be marked as PLUGIN_DISABLED"); michael@0: michael@0: // reset permissions michael@0: gPermissionManager.remove("127.0.0.1:8888", gTestPermissionString); michael@0: gPermissionManager.remove("127.0.0.1:8888", gSecondTestPermissionString); michael@0: // check that changing the permissions affects the radio state in the michael@0: // open Page Info window michael@0: let testRadioGroup = gPageInfo.document.getElementById(gTestPermissionString + "RadioGroup"); michael@0: let testRadioDefault = gPageInfo.document.getElementById(gTestPermissionString + "#0"); michael@0: is(testRadioGroup.selectedItem, testRadioDefault, "part 3: Test radio group should be set to 'Default'"); michael@0: let secondtestRadioGroup = gPageInfo.document.getElementById(gSecondTestPermissionString + "RadioGroup"); michael@0: let secondtestRadioDefault = gPageInfo.document.getElementById(gSecondTestPermissionString + "#0"); michael@0: is(secondtestRadioGroup.selectedItem, secondtestRadioDefault, "part 3: Second Test radio group should be set to 'Default'"); michael@0: michael@0: doOnPageLoad(gHttpTestRoot + "plugin_two_types.html", testPart4a); michael@0: } michael@0: michael@0: // Now test that setting permission directly (as from the popup notification) michael@0: // immediately influences Page Info. michael@0: function testPart4a() { michael@0: // simulate "allow" from the doorhanger michael@0: gPermissionManager.add(gTestBrowser.currentURI, gTestPermissionString, Ci.nsIPermissionManager.ALLOW_ACTION); michael@0: gPermissionManager.add(gTestBrowser.currentURI, gSecondTestPermissionString, Ci.nsIPermissionManager.ALLOW_ACTION); michael@0: michael@0: // check (again) that changing the permissions affects the radio state in the michael@0: // open Page Info window michael@0: let testRadioGroup = gPageInfo.document.getElementById(gTestPermissionString + "RadioGroup"); michael@0: let testRadioAllow = gPageInfo.document.getElementById(gTestPermissionString + "#1"); michael@0: is(testRadioGroup.selectedItem, testRadioAllow, "part 4a: Test radio group should be set to 'Allow'"); michael@0: let secondtestRadioGroup = gPageInfo.document.getElementById(gSecondTestPermissionString + "RadioGroup"); michael@0: let secondtestRadioAllow = gPageInfo.document.getElementById(gSecondTestPermissionString + "#1"); michael@0: is(secondtestRadioGroup.selectedItem, secondtestRadioAllow, "part 4a: Second Test radio group should be set to 'Always Allow'"); michael@0: michael@0: // now close Page Info and see that it opens with the right settings michael@0: gPageInfo.close(); michael@0: doOnOpenPageInfo(testPart4b); michael@0: } michael@0: michael@0: // check that "always allow" resulted in the radio buttons getting set to allow michael@0: function testPart4b() { michael@0: let testRadioGroup = gPageInfo.document.getElementById(gTestPermissionString + "RadioGroup"); michael@0: let testRadioAllow = gPageInfo.document.getElementById(gTestPermissionString + "#1"); michael@0: is(testRadioGroup.selectedItem, testRadioAllow, "part 4b: Test radio group should be set to 'Allow'"); michael@0: michael@0: let secondtestRadioGroup = gPageInfo.document.getElementById(gSecondTestPermissionString + "RadioGroup"); michael@0: let secondtestRadioAllow = gPageInfo.document.getElementById(gSecondTestPermissionString + "#1"); michael@0: is(secondtestRadioGroup.selectedItem, secondtestRadioAllow, "part 4b: Second Test radio group should be set to 'Allow'"); michael@0: michael@0: Services.prefs.setBoolPref("plugins.click_to_play", false); michael@0: gPageInfo.close(); michael@0: finishTest(); michael@0: }