diff options
author | Matt A. Tobin <email@mattatobin.com> | 2018-02-10 04:00:58 -0500 |
---|---|---|
committer | Matt A. Tobin <email@mattatobin.com> | 2018-02-10 04:00:58 -0500 |
commit | deea787c2efbb9c89caec8d9efc023ffafe75613 (patch) | |
tree | 6dbe55f7d24e67ecdcc821b8c5492f6c17217852 /toolkit/mozapps/extensions/test/browser/browser_select_update.js | |
parent | 37d5300335d81cecbecc99812747a657588c63eb (diff) | |
download | UXP-deea787c2efbb9c89caec8d9efc023ffafe75613.tar UXP-deea787c2efbb9c89caec8d9efc023ffafe75613.tar.gz UXP-deea787c2efbb9c89caec8d9efc023ffafe75613.tar.lz UXP-deea787c2efbb9c89caec8d9efc023ffafe75613.tar.xz UXP-deea787c2efbb9c89caec8d9efc023ffafe75613.zip |
Import Tycho's Add-on Manager
Diffstat (limited to 'toolkit/mozapps/extensions/test/browser/browser_select_update.js')
-rw-r--r-- | toolkit/mozapps/extensions/test/browser/browser_select_update.js | 181 |
1 files changed, 181 insertions, 0 deletions
diff --git a/toolkit/mozapps/extensions/test/browser/browser_select_update.js b/toolkit/mozapps/extensions/test/browser/browser_select_update.js new file mode 100644 index 000000000..58f1de687 --- /dev/null +++ b/toolkit/mozapps/extensions/test/browser/browser_select_update.js @@ -0,0 +1,181 @@ +/* Any copyright is dedicated to the Public Domain. + * http://creativecommons.org/publicdomain/zero/1.0/ + */ + +// Tests the update part of the post-app-update dialog + +var gProvider; +var gWin; + +function waitForView(aView, aCallback) { + var view = gWin.document.getElementById(aView); + if (view.parentNode.selectedPanel == view) { + aCallback(); + return; + } + + view.addEventListener("ViewChanged", function() { + view.removeEventListener("ViewChanged", arguments.callee, false); + aCallback(); + }, false); +} + +function waitForClose(aCallback) { + gWin.addEventListener("unload", function() { + gWin.removeEventListener("unload", arguments.callee, false); + + aCallback(); + }, false); +} + +/** + * Creates 4 test add-ons. Two are disabled and two enabled. + */ +function setupUI(aFailDownloads, aFailInstalls, aCallback) { + if (gProvider) + gProvider.unregister(); + + gProvider = new MockProvider(); + + for (var i = 1; i < 5; i++) { + var addon = new MockAddon("test" + i + "@tests.mozilla.org", + "Test Add-on " + i, "extension"); + addon.version = "1.0"; + addon.userDisabled = (i > 2); + addon.appDisabled = false; + addon.isActive = !addon.userDisabled && !addon.appDisabled; + + addon.findUpdates = function(aListener, aReason, aAppVersion, aPlatformVersion) { + var newAddon = new MockAddon(this.id, this.name, "extension"); + newAddon.version = "2.0"; + var install = new MockInstall(this.name, this.type, newAddon); + install.existingAddon = this; + + install.install = function() { + this.state = AddonManager.STATE_DOWNLOADING; + this.callListeners("onDownloadStarted"); + + var self = this; + executeSoon(function() { + if (aFailDownloads) { + self.state = AddonManager.STATE_DOWNLOAD_FAILED; + self.callListeners("onDownloadFailed"); + return; + } + + self.type = self._type; + self.addon = new MockAddon(self.existingAddon.id, self.name, self.type); + self.addon.version = self.version; + self.addon.pendingOperations = AddonManager.PENDING_INSTALL; + self.addon.install = self; + + self.existingAddon.pendingUpgrade = self.addon; + self.existingAddon.pendingOperations |= AddonManager.PENDING_UPGRADE; + + self.state = AddonManager.STATE_DOWNLOADED; + self.callListeners("onDownloadEnded"); + + self.state = AddonManager.STATE_INSTALLING; + self.callListeners("onInstallStarted"); + + if (aFailInstalls) { + self.state = AddonManager.STATE_INSTALL_FAILED; + self.callListeners("onInstallFailed"); + return; + } + + self.state = AddonManager.STATE_INSTALLED; + self.callListeners("onInstallEnded"); + }); + } + + aListener.onUpdateAvailable(this, install); + + aListener.onUpdateFinished(this, AddonManager.UPDATE_STATUS_NO_ERROR); + }; + + gProvider.addAddon(addon); + } + + gWin = Services.ww.openWindow(null, + "chrome://mozapps/content/extensions/selectAddons.xul", + "", + "chrome,centerscreen,dialog,titlebar", + null); + waitForFocus(function() { + waitForView("select", function() { + var row = gWin.document.getElementById("select-rows").firstChild.nextSibling; + while (row) { + if (!row.id || row.id.indexOf("@tests.mozilla.org") < 0) { + // not a test add-on + row = row.nextSibling; + continue; + } + + if (row.id == "test2@tests.mozilla.org" || + row.id == "test4@tests.mozilla.org") { + row.disable(); + } + else { + row.keep(); + } + row = row.nextSibling; + } + + waitForView("confirm", function() { + waitForView("update", aCallback); + EventUtils.synthesizeMouseAtCenter(gWin.document.getElementById("next"), {}, gWin); + }); + EventUtils.synthesizeMouseAtCenter(gWin.document.getElementById("next"), {}, gWin); + }); + }, gWin); +} + +function test() { + waitForExplicitFinish(); + run_next_test(); +} + +function end_test() { + finish(); +} + +// Test for working updates +add_test(function working_test() { + setupUI(false, false, function() { + waitForClose(function() { + is(gWin.document.getElementById("update-progress").value, 2, "Should have finished 2 downloads"); + run_next_test(); + }); + + EventUtils.synthesizeMouseAtCenter(gWin.document.getElementById("next"), {}, gWin); + }); +}); + +// Test for failed updates +add_test(function working_test() { + setupUI(true, false, function() { + waitForView("errors", function() { + is(gWin.document.getElementById("update-progress").value, 2, "Should have finished 2 downloads"); + gWin.close(); + + run_next_test(); + }); + + EventUtils.synthesizeMouseAtCenter(gWin.document.getElementById("next"), {}, gWin); + }); +}); + +// Test for failed updates +add_test(function working_test() { + setupUI(false, true, function() { + waitForView("errors", function() { + is(gWin.document.getElementById("update-progress").value, 2, "Should have finished 2 downloads"); + gWin.close(); + + run_next_test(); + }); + + EventUtils.synthesizeMouseAtCenter(gWin.document.getElementById("next"), {}, gWin); + }); +}); |