summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--DEPS2
-rw-r--r--base/base.gyp1
-rw-r--r--base/sys_string_conversions_unittest.cc25
-rw-r--r--base/test/test_util.h41
-rw-r--r--chrome/chrome_tests.gypi1
-rw-r--r--chrome/common/time_format_browsertest.cc42
6 files changed, 90 insertions, 22 deletions
diff --git a/DEPS b/DEPS
index b0c4b4d..5e7bb87 100644
--- a/DEPS
+++ b/DEPS
@@ -53,7 +53,7 @@ deps = {
"/trunk/deps/third_party/WebKit@76115",
"src/third_party/icu":
- "/trunk/deps/third_party/icu46@87668",
+ "/trunk/deps/third_party/icu46@88321",
"src/third_party/hunspell":
"/trunk/deps/third_party/hunspell@65351",
diff --git a/base/base.gyp b/base/base.gyp
index c1bdcb3..21befe4 100644
--- a/base/base.gyp
+++ b/base/base.gyp
@@ -334,6 +334,7 @@
'test/test_switches.h',
'test/test_timeouts.cc',
'test/test_timeouts.h',
+ 'test/test_util.h',
],
},
{
diff --git a/base/sys_string_conversions_unittest.cc b/base/sys_string_conversions_unittest.cc
index 708da09..fa711f3 100644
--- a/base/sys_string_conversions_unittest.cc
+++ b/base/sys_string_conversions_unittest.cc
@@ -2,12 +2,12 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-#include <locale.h>
#include <string>
#include "base/basictypes.h"
#include "base/string_piece.h"
+#include "base/test/test_util.h"
#include "base/utf_string_conversions.h"
#include "base/sys_string_conversions.h"
#include "testing/gtest/include/gtest/gtest.h"
@@ -74,27 +74,10 @@ TEST(SysStrings, SysUTF8ToWide) {
}
#if defined(OS_LINUX) // Tests depend on setting a specific Linux locale.
-namespace {
-
-class ScopedSetLocale {
- public:
- explicit ScopedSetLocale(const char* locale) {
- old_locale_ = setlocale(LC_ALL, NULL);
- setlocale(LC_ALL, locale);
- }
- ~ScopedSetLocale() {
- setlocale(LC_ALL, old_locale_.c_str());
- }
-
- private:
- std::string old_locale_;
-};
-
-} // namespace
TEST(SysStrings, SysWideToNativeMB) {
using base::SysWideToNativeMB;
- ScopedSetLocale locale("en_US.utf-8");
+ base::ScopedSetLocale locale("en_US.utf-8");
EXPECT_EQ("Hello, world", SysWideToNativeMB(L"Hello, world"));
EXPECT_EQ("\xe4\xbd\xa0\xe5\xa5\xbd", SysWideToNativeMB(L"\x4f60\x597d"));
@@ -125,7 +108,7 @@ TEST(SysStrings, SysWideToNativeMB) {
// We assume the test is running in a UTF8 locale.
TEST(SysStrings, SysNativeMBToWide) {
using base::SysNativeMBToWide;
- ScopedSetLocale locale("en_US.utf-8");
+ base::ScopedSetLocale locale("en_US.utf-8");
EXPECT_EQ(L"Hello, world", SysNativeMBToWide("Hello, world"));
EXPECT_EQ(L"\x4f60\x597d", SysNativeMBToWide("\xe4\xbd\xa0\xe5\xa5\xbd"));
// >16 bits
@@ -179,7 +162,7 @@ static const wchar_t* const kConvertRoundtripCases[] = {
TEST(SysStrings, SysNativeMBAndWide) {
- ScopedSetLocale locale("en_US.utf-8");
+ base::ScopedSetLocale locale("en_US.utf-8");
for (size_t i = 0; i < arraysize(kConvertRoundtripCases); ++i) {
std::wstring wide = kConvertRoundtripCases[i];
std::wstring trip = base::SysNativeMBToWide(base::SysWideToNativeMB(wide));
diff --git a/base/test/test_util.h b/base/test/test_util.h
new file mode 100644
index 0000000..63f0b16
--- /dev/null
+++ b/base/test/test_util.h
@@ -0,0 +1,41 @@
+// Copyright (c) 2011 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef BASE_TEST_TEST_UTIL_H_
+#define BASE_TEST_TEST_UTIL_H_
+#pragma once
+
+// Generic utilities used only by tests.
+
+#include <locale.h>
+
+#include <string>
+
+namespace base {
+
+#if defined(OS_POSIX)
+
+// Sets the given |locale| on construction, and restores the previous locale
+// on destruction.
+class ScopedSetLocale {
+ public:
+ explicit ScopedSetLocale(const char* locale) {
+ old_locale_ = setlocale(LC_ALL, NULL);
+ setlocale(LC_ALL, locale);
+ }
+ ~ScopedSetLocale() {
+ setlocale(LC_ALL, old_locale_.c_str());
+ }
+
+ private:
+ std::string old_locale_;
+
+ DISALLOW_COPY_AND_ASSIGN(ScopedSetLocale);
+};
+
+#endif
+
+} // namespace base
+
+#endif // BASE_TEST_TEST_UTIL_H_
diff --git a/chrome/chrome_tests.gypi b/chrome/chrome_tests.gypi
index 9cae015..282509d 100644
--- a/chrome/chrome_tests.gypi
+++ b/chrome/chrome_tests.gypi
@@ -2484,6 +2484,7 @@
'browser/ui/webui/web_ui_browsertest.h',
'browser/ui/webui/web_ui_test_handler.cc',
'browser/ui/webui/web_ui_test_handler.h',
+ 'common/time_format_browsertest.cc',
'renderer/autofill/autofill_browsertest.cc',
'renderer/autofill/form_autocomplete_browsertest.cc',
'renderer/autofill/form_manager_browsertest.cc',
diff --git a/chrome/common/time_format_browsertest.cc b/chrome/common/time_format_browsertest.cc
new file mode 100644
index 0000000..3aa8582
--- /dev/null
+++ b/chrome/common/time_format_browsertest.cc
@@ -0,0 +1,42 @@
+// Copyright (c) 2011 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+// This whole test runs as a separate browser_test because it depends on a
+// static initialization inside third_party/icu (gDecimal in digitlst.cpp).
+//
+// That initialization depends on the current locale, and on certain locales
+// will lead to wrong behavior. To make sure that the locale is set before
+// icu is used, and that the "wrong" static value doesn't affect other tests,
+// this test is executed on its own process.
+
+#include "base/string16.h"
+#include "base/test/test_util.h"
+#include "base/utf_string_conversions.h"
+#include "chrome/common/time_format.h"
+#include "chrome/test/in_process_browser_test.h"
+
+#if defined(OS_POSIX)
+using base::TimeDelta;
+
+class TimeFormatBrowserTest: public InProcessBrowserTest {
+ public:
+ TimeFormatBrowserTest(): scoped_locale_("fr_FR.utf-8") {}
+
+ private:
+ base::ScopedSetLocale scoped_locale_;
+};
+
+IN_PROC_BROWSER_TEST_F(TimeFormatBrowserTest, DecimalPointNotDot) {
+ // Some locales use a comma ',' instead of a dot '.' as the separator for
+ // decimal digits. The icu library wasn't handling this, leading to "1"
+ // being internally converted to "+1,0e00" and ultimately leading to "NaN".
+ // This showed up on the browser on estimated download time, for example.
+ // http://crbug.com/60476
+
+ string16 one_min = TimeFormat::TimeRemainingShort(TimeDelta::FromMinutes(1));
+ EXPECT_EQ(ASCIIToUTF16("1 min"), one_min) << "fr_FR.utf-8 locale generates "
+ << one_min;
+}
+
+#endif // defined(OS_POSIX)