From 2a6c021c1ff4d2da6d036716cbe260a328ab14a4 Mon Sep 17 00:00:00 2001 From: Dave Townsend Date: Wed, 3 Nov 2010 11:21:04 -0700 Subject: [PATCH] Bug 608680: Throw an exception if illegal arguments are passed to InstallTrigger.install. r=Unfocused, a=blocks-betaN --- .../extensions/content/extensions-content.js | 5 +++- .../extensions/test/xpinstall/Makefile.in | 1 + .../test/xpinstall/browser_badargs.js | 23 +++++++++++++++++++ 3 files changed, 28 insertions(+), 1 deletion(-) create mode 100644 toolkit/mozapps/extensions/test/xpinstall/browser_badargs.js diff --git a/toolkit/mozapps/extensions/content/extensions-content.js b/toolkit/mozapps/extensions/content/extensions-content.js index 9057552ee6ee..b947c52fd5b5 100644 --- a/toolkit/mozapps/extensions/content/extensions-content.js +++ b/toolkit/mozapps/extensions/content/extensions-content.js @@ -93,6 +93,9 @@ InstallTrigger.prototype = { * @see amIInstallTriggerInstaller.idl */ install: function(aArgs, aCallback) { + if (!aArgs || typeof aArgs != "object") + throw new Error("Incorrect arguments passed to InstallTrigger.install()"); + var params = { installerId: this.installerId, mimetype: "application/x-xpinstall", @@ -250,7 +253,7 @@ InstallTriggerManager.prototype = { * @return The callback ID, an integer identifying this callback. */ addCallback: function(aCallback, aUrls) { - if (!aCallback) + if (!aCallback || typeof aCallback != "function") return -1; var callbackId = 0; while (callbackId in this.callbacks) diff --git a/toolkit/mozapps/extensions/test/xpinstall/Makefile.in b/toolkit/mozapps/extensions/test/xpinstall/Makefile.in index f5e658d3fd4c..d4f17b359403 100644 --- a/toolkit/mozapps/extensions/test/xpinstall/Makefile.in +++ b/toolkit/mozapps/extensions/test/xpinstall/Makefile.in @@ -92,6 +92,7 @@ _BROWSER_FILES = head.js \ browser_httphash3.js \ browser_httphash4.js \ browser_httphash5.js \ + browser_badargs.js \ unsigned.xpi \ signed.xpi \ signed2.xpi \ diff --git a/toolkit/mozapps/extensions/test/xpinstall/browser_badargs.js b/toolkit/mozapps/extensions/test/xpinstall/browser_badargs.js new file mode 100644 index 000000000000..f24a69bfe8cf --- /dev/null +++ b/toolkit/mozapps/extensions/test/xpinstall/browser_badargs.js @@ -0,0 +1,23 @@ +// ---------------------------------------------------------------------------- +// Test whether passing a simple string to InstallTrigger.install throws an +// exception +function test() { + waitForExplicitFinish(); + + var triggers = encodeURIComponent(JSON.stringify(TESTROOT + "unsigned.xpi")); + gBrowser.selectedTab = gBrowser.addTab(); + gBrowser.selectedBrowser.addEventListener("load", function() { + gBrowser.selectedBrowser.removeEventListener("load", arguments.callee, true); + // Allow the in-page load handler to run first + executeSoon(page_loaded); + }, true); + gBrowser.loadURI(TESTROOT + "installtrigger.html?" + triggers); +} + +function page_loaded() { + var doc = gBrowser.contentDocument; + is(doc.getElementById("return").textContent, "exception", "installTrigger should have failed"); + gBrowser.removeCurrentTab(); + finish(); +} +// ----------------------------------------------------------------------------