diff --git a/browser/base/content/browser.js b/browser/base/content/browser.js index 511a00c46b69..c954df312272 100644 --- a/browser/base/content/browser.js +++ b/browser/base/content/browser.js @@ -258,6 +258,12 @@ XPCOMUtils.defineLazyGetter(this, "PageMenu", function() { */ function pageShowEventHandlers(persisted) { XULBrowserWindow.asyncUpdateUI(); + + // The PluginClickToPlay events are not fired when navigating using the + // BF cache. |persisted| is true when the page is loaded from the + // BF cache, so this code reshows the notification if necessary. + if (persisted) + gPluginHandler.reshowClickToPlayNotification(); } function UpdateBackForwardCommands(aWebNavigation) { @@ -774,6 +780,13 @@ var gBrowserInit = { gBrowser.addEventListener("DOMUpdatePageReport", gPopupBlockerObserver, false); + // Note that the XBL binding is untrusted + gBrowser.addEventListener("PluginBindingAttached", gPluginHandler, true, true); + gBrowser.addEventListener("PluginCrashed", gPluginHandler, true); + gBrowser.addEventListener("PluginOutdated", gPluginHandler, true); + gBrowser.addEventListener("PluginInstantiated", gPluginHandler, true); + gBrowser.addEventListener("PluginRemoved", gPluginHandler, true); + gBrowser.addEventListener("NewPluginInstalled", gPluginHandler.newPluginInstalled, true); Services.obs.addObserver(gPluginHandler.pluginCrashed, "plugin-crashed", false); diff --git a/browser/base/content/content.js b/browser/base/content/content.js index 3cc0768e6e20..7550f13eb748 100644 --- a/browser/base/content/content.js +++ b/browser/base/content/content.js @@ -16,8 +16,6 @@ XPCOMUtils.defineLazyModuleGetter(this, "LoginManagerContent", "resource://gre/modules/LoginManagerContent.jsm"); XPCOMUtils.defineLazyModuleGetter(this, "InsecurePasswordUtils", "resource://gre/modules/InsecurePasswordUtils.jsm"); -XPCOMUtils.defineLazyModuleGetter(this, "PluginContent", - "resource:///modules/PluginContent.jsm"); XPCOMUtils.defineLazyModuleGetter(this, "PrivateBrowsingUtils", "resource://gre/modules/PrivateBrowsingUtils.jsm"); XPCOMUtils.defineLazyModuleGetter(this, "UITour", @@ -495,9 +493,6 @@ ClickEventHandler.init(); ContentLinkHandler.init(this); -// TODO: Load this lazily so the JSM is run only if a relevant event/message fires. -let pluginContent = new PluginContent(global); - addEventListener("DOMWebNotificationClicked", function(event) { sendAsyncMessage("DOMWebNotificationClicked", {}); }, false); diff --git a/browser/base/content/nsContextMenu.js b/browser/base/content/nsContextMenu.js index 36ec6f07b5cd..75ae2364ea85 100644 --- a/browser/base/content/nsContextMenu.js +++ b/browser/base/content/nsContextMenu.js @@ -1315,11 +1315,11 @@ nsContextMenu.prototype = { }, playPlugin: function() { - gPluginHandler.contextMenuCommand(this.browser, this.target, "play"); + gPluginHandler._showClickToPlayNotification(this.browser, this.target, true); }, hidePlugin: function() { - gPluginHandler.contextMenuCommand(this.browser, this.target, "hide"); + gPluginHandler.hideClickToPlayOverlay(this.target); }, // Generate email address and put it on clipboard. diff --git a/browser/base/content/test/general/browser_datareporting_notification.js b/browser/base/content/test/general/browser_datareporting_notification.js index d1af2b230ebd..aa8d5c21b74f 100644 --- a/browser/base/content/test/general/browser_datareporting_notification.js +++ b/browser/base/content/test/general/browser_datareporting_notification.js @@ -132,7 +132,7 @@ function test_multiple_windows() { let [policy, promise] = sendNotifyRequest("multiple_window_behavior"); let displayCount = 0; - let prefWindowClosed = false; + let prefWindowOpened = false; let mutationObserversRemoved = false; function onAlertDisplayed() { @@ -147,8 +147,8 @@ function test_multiple_windows() { // We register two independent observers and we need both to clean up // properly. This handles gating for test completion. function maybeFinish() { - if (!prefWindowClosed) { - dump("Not finishing test yet because pref pane isn't closed.\n"); + if (!prefWindowOpened) { + dump("Not finishing test yet because pref pane hasn't yet appeared.\n"); return; } @@ -193,16 +193,14 @@ function test_multiple_windows() { is(buttons.length, 1, "There is 1 button in the data reporting notification."); let button = buttons[0]; - // Automatically close preferences window when it is opened as part of - // button press. + // Add an observer to ensure the "advanced" pane opened (but don't bother + // closing it - we close the entire window when done.) Services.obs.addObserver(function observer(prefWin, topic, data) { Services.obs.removeObserver(observer, "advanced-pane-loaded"); ok(true, "Advanced preferences opened on info bar button press."); executeSoon(function soon() { - dump("Closing preferences.\n"); - prefWin.close(); - prefWindowClosed = true; + prefWindowOpened = true; maybeFinish(); }); }, "advanced-pane-loaded", false); diff --git a/browser/base/content/test/plugins/browser_CTP_crashreporting.js b/browser/base/content/test/plugins/browser_CTP_crashreporting.js index c92bb2e01f87..4fd5439223d3 100644 --- a/browser/base/content/test/plugins/browser_CTP_crashreporting.js +++ b/browser/base/content/test/plugins/browser_CTP_crashreporting.js @@ -8,72 +8,6 @@ const SERVER_URL = "http://example.com/browser/toolkit/crashreporter/test/browse const gTestRoot = getRootDirectory(gTestPath); var gTestBrowser = null; -/** - * Frame script that will be injected into the test browser - * to cause the crash, and then manipulate the crashed plugin - * UI. Specifically, after the crash, we ensure that the - * crashed plugin UI is using the right style rules and that - * the submit URL opt-in defaults to checked. Then, we fill in - * a comment with the crash report, uncheck the submit URL - * opt-in, and send the crash reports. - */ -function frameScript() { - function fail(reason) { - sendAsyncMessage("test:crash-plugin:fail", { - reason: `Failure from frameScript: ${reason}`, - }); - } - - addMessageListener("test:crash-plugin", () => { - let doc = content.document; - - addEventListener("PluginCrashed", (event) => { - let plugin = doc.getElementById("test"); - if (!plugin) { - fail("Could not find plugin element"); - return; - } - - let getUI = (anonid) => { - return doc.getAnonymousElementByAttribute(plugin, "anonid", anonid); - }; - - let style = content.getComputedStyle(getUI("pleaseSubmit")); - if (style.display != "block") { - fail("Submission UI visibility is not correct. Expected block, " - + " got " + style.display); - return; - } - - getUI("submitComment").value = "a test comment"; - if (!getUI("submitURLOptIn").checked) { - fail("URL opt-in should default to true."); - return; - } - - getUI("submitURLOptIn").click(); - getUI("submitButton").click(); - }); - - let plugin = doc.getElementById("test"); - try { - plugin.crash() - } catch(e) { - } - }); - - addMessageListener("test:plugin-submit-status", () => { - let doc = content.document; - let plugin = doc.getElementById("test"); - let submitStatusEl = - doc.getAnonymousElementByAttribute(plugin, "anonid", "submitStatus"); - let submitStatus = submitStatusEl.getAttribute("status"); - sendAsyncMessage("test:plugin-submit-status:result", { - submitStatus: submitStatus, - }); - }); -} - // Test that plugin crash submissions still work properly after // click-to-play activation. @@ -97,18 +31,14 @@ function test() { let tab = gBrowser.loadOneTab("about:blank", { inBackground: false }); gTestBrowser = gBrowser.getBrowserForTab(tab); - let mm = gTestBrowser.messageManager; - mm.loadFrameScript("data:,(" + frameScript.toString() + ")();", false); - mm.addMessageListener("test:crash-plugin:fail", (message) => { - ok(false, message.data.reason); - }); - + gTestBrowser.addEventListener("PluginCrashed", onCrash, false); gTestBrowser.addEventListener("load", onPageLoad, true); Services.obs.addObserver(onSubmitStatus, "crash-report-status", false); registerCleanupFunction(function cleanUp() { env.set("MOZ_CRASHREPORTER_NO_REPORT", noReport); env.set("MOZ_CRASHREPORTER_URL", serverURL); + gTestBrowser.removeEventListener("PluginCrashed", onCrash, false); gTestBrowser.removeEventListener("load", onPageLoad, true); Services.obs.removeObserver(onSubmitStatus, "crash-report-status"); gBrowser.removeCurrentTab(); @@ -140,8 +70,31 @@ function afterBindingAttached() { } function pluginActivated() { - let mm = gTestBrowser.messageManager; - mm.sendAsyncMessage("test:crash-plugin"); + let plugin = gTestBrowser.contentDocument.getElementById("test"); + try { + plugin.crash(); + } catch (e) { + // The plugin crashed in the above call, an exception is expected. + } +} + +function onCrash() { + try { + let plugin = gBrowser.contentDocument.getElementById("test"); + let elt = gPluginHandler.getPluginUI.bind(gPluginHandler, plugin); + let style = + gBrowser.contentWindow.getComputedStyle(elt("pleaseSubmit")); + is(style.display, "block", "Submission UI visibility should be correct"); + + elt("submitComment").value = "a test comment"; + is(elt("submitURLOptIn").checked, true, "URL opt-in should default to true"); + EventUtils.synthesizeMouseAtCenter(elt("submitURLOptIn"), {}, gTestBrowser.contentWindow); + EventUtils.synthesizeMouseAtCenter(elt("submitButton"), {}, gTestBrowser.contentWindow); + // And now wait for the submission status notification. + } + catch (err) { + failWithException(err); + } } function onSubmitStatus(subj, topic, data) { @@ -175,23 +128,19 @@ function onSubmitStatus(subj, topic, data) { ok(val === undefined, "URL should be absent from extra data when opt-in not checked"); - let submitStatus = null; - let mm = gTestBrowser.messageManager; - mm.addMessageListener("test:plugin-submit-status:result", (message) => { - submitStatus = message.data.submitStatus; + // Execute this later in case the event to change submitStatus has not + // have been dispatched yet. + executeSoon(function () { + let plugin = gBrowser.contentDocument.getElementById("test"); + let elt = gPluginHandler.getPluginUI.bind(gPluginHandler, plugin); + is(elt("submitStatus").getAttribute("status"), data, + "submitStatus data should match"); }); - - mm.sendAsyncMessage("test:plugin-submit-status"); - - let condition = () => submitStatus; - waitForCondition(condition, () => { - is(submitStatus, data, "submitStatus data should match"); - finish(); - }, "Waiting for submitStatus to be reported from frame script"); } catch (err) { failWithException(err); } + finish(); } function getPropertyBagValue(bag, key) { diff --git a/browser/base/content/test/plugins/browser_CTP_drag_drop.js b/browser/base/content/test/plugins/browser_CTP_drag_drop.js index 66b7de28aa3a..989e079dcd12 100644 --- a/browser/base/content/test/plugins/browser_CTP_drag_drop.js +++ b/browser/base/content/test/plugins/browser_CTP_drag_drop.js @@ -29,11 +29,11 @@ function handleEvent() { function part1() { gBrowser.selectedBrowser.removeEventListener("PluginBindingAttached", handleEvent); - waitForNotificationPopup("click-to-play-plugins", gBrowser.selectedBrowser, () => { - gNextTest = part2; - gNewWindow = gBrowser.replaceTabWithWindow(gBrowser.selectedTab); - gNewWindow.addEventListener("load", handleEvent, true); - }); + ok(PopupNotifications.getNotification("click-to-play-plugins", gBrowser.selectedBrowser), "Should have a click-to-play notification in the initial tab"); + + gNextTest = part2; + gNewWindow = gBrowser.replaceTabWithWindow(gBrowser.selectedTab); + gNewWindow.addEventListener("load", handleEvent, true); } function part2() { @@ -62,10 +62,10 @@ function part4() { function part5() { gBrowser.selectedBrowser.removeEventListener("PluginBindingAttached", handleEvent); - waitForNotificationPopup("click-to-play-plugins", gBrowser.selectedBrowser, () => { - gNewWindow = gBrowser.replaceTabWithWindow(gBrowser.selectedTab); - waitForFocus(part6, gNewWindow); - }); + ok(PopupNotifications.getNotification("click-to-play-plugins", gBrowser.selectedBrowser), "Should have a click-to-play notification in the initial tab"); + + gNewWindow = gBrowser.replaceTabWithWindow(gBrowser.selectedTab); + waitForFocus(part6, gNewWindow); } function part6() { @@ -92,10 +92,8 @@ function part8() { let plugin = gNewWindow.gBrowser.selectedBrowser.contentDocument.getElementById("test"); let objLoadingContent = plugin.QueryInterface(Ci.nsIObjectLoadingContent); - waitForCondition(() => objLoadingContent.activated, shutdown, "plugin should be activated now"); -} + ok(objLoadingContent.activated, "plugin should be activated now"); -function shutdown() { gNewWindow.close(); gNewWindow = null; finish(); diff --git a/browser/base/content/test/plugins/browser_CTP_iframe.js b/browser/base/content/test/plugins/browser_CTP_iframe.js index f459a3fcef2e..9b96807b2653 100644 --- a/browser/base/content/test/plugins/browser_CTP_iframe.js +++ b/browser/base/content/test/plugins/browser_CTP_iframe.js @@ -74,15 +74,13 @@ function test1() { let plugin = doc.getElementById("test"); ok(plugin, "Test 1, Found plugin in page"); - waitForNotificationPopup("click-to-play-plugins", gTestBrowser, () => { - let overlay = doc.getAnonymousElementByAttribute(plugin, "anonid", "main"); - ok(overlay.classList.contains("visible"), "Test 1, Plugin overlay should exist, not be hidden"); - let closeIcon = doc.getAnonymousElementByAttribute(plugin, "anonid", "closeIcon"); + let overlay = doc.getAnonymousElementByAttribute(plugin, "anonid", "main"); + ok(overlay.classList.contains("visible"), "Test 1, Plugin overlay should exist, not be hidden"); + let closeIcon = doc.getAnonymousElementByAttribute(plugin, "anonid", "closeIcon") - EventUtils.synthesizeMouseAtCenter(closeIcon, {}, frame.contentWindow); - let condition = () => !overlay.classList.contains("visible"); - waitForCondition(condition, test2, "Test 1, Waited too long for the overlay to become invisible."); - }); + EventUtils.synthesizeMouseAtCenter(closeIcon, {}, frame.contentWindow); + let condition = () => !overlay.classList.contains("visible"); + waitForCondition(condition, test2, "Test 1, Waited too long for the overlay to become invisible."); } function test2() { diff --git a/browser/base/content/test/plugins/browser_CTP_notificationBar.js b/browser/base/content/test/plugins/browser_CTP_notificationBar.js index f0cd4063fea5..597b78754507 100644 --- a/browser/base/content/test/plugins/browser_CTP_notificationBar.js +++ b/browser/base/content/test/plugins/browser_CTP_notificationBar.js @@ -63,37 +63,43 @@ function runAfterPluginBindingAttached(func) { // Tests for the notification bar for hidden plugins. function test1() { - info("Test 1 - expecting a notification bar for hidden plugins."); - waitForNotificationPopup("click-to-play-plugins", gTestBrowser, () => { - waitForNotificationBar("plugin-hidden", gTestBrowser, () => { + let notification = PopupNotifications.getNotification("click-to-play-plugins"); + ok(notification, "Test 1: There should be a plugin notification"); + + let notificationBox = gBrowser.getNotificationBox(gTestBrowser); + + waitForCondition(() => notificationBox.getNotificationWithValue("plugin-hidden") !== null, + () => { // Don't use setTestPluginEnabledState here because we already saved the // prior value getTestPlugin().enabledState = Ci.nsIPluginTag.STATE_ENABLED; prepareTest(test2, gTestRoot + "plugin_small.html"); - }); - }); + }, + "Test 1, expected to have a plugin notification bar"); } function test2() { - info("Test 2 - expecting no plugin notification bar on visible plugins."); - waitForNotificationPopup("click-to-play-plugins", gTestBrowser, () => { - let notificationBox = gBrowser.getNotificationBox(gTestBrowser); + let notification = PopupNotifications.getNotification("click-to-play-plugins"); + ok(notification, "Test 2: There should be a plugin notification"); - waitForCondition(() => notificationBox.getNotificationWithValue("plugin-hidden") === null, - () => { - getTestPlugin().enabledState = Ci.nsIPluginTag.STATE_CLICKTOPLAY; - prepareTest(test3, gTestRoot + "plugin_overlayed.html"); - }, - "expected to not have a plugin notification bar" - ); - }); + let notificationBox = gBrowser.getNotificationBox(gTestBrowser); + + waitForCondition(() => notificationBox.getNotificationWithValue("plugin-hidden") === null, + () => { + getTestPlugin().enabledState = Ci.nsIPluginTag.STATE_CLICKTOPLAY; + prepareTest(test3, gTestRoot + "plugin_overlayed.html"); + }, + "Test 2, expected to not have a plugin notification bar"); } function test3() { - info("Test 3 - expecting a plugin notification bar when plugins are overlaid"); - waitForNotificationPopup("click-to-play-plugins", gTestBrowser, () => { - waitForNotificationBar("plugin-hidden", gTestBrowser, test3b); - }); + let notification = PopupNotifications.getNotification("click-to-play-plugins"); + ok(notification, "Test 3: There should be a plugin notification"); + + let notificationBox = gBrowser.getNotificationBox(gTestBrowser); + waitForCondition(() => notificationBox.getNotificationWithValue("plugin-hidden") !== null, + test3b, + "Test 3, expected the plugin infobar to be triggered when plugin was overlayed"); } function test3b() @@ -112,10 +118,13 @@ function test3b() } function test4() { - info("Test 4 - expecting a plugin notification bar when plugins are overlaid offscreen") - waitForNotificationPopup("click-to-play-plugins", gTestBrowser, () => { - waitForNotificationBar("plugin-hidden", gTestBrowser, test4b); - }); + let notification = PopupNotifications.getNotification("click-to-play-plugins"); + ok(notification, "Test 4: There should be a plugin notification"); + + let notificationBox = gBrowser.getNotificationBox(gTestBrowser); + waitForCondition(() => notificationBox.getNotificationWithValue("plugin-hidden") !== null, + test4b, + "Test 4, expected the plugin infobar to be triggered when plugin was overlayed"); } function test4b() { @@ -132,6 +141,9 @@ function test4b() { prepareTest(runAfterPluginBindingAttached(test5), gHttpTestRoot + "plugin_small.html"); } +// Test that the notification bar is getting dismissed when directly activating plugins +// via the doorhanger. + function test5() { let notificationBox = gBrowser.getNotificationBox(gTestBrowser); waitForCondition(() => notificationBox.getNotificationWithValue("plugin-hidden") !== null, @@ -139,27 +151,23 @@ function test5() { "Test 5, expected a notification bar for hidden plugins"); } -// Test that the notification bar is getting dismissed when directly activating plugins -// via the doorhanger. - function test6() { - info("Test 6 - expecting the doorhanger to be dismissed when directly activating plugins."); - waitForNotificationPopup("click-to-play-plugins", gTestBrowser, (notification) => { - let plugin = gTestBrowser.contentDocument.getElementById("test"); - ok(plugin, "Test 6, Found plugin in page"); - let objLoadingContent = plugin.QueryInterface(Ci.nsIObjectLoadingContent); - is(objLoadingContent.pluginFallbackType, Ci.nsIObjectLoadingContent.PLUGIN_CLICK_TO_PLAY, - "Test 6, Plugin should be click-to-play"); + let notification = PopupNotifications.getNotification("click-to-play-plugins", gTestBrowser); + ok(notification, "Test 6, Should have a click-to-play notification"); + let plugin = gTestBrowser.contentDocument.getElementById("test"); + ok(plugin, "Test 6, Found plugin in page"); + let objLoadingContent = plugin.QueryInterface(Ci.nsIObjectLoadingContent); + is(objLoadingContent.pluginFallbackType, Ci.nsIObjectLoadingContent.PLUGIN_CLICK_TO_PLAY, + "Test 6, Plugin should be click-to-play"); - // simulate "always allow" - notification.reshow(); - PopupNotifications.panel.firstChild._primaryButton.click(); + // simulate "always allow" + notification.reshow(); + PopupNotifications.panel.firstChild._primaryButton.click(); - let notificationBox = gBrowser.getNotificationBox(gTestBrowser); - waitForCondition(() => notificationBox.getNotificationWithValue("plugin-hidden") === null, - test7, - "Test 6, expected the notification bar for hidden plugins to get dismissed"); - }); + let notificationBox = gBrowser.getNotificationBox(gTestBrowser); + waitForCondition(() => notificationBox.getNotificationWithValue("plugin-hidden") === null, + test7, + "Test 6, expected the notification bar for hidden plugins to get dismissed"); } function test7() { diff --git a/browser/base/content/test/plugins/browser_bug743421.js b/browser/base/content/test/plugins/browser_bug743421.js index 10f7f62835ab..0df83fe80ff3 100644 --- a/browser/base/content/test/plugins/browser_bug743421.js +++ b/browser/base/content/test/plugins/browser_bug743421.js @@ -60,8 +60,10 @@ function test1b() { // Click the activate button on doorhanger to make sure it works popupNotification.reshow(); PopupNotifications.panel.firstChild._primaryButton.click(); - var condition = function() objLoadingContent.activated; - waitForCondition(condition, test1c, "Test 1b, Waited too long for plugin activation"); + + ok(objLoadingContent.activated, "Test 1b, Doorhanger should activate plugin"); + + test1c(); } function test1c() { diff --git a/browser/base/content/test/plugins/browser_bug820497.js b/browser/base/content/test/plugins/browser_bug820497.js index e5ca402f88af..d64a7bbb96da 100644 --- a/browser/base/content/test/plugins/browser_bug820497.js +++ b/browser/base/content/test/plugins/browser_bug820497.js @@ -36,14 +36,12 @@ function pluginBindingAttached() { ok(testplugin, "should have test plugin"); var secondtestplugin = doc.getElementById("secondtest"); ok(!secondtestplugin, "should not yet have second test plugin"); - var notification; - waitForNotificationPopup("click-to-play-plugins", gTestBrowser, (notification => { - ok(notification, "should have popup notification"); - // We don't set up the action list until the notification is shown - notification.reshow(); - is(notification.options.pluginData.size, 1, "should be 1 type of plugin in the popup notification"); - XPCNativeWrapper.unwrap(gTestBrowser.contentWindow).addSecondPlugin(); - })); + var notification = PopupNotifications.getNotification("click-to-play-plugins", gTestBrowser); + ok(notification, "should have popup notification"); + // We don't set up the action list until the notification is shown + notification.reshow(); + is(notification.options.pluginData.size, 1, "should be 1 type of plugin in the popup notification"); + XPCNativeWrapper.unwrap(gTestBrowser.contentWindow).addSecondPlugin(); } else if (gNumPluginBindingsAttached == 2) { var doc = gTestBrowser.contentDocument; var testplugin = doc.getElementById("test"); @@ -53,8 +51,8 @@ function pluginBindingAttached() { var notification = PopupNotifications.getNotification("click-to-play-plugins", gTestBrowser); ok(notification, "should have popup notification"); notification.reshow(); - let condition = () => (notification.options.pluginData.size == 2); - waitForCondition(condition, finish, "Waited too long for 2 types of plugins in popup notification"); + is(notification.options.pluginData.size, 2, "should be 2 types of plugin in the popup notification"); + finish(); } else { ok(false, "if we've gotten here, something is quite wrong"); } diff --git a/browser/base/content/test/plugins/browser_globalplugin_crashinfobar.js b/browser/base/content/test/plugins/browser_globalplugin_crashinfobar.js index 68778dacf081..1c1b69707519 100644 --- a/browser/base/content/test/plugins/browser_globalplugin_crashinfobar.js +++ b/browser/base/content/test/plugins/browser_globalplugin_crashinfobar.js @@ -59,11 +59,11 @@ function onCrash(event) { is (propVal, val, "Correct property in detail propBag: " + name + "."); } - waitForNotificationBar("plugin-crashed", gTestBrowser, (notification) => { - let notificationBox = gBrowser.getNotificationBox(gTestBrowser); - ok(notification, "Infobar was shown."); - is(notification.priority, notificationBox.PRIORITY_WARNING_MEDIUM, "Correct priority."); - is(notification.getAttribute("label"), "The GlobalTestPlugin plugin has crashed.", "Correct message."); - finish(); - }); + let notificationBox = gBrowser.getNotificationBox(gTestBrowser); + let notification = notificationBox.getNotificationWithValue("plugin-crashed"); + + ok(notification, "Infobar was shown."); + is(notification.priority, notificationBox.PRIORITY_WARNING_MEDIUM, "Correct priority."); + is(notification.getAttribute("label"), "The GlobalTestPlugin plugin has crashed.", "Correct message."); + finish(); } diff --git a/browser/base/content/test/plugins/browser_pluginCrashCommentAndURL.js b/browser/base/content/test/plugins/browser_pluginCrashCommentAndURL.js index 216878a21ceb..9dc803d01f3b 100644 --- a/browser/base/content/test/plugins/browser_pluginCrashCommentAndURL.js +++ b/browser/base/content/test/plugins/browser_pluginCrashCommentAndURL.js @@ -6,80 +6,9 @@ Cu.import("resource://gre/modules/CrashSubmit.jsm", this); Cu.import("resource://gre/modules/Services.jsm"); const CRASH_URL = "http://example.com/browser/browser/base/content/test/plugins/plugin_crashCommentAndURL.html"; + const SERVER_URL = "http://example.com/browser/toolkit/crashreporter/test/browser/crashreport.sjs"; -/** - * Frame script that will be injected into the test browser - * to cause plugin crashes, and then manipulate the crashed plugin - * UI. The specific actions and checks that occur in the frame - * script for the crashed plugin UI are set in the - * test:crash-plugin message object sent from the parent. The actions - * and checks that the parent can specify are: - * - * pleaseSubmitStyle: the display style that the pleaseSubmit anonymous element - * should have - example "block", "none". - * submitComment: the comment that should be put into the crash report - * urlOptIn: true if the submitURLOptIn element should be checked. - * sendCrashMessage: if true, the frame script will send a - * test:crash-plugin:crashed message when the plugin has - * crashed. This is used for the last test case, and - * causes the frame script to skip any of the crashed - * plugin UI manipulation, since the last test shows - * no crashed plugin UI. - */ -function frameScript() { - function fail(reason) { - sendAsyncMessage("test:crash-plugin:fail", { - reason: `Failure from frameScript: ${reason}`, - }); - } - - addMessageListener("test:crash-plugin", (message) => { - addEventListener("PluginCrashed", function onPluginCrashed(event) { - removeEventListener("PluginCrashed", onPluginCrashed); - - let doc = content.document; - let plugin = doc.getElementById("plugin"); - if (!plugin) { - fail("Could not find plugin element"); - return; - } - - let getUI = (anonid) => { - return doc.getAnonymousElementByAttribute(plugin, "anonid", anonid); - }; - - let style = content.getComputedStyle(getUI("pleaseSubmit")); - if (style.display != message.data.pleaseSubmitStyle) { - fail("Submission UI visibility is not correct. Expected " + - `${message.data.pleaseSubmitStyle} and got ${style.display}`); - return; - } - - if (message.data.sendCrashMessage) { - let propBag = event.detail.QueryInterface(Ci.nsIPropertyBag2); - let crashID = propBag.getPropertyAsAString("pluginDumpID"); - sendAsyncMessage("test:crash-plugin:crashed", { - crashID: crashID, - }); - return; - } - - if (message.data.submitComment) { - getUI("submitComment").value = message.data.submitComment; - } - getUI("submitURLOptIn").checked = message.data.urlOptIn; - getUI("submitButton").click(); - }); - - let plugin = content.document.getElementById("test"); - try { - plugin.crash() - } catch(e) { - } - }); -} - function test() { // Crashing the plugin takes up a lot of time, so extend the test timeout. requestLongerTimeout(runs.length); @@ -100,18 +29,14 @@ function test() { let tab = gBrowser.loadOneTab("about:blank", { inBackground: false }); let browser = gBrowser.getBrowserForTab(tab); - let mm = browser.messageManager; - mm.loadFrameScript("data:,(" + frameScript.toString() + ")();", true); - - mm.addMessageListener("test:crash-plugin:fail", (message) => { - ok(false, message.data.reason); - }); - + browser.addEventListener("PluginCrashed", onCrash, false); Services.obs.addObserver(onSubmitStatus, "crash-report-status", false); registerCleanupFunction(function cleanUp() { env.set("MOZ_CRASHREPORTER_NO_REPORT", noReport); env.set("MOZ_CRASHREPORTER_URL", serverURL); + gBrowser.selectedBrowser.removeEventListener("PluginCrashed", onCrash, + false); Services.obs.removeObserver(onSubmitStatus, "crash-report-status"); gBrowser.removeCurrentTab(); }); @@ -151,24 +76,6 @@ function doNextRun() { memo[arg] = currentRun[arg]; return memo; }, {}); - let mm = gBrowser.selectedBrowser.messageManager; - - if (!currentRun.shouldSubmittionUIBeVisible) { - mm.addMessageListener("test:crash-plugin:crash", function onCrash(message) { - mm.removeMessageListener("test:crash-plugin:crash", onCrash); - - ok(!!message.data.crashID, "pluginDumpID should be set"); - CrashSubmit.delete(message.data.crashID); - doNextRun(); - }); - } - - mm.sendAsyncMessage("test:crash-plugin", { - pleaseSubmitStyle: currentRun.shouldSubmissionUIBeVisible ? "block" : "none", - submitComment: currentRun.comment, - urlOptIn: currentRun.urlOptIn, - sendOnCrashMessage: !currentRun.shouldSubmissionUIBeVisible, - }); gBrowser.loadURI(CRASH_URL + "?" + encodeURIComponent(JSON.stringify(args))); // And now wait for the crash. @@ -179,6 +86,37 @@ function doNextRun() { } } +function onCrash(event) { + try { + let plugin = gBrowser.contentDocument.getElementById("plugin"); + let elt = gPluginHandler.getPluginUI.bind(gPluginHandler, plugin); + let style = + gBrowser.contentWindow.getComputedStyle(elt("pleaseSubmit")); + is(style.display, + currentRun.shouldSubmissionUIBeVisible ? "block" : "none", + "Submission UI visibility should be correct"); + if (!currentRun.shouldSubmissionUIBeVisible) { + // Done with this run. We don't submit the crash, so we will have to + // remove the dump manually. + let propBag = event.detail.QueryInterface(Ci.nsIPropertyBag2); + let crashID = propBag.getPropertyAsAString("pluginDumpID"); + ok(!!crashID, "pluginDumpID should be set"); + CrashSubmit.delete(crashID); + + doNextRun(); + return; + } + elt("submitComment").value = currentRun.comment; + elt("submitURLOptIn").checked = currentRun.urlOptIn; + elt("submitButton").click(); + // And now wait for the submission status notification. + } + catch (err) { + failWithException(err); + doNextRun(); + } +} + function onSubmitStatus(subj, topic, data) { try { // Wait for success or failed, doesn't matter which. diff --git a/browser/base/content/test/plugins/browser_pluginnotification.js b/browser/base/content/test/plugins/browser_pluginnotification.js index 3841727871ed..234a9f81dc2c 100644 --- a/browser/base/content/test/plugins/browser_pluginnotification.js +++ b/browser/base/content/test/plugins/browser_pluginnotification.js @@ -56,7 +56,6 @@ TabOpenListener.prototype = { function test() { waitForExplicitFinish(); - SimpleTest.requestCompleteLog(); requestLongerTimeout(2); registerCleanupFunction(function() { clearAllPluginPermissions(); @@ -798,10 +797,7 @@ function test24a() { // simulate "always allow" notification.reshow(); PopupNotifications.panel.firstChild._primaryButton.click(); - waitForCondition(() => objLoadingContent.activated, () => { - prepareTest(test24b, gHttpTestRoot + "plugin_test.html"); - }, "Test 24a, plugin should now be activated."); - + prepareTest(test24b, gHttpTestRoot + "plugin_test.html"); } // did the "always allow" work as intended? @@ -809,11 +805,11 @@ function test24b() { var plugin = gTestBrowser.contentDocument.getElementById("test"); ok(plugin, "Test 24b, Found plugin in page"); var objLoadingContent = plugin.QueryInterface(Ci.nsIObjectLoadingContent); - waitForCondition(() => objLoadingContent.activated, () => { - setAndUpdateBlocklist(gHttpTestRoot + "blockPluginVulnerableUpdatable.xml", () => { - prepareTest(runAfterPluginBindingAttached(test24c), gHttpTestRoot + "plugin_test.html"); - }); - }, "Test 24b, plugin should be activated"); + ok(objLoadingContent.activated, "Test 24b, plugin should be activated"); + setAndUpdateBlocklist(gHttpTestRoot + "blockPluginVulnerableUpdatable.xml", + function() { + prepareTest(runAfterPluginBindingAttached(test24c), gHttpTestRoot + "plugin_test.html"); + }); } // the plugin is now blocklisted, so it should not automatically load @@ -824,13 +820,13 @@ function test24c() { ok(plugin, "Test 24c, Found plugin in page"); var objLoadingContent = plugin.QueryInterface(Ci.nsIObjectLoadingContent); is(objLoadingContent.pluginFallbackType, Ci.nsIObjectLoadingContent.PLUGIN_VULNERABLE_UPDATABLE, "Test 24c, Plugin should be vulnerable/updatable"); - waitForCondition(() => !objLoadingContent.activated, () => { - // simulate "always allow" - notification.reshow(); - PopupNotifications.panel.firstChild._primaryButton.click(); + ok(!objLoadingContent.activated, "Test 24c, plugin should not be activated"); - prepareTest(test24d, gHttpTestRoot + "plugin_test.html"); - }, "Test 24c, plugin should not be activated"); + // simulate "always allow" + notification.reshow(); + PopupNotifications.panel.firstChild._primaryButton.click(); + + prepareTest(test24d, gHttpTestRoot + "plugin_test.html"); } // We should still be able to always allow a plugin after we've seen that it's @@ -839,14 +835,15 @@ function test24d() { var plugin = gTestBrowser.contentDocument.getElementById("test"); ok(plugin, "Test 24d, Found plugin in page"); var objLoadingContent = plugin.QueryInterface(Ci.nsIObjectLoadingContent); - waitForCondition(() => objLoadingContent.activated, () => { - // this resets the vulnerable plugin permission - setAndUpdateBlocklist(gHttpTestRoot + "blockNoPlugins.xml", () => { - clearAllPluginPermissions(); - resetBlocklist(); - prepareTest(test25, gTestRoot + "plugin_syncRemoved.html"); - }); - }, "Test 24d, plugin should be activated"); + ok(objLoadingContent.activated, "Test 24d, plugin should be activated"); + + // this resets the vulnerable plugin permission + setAndUpdateBlocklist(gHttpTestRoot + "blockNoPlugins.xml", + function() { + clearAllPluginPermissions(); + resetBlocklist(); + prepareTest(test25, gTestRoot + "plugin_syncRemoved.html"); + }); } function test25() { diff --git a/browser/base/content/test/plugins/head.js b/browser/base/content/test/plugins/head.js index a6c3cd42f549..53359e20adf2 100644 --- a/browser/base/content/test/plugins/head.js +++ b/browser/base/content/test/plugins/head.js @@ -108,28 +108,3 @@ function setAndUpdateBlocklist(aURL, aCallback) { function resetBlocklist() { Services.prefs.setCharPref("extensions.blocklist.url", _originalTestBlocklistURL); } - -function waitForNotificationPopup(notificationID, browser, callback) { - let notification; - waitForCondition( - () => (notification = PopupNotifications.getNotification(notificationID, browser)), - () => { - ok(notification, `Successfully got the ${notificationID} notification popup`); - callback(notification); - }, - `Waited too long for the ${notificationID} notification popup` - ); -} - -function waitForNotificationBar(notificationID, browser, callback) { - let notification; - let notificationBox = gBrowser.getNotificationBox(browser); - waitForCondition( - () => (notification = notificationBox.getNotificationWithValue(notificationID)), - () => { - ok(notification, `Successfully got the ${notificationID} notification bar`); - callback(notification); - }, - `Waited too long for the ${notificationID} notification bar` - ); -} diff --git a/browser/base/content/urlbarBindings.xml b/browser/base/content/urlbarBindings.xml index f5d46e2beeb2..aaead336356a 100644 --- a/browser/base/content/urlbarBindings.xml +++ b/browser/base/content/urlbarBindings.xml @@ -1976,7 +1976,7 @@ return; } - let host = this.notification.options.host; + let host = gPluginHandler._getHostFromPrincipal(this.notification.browser.contentWindow.document.nodePrincipal); this._setupDescription("pluginActivateMultiple.message", null, host); var showBox = document.getAnonymousElementByAttribute(this, "anonid", "plugin-notification-showbox"); diff --git a/browser/components/loop/content/conversation.html b/browser/components/loop/content/conversation.html index f034eba3e0c7..149ba2e04d78 100644 --- a/browser/components/loop/content/conversation.html +++ b/browser/components/loop/content/conversation.html @@ -11,21 +11,14 @@ - +
- + diff --git a/browser/components/loop/content/js/conversation.js b/browser/components/loop/content/js/conversation.js index 0c4d1a6ce587..e181ec7231da 100644 --- a/browser/components/loop/content/js/conversation.js +++ b/browser/components/loop/content/js/conversation.js @@ -431,3 +431,5 @@ loop.conversation = (function(OT, mozL10n) { init: init }; })(window.OT, document.mozL10n); + +document.addEventListener('DOMContentLoaded', loop.conversation.init); diff --git a/browser/components/loop/content/js/conversation.jsx b/browser/components/loop/content/js/conversation.jsx index 14ed605e4eb7..23ff1f3966c1 100644 --- a/browser/components/loop/content/js/conversation.jsx +++ b/browser/components/loop/content/js/conversation.jsx @@ -431,3 +431,5 @@ loop.conversation = (function(OT, mozL10n) { init: init }; })(window.OT, document.mozL10n); + +document.addEventListener('DOMContentLoaded', loop.conversation.init); diff --git a/browser/components/loop/content/js/otconfig.js b/browser/components/loop/content/js/otconfig.js new file mode 100644 index 000000000000..aae45e911cfd --- /dev/null +++ b/browser/components/loop/content/js/otconfig.js @@ -0,0 +1,10 @@ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this file, + * You can obtain one at http://mozilla.org/MPL/2.0/. */ + +window.OTProperties = { + cdnURL: 'loop/', +}; +window.OTProperties.assetURL = window.OTProperties.cdnURL + 'sdk-content/'; +window.OTProperties.configURL = window.OTProperties.assetURL + 'js/dynamic_config.min.js'; +window.OTProperties.cssURL = window.OTProperties.assetURL + 'css/ot.css'; diff --git a/browser/components/loop/content/js/panel.js b/browser/components/loop/content/js/panel.js index a6debcd30d67..df1e4cb23977 100644 --- a/browser/components/loop/content/js/panel.js +++ b/browser/components/loop/content/js/panel.js @@ -551,3 +551,5 @@ loop.panel = (function(_, mozL10n) { ToSView: ToSView }; })(_, document.mozL10n); + +document.addEventListener('DOMContentLoaded', loop.panel.init); diff --git a/browser/components/loop/content/js/panel.jsx b/browser/components/loop/content/js/panel.jsx index 76f5e6371ee0..a4243779233b 100644 --- a/browser/components/loop/content/js/panel.jsx +++ b/browser/components/loop/content/js/panel.jsx @@ -551,3 +551,5 @@ loop.panel = (function(_, mozL10n) { ToSView: ToSView }; })(_, document.mozL10n); + +document.addEventListener('DOMContentLoaded', loop.panel.init); diff --git a/browser/components/loop/content/panel.html b/browser/components/loop/content/panel.html index 553e5b9cc006..c2e244129686 100644 --- a/browser/components/loop/content/panel.html +++ b/browser/components/loop/content/panel.html @@ -10,7 +10,7 @@ - +
diff --git a/browser/components/loop/jar.mn b/browser/components/loop/jar.mn index c28286f50356..4cd797be3724 100644 --- a/browser/components/loop/jar.mn +++ b/browser/components/loop/jar.mn @@ -14,6 +14,7 @@ browser.jar: content/browser/loop/js/client.js (content/js/client.js) content/browser/loop/js/desktopRouter.js (content/js/desktopRouter.js) content/browser/loop/js/conversation.js (content/js/conversation.js) + content/browser/loop/js/otconfig.js (content/js/otconfig.js) content/browser/loop/js/panel.js (content/js/panel.js) # Shared styles diff --git a/browser/components/loop/test/desktop-local/index.html b/browser/components/loop/test/desktop-local/index.html index 8f6200126478..f59468a64d31 100644 --- a/browser/components/loop/test/desktop-local/index.html +++ b/browser/components/loop/test/desktop-local/index.html @@ -49,6 +49,9 @@