diff options
author | tfarina@chromium.org <tfarina@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-12-17 14:50:50 +0000 |
---|---|---|
committer | tfarina@chromium.org <tfarina@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-12-17 14:50:50 +0000 |
commit | f84b5338dfaf39bfe3cf86fbf18d1b3f035dbbf7 (patch) | |
tree | 82b636343d4d9d611979a2f23b964f50c089b698 /components/test | |
parent | 4b4db8717cc71a0d04dadf76e57a6a2f341577a4 (diff) | |
download | chromium_src-f84b5338dfaf39bfe3cf86fbf18d1b3f035dbbf7.zip chromium_src-f84b5338dfaf39bfe3cf86fbf18d1b3f035dbbf7.tar.gz chromium_src-f84b5338dfaf39bfe3cf86fbf18d1b3f035dbbf7.tar.bz2 |
components: Refactor the initialization of ResourceBundle for unit tests.
ResourceBundle should not be initialized in a single test case in
dom_distiller. Instead it should be initialized once and for all test
cases. By initializing it early and in the main function it means we can
make it available for consumption for everyone who needs it.
This also clears the instance we created after the tests are done, which
we were not doing in dom_distiller.
It does not contain any functional changes yet, so android should not be
affected.
BUG=329030
TEST=components_unittests, no functional changes.
R=joi@chromium.org,tony@chromium.org,blundell@chromium.org
Review URL: https://codereview.chromium.org/99133024
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@241284 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'components/test')
-rw-r--r-- | components/test/DEPS | 4 | ||||
-rw-r--r-- | components/test/run_all_unittests.cc | 43 |
2 files changed, 42 insertions, 5 deletions
diff --git a/components/test/DEPS b/components/test/DEPS index c220939..f3e2ad7 100644 --- a/components/test/DEPS +++ b/components/test/DEPS @@ -1,4 +1,6 @@ include_rules = [ "+content/public/test", - "+ui/compositor", + "+ui/base/android/ui_base_jni_registrar.h", + "+ui/base/resource/resource_bundle.h", + "+ui/gfx/android/gfx_jni_registrar.h", ] diff --git a/components/test/run_all_unittests.cc b/components/test/run_all_unittests.cc index a509a82..b59285f 100644 --- a/components/test/run_all_unittests.cc +++ b/components/test/run_all_unittests.cc @@ -8,8 +8,43 @@ #include "base/test/test_suite.h" #include "content/public/test/test_content_client_initializer.h" #include "testing/gtest/include/gtest/gtest.h" +#include "ui/base/resource/resource_bundle.h" -namespace components { +#if defined(OS_ANDROID) +#include "base/android/jni_android.h" +#include "ui/base/android/ui_base_jni_registrar.h" +#include "ui/gfx/android/gfx_jni_registrar.h" +#endif + +namespace { + +class ComponentsTestSuite : public base::TestSuite { + public: + ComponentsTestSuite(int argc, char** argv) : base::TestSuite(argc, argv) {} + + private: + virtual void Initialize() OVERRIDE { + base::TestSuite::Initialize(); + +#if defined(OS_ANDROID) + // Register JNI bindings for android. + JNIEnv* env = base::android::AttachCurrentThread(); + gfx::android::RegisterJni(env); + ui::android::RegisterJni(env); +#endif + + // TODO(tfarina): This should be changed to InitSharedInstanceWithPakFile() + // so we can load our pak file instead of chrome.pak. + ui::ResourceBundle::InitSharedInstanceWithLocale("en-US", NULL); + } + + virtual void Shutdown() OVERRIDE { + ui::ResourceBundle::CleanupSharedInstance(); + base::TestSuite::Shutdown(); + } + + DISALLOW_COPY_AND_ASSIGN(ComponentsTestSuite); +}; class ComponentsUnitTestEventListener : public testing::EmptyTestEventListener { public: @@ -30,16 +65,16 @@ class ComponentsUnitTestEventListener : public testing::EmptyTestEventListener { DISALLOW_COPY_AND_ASSIGN(ComponentsUnitTestEventListener); }; -} // namespace components +} // namespace int main(int argc, char** argv) { - base::TestSuite test_suite(argc, argv); + ComponentsTestSuite test_suite(argc, argv); // The listener will set up common test environment for all components unit // tests. testing::TestEventListeners& listeners = testing::UnitTest::GetInstance()->listeners(); - listeners.Append(new components::ComponentsUnitTestEventListener()); + listeners.Append(new ComponentsUnitTestEventListener()); return base::LaunchUnitTests( argc, argv, base::Bind(&base::TestSuite::Run, |