|
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 var crashReporter = |
|
27 Components.classes["@mozilla.org/toolkit/crash-reporter;1"] |
|
28 .getService(Components.interfaces.nsICrashReporter); |
|
29 var oldServerURL = crashReporter.serverURL; |
|
30 |
|
31 const SERVER_URL = "http://example.com/browser/toolkit/crashreporter/test/browser/crashreport.sjs"; |
|
32 |
|
33 var testObserver = { |
|
34 observe: function(subject, topic, data) { |
|
35 if (data == "submitting") // not done yet |
|
36 return; |
|
37 is(data, "success", "report should have been submitted successfully"); |
|
38 is(topic, "crash-report-status", "Checking correct topic"); |
|
39 ok(subject instanceof Components.interfaces.nsIPropertyBag2, |
|
40 "Subject should be a property bag"); |
|
41 ok(subject.hasKey("serverCrashID"), "Should have a server crash ID"); |
|
42 let crashid = subject.getPropertyAsAString("serverCrashID"); |
|
43 isnot(crashid, "", "Server crash ID should not be an empty string"); |
|
44 |
|
45 // Verify the data. The SJS script will return the data that was POSTed |
|
46 let req = new XMLHttpRequest(); |
|
47 req.open("GET", SERVER_URL + "?id=" + crashid, false); |
|
48 req.send(null); |
|
49 is(req.status, 200, "Server response should be 200 OK"); |
|
50 let submitted = JSON.parse(req.responseText); |
|
51 ok(!("Throttleable" in submitted), "Submit request should not be Throttleable"); |
|
52 is(submitted.ProcessType, "plugin", "Should specify ProcessType=plugin"); |
|
53 |
|
54 // Cleanup |
|
55 // First remove our fake submitted report |
|
56 let file = Services.dirsvc.get("UAppData", Components.interfaces.nsILocalFile); |
|
57 file.append("Crash Reports"); |
|
58 file.append("submitted"); |
|
59 file.append(crashid + ".txt"); |
|
60 file.remove(false); |
|
61 |
|
62 // Next unregister our observer |
|
63 var os = Components.classes["@mozilla.org/observer-service;1"]. |
|
64 getService(Components.interfaces.nsIObserverService); |
|
65 os.removeObserver(testObserver, "crash-report-status"); |
|
66 |
|
67 // Then re-set MOZ_CRASHREPORTER_NO_REPORT |
|
68 let env = Components.classes["@mozilla.org/process/environment;1"] |
|
69 .getService(Components.interfaces.nsIEnvironment); |
|
70 env.set("MOZ_CRASHREPORTER_NO_REPORT", "1"); |
|
71 |
|
72 // Finally re-set crashreporter URL |
|
73 crashReporter.serverURL = oldServerURL; |
|
74 SimpleTest.finish(); |
|
75 }, |
|
76 |
|
77 QueryInterface: function(iid) { |
|
78 if (iid.equals(Components.interfaces.nsIObserver) || |
|
79 iid.equals(Components.interfaces.nsISupportsWeakReference) || |
|
80 iid.equals(Components.interfaces.nsISupports)) |
|
81 return this; |
|
82 throw Components.results.NS_NOINTERFACE; |
|
83 } |
|
84 }; |
|
85 |
|
86 |
|
87 function onPluginCrashed(aEvent) { |
|
88 ok(true, "Plugin crashed notification received"); |
|
89 is(aEvent.type, "PluginCrashed", "event is correct type"); |
|
90 |
|
91 let submitButton = document.getAnonymousElementByAttribute(aEvent.target, |
|
92 "class", |
|
93 "submitButton"); |
|
94 // try to submit this report |
|
95 sendMouseEvent({type:'click'}, submitButton, window); |
|
96 } |
|
97 |
|
98 function runTests() { |
|
99 if (!SimpleTest.testPluginIsOOP()) { |
|
100 todo(false, "Skipping this test when test plugin is not OOP."); |
|
101 SimpleTest.finish(); |
|
102 return; |
|
103 } |
|
104 |
|
105 // the test harness will have set MOZ_CRASHREPORTER_NO_REPORT, |
|
106 // ensure that we can change the setting and have our minidumps |
|
107 // wind up in Crash Reports/pending |
|
108 let env = Components.classes["@mozilla.org/process/environment;1"] |
|
109 .getService(Components.interfaces.nsIEnvironment); |
|
110 env.set("MOZ_CRASHREPORTER_NO_REPORT", ""); |
|
111 |
|
112 // Override the crash reporter URL to send to our fake server |
|
113 crashReporter.serverURL = NetUtil.newURI(SERVER_URL); |
|
114 |
|
115 var os = Components.classes["@mozilla.org/observer-service;1"]. |
|
116 getService(Components.interfaces.nsIObserverService); |
|
117 os.addObserver(testObserver, "crash-report-status", true); |
|
118 |
|
119 document.addEventListener("PluginCrashed", onPluginCrashed, false); |
|
120 |
|
121 var pluginElement = document.getElementById("plugin1"); |
|
122 try { |
|
123 pluginElement.crash(); |
|
124 } catch (e) { |
|
125 } |
|
126 } |
|
127 ]]> |
|
128 </script> |
|
129 </window> |