Wed, 31 Dec 2014 06:09:35 +0100
Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.
michael@0 | 1 | /* Any copyright is dedicated to the Public Domain. |
michael@0 | 2 | * http://creativecommons.org/publicdomain/zero/1.0/ |
michael@0 | 3 | */ |
michael@0 | 4 | |
michael@0 | 5 | // Tests the update part of the post-app-update dialog |
michael@0 | 6 | |
michael@0 | 7 | var gProvider; |
michael@0 | 8 | var gWin; |
michael@0 | 9 | |
michael@0 | 10 | function waitForView(aView, aCallback) { |
michael@0 | 11 | var view = gWin.document.getElementById(aView); |
michael@0 | 12 | if (view.parentNode.selectedPanel == view) { |
michael@0 | 13 | aCallback(); |
michael@0 | 14 | return; |
michael@0 | 15 | } |
michael@0 | 16 | |
michael@0 | 17 | view.addEventListener("ViewChanged", function() { |
michael@0 | 18 | view.removeEventListener("ViewChanged", arguments.callee, false); |
michael@0 | 19 | aCallback(); |
michael@0 | 20 | }, false); |
michael@0 | 21 | } |
michael@0 | 22 | |
michael@0 | 23 | function waitForClose(aCallback) { |
michael@0 | 24 | gWin.addEventListener("unload", function() { |
michael@0 | 25 | gWin.removeEventListener("unload", arguments.callee, false); |
michael@0 | 26 | |
michael@0 | 27 | aCallback(); |
michael@0 | 28 | }, false); |
michael@0 | 29 | } |
michael@0 | 30 | |
michael@0 | 31 | /** |
michael@0 | 32 | * Creates 4 test add-ons. Two are disabled and two enabled. |
michael@0 | 33 | */ |
michael@0 | 34 | function setupUI(aFailDownloads, aFailInstalls, aCallback) { |
michael@0 | 35 | if (gProvider) |
michael@0 | 36 | gProvider.unregister(); |
michael@0 | 37 | |
michael@0 | 38 | gProvider = new MockProvider(); |
michael@0 | 39 | |
michael@0 | 40 | for (var i = 1; i < 5; i++) { |
michael@0 | 41 | var addon = new MockAddon("test" + i + "@tests.mozilla.org", |
michael@0 | 42 | "Test Add-on " + i, "extension"); |
michael@0 | 43 | addon.version = "1.0"; |
michael@0 | 44 | addon.userDisabled = (i > 2); |
michael@0 | 45 | addon.appDisabled = false; |
michael@0 | 46 | addon.isActive = !addon.userDisabled && !addon.appDisabled; |
michael@0 | 47 | |
michael@0 | 48 | addon.findUpdates = function(aListener, aReason, aAppVersion, aPlatformVersion) { |
michael@0 | 49 | var newAddon = new MockAddon(this.id, this.name, "extension"); |
michael@0 | 50 | newAddon.version = "2.0"; |
michael@0 | 51 | var install = new MockInstall(this.name, this.type, newAddon); |
michael@0 | 52 | install.existingAddon = this; |
michael@0 | 53 | |
michael@0 | 54 | install.install = function() { |
michael@0 | 55 | this.state = AddonManager.STATE_DOWNLOADING; |
michael@0 | 56 | this.callListeners("onDownloadStarted"); |
michael@0 | 57 | |
michael@0 | 58 | var self = this; |
michael@0 | 59 | executeSoon(function() { |
michael@0 | 60 | if (aFailDownloads) { |
michael@0 | 61 | self.state = AddonManager.STATE_DOWNLOAD_FAILED; |
michael@0 | 62 | self.callListeners("onDownloadFailed"); |
michael@0 | 63 | return; |
michael@0 | 64 | } |
michael@0 | 65 | |
michael@0 | 66 | self.type = self._type; |
michael@0 | 67 | self.addon = new MockAddon(self.existingAddon.id, self.name, self.type); |
michael@0 | 68 | self.addon.version = self.version; |
michael@0 | 69 | self.addon.pendingOperations = AddonManager.PENDING_INSTALL; |
michael@0 | 70 | self.addon.install = self; |
michael@0 | 71 | |
michael@0 | 72 | self.existingAddon.pendingUpgrade = self.addon; |
michael@0 | 73 | self.existingAddon.pendingOperations |= AddonManager.PENDING_UPGRADE; |
michael@0 | 74 | |
michael@0 | 75 | self.state = AddonManager.STATE_DOWNLOADED; |
michael@0 | 76 | self.callListeners("onDownloadEnded"); |
michael@0 | 77 | |
michael@0 | 78 | self.state = AddonManager.STATE_INSTALLING; |
michael@0 | 79 | self.callListeners("onInstallStarted"); |
michael@0 | 80 | |
michael@0 | 81 | if (aFailInstalls) { |
michael@0 | 82 | self.state = AddonManager.STATE_INSTALL_FAILED; |
michael@0 | 83 | self.callListeners("onInstallFailed"); |
michael@0 | 84 | return; |
michael@0 | 85 | } |
michael@0 | 86 | |
michael@0 | 87 | self.state = AddonManager.STATE_INSTALLED; |
michael@0 | 88 | self.callListeners("onInstallEnded"); |
michael@0 | 89 | }); |
michael@0 | 90 | } |
michael@0 | 91 | |
michael@0 | 92 | aListener.onUpdateAvailable(this, install); |
michael@0 | 93 | |
michael@0 | 94 | aListener.onUpdateFinished(this, AddonManager.UPDATE_STATUS_NO_ERROR); |
michael@0 | 95 | }; |
michael@0 | 96 | |
michael@0 | 97 | gProvider.addAddon(addon); |
michael@0 | 98 | } |
michael@0 | 99 | |
michael@0 | 100 | gWin = Services.ww.openWindow(null, |
michael@0 | 101 | "chrome://mozapps/content/extensions/selectAddons.xul", |
michael@0 | 102 | "", |
michael@0 | 103 | "chrome,centerscreen,dialog,titlebar", |
michael@0 | 104 | null); |
michael@0 | 105 | waitForFocus(function() { |
michael@0 | 106 | waitForView("select", function() { |
michael@0 | 107 | var row = gWin.document.getElementById("select-rows").firstChild.nextSibling; |
michael@0 | 108 | while (row) { |
michael@0 | 109 | if (!row.id || row.id.indexOf("@tests.mozilla.org") < 0) { |
michael@0 | 110 | // not a test add-on |
michael@0 | 111 | row = row.nextSibling; |
michael@0 | 112 | continue; |
michael@0 | 113 | } |
michael@0 | 114 | |
michael@0 | 115 | if (row.id == "test2@tests.mozilla.org" || |
michael@0 | 116 | row.id == "test4@tests.mozilla.org") { |
michael@0 | 117 | row.disable(); |
michael@0 | 118 | } |
michael@0 | 119 | else { |
michael@0 | 120 | row.keep(); |
michael@0 | 121 | } |
michael@0 | 122 | row = row.nextSibling; |
michael@0 | 123 | } |
michael@0 | 124 | |
michael@0 | 125 | waitForView("confirm", function() { |
michael@0 | 126 | waitForView("update", aCallback); |
michael@0 | 127 | EventUtils.synthesizeMouseAtCenter(gWin.document.getElementById("next"), {}, gWin); |
michael@0 | 128 | }); |
michael@0 | 129 | EventUtils.synthesizeMouseAtCenter(gWin.document.getElementById("next"), {}, gWin); |
michael@0 | 130 | }); |
michael@0 | 131 | }, gWin); |
michael@0 | 132 | } |
michael@0 | 133 | |
michael@0 | 134 | function test() { |
michael@0 | 135 | waitForExplicitFinish(); |
michael@0 | 136 | run_next_test(); |
michael@0 | 137 | } |
michael@0 | 138 | |
michael@0 | 139 | function end_test() { |
michael@0 | 140 | finish(); |
michael@0 | 141 | } |
michael@0 | 142 | |
michael@0 | 143 | // Test for working updates |
michael@0 | 144 | add_test(function working_test() { |
michael@0 | 145 | setupUI(false, false, function() { |
michael@0 | 146 | waitForClose(function() { |
michael@0 | 147 | is(gWin.document.getElementById("update-progress").value, 2, "Should have finished 2 downloads"); |
michael@0 | 148 | run_next_test(); |
michael@0 | 149 | }); |
michael@0 | 150 | |
michael@0 | 151 | EventUtils.synthesizeMouseAtCenter(gWin.document.getElementById("next"), {}, gWin); |
michael@0 | 152 | }); |
michael@0 | 153 | }); |
michael@0 | 154 | |
michael@0 | 155 | // Test for failed updates |
michael@0 | 156 | add_test(function working_test() { |
michael@0 | 157 | setupUI(true, false, function() { |
michael@0 | 158 | waitForView("errors", function() { |
michael@0 | 159 | is(gWin.document.getElementById("update-progress").value, 2, "Should have finished 2 downloads"); |
michael@0 | 160 | gWin.close(); |
michael@0 | 161 | |
michael@0 | 162 | run_next_test(); |
michael@0 | 163 | }); |
michael@0 | 164 | |
michael@0 | 165 | EventUtils.synthesizeMouseAtCenter(gWin.document.getElementById("next"), {}, gWin); |
michael@0 | 166 | }); |
michael@0 | 167 | }); |
michael@0 | 168 | |
michael@0 | 169 | // Test for failed updates |
michael@0 | 170 | add_test(function working_test() { |
michael@0 | 171 | setupUI(false, true, function() { |
michael@0 | 172 | waitForView("errors", function() { |
michael@0 | 173 | is(gWin.document.getElementById("update-progress").value, 2, "Should have finished 2 downloads"); |
michael@0 | 174 | gWin.close(); |
michael@0 | 175 | |
michael@0 | 176 | run_next_test(); |
michael@0 | 177 | }); |
michael@0 | 178 | |
michael@0 | 179 | EventUtils.synthesizeMouseAtCenter(gWin.document.getElementById("next"), {}, gWin); |
michael@0 | 180 | }); |
michael@0 | 181 | }); |