toolkit/mozapps/extensions/test/browser/browser_bug587970.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 // Bug 587970 - Provide ability "Update all now" within 'Available Updates' screen
michael@0 6
michael@0 7 var gManagerWindow;
michael@0 8 var gProvider;
michael@0 9
michael@0 10 function test() {
michael@0 11 waitForExplicitFinish();
michael@0 12
michael@0 13 gProvider = new MockProvider();
michael@0 14
michael@0 15 gProvider.createAddons([{
michael@0 16 id: "addon1@tests.mozilla.org",
michael@0 17 name: "addon 1",
michael@0 18 version: "1.0",
michael@0 19 applyBackgroundUpdates: AddonManager.AUTOUPDATE_DISABLE
michael@0 20 }, {
michael@0 21 id: "addon2@tests.mozilla.org",
michael@0 22 name: "addon 2",
michael@0 23 version: "2.0",
michael@0 24 applyBackgroundUpdates: AddonManager.AUTOUPDATE_DISABLE
michael@0 25 }, {
michael@0 26 id: "addon3@tests.mozilla.org",
michael@0 27 name: "addon 3",
michael@0 28 version: "3.0",
michael@0 29 applyBackgroundUpdates: AddonManager.AUTOUPDATE_DISABLE
michael@0 30 }]);
michael@0 31
michael@0 32
michael@0 33 open_manager("addons://updates/available", function(aWindow) {
michael@0 34 gManagerWindow = aWindow;
michael@0 35 run_next_test();
michael@0 36 });
michael@0 37 }
michael@0 38
michael@0 39
michael@0 40 function end_test() {
michael@0 41 close_manager(gManagerWindow, finish);
michael@0 42 }
michael@0 43
michael@0 44
michael@0 45 add_test(function() {
michael@0 46 var list = gManagerWindow.document.getElementById("updates-list");
michael@0 47 is(list.childNodes.length, 0, "Available updates list should be empty");
michael@0 48
michael@0 49 var emptyNotice = gManagerWindow.document.getElementById("empty-availableUpdates-msg");
michael@0 50 is_element_visible(emptyNotice, "Empty notice should be visible");
michael@0 51
michael@0 52 var updateSelected = gManagerWindow.document.getElementById("update-selected-btn");
michael@0 53 is_element_hidden(updateSelected, "Update Selected button should be hidden");
michael@0 54
michael@0 55 info("Adding updates");
michael@0 56 gProvider.createInstalls([{
michael@0 57 name: "addon 1",
michael@0 58 version: "1.1",
michael@0 59 existingAddon: gProvider.addons[0]
michael@0 60 }, {
michael@0 61 name: "addon 2",
michael@0 62 version: "2.1",
michael@0 63 existingAddon: gProvider.addons[1]
michael@0 64 }, {
michael@0 65 name: "addon 3",
michael@0 66 version: "3.1",
michael@0 67 existingAddon: gProvider.addons[2]
michael@0 68 }]);
michael@0 69
michael@0 70 function wait_for_refresh() {
michael@0 71 if (list.childNodes.length == 3 &&
michael@0 72 list.childNodes[0].mManualUpdate &&
michael@0 73 list.childNodes[1].mManualUpdate &&
michael@0 74 list.childNodes[2].mManualUpdate) {
michael@0 75 run_next_test();
michael@0 76 } else {
michael@0 77 info("Waiting for pane to refresh");
michael@0 78 setTimeout(wait_for_refresh, 10);
michael@0 79 }
michael@0 80 }
michael@0 81 info("Waiting for pane to refresh");
michael@0 82 setTimeout(wait_for_refresh, 10);
michael@0 83 });
michael@0 84
michael@0 85
michael@0 86 add_test(function() {
michael@0 87 var list = gManagerWindow.document.getElementById("updates-list");
michael@0 88 is(list.childNodes.length, 3, "Available updates list should have 2 items");
michael@0 89
michael@0 90 var item1 = get_addon_element(gManagerWindow, "addon1@tests.mozilla.org");
michael@0 91 isnot(item1, null, "Item for addon1@tests.mozilla.org should be in list");
michael@0 92 var item2 = get_addon_element(gManagerWindow, "addon2@tests.mozilla.org");
michael@0 93 isnot(item2, null, "Item for addon2@tests.mozilla.org should be in list");
michael@0 94 var item3 = get_addon_element(gManagerWindow, "addon3@tests.mozilla.org");
michael@0 95 isnot(item3, null, "Item for addon3@tests.mozilla.org should be in list");
michael@0 96
michael@0 97 var emptyNotice = gManagerWindow.document.getElementById("empty-availableUpdates-msg");
michael@0 98 is_element_hidden(emptyNotice, "Empty notice should be hidden");
michael@0 99
michael@0 100 var updateSelected = gManagerWindow.document.getElementById("update-selected-btn");
michael@0 101 is_element_visible(updateSelected, "Update Selected button should be visible");
michael@0 102 is(updateSelected.disabled, false, "Update Selected button should be enabled by default");
michael@0 103
michael@0 104 is(item1._includeUpdate.checked, true, "Include Update checkbox should be checked by default for addon1");
michael@0 105 is(item2._includeUpdate.checked, true, "Include Update checkbox should be checked by default for addon2");
michael@0 106 is(item3._includeUpdate.checked, true, "Include Update checkbox should be checked by default for addon3");
michael@0 107
michael@0 108 info("Unchecking Include Update checkbox for addon1");
michael@0 109 EventUtils.synthesizeMouse(item1._includeUpdate, 2, 2, { }, gManagerWindow);
michael@0 110 is(item1._includeUpdate.checked, false, "Include Update checkbox should now be be unchecked for addon1");
michael@0 111 is(updateSelected.disabled, false, "Update Selected button should still be enabled");
michael@0 112
michael@0 113 info("Unchecking Include Update checkbox for addon2");
michael@0 114 EventUtils.synthesizeMouse(item2._includeUpdate, 2, 2, { }, gManagerWindow);
michael@0 115 is(item2._includeUpdate.checked, false, "Include Update checkbox should now be be unchecked for addon2");
michael@0 116 is(updateSelected.disabled, false, "Update Selected button should still be enabled");
michael@0 117
michael@0 118 info("Unchecking Include Update checkbox for addon3");
michael@0 119 EventUtils.synthesizeMouse(item3._includeUpdate, 2, 2, { }, gManagerWindow);
michael@0 120 is(item3._includeUpdate.checked, false, "Include Update checkbox should now be be unchecked for addon3");
michael@0 121 is(updateSelected.disabled, true, "Update Selected button should now be disabled");
michael@0 122
michael@0 123 info("Checking Include Update checkbox for addon2");
michael@0 124 EventUtils.synthesizeMouse(item2._includeUpdate, 2, 2, { }, gManagerWindow);
michael@0 125 is(item2._includeUpdate.checked, true, "Include Update checkbox should now be be checked for addon2");
michael@0 126 is(updateSelected.disabled, false, "Update Selected button should now be enabled");
michael@0 127
michael@0 128 info("Checking Include Update checkbox for addon3");
michael@0 129 EventUtils.synthesizeMouse(item3._includeUpdate, 2, 2, { }, gManagerWindow);
michael@0 130 is(item3._includeUpdate.checked, true, "Include Update checkbox should now be be checked for addon3");
michael@0 131 is(updateSelected.disabled, false, "Update Selected button should now be enabled");
michael@0 132
michael@0 133 var installCount = 0;
michael@0 134 var listener = {
michael@0 135 onDownloadStarted: function(aInstall) {
michael@0 136 isnot(aInstall.existingAddon.id, "addon1@tests.mozilla.org", "Should not have seen a download start for addon1");
michael@0 137 },
michael@0 138
michael@0 139 onInstallEnded: function(aInstall) {
michael@0 140 if (++installCount < 2)
michael@0 141 return;
michael@0 142
michael@0 143 gProvider.installs[0].removeTestListener(listener);
michael@0 144 gProvider.installs[1].removeTestListener(listener);
michael@0 145 gProvider.installs[2].removeTestListener(listener);
michael@0 146
michael@0 147 // Installs are started synchronously so by the time an executeSoon is
michael@0 148 // executed all installs that are going to start will have started
michael@0 149 executeSoon(function() {
michael@0 150 is(gProvider.installs[0].state, AddonManager.STATE_AVAILABLE, "addon1 should not have been upgraded");
michael@0 151 is(gProvider.installs[1].state, AddonManager.STATE_INSTALLED, "addon2 should have been upgraded");
michael@0 152 is(gProvider.installs[2].state, AddonManager.STATE_INSTALLED, "addon3 should have been upgraded");
michael@0 153
michael@0 154 run_next_test();
michael@0 155 });
michael@0 156 }
michael@0 157 }
michael@0 158 gProvider.installs[0].addTestListener(listener);
michael@0 159 gProvider.installs[1].addTestListener(listener);
michael@0 160 gProvider.installs[2].addTestListener(listener);
michael@0 161 info("Clicking Update Selected button");
michael@0 162 EventUtils.synthesizeMouseAtCenter(updateSelected, { }, gManagerWindow);
michael@0 163 });
michael@0 164
michael@0 165
michael@0 166 add_test(function() {
michael@0 167 var updateSelected = gManagerWindow.document.getElementById("update-selected-btn");
michael@0 168 is(updateSelected.disabled, true, "Update Selected button should be disabled");
michael@0 169
michael@0 170 var item1 = get_addon_element(gManagerWindow, "addon1@tests.mozilla.org");
michael@0 171 isnot(item1, null, "Item for addon1@tests.mozilla.org should be in list");
michael@0 172 is(item1._includeUpdate.checked, false, "Include Update checkbox should not have changed");
michael@0 173
michael@0 174 info("Checking Include Update checkbox for addon1");
michael@0 175 EventUtils.synthesizeMouse(item1._includeUpdate, 2, 2, { }, gManagerWindow);
michael@0 176 is(item1._includeUpdate.checked, true, "Include Update checkbox should now be be checked for addon1");
michael@0 177 is(updateSelected.disabled, false, "Update Selected button should now not be disabled");
michael@0 178
michael@0 179 run_next_test();
michael@0 180 });

mercurial