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