toolkit/mozapps/extensions/test/browser/browser_about.js

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/toolkit/mozapps/extensions/test/browser/browser_about.js	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,84 @@
     1.4 +/* Any copyright is dedicated to the Public Domain.
     1.5 + * http://creativecommons.org/publicdomain/zero/1.0/
     1.6 + */
     1.7 +
     1.8 +/**
     1.9 + * Tests the default and custom "about" dialogs of add-ons.
    1.10 + *
    1.11 + * Test for bug 610661 <https://bugzilla.mozilla.org/show_bug.cgi?id=610661>:
    1.12 + * Addon object not passed to custom about dialogs.
    1.13 + */
    1.14 +
    1.15 +var gManagerWindow;
    1.16 +
    1.17 +const URI_ABOUT_DEFAULT = "chrome://mozapps/content/extensions/about.xul";
    1.18 +const URI_ABOUT_CUSTOM = CHROMEROOT + "addon_about.xul";
    1.19 +
    1.20 +function test() {
    1.21 +  requestLongerTimeout(2);
    1.22 +
    1.23 +  waitForExplicitFinish();
    1.24 +
    1.25 +  var gProvider = new MockProvider();
    1.26 +  gProvider.createAddons([{
    1.27 +    id: "test1@tests.mozilla.org",
    1.28 +    name: "Test add-on 1",
    1.29 +    description: "foo"
    1.30 +  },
    1.31 +  {
    1.32 +    id: "test2@tests.mozilla.org",
    1.33 +    name: "Test add-on 2",
    1.34 +    description: "bar",
    1.35 +    aboutURL: URI_ABOUT_CUSTOM
    1.36 +  }]);
    1.37 +
    1.38 +  open_manager("addons://list/extension", function(aManager) {
    1.39 +    gManagerWindow = aManager;
    1.40 +
    1.41 +    test_about_window("Test add-on 1", URI_ABOUT_DEFAULT, function() {
    1.42 +      test_about_window("Test add-on 2", URI_ABOUT_CUSTOM, function() {
    1.43 +        close_manager(gManagerWindow, finish);
    1.44 +      });
    1.45 +    });
    1.46 +  });
    1.47 +}
    1.48 +
    1.49 +function test_about_window(aAddonItemName, aExpectedAboutUri, aCallback) {
    1.50 +  var addonList = gManagerWindow.document.getElementById("addon-list");
    1.51 +  for (var addonItem of addonList.childNodes) {
    1.52 +    if (addonItem.hasAttribute("name") &&
    1.53 +        addonItem.getAttribute("name") === aAddonItemName)
    1.54 +      break;
    1.55 +  }
    1.56 +
    1.57 +  info("Waiting for about dialog");
    1.58 +  Services.ww.registerNotification(function TEST_ww_observer(aSubject, aTopic,
    1.59 +                                                             aData) {
    1.60 +    if (aTopic == "domwindowclosed") {
    1.61 +      Services.ww.unregisterNotification(TEST_ww_observer);
    1.62 +
    1.63 +      info("About dialog closed, waiting for focus on browser window");
    1.64 +      waitForFocus(aCallback);
    1.65 +    } else if (aTopic == "domwindowopened") {
    1.66 +      info("About dialog opened, waiting for focus");
    1.67 +
    1.68 +      let win = aSubject.QueryInterface(Ci.nsIDOMEventTarget);
    1.69 +      waitForFocus(function() {
    1.70 +        info("Saw about dialog");
    1.71 +
    1.72 +        is(win.location,
    1.73 +           aExpectedAboutUri,
    1.74 +           "The correct add-on about window should have opened");
    1.75 +
    1.76 +        is(win.arguments && win.arguments[0] && win.arguments[0].name,
    1.77 +           aAddonItemName,
    1.78 +           "window.arguments[0] should refer to the add-on object");
    1.79 +
    1.80 +        win.close();
    1.81 +      }, win);
    1.82 +    }
    1.83 +  });
    1.84 +
    1.85 +  gManagerWindow.gViewController.doCommand("cmd_showItemAbout",
    1.86 +                                           addonItem.mAddon);
    1.87 +}

mercurial