michael@0: var gHttpTestRoot = getRootDirectory(gTestPath).replace("chrome://mochitests/content/", "http://127.0.0.1:8888/"); michael@0: var gTestBrowser = null; michael@0: var gNextTest = null; michael@0: michael@0: Components.utils.import("resource://gre/modules/Services.jsm"); michael@0: michael@0: function test() { michael@0: waitForExplicitFinish(); michael@0: registerCleanupFunction(function() { michael@0: Services.prefs.clearUserPref("plugins.click_to_play"); michael@0: }); michael@0: Services.prefs.setBoolPref("plugins.click_to_play", true); michael@0: setTestPluginEnabledState(Ci.nsIPluginTag.STATE_CLICKTOPLAY); michael@0: michael@0: var newTab = gBrowser.addTab(); michael@0: gBrowser.selectedTab = newTab; michael@0: gTestBrowser = gBrowser.selectedBrowser; michael@0: gTestBrowser.addEventListener("load", pageLoad, true); michael@0: setAndUpdateBlocklist(gHttpTestRoot + "blockPluginVulnerableUpdatable.xml", michael@0: function() { michael@0: prepareTest(function() { michael@0: // Due to layout being async, "PluginBindAttached" may trigger later. michael@0: // This forces a layout flush, thus triggering it, and schedules the michael@0: // test so it is definitely executed afterwards. michael@0: gTestBrowser.contentDocument.getElementById('test').clientTop; michael@0: testPart1(); michael@0: }, michael@0: gHttpTestRoot + "plugin_test.html"); michael@0: }); michael@0: } michael@0: michael@0: function finishTest() { michael@0: gTestBrowser.removeEventListener("load", pageLoad, true); michael@0: gBrowser.removeCurrentTab(); michael@0: window.focus(); michael@0: setAndUpdateBlocklist(gHttpTestRoot + "blockNoPlugins.xml", michael@0: function() { michael@0: resetBlocklist(); michael@0: finish(); michael@0: }); michael@0: } michael@0: michael@0: function pageLoad(aEvent) { 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: if (gNextTest != null) michael@0: executeSoon(gNextTest); michael@0: } michael@0: michael@0: function prepareTest(nextTest, url) { michael@0: gNextTest = nextTest; michael@0: gTestBrowser.contentWindow.location = url; michael@0: } michael@0: michael@0: // Tests that the going back will reshow the notification for click-to-play michael@0: // blocklisted plugins (part 1/4) michael@0: function testPart1() { michael@0: var popupNotification = PopupNotifications.getNotification("click-to-play-plugins", gTestBrowser); michael@0: ok(popupNotification, "test part 1: Should have a click-to-play notification"); michael@0: var plugin = gTestBrowser.contentDocument.getElementById("test"); michael@0: var objLoadingContent = plugin.QueryInterface(Ci.nsIObjectLoadingContent); michael@0: is(objLoadingContent.pluginFallbackType, Ci.nsIObjectLoadingContent.PLUGIN_VULNERABLE_UPDATABLE, "test part 1: plugin fallback type should be PLUGIN_VULNERABLE_UPDATABLE"); michael@0: ok(!objLoadingContent.activated, "test part 1: plugin should not be activated"); michael@0: michael@0: prepareTest(testPart2, "about:blank"); michael@0: } michael@0: michael@0: function testPart2() { michael@0: var popupNotification = PopupNotifications.getNotification("click-to-play-plugins", gTestBrowser); michael@0: ok(!popupNotification, "test part 2: Should not have a click-to-play notification"); michael@0: var plugin = gTestBrowser.contentDocument.getElementById("test"); michael@0: ok(!plugin, "test part 2: Should not have a plugin in this page"); michael@0: michael@0: Services.obs.addObserver(testPart3, "PopupNotifications-updateNotShowing", false); michael@0: gTestBrowser.contentWindow.history.back(); michael@0: } michael@0: michael@0: function testPart3() { michael@0: Services.obs.removeObserver(testPart3, "PopupNotifications-updateNotShowing"); michael@0: var condition = function() PopupNotifications.getNotification("click-to-play-plugins", gTestBrowser); michael@0: waitForCondition(condition, testPart4, "test part 3: waited too long for click-to-play-plugin notification"); michael@0: } michael@0: michael@0: function testPart4() { michael@0: var popupNotification = PopupNotifications.getNotification("click-to-play-plugins", gTestBrowser); michael@0: ok(popupNotification, "test part 4: Should have a click-to-play notification"); michael@0: var plugin = gTestBrowser.contentDocument.getElementById("test"); michael@0: var objLoadingContent = plugin.QueryInterface(Ci.nsIObjectLoadingContent); michael@0: is(objLoadingContent.pluginFallbackType, Ci.nsIObjectLoadingContent.PLUGIN_VULNERABLE_UPDATABLE, "test part 4: plugin fallback type should be PLUGIN_VULNERABLE_UPDATABLE"); michael@0: ok(!objLoadingContent.activated, "test part 4: plugin should not be activated"); michael@0: michael@0: finishTest(); michael@0: }