Wed, 31 Dec 2014 06:09:35 +0100
Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.
michael@0 | 1 | <?xml version="1.0"?> |
michael@0 | 2 | <?xml-stylesheet href="chrome://global/skin" type="text/css"?> |
michael@0 | 3 | <?xml-stylesheet href="chrome://mochikit/content/tests/SimpleTest/test.css" |
michael@0 | 4 | type="text/css"?> |
michael@0 | 5 | <window title="Basic Plugin Tests" |
michael@0 | 6 | xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"> |
michael@0 | 7 | <script type="application/javascript" |
michael@0 | 8 | src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js" /> |
michael@0 | 9 | <script type="application/javascript" |
michael@0 | 10 | src="chrome://mochikit/content/tests/SimpleTest/EventUtils.js" /> |
michael@0 | 11 | <script type="application/javascript" src="utils.js"></script> |
michael@0 | 12 | <script type="application/javascript"> |
michael@0 | 13 | setTestPluginEnabledState(SpecialPowers.Ci.nsIPluginTag.STATE_ENABLED); |
michael@0 | 14 | </script> |
michael@0 | 15 | <body xmlns="http://www.w3.org/1999/xhtml" onload="runTests()"> |
michael@0 | 16 | <embed id="plugin1" type="application/x-test" width="200" height="200"></embed> |
michael@0 | 17 | </body> |
michael@0 | 18 | <script class="testbody" type="application/javascript"> |
michael@0 | 19 | <![CDATA[ |
michael@0 | 20 | SimpleTest.waitForExplicitFinish(); |
michael@0 | 21 | SimpleTest.ignoreAllUncaughtExceptions(); |
michael@0 | 22 | |
michael@0 | 23 | Components.utils.import("resource://gre/modules/NetUtil.jsm"); |
michael@0 | 24 | Components.utils.import("resource://gre/modules/Services.jsm"); |
michael@0 | 25 | |
michael@0 | 26 | const Cc = Components.classes; |
michael@0 | 27 | const Ci = Components.interfaces; |
michael@0 | 28 | |
michael@0 | 29 | const crashReporter = Cc["@mozilla.org/toolkit/crash-reporter;1"].getService(Ci.nsICrashReporter); |
michael@0 | 30 | const SERVER_URL = "http://example.com/browser/toolkit/crashreporter/test/browser/crashreport.sjs"; |
michael@0 | 31 | |
michael@0 | 32 | const serverPrefName = "toolkit.crashreporter.pluginHangSubmitURL"; |
michael@0 | 33 | |
michael@0 | 34 | var oldServerPref; |
michael@0 | 35 | try { |
michael@0 | 36 | oldServerPref = Services.prefs.getCharPref(serverPrefName); |
michael@0 | 37 | } |
michael@0 | 38 | catch(e) { |
michael@0 | 39 | } |
michael@0 | 40 | |
michael@0 | 41 | const oldTimeoutPref = Services.prefs.getIntPref("dom.ipc.plugins.timeoutSecs"); |
michael@0 | 42 | |
michael@0 | 43 | var testObserver = { |
michael@0 | 44 | observe: function(subject, topic, data) { |
michael@0 | 45 | if (data == "submitting") // not done yet |
michael@0 | 46 | return; |
michael@0 | 47 | is(data, "success", "report should have been submitted successfully"); |
michael@0 | 48 | is(topic, "crash-report-status", "Checking correct topic"); |
michael@0 | 49 | ok(subject instanceof Ci.nsIPropertyBag2, "Subject should be a property bag"); |
michael@0 | 50 | ok(subject.hasKey("serverCrashID"), "Should have a server crash ID"); |
michael@0 | 51 | let crashid = subject.getPropertyAsAString("serverCrashID"); |
michael@0 | 52 | isnot(crashid, "", "Server crash ID should not be an empty string"); |
michael@0 | 53 | |
michael@0 | 54 | // Verify the data. The SJS script will return the data that was POSTed |
michael@0 | 55 | let req = new XMLHttpRequest(); |
michael@0 | 56 | req.open("GET", SERVER_URL + "?id=" + crashid, false); |
michael@0 | 57 | req.send(null); |
michael@0 | 58 | is(req.status, 200, "Server response should be 200 OK"); |
michael@0 | 59 | let submitted = JSON.parse(req.responseText); |
michael@0 | 60 | |
michael@0 | 61 | ok(!("Throttleable" in submitted), "Submit request should not be Throttleable"); |
michael@0 | 62 | is(submitted.ProcessType, "plugin", "Should specify ProcessType=plugin"); |
michael@0 | 63 | ok("PluginHang" in submitted, "Request should contain PluginHang field"); |
michael@0 | 64 | ok("additional_minidumps" in submitted, "Request should contain additional_minidumps field"); |
michael@0 | 65 | let dumpNames = submitted.additional_minidumps.split(','); |
michael@0 | 66 | ok(dumpNames.indexOf("browser") != -1, "additional_minidumps should contain browser"); |
michael@0 | 67 | info("additional_minidumps="+submitted.additional_minidumps); |
michael@0 | 68 | ok("upload_file_minidump" in submitted, "Request should contain upload_file_minidump field"); |
michael@0 | 69 | ok("upload_file_minidump_browser" in submitted, "Request should contain upload_file_minidump_browser field"); |
michael@0 | 70 | |
michael@0 | 71 | // Cleanup |
michael@0 | 72 | // First remove our fake submitted report |
michael@0 | 73 | let file = Services.dirsvc.get("UAppData", Ci.nsILocalFile); |
michael@0 | 74 | file.append("Crash Reports"); |
michael@0 | 75 | file.append("submitted"); |
michael@0 | 76 | file.append(crashid + ".txt"); |
michael@0 | 77 | file.remove(false); |
michael@0 | 78 | |
michael@0 | 79 | // Next unregister our observer |
michael@0 | 80 | Services.obs.removeObserver(testObserver, "crash-report-status"); |
michael@0 | 81 | |
michael@0 | 82 | // Then re-set MOZ_CRASHREPORTER_NO_REPORT |
michael@0 | 83 | let env = Cc["@mozilla.org/process/environment;1"].getService(Ci.nsIEnvironment); |
michael@0 | 84 | env.set("MOZ_CRASHREPORTER_NO_REPORT", "1"); |
michael@0 | 85 | |
michael@0 | 86 | // Finally re-set prefs |
michael@0 | 87 | if (oldServerPref === undefined) { |
michael@0 | 88 | Services.prefs.clearUserPref(serverPrefName); |
michael@0 | 89 | } |
michael@0 | 90 | else { |
michael@0 | 91 | Services.prefs.setCharPref(serverPrefName, oldServerPref); |
michael@0 | 92 | } |
michael@0 | 93 | Services.prefs.setIntPref("dom.ipc.plugins.timeoutSecs", oldTimeoutPref); |
michael@0 | 94 | SimpleTest.finish(); |
michael@0 | 95 | }, |
michael@0 | 96 | |
michael@0 | 97 | QueryInterface: function(iid) { |
michael@0 | 98 | if (iid.equals(Ci.nsIObserver) || |
michael@0 | 99 | iid.equals(Ci.nsISupportsWeakReference) || |
michael@0 | 100 | iid.equals(Ci.nsISupports)) |
michael@0 | 101 | return this; |
michael@0 | 102 | throw Components.results.NS_NOINTERFACE; |
michael@0 | 103 | } |
michael@0 | 104 | }; |
michael@0 | 105 | |
michael@0 | 106 | function onPluginCrashed(aEvent) { |
michael@0 | 107 | ok(true, "Plugin crashed notification received"); |
michael@0 | 108 | is(aEvent.type, "PluginCrashed", "event is correct type"); |
michael@0 | 109 | |
michael@0 | 110 | let submitButton = document.getAnonymousElementByAttribute(aEvent.target, |
michael@0 | 111 | "class", |
michael@0 | 112 | "submitButton"); |
michael@0 | 113 | // try to submit this report |
michael@0 | 114 | sendMouseEvent({type:'click'}, submitButton, window); |
michael@0 | 115 | } |
michael@0 | 116 | |
michael@0 | 117 | function runTests() { |
michael@0 | 118 | if (!SimpleTest.testPluginIsOOP()) { |
michael@0 | 119 | todo(false, "Skipping this test when test plugin is not OOP."); |
michael@0 | 120 | SimpleTest.finish(); |
michael@0 | 121 | return; |
michael@0 | 122 | } |
michael@0 | 123 | |
michael@0 | 124 | // Default plugin hang timeout is too high for mochitests |
michael@0 | 125 | Services.prefs.setIntPref("dom.ipc.plugins.timeoutSecs", 1); |
michael@0 | 126 | |
michael@0 | 127 | // the test harness will have set MOZ_CRASHREPORTER_NO_REPORT, |
michael@0 | 128 | // ensure that we can change the setting and have our minidumps |
michael@0 | 129 | // wind up in Crash Reports/pending |
michael@0 | 130 | let env = Cc["@mozilla.org/process/environment;1"] |
michael@0 | 131 | .getService(Ci.nsIEnvironment); |
michael@0 | 132 | env.set("MOZ_CRASHREPORTER_NO_REPORT", ""); |
michael@0 | 133 | |
michael@0 | 134 | // Override the crash reporter URL to send to our fake server |
michael@0 | 135 | Services.prefs.setCharPref("toolkit.crashreporter.pluginHangSubmitURL", SERVER_URL); |
michael@0 | 136 | |
michael@0 | 137 | // Hook into plugin crash events |
michael@0 | 138 | Services.obs.addObserver(testObserver, "crash-report-status", true); |
michael@0 | 139 | document.addEventListener("PluginCrashed", onPluginCrashed, false); |
michael@0 | 140 | |
michael@0 | 141 | var pluginElement = document.getElementById("plugin1"); |
michael@0 | 142 | try { |
michael@0 | 143 | pluginElement.hang(); |
michael@0 | 144 | } catch (e) { |
michael@0 | 145 | } |
michael@0 | 146 | } |
michael@0 | 147 | ]]> |
michael@0 | 148 | </script> |
michael@0 | 149 | </window> |