gecko/browser/base/content/test/browser_bug743421.js
Benjamin Smedberg d0ea1dfb67 Bug 880735 test fixups:
* Add a test-only setter to the center-item XBL binding
* add a head.js function to remove plugin permissions for use in cleanup functions
* browser_pluginnotification.js - lots of fixes for the core feature tests
* Alter test_bug751809 not to assume that clicking the page overlay will directly activate the plugin
* Alter browser_CTP_plugins.js because disabled plugins now do show up in the plugin doorhanger
* remove browser_CTPScriptPlugin.js and supporting files because we no longer auto-pop based on scripting
* fix browser_CTP_drag_drop.js so that active plugins still show the doorhanger icon, and other fixup
* fix browser_bug743421.js to expect the doorhanger all the time and activate it correctly
* fix browser_bug752516.js to check for doorhanger activation instead of plugin activation
* remove browser_bug818009.js and supporting files because they are testing something that no longer exists
* alter browser_bug820497.js so that it shows the popup notification before checking .centerActions, since we populate that data lazily now
* browser_plugins_added_dynamically.js: remove the "activate all" tests which are no longer relevant and fix the rest to match the new doorhanger structure.
2013-06-24 08:51:07 -04:00

119 lines
4.8 KiB
JavaScript

const gTestRoot = "http://mochi.test:8888/browser/browser/base/content/test/";
var gTestBrowser = null;
var gNextTest = null;
Components.utils.import("resource://gre/modules/Services.jsm");
function test() {
waitForExplicitFinish();
registerCleanupFunction(function() {
clearAllPluginPermissions();
Services.prefs.clearUserPref("plugins.click_to_play");
var plugin = getTestPlugin();
plugin.enabledState = Ci.nsIPluginTag.STATE_ENABLED;
});
Services.prefs.setBoolPref("plugins.click_to_play", true);
var plugin = getTestPlugin();
plugin.enabledState = Ci.nsIPluginTag.STATE_CLICKTOPLAY;
var newTab = gBrowser.addTab();
gBrowser.selectedTab = newTab;
gTestBrowser = gBrowser.selectedBrowser;
gTestBrowser.addEventListener("load", pageLoad, true);
prepareTest(test1a, gTestRoot + "plugin_add_dynamically.html");
}
function finishTest() {
gTestBrowser.removeEventListener("load", pageLoad, true);
gBrowser.removeCurrentTab();
window.focus();
finish();
}
function pageLoad() {
// The plugin events are async dispatched and can come after the load event
// This just allows the events to fire before we then go on to test the states
executeSoon(gNextTest);
}
function prepareTest(nextTest, url) {
gNextTest = nextTest;
gTestBrowser.contentWindow.location = url;
}
// Tests that navigation within the page and the window.history API doesn't break click-to-play state.
function test1a() {
var popupNotification = PopupNotifications.getNotification("click-to-play-plugins", gTestBrowser);
ok(!popupNotification, "Test 1a, Should not have a click-to-play notification");
var plugin = new XPCNativeWrapper(XPCNativeWrapper.unwrap(gTestBrowser.contentWindow).addPlugin());
var condition = function() PopupNotifications.getNotification("click-to-play-plugins", gTestBrowser);
waitForCondition(condition, test1b, "Test 1a, Waited too long for plugin notification");
}
function test1b() {
var popupNotification = PopupNotifications.getNotification("click-to-play-plugins", gTestBrowser);
ok(popupNotification, "Test 1b, Should have a click-to-play notification");
var plugin = gTestBrowser.contentDocument.getElementsByTagName("embed")[0];
var objLoadingContent = plugin.QueryInterface(Ci.nsIObjectLoadingContent);
ok(!objLoadingContent.activated, "Test 1b, Plugin should not be activated");
// Click the activate button on doorhanger to make sure it works
popupNotification.reshow();
PopupNotifications.panel.firstChild._primaryButton.click();
ok(objLoadingContent.activated, "Test 1b, Doorhanger should activate plugin");
test1c();
}
function test1c() {
var popupNotification = PopupNotifications.getNotification("click-to-play-plugins", gTestBrowser);
ok(popupNotification, "Test 1c, Should still have a click-to-play notification");
var plugin = new XPCNativeWrapper(XPCNativeWrapper.unwrap(gTestBrowser.contentWindow).addPlugin());
var objLoadingContent = plugin.QueryInterface(Ci.nsIObjectLoadingContent);
var condition = function() objLoadingContent.activated;
waitForCondition(condition, test1d, "Test 1c, Waited too long for plugin activation");
}
function test1d() {
var plugin = gTestBrowser.contentDocument.getElementsByTagName("embed")[1];
var objLoadingContent = plugin.QueryInterface(Ci.nsIObjectLoadingContent);
ok(objLoadingContent.activated, "Test 1d, Plugin should be activated");
gNextTest = test1e;
gTestBrowser.contentWindow.addEventListener("hashchange", test1e, false);
gTestBrowser.contentWindow.location += "#anchorNavigation";
}
function test1e() {
gTestBrowser.contentWindow.removeEventListener("hashchange", test1e, false);
var plugin = new XPCNativeWrapper(XPCNativeWrapper.unwrap(gTestBrowser.contentWindow).addPlugin());
var objLoadingContent = plugin.QueryInterface(Ci.nsIObjectLoadingContent);
var condition = function() objLoadingContent.activated;
waitForCondition(condition, test1f, "Test 1e, Waited too long for plugin activation");
}
function test1f() {
var plugin = gTestBrowser.contentDocument.getElementsByTagName("embed")[2];
var objLoadingContent = plugin.QueryInterface(Ci.nsIObjectLoadingContent);
ok(objLoadingContent.activated, "Test 1f, Plugin should be activated");
gTestBrowser.contentWindow.history.replaceState({}, "", "replacedState");
var plugin = new XPCNativeWrapper(XPCNativeWrapper.unwrap(gTestBrowser.contentWindow).addPlugin());
var objLoadingContent = plugin.QueryInterface(Ci.nsIObjectLoadingContent);
var condition = function() objLoadingContent.activated;
waitForCondition(condition, test1g, "Test 1f, Waited too long for plugin activation");
}
function test1g() {
var plugin = gTestBrowser.contentDocument.getElementsByTagName("embed")[3];
var objLoadingContent2 = plugin.QueryInterface(Ci.nsIObjectLoadingContent);
ok(objLoadingContent2.activated, "Test 1g, Plugin should be activated");
finishTest();
}