1 // Copyright (c) 2012 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.
5 #include "base/command_line.h"
6 #include "base/environment.h"
7 #include "build/build_config.h"
8 #include "chrome/test/base/in_process_browser_test.h"
9 #include "ui/base/ui_base_switches.h"
13 // A class that over-writes the system locale only in a scope. To emulate the
14 // specified environment on Linux, this class over-writes a LC_ALL environment
15 // variable when creating a LocaleTest object and restore it with the original
16 // value when deleting the object. (This environment variable may affect other
17 // tests and we have to restore it regardless of the results of LocaleTests.)
20 explicit ScopedLocale(const char* locale
) : locale_(locale
) {
22 old_locale_
= getenv("LC_ALL");
25 const char* chrome_locale
;
26 const char* system_locale
;
28 { "da", "da_DK.UTF-8" },
29 { "he", "he_IL.UTF-8" },
30 { "zh-TW", "zh_TW.UTF-8" }
32 bool found_locale
= false;
33 for (size_t i
= 0; i
< arraysize(kLocales
); ++i
) {
34 if (kLocales
[i
].chrome_locale
== locale
) {
36 setenv("LC_ALL", kLocales
[i
].system_locale
, 1);
45 scoped_ptr
<base::Environment
> env(base::Environment::Create());
47 env
->SetVar("LC_ALL", old_locale_
);
49 env
->UnSetVar("LC_ALL");
54 const std::string
& locale() { return locale_
; }
59 const char* old_locale_
;
63 // A base class for tests used in this file. This class over-writes the system
64 // locale and run Chrome with a '--lang' option. To add a new LocaleTest, add a
65 // class derived from this class and call the constructor with the locale name
67 class LocaleTestBase
: public InProcessBrowserTest
{
69 explicit LocaleTestBase(const char* locale
) : locale_(locale
) {
72 void SetUpCommandLine(base::CommandLine
* command_line
) override
{
73 command_line
->AppendSwitchASCII(switches::kLang
, locale_
.locale());
80 // Test classes that run Chrome on the Danish locale, the Hebrew locale, and
81 // the Traditional-Chinese locale, respectively.
82 class LocaleTestDanish
: public LocaleTestBase
{
84 LocaleTestDanish() : LocaleTestBase("da") {
88 class LocaleTestHebrew
: public LocaleTestBase
{
90 LocaleTestHebrew() : LocaleTestBase("he") {
94 class LocaleTestTraditionalChinese
: public LocaleTestBase
{
96 LocaleTestTraditionalChinese() : LocaleTestBase("zh-TW") {
102 // Start Chrome and shut it down on the Danish locale, the Hebrew locale, and
103 // the Traditional-Chinese locale, respectively. These tests do not need any
104 // code here because they just verify we can start Chrome and shut it down
105 // cleanly on these locales.
106 IN_PROC_BROWSER_TEST_F(LocaleTestDanish
, TestStart
) {
109 IN_PROC_BROWSER_TEST_F(LocaleTestHebrew
, TestStart
) {
112 IN_PROC_BROWSER_TEST_F(LocaleTestTraditionalChinese
, TestStart
) {