BookmarkManager: Fix 'new folder text field size changes on clicking it' issue.
[chromium-blink-merge.git] / chrome / browser / locale_tests_browsertest.cc
blob6c57279e081a23288c390397a17805537489220c
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"
11 namespace {
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.)
18 class ScopedLocale {
19 public:
20 explicit ScopedLocale(const char* locale) : locale_(locale) {
21 #if defined(OS_LINUX)
22 old_locale_ = getenv("LC_ALL");
24 static const struct {
25 const char* chrome_locale;
26 const char* system_locale;
27 } kLocales[] = {
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) {
35 found_locale = true;
36 setenv("LC_ALL", kLocales[i].system_locale, 1);
39 DCHECK(found_locale);
40 #endif
43 ~ScopedLocale() {
44 #if defined(OS_LINUX)
45 scoped_ptr<base::Environment> env(base::Environment::Create());
46 if (old_locale_) {
47 env->SetVar("LC_ALL", old_locale_);
48 } else {
49 env->UnSetVar("LC_ALL");
51 #endif
54 const std::string& locale() { return locale_; }
56 private:
57 std::string locale_;
58 #if defined(OS_LINUX)
59 const char* old_locale_;
60 #endif
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
66 // used by Chrome.
67 class LocaleTestBase : public InProcessBrowserTest {
68 public:
69 explicit LocaleTestBase(const char* locale) : locale_(locale) {
72 void SetUpCommandLine(base::CommandLine* command_line) override {
73 command_line->AppendSwitchASCII(switches::kLang, locale_.locale());
76 protected:
77 ScopedLocale 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 {
83 public:
84 LocaleTestDanish() : LocaleTestBase("da") {
88 class LocaleTestHebrew : public LocaleTestBase {
89 public:
90 LocaleTestHebrew() : LocaleTestBase("he") {
94 class LocaleTestTraditionalChinese : public LocaleTestBase {
95 public:
96 LocaleTestTraditionalChinese() : LocaleTestBase("zh-TW") {
100 } // namespace
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) {