summaryrefslogtreecommitdiffstats
path: root/toolkit/mozapps/extensions/test/browser/browser_bug596336.js
blob: 935820613438c9032d06d5f43af52c7233f3baa2 (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/
 */

// Tests that upgrading bootstrapped add-ons behaves correctly while the
// manager is open

var gManagerWindow;
var gCategoryUtilities;

function test() {
  waitForExplicitFinish();

  open_manager("addons://list/extension", function(aWindow) {
    gManagerWindow = aWindow;
    gCategoryUtilities = new CategoryUtilities(gManagerWindow);
    run_next_test();
  });
}

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

function get_list_item_count() {
  return get_test_items_in_list(gManagerWindow).length;
}

function get_node(parent, anonid) {
  return parent.ownerDocument.getAnonymousElementByAttribute(parent, "anonid", anonid);
}

function get_class_node(parent, cls) {
  return parent.ownerDocument.getAnonymousElementByAttribute(parent, "class", cls);
}

function install_addon(aXpi, aCallback) {
  AddonManager.getInstallForURL(TESTROOT + "addons/" + aXpi + ".xpi",
                                function(aInstall) {
    aInstall.addListener({
      onInstallEnded: function(aInstall) {
        executeSoon(aCallback);
      }
    });
    aInstall.install();
  }, "application/x-xpinstall");
}

function check_addon(aAddon, version) {
  is(get_list_item_count(), 1, "Should be one item in the list");
  is(aAddon.version, version, "Add-on should have the right version");

  let item = get_addon_element(gManagerWindow, "addon1@tests.mozilla.org");
  ok(!!item, "Should see the add-on in the list");

  // Force XBL to apply
  item.clientTop;

  is(get_node(item, "version").value, version, "Version should be correct");

  if (aAddon.userDisabled)
    is_element_visible(get_class_node(item, "disabled-postfix"), "Disabled postfix should be hidden");
  else
    is_element_hidden(get_class_node(item, "disabled-postfix"), "Disabled postfix should be hidden");
}

// Install version 1 then upgrade to version 2 with the manager open
add_test(function() {
  install_addon("browser_bug596336_1", function() {
    AddonManager.getAddonByID("addon1@tests.mozilla.org", function(aAddon) {
      check_addon(aAddon, "1.0");
      ok(!aAddon.userDisabled, "Add-on should not be disabled");

      install_addon("browser_bug596336_2", function() {
        AddonManager.getAddonByID("addon1@tests.mozilla.org", function(aAddon) {
          check_addon(aAddon, "2.0");
          ok(!aAddon.userDisabled, "Add-on should not be disabled");

          aAddon.uninstall();

          is(get_list_item_count(), 0, "Should be no items in the list");

          run_next_test();
        });
      });
    });
  });
});

// Install version 1 mark it as disabled then upgrade to version 2 with the
// manager open
add_test(function() {
  install_addon("browser_bug596336_1", function() {
    AddonManager.getAddonByID("addon1@tests.mozilla.org", function(aAddon) {
      aAddon.userDisabled = true;
      check_addon(aAddon, "1.0");
      ok(aAddon.userDisabled, "Add-on should be disabled");

      install_addon("browser_bug596336_2", function() {
        AddonManager.getAddonByID("addon1@tests.mozilla.org", function(aAddon) {
          check_addon(aAddon, "2.0");
          ok(aAddon.userDisabled, "Add-on should be disabled");

          aAddon.uninstall();

          is(get_list_item_count(), 0, "Should be no items in the list");

          run_next_test();
        });
      });
    });
  });
});

// Install version 1 click the remove button and then upgrade to version 2 with
// the manager open
add_test(function() {
  install_addon("browser_bug596336_1", function() {
    AddonManager.getAddonByID("addon1@tests.mozilla.org", function(aAddon) {
      check_addon(aAddon, "1.0");
      ok(!aAddon.userDisabled, "Add-on should not be disabled");

      let item = get_addon_element(gManagerWindow, "addon1@tests.mozilla.org");
      EventUtils.synthesizeMouseAtCenter(get_node(item, "remove-btn"), { }, gManagerWindow);

      // Force XBL to apply
      item.clientTop;

      ok(!!(aAddon.pendingOperations & AddonManager.PENDING_UNINSTALL), "Add-on should be pending uninstall");
      is_element_visible(get_class_node(item, "pending"), "Pending message should be visible");

      install_addon("browser_bug596336_2", function() {
        AddonManager.getAddonByID("addon1@tests.mozilla.org", function(aAddon) {
          check_addon(aAddon, "2.0");
          ok(!aAddon.userDisabled, "Add-on should not be disabled");

          aAddon.uninstall();

          is(get_list_item_count(), 0, "Should be no items in the list");

          run_next_test();
        });
      });
    });
  });
});

// Install version 1, disable it, click the remove button and then upgrade to
// version 2 with the manager open
add_test(function() {
  install_addon("browser_bug596336_1", function() {
    AddonManager.getAddonByID("addon1@tests.mozilla.org", function(aAddon) {
      aAddon.userDisabled = true;
      check_addon(aAddon, "1.0");
      ok(aAddon.userDisabled, "Add-on should be disabled");

      let item = get_addon_element(gManagerWindow, "addon1@tests.mozilla.org");
      EventUtils.synthesizeMouseAtCenter(get_node(item, "remove-btn"), { }, gManagerWindow);

      // Force XBL to apply
      item.clientTop;

      ok(!!(aAddon.pendingOperations & AddonManager.PENDING_UNINSTALL), "Add-on should be pending uninstall");
      is_element_visible(get_class_node(item, "pending"), "Pending message should be visible");

      install_addon("browser_bug596336_2", function() {
        AddonManager.getAddonByID("addon1@tests.mozilla.org", function(aAddon) {
          check_addon(aAddon, "2.0");
          ok(aAddon.userDisabled, "Add-on should be disabled");

          aAddon.uninstall();

          is(get_list_item_count(), 0, "Should be no items in the list");

          run_next_test();
        });
      });
    });
  });
});