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