Bug 610661: Pass Addon object to custom about dialogs. r+a=dtownsend
authorPaolo Amadini <paolo.02.prg@amadzone.org>
Tue, 11 Jan 2011 09:47:53 -0800
changeset 60304 e30ee0ae39b6a0f28289501005a98ddd3d8dcf03
parent 60303 286f71fe6a2ee5f240ab3a820ad55657bd4bceee
child 60305 3844d838d24afbe1312f0060f31aee3e27b30864
push idunknown
push userunknown
push dateunknown
bugs610661
milestone2.0b10pre
Bug 610661: Pass Addon object to custom about dialogs. r+a=dtownsend
toolkit/mozapps/extensions/content/extensions.js
toolkit/mozapps/extensions/test/browser/Makefile.in
toolkit/mozapps/extensions/test/browser/addon_about.xul
toolkit/mozapps/extensions/test/browser/browser_about.js
--- a/toolkit/mozapps/extensions/content/extensions.js
+++ b/toolkit/mozapps/extensions/content/extensions.js
@@ -882,17 +882,17 @@ var gViewController = {
     cmd_showItemAbout: {
       isEnabled: function(aAddon) {
         // XXXunf This may be applicable to install items too. See bug 561260
         return !!aAddon;
       },
       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);
       }
     },
 
     cmd_enableItem: {
       isEnabled: function(aAddon) {
--- a/toolkit/mozapps/extensions/test/browser/Makefile.in
+++ b/toolkit/mozapps/extensions/test/browser/Makefile.in
@@ -42,16 +42,17 @@ VPATH = @srcdir@
 relativesrcdir  = toolkit/mozapps/extensions/test/browser
 ADDONSRC = $(srcdir)/addons
 TESTXPI = $(CURDIR)/$(DEPTH)/_tests/testing/mochitest/browser/$(relativesrcdir)/addons
 
 include $(DEPTH)/config/autoconf.mk
 
 _MAIN_TEST_FILES = \
   head.js \
+  browser_about.js \
   browser_bug557943.js \
   browser_bug562797.js \
   browser_bug562890.js \
   browser_bug562899.js \
   browser_bug562992.js \
   browser_bug567127.js \
   browser_bug567137.js \
   browser_bug572561.js \
@@ -84,16 +85,17 @@ include $(DEPTH)/config/autoconf.mk
 _TEST_FILES = \
   head.js \
   browser_bug557956.js \
   browser_updatessl.js \
   browser_installssl.js \
   $(NULL)
 
 _TEST_RESOURCES = \
+  addon_about.xul \
   addon_prefs.xul \
   browser_bug557956.rdf \
   browser_bug557956_8_2.xpi \
   browser_bug557956_9_2.xpi \
   browser_bug591465.xml \
   browser_bug593535.xml \
   browser_searching.xml \
   browser_searching_empty.xml \
copy from toolkit/mozapps/extensions/test/browser/addon_prefs.xul
copy to toolkit/mozapps/extensions/test/browser/addon_about.xul
--- a/toolkit/mozapps/extensions/test/browser/addon_prefs.xul
+++ b/toolkit/mozapps/extensions/test/browser/addon_about.xul
@@ -1,6 +1,6 @@
 <?xml version="1.0"?>
 <?xml-stylesheet href="chrome://global/skin/" type="text/css"?>
 <window xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
-        id="addon-test-pref-window">
+        id="addon-test-about-window">
   <label value="Oh hai!"/>
 </window>
new file mode 100644
--- /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 <https://bugzilla.mozilla.org/show_bug.cgi?id=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);
+}