1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/dom/plugins/test/mochitest/test_crash_submit.xul Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,129 @@ 1.4 +<?xml version="1.0"?> 1.5 +<?xml-stylesheet href="chrome://global/skin" type="text/css"?> 1.6 +<?xml-stylesheet href="chrome://mochikit/content/tests/SimpleTest/test.css" 1.7 + type="text/css"?> 1.8 +<window title="Basic Plugin Tests" 1.9 + xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"> 1.10 + <script type="application/javascript" 1.11 + src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js" /> 1.12 + <script type="application/javascript" 1.13 + src="chrome://mochikit/content/tests/SimpleTest/EventUtils.js" /> 1.14 + <script type="application/javascript" src="utils.js"></script> 1.15 + <script type="application/javascript"> 1.16 + setTestPluginEnabledState(SpecialPowers.Ci.nsIPluginTag.STATE_ENABLED); 1.17 + </script> 1.18 +<body xmlns="http://www.w3.org/1999/xhtml" onload="runTests()"> 1.19 +<embed id="plugin1" type="application/x-test" width="200" height="200"></embed> 1.20 +</body> 1.21 +<script class="testbody" type="application/javascript"> 1.22 +<![CDATA[ 1.23 +SimpleTest.waitForExplicitFinish(); 1.24 +SimpleTest.ignoreAllUncaughtExceptions(); 1.25 + 1.26 +Components.utils.import("resource://gre/modules/NetUtil.jsm"); 1.27 +Components.utils.import("resource://gre/modules/Services.jsm"); 1.28 + 1.29 +var crashReporter = 1.30 + Components.classes["@mozilla.org/toolkit/crash-reporter;1"] 1.31 + .getService(Components.interfaces.nsICrashReporter); 1.32 +var oldServerURL = crashReporter.serverURL; 1.33 + 1.34 +const SERVER_URL = "http://example.com/browser/toolkit/crashreporter/test/browser/crashreport.sjs"; 1.35 + 1.36 +var testObserver = { 1.37 + observe: function(subject, topic, data) { 1.38 + if (data == "submitting") // not done yet 1.39 + return; 1.40 + is(data, "success", "report should have been submitted successfully"); 1.41 + is(topic, "crash-report-status", "Checking correct topic"); 1.42 + ok(subject instanceof Components.interfaces.nsIPropertyBag2, 1.43 + "Subject should be a property bag"); 1.44 + ok(subject.hasKey("serverCrashID"), "Should have a server crash ID"); 1.45 + let crashid = subject.getPropertyAsAString("serverCrashID"); 1.46 + isnot(crashid, "", "Server crash ID should not be an empty string"); 1.47 + 1.48 + // Verify the data. The SJS script will return the data that was POSTed 1.49 + let req = new XMLHttpRequest(); 1.50 + req.open("GET", SERVER_URL + "?id=" + crashid, false); 1.51 + req.send(null); 1.52 + is(req.status, 200, "Server response should be 200 OK"); 1.53 + let submitted = JSON.parse(req.responseText); 1.54 + ok(!("Throttleable" in submitted), "Submit request should not be Throttleable"); 1.55 + is(submitted.ProcessType, "plugin", "Should specify ProcessType=plugin"); 1.56 + 1.57 + // Cleanup 1.58 + // First remove our fake submitted report 1.59 + let file = Services.dirsvc.get("UAppData", Components.interfaces.nsILocalFile); 1.60 + file.append("Crash Reports"); 1.61 + file.append("submitted"); 1.62 + file.append(crashid + ".txt"); 1.63 + file.remove(false); 1.64 + 1.65 + // Next unregister our observer 1.66 + var os = Components.classes["@mozilla.org/observer-service;1"]. 1.67 + getService(Components.interfaces.nsIObserverService); 1.68 + os.removeObserver(testObserver, "crash-report-status"); 1.69 + 1.70 + // Then re-set MOZ_CRASHREPORTER_NO_REPORT 1.71 + let env = Components.classes["@mozilla.org/process/environment;1"] 1.72 + .getService(Components.interfaces.nsIEnvironment); 1.73 + env.set("MOZ_CRASHREPORTER_NO_REPORT", "1"); 1.74 + 1.75 + // Finally re-set crashreporter URL 1.76 + crashReporter.serverURL = oldServerURL; 1.77 + SimpleTest.finish(); 1.78 + }, 1.79 + 1.80 + QueryInterface: function(iid) { 1.81 + if (iid.equals(Components.interfaces.nsIObserver) || 1.82 + iid.equals(Components.interfaces.nsISupportsWeakReference) || 1.83 + iid.equals(Components.interfaces.nsISupports)) 1.84 + return this; 1.85 + throw Components.results.NS_NOINTERFACE; 1.86 + } 1.87 +}; 1.88 + 1.89 + 1.90 +function onPluginCrashed(aEvent) { 1.91 + ok(true, "Plugin crashed notification received"); 1.92 + is(aEvent.type, "PluginCrashed", "event is correct type"); 1.93 + 1.94 + let submitButton = document.getAnonymousElementByAttribute(aEvent.target, 1.95 + "class", 1.96 + "submitButton"); 1.97 + // try to submit this report 1.98 + sendMouseEvent({type:'click'}, submitButton, window); 1.99 +} 1.100 + 1.101 +function runTests() { 1.102 + if (!SimpleTest.testPluginIsOOP()) { 1.103 + todo(false, "Skipping this test when test plugin is not OOP."); 1.104 + SimpleTest.finish(); 1.105 + return; 1.106 + } 1.107 + 1.108 + // the test harness will have set MOZ_CRASHREPORTER_NO_REPORT, 1.109 + // ensure that we can change the setting and have our minidumps 1.110 + // wind up in Crash Reports/pending 1.111 + let env = Components.classes["@mozilla.org/process/environment;1"] 1.112 + .getService(Components.interfaces.nsIEnvironment); 1.113 + env.set("MOZ_CRASHREPORTER_NO_REPORT", ""); 1.114 + 1.115 + // Override the crash reporter URL to send to our fake server 1.116 + crashReporter.serverURL = NetUtil.newURI(SERVER_URL); 1.117 + 1.118 + var os = Components.classes["@mozilla.org/observer-service;1"]. 1.119 + getService(Components.interfaces.nsIObserverService); 1.120 + os.addObserver(testObserver, "crash-report-status", true); 1.121 + 1.122 + document.addEventListener("PluginCrashed", onPluginCrashed, false); 1.123 + 1.124 + var pluginElement = document.getElementById("plugin1"); 1.125 + try { 1.126 + pluginElement.crash(); 1.127 + } catch (e) { 1.128 + } 1.129 +} 1.130 +]]> 1.131 +</script> 1.132 +</window>