toolkit/mozapps/extensions/test/browser/browser_select_confirm.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_select_confirm.js	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,181 @@
     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 +// Tests the confirmation part of the post-app-update dialog
     1.9 +
    1.10 +var gProvider;
    1.11 +var gWin;
    1.12 +
    1.13 +function waitForView(aView, aCallback) {
    1.14 +  var view = gWin.document.getElementById(aView);
    1.15 +  if (view.parentNode.selectedPanel == view) {
    1.16 +    aCallback();
    1.17 +    return;
    1.18 +  }
    1.19 +
    1.20 +  view.addEventListener("ViewChanged", function() {
    1.21 +    view.removeEventListener("ViewChanged", arguments.callee, false);
    1.22 +    try {
    1.23 +      aCallback();
    1.24 +    }
    1.25 +    catch (e) {
    1.26 +      ok(false, e);
    1.27 +    }
    1.28 +  }, false);
    1.29 +}
    1.30 +
    1.31 +/**
    1.32 + * Creates 4 test add-ons. Two are disabled and two enabled.
    1.33 + *
    1.34 + * @param  aAppDisabled
    1.35 + *         The appDisabled property for the test add-ons
    1.36 + * @param  aUpdateAvailable
    1.37 + *         True if the test add-ons should claim to have an update available
    1.38 + */
    1.39 +function setupUI(aAppDisabled, aUpdateAvailable, aCallback) {
    1.40 +  if (gProvider)
    1.41 +    gProvider.unregister();
    1.42 +
    1.43 +  gProvider = new MockProvider();
    1.44 +
    1.45 +  for (var i = 1; i < 5; i++) {
    1.46 +    var addon = new MockAddon("test" + i + "@tests.mozilla.org",
    1.47 +                              "Test Add-on " + i, "extension");
    1.48 +    addon.version = "1.0";
    1.49 +    addon.userDisabled = (i > 2);
    1.50 +    addon.appDisabled = aAppDisabled;
    1.51 +    addon.isActive = !addon.userDisabled && !addon.appDisabled;
    1.52 +
    1.53 +    addon.findUpdates = function(aListener, aReason, aAppVersion, aPlatformVersion) {
    1.54 +      if (aUpdateAvailable) {
    1.55 +        var newAddon = new MockAddon(this.id, this.name, "extension");
    1.56 +        newAddon.version = "2.0";
    1.57 +        var install = new MockInstall(this.name, this.type, newAddon);
    1.58 +        install.existingAddon = this;
    1.59 +        aListener.onUpdateAvailable(this, install);
    1.60 +      }
    1.61 +
    1.62 +      aListener.onUpdateFinished(this, AddonManager.UPDATE_STATUS_NO_ERROR);
    1.63 +    };
    1.64 +
    1.65 +    gProvider.addAddon(addon);
    1.66 +  }
    1.67 +
    1.68 +  gWin = Services.ww.openWindow(null,
    1.69 +                                "chrome://mozapps/content/extensions/selectAddons.xul",
    1.70 +                                "",
    1.71 +                                "chrome,centerscreen,dialog,titlebar",
    1.72 +                                null);
    1.73 +  waitForFocus(function() {
    1.74 +    waitForView("select", function() {
    1.75 +      var row = gWin.document.getElementById("select-rows").firstChild.nextSibling;
    1.76 +      while (row) {
    1.77 +        if (!row.id || row.id.indexOf("@tests.mozilla.org") < 0) {
    1.78 +          // not a test add-on
    1.79 +          row = row.nextSibling;
    1.80 +          continue;
    1.81 +        }
    1.82 +
    1.83 +        if (row.id == "test2@tests.mozilla.org" ||
    1.84 +            row.id == "test4@tests.mozilla.org") {
    1.85 +          row.disable();
    1.86 +        }
    1.87 +        else {
    1.88 +          row.keep();
    1.89 +        }
    1.90 +        row = row.nextSibling;
    1.91 +      }
    1.92 +
    1.93 +      waitForView("confirm", aCallback);
    1.94 +      EventUtils.synthesizeMouseAtCenter(gWin.document.getElementById("next"), {}, gWin);
    1.95 +    });
    1.96 +  }, gWin);
    1.97 +}
    1.98 +
    1.99 +function test() {
   1.100 +  waitForExplicitFinish();
   1.101 +
   1.102 +  run_next_test();
   1.103 +}
   1.104 +
   1.105 +function end_test() {
   1.106 +  finish();
   1.107 +}
   1.108 +
   1.109 +// Test for disabling
   1.110 +add_test(function disabling_test() {
   1.111 +  setupUI(false, false, function() {
   1.112 +    ok(gWin.document.getElementById("incompatible-list").hidden, "Incompatible list should be hidden");
   1.113 +    ok(gWin.document.getElementById("update-list").hidden, "Update list should be hidden");
   1.114 +
   1.115 +    var list = gWin.document.getElementById("disable-list");
   1.116 +    ok(!list.hidden, "Disable list should be visible");
   1.117 +    is(list.childNodes.length, 2, "Should be one add-on getting disabled (plus the header)");
   1.118 +    is(list.childNodes[1].id, "test2@tests.mozilla.org", "Should be the right add-on ID");
   1.119 +    is(list.childNodes[1].getAttribute("name"), "Test Add-on 2", "Should be the right add-on name");
   1.120 +
   1.121 +    var list = gWin.document.getElementById("enable-list");
   1.122 +    ok(!list.hidden, "Enable list should be visible");
   1.123 +    is(list.childNodes.length, 2, "Should be one add-on getting disabled (plus the header)");
   1.124 +    is(list.childNodes[1].id, "test3@tests.mozilla.org", "Should be the right add-on ID");
   1.125 +    is(list.childNodes[1].getAttribute("name"), "Test Add-on 3", "Should be the right add-on name");
   1.126 +
   1.127 +    ok(gWin.document.getElementById("next").hidden, "Next button should be hidden");
   1.128 +    ok(!gWin.document.getElementById("done").hidden, "Done button should be visible");
   1.129 +    gWin.close();
   1.130 +
   1.131 +    run_next_test();
   1.132 +  });
   1.133 +});
   1.134 +
   1.135 +// Test for incompatible
   1.136 +add_test(function incompatible_test() {
   1.137 +  setupUI(true, false, function() {
   1.138 +    ok(gWin.document.getElementById("update-list").hidden, "Update list should be hidden");
   1.139 +    ok(gWin.document.getElementById("disable-list").hidden, "Disable list should be hidden");
   1.140 +    ok(gWin.document.getElementById("enable-list").hidden, "Enable list should be hidden");
   1.141 +
   1.142 +    var list = gWin.document.getElementById("incompatible-list");
   1.143 +    ok(!list.hidden, "Incompatible list should be visible");
   1.144 +    is(list.childNodes.length, 3, "Should be two add-ons waiting to be compatible (plus the header)");
   1.145 +    is(list.childNodes[1].id, "test1@tests.mozilla.org", "Should be the right add-on ID");
   1.146 +    is(list.childNodes[1].getAttribute("name"), "Test Add-on 1", "Should be the right add-on name");
   1.147 +    is(list.childNodes[2].id, "test3@tests.mozilla.org", "Should be the right add-on ID");
   1.148 +    is(list.childNodes[2].getAttribute("name"), "Test Add-on 3", "Should be the right add-on name");
   1.149 +
   1.150 +    ok(gWin.document.getElementById("next").hidden, "Next button should be hidden");
   1.151 +    ok(!gWin.document.getElementById("done").hidden, "Done button should be visible");
   1.152 +    gWin.close();
   1.153 +
   1.154 +    run_next_test();
   1.155 +  });
   1.156 +});
   1.157 +
   1.158 +// Test for updates
   1.159 +add_test(function update_test() {
   1.160 +  setupUI(false, true, function() {
   1.161 +    ok(gWin.document.getElementById("incompatible-list").hidden, "Incompatible list should be hidden");
   1.162 +    ok(gWin.document.getElementById("enable-list").hidden, "Enable list should be hidden");
   1.163 +
   1.164 +    var list = gWin.document.getElementById("update-list");
   1.165 +    ok(!list.hidden, "Update list should be visible");
   1.166 +    is(list.childNodes.length, 3, "Should be two add-ons waiting to be updated (plus the header)");
   1.167 +    is(list.childNodes[1].id, "test1@tests.mozilla.org", "Should be the right add-on ID");
   1.168 +    is(list.childNodes[1].getAttribute("name"), "Test Add-on 1", "Should be the right add-on name");
   1.169 +    is(list.childNodes[2].id, "test3@tests.mozilla.org", "Should be the right add-on ID");
   1.170 +    is(list.childNodes[2].getAttribute("name"), "Test Add-on 3", "Should be the right add-on name");
   1.171 +
   1.172 +    list = gWin.document.getElementById("disable-list");
   1.173 +    ok(!list.hidden, "Disable list should be visible");
   1.174 +    is(list.childNodes.length, 2, "Should be one add-on getting disabled (plus the header)");
   1.175 +    is(list.childNodes[1].id, "test2@tests.mozilla.org", "Should be the right add-on ID");
   1.176 +    is(list.childNodes[1].getAttribute("name"), "Test Add-on 2", "Should be the right add-on name");
   1.177 +
   1.178 +    ok(!gWin.document.getElementById("next").hidden, "Next button should be visible");
   1.179 +    ok(gWin.document.getElementById("done").hidden, "Done button should be hidden");
   1.180 +    gWin.close();
   1.181 +
   1.182 +    run_next_test();
   1.183 +  });
   1.184 +});

mercurial