toolkit/mozapps/extensions/test/browser/browser_bug562854.js

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/toolkit/mozapps/extensions/test/browser/browser_bug562854.js	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,129 @@
     1.4 +/* Any copyright is dedicated to the Public Domain.
     1.5 + * http://creativecommons.org/publicdomain/zero/1.0/
     1.6 + */
     1.7 +
     1.8 +/**
     1.9 + * Tests that double-click does not go to detail view if the target is a link or button.
    1.10 + */
    1.11 +
    1.12 +function test() {
    1.13 +  requestLongerTimeout(2);
    1.14 +
    1.15 +  waitForExplicitFinish();
    1.16 +
    1.17 +  var gProvider = new MockProvider();
    1.18 +  gProvider.createAddons([{
    1.19 +    id: "test1@tests.mozilla.org",
    1.20 +    name: "Test add-on 1",
    1.21 +    description: "foo",
    1.22 +    operationsRequiringRestart: AddonManager.OP_NEEDS_RESTART_NONE
    1.23 +  }]);
    1.24 +
    1.25 +  run_next_test();
    1.26 +}
    1.27 +
    1.28 +function end_test() {
    1.29 +  finish();
    1.30 +}
    1.31 +
    1.32 +function is_in_list(aManager, view) {
    1.33 +  var doc = aManager.document;
    1.34 +
    1.35 +  is(doc.getElementById("categories").selectedItem.value, view, "Should be on the right category");
    1.36 +  is(doc.getElementById("view-port").selectedPanel.id, "list-view", "Should be on the right view");
    1.37 +}
    1.38 +
    1.39 +function is_in_detail(aManager, view) {
    1.40 +  var doc = aManager.document;
    1.41 +
    1.42 +  is(doc.getElementById("categories").selectedItem.value, view, "Should be on the right category");
    1.43 +  is(doc.getElementById("view-port").selectedPanel.id, "detail-view", "Should be on the right view");
    1.44 +}
    1.45 +
    1.46 +// Check that double-click does something.
    1.47 +add_test(function() {
    1.48 +  open_manager("addons://list/extension", function(aManager) {
    1.49 +    info("Part 1");
    1.50 +    is_in_list(aManager, "addons://list/extension");
    1.51 +
    1.52 +    var addon = get_addon_element(aManager, "test1@tests.mozilla.org");
    1.53 +    addon.parentNode.ensureElementIsVisible(addon);
    1.54 +    EventUtils.synthesizeMouseAtCenter(addon, { clickCount: 1 }, aManager);
    1.55 +    EventUtils.synthesizeMouseAtCenter(addon, { clickCount: 2 }, aManager);
    1.56 +
    1.57 +    wait_for_view_load(aManager, function(aManager) {
    1.58 +      info("Part 2");
    1.59 +      is_in_detail(aManager, "addons://list/extension");
    1.60 +
    1.61 +      close_manager(aManager, run_next_test);
    1.62 +    });
    1.63 +  });
    1.64 +});
    1.65 +
    1.66 +// Check that double-click does nothing when over the disable button.
    1.67 +add_test(function() {
    1.68 +  open_manager("addons://list/extension", function(aManager) {
    1.69 +    info("Part 1");
    1.70 +    is_in_list(aManager, "addons://list/extension");
    1.71 +
    1.72 +    var addon = get_addon_element(aManager, "test1@tests.mozilla.org");
    1.73 +    addon.parentNode.ensureElementIsVisible(addon);
    1.74 +    EventUtils.synthesizeMouseAtCenter(
    1.75 +      aManager.document.getAnonymousElementByAttribute(addon, "anonid", "disable-btn"),
    1.76 +      { clickCount: 1 },
    1.77 +      aManager
    1.78 +    );
    1.79 +    // The disable button is replaced by the enable button when clicked on.
    1.80 +    EventUtils.synthesizeMouseAtCenter(
    1.81 +      aManager.document.getAnonymousElementByAttribute(addon, "anonid", "enable-btn"),
    1.82 +      { clickCount: 2 },
    1.83 +      aManager
    1.84 +    );
    1.85 +
    1.86 +    wait_for_view_load(aManager, function(aManager) {
    1.87 +      info("Part 2");
    1.88 +      is_in_list(aManager, "addons://list/extension");
    1.89 +
    1.90 +      close_manager(aManager, run_next_test);
    1.91 +    });
    1.92 +  });
    1.93 +});
    1.94 +
    1.95 +// Check that double-click does nothing when over the undo button.
    1.96 +add_test(function() {
    1.97 +  open_manager("addons://list/extension", function(aManager) {
    1.98 +    info("Part 1");
    1.99 +    is_in_list(aManager, "addons://list/extension");
   1.100 +
   1.101 +    var addon = get_addon_element(aManager, "test1@tests.mozilla.org");
   1.102 +    addon.parentNode.ensureElementIsVisible(addon);
   1.103 +    EventUtils.synthesizeMouseAtCenter(
   1.104 +      aManager.document.getAnonymousElementByAttribute(addon, "anonid", "remove-btn"),
   1.105 +      { clickCount: 1 },
   1.106 +      aManager
   1.107 +    );
   1.108 +
   1.109 +    // The undo button is removed when clicked on.
   1.110 +    // We need to wait for the UI to catch up.
   1.111 +    setTimeout(function() {
   1.112 +      var target = aManager.document.getAnonymousElementByAttribute(addon, "anonid", "undo-btn");
   1.113 +      var rect = target.getBoundingClientRect();
   1.114 +      var addonRect = addon.getBoundingClientRect();
   1.115 +
   1.116 +      EventUtils.synthesizeMouse(target, rect.width / 2, rect.height / 2, { clickCount: 1 }, aManager);
   1.117 +      EventUtils.synthesizeMouse(addon,
   1.118 +        rect.left - addonRect.left + rect.width / 2,
   1.119 +        rect.top - addonRect.top + rect.height / 2,
   1.120 +        { clickCount: 2 },
   1.121 +        aManager
   1.122 +      );
   1.123 +
   1.124 +      wait_for_view_load(aManager, function(aManager) {
   1.125 +        info("Part 2");
   1.126 +        is_in_list(aManager, "addons://list/extension");
   1.127 +
   1.128 +        close_manager(aManager, run_next_test);
   1.129 +      });
   1.130 +    }, 0);
   1.131 +  });
   1.132 +});

mercurial