From d47122e610424eae27cba9ec194749a29eacb23c Mon Sep 17 00:00:00 2001 From: Geoff Lankow Date: Tue, 24 May 2011 11:03:52 +1200 Subject: [PATCH] Bug 653637 - Provide a simple way for addons to have preferences UI - Tests; r=dtownsend --- .../extensions/test/browser/Makefile.in | 2 + .../browser_inlinesettings1/bootstrap.js | 8 + .../browser_inlinesettings1/install.rdf | 19 ++ .../browser_inlinesettings1/options.xul | 16 ++ .../test/browser/browser_inlinesettings.js | 268 ++++++++++++++++++ .../mozapps/extensions/test/browser/head.js | 2 + .../extensions/test/browser/options.xul | 5 + .../extensions/test/xpcshell/head_addons.js | 2 +- .../extensions/test/xpcshell/test_manifest.js | 90 +++++- 9 files changed, 409 insertions(+), 3 deletions(-) create mode 100644 toolkit/mozapps/extensions/test/browser/addons/browser_inlinesettings1/bootstrap.js create mode 100644 toolkit/mozapps/extensions/test/browser/addons/browser_inlinesettings1/install.rdf create mode 100644 toolkit/mozapps/extensions/test/browser/addons/browser_inlinesettings1/options.xul create mode 100644 toolkit/mozapps/extensions/test/browser/browser_inlinesettings.js create mode 100644 toolkit/mozapps/extensions/test/browser/options.xul diff --git a/toolkit/mozapps/extensions/test/browser/Makefile.in b/toolkit/mozapps/extensions/test/browser/Makefile.in index 69c4543493af..1f0f90902612 100644 --- a/toolkit/mozapps/extensions/test/browser/Makefile.in +++ b/toolkit/mozapps/extensions/test/browser/Makefile.in @@ -87,6 +87,7 @@ _MAIN_TEST_FILES = \ browser_purchase.js \ browser_openDialog.js \ browser_types.js \ + browser_inlinesettings.js \ $(NULL) _TEST_FILES = \ @@ -115,6 +116,7 @@ _TEST_RESOURCES = \ browser_eula.xml \ browser_purchase.xml \ discovery.html \ + options.xul \ redirect.sjs \ releaseNotes.xhtml \ $(NULL) diff --git a/toolkit/mozapps/extensions/test/browser/addons/browser_inlinesettings1/bootstrap.js b/toolkit/mozapps/extensions/test/browser/addons/browser_inlinesettings1/bootstrap.js new file mode 100644 index 000000000000..7871af738e5f --- /dev/null +++ b/toolkit/mozapps/extensions/test/browser/addons/browser_inlinesettings1/bootstrap.js @@ -0,0 +1,8 @@ +function install (params, aReason) { +} +function uninstall (params, aReason) { +} +function startup (params, aReason) { +} +function shutdown (params, aReason) { +} diff --git a/toolkit/mozapps/extensions/test/browser/addons/browser_inlinesettings1/install.rdf b/toolkit/mozapps/extensions/test/browser/addons/browser_inlinesettings1/install.rdf new file mode 100644 index 000000000000..2bf7c6e2ef85 --- /dev/null +++ b/toolkit/mozapps/extensions/test/browser/addons/browser_inlinesettings1/install.rdf @@ -0,0 +1,19 @@ + + + + + inlinesettings1@tests.mozilla.org + Inline Settings (Bootstrap) + 1 + true + + + + toolkit@mozilla.org + 0 + * + + + + + diff --git a/toolkit/mozapps/extensions/test/browser/addons/browser_inlinesettings1/options.xul b/toolkit/mozapps/extensions/test/browser/addons/browser_inlinesettings1/options.xul new file mode 100644 index 000000000000..4a4b45649032 --- /dev/null +++ b/toolkit/mozapps/extensions/test/browser/addons/browser_inlinesettings1/options.xul @@ -0,0 +1,16 @@ + + + + + + + + + + + + + + + + diff --git a/toolkit/mozapps/extensions/test/browser/browser_inlinesettings.js b/toolkit/mozapps/extensions/test/browser/browser_inlinesettings.js new file mode 100644 index 000000000000..fc51b77ebe0a --- /dev/null +++ b/toolkit/mozapps/extensions/test/browser/browser_inlinesettings.js @@ -0,0 +1,268 @@ +/* Any copyright is dedicated to the Public Domain. + * http://creativecommons.org/publicdomain/zero/1.0/ + */ + +// Tests various aspects of the details view + +var gManagerWindow; +var gCategoryUtilities; +var gProvider; + +function installAddon(aCallback) { + AddonManager.getInstallForURL(TESTROOT + "addons/browser_inlinesettings1.xpi", + function(aInstall) { + aInstall.addListener({ + onInstallEnded: function() { + executeSoon(aCallback); + } + }); + aInstall.install(); + }, "application/x-xpinstall"); +} + +function test() { + waitForExplicitFinish(); + + gProvider = new MockProvider(); + + gProvider.createAddons([{ + id: "inlinesettings2@tests.mozilla.org", + name: "Inline Settings (Regular)", + version: "1", + optionsURL: CHROMEROOT + "options.xul", + optionsType: AddonManager.OPTIONS_TYPE_INLINE + },{ + id: "noninlinesettings@tests.mozilla.org", + name: "Non-Inline Settings", + version: "1", + optionsURL: CHROMEROOT + "addon_prefs.xul" + }]); + + installAddon(function () { + open_manager("addons://list/extension", function(aWindow) { + gManagerWindow = aWindow; + gCategoryUtilities = new CategoryUtilities(gManagerWindow); + + run_next_test(); + }); + }); +} + +function end_test() { + close_manager(gManagerWindow, function() { + AddonManager.getAddonByID("inlinesettings1@tests.mozilla.org", function(aAddon) { + aAddon.uninstall(); + finish(); + }); + }); +} + +// Addon with options.xul +add_test(function() { + var addon = get_addon_element(gManagerWindow, "inlinesettings1@tests.mozilla.org"); + is(addon.mAddon.optionsType, AddonManager.OPTIONS_TYPE_INLINE, "Options should be inline type"); + addon.parentNode.ensureElementIsVisible(addon); + + var button = gManagerWindow.document.getAnonymousElementByAttribute(addon, "anonid", "preferences-btn"); + is_element_visible(button, "Preferences button should be visible"); + + run_next_test(); +}); + +// Addon with inline preferences as optionsURL +add_test(function() { + var addon = get_addon_element(gManagerWindow, "inlinesettings2@tests.mozilla.org"); + is(addon.mAddon.optionsType, AddonManager.OPTIONS_TYPE_INLINE, "Options should be inline type"); + addon.parentNode.ensureElementIsVisible(addon); + + var button = gManagerWindow.document.getAnonymousElementByAttribute(addon, "anonid", "preferences-btn"); + is_element_visible(button, "Preferences button should be visible"); + + run_next_test(); +}); + +// Addon with non-inline preferences as optionsURL +add_test(function() { + var addon = get_addon_element(gManagerWindow, "noninlinesettings@tests.mozilla.org"); + is(addon.mAddon.optionsType, AddonManager.OPTIONS_TYPE_DIALOG, "Options should be dialog type"); + addon.parentNode.ensureElementIsVisible(addon); + + var button = gManagerWindow.document.getAnonymousElementByAttribute(addon, "anonid", "preferences-btn"); + is_element_visible(button, "Preferences button should be visible"); + + run_next_test(); +}); + +// Addon with options.xul, also a test for the setting.xml bindings +add_test(function() { + var addon = get_addon_element(gManagerWindow, "inlinesettings1@tests.mozilla.org"); + addon.parentNode.ensureElementIsVisible(addon); + + var button = gManagerWindow.document.getAnonymousElementByAttribute(addon, "anonid", "preferences-btn"); + EventUtils.synthesizeMouseAtCenter(button, { clickCount: 1 }, gManagerWindow); + + wait_for_view_load(gManagerWindow, function() { + var grid = gManagerWindow.document.getElementById("detail-grid"); + var settings = grid.querySelectorAll("rows > setting"); + is(settings.length, 4, "Grid should have settings children"); + + // Force bindings to apply + settings[0].clientTop; + + Services.prefs.setBoolPref("extensions.inlinesettings1.bool", false); + var input = gManagerWindow.document.getAnonymousElementByAttribute(settings[0], "anonid", "input"); + isnot(input.checked, true, "Checkbox should have initial value"); + EventUtils.synthesizeMouseAtCenter(input, { clickCount: 1 }, gManagerWindow); + is(input.checked, true, "Checkbox should have updated value"); + is(Services.prefs.getBoolPref("extensions.inlinesettings1.bool"), true, "Bool pref should have been updated"); + EventUtils.synthesizeMouseAtCenter(input, { clickCount: 1 }, gManagerWindow); + isnot(input.checked, true, "Checkbox should have updated value"); + is(Services.prefs.getBoolPref("extensions.inlinesettings1.bool"), false, "Bool pref should have been updated"); + + Services.prefs.setIntPref("extensions.inlinesettings1.boolint", 0); + var input = gManagerWindow.document.getAnonymousElementByAttribute(settings[1], "anonid", "input"); + isnot(input.checked, true, "Checkbox should have initial value"); + EventUtils.synthesizeMouseAtCenter(input, { clickCount: 1 }, gManagerWindow); + is(input.checked, true, "Checkbox should have updated value"); + is(Services.prefs.getIntPref("extensions.inlinesettings1.boolint"), 1, "BoolInt pref should have been updated"); + EventUtils.synthesizeMouseAtCenter(input, { clickCount: 1 }, gManagerWindow); + isnot(input.checked, true, "Checkbox should have updated value"); + is(Services.prefs.getIntPref("extensions.inlinesettings1.boolint"), 2, "BoolInt pref should have been updated"); + + Services.prefs.setIntPref("extensions.inlinesettings1.integer", 0); + var input = gManagerWindow.document.getAnonymousElementByAttribute(settings[2], "anonid", "input"); + is(input.value, "0", "Number box should have initial value"); + input.select(); + EventUtils.synthesizeKey("1", {}, gManagerWindow); + EventUtils.synthesizeKey("3", {}, gManagerWindow); + is(input.value, "13", "Number box should have updated value"); + is(Services.prefs.getIntPref("extensions.inlinesettings1.integer"), 13, "Integer pref should have been updated"); + EventUtils.synthesizeKey("VK_DOWN", {}, gManagerWindow); + is(input.value, "12", "Number box should have updated value"); + is(Services.prefs.getIntPref("extensions.inlinesettings1.integer"), 12, "Integer pref should have been updated"); + + Services.prefs.setCharPref("extensions.inlinesettings1.string", "foo"); + var input = gManagerWindow.document.getAnonymousElementByAttribute(settings[3], "anonid", "input"); + is(input.value, "foo", "Text box should have initial value"); + input.select(); + EventUtils.synthesizeKey("b", {}, gManagerWindow); + EventUtils.synthesizeKey("a", {}, gManagerWindow); + EventUtils.synthesizeKey("r", {}, gManagerWindow); + is(input.value, "bar", "Text box should have updated value"); + is(Services.prefs.getCharPref("extensions.inlinesettings1.string"), "bar", "String pref should have been updated"); + + var button = gManagerWindow.document.getElementById("detail-prefs-btn"); + is_element_hidden(button, "Preferences button should not be visible"); + + gCategoryUtilities.openType("extension", run_next_test); + }); +}); + +// Addon with inline preferences as optionsURL +add_test(function() { + var addon = get_addon_element(gManagerWindow, "inlinesettings2@tests.mozilla.org"); + addon.parentNode.ensureElementIsVisible(addon); + + var button = gManagerWindow.document.getAnonymousElementByAttribute(addon, "anonid", "preferences-btn"); + EventUtils.synthesizeMouseAtCenter(button, { clickCount: 1 }, gManagerWindow); + + wait_for_view_load(gManagerWindow, function() { + var grid = gManagerWindow.document.getElementById("detail-grid"); + var settings = grid.querySelectorAll("rows > setting"); + is(settings.length, 2, "Grid should have settings children"); + + // Force bindings to apply + settings[0].clientTop; + + var node = settings[0]; + is(node.nodeName, "setting", "Should be a setting node"); + var description = gManagerWindow.document.getAnonymousElementByAttribute(node, "class", "preferences-description"); + is(description.textContent.trim(), "", "Description node should be empty"); + + node = node.nextSibling; + is(node.nodeName, "row", "Setting should be followed by a row node"); + is(node.textContent, "Description Attribute", "Description should be in this row"); + + node = settings[1]; + is(node.nodeName, "setting", "Should be a setting node"); + description = gManagerWindow.document.getAnonymousElementByAttribute(node, "class", "preferences-description"); + is(description.textContent.trim(), "", "Description node should be empty"); + + node = node.nextSibling; + is(node.nodeName, "row", "Setting should be followed by a row node"); + is(node.textContent, "Description Text Node", "Description should be in this row"); + + var button = gManagerWindow.document.getElementById("detail-prefs-btn"); + is_element_hidden(button, "Preferences button should not be visible"); + + gCategoryUtilities.openType("extension", run_next_test); + }); +}); + +// Addon with non-inline preferences as optionsURL +add_test(function() { + var addon = get_addon_element(gManagerWindow, "noninlinesettings@tests.mozilla.org"); + addon.parentNode.ensureElementIsVisible(addon); + + var button = gManagerWindow.document.getAnonymousElementByAttribute(addon, "anonid", "details-btn"); + EventUtils.synthesizeMouseAtCenter(button, { clickCount: 1 }, gManagerWindow); + + wait_for_view_load(gManagerWindow, function() { + var grid = gManagerWindow.document.getElementById("detail-grid"); + var settings = grid.querySelectorAll("rows > setting"); + is(settings.length, 0, "Grid should not have settings children"); + + var button = gManagerWindow.document.getElementById("detail-prefs-btn"); + is_element_visible(button, "Preferences button should be visible"); + + gCategoryUtilities.openType("extension", run_next_test); + }); +}); + +// Addon with options.xul, disabling and enabling should hide and show settings UI +add_test(function() { + var addon = get_addon_element(gManagerWindow, "inlinesettings1@tests.mozilla.org"); + addon.parentNode.ensureElementIsVisible(addon); + + var button = gManagerWindow.document.getAnonymousElementByAttribute(addon, "anonid", "preferences-btn"); + EventUtils.synthesizeMouseAtCenter(button, { clickCount: 1 }, gManagerWindow); + + wait_for_view_load(gManagerWindow, function() { + var grid = gManagerWindow.document.getElementById("detail-grid"); + var settings = grid.querySelectorAll("rows > setting"); + is(settings.length, 4, "Grid should have settings children"); + + // disable + var button = gManagerWindow.document.getElementById("detail-disable-btn"); + EventUtils.synthesizeMouseAtCenter(button, { clickCount: 1 }, gManagerWindow); + + settings = grid.querySelectorAll("rows > setting"); + is(settings.length, 0, "Grid should not have settings children"); + + gCategoryUtilities.openType("extension", function() { + var addon = get_addon_element(gManagerWindow, "inlinesettings1@tests.mozilla.org"); + addon.parentNode.ensureElementIsVisible(addon); + + var button = gManagerWindow.document.getAnonymousElementByAttribute(addon, "anonid", "preferences-btn"); + is_element_hidden(button, "Preferences button should not be visible"); + + button = gManagerWindow.document.getAnonymousElementByAttribute(addon, "anonid", "details-btn"); + EventUtils.synthesizeMouseAtCenter(button, { clickCount: 1 }, gManagerWindow); + + wait_for_view_load(gManagerWindow, function() { + var grid = gManagerWindow.document.getElementById("detail-grid"); + var settings = grid.querySelectorAll("rows > setting"); + is(settings.length, 0, "Grid should not have settings children"); + + // enable + var button = gManagerWindow.document.getElementById("detail-enable-btn"); + EventUtils.synthesizeMouseAtCenter(button, { clickCount: 1 }, gManagerWindow); + + settings = grid.querySelectorAll("rows > setting"); + is(settings.length, 4, "Grid should have settings children"); + + gCategoryUtilities.openType("extension", run_next_test); + }); + }); + }); +}); diff --git a/toolkit/mozapps/extensions/test/browser/head.js b/toolkit/mozapps/extensions/test/browser/head.js index b41d47cd1a74..4c3ab6f9ab32 100644 --- a/toolkit/mozapps/extensions/test/browser/head.js +++ b/toolkit/mozapps/extensions/test/browser/head.js @@ -622,6 +622,8 @@ MockProvider.prototype = { } addon[prop] = aAddonProp[prop]; } + if (!addon.optionsType && !!addon.optionsURL) + addon.optionsType = AddonManager.OPTIONS_TYPE_DIALOG; this.addAddon(addon); newAddons.push(addon); }, this); diff --git a/toolkit/mozapps/extensions/test/browser/options.xul b/toolkit/mozapps/extensions/test/browser/options.xul new file mode 100644 index 000000000000..46e9e5b1b3fc --- /dev/null +++ b/toolkit/mozapps/extensions/test/browser/options.xul @@ -0,0 +1,5 @@ + + + + Description Text Node + diff --git a/toolkit/mozapps/extensions/test/xpcshell/head_addons.js b/toolkit/mozapps/extensions/test/xpcshell/head_addons.js index 8f1f2c6705d4..9c5c37c4ec2c 100644 --- a/toolkit/mozapps/extensions/test/xpcshell/head_addons.js +++ b/toolkit/mozapps/extensions/test/xpcshell/head_addons.js @@ -467,7 +467,7 @@ function createInstallRDF(aData) { rdf += '\n'; ["id", "version", "type", "internalName", "updateURL", "updateKey", - "optionsURL", "aboutURL", "iconURL", "icon64URL", + "optionsURL", "optionsType", "aboutURL", "iconURL", "icon64URL", "skinnable", "bootstrap"].forEach(function(aProp) { if (aProp in aData) rdf += "" + escapeXML(aData[aProp]) + "\n"; diff --git a/toolkit/mozapps/extensions/test/xpcshell/test_manifest.js b/toolkit/mozapps/extensions/test/xpcshell/test_manifest.js index fa9e7bbe20a2..4e9f2d10212e 100644 --- a/toolkit/mozapps/extensions/test/xpcshell/test_manifest.js +++ b/toolkit/mozapps/extensions/test/xpcshell/test_manifest.js @@ -221,6 +221,55 @@ function run_test() { name: "Test Addon 16" }, profileDir); + writeInstallRDFForExtension({ + id: "addon17@tests.mozilla.org", + version: "1.0", + optionsURL: "chrome://test/content/options.xul", + optionsType: "2", + targetApplications: [{ + id: "xpcshell@tests.mozilla.org", + minVersion: "1", + maxVersion: "1" + }], + name: "Test Addon 17" + }, profileDir); + + writeInstallRDFForExtension({ + id: "addon18@tests.mozilla.org", + version: "1.0", + targetApplications: [{ + id: "xpcshell@tests.mozilla.org", + minVersion: "1", + maxVersion: "1" + }], + name: "Test Addon 18" + }, profileDir, null, "options.xul"); + + writeInstallRDFForExtension({ + id: "addon19@tests.mozilla.org", + version: "1.0", + optionsType: "99", + targetApplications: [{ + id: "xpcshell@tests.mozilla.org", + minVersion: "1", + maxVersion: "1" + }], + name: "Test Addon 19" + }, profileDir); + + writeInstallRDFForExtension({ + id: "addon20@tests.mozilla.org", + version: "1.0", + optionsType: "1", + optionsURL: "chrome://test/content/options.xul", + targetApplications: [{ + id: "xpcshell@tests.mozilla.org", + minVersion: "1", + maxVersion: "1" + }], + name: "Test Addon 20" + }, profileDir); + do_test_pending(); startupManager(); AddonManager.getAddonsByIDs(["addon1@tests.mozilla.org", @@ -238,15 +287,20 @@ function run_test() { "addon13@tests.mozilla.org", "addon14@tests.mozilla.org", "addon15@tests.mozilla.org", - "addon16@tests.mozilla.org"], + "addon16@tests.mozilla.org", + "addon17@tests.mozilla.org", + "addon18@tests.mozilla.org", + "addon19@tests.mozilla.org", + "addon20@tests.mozilla.org"], function([a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, - a11, a12, a13, a14, a15, a16]) { + a11, a12, a13, a14, a15, a16, a17, a18, a19, a20]) { do_check_neq(a1, null); do_check_eq(a1.id, "addon1@tests.mozilla.org"); do_check_eq(a1.type, "extension"); do_check_eq(a1.version, "1.0"); do_check_eq(a1.optionsURL, "chrome://test/content/options.xul"); + do_check_eq(a1.optionsType, AddonManager.OPTIONS_TYPE_DIALOG); do_check_eq(a1.aboutURL, "chrome://test/content/about.xul"); do_check_eq(a1.iconURL, "chrome://test/skin/icon.png"); do_check_eq(a1.icon64URL, "chrome://test/skin/icon64.png"); @@ -362,6 +416,38 @@ function run_test() { do_check_true(a16.isCompatible); do_check_true(a16.providesUpdatesSecurely); + do_check_neq(a17, null); + do_check_true(a17.isActive); + do_check_false(a17.userDisabled); + do_check_false(a17.appDisabled); + do_check_true(a17.isCompatible); + do_check_eq(a17.optionsURL, "chrome://test/content/options.xul"); + do_check_eq(a17.optionsType, AddonManager.OPTIONS_TYPE_INLINE); + + do_check_neq(a18, null); + do_check_true(a18.isActive); + do_check_false(a18.userDisabled); + do_check_false(a18.appDisabled); + do_check_true(a18.isCompatible); + if (Services.prefs.getBoolPref("extensions.alwaysUnpack")) { + do_check_eq(a18.optionsURL, Services.io.newFileURI(profileDir).spec + + "addon18@tests.mozilla.org/options.xul"); + } else { + do_check_eq(a18.optionsURL, "jar:" + Services.io.newFileURI(profileDir).spec + + "addon18@tests.mozilla.org.xpi!/options.xul"); + } + do_check_eq(a18.optionsType, AddonManager.OPTIONS_TYPE_INLINE); + + do_check_eq(a19, null); + + do_check_neq(a20, null); + do_check_true(a20.isActive); + do_check_false(a20.userDisabled); + do_check_false(a20.appDisabled); + do_check_true(a20.isCompatible); + do_check_eq(a20.optionsURL, "chrome://test/content/options.xul"); + do_check_eq(a20.optionsType, AddonManager.OPTIONS_TYPE_DIALOG); + do_test_finished(); }); }