From 6ac643be3c3ef9787767405a9270509e23c3169f Mon Sep 17 00:00:00 2001 From: Connor Date: Wed, 22 Oct 2014 00:41:32 -0400 Subject: [PATCH] Bug 1045100 - This is 1 of 2 patches. This patch implements on the front end the new "PluginCrashedEvent" WebIDL binding. r=gfritzsche,mconley --- .../browser_globalplugin_crashinfobar.js | 27 +++++++---------- .../browser_pluginCrashCommentAndURL.js | 4 +-- browser/modules/PluginContent.jsm | 30 +++++-------------- dom/plugins/test/mochitest/hang_test.js | 19 ++++++------ .../test/mochitest/test_crash_notify.xul | 19 ++++++------ .../mochitest/test_crash_notify_no_report.xul | 12 ++++---- dom/plugins/test/mochitest/test_hangui.xul | 20 ++++++------- 7 files changed, 53 insertions(+), 78 deletions(-) diff --git a/browser/base/content/test/plugins/browser_globalplugin_crashinfobar.js b/browser/base/content/test/plugins/browser_globalplugin_crashinfobar.js index 68778dacf081..49e11cd86cdc 100644 --- a/browser/base/content/test/plugins/browser_globalplugin_crashinfobar.js +++ b/browser/base/content/test/plugins/browser_globalplugin_crashinfobar.js @@ -4,11 +4,13 @@ let gTestBrowser = null; -let propBagProperties = { +let crashedEventProperties = { pluginName: "GlobalTestPlugin", pluginDumpID: "1234", browserDumpID: "5678", - submittedCrashReport: false + submittedCrashReport: false, + bubbles: true, + cancelable: true } // Test that plugin crash submissions still work properly after @@ -34,15 +36,9 @@ function onPageLoad() { function generateCrashEvent() { let window = gTestBrowser.contentWindow; - let propBag = Cc["@mozilla.org/hash-property-bag;1"] - .createInstance(Ci.nsIWritablePropertyBag); - for (let [name, val] of Iterator(propBagProperties)) { - propBag.setProperty(name, val); - } + let crashedEvent = new window.PluginCrashedEvent("PluginCrashed", crashedEventProperties); - let event = window.document.createEvent("CustomEvent"); - event.initCustomEvent("PluginCrashed", true, true, propBag); - window.dispatchEvent(event); + window.dispatchEvent(crashedEvent); } @@ -50,13 +46,10 @@ function onCrash(event) { let target = event.target; is (target, gTestBrowser.contentWindow, "Event target is the window."); - let propBag = event.detail.QueryInterface(Ci.nsIPropertyBag2); - for (let [name, val] of Iterator(propBagProperties)) { - let type = typeof val; - let propVal = type == "string" - ? propBag.getPropertyAsAString(name) - : propBag.getPropertyAsBool(name); - is (propVal, val, "Correct property in detail propBag: " + name + "."); + for (let [name, val] of Iterator(crashedEventProperties)) { + let propVal = event[name]; + + is (propVal, val, "Correct property: " + name + "."); } waitForNotificationBar("plugin-crashed", gTestBrowser, (notification) => { diff --git a/browser/base/content/test/plugins/browser_pluginCrashCommentAndURL.js b/browser/base/content/test/plugins/browser_pluginCrashCommentAndURL.js index 216878a21ceb..ac7ec5581166 100644 --- a/browser/base/content/test/plugins/browser_pluginCrashCommentAndURL.js +++ b/browser/base/content/test/plugins/browser_pluginCrashCommentAndURL.js @@ -57,10 +57,8 @@ function frameScript() { } if (message.data.sendCrashMessage) { - let propBag = event.detail.QueryInterface(Ci.nsIPropertyBag2); - let crashID = propBag.getPropertyAsAString("pluginDumpID"); sendAsyncMessage("test:crash-plugin:crashed", { - crashID: crashID, + crashID: event.pluginDumpID, }); return; } diff --git a/browser/modules/PluginContent.jsm b/browser/modules/PluginContent.jsm index 1fa45185876a..7634040fa080 100644 --- a/browser/modules/PluginContent.jsm +++ b/browser/modules/PluginContent.jsm @@ -849,30 +849,16 @@ PluginContent.prototype = { // Crashed-plugin event listener. Called for every instance of a // plugin in content. pluginInstanceCrashed: function (target, aEvent) { - // Ensure the plugin and event are of the right type. - if (!(aEvent instanceof Ci.nsIDOMCustomEvent)) + if (!(aEvent instanceof this.content.PluginCrashedEvent)) return; - let propBag = aEvent.detail.QueryInterface(Ci.nsIPropertyBag2); - let submittedReport = propBag.getPropertyAsBool("submittedCrashReport"); - let doPrompt = true; // XXX followup for .getPropertyAsBool("doPrompt"); - let submitReports = true; // XXX followup for .getPropertyAsBool("submitReports"); - let pluginName = propBag.getPropertyAsAString("pluginName"); - let pluginDumpID = propBag.getPropertyAsAString("pluginDumpID"); - let browserDumpID = null; - let gmpPlugin = false; - - try { - browserDumpID = propBag.getPropertyAsAString("browserDumpID"); - } catch (e) { - // For GMP crashes we don't get a browser dump. - } - - try { - gmpPlugin = propBag.getPropertyAsBool("gmpPlugin"); - } catch (e) { - // This property is only set for GMP plugins. - } + let submittedReport = aEvent.submittedCrashReport; + let doPrompt = true; // XXX followup for aEvent.doPrompt; + let submitReports = true; // XXX followup for aEvent.submitReports; + let pluginName = aEvent.pluginName; + let pluginDumpID = aEvent.pluginDumpID; + let browserDumpID = aEvent.browserDumpID; + let gmpPlugin = aEvent.gmpPlugin; // For non-GMP plugins, remap the plugin name to a more user-presentable form. if (!gmpPlugin) { diff --git a/dom/plugins/test/mochitest/hang_test.js b/dom/plugins/test/mochitest/hang_test.js index 6beeeb14412c..aabd65f0e3e2 100644 --- a/dom/plugins/test/mochitest/hang_test.js +++ b/dom/plugins/test/mochitest/hang_test.js @@ -92,20 +92,19 @@ function onPluginCrashed(aEvent) { var pluginElement = document.getElementById("plugin1"); is (pluginElement, aEvent.target, "Plugin crashed event target is plugin element"); - ok(aEvent instanceof Ci.nsIDOMCustomEvent, + ok(aEvent instanceof PluginCrashedEvent, "plugin crashed event has the right interface"); - var propBag = aEvent.detail.QueryInterface(Ci.nsIPropertyBag2); - var pluginDumpID = propBag.getPropertyAsAString("pluginDumpID"); - isnot(pluginDumpID, "", "got a non-empty dump ID"); - var pluginName = propBag.getPropertyAsAString("pluginName"); - is(pluginName, "Test Plug-in", "got correct plugin name"); - var pluginFilename = propBag.getPropertyAsAString("pluginFilename"); - isnot(pluginFilename, "", "got a non-empty filename"); - var didReport = propBag.getPropertyAsBool("submittedCrashReport"); + is(typeof aEvent.pluginDumpID, "string", "pluginDumpID is correct type"); + isnot(aEvent.pluginDumpID, "", "got a non-empty dump ID"); + is(typeof aEvent.pluginName, "string", "pluginName is correct type"); + is(aEvent.pluginName, "Test Plug-in", "got correct plugin name"); + is(typeof aEvent.pluginFilename, "string", "pluginFilename is correct type"); + isnot(aEvent.pluginFilename, "", "got a non-empty filename"); // The app itself may or may not have decided to submit the report, so // allow either true or false here. - ok((didReport == true || didReport == false), "event said crash report was submitted"); + ok("submittedCrashReport" in aEvent, "submittedCrashReport is a property of event"); + is(typeof aEvent.submittedCrashReport, "boolean", "submittedCrashReport is correct type"); var os = Cc["@mozilla.org/observer-service;1"]. getService(Ci.nsIObserverService); diff --git a/dom/plugins/test/mochitest/test_crash_notify.xul b/dom/plugins/test/mochitest/test_crash_notify.xul index ce5f3b040c7d..d33c58ffa51a 100644 --- a/dom/plugins/test/mochitest/test_crash_notify.xul +++ b/dom/plugins/test/mochitest/test_crash_notify.xul @@ -66,20 +66,19 @@ function onPluginCrashed(aEvent) { var pluginElement = document.getElementById("plugin1"); is (pluginElement, aEvent.target, "Plugin crashed event target is plugin element"); - ok(aEvent instanceof Components.interfaces.nsIDOMCustomEvent, + ok(aEvent instanceof PluginCrashedEvent, "plugin crashed event has the right interface"); - var propBag = aEvent.detail.QueryInterface(Components.interfaces.nsIPropertyBag2); - var pluginDumpID = propBag.getPropertyAsAString("pluginDumpID"); - isnot(pluginDumpID, "", "got a non-empty dump ID"); - var pluginName = propBag.getPropertyAsAString("pluginName"); - is(pluginName, "Test Plug-in", "got correct plugin name"); - var pluginFilename = propBag.getPropertyAsAString("pluginFilename"); - isnot(pluginFilename, "", "got a non-empty filename"); - var didReport = propBag.getPropertyAsBool("submittedCrashReport"); + is(typeof aEvent.pluginDumpID, "string", "pluginDumpID is correct type"); + isnot(aEvent.pluginDumpID, "", "got a non-empty dump ID"); + is(typeof aEvent.pluginName, "string", "pluginName is correct type"); + is(aEvent.pluginName, "Test Plug-in", "got correct plugin name"); + is(typeof aEvent.pluginFilename, "string", "pluginFilename is correct type"); + isnot(aEvent.pluginFilename, "", "got a non-empty filename"); // The app itself may or may not have decided to submit the report, so // allow either true or false here. - ok((didReport == true || didReport == false), "event said crash report was submitted"); + ok("submittedCrashReport" in aEvent, "submittedCrashReport is a property of event"); + is(typeof aEvent.submittedCrashReport, "boolean", "submittedCrashReport is correct type"); var os = Components.classes["@mozilla.org/observer-service;1"]. getService(Components.interfaces.nsIObserverService); diff --git a/dom/plugins/test/mochitest/test_crash_notify_no_report.xul b/dom/plugins/test/mochitest/test_crash_notify_no_report.xul index 0b5c914259c7..154de8e60c79 100644 --- a/dom/plugins/test/mochitest/test_crash_notify_no_report.xul +++ b/dom/plugins/test/mochitest/test_crash_notify_no_report.xul @@ -69,15 +69,15 @@ function onPluginCrashed(aEvent) { var pluginElement = document.getElementById("plugin1"); is (pluginElement, aEvent.target, "Plugin crashed event target is plugin element"); - ok(aEvent instanceof Components.interfaces.nsIDOMCustomEvent, + ok(aEvent instanceof PluginCrashedEvent, "plugin crashed event has the right interface"); - var propBag = aEvent.detail.QueryInterface(Components.interfaces.nsIPropertyBag2); - var pluginName = propBag.getPropertyAsAString("pluginName"); - is(pluginName, "Test Plug-in"); - var didReport = propBag.getPropertyAsBool("submittedCrashReport"); + + is(typeof aEvent.pluginName, "string", "pluginName is correct type"); + is(aEvent.pluginName, "Test Plug-in"); // The app itself may or may not have decided to submit the report, so // allow either true or false here. - ok((didReport == true || didReport == false), "event said crash report was submitted"); + ok("submittedCrashReport" in aEvent, "submittedCrashReport is a property of event"); + is(typeof aEvent.submittedCrashReport, "boolean", "submittedCrashReport is correct type"); var os = Components.classes["@mozilla.org/observer-service;1"]. getService(Components.interfaces.nsIObserverService); diff --git a/dom/plugins/test/mochitest/test_hangui.xul b/dom/plugins/test/mochitest/test_hangui.xul index aa04b2766043..9c301f499815 100644 --- a/dom/plugins/test/mochitest/test_hangui.xul +++ b/dom/plugins/test/mochitest/test_hangui.xul @@ -117,20 +117,20 @@ function onPluginCrashedHangUI(aEvent) { is(p, aEvent.target, "Plugin crashed event target is plugin element"); - ok(aEvent instanceof Components.interfaces.nsIDOMCustomEvent, + ok(aEvent instanceof PluginCrashedEvent, "plugin crashed event has the right interface"); - var propBag = aEvent.detail.QueryInterface(Components.interfaces.nsIPropertyBag2); - var pluginDumpID = propBag.getPropertyAsAString("pluginDumpID"); - isnot(pluginDumpID, "", "got a non-empty dump ID"); - var pluginName = propBag.getPropertyAsAString("pluginName"); - is(pluginName, "Test Plug-in", "got correct plugin name"); - var pluginFilename = propBag.getPropertyAsAString("pluginFilename"); - isnot(pluginFilename, "", "got a non-empty filename"); - var didReport = propBag.getPropertyAsBool("submittedCrashReport"); + is(typeof aEvent.pluginDumpID, "string", "pluginDumpID is correct type"); + isnot(aEvent.pluginDumpID, "", "got a non-empty dump ID"); + is(typeof aEvent.pluginName, "string", "pluginName is correct type"); + is(aEvent.pluginName, "Test Plug-in", "got correct plugin name"); + is(typeof aEvent.pluginFilename, "string", "pluginFilename is correct type"); + isnot(aEvent.pluginFilename, "", "got a non-empty filename"); // The app itself may or may not have decided to submit the report, so // allow either true or false here. - ok((didReport == true || didReport == false), "event said crash report was submitted"); + ok("submittedCrashReport" in aEvent, "submittedCrashReport is a property of event"); + is(typeof aEvent.submittedCrashReport, "boolean", "submittedCrashReport is correct type"); + os.removeObserver(testObserver, "plugin-crashed"); --obsCount; }