Bug 612035 - "Don't compare unnecessary labels during browser-chrome tests." [r=mark.finkle]

This commit is contained in:
Wesley Johnston 2010-11-15 16:00:00 -05:00
Родитель fdc7e33baa
Коммит 2844a8500b
2 изменённых файлов: 126 добавлений и 162 удалений

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

@ -27,7 +27,10 @@ var addons = [{
homepageURL: "http://example.com/", homepageURL: "http://example.com/",
version: "1.0", version: "1.0",
description: "Test add-on", description: "Test add-on",
sourceURL: TESTROOT + "addons/browser_install1_1.xpi" sourceURL: TESTROOT + "addons/browser_install1_1.xpi",
bootstrapped: true,
willFail: false,
updateIndex: 2,
}, },
{ {
id: "addon2@tests.mozilla.org", id: "addon2@tests.mozilla.org",
@ -36,7 +39,20 @@ var addons = [{
homepageURL: "http://example.com/", homepageURL: "http://example.com/",
version: "1.0", version: "1.0",
description: "Test add-on 2", description: "Test add-on 2",
sourceURL: TESTROOT + "addons/browser_install1_2.xpi" sourceURL: TESTROOT + "addons/browser_install1_2.xpi",
bootstrapped: false,
willFail: false,
},
{
id: "addon1@tests.mozilla.org",
name : "Install Tests 3",
iconURL: "http://example.com/icon.png",
homepageURL: "http://example.com/",
version: "1.0",
description: "Test add-on 3",
sourceURL: TESTROOT + "addons/browser_install1_3.xpi",
bootstrapped: false,
willFail: false,
}]; }];
@ -60,13 +76,12 @@ function test() {
} }
function end_test() { function end_test() {
close_manager(function() { close_manager();
Services.prefs.clearUserPref(PREF_GETADDONS_GETRECOMMENDED); Services.prefs.clearUserPref(PREF_GETADDONS_GETRECOMMENDED);
Services.prefs.clearUserPref(PREF_GETADDONS_BROWSERECOMMENDED); Services.prefs.clearUserPref(PREF_GETADDONS_BROWSERECOMMENDED);
Services.prefs.clearUserPref(PREF_GETADDONS_GETSEARCHRESULTS); Services.prefs.clearUserPref(PREF_GETADDONS_GETSEARCHRESULTS);
Services.prefs.clearUserPref(PREF_GETADDONS_BROWSESEARCHRESULTS); Services.prefs.clearUserPref(PREF_GETADDONS_BROWSESEARCHRESULTS);
finish(); finish();
});
} }
function add_test(test) { function add_test(test) {
@ -108,22 +123,31 @@ function installExtension(elt, aListener) {
ExtensionsView.installFromRepo(elt); ExtensionsView.installFromRepo(elt);
} }
function isRestartShown(aShown, isUpdate) { function isRestartShown(aShown, isUpdate, aCallback) {
let msg = document.getElementById("addons-messages"); let msg = document.getElementById("addons-messages");
ok(!!msg, "Have message box"); ok(!!msg, "Have message box");
let notification = msg.getNotificationWithValue("restart-app");
is(!!notification, aShown, "Restart exists = " + aShown);
if(notification) { let done = function(aNotification) {
let label = ""; is(!!aNotification, aShown, "Restart exists = " + aShown);
dump("Label: " + notification.label + "\n"); if (aShown && aNotification) {
if(isUpdate) let showsUpdate = aNotification.label.match(/update/i) != null;
label = "Add-ons updated. Restart to complete changes." // this test regularly fails due to race conditions here
else is(showsUpdate, isUpdate, "Restart shows correct message");
label = "Restart to complete changes."; }
is(notification.label, label, "Restart shows correct message"); msg.removeAllNotifications(true);
aCallback();
}
let notification = msg.getNotificationWithValue("restart-app");
if (!notification && aShown) {
window.addEventListener("AlertActive", function() {
window.removeEventListener("AlertActive", arguments.callee, true);
notification = msg.getNotificationWithValue("restart-app");
done(notification);
}, true);
} else {
done(notification);
} }
msg.removeAllNotifications(true)
} }
function checkAddonListing(aAddon, elt) { function checkAddonListing(aAddon, elt) {
@ -139,103 +163,79 @@ function checkAddonListing(aAddon, elt) {
checkAttribute(elt, "sourceURL", aAddon.sourceURL); checkAttribute(elt, "sourceURL", aAddon.sourceURL);
ok(elt.install, "Extension has install property"); ok(elt.install, "Extension has install property");
} }
function checkUpdate(aAddon, aSettings) { function checkUpdate(aSettings) {
let os = Services.obs; let os = Services.obs;
let ul = new updateListener(aSettings); let ul = new updateListener(aSettings);
os.addObserver(ul, "addon-update-ended", false); os.addObserver(ul, "addon-update-ended", false);
ExtensionsView.updateAll(); ExtensionsView.updateAll();
//aAddon.findUpdates(new updateListener(aSettings), AddonManager.UPDATE_WHEN_USER_REQUESTED, "4.0", "4.0");
} }
function get_addon_element(aId) { function get_addon_element(aId) {
return document.getElementById("urn:mozilla:item:" + aId);
var node = document.getElementById("addons-list").firstChild;
while (node) {
if (("urn:mozilla:item:" + aId) == node.id)
return node;
node = node.nextSibling;
}
return null;
} }
function open_manager(aView, aCallback) { function open_manager(aView, aCallback) {
var panelButton = document.getElementById("tool-panel-open") BrowserUI.showPanel("addons-container");
panelButton.click();
var addonsButton = document.getElementById("tool-addons");
addonsButton.click();
if (!ExtensionsView._list) { ExtensionsView.init();
window.addEventListener("ViewChanged", function() { ExtensionsView._delayedInit();
window.removeEventListener("ViewChanged", arguments.callee, true);
aCallback(); window.addEventListener("ViewChanged", function() {
}, true); window.removeEventListener("ViewChanged", arguments.callee, true);
aCallback();
ExtensionsView.init(); }, true);
ExtensionsView._delayedInit(); }
} else {
aCallback(); function close_manager() {
var prefsButton = document.getElementById("tool-preferences");
prefsButton.click();
ExtensionsView.clearSection();
ExtensionsView.clearSection("local");
ExtensionsView._list = null;
ExtensionsView._restartCount = 0;
BrowserUI.hidePanel();
}
// Installs an addon from the addons pref pane, and then
// updates it if requested. Checks to make sure
// restart notifications are shown at the right time
function installFromAddonsPage(aAddon, aDoUpdate) {
return function() {
open_manager(null, function() {
var elt = get_addon_element(aAddon.id);
checkAddonListing(aAddon, elt);
installExtension(elt, new installListener({
addon: aAddon,
onComplete: function() {
if (aDoUpdate) {
checkUpdate({
addon: addons[aAddon.updateIndex],
onComplete: function() {
close_manager();
run_next_test();
}
});
} else {
close_manager();
run_next_test();
}
}
}));
});
} }
} }
function close_manager(aCallback) { add_test(installFromAddonsPage(addons[0], true));
var prefsButton = document.getElementById("tool-preferences"); add_test(installFromAddonsPage(addons[1], false));
prefsButton.click();
BrowserUI.hidePanel();
aCallback();
}
// Installs a bootstrapped (restartless) addon first, and then
// updates it to a non-bootstrapped addon. Checks to make sure
// restart notifications are shown at the right time
// We currently don't handle bootstrapped addons very well, i.e.
// they aren't moved from the browse area into the main area
add_test(function() {
open_manager(null, function() {
var elt = get_addon_element("addon1@tests.mozilla.org");
checkAddonListing(addons[0], elt);
installExtension(elt, new installListener({
showRestart: false,
willFail: false,
onComplete: function(aAddon) {
checkUpdate(aAddon, {
showRestart: true,
willFail: false,
addon: addons[0],
onComplete: function(aAddon) {
close_manager(run_next_test);
}
});
}
}));
});
});
// Installs a non-bootstrapped addon and checks to make sure
// the correct restart notifications are shown
add_test(function() {
open_manager(null, function() {
var elt = get_addon_element("addon2@tests.mozilla.org");
checkAddonListing(addons[1], elt);
installExtension(elt, new installListener({
showRestart: true,
willFail: false,
onComplete: run_next_test,
}));
});
})
function installListener(aSettings) { function installListener(aSettings) {
this.willFail = aSettings.willFail; this.onComplete = aSettings.onComplete;
this.onComplete = aSettings.onComplete; this.addon = aSettings.addon;
this.showRestart = aSettings.showRestart;
} }
installListener.prototype = { installListener.prototype = {
onNewInstall : function(install) { }, onNewInstall : function(install) { },
onDownloadStarted : function(install) { onDownloadStarted : function(install) {
info("download started"); info("download started");
@ -250,7 +250,7 @@ installListener.prototype = {
info("download cancelled"); info("download cancelled");
}, },
onDownloadFailed : function(install) { onDownloadFailed : function(install) {
if(this.willFail) if(this.addon.willFail)
ok(false, "Install failed"); ok(false, "Install failed");
info("download failed"); info("download failed");
}, },
@ -258,14 +258,12 @@ installListener.prototype = {
info("Install started"); info("Install started");
}, },
onInstallEnded : function(install, addon) { onInstallEnded : function(install, addon) {
// this needs to fire after the extension manager's install ended info("Install ended");
let self = this; let self = this;
setTimeout(function() { isRestartShown(!this.addon.bootstrapped, false, function() {
info("Install ended");
isRestartShown(self.showRestart, false);
if(self.onComplete) if(self.onComplete)
self.onComplete(addon); self.onComplete();
}, 0); });
}, },
onInstallCancelled : function(install) { onInstallCancelled : function(install) {
info("Install cancelled"); info("Install cancelled");
@ -279,9 +277,7 @@ installListener.prototype = {
}; };
function updateListener(aSettings) { function updateListener(aSettings) {
this.willFail = aSettings.willFail;
this.onComplete = aSettings.onComplete; this.onComplete = aSettings.onComplete;
this.showRestart = aSettings.showRestart;
this.addon = aSettings.addon; this.addon = aSettings.addon;
} }
@ -289,25 +285,20 @@ updateListener.prototype = {
observe: function (aSubject, aTopic, aData) { observe: function (aSubject, aTopic, aData) {
switch(aTopic) { switch(aTopic) {
case "addon-update-ended" : case "addon-update-ended" :
info("Update ended");
// this needs to fire after the extension manager's install ended
let self = this;
let json = aSubject.QueryInterface(Ci.nsISupportsString).data; let json = aSubject.QueryInterface(Ci.nsISupportsString).data;
let update = JSON.parse(json); let update = JSON.parse(json);
if(update.id == this.addon.id) { if(update.id == this.addon.id) {
let element = get_addon_element(update.id);
ok(!!element, "Have element for upgrade");
let addon = element.addon;
setTimeout(function() {
isRestartShown(self.showRestart, true);
if(self.onComplete)
self.onComplete(addon);
}, 100);
let os = Services.obs; let os = Services.obs;
os.removeObserver(this, "addon-update-ended", false); os.removeObserver(this, "addon-update-ended", false);
let element = get_addon_element(update.id);
ok(!!element, "Have element for upgrade");
let self = this;
isRestartShown(!this.addon.bootstrapped, true, function() {
if(self.onComplete)
self.onComplete();
});
} }
break; break;
} }

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

@ -3,19 +3,19 @@
var gTests = []; var gTests = [];
var gCurrentTest = null; var gCurrentTest = null;
var expected = { var expected = {
"aboutButton": {"label": "Go to Page", "tagName": "button", "value": "About Fennec", "element_id": "prefs-about-button"}, "aboutButton": {"tagName": "button", "element_id": "prefs-about-button"},
"homepage": {"element_id": "prefs-homepage", "value": "Start page", "label": "Fennec Start", "homepage": {"element_id": "prefs-homepage",
"home_page": "prefs-homepage-default", "home_page_label": "Fennec Start", "home_page": "prefs-homepage-default",
"blank_page": "prefs-homepage-none", "blank_page_label": "Blank Page", "blank_page": "prefs-homepage-none",
"current_page": "prefs-homepage-currentpage", "current_page_label": "Use Current Page"}, "current_page": "prefs-homepage-currentpage"},
"doneButton": {"label": "Done", "tagName": "button"}, "doneButton": {"tagName": "button"},
"contentRegion": {"element_id": "prefs-content", "label": "Content"}, "contentRegion": {"element_id": "prefs-content"},
"imageRegion": {"pref": "permissions.default.image", "value": "Show images", "anonid": "input", "localName": "checkbox"}, "imageRegion": {"pref": "permissions.default.image", "anonid": "input", "localName": "checkbox"},
"jsRegion": {"pref": "javascript.enabled", "value": "Enable JavaScript", "anonid": "input", "localName": "checkbox"}, "jsRegion": {"pref": "javascript.enabled", "anonid": "input", "localName": "checkbox"},
"privacyRegion": {"element_id": "prefs-privacy", "label": "Privacy & Security"}, "privacyRegion": {"element_id": "prefs-privacy" },
"cookiesRegion": {"pref": "network.cookie.cookieBehavior", "value": "Allow cookies", "anonid": "input", "localName": "checkbox"}, "cookiesRegion": {"pref": "network.cookie.cookieBehavior", "anonid": "input", "localName": "checkbox"},
"passwordsRegion": {"pref": "signon.rememberSignons", "value": "Remember passwords", "anonid": "input", "localName": "checkbox"}, "passwordsRegion": {"pref": "signon.rememberSignons", "anonid": "input", "localName": "checkbox"},
"clearDataButton": {"value": "Clear private data", "element_id": "prefs-clear-data", "label": "Clear", "tagName": "button"} "clearDataButton": {"element_id": "prefs-clear-data", "tagName": "button"}
}; };
function getPreferencesElements() { function getPreferencesElements() {
@ -76,44 +76,27 @@ gTests.push({
// Check for *About page* // Check for *About page*
let about = expected.aboutButton; let about = expected.aboutButton;
var aboutRegion = document.getAnonymousElementByAttribute(prefsList, "title", "About Fennec"); var aboutRegion = document.getAnonymousElementByAttribute(prefsList, "title", "About Fennec");
var aboutLabel = document.getAnonymousElementByAttribute(aboutRegion, "class", "preftitle");
is(aboutLabel.value, about.value, "Label Text for About Fennec");
var aboutButton = document.getElementById(about.element_id); var aboutButton = document.getElementById(about.element_id);
is(aboutButton.label, about.label, "Text for about button is Go to Page");
is(aboutButton.tagName, about.tagName, "The About Fennec input must be a button"); is(aboutButton.tagName, about.tagName, "The About Fennec input must be a button");
// Check for *Startpage* // Check for *Startpage*
let homepage = expected.homepage; let homepage = expected.homepage;
var homepageRegion = document.getElementById(homepage.element_id); var homepageRegion = document.getElementById(homepage.element_id);
var homepageLabel = document.getAnonymousElementByAttribute(homepageRegion, "class", "preftitle");
is(homepageLabel.value, homepage.value, "Label Text for Start Page");
is(prefs.homeButton.label, homepage.label, "The text on the homepage label must be Fennec Start");
prefs.homeButton.click(); prefs.homeButton.click();
is(prefs.selectContainer.hidden, false, "Homepage select dialog must be visible"); is(prefs.selectContainer.hidden, false, "Homepage select dialog must be visible");
is(document.getElementById(homepage.home_page).label,
homepage.home_page_label, " First option is Fennec Start");
is(document.getElementById(homepage.blank_page).label,
homepage.blank_page_label, " Second option is Blank page");
is(document.getElementById(homepage.current_page).label,
homepage.current_page_label, " First option is Custom page");
let doneButton = expected.doneButton; let doneButton = expected.doneButton;
is(prefs.doneButton.label, doneButton.label, "The text for the Done button");
is(prefs.doneButton.tagName, doneButton.tagName, "The type of the Done input is button"); is(prefs.doneButton.tagName, doneButton.tagName, "The type of the Done input is button");
prefs.doneButton.click(); prefs.doneButton.click();
is(prefs.selectContainer.hidden, true, "Homepage select dialog must be closed"); is(prefs.selectContainer.hidden, true, "Homepage select dialog must be closed");
let content = expected.contentRegion; let content = expected.contentRegion;
var contentRegion = document.getElementById(content.element_id); var contentRegion = document.getElementById(content.element_id);
todo_is(contentRegion.label, content.label, "The Content region");
// Check for *Show images* // Check for *Show images*
var images = expected.imageRegion; var images = expected.imageRegion;
var imageRegion = document.getAnonymousElementByAttribute(contentRegion, "pref", images.pref); var imageRegion = document.getAnonymousElementByAttribute(contentRegion, "pref", images.pref);
var imageLabel = document.getAnonymousElementByAttribute(imageRegion, "class", "preftitle");
is(imageLabel.value, images.value, "Show images label");
var imageButton = document.getAnonymousElementByAttribute(imageRegion, "anonid", images.anonid); var imageButton = document.getAnonymousElementByAttribute(imageRegion, "anonid", images.anonid);
is(imageButton.localName, images.localName, "Show images checkbox check"); is(imageButton.localName, images.localName, "Show images checkbox check");
// Checkbox or radiobutton? // Checkbox or radiobutton?
@ -121,21 +104,16 @@ gTests.push({
// Check for *Enable javascript* // Check for *Enable javascript*
let js = expected.jsRegion; let js = expected.jsRegion;
var jsRegion = document.getAnonymousElementByAttribute(contentRegion, "pref", js.pref); var jsRegion = document.getAnonymousElementByAttribute(contentRegion, "pref", js.pref);
var jsLabel = document.getAnonymousElementByAttribute(jsRegion, "class", "preftitle");
is(jsLabel.value, js.value, "Enable JavaScript Label");
var jsButton = document.getAnonymousElementByAttribute(jsRegion, "anonid", js.anonid); var jsButton = document.getAnonymousElementByAttribute(jsRegion, "anonid", js.anonid);
is(jsButton.localName, js.localName, "Enable JavaScript checkbox check"); is(jsButton.localName, js.localName, "Enable JavaScript checkbox check");
// Checkbox or radiobutton? // Checkbox or radiobutton?
let privacyRegion = expected.privacyRegion; let privacyRegion = expected.privacyRegion;
var prefsPrivacy = document.getElementById(privacyRegion.element_id); var prefsPrivacy = document.getElementById(privacyRegion.element_id);
todo_is(prefsPrivacy.label, privacyRegion.label, "The privacy and security region");
// Check for *Allow cookies* // Check for *Allow cookies*
let cookies = expected.cookiesRegion; let cookies = expected.cookiesRegion;
var cookiesRegion = document.getAnonymousElementByAttribute(prefsPrivacy, "pref", cookies.pref); var cookiesRegion = document.getAnonymousElementByAttribute(prefsPrivacy, "pref", cookies.pref);
var cookiesLabel = document.getAnonymousElementByAttribute(cookiesRegion, "class", "preftitle");
is(cookiesLabel.value, cookies.value, "Allow cookies label");
var cookiesButton = document.getAnonymousElementByAttribute(cookiesRegion, "anonid", cookies.anonid); var cookiesButton = document.getAnonymousElementByAttribute(cookiesRegion, "anonid", cookies.anonid);
is(cookiesButton.localName, cookies.localName, "Allow cookies checkbox check"); is(cookiesButton.localName, cookies.localName, "Allow cookies checkbox check");
// Checkbox or radiobutton? // Checkbox or radiobutton?
@ -143,8 +121,6 @@ gTests.push({
// Check for *Remember password* // Check for *Remember password*
let passwords = expected.passwordsRegion; let passwords = expected.passwordsRegion;
var passwordsRegion = document.getAnonymousElementByAttribute(prefsPrivacy, "pref", passwords.pref); var passwordsRegion = document.getAnonymousElementByAttribute(prefsPrivacy, "pref", passwords.pref);
var passwordLabel = document.getAnonymousElementByAttribute(passwordsRegion, "class", "preftitle");
is(passwordLabel.value, passwords.value, "Remember Passwords Label");
var passwordsButton = document.getAnonymousElementByAttribute(passwordsRegion, "anonid", passwords.anonid); var passwordsButton = document.getAnonymousElementByAttribute(passwordsRegion, "anonid", passwords.anonid);
is(passwordsButton.localName, passwords.localName, "Allow cookies checkbox check"); is(passwordsButton.localName, passwords.localName, "Allow cookies checkbox check");
// Checkbox or radiobutton? // Checkbox or radiobutton?
@ -152,10 +128,7 @@ gTests.push({
// Check for *Clear Private Data* // Check for *Clear Private Data*
let clearData = expected.clearDataButton; let clearData = expected.clearDataButton;
var clearDataRegion = prefsPrivacy.lastChild; var clearDataRegion = prefsPrivacy.lastChild;
var clearDataLabel = document.getAnonymousElementByAttribute(clearDataRegion, "class", "preftitle");
is(clearDataLabel.value, clearData.value, "Clear Private Data Label");
var clearDataButton = document.getElementById(clearData.element_id); var clearDataButton = document.getElementById(clearData.element_id);
is(clearDataButton.label, clearData.label, "Label for Clear Private Data button");
is(clearDataButton.tagName, clearData.tagName, "Check for Clear Private Data button type"); is(clearDataButton.tagName, clearData.tagName, "Check for Clear Private Data button type");
// 3. Verify content & privacy and security reasons are gray and of same height // 3. Verify content & privacy and security reasons are gray and of same height