michael@0: /* Any copyright is dedicated to the Public Domain. michael@0: * http://creativecommons.org/publicdomain/zero/1.0/ michael@0: */ michael@0: michael@0: // Tests the confirmation part of the post-app-update dialog michael@0: michael@0: var gProvider; michael@0: var gWin; michael@0: michael@0: function waitForView(aView, aCallback) { michael@0: var view = gWin.document.getElementById(aView); michael@0: if (view.parentNode.selectedPanel == view) { michael@0: aCallback(); michael@0: return; michael@0: } michael@0: michael@0: view.addEventListener("ViewChanged", function() { michael@0: view.removeEventListener("ViewChanged", arguments.callee, false); michael@0: try { michael@0: aCallback(); michael@0: } michael@0: catch (e) { michael@0: ok(false, e); michael@0: } michael@0: }, false); michael@0: } michael@0: michael@0: /** michael@0: * Creates 4 test add-ons. Two are disabled and two enabled. michael@0: * michael@0: * @param aAppDisabled michael@0: * The appDisabled property for the test add-ons michael@0: * @param aUpdateAvailable michael@0: * True if the test add-ons should claim to have an update available michael@0: */ michael@0: function setupUI(aAppDisabled, aUpdateAvailable, aCallback) { michael@0: if (gProvider) michael@0: gProvider.unregister(); michael@0: michael@0: gProvider = new MockProvider(); michael@0: michael@0: for (var i = 1; i < 5; i++) { michael@0: var addon = new MockAddon("test" + i + "@tests.mozilla.org", michael@0: "Test Add-on " + i, "extension"); michael@0: addon.version = "1.0"; michael@0: addon.userDisabled = (i > 2); michael@0: addon.appDisabled = aAppDisabled; michael@0: addon.isActive = !addon.userDisabled && !addon.appDisabled; michael@0: michael@0: addon.findUpdates = function(aListener, aReason, aAppVersion, aPlatformVersion) { michael@0: if (aUpdateAvailable) { michael@0: var newAddon = new MockAddon(this.id, this.name, "extension"); michael@0: newAddon.version = "2.0"; michael@0: var install = new MockInstall(this.name, this.type, newAddon); michael@0: install.existingAddon = this; michael@0: aListener.onUpdateAvailable(this, install); michael@0: } michael@0: michael@0: aListener.onUpdateFinished(this, AddonManager.UPDATE_STATUS_NO_ERROR); michael@0: }; michael@0: michael@0: gProvider.addAddon(addon); michael@0: } michael@0: michael@0: gWin = Services.ww.openWindow(null, michael@0: "chrome://mozapps/content/extensions/selectAddons.xul", michael@0: "", michael@0: "chrome,centerscreen,dialog,titlebar", michael@0: null); michael@0: waitForFocus(function() { michael@0: waitForView("select", function() { michael@0: var row = gWin.document.getElementById("select-rows").firstChild.nextSibling; michael@0: while (row) { michael@0: if (!row.id || row.id.indexOf("@tests.mozilla.org") < 0) { michael@0: // not a test add-on michael@0: row = row.nextSibling; michael@0: continue; michael@0: } michael@0: michael@0: if (row.id == "test2@tests.mozilla.org" || michael@0: row.id == "test4@tests.mozilla.org") { michael@0: row.disable(); michael@0: } michael@0: else { michael@0: row.keep(); michael@0: } michael@0: row = row.nextSibling; michael@0: } michael@0: michael@0: waitForView("confirm", aCallback); michael@0: EventUtils.synthesizeMouseAtCenter(gWin.document.getElementById("next"), {}, gWin); michael@0: }); michael@0: }, gWin); michael@0: } michael@0: michael@0: function test() { michael@0: waitForExplicitFinish(); michael@0: michael@0: run_next_test(); michael@0: } michael@0: michael@0: function end_test() { michael@0: finish(); michael@0: } michael@0: michael@0: // Test for disabling michael@0: add_test(function disabling_test() { michael@0: setupUI(false, false, function() { michael@0: ok(gWin.document.getElementById("incompatible-list").hidden, "Incompatible list should be hidden"); michael@0: ok(gWin.document.getElementById("update-list").hidden, "Update list should be hidden"); michael@0: michael@0: var list = gWin.document.getElementById("disable-list"); michael@0: ok(!list.hidden, "Disable list should be visible"); michael@0: is(list.childNodes.length, 2, "Should be one add-on getting disabled (plus the header)"); michael@0: is(list.childNodes[1].id, "test2@tests.mozilla.org", "Should be the right add-on ID"); michael@0: is(list.childNodes[1].getAttribute("name"), "Test Add-on 2", "Should be the right add-on name"); michael@0: michael@0: var list = gWin.document.getElementById("enable-list"); michael@0: ok(!list.hidden, "Enable list should be visible"); michael@0: is(list.childNodes.length, 2, "Should be one add-on getting disabled (plus the header)"); michael@0: is(list.childNodes[1].id, "test3@tests.mozilla.org", "Should be the right add-on ID"); michael@0: is(list.childNodes[1].getAttribute("name"), "Test Add-on 3", "Should be the right add-on name"); michael@0: michael@0: ok(gWin.document.getElementById("next").hidden, "Next button should be hidden"); michael@0: ok(!gWin.document.getElementById("done").hidden, "Done button should be visible"); michael@0: gWin.close(); michael@0: michael@0: run_next_test(); michael@0: }); michael@0: }); michael@0: michael@0: // Test for incompatible michael@0: add_test(function incompatible_test() { michael@0: setupUI(true, false, function() { michael@0: ok(gWin.document.getElementById("update-list").hidden, "Update list should be hidden"); michael@0: ok(gWin.document.getElementById("disable-list").hidden, "Disable list should be hidden"); michael@0: ok(gWin.document.getElementById("enable-list").hidden, "Enable list should be hidden"); michael@0: michael@0: var list = gWin.document.getElementById("incompatible-list"); michael@0: ok(!list.hidden, "Incompatible list should be visible"); michael@0: is(list.childNodes.length, 3, "Should be two add-ons waiting to be compatible (plus the header)"); michael@0: is(list.childNodes[1].id, "test1@tests.mozilla.org", "Should be the right add-on ID"); michael@0: is(list.childNodes[1].getAttribute("name"), "Test Add-on 1", "Should be the right add-on name"); michael@0: is(list.childNodes[2].id, "test3@tests.mozilla.org", "Should be the right add-on ID"); michael@0: is(list.childNodes[2].getAttribute("name"), "Test Add-on 3", "Should be the right add-on name"); michael@0: michael@0: ok(gWin.document.getElementById("next").hidden, "Next button should be hidden"); michael@0: ok(!gWin.document.getElementById("done").hidden, "Done button should be visible"); michael@0: gWin.close(); michael@0: michael@0: run_next_test(); michael@0: }); michael@0: }); michael@0: michael@0: // Test for updates michael@0: add_test(function update_test() { michael@0: setupUI(false, true, function() { michael@0: ok(gWin.document.getElementById("incompatible-list").hidden, "Incompatible list should be hidden"); michael@0: ok(gWin.document.getElementById("enable-list").hidden, "Enable list should be hidden"); michael@0: michael@0: var list = gWin.document.getElementById("update-list"); michael@0: ok(!list.hidden, "Update list should be visible"); michael@0: is(list.childNodes.length, 3, "Should be two add-ons waiting to be updated (plus the header)"); michael@0: is(list.childNodes[1].id, "test1@tests.mozilla.org", "Should be the right add-on ID"); michael@0: is(list.childNodes[1].getAttribute("name"), "Test Add-on 1", "Should be the right add-on name"); michael@0: is(list.childNodes[2].id, "test3@tests.mozilla.org", "Should be the right add-on ID"); michael@0: is(list.childNodes[2].getAttribute("name"), "Test Add-on 3", "Should be the right add-on name"); michael@0: michael@0: list = gWin.document.getElementById("disable-list"); michael@0: ok(!list.hidden, "Disable list should be visible"); michael@0: is(list.childNodes.length, 2, "Should be one add-on getting disabled (plus the header)"); michael@0: is(list.childNodes[1].id, "test2@tests.mozilla.org", "Should be the right add-on ID"); michael@0: is(list.childNodes[1].getAttribute("name"), "Test Add-on 2", "Should be the right add-on name"); michael@0: michael@0: ok(!gWin.document.getElementById("next").hidden, "Next button should be visible"); michael@0: ok(gWin.document.getElementById("done").hidden, "Done button should be hidden"); michael@0: gWin.close(); michael@0: michael@0: run_next_test(); michael@0: }); michael@0: });