michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: Cu.import("resource://gre/modules/Services.jsm"); michael@0: michael@0: const SERVER_URL = "http://example.com/browser/toolkit/crashreporter/test/browser/crashreport.sjs"; michael@0: const gTestRoot = getRootDirectory(gTestPath); michael@0: var gTestBrowser = null; michael@0: michael@0: // Test that plugin crash submissions still work properly after michael@0: // click-to-play activation. michael@0: michael@0: function test() { michael@0: // Crashing the plugin takes up a lot of time, so extend the test timeout. michael@0: requestLongerTimeout(2); michael@0: waitForExplicitFinish(); michael@0: setTestPluginEnabledState(Ci.nsIPluginTag.STATE_CLICKTOPLAY); michael@0: michael@0: // The test harness sets MOZ_CRASHREPORTER_NO_REPORT, which disables plugin michael@0: // crash reports. This test needs them enabled. The test also needs a mock michael@0: // report server, and fortunately one is already set up by toolkit/ michael@0: // crashreporter/test/Makefile.in. Assign its URL to MOZ_CRASHREPORTER_URL, michael@0: // which CrashSubmit.jsm uses as a server override. michael@0: let env = Cc["@mozilla.org/process/environment;1"]. michael@0: getService(Components.interfaces.nsIEnvironment); michael@0: let noReport = env.get("MOZ_CRASHREPORTER_NO_REPORT"); michael@0: let serverURL = env.get("MOZ_CRASHREPORTER_URL"); michael@0: env.set("MOZ_CRASHREPORTER_NO_REPORT", ""); michael@0: env.set("MOZ_CRASHREPORTER_URL", SERVER_URL); michael@0: michael@0: let tab = gBrowser.loadOneTab("about:blank", { inBackground: false }); michael@0: gTestBrowser = gBrowser.getBrowserForTab(tab); michael@0: gTestBrowser.addEventListener("PluginCrashed", onCrash, false); michael@0: gTestBrowser.addEventListener("load", onPageLoad, true); michael@0: Services.obs.addObserver(onSubmitStatus, "crash-report-status", false); michael@0: michael@0: registerCleanupFunction(function cleanUp() { michael@0: env.set("MOZ_CRASHREPORTER_NO_REPORT", noReport); michael@0: env.set("MOZ_CRASHREPORTER_URL", serverURL); michael@0: gTestBrowser.removeEventListener("PluginCrashed", onCrash, false); michael@0: gTestBrowser.removeEventListener("load", onPageLoad, true); michael@0: Services.obs.removeObserver(onSubmitStatus, "crash-report-status"); michael@0: gBrowser.removeCurrentTab(); michael@0: }); michael@0: michael@0: gTestBrowser.contentWindow.location = gTestRoot + "plugin_big.html"; michael@0: } michael@0: function onPageLoad() { michael@0: // Force the plugins binding to attach as layout is async. michael@0: let plugin = gTestBrowser.contentDocument.getElementById("test"); michael@0: plugin.clientTop; michael@0: executeSoon(afterBindingAttached); michael@0: } michael@0: michael@0: function afterBindingAttached() { michael@0: let popupNotification = PopupNotifications.getNotification("click-to-play-plugins", gTestBrowser); michael@0: ok(popupNotification, "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, "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, pluginActivated, "Waited too long for plugin to activate"); michael@0: } michael@0: michael@0: function pluginActivated() { michael@0: let plugin = gTestBrowser.contentDocument.getElementById("test"); michael@0: try { michael@0: plugin.crash(); michael@0: } catch (e) { michael@0: // The plugin crashed in the above call, an exception is expected. michael@0: } michael@0: } michael@0: michael@0: function onCrash() { michael@0: try { michael@0: let plugin = gBrowser.contentDocument.getElementById("test"); michael@0: let elt = gPluginHandler.getPluginUI.bind(gPluginHandler, plugin); michael@0: let style = michael@0: gBrowser.contentWindow.getComputedStyle(elt("pleaseSubmit")); michael@0: is(style.display, "block", "Submission UI visibility should be correct"); michael@0: michael@0: elt("submitComment").value = "a test comment"; michael@0: is(elt("submitURLOptIn").checked, true, "URL opt-in should default to true"); michael@0: EventUtils.synthesizeMouseAtCenter(elt("submitURLOptIn"), {}, gTestBrowser.contentWindow); michael@0: EventUtils.synthesizeMouseAtCenter(elt("submitButton"), {}, gTestBrowser.contentWindow); michael@0: // And now wait for the submission status notification. michael@0: } michael@0: catch (err) { michael@0: failWithException(err); michael@0: } michael@0: } michael@0: michael@0: function onSubmitStatus(subj, topic, data) { michael@0: try { michael@0: // Wait for success or failed, doesn't matter which. michael@0: if (data != "success" && data != "failed") michael@0: return; michael@0: michael@0: let extra = getPropertyBagValue(subj.QueryInterface(Ci.nsIPropertyBag), michael@0: "extra"); michael@0: ok(extra instanceof Ci.nsIPropertyBag, "Extra data should be property bag"); michael@0: michael@0: let val = getPropertyBagValue(extra, "PluginUserComment"); michael@0: is(val, "a test comment", michael@0: "Comment in extra data should match comment in textbox"); michael@0: michael@0: val = getPropertyBagValue(extra, "PluginContentURL"); michael@0: ok(val === undefined, michael@0: "URL should be absent from extra data when opt-in not checked"); michael@0: } michael@0: catch (err) { michael@0: failWithException(err); michael@0: } michael@0: finish(); michael@0: } michael@0: michael@0: function getPropertyBagValue(bag, key) { michael@0: try { michael@0: var val = bag.getProperty(key); michael@0: } michael@0: catch (e if e.result == Cr.NS_ERROR_FAILURE) {} michael@0: return val; michael@0: } michael@0: michael@0: function failWithException(err) { michael@0: ok(false, "Uncaught exception: " + err + "\n" + err.stack); michael@0: }