summaryrefslogtreecommitdiffstats
path: root/toolkit/mozapps/extensions/test/browser/browser_bug587970.js
blob: ef05ba4ea5b25febd46f0fbf12a48bf7882e0ce0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
/* Any copyright is dedicated to the Public Domain.
 * http://creativecommons.org/publicdomain/zero/1.0/
 */

// Bug 587970 - Provide ability "Update all now" within 'Available Updates' screen

var gManagerWindow;
var gProvider;

function test() {
  waitForExplicitFinish();

  gProvider = new MockProvider();

  gProvider.createAddons([{
    id: "addon1@tests.mozilla.org",
    name: "addon 1",
    version: "1.0",
    applyBackgroundUpdates: AddonManager.AUTOUPDATE_DISABLE
  }, {
    id: "addon2@tests.mozilla.org",
    name: "addon 2",
    version: "2.0",
    applyBackgroundUpdates: AddonManager.AUTOUPDATE_DISABLE
  }, {
    id: "addon3@tests.mozilla.org",
    name: "addon 3",
    version: "3.0",
    applyBackgroundUpdates: AddonManager.AUTOUPDATE_DISABLE
  }]);


  open_manager("addons://updates/available", function(aWindow) {
    gManagerWindow = aWindow;
    run_next_test();
  });
}


function end_test() {
  close_manager(gManagerWindow, finish);
}


add_test(function() {
  var list = gManagerWindow.document.getElementById("updates-list");
  is(list.childNodes.length, 0, "Available updates list should be empty");

  var emptyNotice = gManagerWindow.document.getElementById("empty-availableUpdates-msg");
  is_element_visible(emptyNotice, "Empty notice should be visible");

  var updateSelected = gManagerWindow.document.getElementById("update-selected-btn");
  is_element_hidden(updateSelected, "Update Selected button should be hidden");

  info("Adding updates");
  gProvider.createInstalls([{
    name: "addon 1",
    version: "1.1",
    existingAddon: gProvider.addons[0]
  }, {
    name: "addon 2",
    version: "2.1",
    existingAddon: gProvider.addons[1]
  }, {
    name: "addon 3",
    version: "3.1",
    existingAddon: gProvider.addons[2]
  }]);

  function wait_for_refresh() {
    if (list.childNodes.length == 3 &&
        list.childNodes[0].mManualUpdate &&
        list.childNodes[1].mManualUpdate &&
        list.childNodes[2].mManualUpdate) {
      run_next_test();
    } else {
      info("Waiting for pane to refresh");
      setTimeout(wait_for_refresh, 10);
    }
  }
  info("Waiting for pane to refresh");
  setTimeout(wait_for_refresh, 10);
});


add_test(function() {
  var list = gManagerWindow.document.getElementById("updates-list");
  is(list.childNodes.length, 3, "Available updates list should have 2 items");

  var item1 = get_addon_element(gManagerWindow, "addon1@tests.mozilla.org");
  isnot(item1, null, "Item for addon1@tests.mozilla.org should be in list");
  var item2 = get_addon_element(gManagerWindow, "addon2@tests.mozilla.org");
  isnot(item2, null, "Item for addon2@tests.mozilla.org should be in list");
  var item3 = get_addon_element(gManagerWindow, "addon3@tests.mozilla.org");
  isnot(item3, null, "Item for addon3@tests.mozilla.org should be in list");

  var emptyNotice = gManagerWindow.document.getElementById("empty-availableUpdates-msg");
  is_element_hidden(emptyNotice, "Empty notice should be hidden");

  var updateSelected = gManagerWindow.document.getElementById("update-selected-btn");
  is_element_visible(updateSelected, "Update Selected button should be visible");
  is(updateSelected.disabled, false, "Update Selected button should be enabled by default");

  is(item1._includeUpdate.checked, true, "Include Update checkbox should be checked by default for addon1");
  is(item2._includeUpdate.checked, true, "Include Update checkbox should be checked by default for addon2");
  is(item3._includeUpdate.checked, true, "Include Update checkbox should be checked by default for addon3");

  info("Unchecking Include Update checkbox for addon1");
  EventUtils.synthesizeMouse(item1._includeUpdate, 2, 2, { }, gManagerWindow);
  is(item1._includeUpdate.checked, false, "Include Update checkbox should now be be unchecked for addon1");
  is(updateSelected.disabled, false, "Update Selected button should still be enabled");

  info("Unchecking Include Update checkbox for addon2");
  EventUtils.synthesizeMouse(item2._includeUpdate, 2, 2, { }, gManagerWindow);
  is(item2._includeUpdate.checked, false, "Include Update checkbox should now be be unchecked for addon2");
  is(updateSelected.disabled, false, "Update Selected button should still be enabled");

  info("Unchecking Include Update checkbox for addon3");
  EventUtils.synthesizeMouse(item3._includeUpdate, 2, 2, { }, gManagerWindow);
  is(item3._includeUpdate.checked, false, "Include Update checkbox should now be be unchecked for addon3");
  is(updateSelected.disabled, true, "Update Selected button should now be disabled");

  info("Checking Include Update checkbox for addon2");
  EventUtils.synthesizeMouse(item2._includeUpdate, 2, 2, { }, gManagerWindow);
  is(item2._includeUpdate.checked, true, "Include Update checkbox should now be be checked for addon2");
  is(updateSelected.disabled, false, "Update Selected button should now be enabled");

  info("Checking Include Update checkbox for addon3");
  EventUtils.synthesizeMouse(item3._includeUpdate, 2, 2, { }, gManagerWindow);
  is(item3._includeUpdate.checked, true, "Include Update checkbox should now be be checked for addon3");
  is(updateSelected.disabled, false, "Update Selected button should now be enabled");

  var installCount = 0;
  var listener = {
    onDownloadStarted: function(aInstall) {
      isnot(aInstall.existingAddon.id, "addon1@tests.mozilla.org", "Should not have seen a download start for addon1");
    },

    onInstallEnded: function(aInstall) {
      if (++installCount < 2)
        return;

      gProvider.installs[0].removeTestListener(listener);
      gProvider.installs[1].removeTestListener(listener);
      gProvider.installs[2].removeTestListener(listener);

      // Installs are started synchronously so by the time an executeSoon is
      // executed all installs that are going to start will have started
      executeSoon(function() {
        is(gProvider.installs[0].state, AddonManager.STATE_AVAILABLE, "addon1 should not have been upgraded");
        is(gProvider.installs[1].state, AddonManager.STATE_INSTALLED, "addon2 should have been upgraded");
        is(gProvider.installs[2].state, AddonManager.STATE_INSTALLED, "addon3 should have been upgraded");

        run_next_test();
      });
    }
  }
  gProvider.installs[0].addTestListener(listener);
  gProvider.installs[1].addTestListener(listener);
  gProvider.installs[2].addTestListener(listener);
  info("Clicking Update Selected button");
  EventUtils.synthesizeMouseAtCenter(updateSelected, { }, gManagerWindow);
});


add_test(function() {
  var updateSelected = gManagerWindow.document.getElementById("update-selected-btn");
  is(updateSelected.disabled, true, "Update Selected button should be disabled");

  var item1 = get_addon_element(gManagerWindow, "addon1@tests.mozilla.org");
  isnot(item1, null, "Item for addon1@tests.mozilla.org should be in list");
  is(item1._includeUpdate.checked, false, "Include Update checkbox should not have changed");

  info("Checking Include Update checkbox for addon1");
  EventUtils.synthesizeMouse(item1._includeUpdate, 2, 2, { }, gManagerWindow);
  is(item1._includeUpdate.checked, true, "Include Update checkbox should now be be checked for addon1");
  is(updateSelected.disabled, false, "Update Selected button should now not be disabled");

  run_next_test();
});