Wed, 31 Dec 2014 13:27:57 +0100
Ignore runtime configuration files generated during quality assurance.
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 CRASH_URL = "http://example.com/browser/browser/base/content/test/plugins/plugin_crashCommentAndURL.html"; |
michael@0 | 8 | |
michael@0 | 9 | const SERVER_URL = "http://example.com/browser/toolkit/crashreporter/test/browser/crashreport.sjs"; |
michael@0 | 10 | |
michael@0 | 11 | function test() { |
michael@0 | 12 | // Crashing the plugin takes up a lot of time, so extend the test timeout. |
michael@0 | 13 | requestLongerTimeout(runs.length); |
michael@0 | 14 | waitForExplicitFinish(); |
michael@0 | 15 | setTestPluginEnabledState(Ci.nsIPluginTag.STATE_ENABLED); |
michael@0 | 16 | |
michael@0 | 17 | // The test harness sets MOZ_CRASHREPORTER_NO_REPORT, which disables plugin |
michael@0 | 18 | // crash reports. This test needs them enabled. The test also needs a mock |
michael@0 | 19 | // report server, and fortunately one is already set up by toolkit/ |
michael@0 | 20 | // crashreporter/test/Makefile.in. Assign its URL to MOZ_CRASHREPORTER_URL, |
michael@0 | 21 | // which CrashSubmit.jsm uses as a server override. |
michael@0 | 22 | let env = Cc["@mozilla.org/process/environment;1"]. |
michael@0 | 23 | getService(Components.interfaces.nsIEnvironment); |
michael@0 | 24 | let noReport = env.get("MOZ_CRASHREPORTER_NO_REPORT"); |
michael@0 | 25 | let serverURL = env.get("MOZ_CRASHREPORTER_URL"); |
michael@0 | 26 | env.set("MOZ_CRASHREPORTER_NO_REPORT", ""); |
michael@0 | 27 | env.set("MOZ_CRASHREPORTER_URL", SERVER_URL); |
michael@0 | 28 | |
michael@0 | 29 | let tab = gBrowser.loadOneTab("about:blank", { inBackground: false }); |
michael@0 | 30 | let browser = gBrowser.getBrowserForTab(tab); |
michael@0 | 31 | browser.addEventListener("PluginCrashed", onCrash, false); |
michael@0 | 32 | Services.obs.addObserver(onSubmitStatus, "crash-report-status", false); |
michael@0 | 33 | |
michael@0 | 34 | registerCleanupFunction(function cleanUp() { |
michael@0 | 35 | env.set("MOZ_CRASHREPORTER_NO_REPORT", noReport); |
michael@0 | 36 | env.set("MOZ_CRASHREPORTER_URL", serverURL); |
michael@0 | 37 | gBrowser.selectedBrowser.removeEventListener("PluginCrashed", onCrash, |
michael@0 | 38 | false); |
michael@0 | 39 | Services.obs.removeObserver(onSubmitStatus, "crash-report-status"); |
michael@0 | 40 | gBrowser.removeCurrentTab(); |
michael@0 | 41 | }); |
michael@0 | 42 | |
michael@0 | 43 | doNextRun(); |
michael@0 | 44 | } |
michael@0 | 45 | |
michael@0 | 46 | let runs = [ |
michael@0 | 47 | { |
michael@0 | 48 | shouldSubmissionUIBeVisible: true, |
michael@0 | 49 | comment: "", |
michael@0 | 50 | urlOptIn: false, |
michael@0 | 51 | }, |
michael@0 | 52 | { |
michael@0 | 53 | shouldSubmissionUIBeVisible: true, |
michael@0 | 54 | comment: "a test comment", |
michael@0 | 55 | urlOptIn: true, |
michael@0 | 56 | }, |
michael@0 | 57 | { |
michael@0 | 58 | width: 300, |
michael@0 | 59 | height: 300, |
michael@0 | 60 | shouldSubmissionUIBeVisible: false, |
michael@0 | 61 | }, |
michael@0 | 62 | ]; |
michael@0 | 63 | |
michael@0 | 64 | let currentRun = null; |
michael@0 | 65 | |
michael@0 | 66 | function doNextRun() { |
michael@0 | 67 | try { |
michael@0 | 68 | if (!runs.length) { |
michael@0 | 69 | finish(); |
michael@0 | 70 | return; |
michael@0 | 71 | } |
michael@0 | 72 | currentRun = runs.shift(); |
michael@0 | 73 | let args = ["width", "height"].reduce(function (memo, arg) { |
michael@0 | 74 | if (arg in currentRun) |
michael@0 | 75 | memo[arg] = currentRun[arg]; |
michael@0 | 76 | return memo; |
michael@0 | 77 | }, {}); |
michael@0 | 78 | gBrowser.loadURI(CRASH_URL + "?" + |
michael@0 | 79 | encodeURIComponent(JSON.stringify(args))); |
michael@0 | 80 | // And now wait for the crash. |
michael@0 | 81 | } |
michael@0 | 82 | catch (err) { |
michael@0 | 83 | failWithException(err); |
michael@0 | 84 | finish(); |
michael@0 | 85 | } |
michael@0 | 86 | } |
michael@0 | 87 | |
michael@0 | 88 | function onCrash() { |
michael@0 | 89 | try { |
michael@0 | 90 | let plugin = gBrowser.contentDocument.getElementById("plugin"); |
michael@0 | 91 | let elt = gPluginHandler.getPluginUI.bind(gPluginHandler, plugin); |
michael@0 | 92 | let style = |
michael@0 | 93 | gBrowser.contentWindow.getComputedStyle(elt("pleaseSubmit")); |
michael@0 | 94 | is(style.display, |
michael@0 | 95 | currentRun.shouldSubmissionUIBeVisible ? "block" : "none", |
michael@0 | 96 | "Submission UI visibility should be correct"); |
michael@0 | 97 | if (!currentRun.shouldSubmissionUIBeVisible) { |
michael@0 | 98 | // Done with this run. |
michael@0 | 99 | doNextRun(); |
michael@0 | 100 | return; |
michael@0 | 101 | } |
michael@0 | 102 | elt("submitComment").value = currentRun.comment; |
michael@0 | 103 | elt("submitURLOptIn").checked = currentRun.urlOptIn; |
michael@0 | 104 | elt("submitButton").click(); |
michael@0 | 105 | // And now wait for the submission status notification. |
michael@0 | 106 | } |
michael@0 | 107 | catch (err) { |
michael@0 | 108 | failWithException(err); |
michael@0 | 109 | doNextRun(); |
michael@0 | 110 | } |
michael@0 | 111 | } |
michael@0 | 112 | |
michael@0 | 113 | function onSubmitStatus(subj, topic, data) { |
michael@0 | 114 | try { |
michael@0 | 115 | // Wait for success or failed, doesn't matter which. |
michael@0 | 116 | if (data != "success" && data != "failed") |
michael@0 | 117 | return; |
michael@0 | 118 | |
michael@0 | 119 | let extra = getPropertyBagValue(subj.QueryInterface(Ci.nsIPropertyBag), |
michael@0 | 120 | "extra"); |
michael@0 | 121 | ok(extra instanceof Ci.nsIPropertyBag, "Extra data should be property bag"); |
michael@0 | 122 | |
michael@0 | 123 | let val = getPropertyBagValue(extra, "PluginUserComment"); |
michael@0 | 124 | if (currentRun.comment) |
michael@0 | 125 | is(val, currentRun.comment, |
michael@0 | 126 | "Comment in extra data should match comment in textbox"); |
michael@0 | 127 | else |
michael@0 | 128 | ok(val === undefined, |
michael@0 | 129 | "Comment should be absent from extra data when textbox is empty"); |
michael@0 | 130 | |
michael@0 | 131 | val = getPropertyBagValue(extra, "PluginContentURL"); |
michael@0 | 132 | if (currentRun.urlOptIn) |
michael@0 | 133 | is(val, gBrowser.currentURI.spec, |
michael@0 | 134 | "URL in extra data should match browser URL when opt-in checked"); |
michael@0 | 135 | else |
michael@0 | 136 | ok(val === undefined, |
michael@0 | 137 | "URL should be absent from extra data when opt-in not checked"); |
michael@0 | 138 | } |
michael@0 | 139 | catch (err) { |
michael@0 | 140 | failWithException(err); |
michael@0 | 141 | } |
michael@0 | 142 | doNextRun(); |
michael@0 | 143 | } |
michael@0 | 144 | |
michael@0 | 145 | function getPropertyBagValue(bag, key) { |
michael@0 | 146 | try { |
michael@0 | 147 | var val = bag.getProperty(key); |
michael@0 | 148 | } |
michael@0 | 149 | catch (e if e.result == Cr.NS_ERROR_FAILURE) {} |
michael@0 | 150 | return val; |
michael@0 | 151 | } |
michael@0 | 152 | |
michael@0 | 153 | function failWithException(err) { |
michael@0 | 154 | ok(false, "Uncaught exception: " + err + "\n" + err.stack); |
michael@0 | 155 | } |