michael@0: var rootDir = getRootDirectory(gTestPath); michael@0: const gTestRoot = rootDir.replace("chrome://mochitests/content/", "http://mochi.test:8888/"); michael@0: 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: clearAllPluginPermissions(); 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: prepareTest(test1a, gTestRoot + "plugin_add_dynamically.html"); 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: 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: // Tests that navigation within the page and the window.history API doesn't break click-to-play state. michael@0: function test1a() { michael@0: var popupNotification = PopupNotifications.getNotification("click-to-play-plugins", gTestBrowser); michael@0: ok(!popupNotification, "Test 1a, Should not have a click-to-play notification"); michael@0: var plugin = new XPCNativeWrapper(XPCNativeWrapper.unwrap(gTestBrowser.contentWindow).addPlugin()); michael@0: michael@0: var condition = function() PopupNotifications.getNotification("click-to-play-plugins", gTestBrowser); michael@0: waitForCondition(condition, test1b, "Test 1a, Waited too long for plugin notification"); michael@0: } michael@0: michael@0: function test1b() { michael@0: var popupNotification = PopupNotifications.getNotification("click-to-play-plugins", gTestBrowser); michael@0: ok(popupNotification, "Test 1b, Should have a click-to-play notification"); michael@0: var plugin = gTestBrowser.contentDocument.getElementsByTagName("embed")[0]; michael@0: var objLoadingContent = plugin.QueryInterface(Ci.nsIObjectLoadingContent); michael@0: ok(!objLoadingContent.activated, "Test 1b, Plugin should not be activated"); michael@0: michael@0: // Click the activate button on doorhanger to make sure it works michael@0: popupNotification.reshow(); michael@0: PopupNotifications.panel.firstChild._primaryButton.click(); michael@0: michael@0: ok(objLoadingContent.activated, "Test 1b, Doorhanger should activate plugin"); michael@0: michael@0: test1c(); michael@0: } michael@0: michael@0: function test1c() { michael@0: var popupNotification = PopupNotifications.getNotification("click-to-play-plugins", gTestBrowser); michael@0: ok(popupNotification, "Test 1c, Should still have a click-to-play notification"); michael@0: var plugin = new XPCNativeWrapper(XPCNativeWrapper.unwrap(gTestBrowser.contentWindow).addPlugin()); michael@0: michael@0: var objLoadingContent = plugin.QueryInterface(Ci.nsIObjectLoadingContent); michael@0: var condition = function() objLoadingContent.activated; michael@0: waitForCondition(condition, test1d, "Test 1c, Waited too long for plugin activation"); michael@0: } michael@0: michael@0: function test1d() { michael@0: var plugin = gTestBrowser.contentDocument.getElementsByTagName("embed")[1]; michael@0: var objLoadingContent = plugin.QueryInterface(Ci.nsIObjectLoadingContent); michael@0: ok(objLoadingContent.activated, "Test 1d, Plugin should be activated"); michael@0: michael@0: gNextTest = test1e; michael@0: gTestBrowser.contentWindow.addEventListener("hashchange", test1e, false); michael@0: gTestBrowser.contentWindow.location += "#anchorNavigation"; michael@0: } michael@0: michael@0: function test1e() { michael@0: gTestBrowser.contentWindow.removeEventListener("hashchange", test1e, false); michael@0: michael@0: var plugin = new XPCNativeWrapper(XPCNativeWrapper.unwrap(gTestBrowser.contentWindow).addPlugin()); michael@0: michael@0: var objLoadingContent = plugin.QueryInterface(Ci.nsIObjectLoadingContent); michael@0: var condition = function() objLoadingContent.activated; michael@0: waitForCondition(condition, test1f, "Test 1e, Waited too long for plugin activation"); michael@0: } michael@0: michael@0: function test1f() { michael@0: var plugin = gTestBrowser.contentDocument.getElementsByTagName("embed")[2]; michael@0: var objLoadingContent = plugin.QueryInterface(Ci.nsIObjectLoadingContent); michael@0: ok(objLoadingContent.activated, "Test 1f, Plugin should be activated"); michael@0: michael@0: gTestBrowser.contentWindow.history.replaceState({}, "", "replacedState"); michael@0: var plugin = new XPCNativeWrapper(XPCNativeWrapper.unwrap(gTestBrowser.contentWindow).addPlugin()); michael@0: var objLoadingContent = plugin.QueryInterface(Ci.nsIObjectLoadingContent); michael@0: var condition = function() objLoadingContent.activated; michael@0: waitForCondition(condition, test1g, "Test 1f, Waited too long for plugin activation"); michael@0: } michael@0: michael@0: function test1g() { michael@0: var plugin = gTestBrowser.contentDocument.getElementsByTagName("embed")[3]; michael@0: var objLoadingContent2 = plugin.QueryInterface(Ci.nsIObjectLoadingContent); michael@0: ok(objLoadingContent2.activated, "Test 1g, Plugin should be activated"); michael@0: finishTest(); michael@0: }