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

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

michael@0 1 /* Any copyright is dedicated to the Public Domain.
michael@0 2 * http://creativecommons.org/publicdomain/zero/1.0/
michael@0 3 */
michael@0 4
michael@0 5 // Tests the recent updates pane
michael@0 6
michael@0 7 var gProvider;
michael@0 8 var gManagerWindow;
michael@0 9 var gCategoryUtilities;
michael@0 10
michael@0 11 function test() {
michael@0 12 waitForExplicitFinish();
michael@0 13
michael@0 14 gProvider = new MockProvider();
michael@0 15
michael@0 16 gProvider.createAddons([{
michael@0 17 id: "addon1@tests.mozilla.org",
michael@0 18 name: "updated 6 hours ago",
michael@0 19 version: "1.0",
michael@0 20 updateDate: new Date(Date.now() - (1000 * 60 * 60 * 6)),
michael@0 21 releaseNotesURI: Services.io.newURI(TESTROOT + "releaseNotes.xhtml", null, null)
michael@0 22 }, {
michael@0 23 id: "addon2@tests.mozilla.org",
michael@0 24 name: "updated 5 seconds ago",
michael@0 25 version: "1.0",
michael@0 26 updateDate: new Date(Date.now() - (1000 * 5))
michael@0 27 }, {
michael@0 28 id: "addon3@tests.mozilla.org",
michael@0 29 name: "updated 1 month ago",
michael@0 30 version: "1.0",
michael@0 31 updateDate: new Date(Date.now() - (1000 * 60 * 60 * 25 * 30))
michael@0 32 }]);
michael@0 33
michael@0 34 open_manager("addons://list/extension", function(aWindow) {
michael@0 35 gManagerWindow = aWindow;
michael@0 36 gCategoryUtilities = new CategoryUtilities(gManagerWindow);
michael@0 37 run_next_test();
michael@0 38 });
michael@0 39 }
michael@0 40
michael@0 41 function end_test() {
michael@0 42 close_manager(gManagerWindow, function() {
michael@0 43 finish();
michael@0 44 });
michael@0 45 }
michael@0 46
michael@0 47
michael@0 48 add_test(function() {
michael@0 49 info("Checking menuitem for Recent Updates opens that pane");
michael@0 50 var recentCat = gManagerWindow.gCategories.get("addons://updates/recent");
michael@0 51 is(gCategoryUtilities.isVisible(recentCat), false, "Recent Updates category should initially be hidden");
michael@0 52
michael@0 53 var utilsBtn = gManagerWindow.document.getElementById("header-utils-btn");
michael@0 54 utilsBtn.addEventListener("popupshown", function() {
michael@0 55 utilsBtn.removeEventListener("popupshown", arguments.callee, false);
michael@0 56 wait_for_view_load(gManagerWindow, function() {
michael@0 57 is(gCategoryUtilities.isVisible(recentCat), true, "Recent Updates category should now be visible");
michael@0 58 is(gManagerWindow.document.getElementById("categories").selectedItem.value, "addons://updates/recent", "Recent Updates category should now be selected");
michael@0 59 is(gManagerWindow.gViewController.currentViewId, "addons://updates/recent", "Recent Updates view should be the current view");
michael@0 60 run_next_test();
michael@0 61 }, true);
michael@0 62 var menuitem = gManagerWindow.document.getElementById("utils-viewUpdates");
michael@0 63 EventUtils.synthesizeMouse(menuitem, 2, 2, { }, gManagerWindow);
michael@0 64 }, false);
michael@0 65 EventUtils.synthesizeMouse(utilsBtn, 2, 2, { }, gManagerWindow);
michael@0 66 });
michael@0 67
michael@0 68
michael@0 69 add_test(function() {
michael@0 70 var updatesList = gManagerWindow.document.getElementById("updates-list");
michael@0 71 var sorters = gManagerWindow.document.getElementById("updates-sorters");
michael@0 72 var dateSorter = gManagerWindow.document.getAnonymousElementByAttribute(sorters, "anonid", "date-btn");
michael@0 73 var nameSorter = gManagerWindow.document.getAnonymousElementByAttribute(sorters, "anonid", "name-btn");
michael@0 74
michael@0 75 function check_order(expected) {
michael@0 76 var items = updatesList.getElementsByTagName("richlistitem");
michael@0 77 var possible = ["addon1@tests.mozilla.org", "addon2@tests.mozilla.org", "addon3@tests.mozilla.org"];
michael@0 78 for (let item of items) {
michael@0 79 let itemId = item.mAddon.id;
michael@0 80 if (possible.indexOf(itemId) == -1)
michael@0 81 continue; // skip over any other addons, such as shipped addons that would update on every build
michael@0 82 isnot(expected.length, 0, "Should be expecting more items");
michael@0 83 is(itemId, expected.shift(), "Should get expected item based on sort order");
michael@0 84 if (itemId == "addon1@tests.mozilla.org")
michael@0 85 is_element_visible(item._relNotesToggle, "Release notes toggle should be visible for addon with release notes");
michael@0 86 else
michael@0 87 is_element_hidden(item._relNotesToggle, "Release notes toggle should be hidden for addon with no release notes");
michael@0 88 }
michael@0 89 }
michael@0 90
michael@0 91 is_element_visible(dateSorter);
michael@0 92 is_element_visible(nameSorter);
michael@0 93
michael@0 94 // sorted by date, descending
michael@0 95 check_order(["addon2@tests.mozilla.org", "addon1@tests.mozilla.org"]);
michael@0 96
michael@0 97 // sorted by date, ascending
michael@0 98 EventUtils.synthesizeMouseAtCenter(dateSorter, { }, gManagerWindow);
michael@0 99 check_order(["addon1@tests.mozilla.org", "addon2@tests.mozilla.org"]);
michael@0 100
michael@0 101 // sorted by name, ascending
michael@0 102 EventUtils.synthesizeMouseAtCenter(nameSorter, { }, gManagerWindow);
michael@0 103 check_order(["addon2@tests.mozilla.org", "addon1@tests.mozilla.org"]);
michael@0 104
michael@0 105 // sorted by name, descending
michael@0 106 EventUtils.synthesizeMouseAtCenter(nameSorter, { }, gManagerWindow);
michael@0 107 check_order(["addon1@tests.mozilla.org", "addon2@tests.mozilla.org"]);
michael@0 108
michael@0 109 run_next_test();
michael@0 110 });
michael@0 111
michael@0 112
michael@0 113 add_test(function() {
michael@0 114 close_manager(gManagerWindow, function() {
michael@0 115 open_manager(null, function(aWindow) {
michael@0 116 gManagerWindow = aWindow;
michael@0 117 gCategoryUtilities = new CategoryUtilities(gManagerWindow);
michael@0 118
michael@0 119 var recentCat = gManagerWindow.gCategories.get("addons://updates/recent");
michael@0 120 is(gCategoryUtilities.isVisible(recentCat), true, "Recent Updates category should still be visible");
michael@0 121
michael@0 122 run_next_test();
michael@0 123 });
michael@0 124 });
michael@0 125 });

mercurial