diff options
-rw-r--r-- | chrome/browser/locale_tests_browsertest.cc | 111 | ||||
-rw-r--r-- | chrome/browser/locale_tests_uitest.cc | 85 | ||||
-rw-r--r-- | chrome/chrome_tests.gypi | 2 |
3 files changed, 112 insertions, 86 deletions
diff --git a/chrome/browser/locale_tests_browsertest.cc b/chrome/browser/locale_tests_browsertest.cc new file mode 100644 index 0000000..1b3b287 --- /dev/null +++ b/chrome/browser/locale_tests_browsertest.cc @@ -0,0 +1,111 @@ +// Copyright (c) 2012 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. + +#include "base/command_line.h" +#include "base/environment.h" +#include "build/build_config.h" +#include "chrome/test/base/in_process_browser_test.h" +#include "ui/base/ui_base_switches.h" + +namespace { + +// A class that over-writes the system locale only in a scope. To emulate the +// specified environment on Linux, this class over-writes a LC_ALL environment +// variable when creating a LocaleTest object and restore it with the original +// value when deleting the object. (This environment variable may affect other +// tests and we have to restore it regardless of the results of LocaleTests.) +class ScopedLocale { + public: + explicit ScopedLocale(const char* locale) : locale_(locale) { +#if defined(OS_LINUX) + old_locale_ = getenv("LC_ALL"); + + static const struct { + const char* chrome_locale; + const char* system_locale; + } kLocales[] = { + { "da", "da_DK.UTF-8" }, + { "he", "he_IL.UTF-8" }, + { "zh-TW", "zh-TW.UTF-8" } + }; + bool found_locale = false; + for (size_t i = 0; i < ARRAYSIZE_UNSAFE(kLocales); ++i) { + if (kLocales[i].chrome_locale == locale) { + found_locale = true; + setenv("LC_ALL", kLocales[i].system_locale, 1); + } + } + DCHECK(found_locale); +#endif + } + + ~ScopedLocale() { +#if defined(OS_LINUX) + scoped_ptr<base::Environment> env(base::Environment::Create()); + if (old_locale_) { + env->SetVar("LC_ALL", old_locale_); + } else { + env->UnSetVar("LC_ALL"); + } +#endif + } + + const std::string& locale() { return locale_; } + + private: + std::string locale_; + const char* old_locale_; +}; + +// A base class for tests used in this file. This class over-writes the system +// locale and run Chrome with a '--lang' option. To add a new LocaleTest, add a +// class derived from this class and call the constructor with the locale name +// used by Chrome. +class LocaleTestBase : public InProcessBrowserTest { + public: + explicit LocaleTestBase(const char* locale) : locale_(locale) { + } + + virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE { + command_line->AppendSwitchASCII(switches::kLang, locale_.locale()); + } + + protected: + ScopedLocale locale_; +}; + +// Test classes that run Chrome on the Danish locale, the Hebrew locale, and +// the Traditional-Chinese locale, respectively. +class LocaleTestDanish : public LocaleTestBase { + public: + LocaleTestDanish() : LocaleTestBase("da") { + } +}; + +class LocaleTestHebrew : public LocaleTestBase { + public: + LocaleTestHebrew() : LocaleTestBase("he") { + } +}; + +class LocaleTestTraditionalChinese : public LocaleTestBase { + public: + LocaleTestTraditionalChinese() : LocaleTestBase("zh-TW") { + } +}; + +} // namespace + +// Start Chrome and shut it down on the Danish locale, the Hebrew locale, and +// the Traditional-Chinese locale, respectively. These tests do not need any +// code here because they just verify we can start Chrome and shut it down +// cleanly on these locales. +IN_PROC_BROWSER_TEST_F(LocaleTestDanish, TestStart) { +} + +IN_PROC_BROWSER_TEST_F(LocaleTestHebrew, TestStart) { +} + +IN_PROC_BROWSER_TEST_F(LocaleTestTraditionalChinese, TestStart) { +} diff --git a/chrome/browser/locale_tests_uitest.cc b/chrome/browser/locale_tests_uitest.cc deleted file mode 100644 index fe86134..0000000 --- a/chrome/browser/locale_tests_uitest.cc +++ /dev/null @@ -1,85 +0,0 @@ -// Copyright (c) 2012 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. - -#include "chrome/test/ui/ui_test.h" - -#include "base/environment.h" -#include "build/build_config.h" -#include "ui/base/ui_base_switches.h" - -class LocaleTestsBase : public UITest { - public: - LocaleTestsBase() : UITest(), old_lc_all_(NULL) { - } - - virtual void TearDown() { -#if defined(OS_LINUX) - scoped_ptr<base::Environment> env(base::Environment::Create()); - if (old_lc_all_) { - env->SetVar("LC_ALL", old_lc_all_); - } else { - env->UnSetVar("LC_ALL"); - } -#endif - UITest::TearDown(); - } - - protected: - const char* old_lc_all_; -}; - - -class LocaleTestsDa : public LocaleTestsBase { - public: - LocaleTestsDa() : LocaleTestsBase() { - launch_arguments_.AppendSwitchASCII(switches::kLang, "da"); - - // Linux doesn't use --lang, it only uses environment variables to set the - // language. -#if defined(OS_LINUX) - old_lc_all_ = getenv("LC_ALL"); - setenv("LC_ALL", "da_DK.UTF-8", 1); -#endif - } -}; - -class LocaleTestsHe : public LocaleTestsBase { - public: - LocaleTestsHe() : LocaleTestsBase() { - launch_arguments_.AppendSwitchASCII(switches::kLang, "he"); -#if defined(OS_LINUX) - old_lc_all_ = getenv("LC_ALL"); - setenv("LC_ALL", "he_IL.UTF-8", 1); -#endif - } -}; - -class LocaleTestsZhTw : public LocaleTestsBase { - public: - LocaleTestsZhTw() : LocaleTestsBase() { - launch_arguments_.AppendSwitchASCII(switches::kLang, "zh-TW"); -#if defined(OS_LINUX) - old_lc_all_ = getenv("LC_ALL"); - setenv("LC_ALL", "zh_TW.UTF-8", 1); -#endif - } -}; - -#if defined(OS_CHROMEOS) -// See http://crbug.com/122366 -#define MAYBE_TestStart FAILS_TestStart -#else -#define MAYBE_TestStart TestStart -#endif -TEST_F(LocaleTestsDa, MAYBE_TestStart) { - // Just making sure we can start/shutdown cleanly. -} - -TEST_F(LocaleTestsHe, TestStart) { - // Just making sure we can start/shutdown cleanly. -} - -TEST_F(LocaleTestsZhTw, TestStart) { - // Just making sure we can start/shutdown cleanly. -} diff --git a/chrome/chrome_tests.gypi b/chrome/chrome_tests.gypi index 9a0957e..c66de333 100644 --- a/chrome/chrome_tests.gypi +++ b/chrome/chrome_tests.gypi @@ -757,7 +757,6 @@ # NOTE: DON'T ADD NEW TESTS HERE! # New tests should be browser_tests. browser_tests are sharded and are # less flakier. - 'browser/locale_tests_uitest.cc', 'browser/process_singleton_linux_uitest.cc', 'browser/process_singleton_uitest.cc', 'browser/sanity_uitest.cc', @@ -2848,6 +2847,7 @@ 'browser/iframe_browsertest.cc', 'browser/infobars/infobar_extension_apitest.cc', 'browser/importer/toolbar_importer_utils_browsertest.cc', + 'browser/locale_tests_browsertest.cc', 'browser/metrics/metrics_service_browsertest.cc', 'browser/net/cookie_policy_browsertest.cc', 'browser/net/ftp_browsertest.cc', |