browser/base/content/test/plugins/browser_CTP_crashreporting.js

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

michael@0 1 /* This Source Code Form is subject to the terms of the Mozilla Public
michael@0 2 * License, v. 2.0. If a copy of the MPL was not distributed with this
michael@0 3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
michael@0 4
michael@0 5 Cu.import("resource://gre/modules/Services.jsm");
michael@0 6
michael@0 7 const SERVER_URL = "http://example.com/browser/toolkit/crashreporter/test/browser/crashreport.sjs";
michael@0 8 const gTestRoot = getRootDirectory(gTestPath);
michael@0 9 var gTestBrowser = null;
michael@0 10
michael@0 11 // Test that plugin crash submissions still work properly after
michael@0 12 // click-to-play activation.
michael@0 13
michael@0 14 function test() {
michael@0 15 // Crashing the plugin takes up a lot of time, so extend the test timeout.
michael@0 16 requestLongerTimeout(2);
michael@0 17 waitForExplicitFinish();
michael@0 18 setTestPluginEnabledState(Ci.nsIPluginTag.STATE_CLICKTOPLAY);
michael@0 19
michael@0 20 // The test harness sets MOZ_CRASHREPORTER_NO_REPORT, which disables plugin
michael@0 21 // crash reports. This test needs them enabled. The test also needs a mock
michael@0 22 // report server, and fortunately one is already set up by toolkit/
michael@0 23 // crashreporter/test/Makefile.in. Assign its URL to MOZ_CRASHREPORTER_URL,
michael@0 24 // which CrashSubmit.jsm uses as a server override.
michael@0 25 let env = Cc["@mozilla.org/process/environment;1"].
michael@0 26 getService(Components.interfaces.nsIEnvironment);
michael@0 27 let noReport = env.get("MOZ_CRASHREPORTER_NO_REPORT");
michael@0 28 let serverURL = env.get("MOZ_CRASHREPORTER_URL");
michael@0 29 env.set("MOZ_CRASHREPORTER_NO_REPORT", "");
michael@0 30 env.set("MOZ_CRASHREPORTER_URL", SERVER_URL);
michael@0 31
michael@0 32 let tab = gBrowser.loadOneTab("about:blank", { inBackground: false });
michael@0 33 gTestBrowser = gBrowser.getBrowserForTab(tab);
michael@0 34 gTestBrowser.addEventListener("PluginCrashed", onCrash, false);
michael@0 35 gTestBrowser.addEventListener("load", onPageLoad, true);
michael@0 36 Services.obs.addObserver(onSubmitStatus, "crash-report-status", false);
michael@0 37
michael@0 38 registerCleanupFunction(function cleanUp() {
michael@0 39 env.set("MOZ_CRASHREPORTER_NO_REPORT", noReport);
michael@0 40 env.set("MOZ_CRASHREPORTER_URL", serverURL);
michael@0 41 gTestBrowser.removeEventListener("PluginCrashed", onCrash, false);
michael@0 42 gTestBrowser.removeEventListener("load", onPageLoad, true);
michael@0 43 Services.obs.removeObserver(onSubmitStatus, "crash-report-status");
michael@0 44 gBrowser.removeCurrentTab();
michael@0 45 });
michael@0 46
michael@0 47 gTestBrowser.contentWindow.location = gTestRoot + "plugin_big.html";
michael@0 48 }
michael@0 49 function onPageLoad() {
michael@0 50 // Force the plugins binding to attach as layout is async.
michael@0 51 let plugin = gTestBrowser.contentDocument.getElementById("test");
michael@0 52 plugin.clientTop;
michael@0 53 executeSoon(afterBindingAttached);
michael@0 54 }
michael@0 55
michael@0 56 function afterBindingAttached() {
michael@0 57 let popupNotification = PopupNotifications.getNotification("click-to-play-plugins", gTestBrowser);
michael@0 58 ok(popupNotification, "Should have a click-to-play notification");
michael@0 59
michael@0 60 let plugin = gTestBrowser.contentDocument.getElementById("test");
michael@0 61 let objLoadingContent = plugin.QueryInterface(Ci.nsIObjectLoadingContent);
michael@0 62 ok(!objLoadingContent.activated, "Plugin should not be activated");
michael@0 63
michael@0 64 // Simulate clicking the "Allow Always" button.
michael@0 65 popupNotification.reshow();
michael@0 66 PopupNotifications.panel.firstChild._primaryButton.click();
michael@0 67
michael@0 68 let condition = function() objLoadingContent.activated;
michael@0 69 waitForCondition(condition, pluginActivated, "Waited too long for plugin to activate");
michael@0 70 }
michael@0 71
michael@0 72 function pluginActivated() {
michael@0 73 let plugin = gTestBrowser.contentDocument.getElementById("test");
michael@0 74 try {
michael@0 75 plugin.crash();
michael@0 76 } catch (e) {
michael@0 77 // The plugin crashed in the above call, an exception is expected.
michael@0 78 }
michael@0 79 }
michael@0 80
michael@0 81 function onCrash() {
michael@0 82 try {
michael@0 83 let plugin = gBrowser.contentDocument.getElementById("test");
michael@0 84 let elt = gPluginHandler.getPluginUI.bind(gPluginHandler, plugin);
michael@0 85 let style =
michael@0 86 gBrowser.contentWindow.getComputedStyle(elt("pleaseSubmit"));
michael@0 87 is(style.display, "block", "Submission UI visibility should be correct");
michael@0 88
michael@0 89 elt("submitComment").value = "a test comment";
michael@0 90 is(elt("submitURLOptIn").checked, true, "URL opt-in should default to true");
michael@0 91 EventUtils.synthesizeMouseAtCenter(elt("submitURLOptIn"), {}, gTestBrowser.contentWindow);
michael@0 92 EventUtils.synthesizeMouseAtCenter(elt("submitButton"), {}, gTestBrowser.contentWindow);
michael@0 93 // And now wait for the submission status notification.
michael@0 94 }
michael@0 95 catch (err) {
michael@0 96 failWithException(err);
michael@0 97 }
michael@0 98 }
michael@0 99
michael@0 100 function onSubmitStatus(subj, topic, data) {
michael@0 101 try {
michael@0 102 // Wait for success or failed, doesn't matter which.
michael@0 103 if (data != "success" && data != "failed")
michael@0 104 return;
michael@0 105
michael@0 106 let extra = getPropertyBagValue(subj.QueryInterface(Ci.nsIPropertyBag),
michael@0 107 "extra");
michael@0 108 ok(extra instanceof Ci.nsIPropertyBag, "Extra data should be property bag");
michael@0 109
michael@0 110 let val = getPropertyBagValue(extra, "PluginUserComment");
michael@0 111 is(val, "a test comment",
michael@0 112 "Comment in extra data should match comment in textbox");
michael@0 113
michael@0 114 val = getPropertyBagValue(extra, "PluginContentURL");
michael@0 115 ok(val === undefined,
michael@0 116 "URL should be absent from extra data when opt-in not checked");
michael@0 117 }
michael@0 118 catch (err) {
michael@0 119 failWithException(err);
michael@0 120 }
michael@0 121 finish();
michael@0 122 }
michael@0 123
michael@0 124 function getPropertyBagValue(bag, key) {
michael@0 125 try {
michael@0 126 var val = bag.getProperty(key);
michael@0 127 }
michael@0 128 catch (e if e.result == Cr.NS_ERROR_FAILURE) {}
michael@0 129 return val;
michael@0 130 }
michael@0 131
michael@0 132 function failWithException(err) {
michael@0 133 ok(false, "Uncaught exception: " + err + "\n" + err.stack);
michael@0 134 }

mercurial