diff options
author | hbono@chromium.org <hbono@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-04-10 02:44:08 +0000 |
---|---|---|
committer | hbono@chromium.org <hbono@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-04-10 02:44:08 +0000 |
commit | 5e6a84e9c1e444bb8ecf6ec75d9f4917cfad59c0 (patch) | |
tree | 91a848f71a10dc34c29596174021f30da750dceb /chrome/browser/locale_tests_browsertest.cc | |
parent | 7686c4fed3904d8b5ffc78b91d6b2170b45b829c (diff) | |
download | chromium_src-5e6a84e9c1e444bb8ecf6ec75d9f4917cfad59c0.zip chromium_src-5e6a84e9c1e444bb8ecf6ec75d9f4917cfad59c0.tar.gz chromium_src-5e6a84e9c1e444bb8ecf6ec75d9f4917cfad59c0.tar.bz2 |
Convert LocaleTests* from ui_tests to browser_tests.
For better readability, this change also adds a local class that over-writes the system locale only in a scope and renames test names.
BUG=121574
TEST=LocaleTestsDanish,LocaleTestsHebrew,LocaleTestsTraditionalChinese
Review URL: http://codereview.chromium.org/10020016
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@131523 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/locale_tests_browsertest.cc')
-rw-r--r-- | chrome/browser/locale_tests_browsertest.cc | 111 |
1 files changed, 111 insertions, 0 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) { +} |