Bug 653637 - Provide a simple way for addons to have preferences UI - Tests; r=dtownsend

This commit is contained in:
Geoff Lankow 2011-05-24 11:03:52 +12:00
Родитель 45284e1365
Коммит d47122e610
9 изменённых файлов: 409 добавлений и 3 удалений

Просмотреть файл

@ -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)

Просмотреть файл

@ -0,0 +1,8 @@
function install (params, aReason) {
}
function uninstall (params, aReason) {
}
function startup (params, aReason) {
}
function shutdown (params, aReason) {
}

Просмотреть файл

@ -0,0 +1,19 @@
<?xml version="1.0" ?>
<RDF xmlns="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:em="http://www.mozilla.org/2004/em-rdf#">
<Description about="urn:mozilla:install-manifest">
<em:id>inlinesettings1@tests.mozilla.org</em:id>
<em:name>Inline Settings (Bootstrap)</em:name>
<em:version>1</em:version>
<em:bootstrap>true</em:bootstrap>
<em:targetApplication>
<Description>
<em:id>toolkit@mozilla.org</em:id>
<em:minVersion>0</em:minVersion>
<em:maxVersion>*</em:maxVersion>
</Description>
</em:targetApplication>
</Description>
</RDF>

Просмотреть файл

@ -0,0 +1,16 @@
<?xml version="1.0" ?>
<vbox xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
<setting pref="extensions.inlinesettings1.bool" type="bool" title="Bool"/>
<setting pref="extensions.inlinesettings1.boolint" type="boolint" on="1" off="2" title="BoolInt"/>
<setting pref="extensions.inlinesettings1.integer" type="integer" title="Integer"/>
<setting pref="extensions.inlinesettings1.string" type="string" title="String"/>
<setting type="control" title="Menulist">
<menulist sizetopopup="always">
<menupopup>
<menuitem label="Test 1" value="1" />
<menuitem label="Test 2" value="2" />
<menuitem label="Test 3" value="3" />
</menupopup>
</menulist>
</setting>
</vbox>

Просмотреть файл

@ -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);
});
});
});
});

Просмотреть файл

@ -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);

Просмотреть файл

@ -0,0 +1,5 @@
<?xml version="1.0" ?>
<vbox xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
<setting pref="extensions.inlinesettings2.bool1" type="bool" title="Bool 1" desc="Description Attribute"/>
<setting pref="extensions.inlinesettings2.bool2" type="bool" title="Bool 2">Description Text Node</setting>
</vbox>

Просмотреть файл

@ -467,7 +467,7 @@ function createInstallRDF(aData) {
rdf += '<Description about="urn:mozilla:install-manifest">\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 += "<em:" + aProp + ">" + escapeXML(aData[aProp]) + "</em:" + aProp + ">\n";

Просмотреть файл

@ -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();
});
}