From 1066e91218885ad5ffc6329911b65116f04fbe1c Mon Sep 17 00:00:00 2001 From: Paolo Amadini Date: Tue, 11 Jan 2011 09:47:53 -0800 Subject: [PATCH] Bug 610661: Pass Addon object to custom about dialogs. r+a=dtownsend --HG-- rename : toolkit/mozapps/extensions/test/browser/addon_prefs.xul => toolkit/mozapps/extensions/test/browser/addon_about.xul --- .../mozapps/extensions/content/extensions.js | 2 +- .../extensions/test/browser/Makefile.in | 2 + .../extensions/test/browser/addon_about.xul | 6 ++ .../extensions/test/browser/browser_about.js | 81 +++++++++++++++++++ 4 files changed, 90 insertions(+), 1 deletion(-) create mode 100644 toolkit/mozapps/extensions/test/browser/addon_about.xul create mode 100644 toolkit/mozapps/extensions/test/browser/browser_about.js diff --git a/toolkit/mozapps/extensions/content/extensions.js b/toolkit/mozapps/extensions/content/extensions.js index 0dd7544d00c..2d0a06b08d5 100644 --- a/toolkit/mozapps/extensions/content/extensions.js +++ b/toolkit/mozapps/extensions/content/extensions.js @@ -887,7 +887,7 @@ var gViewController = { doCommand: function(aAddon) { var aboutURL = aAddon.aboutURL; if (aboutURL) - openDialog(aboutURL, "", "chrome,centerscreen,modal"); + openDialog(aboutURL, "", "chrome,centerscreen,modal", aAddon); else openDialog("chrome://mozapps/content/extensions/about.xul", "", "chrome,centerscreen,modal", aAddon); diff --git a/toolkit/mozapps/extensions/test/browser/Makefile.in b/toolkit/mozapps/extensions/test/browser/Makefile.in index d09a0b4decb..98a51d0a603 100644 --- a/toolkit/mozapps/extensions/test/browser/Makefile.in +++ b/toolkit/mozapps/extensions/test/browser/Makefile.in @@ -47,6 +47,7 @@ include $(DEPTH)/config/autoconf.mk _MAIN_TEST_FILES = \ head.js \ + browser_about.js \ browser_bug557943.js \ browser_bug562797.js \ browser_bug562890.js \ @@ -89,6 +90,7 @@ _TEST_FILES = \ $(NULL) _TEST_RESOURCES = \ + addon_about.xul \ addon_prefs.xul \ browser_bug557956.rdf \ browser_bug557956_8_2.xpi \ diff --git a/toolkit/mozapps/extensions/test/browser/addon_about.xul b/toolkit/mozapps/extensions/test/browser/addon_about.xul new file mode 100644 index 00000000000..c2b8b935eaa --- /dev/null +++ b/toolkit/mozapps/extensions/test/browser/addon_about.xul @@ -0,0 +1,6 @@ + + + + diff --git a/toolkit/mozapps/extensions/test/browser/browser_about.js b/toolkit/mozapps/extensions/test/browser/browser_about.js new file mode 100644 index 00000000000..5f205cca1c5 --- /dev/null +++ b/toolkit/mozapps/extensions/test/browser/browser_about.js @@ -0,0 +1,81 @@ +/* Any copyright is dedicated to the Public Domain. + * http://creativecommons.org/publicdomain/zero/1.0/ + */ + +/** + * Tests the default and custom "about" dialogs of add-ons. + * + * Test for bug 610661 : + * Addon object not passed to custom about dialogs. + */ + +var gManagerWindow; + +const URI_ABOUT_DEFAULT = "chrome://mozapps/content/extensions/about.xul"; +const URI_ABOUT_CUSTOM = CHROMEROOT + "addon_about.xul"; + +function test() { + requestLongerTimeout(2); + + waitForExplicitFinish(); + + var gProvider = new MockProvider(); + gProvider.createAddons([{ + id: "test1@tests.mozilla.org", + name: "Test add-on 1", + description: "foo" + }, + { + id: "test2@tests.mozilla.org", + name: "Test add-on 2", + description: "bar", + aboutURL: URI_ABOUT_CUSTOM + }]); + + open_manager("addons://list/extension", function(aManager) { + gManagerWindow = aManager; + + test_about_window("Test add-on 1", URI_ABOUT_DEFAULT, function() { + test_about_window("Test add-on 2", URI_ABOUT_CUSTOM, function() { + close_manager(gManagerWindow, finish); + }); + }); + }); +} + +function test_about_window(aAddonItemName, aExpectedAboutUri, aCallback) { + var addonList = gManagerWindow.document.getElementById("addon-list"); + for (var i = 0; i < addonList.childNodes.length; i++) { + var addonItem = addonList.childNodes[i]; + if (addonItem.hasAttribute("name") && + addonItem.getAttribute("name") === aAddonItemName) + break; + } + + Services.ww.registerNotification(function TEST_ww_observer(aSubject, aTopic, + aData) { + if (aTopic == "domwindowclosed") { + Services.ww.unregisterNotification(TEST_ww_observer); + // Give the window a chance to finish closing before continuing. + executeSoon(aCallback); + } else if (aTopic == "domwindowopened") { + let win = aSubject.QueryInterface(Ci.nsIDOMEventTarget); + win.addEventListener("load", function TEST_ww_onLoad() { + + is(win.location, + aExpectedAboutUri, + "The correct add-on about window should have opened"); + + is(win.arguments && win.arguments[0] && win.arguments[0].name, + aAddonItemName, + "window.arguments[0] should refer to the add-on object"); + + win.removeEventListener("load", TEST_ww_onLoad, false); + win.close(); + }, false); + } + }); + + gManagerWindow.gViewController.doCommand("cmd_showItemAbout", + addonItem.mAddon); +}