1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/toolkit/mozapps/plugins/tests/browser_bug435788.js Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,461 @@ 1.4 +const TEST_ROOT = "http://example.com/browser/toolkit/mozapps/plugins/tests/"; 1.5 + 1.6 +let tmp = {}; 1.7 +Components.utils.import("resource://gre/modules/AddonManager.jsm", tmp); 1.8 +let AddonManager = tmp.AddonManager; 1.9 + 1.10 +var gPFS; 1.11 + 1.12 +function test() { 1.13 + waitForExplicitFinish(); 1.14 + 1.15 + prepare_test_1(); 1.16 +} 1.17 + 1.18 +function finishTest() { 1.19 + Services.prefs.clearUserPref("pfs.datasource.url"); 1.20 + finish(); 1.21 +} 1.22 + 1.23 +// Gets the number of plugin items in the detected list 1.24 +function getListCount() { 1.25 + var list = gPFS.document.getElementById("pluginList"); 1.26 + return list.childNodes.length; 1.27 +} 1.28 + 1.29 +// Gets wether the list contains a particular plugin name 1.30 +function hasListItem(name, version) { 1.31 + var label = name + " " + (version ? version : ""); 1.32 + var list = gPFS.document.getElementById("pluginList"); 1.33 + for (var i = 0; i < list.childNodes.length; i++) { 1.34 + if (list.childNodes[i].label == label) 1.35 + return true; 1.36 + } 1.37 + return false; 1.38 +} 1.39 + 1.40 +// Gets the number of plugin results 1.41 +function getResultCount() { 1.42 + var list = gPFS.document.getElementById("pluginResultList"); 1.43 + return list.childNodes.length; 1.44 +} 1.45 + 1.46 +// Gets the plugin result for a particular plugin name 1.47 +function getResultItem(name, version) { 1.48 + var label = name + " " + (version ? version : ""); 1.49 + var list = gPFS.document.getElementById("pluginResultList"); 1.50 + for (var i = 0; i < list.childNodes.length; i++) { 1.51 + if (list.childNodes[i].childNodes[1].value == label) { 1.52 + var item = { 1.53 + name: name, 1.54 + version: version, 1.55 + status: null 1.56 + }; 1.57 + if (list.childNodes[i].childNodes[2].tagName == "label") 1.58 + item.status = list.childNodes[i].childNodes[2].value; 1.59 + return item; 1.60 + } 1.61 + } 1.62 + return null; 1.63 +} 1.64 + 1.65 +// Logs the currently displaying wizard page 1.66 +function page_shown() { 1.67 + function show_button_state(name) { 1.68 + var button = gPFS.document.documentElement.getButton(name); 1.69 + info("Button " + name + ". hidden: " + button.hidden + 1.70 + ", disabled: " + button.disabled); 1.71 + } 1.72 + 1.73 + info("Page shown: " + 1.74 + gPFS.document.documentElement.currentPage.getAttribute("label")); 1.75 + show_button_state("next"); 1.76 + show_button_state("finish"); 1.77 +} 1.78 + 1.79 +function pfs_loaded() { 1.80 + info("PFS loaded"); 1.81 + var docEle = gPFS.document.documentElement; 1.82 + 1.83 + var onwizardfinish = function () { 1.84 + info("wizardfinish event"); 1.85 + }; 1.86 + var onwizardnext = function () { 1.87 + info("wizardnext event"); 1.88 + }; 1.89 + 1.90 + docEle.addEventListener("pageshow", page_shown, false); 1.91 + docEle.addEventListener("wizardfinish", onwizardfinish, false); 1.92 + docEle.addEventListener("wizardnext", onwizardnext, false); 1.93 + 1.94 + gPFS.addEventListener("unload", function() { 1.95 + info("unload event"); 1.96 + gPFS.removeEventListener("unload", arguments.callee, false); 1.97 + docEle.removeEventListener("pageshow", page_shown, false); 1.98 + docEle.removeEventListener("wizardfinish", onwizardfinish, false); 1.99 + docEle.removeEventListener("wizardnext", onwizardnext, false); 1.100 + }, false); 1.101 + 1.102 + page_shown(); 1.103 +} 1.104 + 1.105 +function startTest(num, missingPluginsArray) { 1.106 + info("Test " + num); 1.107 + 1.108 + gPFS = window.openDialog("chrome://mozapps/content/plugins/pluginInstallerWizard.xul", 1.109 + "PFSWindow", "chrome,centerscreen,resizable=yes", 1.110 + {plugins: missingPluginsArray}); 1.111 + 1.112 + var testScope = this; 1.113 + 1.114 + gPFS.addEventListener("load", function () { 1.115 + gPFS.removeEventListener("load", arguments.callee, false); 1.116 + 1.117 + pfs_loaded(); 1.118 + 1.119 + var seenAvailable = false; 1.120 + var expectAvailable = typeof testScope["test_" + num + "_available"] == "function"; 1.121 + 1.122 + function availableListener() { 1.123 + seenAvailable = true; 1.124 + 1.125 + if (expectAvailable) { 1.126 + executeSoon(function () { 1.127 + testScope["test_" + num + "_available"](); 1.128 + gPFS.document.documentElement.getButton("next").click(); 1.129 + }); 1.130 + } else { 1.131 + ok(false, "Should not have found plugins to install"); 1.132 + } 1.133 + } 1.134 + 1.135 + function completeListener() { 1.136 + if (expectAvailable) 1.137 + ok(seenAvailable, "Should have seen the list of available plugins"); 1.138 + 1.139 + executeSoon(testScope["test_" + num + "_complete"]); 1.140 + } 1.141 + 1.142 + gPFS.document.documentElement.wizardPages[1].addEventListener("pageshow", availableListener); 1.143 + gPFS.document.documentElement.wizardPages[4].addEventListener("pageshow", completeListener); 1.144 + 1.145 + gPFS.addEventListener("unload", function () { 1.146 + gPFS.removeEventListener("unload", arguments.callee, false); 1.147 + gPFS.document.documentElement.wizardPages[1].removeEventListener("pageshow", availableListener, false); 1.148 + gPFS.document.documentElement.wizardPages[4].removeEventListener("pageshow", completeListener, false); 1.149 + 1.150 + num++; 1.151 + if (typeof testScope["prepare_test_" + num] == "function") 1.152 + testScope["prepare_test_" + num](); 1.153 + else 1.154 + finishTest(); 1.155 + }); 1.156 + }); 1.157 +} 1.158 + 1.159 +function clickFinish() { 1.160 + var finish = gPFS.document.documentElement.getButton("finish"); 1.161 + ok(!finish.hidden, "Finish button should not be hidden"); 1.162 + ok(!finish.disabled, "Finish button should not be disabled"); 1.163 + finish.click(); 1.164 +} 1.165 + 1.166 +// Test a working installer 1.167 +function prepare_test_1() { 1.168 + Services.prefs.setCharPref("pfs.datasource.url", TEST_ROOT + "pfs_bug435788_1.rdf"); 1.169 + 1.170 + var missingPluginsArray = { 1.171 + "application/x-working-plugin": { 1.172 + mimetype: "application/x-working-plugin", 1.173 + pluginsPage: "" 1.174 + } 1.175 + }; 1.176 + 1.177 + startTest(1, missingPluginsArray); 1.178 +} 1.179 + 1.180 +function test_1_available() { 1.181 + is(getListCount(), 1, "Should have found 1 plugin to install"); 1.182 + ok(hasListItem("Test plugin 1", null), "Should have seen the right plugin name"); 1.183 +} 1.184 + 1.185 +function test_1_complete() { 1.186 + is(getResultCount(), 1, "Should have attempted to install 1 plugin"); 1.187 + var item = getResultItem("Test plugin 1", null); 1.188 + ok(item, "Should have seen the installed item"); 1.189 + is(item.status, "Installed", "Should have been a successful install"); 1.190 + 1.191 + clickFinish(); 1.192 +} 1.193 + 1.194 +// Test a broken installer (returns exit code 1) 1.195 +function prepare_test_2() { 1.196 + var missingPluginsArray = { 1.197 + "application/x-broken-installer": { 1.198 + mimetype: "application/x-broken-installer", 1.199 + pluginsPage: "" 1.200 + } 1.201 + }; 1.202 + 1.203 + startTest(2, missingPluginsArray); 1.204 +} 1.205 + 1.206 +function test_2_available() { 1.207 + is(getListCount(), 1, "Should have found 1 plugin to install"); 1.208 + ok(hasListItem("Test plugin 2", null), "Should have seen the right plugin name"); 1.209 +} 1.210 + 1.211 +function test_2_complete() { 1.212 + is(getResultCount(), 1, "Should have attempted to install 1 plugin"); 1.213 + var item = getResultItem("Test plugin 2", null); 1.214 + ok(item, "Should have seen the installed item"); 1.215 + is(item.status, "Failed", "Should have been a failed install"); 1.216 + 1.217 + clickFinish(); 1.218 +} 1.219 + 1.220 +// Test both working and broken together 1.221 +function prepare_test_3() { 1.222 + var missingPluginsArray = { 1.223 + "application/x-working-plugin": { 1.224 + mimetype: "application/x-working-plugin", 1.225 + pluginsPage: "" 1.226 + }, 1.227 + "application/x-broken-installer": { 1.228 + mimetype: "application/x-broken-installer", 1.229 + pluginsPage: "" 1.230 + } 1.231 + }; 1.232 + 1.233 + startTest(3, missingPluginsArray); 1.234 +} 1.235 + 1.236 +function test_3_available() { 1.237 + is(getListCount(), 2, "Should have found 2 plugins to install"); 1.238 + ok(hasListItem("Test plugin 1", null), "Should have seen the right plugin name"); 1.239 + ok(hasListItem("Test plugin 2", null), "Should have seen the right plugin name"); 1.240 +} 1.241 + 1.242 +function test_3_complete() { 1.243 + is(getResultCount(), 2, "Should have attempted to install 2 plugins"); 1.244 + var item = getResultItem("Test plugin 1", null); 1.245 + ok(item, "Should have seen the installed item"); 1.246 + is(item.status, "Installed", "Should have been a successful install"); 1.247 + item = getResultItem("Test plugin 2", null); 1.248 + ok(item, "Should have seen the installed item"); 1.249 + is(item.status, "Failed", "Should have been a failed install"); 1.250 + 1.251 + clickFinish(); 1.252 +} 1.253 + 1.254 +// Test an installer with a bad hash 1.255 +function prepare_test_4() { 1.256 + var missingPluginsArray = { 1.257 + "application/x-broken-plugin-hash": { 1.258 + mimetype: "application/x-broken-plugin-hash", 1.259 + pluginsPage: "" 1.260 + } 1.261 + }; 1.262 + 1.263 + startTest(4, missingPluginsArray); 1.264 +} 1.265 + 1.266 +function test_4_available() { 1.267 + is(getListCount(), 1, "Should have found 1 plugin to install"); 1.268 + ok(hasListItem("Test plugin 3", null), "Should have seen the right plugin name"); 1.269 +} 1.270 + 1.271 +function test_4_complete() { 1.272 + is(getResultCount(), 1, "Should have attempted to install 1 plugin"); 1.273 + var item = getResultItem("Test plugin 3", null); 1.274 + ok(item, "Should have seen the installed item"); 1.275 + is(item.status, "Failed", "Should have not been a successful install"); 1.276 + 1.277 + clickFinish(); 1.278 +} 1.279 + 1.280 +// Test a working xpi 1.281 +function prepare_test_5() { 1.282 + var missingPluginsArray = { 1.283 + "application/x-working-extension": { 1.284 + mimetype: "application/x-working-extension", 1.285 + pluginsPage: "" 1.286 + } 1.287 + }; 1.288 + 1.289 + startTest(5, missingPluginsArray); 1.290 +} 1.291 + 1.292 +function test_5_available() { 1.293 + is(getListCount(), 1, "Should have found 1 plugin to install"); 1.294 + ok(hasListItem("Test extension 1", null), "Should have seen the right plugin name"); 1.295 +} 1.296 + 1.297 +function test_5_complete() { 1.298 + is(getResultCount(), 1, "Should have attempted to install 1 plugin"); 1.299 + var item = getResultItem("Test extension 1", null); 1.300 + ok(item, "Should have seen the installed item"); 1.301 + is(item.status, "Installed", "Should have been a successful install"); 1.302 + 1.303 + AddonManager.getAllInstalls(function(installs) { 1.304 + is(installs.length, 1, "Should be just one install"); 1.305 + is(installs[0].state, AddonManager.STATE_INSTALLED, "Should be fully installed"); 1.306 + is(installs[0].addon.id, "bug435788_1@tests.mozilla.org", "Should have installed the extension"); 1.307 + installs[0].cancel(); 1.308 + 1.309 + clickFinish(); 1.310 + }); 1.311 +} 1.312 + 1.313 +// Test a broke xpi (no install.rdf) 1.314 +function prepare_test_6() { 1.315 + var missingPluginsArray = { 1.316 + "application/x-broken-extension": { 1.317 + mimetype: "application/x-broken-extension", 1.318 + pluginsPage: "" 1.319 + } 1.320 + }; 1.321 + 1.322 + startTest(6, missingPluginsArray); 1.323 +} 1.324 + 1.325 +function test_6_available() { 1.326 + is(getListCount(), 1, "Should have found 1 plugin to install"); 1.327 + ok(hasListItem("Test extension 2", null), "Should have seen the right plugin name"); 1.328 +} 1.329 + 1.330 +function test_6_complete() { 1.331 + is(getResultCount(), 1, "Should have attempted to install 1 plugin"); 1.332 + var item = getResultItem("Test extension 2", null); 1.333 + ok(item, "Should have seen the installed item"); 1.334 + is(item.status, "Failed", "Should have been a failed install"); 1.335 + 1.336 + clickFinish(); 1.337 +} 1.338 + 1.339 +// Test both working and broken xpi 1.340 +function prepare_test_7() { 1.341 + var missingPluginsArray = { 1.342 + "application/x-working-extension": { 1.343 + mimetype: "application/x-working-extension", 1.344 + pluginsPage: "" 1.345 + }, 1.346 + "application/x-broken-extension": { 1.347 + mimetype: "application/x-broken-extension", 1.348 + pluginsPage: "" 1.349 + } 1.350 + }; 1.351 + 1.352 + startTest(7, missingPluginsArray); 1.353 +} 1.354 + 1.355 +function test_7_available() { 1.356 + is(getListCount(), 2, "Should have found 2 plugins to install"); 1.357 + ok(hasListItem("Test extension 1", null), "Should have seen the right plugin name"); 1.358 + ok(hasListItem("Test extension 2", null), "Should have seen the right plugin name"); 1.359 +} 1.360 + 1.361 +function test_7_complete() { 1.362 + is(getResultCount(), 2, "Should have attempted to install 2 plugins"); 1.363 + var item = getResultItem("Test extension 1", null); 1.364 + ok(item, "Should have seen the installed item"); 1.365 + is(item.status, "Installed", "Should have been a failed install"); 1.366 + item = getResultItem("Test extension 2", null); 1.367 + ok(item, "Should have seen the installed item"); 1.368 + is(item.status, "Failed", "Should have been a failed install"); 1.369 + 1.370 + AddonManager.getAllInstalls(function(installs) { 1.371 + is(installs.length, 1, "Should be one active installs"); 1.372 + installs[0].cancel(); 1.373 + 1.374 + clickFinish(); 1.375 + }); 1.376 +} 1.377 + 1.378 +// Test an xpi with a bad hash 1.379 +function prepare_test_8() { 1.380 + var missingPluginsArray = { 1.381 + "application/x-broken-extension-hash": { 1.382 + mimetype: "application/x-broken-extension-hash", 1.383 + pluginsPage: "" 1.384 + } 1.385 + }; 1.386 + 1.387 + startTest(8, missingPluginsArray); 1.388 +} 1.389 + 1.390 +function test_8_available() { 1.391 + is(getListCount(), 1, "Should have found 1 plugin to install"); 1.392 + ok(hasListItem("Test extension 3", null), "Should have seen the right plugin name"); 1.393 +} 1.394 + 1.395 +function test_8_complete() { 1.396 + is(getResultCount(), 1, "Should have attempted to install 1 plugin"); 1.397 + var item = getResultItem("Test extension 3", null); 1.398 + ok(item, "Should have seen the installed item"); 1.399 + is(item.status, "Failed", "Should have not been a successful install"); 1.400 + 1.401 + AddonManager.getAllInstalls(function(installs) { 1.402 + is(installs.length, 0, "Should not be any installs"); 1.403 + 1.404 + clickFinish(); 1.405 + }); 1.406 +} 1.407 + 1.408 +// Test when no plugin exists in the datasource 1.409 +function prepare_test_9() { 1.410 + var missingPluginsArray = { 1.411 + "application/x-unknown-plugin": { 1.412 + mimetype: "application/x-unknown-plugin", 1.413 + pluginsPage: "" 1.414 + } 1.415 + }; 1.416 + 1.417 + startTest(9, missingPluginsArray); 1.418 +} 1.419 + 1.420 +function test_9_complete() { 1.421 + is(getResultCount(), 0, "Should have found no plugins"); 1.422 + 1.423 + clickFinish(); 1.424 +} 1.425 + 1.426 +// Test when the datasource is invalid xml 1.427 +function prepare_test_10() { 1.428 + Services.prefs.setCharPref("pfs.datasource.url", TEST_ROOT + "pfs_bug435788_2.rdf"); 1.429 + 1.430 + var missingPluginsArray = { 1.431 + "application/x-broken-xml": { 1.432 + mimetype: "application/x-broken-xml", 1.433 + pluginsPage: "" 1.434 + } 1.435 + }; 1.436 + 1.437 + startTest(10, missingPluginsArray); 1.438 +} 1.439 + 1.440 +function test_10_complete() { 1.441 + is(getResultCount(), 0, "Should have found no plugins"); 1.442 + 1.443 + clickFinish(); 1.444 +} 1.445 + 1.446 +// Test when no datasource is returned 1.447 +function prepare_test_11() { 1.448 + Services.prefs.setCharPref("pfs.datasource.url", TEST_ROOT + "pfs_bug435788_foo.rdf"); 1.449 + 1.450 + var missingPluginsArray = { 1.451 + "application/x-missing-xml": { 1.452 + mimetype: "application/x-missing-xml", 1.453 + pluginsPage: "" 1.454 + } 1.455 + }; 1.456 + 1.457 + startTest(11, missingPluginsArray); 1.458 +} 1.459 + 1.460 +function test_11_complete() { 1.461 + is(getResultCount(), 0, "Should have found no plugins"); 1.462 + 1.463 + clickFinish(); 1.464 +}