1 // Copyright (c) 2011 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 // This whole test runs as a separate browser_test because it depends on a
6 // static initialization inside third_party/icu (gDecimal in digitlst.cpp).
7 //
8 // That initialization depends on the current locale, and on certain locales
9 // will lead to wrong behavior. To make sure that the locale is set before
10 // icu is used, and that the "wrong" static value doesn't affect other tests,
11 // this test is executed on its own process.
12
13 #include "base/strings/string16.h"
14 #include "base/strings/utf_string_conversions.h"
15 #include "base/test/scoped_locale.h"
16 #include "chrome/test/base/in_process_browser_test.h"
17 #include "content/public/test/browser_test.h"
18 #include "ui/base/l10n/time_format.h"
19
20 using base::TimeDelta;
21
22 class TimeFormatBrowserTest : public InProcessBrowserTest {
23 public:
TimeFormatBrowserTest()24 TimeFormatBrowserTest() : scoped_locale_("fr_FR.utf-8") {
25 }
26
27 private:
28 base::ScopedLocale scoped_locale_;
29 };
30
IN_PROC_BROWSER_TEST_F(TimeFormatBrowserTest,DecimalPointNotDot)31 IN_PROC_BROWSER_TEST_F(TimeFormatBrowserTest, DecimalPointNotDot) {
32 // Some locales use a comma ',' instead of a dot '.' as the separator for
33 // decimal digits. The icu library wasn't handling this, leading to "1"
34 // being internally converted to "+1,0e00" and ultimately leading to "NaN".
35 // This showed up on the browser on estimated download time, for example.
36 // http://crbug.com/60476
37
38 base::string16 one_min =
39 ui::TimeFormat::Simple(ui::TimeFormat::FORMAT_DURATION,
40 ui::TimeFormat::LENGTH_SHORT,
41 TimeDelta::FromMinutes(1));
42 EXPECT_EQ(base::ASCIIToUTF16("1 min"), one_min);
43 }
44