summaryrefslogtreecommitdiffstats
path: root/components
diff options
context:
space:
mode:
authortfarina@chromium.org <tfarina@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-12-17 14:50:50 +0000
committertfarina@chromium.org <tfarina@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-12-17 14:50:50 +0000
commitf84b5338dfaf39bfe3cf86fbf18d1b3f035dbbf7 (patch)
tree82b636343d4d9d611979a2f23b964f50c089b698 /components
parent4b4db8717cc71a0d04dadf76e57a6a2f341577a4 (diff)
downloadchromium_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')
-rw-r--r--components/components_tests.gyp2
-rw-r--r--components/dom_distiller/DEPS2
-rw-r--r--components/dom_distiller/core/distiller_unittest.cc15
-rw-r--r--components/test/DEPS4
-rw-r--r--components/test/run_all_unittests.cc43
5 files changed, 44 insertions, 22 deletions
diff --git a/components/components_tests.gyp b/components/components_tests.gyp
index acc9526..ec5b356 100644
--- a/components/components_tests.gyp
+++ b/components/components_tests.gyp
@@ -79,6 +79,8 @@
'../sync/sync.gyp:sync',
'../testing/gmock.gyp:gmock',
'../testing/gtest.gyp:gtest',
+ '../ui/gfx/gfx.gyp:gfx',
+ '../ui/ui.gyp:ui',
# Dependencies of auto_login_parser
'components.gyp:auto_login_parser',
diff --git a/components/dom_distiller/DEPS b/components/dom_distiller/DEPS
index 1c12a78..07b7999 100644
--- a/components/dom_distiller/DEPS
+++ b/components/dom_distiller/DEPS
@@ -5,9 +5,7 @@ include_rules = [
"+third_party/leveldatabase/src/include",
"+net/http",
"+net/url_request",
- "+ui/base/android",
"+ui/base/resource",
- "+ui/gfx/android",
# The dom distiller is a layered component; subdirectories must explicitly
# introduce the ability to use the content layer as appropriate.
diff --git a/components/dom_distiller/core/distiller_unittest.cc b/components/dom_distiller/core/distiller_unittest.cc
index 248340b..3784fd5 100644
--- a/components/dom_distiller/core/distiller_unittest.cc
+++ b/components/dom_distiller/core/distiller_unittest.cc
@@ -16,13 +16,6 @@
#include "net/url_request/url_request_context_getter.h"
#include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h"
-#include "ui/base/resource/resource_bundle.h"
-
-#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
using::testing::Invoke;
using::testing::Return;
@@ -131,14 +124,6 @@ ACTION_P2(CreateMockDistillerPage, list, kurl) {
}
TEST_F(DistillerTest, DistillPage) {
-#if defined(OS_ANDROID)
- // Register JNI bindings for android.
- JNIEnv* env = base::android::AttachCurrentThread();
- gfx::android::RegisterJni(env);
- ui::android::RegisterJni(env);
-#endif
-
- ui::ResourceBundle::InitSharedInstanceWithLocale("en-US", NULL);
base::MessageLoop loop(base::MessageLoop::TYPE_UI);
scoped_ptr<base::ListValue> list(new base::ListValue());
list->AppendString(kTitle);
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,