michael@0: const TEST_ROOT = "http://example.com/browser/toolkit/mozapps/plugins/tests/"; michael@0: michael@0: let tmp = {}; michael@0: Components.utils.import("resource://gre/modules/AddonManager.jsm", tmp); michael@0: let AddonManager = tmp.AddonManager; michael@0: michael@0: var gPFS; michael@0: michael@0: function test() { michael@0: waitForExplicitFinish(); michael@0: michael@0: prepare_test_1(); michael@0: } michael@0: michael@0: function finishTest() { michael@0: Services.prefs.clearUserPref("pfs.datasource.url"); michael@0: finish(); michael@0: } michael@0: michael@0: // Gets the number of plugin items in the detected list michael@0: function getListCount() { michael@0: var list = gPFS.document.getElementById("pluginList"); michael@0: return list.childNodes.length; michael@0: } michael@0: michael@0: // Gets wether the list contains a particular plugin name michael@0: function hasListItem(name, version) { michael@0: var label = name + " " + (version ? version : ""); michael@0: var list = gPFS.document.getElementById("pluginList"); michael@0: for (var i = 0; i < list.childNodes.length; i++) { michael@0: if (list.childNodes[i].label == label) michael@0: return true; michael@0: } michael@0: return false; michael@0: } michael@0: michael@0: // Gets the number of plugin results michael@0: function getResultCount() { michael@0: var list = gPFS.document.getElementById("pluginResultList"); michael@0: return list.childNodes.length; michael@0: } michael@0: michael@0: // Gets the plugin result for a particular plugin name michael@0: function getResultItem(name, version) { michael@0: var label = name + " " + (version ? version : ""); michael@0: var list = gPFS.document.getElementById("pluginResultList"); michael@0: for (var i = 0; i < list.childNodes.length; i++) { michael@0: if (list.childNodes[i].childNodes[1].value == label) { michael@0: var item = { michael@0: name: name, michael@0: version: version, michael@0: status: null michael@0: }; michael@0: if (list.childNodes[i].childNodes[2].tagName == "label") michael@0: item.status = list.childNodes[i].childNodes[2].value; michael@0: return item; michael@0: } michael@0: } michael@0: return null; michael@0: } michael@0: michael@0: // Logs the currently displaying wizard page michael@0: function page_shown() { michael@0: function show_button_state(name) { michael@0: var button = gPFS.document.documentElement.getButton(name); michael@0: info("Button " + name + ". hidden: " + button.hidden + michael@0: ", disabled: " + button.disabled); michael@0: } michael@0: michael@0: info("Page shown: " + michael@0: gPFS.document.documentElement.currentPage.getAttribute("label")); michael@0: show_button_state("next"); michael@0: show_button_state("finish"); michael@0: } michael@0: michael@0: function pfs_loaded() { michael@0: info("PFS loaded"); michael@0: var docEle = gPFS.document.documentElement; michael@0: michael@0: var onwizardfinish = function () { michael@0: info("wizardfinish event"); michael@0: }; michael@0: var onwizardnext = function () { michael@0: info("wizardnext event"); michael@0: }; michael@0: michael@0: docEle.addEventListener("pageshow", page_shown, false); michael@0: docEle.addEventListener("wizardfinish", onwizardfinish, false); michael@0: docEle.addEventListener("wizardnext", onwizardnext, false); michael@0: michael@0: gPFS.addEventListener("unload", function() { michael@0: info("unload event"); michael@0: gPFS.removeEventListener("unload", arguments.callee, false); michael@0: docEle.removeEventListener("pageshow", page_shown, false); michael@0: docEle.removeEventListener("wizardfinish", onwizardfinish, false); michael@0: docEle.removeEventListener("wizardnext", onwizardnext, false); michael@0: }, false); michael@0: michael@0: page_shown(); michael@0: } michael@0: michael@0: function startTest(num, missingPluginsArray) { michael@0: info("Test " + num); michael@0: michael@0: gPFS = window.openDialog("chrome://mozapps/content/plugins/pluginInstallerWizard.xul", michael@0: "PFSWindow", "chrome,centerscreen,resizable=yes", michael@0: {plugins: missingPluginsArray}); michael@0: michael@0: var testScope = this; michael@0: michael@0: gPFS.addEventListener("load", function () { michael@0: gPFS.removeEventListener("load", arguments.callee, false); michael@0: michael@0: pfs_loaded(); michael@0: michael@0: var seenAvailable = false; michael@0: var expectAvailable = typeof testScope["test_" + num + "_available"] == "function"; michael@0: michael@0: function availableListener() { michael@0: seenAvailable = true; michael@0: michael@0: if (expectAvailable) { michael@0: executeSoon(function () { michael@0: testScope["test_" + num + "_available"](); michael@0: gPFS.document.documentElement.getButton("next").click(); michael@0: }); michael@0: } else { michael@0: ok(false, "Should not have found plugins to install"); michael@0: } michael@0: } michael@0: michael@0: function completeListener() { michael@0: if (expectAvailable) michael@0: ok(seenAvailable, "Should have seen the list of available plugins"); michael@0: michael@0: executeSoon(testScope["test_" + num + "_complete"]); michael@0: } michael@0: michael@0: gPFS.document.documentElement.wizardPages[1].addEventListener("pageshow", availableListener); michael@0: gPFS.document.documentElement.wizardPages[4].addEventListener("pageshow", completeListener); michael@0: michael@0: gPFS.addEventListener("unload", function () { michael@0: gPFS.removeEventListener("unload", arguments.callee, false); michael@0: gPFS.document.documentElement.wizardPages[1].removeEventListener("pageshow", availableListener, false); michael@0: gPFS.document.documentElement.wizardPages[4].removeEventListener("pageshow", completeListener, false); michael@0: michael@0: num++; michael@0: if (typeof testScope["prepare_test_" + num] == "function") michael@0: testScope["prepare_test_" + num](); michael@0: else michael@0: finishTest(); michael@0: }); michael@0: }); michael@0: } michael@0: michael@0: function clickFinish() { michael@0: var finish = gPFS.document.documentElement.getButton("finish"); michael@0: ok(!finish.hidden, "Finish button should not be hidden"); michael@0: ok(!finish.disabled, "Finish button should not be disabled"); michael@0: finish.click(); michael@0: } michael@0: michael@0: // Test a working installer michael@0: function prepare_test_1() { michael@0: Services.prefs.setCharPref("pfs.datasource.url", TEST_ROOT + "pfs_bug435788_1.rdf"); michael@0: michael@0: var missingPluginsArray = { michael@0: "application/x-working-plugin": { michael@0: mimetype: "application/x-working-plugin", michael@0: pluginsPage: "" michael@0: } michael@0: }; michael@0: michael@0: startTest(1, missingPluginsArray); michael@0: } michael@0: michael@0: function test_1_available() { michael@0: is(getListCount(), 1, "Should have found 1 plugin to install"); michael@0: ok(hasListItem("Test plugin 1", null), "Should have seen the right plugin name"); michael@0: } michael@0: michael@0: function test_1_complete() { michael@0: is(getResultCount(), 1, "Should have attempted to install 1 plugin"); michael@0: var item = getResultItem("Test plugin 1", null); michael@0: ok(item, "Should have seen the installed item"); michael@0: is(item.status, "Installed", "Should have been a successful install"); michael@0: michael@0: clickFinish(); michael@0: } michael@0: michael@0: // Test a broken installer (returns exit code 1) michael@0: function prepare_test_2() { michael@0: var missingPluginsArray = { michael@0: "application/x-broken-installer": { michael@0: mimetype: "application/x-broken-installer", michael@0: pluginsPage: "" michael@0: } michael@0: }; michael@0: michael@0: startTest(2, missingPluginsArray); michael@0: } michael@0: michael@0: function test_2_available() { michael@0: is(getListCount(), 1, "Should have found 1 plugin to install"); michael@0: ok(hasListItem("Test plugin 2", null), "Should have seen the right plugin name"); michael@0: } michael@0: michael@0: function test_2_complete() { michael@0: is(getResultCount(), 1, "Should have attempted to install 1 plugin"); michael@0: var item = getResultItem("Test plugin 2", null); michael@0: ok(item, "Should have seen the installed item"); michael@0: is(item.status, "Failed", "Should have been a failed install"); michael@0: michael@0: clickFinish(); michael@0: } michael@0: michael@0: // Test both working and broken together michael@0: function prepare_test_3() { michael@0: var missingPluginsArray = { michael@0: "application/x-working-plugin": { michael@0: mimetype: "application/x-working-plugin", michael@0: pluginsPage: "" michael@0: }, michael@0: "application/x-broken-installer": { michael@0: mimetype: "application/x-broken-installer", michael@0: pluginsPage: "" michael@0: } michael@0: }; michael@0: michael@0: startTest(3, missingPluginsArray); michael@0: } michael@0: michael@0: function test_3_available() { michael@0: is(getListCount(), 2, "Should have found 2 plugins to install"); michael@0: ok(hasListItem("Test plugin 1", null), "Should have seen the right plugin name"); michael@0: ok(hasListItem("Test plugin 2", null), "Should have seen the right plugin name"); michael@0: } michael@0: michael@0: function test_3_complete() { michael@0: is(getResultCount(), 2, "Should have attempted to install 2 plugins"); michael@0: var item = getResultItem("Test plugin 1", null); michael@0: ok(item, "Should have seen the installed item"); michael@0: is(item.status, "Installed", "Should have been a successful install"); michael@0: item = getResultItem("Test plugin 2", null); michael@0: ok(item, "Should have seen the installed item"); michael@0: is(item.status, "Failed", "Should have been a failed install"); michael@0: michael@0: clickFinish(); michael@0: } michael@0: michael@0: // Test an installer with a bad hash michael@0: function prepare_test_4() { michael@0: var missingPluginsArray = { michael@0: "application/x-broken-plugin-hash": { michael@0: mimetype: "application/x-broken-plugin-hash", michael@0: pluginsPage: "" michael@0: } michael@0: }; michael@0: michael@0: startTest(4, missingPluginsArray); michael@0: } michael@0: michael@0: function test_4_available() { michael@0: is(getListCount(), 1, "Should have found 1 plugin to install"); michael@0: ok(hasListItem("Test plugin 3", null), "Should have seen the right plugin name"); michael@0: } michael@0: michael@0: function test_4_complete() { michael@0: is(getResultCount(), 1, "Should have attempted to install 1 plugin"); michael@0: var item = getResultItem("Test plugin 3", null); michael@0: ok(item, "Should have seen the installed item"); michael@0: is(item.status, "Failed", "Should have not been a successful install"); michael@0: michael@0: clickFinish(); michael@0: } michael@0: michael@0: // Test a working xpi michael@0: function prepare_test_5() { michael@0: var missingPluginsArray = { michael@0: "application/x-working-extension": { michael@0: mimetype: "application/x-working-extension", michael@0: pluginsPage: "" michael@0: } michael@0: }; michael@0: michael@0: startTest(5, missingPluginsArray); michael@0: } michael@0: michael@0: function test_5_available() { michael@0: is(getListCount(), 1, "Should have found 1 plugin to install"); michael@0: ok(hasListItem("Test extension 1", null), "Should have seen the right plugin name"); michael@0: } michael@0: michael@0: function test_5_complete() { michael@0: is(getResultCount(), 1, "Should have attempted to install 1 plugin"); michael@0: var item = getResultItem("Test extension 1", null); michael@0: ok(item, "Should have seen the installed item"); michael@0: is(item.status, "Installed", "Should have been a successful install"); michael@0: michael@0: AddonManager.getAllInstalls(function(installs) { michael@0: is(installs.length, 1, "Should be just one install"); michael@0: is(installs[0].state, AddonManager.STATE_INSTALLED, "Should be fully installed"); michael@0: is(installs[0].addon.id, "bug435788_1@tests.mozilla.org", "Should have installed the extension"); michael@0: installs[0].cancel(); michael@0: michael@0: clickFinish(); michael@0: }); michael@0: } michael@0: michael@0: // Test a broke xpi (no install.rdf) michael@0: function prepare_test_6() { michael@0: var missingPluginsArray = { michael@0: "application/x-broken-extension": { michael@0: mimetype: "application/x-broken-extension", michael@0: pluginsPage: "" michael@0: } michael@0: }; michael@0: michael@0: startTest(6, missingPluginsArray); michael@0: } michael@0: michael@0: function test_6_available() { michael@0: is(getListCount(), 1, "Should have found 1 plugin to install"); michael@0: ok(hasListItem("Test extension 2", null), "Should have seen the right plugin name"); michael@0: } michael@0: michael@0: function test_6_complete() { michael@0: is(getResultCount(), 1, "Should have attempted to install 1 plugin"); michael@0: var item = getResultItem("Test extension 2", null); michael@0: ok(item, "Should have seen the installed item"); michael@0: is(item.status, "Failed", "Should have been a failed install"); michael@0: michael@0: clickFinish(); michael@0: } michael@0: michael@0: // Test both working and broken xpi michael@0: function prepare_test_7() { michael@0: var missingPluginsArray = { michael@0: "application/x-working-extension": { michael@0: mimetype: "application/x-working-extension", michael@0: pluginsPage: "" michael@0: }, michael@0: "application/x-broken-extension": { michael@0: mimetype: "application/x-broken-extension", michael@0: pluginsPage: "" michael@0: } michael@0: }; michael@0: michael@0: startTest(7, missingPluginsArray); michael@0: } michael@0: michael@0: function test_7_available() { michael@0: is(getListCount(), 2, "Should have found 2 plugins to install"); michael@0: ok(hasListItem("Test extension 1", null), "Should have seen the right plugin name"); michael@0: ok(hasListItem("Test extension 2", null), "Should have seen the right plugin name"); michael@0: } michael@0: michael@0: function test_7_complete() { michael@0: is(getResultCount(), 2, "Should have attempted to install 2 plugins"); michael@0: var item = getResultItem("Test extension 1", null); michael@0: ok(item, "Should have seen the installed item"); michael@0: is(item.status, "Installed", "Should have been a failed install"); michael@0: item = getResultItem("Test extension 2", null); michael@0: ok(item, "Should have seen the installed item"); michael@0: is(item.status, "Failed", "Should have been a failed install"); michael@0: michael@0: AddonManager.getAllInstalls(function(installs) { michael@0: is(installs.length, 1, "Should be one active installs"); michael@0: installs[0].cancel(); michael@0: michael@0: clickFinish(); michael@0: }); michael@0: } michael@0: michael@0: // Test an xpi with a bad hash michael@0: function prepare_test_8() { michael@0: var missingPluginsArray = { michael@0: "application/x-broken-extension-hash": { michael@0: mimetype: "application/x-broken-extension-hash", michael@0: pluginsPage: "" michael@0: } michael@0: }; michael@0: michael@0: startTest(8, missingPluginsArray); michael@0: } michael@0: michael@0: function test_8_available() { michael@0: is(getListCount(), 1, "Should have found 1 plugin to install"); michael@0: ok(hasListItem("Test extension 3", null), "Should have seen the right plugin name"); michael@0: } michael@0: michael@0: function test_8_complete() { michael@0: is(getResultCount(), 1, "Should have attempted to install 1 plugin"); michael@0: var item = getResultItem("Test extension 3", null); michael@0: ok(item, "Should have seen the installed item"); michael@0: is(item.status, "Failed", "Should have not been a successful install"); michael@0: michael@0: AddonManager.getAllInstalls(function(installs) { michael@0: is(installs.length, 0, "Should not be any installs"); michael@0: michael@0: clickFinish(); michael@0: }); michael@0: } michael@0: michael@0: // Test when no plugin exists in the datasource michael@0: function prepare_test_9() { michael@0: var missingPluginsArray = { michael@0: "application/x-unknown-plugin": { michael@0: mimetype: "application/x-unknown-plugin", michael@0: pluginsPage: "" michael@0: } michael@0: }; michael@0: michael@0: startTest(9, missingPluginsArray); michael@0: } michael@0: michael@0: function test_9_complete() { michael@0: is(getResultCount(), 0, "Should have found no plugins"); michael@0: michael@0: clickFinish(); michael@0: } michael@0: michael@0: // Test when the datasource is invalid xml michael@0: function prepare_test_10() { michael@0: Services.prefs.setCharPref("pfs.datasource.url", TEST_ROOT + "pfs_bug435788_2.rdf"); michael@0: michael@0: var missingPluginsArray = { michael@0: "application/x-broken-xml": { michael@0: mimetype: "application/x-broken-xml", michael@0: pluginsPage: "" michael@0: } michael@0: }; michael@0: michael@0: startTest(10, missingPluginsArray); michael@0: } michael@0: michael@0: function test_10_complete() { michael@0: is(getResultCount(), 0, "Should have found no plugins"); michael@0: michael@0: clickFinish(); michael@0: } michael@0: michael@0: // Test when no datasource is returned michael@0: function prepare_test_11() { michael@0: Services.prefs.setCharPref("pfs.datasource.url", TEST_ROOT + "pfs_bug435788_foo.rdf"); michael@0: michael@0: var missingPluginsArray = { michael@0: "application/x-missing-xml": { michael@0: mimetype: "application/x-missing-xml", michael@0: pluginsPage: "" michael@0: } michael@0: }; michael@0: michael@0: startTest(11, missingPluginsArray); michael@0: } michael@0: michael@0: function test_11_complete() { michael@0: is(getResultCount(), 0, "Should have found no plugins"); michael@0: michael@0: clickFinish(); michael@0: }