michael@0: var rootDir = getRootDirectory(gTestPath); michael@0: const gTestRoot = rootDir; michael@0: const gHttpTestRoot = rootDir.replace("chrome://mochitests/content/", "http://127.0.0.1:8888/"); michael@0: michael@0: var gTestBrowser = null; michael@0: var gNextTest = null; michael@0: var gPluginHost = Components.classes["@mozilla.org/plugin/host;1"].getService(Components.interfaces.nsIPluginHost); 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: clearAllPluginPermissions(); michael@0: Services.prefs.clearUserPref("extensions.blocklist.suppressUI"); michael@0: }); michael@0: Services.prefs.setBoolPref("extensions.blocklist.suppressUI", true); 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: michael@0: Services.prefs.setBoolPref("plugins.click_to_play", true); michael@0: setTestPluginEnabledState(Ci.nsIPluginTag.STATE_CLICKTOPLAY); michael@0: setTestPluginEnabledState(Ci.nsIPluginTag.STATE_CLICKTOPLAY, "Second Test Plug-in"); michael@0: michael@0: prepareTest(test1a, gHttpTestRoot + "plugin_data_url.html"); michael@0: } michael@0: michael@0: function finishTest() { michael@0: clearAllPluginPermissions(); michael@0: gTestBrowser.removeEventListener("load", pageLoad, true); michael@0: gBrowser.removeCurrentTab(); michael@0: window.focus(); michael@0: finish(); michael@0: } michael@0: michael@0: function 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 prepareTest(nextTest, url) { michael@0: gNextTest = nextTest; michael@0: gTestBrowser.contentWindow.location = url; michael@0: } michael@0: michael@0: // Due to layout being async, "PluginBindAttached" may trigger later. michael@0: // This wraps a function to force a layout flush, thus triggering it, michael@0: // and schedules the function execution so they're definitely executed michael@0: // afterwards. michael@0: function runAfterPluginBindingAttached(func) { michael@0: return function() { michael@0: let doc = gTestBrowser.contentDocument; michael@0: let elems = doc.getElementsByTagName('embed'); michael@0: if (elems.length < 1) { michael@0: elems = doc.getElementsByTagName('object'); michael@0: } michael@0: elems[0].clientTop; michael@0: executeSoon(func); michael@0: }; michael@0: } michael@0: michael@0: // Test that the click-to-play doorhanger still works when navigating to data URLs michael@0: function test1a() { michael@0: let popupNotification = PopupNotifications.getNotification("click-to-play-plugins", gTestBrowser); michael@0: ok(popupNotification, "Test 1a, Should have a click-to-play notification"); michael@0: michael@0: let plugin = gTestBrowser.contentDocument.getElementById("test"); michael@0: let objLoadingContent = plugin.QueryInterface(Ci.nsIObjectLoadingContent); michael@0: ok(!objLoadingContent.activated, "Test 1a, Plugin should not be activated"); michael@0: michael@0: gNextTest = runAfterPluginBindingAttached(test1b); michael@0: gTestBrowser.contentDocument.getElementById("data-link-1").click(); michael@0: } michael@0: michael@0: function test1b() { michael@0: let popupNotification = PopupNotifications.getNotification("click-to-play-plugins", gTestBrowser); michael@0: ok(popupNotification, "Test 1b, Should have a click-to-play notification"); michael@0: michael@0: let plugin = gTestBrowser.contentDocument.getElementById("test"); michael@0: let objLoadingContent = plugin.QueryInterface(Ci.nsIObjectLoadingContent); michael@0: ok(!objLoadingContent.activated, "Test 1b, Plugin should not be activated"); michael@0: michael@0: // Simulate clicking the "Allow Always" button. michael@0: popupNotification.reshow(); michael@0: PopupNotifications.panel.firstChild._primaryButton.click(); michael@0: michael@0: let condition = function() objLoadingContent.activated; michael@0: waitForCondition(condition, test1c, "Test 1b, Waited too long for plugin to activate"); michael@0: } michael@0: michael@0: function test1c() { michael@0: clearAllPluginPermissions(); michael@0: prepareTest(runAfterPluginBindingAttached(test2a), gHttpTestRoot + "plugin_data_url.html"); michael@0: } michael@0: michael@0: // Test that the click-to-play notification doesn't break when navigating to data URLs with multiple plugins michael@0: function test2a() { michael@0: let popupNotification = PopupNotifications.getNotification("click-to-play-plugins", gTestBrowser); michael@0: ok(popupNotification, "Test 2a, Should have a click-to-play notification"); michael@0: let plugin = gTestBrowser.contentDocument.getElementById("test"); michael@0: let objLoadingContent = plugin.QueryInterface(Ci.nsIObjectLoadingContent); michael@0: ok(!objLoadingContent.activated, "Test 2a, Plugin should not be activated"); michael@0: michael@0: gNextTest = runAfterPluginBindingAttached(test2b); michael@0: gTestBrowser.contentDocument.getElementById("data-link-2").click(); michael@0: } michael@0: michael@0: function test2b() { michael@0: let notification = PopupNotifications.getNotification("click-to-play-plugins", gTestBrowser); michael@0: ok(notification, "Test 2b, Should have a click-to-play notification"); michael@0: michael@0: // Simulate choosing "Allow now" for the test plugin michael@0: notification.reshow(); michael@0: is(notification.options.pluginData.size, 2, "Test 2b, Should have two types of plugin in the notification"); michael@0: michael@0: var centerAction = null; michael@0: for (var action of notification.options.pluginData.values()) { michael@0: if (action.pluginName == "Test") { michael@0: centerAction = action; michael@0: break; michael@0: } michael@0: } michael@0: ok(centerAction, "Test 2b, found center action for the Test plugin"); michael@0: michael@0: var centerItem = null; michael@0: for (var item of PopupNotifications.panel.firstChild.childNodes) { michael@0: is(item.value, "block", "Test 2b, all plugins should start out blocked"); michael@0: if (item.action == centerAction) { michael@0: centerItem = item; michael@0: break; michael@0: } michael@0: } michael@0: ok(centerItem, "Test 2b, found center item for the Test plugin"); michael@0: michael@0: // "click" the button to activate the Test plugin michael@0: centerItem.value = "allownow"; michael@0: PopupNotifications.panel.firstChild._primaryButton.click(); michael@0: michael@0: let plugin = gTestBrowser.contentDocument.getElementById("test1"); michael@0: let objLoadingContent = plugin.QueryInterface(Ci.nsIObjectLoadingContent); michael@0: let condition = function() objLoadingContent.activated; michael@0: waitForCondition(condition, test2c, "Test 2b, Waited too long for plugin to activate"); michael@0: } michael@0: michael@0: function test2c() { michael@0: let plugin = gTestBrowser.contentDocument.getElementById("test1"); michael@0: let objLoadingContent = plugin.QueryInterface(Ci.nsIObjectLoadingContent); michael@0: ok(objLoadingContent.activated, "Test 2c, Plugin should be activated"); michael@0: michael@0: clearAllPluginPermissions(); michael@0: prepareTest(runAfterPluginBindingAttached(test3a), gHttpTestRoot + "plugin_data_url.html"); michael@0: } michael@0: michael@0: // Test that when navigating to a data url, the plugin permission is inherited michael@0: function test3a() { michael@0: let popupNotification = PopupNotifications.getNotification("click-to-play-plugins", gTestBrowser); michael@0: ok(popupNotification, "Test 3a, Should have a click-to-play notification"); michael@0: let plugin = gTestBrowser.contentDocument.getElementById("test"); michael@0: let objLoadingContent = plugin.QueryInterface(Ci.nsIObjectLoadingContent); michael@0: ok(!objLoadingContent.activated, "Test 3a, Plugin should not be activated"); michael@0: michael@0: // Simulate clicking the "Allow Always" button. michael@0: popupNotification.reshow(); michael@0: PopupNotifications.panel.firstChild._primaryButton.click(); michael@0: michael@0: let condition = function() objLoadingContent.activated; michael@0: waitForCondition(condition, test3b, "Test 3a, Waited too long for plugin to activate"); michael@0: } michael@0: michael@0: function test3b() { michael@0: gNextTest = test3c; michael@0: gTestBrowser.contentDocument.getElementById("data-link-1").click(); michael@0: } michael@0: michael@0: function test3c() { michael@0: let plugin = gTestBrowser.contentDocument.getElementById("test"); michael@0: let objLoadingContent = plugin.QueryInterface(Ci.nsIObjectLoadingContent); michael@0: ok(objLoadingContent.activated, "Test 3c, Plugin should be activated"); michael@0: michael@0: clearAllPluginPermissions(); michael@0: prepareTest(runAfterPluginBindingAttached(test4b), michael@0: 'data:text/html,'); michael@0: } michael@0: michael@0: // Test that the click-to-play doorhanger still works when directly navigating to data URLs michael@0: function test4a() { michael@0: let popupNotification = PopupNotifications.getNotification("click-to-play-plugins", gTestBrowser); michael@0: ok(popupNotification, "Test 4a, Should have a click-to-play notification"); michael@0: let plugin = gTestBrowser.contentDocument.getElementById("test"); michael@0: let objLoadingContent = plugin.QueryInterface(Ci.nsIObjectLoadingContent); michael@0: ok(!objLoadingContent.activated, "Test 4a, Plugin should not be activated"); michael@0: michael@0: // Simulate clicking the "Allow Always" button. michael@0: popupNotification.reshow(); michael@0: PopupNotifications.panel.firstChild._primaryButton.click(); michael@0: michael@0: let condition = function() objLoadingContent.activated; michael@0: waitForCondition(condition, test4b, "Test 4a, Waited too long for plugin to activate"); michael@0: } michael@0: michael@0: function test4b() { michael@0: clearAllPluginPermissions(); michael@0: finishTest(); michael@0: }