summaryrefslogtreecommitdiffstats
path: root/toolkit/mozapps/extensions/test/browser/browser_bug608316.js
blob: 39986c23b3be8c320ec8cbebeca5ea3c00467096 (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
/* Any copyright is dedicated to the Public Domain.
 * http://creativecommons.org/publicdomain/zero/1.0/
 */

// Bug 608316 - Test that cancelling an uninstall during the onUninstalling
// event doesn't confuse the UI

var gProvider;

function test() {
  waitForExplicitFinish();
  
  gProvider = new MockProvider();

  gProvider.createAddons([{
    id: "addon1@tests.mozilla.org",
    name: "addon 1",
    version: "1.0"
  }]);

  run_next_test();
}


function end_test() {
  finish();
}


add_test(function() {
  var sawUninstall = false;
  var listener = {
    onUninstalling: function(aAddon, aRestartRequired) {
      if (aAddon.id != "addon1@tests.mozilla.org")
        return;
      sawUninstall = true;
      aAddon.cancelUninstall();
    }
  }

  // Important to add this before opening the UI so it gets its events first
  AddonManager.addAddonListener(listener);
  registerCleanupFunction(function() {
    AddonManager.removeAddonListener(listener);
  });

  open_manager("addons://list/extension", function(aManager) {
    var addon = get_addon_element(aManager, "addon1@tests.mozilla.org");
    isnot(addon, null, "Should see the add-on in the list");

    var removeBtn = aManager.document.getAnonymousElementByAttribute(addon, "anonid", "remove-btn");
    EventUtils.synthesizeMouseAtCenter(removeBtn, { }, aManager);

    ok(sawUninstall, "Should have seen the uninstall event");
    sawUninstall = false;

    is(addon.getAttribute("pending"), "", "Add-on should not be uninstalling");

    close_manager(aManager, function() {
      ok(!sawUninstall, "Should not have seen another uninstall event");

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