toolkit/mozapps/extensions/test/browser/browser_bug591663.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 // Test that the empty notice in the list view disappears as it should
michael@0 6
michael@0 7 // Don't use a standard list view (e.g. "extension") to ensure that the list is
michael@0 8 // initially empty. Don't need to worry about the list of categories displayed
michael@0 9 // since only the list view itself is tested.
michael@0 10 let VIEW_ID = "addons://list/mock-addon";
michael@0 11
michael@0 12 let LIST_ID = "addon-list";
michael@0 13 let EMPTY_ID = "addon-list-empty";
michael@0 14
michael@0 15 let gManagerWindow;
michael@0 16 let gProvider;
michael@0 17 let gItem;
michael@0 18
michael@0 19 let gInstallProperties = {
michael@0 20 name: "Bug 591663 Mock Install",
michael@0 21 type: "mock-addon"
michael@0 22 };
michael@0 23 let gAddonProperties = {
michael@0 24 id: "test1@tests.mozilla.org",
michael@0 25 name: "Bug 591663 Mock Add-on",
michael@0 26 type: "mock-addon"
michael@0 27 };
michael@0 28 let gExtensionProperties = {
michael@0 29 name: "Bug 591663 Extension Install",
michael@0 30 type: "extension"
michael@0 31 };
michael@0 32
michael@0 33 function test() {
michael@0 34 waitForExplicitFinish();
michael@0 35
michael@0 36 gProvider = new MockProvider(true, [{
michael@0 37 id: "mock-addon",
michael@0 38 name: "Mock Add-ons",
michael@0 39 uiPriority: 4500,
michael@0 40 flags: AddonManager.TYPE_UI_VIEW_LIST
michael@0 41 }]);
michael@0 42
michael@0 43 open_manager(VIEW_ID, function(aWindow) {
michael@0 44 gManagerWindow = aWindow;
michael@0 45 run_next_test();
michael@0 46 });
michael@0 47 }
michael@0 48
michael@0 49 function end_test() {
michael@0 50 close_manager(gManagerWindow, finish);
michael@0 51 }
michael@0 52
michael@0 53 /**
michael@0 54 * Check that the list view is as expected
michael@0 55 *
michael@0 56 * @param aItem
michael@0 57 * The expected item in the list, or null if list should be empty
michael@0 58 */
michael@0 59 function check_list(aItem) {
michael@0 60 // Check state of the empty notice
michael@0 61 let emptyNotice = gManagerWindow.document.getElementById(EMPTY_ID);
michael@0 62 ok(emptyNotice != null, "Should have found the empty notice");
michael@0 63 is(!emptyNotice.hidden, (aItem == null), "Empty notice should be showing if list empty");
michael@0 64
michael@0 65 // Check the children of the list
michael@0 66 let list = gManagerWindow.document.getElementById(LIST_ID);
michael@0 67 is(list.itemCount, aItem ? 1 : 0, "Should get expected number of items in list");
michael@0 68 if (aItem != null) {
michael@0 69 let itemName = list.firstChild.getAttribute("name");
michael@0 70 is(itemName, aItem.name, "List item should have correct name");
michael@0 71 }
michael@0 72 }
michael@0 73
michael@0 74
michael@0 75 // Test that the empty notice is showing and no items are showing in list
michael@0 76 add_test(function() {
michael@0 77 check_list(null);
michael@0 78 run_next_test();
michael@0 79 });
michael@0 80
michael@0 81 // Test that a new, non-active, install does not affect the list view
michael@0 82 add_test(function() {
michael@0 83 gItem = gProvider.createInstalls([gInstallProperties])[0];
michael@0 84 check_list(null);
michael@0 85 run_next_test();
michael@0 86 });
michael@0 87
michael@0 88 // Test that onInstallStarted properly hides empty notice and adds install to list
michael@0 89 add_test(function() {
michael@0 90 gItem.addTestListener({
michael@0 91 onDownloadStarted: function() {
michael@0 92 // Install type unknown until download complete
michael@0 93 check_list(null);
michael@0 94 },
michael@0 95 onInstallStarted: function() {
michael@0 96 check_list(gItem);
michael@0 97 },
michael@0 98 onInstallEnded: function() {
michael@0 99 check_list(gItem);
michael@0 100 run_next_test();
michael@0 101 }
michael@0 102 });
michael@0 103
michael@0 104 gItem.install();
michael@0 105 });
michael@0 106
michael@0 107 // Test that restarting the manager does not change list
michael@0 108 add_test(function() {
michael@0 109 restart_manager(gManagerWindow, VIEW_ID, function(aManagerWindow) {
michael@0 110 gManagerWindow = aManagerWindow;
michael@0 111 check_list(gItem);
michael@0 112 run_next_test();
michael@0 113 });
michael@0 114 });
michael@0 115
michael@0 116 // Test that onInstallCancelled removes install and shows empty notice
michael@0 117 add_test(function() {
michael@0 118 gItem.cancel();
michael@0 119 gItem = null;
michael@0 120 check_list(null);
michael@0 121 run_next_test();
michael@0 122 });
michael@0 123
michael@0 124 // Test that add-ons of a different type do not show up in the list view
michael@0 125 add_test(function() {
michael@0 126 let extension = gProvider.createInstalls([gExtensionProperties])[0];
michael@0 127 check_list(null);
michael@0 128
michael@0 129 extension.addTestListener({
michael@0 130 onDownloadStarted: function() {
michael@0 131 check_list(null);
michael@0 132 },
michael@0 133 onInstallStarted: function() {
michael@0 134 check_list(null);
michael@0 135 },
michael@0 136 onInstallEnded: function() {
michael@0 137 check_list(null);
michael@0 138 extension.cancel();
michael@0 139 run_next_test();
michael@0 140 }
michael@0 141 });
michael@0 142
michael@0 143 extension.install();
michael@0 144 });
michael@0 145
michael@0 146 // Test that onExternalInstall properly hides empty notice and adds install to list
michael@0 147 add_test(function() {
michael@0 148 gItem = gProvider.createAddons([gAddonProperties])[0];
michael@0 149 check_list(gItem);
michael@0 150 run_next_test();
michael@0 151 });
michael@0 152
michael@0 153 // Test that restarting the manager does not change list
michael@0 154 add_test(function() {
michael@0 155 restart_manager(gManagerWindow, VIEW_ID, function(aManagerWindow) {
michael@0 156 gManagerWindow = aManagerWindow;
michael@0 157 check_list(gItem);
michael@0 158 run_next_test();
michael@0 159 });
michael@0 160 });
michael@0 161

mercurial