Bug 689702 - Test updating locale pref. r=mfinkle
authorWes Johnston <wjohnston@mozilla.com>
Thu, 29 Sep 2011 12:17:31 -0700
changeset 77872 8810d1986de2aa81ed5db717dd1df33706faeb1a
parent 77871 239a1408d5a01e84830b3913b7516a0559540ca5
child 77873 5d06ccaa88f055f4d03fbd248abc6699c6149212
push id3
push userfelipc@gmail.com
push dateFri, 30 Sep 2011 20:09:13 +0000
reviewersmfinkle
bugs689702
milestone10.0a1
Bug 689702 - Test updating locale pref. r=mfinkle
mobile/chrome/tests/Makefile.in
mobile/chrome/tests/browser_localerepository_pref.js
mobile/chrome/tests/locales_list.sjs
--- a/mobile/chrome/tests/Makefile.in
+++ b/mobile/chrome/tests/Makefile.in
@@ -93,16 +93,17 @@ include $(topsrcdir)/config/rules.mk
   $(warning browser_viewport.js disabled due to failures) \
   browser_viewport.sjs \
   browser_scrollbar.sjs \
   browser_title.sjs \
   browser_thumbnails.js \
   browser_install.xml \
   browser_upgrade.rdf\
   browser_localerepository.js \
+  browser_localerepository_pref.js \
   locales_list.sjs \
   mock_autocomplete.json\
   $(NULL)
 
 ifneq ($(OS_TARGET),Android)
 _BROWSER_FILES += \
   browser_autocomplete.html \
   browser_autocomplete.js \
new file mode 100644
--- /dev/null
+++ b/mobile/chrome/tests/browser_localerepository_pref.js
@@ -0,0 +1,35 @@
+var localeList = serverRoot + "locales_list.sjs";
+var PREF_LOCALE_LIST = "extensions.getLocales.get.url";
+
+Components.utils.import("resource://gre/modules/Services.jsm");
+Components.utils.import("resource://gre/modules/LocaleRepository.jsm");
+
+function test() {
+  waitForExplicitFinish();
+  runNextTest();
+}
+
+function end_test() {
+  Services.prefs.clearUserPref(PREF_LOCALE_LIST);
+}
+
+registerCleanupFunction(end_test);
+
+gTests.push({
+  desc: "Test dynamically changing extensions.getLocales.get.url",
+  run: function() {
+    Services.prefs.setCharPref(PREF_LOCALE_LIST, localeList);
+    LocaleRepository.getLocales(this.listLoaded.bind(this));
+  },
+
+  listLoaded: function(aLocales) {
+    is(aLocales.length, 1, "Correct number of locales were found");
+    Services.prefs.setCharPref(PREF_LOCALE_LIST, localeList + "?numvalid=2");
+    LocaleRepository.getLocales(this.secondListLoaded.bind(this));
+  },
+
+  secondListLoaded: function(aLocales) {
+    is(aLocales.length, 2, "Correct number of locales were found");
+    runNextTest();
+  }
+});
--- a/mobile/chrome/tests/locales_list.sjs
+++ b/mobile/chrome/tests/locales_list.sjs
@@ -28,30 +28,16 @@ function getLocale(aLocaleParams, aAppPa
    a[entry] = aAppParams[entry];
   }
  }
 
  l.app = a;
  return l;
 }
 
-let gLocales = [
- getLocale({IDNUMBER: 1}),
-
- /* These locales should fail in the LocaleRepository */
- getLocale({IDNUMBER: 1}),                         // no duplicate ids
- getLocale({IDNUMBER: 2, INSTALL: "INVALID_URL"}),
- getLocale({IDNUMBER: 3}, {APPID: "INVALID_ID"}),
- getLocale({IDNUMBER: 3}, {MAXVERSION: "0"}),
- getLocale({IDNUMBER: 4, TARGETLOCALE: ""}),
- getLocale({IDNUMBER: 5, NAME: ""}),
- getLocale({IDNUMBER: 6, VERSION: ""}),
- getLocale({IDNUMBER: 7, TYPENUMBER: ""})
-];
-
 let appTemplate = "<application>" +
 "<name>{APPNAME}</name>" +
  "<min_version>{MINVERSION}</min_version>" +
  "<max_version>{MAXVERSION}</max_version>" +
  "<appID>{APPID}</appID>" +
 "</application>";
 
 let template = "<addon>"+
@@ -80,30 +66,53 @@ let template = "<addon>"+
 function handleRequest(request, response) {
 
   response.setStatusLine(request.httpVersion, 200, "OK");
   response.setHeader("Content-Type", "text/xml", false);
 
   response.write("<?xml version=\"1.0\" encoding=\"UTF-8\"?>");
   response.write("<addons>");
 
-  for(var i = 0; i < gLocales.length; i++) {
+  let locales = [];
+  let query = decodeURIComponent(request.queryString || "").split("=");
+  switch(query[0]) {
+   case "numvalid":
+    let numValid = parseInt(query[1]);
+    for (let i = 0; i < numValid; i++) {
+     locales.push( getLocale({IDNUMBER: i}) );
+    }
+    break;
+   default :
+    locales.push( getLocale({IDNUMBER: 1}) );
+    /* These locales should fail in the LocaleRepository */
+    locales.push( getLocale({IDNUMBER: 1}) );                         // no duplicate ids
+    locales.push( getLocale({IDNUMBER: 2, INSTALL: "INVALID_URL"}) );
+    locales.push( getLocale({IDNUMBER: 3}, {APPID: "INVALID_ID"}) );
+    locales.push( getLocale({IDNUMBER: 3}, {MAXVERSION: "0"}) );
+    locales.push( getLocale({IDNUMBER: 4, TARGETLOCALE: ""}) );
+    locales.push( getLocale({IDNUMBER: 5, NAME: ""}) );
+    locales.push( getLocale({IDNUMBER: 6, VERSION: ""}) );
+    locales.push( getLocale({IDNUMBER: 7, TYPENUMBER: ""}) );
+    break;
+  }
+
+  for(var i = 0; i < locales.length; i++) {
    let t = template;
-   t = t.replace(/{TARGETLOCALE}/g, gLocales[i].TARGETLOCALE);
-   t = t.replace(/{NAME}/, gLocales[i].NAME);
-   t = t.replace(/{VERSION}/, gLocales[i].VERSION);
-   t = t.replace(/{INSTALL}/, gLocales[i].INSTALL);
-   t = t.replace(/{TYPENUMBER}/, gLocales[i].TYPENUMBER);
-   t = t.replace(/{TYPENAME}/, gLocales[i].TYPENAME);
-   t = t.replace(/{IDNUMBER}/, gLocales[i].IDNUMBER)
+   t = t.replace(/{TARGETLOCALE}/g, locales[i].TARGETLOCALE);
+   t = t.replace(/{NAME}/, locales[i].NAME);
+   t = t.replace(/{VERSION}/, locales[i].VERSION);
+   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)
 
    let a = appTemplate;
-   a = a.replace(/{APPNAME}/, gLocales[i].app.APPNAME);
-   a = a.replace(/{MINVERSION}/, gLocales[i].app.MINVERSION);
-   a = a.replace(/{MAXVERSION}/, gLocales[i].app.MAXVERSION);
-   a = a.replace(/{APPID}/, gLocales[i].app.APPID);
+   a = a.replace(/{APPNAME}/, locales[i].app.APPNAME);
+   a = a.replace(/{MINVERSION}/, locales[i].app.MINVERSION);
+   a = a.replace(/{MAXVERSION}/, locales[i].app.MAXVERSION);
+   a = a.replace(/{APPID}/, locales[i].app.APPID);
 
    t = t.replace(/{APPS}/, a);
    response.write(t);
   }
 
   response.write("</addons>");
 }