mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-11-25 13:51:41 +00:00
Bug 684241 - Add basic tests for locale picker. r=mfinkle
This commit is contained in:
parent
aa3dada3f4
commit
9295f6a3a8
@ -13,7 +13,7 @@ let stringPrefs = [
|
||||
{ selector: "#picker-title", pref: "chooseLanguage", data: null },
|
||||
{ selector: "#continue-button", pref: "continue", data: null },
|
||||
{ selector: "#cancel-button", pref: "cancel", data: null },
|
||||
{ selector: "#intalling-message", pref: "installing", data: ["CURRENT_LOCALE"] },
|
||||
{ selector: "#installing-message", pref: "installing", data: ["CURRENT_LOCALE"] },
|
||||
{ selector: "#cancel-install-button", pref: "cancel", data: null },
|
||||
{ selector: "#installing-error", pref: "installerror", data: null },
|
||||
{ selector: "#install-continue", pref: "continue", data: null },
|
||||
@ -88,7 +88,7 @@ let LocaleUI = {
|
||||
return this.list = document.getElementById("language-list");
|
||||
},
|
||||
|
||||
_createItem: function(aId, aText, aLocale) {
|
||||
_createItem: function lp__createItem(aId, aText, aLocale) {
|
||||
let item = document.createElement("richlistitem");
|
||||
item.setAttribute("id", aId);
|
||||
|
||||
@ -109,7 +109,7 @@ let LocaleUI = {
|
||||
return item;
|
||||
},
|
||||
|
||||
addLocales: function(aLocales) {
|
||||
addLocales: function lp_addLocales(aLocales) {
|
||||
let fragment = document.createDocumentFragment();
|
||||
let selectedItem = null;
|
||||
let bestMatch = NO_MATCH;
|
||||
@ -158,9 +158,6 @@ let LocaleUI = {
|
||||
_locale: "",
|
||||
|
||||
set locale(aVal) {
|
||||
if (aVal == this._locale)
|
||||
return;
|
||||
|
||||
Services.prefs.setBoolPref("intl.locale.matchOS", false);
|
||||
Services.prefs.setCharPref("general.useragent.locale", aVal);
|
||||
this._locale = aVal;
|
||||
@ -194,7 +191,7 @@ let LocaleUI = {
|
||||
}
|
||||
},
|
||||
|
||||
installAddon: function() {
|
||||
installAddon: function lp_installAddon() {
|
||||
let locale = LocaleUI.list.selectedItem.locale;
|
||||
|
||||
if (locale.install) {
|
||||
@ -210,9 +207,9 @@ let LocaleUI = {
|
||||
cancelPicker: function() {
|
||||
if (this.pendingInstall)
|
||||
this.pendingInstall = null;
|
||||
|
||||
// restore the last known "good" locale
|
||||
this.locale = this.defaultLocale;
|
||||
this.updateStrings();
|
||||
this.closePicker();
|
||||
},
|
||||
|
||||
@ -252,8 +249,6 @@ let LocaleUI = {
|
||||
try { addonInstall.cancel(); }
|
||||
catch(ex) { }
|
||||
LocaleUI.pendingInstall = null;
|
||||
|
||||
this.locale = this.defaultLocale;
|
||||
}
|
||||
},
|
||||
|
||||
|
@ -30,7 +30,7 @@
|
||||
|
||||
<deck id="installer-page" class="pane" flex="1">
|
||||
<vbox id="installer-page-installing" flex="1" pack="center" align="center">
|
||||
<description id="intalling-message" class="install-message"/>
|
||||
<description id="installing-message" class="install-message"/>
|
||||
<button id="cancel-install-button" class="cancel" onclick="LocaleUI.cancelInstall();" crop="center"/>
|
||||
</vbox>
|
||||
<vbox id="installer-page-error" flex="1" pack="center" align="center">
|
||||
|
@ -74,6 +74,7 @@ _BROWSER_FILES = \
|
||||
browser_formsZoom.html \
|
||||
$(warning browser_formsZoom.js disabled due to failures) \
|
||||
browser_history.js \
|
||||
browser_localepicker.js \
|
||||
browser_mainui.js \
|
||||
browser_preferences_text.js \
|
||||
browser_preferences_fulltoggle.js \
|
||||
|
9
mobile/chrome/tests/addons/browser_locale1/boostrap.js
Normal file
9
mobile/chrome/tests/addons/browser_locale1/boostrap.js
Normal file
@ -0,0 +1,9 @@
|
||||
/* Any copyright is dedicated to the Public Domain.
|
||||
* http://creativecommons.org/publicdomain/zero/1.0/
|
||||
*/
|
||||
|
||||
function install(data, reason) {}
|
||||
function startup(data, reason) {}
|
||||
function shutdown(data, reason) {}
|
||||
function uninstall(data, reason) {}
|
||||
|
24
mobile/chrome/tests/addons/browser_locale1/install.rdf
Normal file
24
mobile/chrome/tests/addons/browser_locale1/install.rdf
Normal file
@ -0,0 +1,24 @@
|
||||
<?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>locale1@tests.mozilla.org</em:id>
|
||||
<em:version>1.0</em:version>
|
||||
<em:type>8</em:type>
|
||||
<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>
|
||||
|
||||
<!-- Front End MetaData -->
|
||||
<em:name>Test Locale</em:name>
|
||||
|
||||
</Description>
|
||||
</RDF>
|
282
mobile/chrome/tests/browser_localepicker.js
Normal file
282
mobile/chrome/tests/browser_localepicker.js
Normal file
@ -0,0 +1,282 @@
|
||||
/* Any copyright is dedicated to the Public Domain.
|
||||
* http://creativecommons.org/publicdomain/zero/1.0/
|
||||
*/
|
||||
|
||||
Components.utils.import("resource://gre/modules/Services.jsm");
|
||||
Components.utils.import("resource://gre/modules/XPCOMUtils.jsm");
|
||||
|
||||
const RELATIVE_DIR = "browser/mobile/chrome/tests/";
|
||||
const TESTROOT = "http://example.com/" + RELATIVE_DIR;
|
||||
const PREF_GET_LOCALES = "extensions.getLocales.get.url";
|
||||
|
||||
var gAvailable = [];
|
||||
|
||||
var restartObserver = {
|
||||
observe: function(aSubject, aTopic, aData) {
|
||||
// cancel restart requests
|
||||
aSubject.QueryInterface(Ci.nsISupportsPRBool);
|
||||
aSubject.data = true;
|
||||
},
|
||||
QueryInterface: XPCOMUtils.generateQI([Ci.nsIObserver])
|
||||
}
|
||||
|
||||
function test() {
|
||||
Services.obs.addObserver(restartObserver, "quit-application-requested", false);
|
||||
waitForExplicitFinish();
|
||||
Services.prefs.setCharPref(PREF_GET_LOCALES, TESTROOT + "locales_list.sjs?numvalid=2");
|
||||
|
||||
let chromeReg = Components.classes["@mozilla.org/chrome/chrome-registry;1"].getService(Components.interfaces.nsIXULChromeRegistry);
|
||||
chromeReg.QueryInterface(Ci.nsIToolkitChromeRegistry);
|
||||
let availableLocales = chromeReg.getLocalesForPackage("browser");
|
||||
while (availableLocales.hasMore())
|
||||
gAvailable.push( availableLocales.getNext() );
|
||||
|
||||
|
||||
// in order to test restart notifications being shown, we much open the settings panel once
|
||||
let settingsButton = document.getElementById("tool-panel-open");
|
||||
settingsButton.click();
|
||||
waitForAndContinue(runNextTest, function() {
|
||||
return !document.getElementById("panel-container").hidden;
|
||||
});
|
||||
}
|
||||
|
||||
function end_test() {
|
||||
BrowserUI.hidePanel();
|
||||
Services.prefs.clearUserPref(PREF_GET_LOCALES);
|
||||
Services.obs.removeObserver(restartObserver, "quit-application-requested");
|
||||
}
|
||||
|
||||
registerCleanupFunction(end_test);
|
||||
|
||||
function CheckListLoad(aList, aLength) {
|
||||
return function() {
|
||||
return aList.childNodes.length == aLength;
|
||||
}
|
||||
}
|
||||
|
||||
function CheckDeck(aDeck, aPanel) {
|
||||
return function() {
|
||||
return aDeck.selectedPanel == aPanel;
|
||||
}
|
||||
}
|
||||
|
||||
function LocaleTest(aName, aOptions) {
|
||||
var install = null;
|
||||
return {
|
||||
desc: aName,
|
||||
win: null,
|
||||
run: function lt_run() {
|
||||
this.loadedWindow = this.loadedWindow.bind(this);
|
||||
this.windowClosed = this.windowClosed.bind(this);
|
||||
this.win = Services.ww.openWindow(aOptions.opener, "chrome://browser/content/localePicker.xul", "_browser", "chrome,dialog=no,all", null);
|
||||
this.win.addEventListener("load", this.loadedWindow, false);
|
||||
},
|
||||
|
||||
loadedWindow: function lt_loadedWindow() {
|
||||
this.win.removeEventListener("load", this.loadedWindow, false);
|
||||
if (aOptions.opener)
|
||||
setTimeout(this.delayedLoadPicker.bind(this), 0);
|
||||
else
|
||||
setTimeout(this.delayedLoadMain.bind(this), 0);
|
||||
},
|
||||
|
||||
delayedLoadMain: function lt_delayedLoadMain() {
|
||||
let deck = this.win.document.getElementById("language-deck");
|
||||
let mainPage = this.win.document.getElementById("main-page");
|
||||
is(deck.selectedPanel, mainPage, "Deck is showing the main page");
|
||||
|
||||
if (aOptions.loadLocalesList) {
|
||||
// load the locales list
|
||||
let changeButton = this.win.document.getElementById("change-language");
|
||||
changeButton.click();
|
||||
this.delayedLoadPicker();
|
||||
} else {
|
||||
// click the "Continue in English" button
|
||||
let continueButton = this.win.document.getElementById("continue-in-button");
|
||||
ok(/english/i.test(continueButton.textContent), "Continue button says English");
|
||||
this.win.addEventListener("unload", this.windowClosed, false);
|
||||
continueButton.click();
|
||||
}
|
||||
},
|
||||
|
||||
delayedLoadPicker: function lt_delayedLoadPicker() {
|
||||
let deck = this.win.document.getElementById("language-deck");
|
||||
let pickerPage = this.win.document.getElementById("picker-page");
|
||||
is(deck.selectedPanel, pickerPage, "Deck is showing the picker page");
|
||||
|
||||
let list = this.win.document.getElementById("language-list");
|
||||
// wait till the list shows the number of locales bundled with this build + the 2 from the downloaded list
|
||||
waitForAndContinue(this.listLoaded.bind(this), CheckListLoad(list, gAvailable.length + 2));
|
||||
},
|
||||
|
||||
listLoaded: function() {
|
||||
let continueButton = this.win.document.getElementById("continue-button");
|
||||
let cancelButton = this.win.document.getElementById("cancel-button");
|
||||
ok(/continue/i.test(continueButton.textContent), "Continue button has correct text");
|
||||
ok(/cancel/i.test(cancelButton.textContent), "Cancel button has correct text");
|
||||
|
||||
let list = this.win.document.getElementById("language-list");
|
||||
is(list.childNodes.length, gAvailable.length + 2, "List has correct number of children");
|
||||
|
||||
let nextSelected = null;
|
||||
let selectedItem = null;
|
||||
for(var i = 0; i < list.childNodes.length; i++) {
|
||||
let child = list.childNodes[i];
|
||||
if (/english/i.test(child.textContent)) {
|
||||
ok(child.hasAttribute("selected"), "English is initially selected");
|
||||
selectedItem = child;
|
||||
} else {
|
||||
ok(!child.hasAttribute("selected"), "Language is not selected");
|
||||
if (aOptions.selectAddon && child.textContent == aOptions.selectAddon.name)
|
||||
nextSelected = child;
|
||||
}
|
||||
}
|
||||
this.testInstallingItem(nextSelected);
|
||||
},
|
||||
|
||||
testInstallingItem: function lt_testInstallingItem(aSelect) {
|
||||
let continueButton = this.win.document.getElementById("continue-button");
|
||||
let cancelButton = this.win.document.getElementById("cancel-button");
|
||||
|
||||
if (aSelect) {
|
||||
aSelect.click();
|
||||
is(continueButton.textContent, aOptions.selectAddon.continueButton, "Continue button says " + aOptions.selectAddon.continueButton);
|
||||
is(cancelButton.textContent, aOptions.selectAddon.cancelButton, "Cancel button says " + aOptions.selectAddon.cancelButton);
|
||||
let title = this.win.document.getElementById("picker-title");
|
||||
is(title.textContent, aOptions.selectAddon.title, "Title says " + aOptions.selectAddon.title);
|
||||
continueButton.click();
|
||||
|
||||
let deck = this.win.document.getElementById("language-deck");
|
||||
let installerPage = this.win.document.getElementById("installer-page");
|
||||
is(deck.selectedPanel, installerPage, "Deck is showing the installer page");
|
||||
|
||||
let installingPage = this.win.document.getElementById("installer-page-installing");
|
||||
is(installerPage.selectedPanel, installingPage, "Installer is showing installing page");
|
||||
let installMsg = this.win.document.getElementById("installing-message");
|
||||
is(installMsg.textContent, aOptions.selectAddon.installMessage, "Installer is showing correct message");
|
||||
|
||||
if (aOptions.selectAddon.willFail) {
|
||||
let failedPage = this.win.document.getElementById("installer-page-error");
|
||||
waitForAndContinue(this.installFailed.bind(this), CheckDeck(installerPage, failedPage));
|
||||
} else {
|
||||
let install = aSelect.locale;
|
||||
this.win.addEventListener("unload", this.windowClosed, false);
|
||||
}
|
||||
} else {
|
||||
this.cancelList();
|
||||
}
|
||||
},
|
||||
|
||||
installFailed: function lt_installFailed() {
|
||||
let continueButton = this.win.document.getElementById("install-continue");
|
||||
is(continueButton.textContent, aOptions.selectAddon.installFailed, "Install failed button has correct label");
|
||||
continueButton.click();
|
||||
|
||||
let deck = this.win.document.getElementById("language-deck");
|
||||
let pickerPage = this.win.document.getElementById("picker-page");
|
||||
is(deck.selectedPanel, pickerPage, "Deck is showing the picker page");
|
||||
this.cancelList();
|
||||
},
|
||||
|
||||
cancelList: function lt_cancelList() {
|
||||
this.win.addEventListener("unload", this.windowClosed, false);
|
||||
|
||||
let cancelButton = this.win.document.getElementById("cancel-button");
|
||||
cancelButton.click();
|
||||
if (!aOptions.opener) {
|
||||
// canceling out of the list, should revert back to english ui
|
||||
let deck = this.win.document.getElementById("language-deck");
|
||||
let mainPage = this.win.document.getElementById("main-page");
|
||||
is(deck.selectedPanel, mainPage, "Deck is showing the main page again");
|
||||
let continueButton = this.win.document.getElementById("continue-in-button");
|
||||
ok(/english/i.test(continueButton.textContent), "Cancelling returned the UI to English");
|
||||
continueButton.click();
|
||||
}
|
||||
},
|
||||
|
||||
windowClosed: function lt_windowClosed(aEvent) {
|
||||
this.checkMainUI(aOptions.selectAddon);
|
||||
|
||||
Services.prefs.clearUserPref("intl.locale.matchOS");
|
||||
Services.prefs.clearUserPref("general.useragent.locale");
|
||||
window.PreferencesView.hideRestart();
|
||||
|
||||
if (install)
|
||||
install.uninstall();
|
||||
|
||||
runNextTest();
|
||||
},
|
||||
|
||||
checkMainUI: function(aAddon) {
|
||||
let systemPref = "";
|
||||
let userAgentPref = "";
|
||||
try {
|
||||
systemPref = Services.prefs.getBoolPref("intl.locale.matchOS");
|
||||
userAgentPref = Services.prefs.getCharPref("general.useragent.locale")
|
||||
} catch(ex) { }
|
||||
|
||||
let notification = document.getElementById("prefs-messages").getNotificationWithValue("restart-app");
|
||||
let showRestart = aAddon ? !aAddon.willFail : false;
|
||||
is(!!notification, showRestart, "Restart message is " + (showRestart ? "" : "not ") + "shown");
|
||||
|
||||
// check that locale pref has been updated
|
||||
let localeName = aAddon ? aAddon.locale : "en-US";
|
||||
is(systemPref, false, "Match system locale is false");
|
||||
is(userAgentPref, localeName, "User agent locale is " + localeName);
|
||||
let buttonLabel = aAddon ? aAddon.localeName : "English (US)";
|
||||
is(document.getElementById("prefs-uilanguage-button").getAttribute("label"), buttonLabel, "Locale button says " + buttonLabel);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
let invalidInstall = {
|
||||
name: "Test Locale 0",
|
||||
installMessage: "INSTALLINGTest Locale 0",
|
||||
continueButton: "CONTINUE",
|
||||
cancelButton: "CANCEL",
|
||||
title: "CHOOSELANGUAGE",
|
||||
installFailed: "CONTINUE",
|
||||
locale: "en-US",
|
||||
localeName: "English (US)",
|
||||
willFail: true
|
||||
};
|
||||
let validInstall = {
|
||||
name: "Test Locale 1",
|
||||
installMessage: "INSTALLINGTest Locale 1",
|
||||
continueButton: "CONTINUE",
|
||||
cancelButton: "CANCEL",
|
||||
title: "CHOOSELANGUAGE",
|
||||
locale: "test1",
|
||||
localeName: "test1",
|
||||
willFail: false
|
||||
}
|
||||
|
||||
gTests.push(new LocaleTest("Load locale picker with no opener and continue",
|
||||
{ opener: null,
|
||||
loadLocalesList: false,
|
||||
selectAddon: null
|
||||
}));
|
||||
|
||||
gTests.push(new LocaleTest("Load locale picker with no opener and try to install an invalid language",
|
||||
{ opener: null,
|
||||
loadLocalesList: true,
|
||||
selectAddon: invalidInstall
|
||||
}));
|
||||
|
||||
gTests.push(new LocaleTest("Load locale picker with no opener and try to install a valid language",
|
||||
{ opener: null,
|
||||
loadLocalesList: true,
|
||||
selectAddon: validInstall
|
||||
}));
|
||||
|
||||
gTests.push(new LocaleTest("Load locale picker with opener and try to install an invalid language",
|
||||
{ opener: this.window,
|
||||
loadLocalesList: true,
|
||||
selectAddon: invalidInstall
|
||||
}));
|
||||
|
||||
gTests.push(new LocaleTest("Load locale picker with opener and try to install a valid language",
|
||||
{ opener: this.window,
|
||||
loadLocalesList: true,
|
||||
selectAddon: validInstall
|
||||
}));
|
@ -25,14 +25,14 @@ gTests.push({
|
||||
listLoaded: function(aLocales) {
|
||||
is(aLocales.length, 1, "Correct number of locales were found");
|
||||
isnot(aLocales[0].addon, null, "Locale has an addon");
|
||||
is(aLocales[0].xpiURL, "http://www.example.com/mylocale.xpi", "Locale has correct xpi url");
|
||||
is(aLocales[0].xpiURL, "http://www.example.com/browser/mobile/chrome/tests/addons/browser_locale1.xpi", "Locale has correct xpi url");
|
||||
is(aLocales[0].xpiHash, null, "Locale has correct hash");
|
||||
|
||||
is(aLocales[0].addon.id, "langpack-test-1@firefox-mobile.mozilla.org", "Locale has correct id");
|
||||
is(aLocales[0].addon.name, "Test Locale", "Locale has correct name");
|
||||
is(aLocales[0].addon.id, "langpack-test1@firefox-mobile.mozilla.org", "Locale has correct id");
|
||||
is(aLocales[0].addon.name, "Test Locale 1", "Locale has correct name");
|
||||
is(aLocales[0].addon.type, "language", "Locale has correct type");
|
||||
|
||||
is(aLocales[0].addon.targetLocale, "test", "Locale has correct target locale");
|
||||
is(aLocales[0].addon.targetLocale, "test1", "Locale has correct target locale");
|
||||
is(aLocales[0].addon.version, "1.0", "Locale has correct version");
|
||||
runNextTest();
|
||||
}
|
||||
|
@ -3,10 +3,10 @@ Components.utils.import("resource://gre/modules/Services.jsm");
|
||||
|
||||
function getLocale(aLocaleParams, aAppParams) {
|
||||
let l = {
|
||||
TARGETLOCALE: "test",
|
||||
NAME: "Test Locale",
|
||||
TARGETLOCALE: "test{IDNUMBER}",
|
||||
NAME: "Test Locale {IDNUMBER}",
|
||||
VERSION: "1.0",
|
||||
INSTALL: "http://www.example.com/mylocale.xpi",
|
||||
INSTALL: "http://www.example.com/browser/mobile/chrome/tests/addons/browser_locale{IDNUMBER}.xpi",
|
||||
TYPENUMBER: 5,
|
||||
TYPENAME: "Language Pack (Application)",
|
||||
IDNUMBER: "",
|
||||
@ -44,20 +44,20 @@ let template = "<addon>"+
|
||||
"<target_locale>{TARGETLOCALE}</target_locale>" +
|
||||
"<name>{NAME}</name>"+
|
||||
"<type id=\"{TYPENUMBER}\">{TYPENAME}</type>"+
|
||||
"<guid>langpack-{TARGETLOCALE}-{IDNUMBER}@firefox-mobile.mozilla.org</guid>"+
|
||||
"<guid>langpack-{TARGETLOCALE}@firefox-mobile.mozilla.org</guid>"+
|
||||
"<version>{VERSION}</version>"+
|
||||
"<status id=\"4\">Public</status>"+
|
||||
"<compatible_applications>{APPS}</compatible_applications>"+
|
||||
"<all_compatible_os><os>ALL</os></all_compatible_os>"+
|
||||
"<install os=\"ALL\">{INSTALL}</install><strings>\n" +
|
||||
"title=TITLE\n" +
|
||||
"continueIn=CONTINUEIN\n" +
|
||||
"continueIn=CONTINUEIN%S\n" +
|
||||
"name=NAME\n" +
|
||||
"choose=CHOOSE\n" +
|
||||
"chooseLanguage=CHOOSELANGUAGE\n" +
|
||||
"cancel=CANCEL\n" +
|
||||
"continue=CONTINUE\n" +
|
||||
"installing=INSTALLING\n" +
|
||||
"installing=INSTALLING%S\n" +
|
||||
"installerror=INSTALLERROR\n" +
|
||||
"loading=LOADING" +
|
||||
"</strings>"+
|
||||
@ -105,7 +105,7 @@ function handleRequest(request, response) {
|
||||
t = t.replace(/{INSTALL}/, locales[i].INSTALL);
|
||||
t = t.replace(/{TYPENUMBER}/, locales[i].TYPENUMBER);
|
||||
t = t.replace(/{TYPENAME}/, locales[i].TYPENAME);
|
||||
t = t.replace(/{IDNUMBER}/, locales[i].IDNUMBER)
|
||||
t = t.replace(/{IDNUMBER}/g, locales[i].IDNUMBER)
|
||||
|
||||
let a = appTemplate;
|
||||
a = a.replace(/{APPNAME}/, locales[i].app.APPNAME);
|
||||
|
Loading…
Reference in New Issue
Block a user