toolkit/mozapps/extensions/test/browser/browser_recentupdates.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_recentupdates.js	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,125 @@
     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 +// Tests the recent updates pane
     1.9 +
    1.10 +var gProvider;
    1.11 +var gManagerWindow;
    1.12 +var gCategoryUtilities;
    1.13 +
    1.14 +function test() {
    1.15 +  waitForExplicitFinish();
    1.16 +
    1.17 +  gProvider = new MockProvider();
    1.18 +
    1.19 +  gProvider.createAddons([{
    1.20 +    id: "addon1@tests.mozilla.org",
    1.21 +    name: "updated 6 hours ago",
    1.22 +    version: "1.0",
    1.23 +    updateDate: new Date(Date.now() - (1000 * 60 * 60 * 6)),
    1.24 +    releaseNotesURI: Services.io.newURI(TESTROOT + "releaseNotes.xhtml", null, null)
    1.25 +  }, {
    1.26 +    id: "addon2@tests.mozilla.org",
    1.27 +    name: "updated 5 seconds ago",
    1.28 +    version: "1.0",
    1.29 +    updateDate: new Date(Date.now() - (1000 * 5))
    1.30 +  }, {
    1.31 +    id: "addon3@tests.mozilla.org",
    1.32 +    name: "updated 1 month ago",
    1.33 +    version: "1.0",
    1.34 +    updateDate: new Date(Date.now() - (1000 * 60 * 60 * 25 * 30))
    1.35 +  }]);
    1.36 +  
    1.37 +  open_manager("addons://list/extension", function(aWindow) {
    1.38 +    gManagerWindow = aWindow;
    1.39 +    gCategoryUtilities = new CategoryUtilities(gManagerWindow);
    1.40 +    run_next_test();
    1.41 +  });
    1.42 +}
    1.43 +
    1.44 +function end_test() {
    1.45 +  close_manager(gManagerWindow, function() {
    1.46 +    finish();
    1.47 +  });
    1.48 +}
    1.49 +
    1.50 +
    1.51 +add_test(function() {
    1.52 +  info("Checking menuitem for Recent Updates opens that pane");
    1.53 +  var recentCat = gManagerWindow.gCategories.get("addons://updates/recent");
    1.54 +  is(gCategoryUtilities.isVisible(recentCat), false, "Recent Updates category should initially be hidden");
    1.55 +
    1.56 +  var utilsBtn = gManagerWindow.document.getElementById("header-utils-btn");
    1.57 +  utilsBtn.addEventListener("popupshown", function() {
    1.58 +    utilsBtn.removeEventListener("popupshown", arguments.callee, false);
    1.59 +    wait_for_view_load(gManagerWindow, function() {
    1.60 +      is(gCategoryUtilities.isVisible(recentCat), true, "Recent Updates category should now be visible");
    1.61 +      is(gManagerWindow.document.getElementById("categories").selectedItem.value, "addons://updates/recent", "Recent Updates category should now be selected");
    1.62 +      is(gManagerWindow.gViewController.currentViewId, "addons://updates/recent", "Recent Updates view should be the current view");
    1.63 +      run_next_test();
    1.64 +    }, true);
    1.65 +    var menuitem = gManagerWindow.document.getElementById("utils-viewUpdates");
    1.66 +    EventUtils.synthesizeMouse(menuitem, 2, 2, { }, gManagerWindow);
    1.67 +  }, false);
    1.68 +  EventUtils.synthesizeMouse(utilsBtn, 2, 2, { }, gManagerWindow);
    1.69 +});
    1.70 +
    1.71 +
    1.72 +add_test(function() {
    1.73 +  var updatesList = gManagerWindow.document.getElementById("updates-list");
    1.74 +  var sorters = gManagerWindow.document.getElementById("updates-sorters");
    1.75 +  var dateSorter = gManagerWindow.document.getAnonymousElementByAttribute(sorters, "anonid", "date-btn");
    1.76 +  var nameSorter = gManagerWindow.document.getAnonymousElementByAttribute(sorters, "anonid", "name-btn");
    1.77 +
    1.78 +  function check_order(expected) {
    1.79 +    var items = updatesList.getElementsByTagName("richlistitem");
    1.80 +    var possible = ["addon1@tests.mozilla.org", "addon2@tests.mozilla.org", "addon3@tests.mozilla.org"];
    1.81 +    for (let item of items) {
    1.82 +      let itemId = item.mAddon.id;
    1.83 +      if (possible.indexOf(itemId) == -1)
    1.84 +        continue; // skip over any other addons, such as shipped addons that would update on every build
    1.85 +      isnot(expected.length, 0, "Should be expecting more items");
    1.86 +      is(itemId, expected.shift(), "Should get expected item based on sort order");
    1.87 +      if (itemId == "addon1@tests.mozilla.org")
    1.88 +        is_element_visible(item._relNotesToggle, "Release notes toggle should be visible for addon with release notes");
    1.89 +      else
    1.90 +        is_element_hidden(item._relNotesToggle, "Release notes toggle should be hidden for addon with no release notes");
    1.91 +    }
    1.92 +  }
    1.93 +
    1.94 +  is_element_visible(dateSorter);
    1.95 +  is_element_visible(nameSorter);
    1.96 +
    1.97 +  // sorted by date, descending
    1.98 +  check_order(["addon2@tests.mozilla.org", "addon1@tests.mozilla.org"]);
    1.99 +
   1.100 +  // sorted by date, ascending
   1.101 +  EventUtils.synthesizeMouseAtCenter(dateSorter, { }, gManagerWindow);
   1.102 +  check_order(["addon1@tests.mozilla.org", "addon2@tests.mozilla.org"]);
   1.103 +
   1.104 +  // sorted by name, ascending
   1.105 +  EventUtils.synthesizeMouseAtCenter(nameSorter, { }, gManagerWindow);
   1.106 +  check_order(["addon2@tests.mozilla.org", "addon1@tests.mozilla.org"]);
   1.107 +
   1.108 +  // sorted by name, descending
   1.109 +  EventUtils.synthesizeMouseAtCenter(nameSorter, { }, gManagerWindow);
   1.110 +  check_order(["addon1@tests.mozilla.org", "addon2@tests.mozilla.org"]);
   1.111 +
   1.112 +  run_next_test();
   1.113 +});
   1.114 +
   1.115 +
   1.116 +add_test(function() {
   1.117 +  close_manager(gManagerWindow, function() {
   1.118 +    open_manager(null, function(aWindow) {
   1.119 +      gManagerWindow = aWindow;
   1.120 +      gCategoryUtilities = new CategoryUtilities(gManagerWindow);
   1.121 +
   1.122 +      var recentCat = gManagerWindow.gCategories.get("addons://updates/recent");
   1.123 +      is(gCategoryUtilities.isVisible(recentCat), true, "Recent Updates category should still be visible");
   1.124 +
   1.125 +      run_next_test();
   1.126 +    });
   1.127 +  });
   1.128 +});

mercurial