Bug 1045053 - Part 2: tests for OS locale handling. r=bnicholson
☠☠ backed out by 02b0fb265642 ☠ ☠
authorRichard Newman <rnewman@mozilla.com>
Wed, 01 Oct 2014 18:38:43 -0700
changeset 231658 9ac001517068834b5a4df775c3d894046590db69
parent 231657 4782b099ef938adf55d28278c9a87c9a0637aba6
child 231659 d263222c8c443210a83664cfda02a9698b3de506
push id4187
push userbhearsum@mozilla.com
push dateFri, 28 Nov 2014 15:29:12 +0000
treeherdermozilla-beta@f23cc6a30c11 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbnicholson
bugs1045053
milestone35.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1045053 - Part 2: tests for OS locale handling. r=bnicholson
mobile/android/base/tests/BaseTest.java
mobile/android/base/tests/JavascriptTest.java
mobile/android/base/tests/robocop.ini
mobile/android/base/tests/testOSLocale.java
mobile/android/base/tests/testOSLocale.js
--- a/mobile/android/base/tests/BaseTest.java
+++ b/mobile/android/base/tests/BaseTest.java
@@ -77,16 +77,26 @@ abstract class BaseTest extends BaseRobo
     protected String mRawBaseUrl;
     protected String mProfile;
     public Device mDevice;
     protected DatabaseHelper mDatabaseHelper;
     protected int mScreenMidWidth;
     protected int mScreenMidHeight;
     private final HashSet<Integer> mKnownTabIDs = new HashSet<Integer>();
 
+    protected void blockForDelayedStartup() {
+        try {
+            Actions.EventExpecter delayedStartupExpector = mActions.expectGeckoEvent("Gecko:DelayedStartup");
+            delayedStartupExpector.blockForEvent(GECKO_READY_WAIT_MS, true);
+            delayedStartupExpector.unregisterListener();
+        } catch (Exception e) {
+            mAsserter.dumpLog("Exception in blockForDelayedStartup", e);
+        }
+    }
+
     protected void blockForGeckoReady() {
         try {
             Actions.EventExpecter geckoReadyExpector = mActions.expectGeckoEvent("Gecko:Ready");
             if (!GeckoThread.checkLaunchState(LaunchState.GeckoRunning)) {
                 geckoReadyExpector.blockForEvent(GECKO_READY_WAIT_MS, true);
             }
             geckoReadyExpector.unregisterListener();
         } catch (Exception e) {
--- a/mobile/android/base/tests/JavascriptTest.java
+++ b/mobile/android/base/tests/JavascriptTest.java
@@ -16,21 +16,24 @@ public class JavascriptTest extends Base
     public JavascriptTest(String javascriptUrl) {
         super();
         this.javascriptUrl = javascriptUrl;
     }
 
     public void testJavascript() throws Exception {
         blockForGeckoReady();
 
+        doTestJavascript();
+    }
+
+    protected void doTestJavascript() throws Exception {
         // We want to be waiting for Robocop messages before the page is loaded
         // because the test harness runs each test in the suite (and possibly
         // completes testing) before the page load event is fired.
-        final Actions.EventExpecter expecter =
-            mActions.expectGeckoEvent(EVENT_TYPE);
+        final Actions.EventExpecter expecter = mActions.expectGeckoEvent(EVENT_TYPE);
         mAsserter.dumpLog("Registered listener for " + EVENT_TYPE);
 
         final String url = getAbsoluteUrl(StringHelper.getHarnessUrlForJavascript(javascriptUrl));
         mAsserter.dumpLog("Loading JavaScript test from " + url);
         loadUrl(url);
 
         final JavascriptMessageParser testMessageParser =
                 new JavascriptMessageParser(mAsserter, false);
--- a/mobile/android/base/tests/robocop.ini
+++ b/mobile/android/base/tests/robocop.ini
@@ -99,16 +99,17 @@ skip-if = android_version == "10"
 [testAccounts]
 [testAndroidLog]
 [testBrowserDiscovery]
 [testDebuggerServer]
 [testDeviceSearchEngine]
 [testJNI]
 # [testMozPay] # see bug 945675
 [testOrderedBroadcast]
+[testOSLocale]
 [testResourceSubstitutions]
 [testRestrictedProfiles]
 [testSharedPreferences]
 [testSimpleDiscovery]
 [testUITelemetry]
 [testVideoDiscovery]
 
 # Used for Talos, please don't use in mochitest
new file mode 100644
--- /dev/null
+++ b/mobile/android/base/tests/testOSLocale.java
@@ -0,0 +1,25 @@
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+package org.mozilla.gecko.tests;
+
+import org.mozilla.gecko.Actions;
+
+public class testOSLocale extends JavascriptTest {
+    private static final String GECKO_DELAYED_STARTUP = "Gecko:DelayedStartup";
+
+    public testOSLocale() {
+        super("testOSLocale.js");
+    }
+
+    @Override
+    public void testJavascript() throws Exception {
+        final Actions.EventExpecter expecter = mActions.expectGeckoEvent(GECKO_DELAYED_STARTUP);
+        expecter.blockForEvent(MAX_WAIT_MS, true);
+
+        // We wait for Gecko:DelayedStartup above, so we *must not* wait for Gecko:Ready.
+        // Call doTestJavascript directly.
+        super.doTestJavascript();
+    }
+}
new file mode 100644
--- /dev/null
+++ b/mobile/android/base/tests/testOSLocale.js
@@ -0,0 +1,93 @@
+// -*- indent-tabs-mode: nil; js-indent-level: 2 -*-
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this file,
+ * You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+const { utils: Cu, interfaces: Ci } = Components;
+
+Cu.import("resource://gre/modules/Services.jsm");
+
+/**
+ * If we ever start running tests with a different default OS locale,
+ * this test will break.
+ */
+
+function getOSLocale() {
+  try {
+    return Services.prefs.getCharPref("intl.locale.os");
+  } catch (ex) {
+    return null;
+  }
+}
+
+function getAcceptLanguages() {
+  return Services.prefs.getComplexValue("intl.accept_languages",
+                                        Ci.nsIPrefLocalizedString).data;
+}
+
+/**
+ * Ensure that by the time we come to run, the OS locale
+ * has been sent over the wire and persisted in prefs.
+ */
+add_test(function test_OSLocale() {
+  let osObserver = function () {
+    Services.prefs.removeObserver("intl.locale.os", osObserver);
+    do_check_eq(getOSLocale(), "en-US");
+    run_next_test();
+  };
+
+  let osLocale = getOSLocale();
+  if (osLocale) {
+    // Proceed with the test.
+    run_next_test();
+    return;
+  }
+
+  // Otherwise, wait for it. We're probably running before the message has
+  // been handled.
+  Services.prefs.addObserver("intl.locale.os", osObserver, false);
+});
+
+add_test(function test_AcceptLanguages() {
+  // Fake that we have an app locale, and fake
+  // a different OS locale to make it interesting.
+
+  // The correct set here depends on whether the
+  // browser was built with multiple locales or not.
+  // This is exasperating, but hey.
+
+  // Expected, from es-ES's intl.properties:
+  const ES_ES_EXPECTED_BASE = "es-ES,es,en-US,en";
+
+  // Expected, from en-US (the default).
+  const MONO_EXPECTED_BASE = "en-US,en";
+
+  // This will always be the same: it's deduced from our language setting and
+  // the fake OS.
+  const SELECTED_LOCALES = "es-es,fr,";
+
+  // And so the two expected results:
+  const ES_ES_EXPECTED = SELECTED_LOCALES +
+                         "es,en-us,en";      // Remainder of ES_ES_EXPECTED_BASE.
+  const MONO_EXPECTED = SELECTED_LOCALES +
+                        "en-us,en";          // Remainder of MONO_EXPECTED_BASE.
+
+  let observer = function () {
+    Services.prefs.removeObserver("intl.accept_languages", observer);
+
+    // And so intl.accept_languages should be one of these two...
+    let acc = getAcceptLanguages();
+    let is_es = ES_ES_EXPECTED == acc;
+    let is_en = MONO_EXPECTED == acc;
+
+    do_check_true(is_es || is_en);
+    do_check_true(is_es != is_en);
+    run_next_test();
+  };
+
+  Services.prefs.setCharPref("intl.locale.os", "fr");
+  Services.prefs.addObserver("intl.accept_languages", observer, false);
+  Services.obs.notifyObservers(null, "Locale:Changed", "es-ES");
+});
+
+run_next_test();