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 confirmation 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 | try { |
michael@0 | 20 | aCallback(); |
michael@0 | 21 | } |
michael@0 | 22 | catch (e) { |
michael@0 | 23 | ok(false, e); |
michael@0 | 24 | } |
michael@0 | 25 | }, false); |
michael@0 | 26 | } |
michael@0 | 27 | |
michael@0 | 28 | /** |
michael@0 | 29 | * Creates 4 test add-ons. Two are disabled and two enabled. |
michael@0 | 30 | * |
michael@0 | 31 | * @param aAppDisabled |
michael@0 | 32 | * The appDisabled property for the test add-ons |
michael@0 | 33 | * @param aUpdateAvailable |
michael@0 | 34 | * True if the test add-ons should claim to have an update available |
michael@0 | 35 | */ |
michael@0 | 36 | function setupUI(aAppDisabled, aUpdateAvailable, aCallback) { |
michael@0 | 37 | if (gProvider) |
michael@0 | 38 | gProvider.unregister(); |
michael@0 | 39 | |
michael@0 | 40 | gProvider = new MockProvider(); |
michael@0 | 41 | |
michael@0 | 42 | for (var i = 1; i < 5; i++) { |
michael@0 | 43 | var addon = new MockAddon("test" + i + "@tests.mozilla.org", |
michael@0 | 44 | "Test Add-on " + i, "extension"); |
michael@0 | 45 | addon.version = "1.0"; |
michael@0 | 46 | addon.userDisabled = (i > 2); |
michael@0 | 47 | addon.appDisabled = aAppDisabled; |
michael@0 | 48 | addon.isActive = !addon.userDisabled && !addon.appDisabled; |
michael@0 | 49 | |
michael@0 | 50 | addon.findUpdates = function(aListener, aReason, aAppVersion, aPlatformVersion) { |
michael@0 | 51 | if (aUpdateAvailable) { |
michael@0 | 52 | var newAddon = new MockAddon(this.id, this.name, "extension"); |
michael@0 | 53 | newAddon.version = "2.0"; |
michael@0 | 54 | var install = new MockInstall(this.name, this.type, newAddon); |
michael@0 | 55 | install.existingAddon = this; |
michael@0 | 56 | aListener.onUpdateAvailable(this, install); |
michael@0 | 57 | } |
michael@0 | 58 | |
michael@0 | 59 | aListener.onUpdateFinished(this, AddonManager.UPDATE_STATUS_NO_ERROR); |
michael@0 | 60 | }; |
michael@0 | 61 | |
michael@0 | 62 | gProvider.addAddon(addon); |
michael@0 | 63 | } |
michael@0 | 64 | |
michael@0 | 65 | gWin = Services.ww.openWindow(null, |
michael@0 | 66 | "chrome://mozapps/content/extensions/selectAddons.xul", |
michael@0 | 67 | "", |
michael@0 | 68 | "chrome,centerscreen,dialog,titlebar", |
michael@0 | 69 | null); |
michael@0 | 70 | waitForFocus(function() { |
michael@0 | 71 | waitForView("select", function() { |
michael@0 | 72 | var row = gWin.document.getElementById("select-rows").firstChild.nextSibling; |
michael@0 | 73 | while (row) { |
michael@0 | 74 | if (!row.id || row.id.indexOf("@tests.mozilla.org") < 0) { |
michael@0 | 75 | // not a test add-on |
michael@0 | 76 | row = row.nextSibling; |
michael@0 | 77 | continue; |
michael@0 | 78 | } |
michael@0 | 79 | |
michael@0 | 80 | if (row.id == "test2@tests.mozilla.org" || |
michael@0 | 81 | row.id == "test4@tests.mozilla.org") { |
michael@0 | 82 | row.disable(); |
michael@0 | 83 | } |
michael@0 | 84 | else { |
michael@0 | 85 | row.keep(); |
michael@0 | 86 | } |
michael@0 | 87 | row = row.nextSibling; |
michael@0 | 88 | } |
michael@0 | 89 | |
michael@0 | 90 | waitForView("confirm", aCallback); |
michael@0 | 91 | EventUtils.synthesizeMouseAtCenter(gWin.document.getElementById("next"), {}, gWin); |
michael@0 | 92 | }); |
michael@0 | 93 | }, gWin); |
michael@0 | 94 | } |
michael@0 | 95 | |
michael@0 | 96 | function test() { |
michael@0 | 97 | waitForExplicitFinish(); |
michael@0 | 98 | |
michael@0 | 99 | run_next_test(); |
michael@0 | 100 | } |
michael@0 | 101 | |
michael@0 | 102 | function end_test() { |
michael@0 | 103 | finish(); |
michael@0 | 104 | } |
michael@0 | 105 | |
michael@0 | 106 | // Test for disabling |
michael@0 | 107 | add_test(function disabling_test() { |
michael@0 | 108 | setupUI(false, false, function() { |
michael@0 | 109 | ok(gWin.document.getElementById("incompatible-list").hidden, "Incompatible list should be hidden"); |
michael@0 | 110 | ok(gWin.document.getElementById("update-list").hidden, "Update list should be hidden"); |
michael@0 | 111 | |
michael@0 | 112 | var list = gWin.document.getElementById("disable-list"); |
michael@0 | 113 | ok(!list.hidden, "Disable list should be visible"); |
michael@0 | 114 | is(list.childNodes.length, 2, "Should be one add-on getting disabled (plus the header)"); |
michael@0 | 115 | is(list.childNodes[1].id, "test2@tests.mozilla.org", "Should be the right add-on ID"); |
michael@0 | 116 | is(list.childNodes[1].getAttribute("name"), "Test Add-on 2", "Should be the right add-on name"); |
michael@0 | 117 | |
michael@0 | 118 | var list = gWin.document.getElementById("enable-list"); |
michael@0 | 119 | ok(!list.hidden, "Enable list should be visible"); |
michael@0 | 120 | is(list.childNodes.length, 2, "Should be one add-on getting disabled (plus the header)"); |
michael@0 | 121 | is(list.childNodes[1].id, "test3@tests.mozilla.org", "Should be the right add-on ID"); |
michael@0 | 122 | is(list.childNodes[1].getAttribute("name"), "Test Add-on 3", "Should be the right add-on name"); |
michael@0 | 123 | |
michael@0 | 124 | ok(gWin.document.getElementById("next").hidden, "Next button should be hidden"); |
michael@0 | 125 | ok(!gWin.document.getElementById("done").hidden, "Done button should be visible"); |
michael@0 | 126 | gWin.close(); |
michael@0 | 127 | |
michael@0 | 128 | run_next_test(); |
michael@0 | 129 | }); |
michael@0 | 130 | }); |
michael@0 | 131 | |
michael@0 | 132 | // Test for incompatible |
michael@0 | 133 | add_test(function incompatible_test() { |
michael@0 | 134 | setupUI(true, false, function() { |
michael@0 | 135 | ok(gWin.document.getElementById("update-list").hidden, "Update list should be hidden"); |
michael@0 | 136 | ok(gWin.document.getElementById("disable-list").hidden, "Disable list should be hidden"); |
michael@0 | 137 | ok(gWin.document.getElementById("enable-list").hidden, "Enable list should be hidden"); |
michael@0 | 138 | |
michael@0 | 139 | var list = gWin.document.getElementById("incompatible-list"); |
michael@0 | 140 | ok(!list.hidden, "Incompatible list should be visible"); |
michael@0 | 141 | is(list.childNodes.length, 3, "Should be two add-ons waiting to be compatible (plus the header)"); |
michael@0 | 142 | is(list.childNodes[1].id, "test1@tests.mozilla.org", "Should be the right add-on ID"); |
michael@0 | 143 | is(list.childNodes[1].getAttribute("name"), "Test Add-on 1", "Should be the right add-on name"); |
michael@0 | 144 | is(list.childNodes[2].id, "test3@tests.mozilla.org", "Should be the right add-on ID"); |
michael@0 | 145 | is(list.childNodes[2].getAttribute("name"), "Test Add-on 3", "Should be the right add-on name"); |
michael@0 | 146 | |
michael@0 | 147 | ok(gWin.document.getElementById("next").hidden, "Next button should be hidden"); |
michael@0 | 148 | ok(!gWin.document.getElementById("done").hidden, "Done button should be visible"); |
michael@0 | 149 | gWin.close(); |
michael@0 | 150 | |
michael@0 | 151 | run_next_test(); |
michael@0 | 152 | }); |
michael@0 | 153 | }); |
michael@0 | 154 | |
michael@0 | 155 | // Test for updates |
michael@0 | 156 | add_test(function update_test() { |
michael@0 | 157 | setupUI(false, true, function() { |
michael@0 | 158 | ok(gWin.document.getElementById("incompatible-list").hidden, "Incompatible list should be hidden"); |
michael@0 | 159 | ok(gWin.document.getElementById("enable-list").hidden, "Enable list should be hidden"); |
michael@0 | 160 | |
michael@0 | 161 | var list = gWin.document.getElementById("update-list"); |
michael@0 | 162 | ok(!list.hidden, "Update list should be visible"); |
michael@0 | 163 | is(list.childNodes.length, 3, "Should be two add-ons waiting to be updated (plus the header)"); |
michael@0 | 164 | is(list.childNodes[1].id, "test1@tests.mozilla.org", "Should be the right add-on ID"); |
michael@0 | 165 | is(list.childNodes[1].getAttribute("name"), "Test Add-on 1", "Should be the right add-on name"); |
michael@0 | 166 | is(list.childNodes[2].id, "test3@tests.mozilla.org", "Should be the right add-on ID"); |
michael@0 | 167 | is(list.childNodes[2].getAttribute("name"), "Test Add-on 3", "Should be the right add-on name"); |
michael@0 | 168 | |
michael@0 | 169 | list = gWin.document.getElementById("disable-list"); |
michael@0 | 170 | ok(!list.hidden, "Disable list should be visible"); |
michael@0 | 171 | is(list.childNodes.length, 2, "Should be one add-on getting disabled (plus the header)"); |
michael@0 | 172 | is(list.childNodes[1].id, "test2@tests.mozilla.org", "Should be the right add-on ID"); |
michael@0 | 173 | is(list.childNodes[1].getAttribute("name"), "Test Add-on 2", "Should be the right add-on name"); |
michael@0 | 174 | |
michael@0 | 175 | ok(!gWin.document.getElementById("next").hidden, "Next button should be visible"); |
michael@0 | 176 | ok(gWin.document.getElementById("done").hidden, "Done button should be hidden"); |
michael@0 | 177 | gWin.close(); |
michael@0 | 178 | |
michael@0 | 179 | run_next_test(); |
michael@0 | 180 | }); |
michael@0 | 181 | }); |