OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "base/bind.h" | 5 #include "base/bind.h" |
6 #include "base/files/file_path.h" | |
6 #include "base/memory/scoped_ptr.h" | 7 #include "base/memory/scoped_ptr.h" |
7 #include "base/path_service.h" | 8 #include "base/path_service.h" |
8 #include "base/test/launcher/unit_test_launcher.h" | 9 #include "base/test/launcher/unit_test_launcher.h" |
9 #include "base/test/test_suite.h" | 10 #include "base/test/test_suite.h" |
10 #include "content/public/test/test_content_client_initializer.h" | 11 #include "content/public/test/test_content_client_initializer.h" |
11 #include "testing/gtest/include/gtest/gtest.h" | 12 #include "testing/gtest/include/gtest/gtest.h" |
12 #include "ui/base/resource/resource_bundle.h" | 13 #include "ui/base/resource/resource_bundle.h" |
13 #include "ui/base/ui_base_paths.h" | 14 #include "ui/base/ui_base_paths.h" |
14 | 15 |
15 #if defined(OS_MACOSX) | |
16 #include "base/mac/bundle_locations.h" | |
17 #endif | |
18 | |
19 #if !defined(OS_IOS) | 16 #if !defined(OS_IOS) |
20 #include "ui/gl/gl_surface.h" | 17 #include "ui/gl/gl_surface.h" |
21 #endif | 18 #endif |
22 | 19 |
23 #if defined(OS_ANDROID) | 20 #if defined(OS_ANDROID) |
24 #include "base/android/jni_android.h" | 21 #include "base/android/jni_android.h" |
25 #include "ui/base/android/ui_base_jni_registrar.h" | 22 #include "ui/base/android/ui_base_jni_registrar.h" |
26 #include "ui/gfx/android/gfx_jni_registrar.h" | 23 #include "ui/gfx/android/gfx_jni_registrar.h" |
27 #endif | 24 #endif |
28 | 25 |
29 namespace { | 26 namespace { |
30 | 27 |
31 class ComponentsTestSuite : public base::TestSuite { | 28 class ComponentsTestSuite : public base::TestSuite { |
32 public: | 29 public: |
33 ComponentsTestSuite(int argc, char** argv) : base::TestSuite(argc, argv) {} | 30 ComponentsTestSuite(int argc, char** argv) : base::TestSuite(argc, argv) {} |
34 | 31 |
35 private: | 32 private: |
36 virtual void Initialize() OVERRIDE { | 33 virtual void Initialize() OVERRIDE { |
37 base::TestSuite::Initialize(); | 34 base::TestSuite::Initialize(); |
38 #if !defined(OS_IOS) | 35 #if !defined(OS_IOS) |
39 gfx::GLSurface::InitializeOneOffForTests(); | 36 gfx::GLSurface::InitializeOneOffForTests(); |
40 #endif | 37 #endif |
41 #if defined(OS_ANDROID) | 38 #if defined(OS_ANDROID) |
42 // Register JNI bindings for android. | 39 // Register JNI bindings for android. |
43 JNIEnv* env = base::android::AttachCurrentThread(); | 40 JNIEnv* env = base::android::AttachCurrentThread(); |
44 gfx::android::RegisterJni(env); | 41 gfx::android::RegisterJni(env); |
45 ui::android::RegisterJni(env); | 42 ui::android::RegisterJni(env); |
46 #endif | 43 #endif |
47 | 44 |
48 #if defined(OS_MACOSX) && !defined(OS_IOS) | |
49 // Look in the framework bundle for resources. | |
50 base::FilePath path; | |
51 PathService::Get(base::DIR_EXE, &path); | |
52 | |
53 // TODO(tfarina): This is temporary. The right fix is to write a | |
54 // framework-Info.plist and integrate that into the build. | |
55 // Hardcode the framework name here to avoid having to depend on chrome's | |
56 // common target for chrome::kFrameworkName. | |
57 #if defined(GOOGLE_CHROME_BUILD) | |
58 path = path.AppendASCII("Google Chrome Framework.framework"); | |
59 #elif defined(CHROMIUM_BUILD) | |
60 path = path.AppendASCII("Chromium Framework.framework"); | |
61 #else | |
62 #error Unknown branding | |
63 #endif | |
64 | |
65 base::mac::SetOverrideFrameworkBundlePath(path); | |
66 #endif | |
67 | |
68 ui::RegisterPathProvider(); | 45 ui::RegisterPathProvider(); |
tfarina
2014/05/07 20:58:40
Yaron, there is no components_paths.cc:RegisterPat
| |
69 | 46 |
70 // TODO(tfarina): This should be changed to InitSharedInstanceWithPakFile() | |
71 // so we can load our pak file instead of chrome.pak. crbug.com/348563 | |
72 ui::ResourceBundle::InitSharedInstanceWithLocale("en-US", NULL); | |
73 base::FilePath resources_pack_path; | 47 base::FilePath resources_pack_path; |
74 PathService::Get(base::DIR_MODULE, &resources_pack_path); | 48 PathService::Get(base::DIR_MODULE, &resources_pack_path); |
75 ui::ResourceBundle::GetSharedInstance().AddDataPackFromPath( | 49 ui::ResourceBundle::InitSharedInstanceWithPakPath( |
76 resources_pack_path.AppendASCII("resources.pak"), | 50 resources_pack_path.AppendASCII("components_unittests_resources.pak")); |
77 ui::SCALE_FACTOR_NONE); | |
78 } | 51 } |
79 | 52 |
80 virtual void Shutdown() OVERRIDE { | 53 virtual void Shutdown() OVERRIDE { |
81 ui::ResourceBundle::CleanupSharedInstance(); | 54 ui::ResourceBundle::CleanupSharedInstance(); |
82 | 55 |
83 #if defined(OS_MACOSX) && !defined(OS_IOS) | |
84 base::mac::SetOverrideFrameworkBundle(NULL); | |
85 #endif | |
86 | |
87 base::TestSuite::Shutdown(); | 56 base::TestSuite::Shutdown(); |
88 } | 57 } |
89 | 58 |
90 DISALLOW_COPY_AND_ASSIGN(ComponentsTestSuite); | 59 DISALLOW_COPY_AND_ASSIGN(ComponentsTestSuite); |
91 }; | 60 }; |
92 | 61 |
93 class ComponentsUnitTestEventListener : public testing::EmptyTestEventListener { | 62 class ComponentsUnitTestEventListener : public testing::EmptyTestEventListener { |
94 public: | 63 public: |
95 ComponentsUnitTestEventListener() {} | 64 ComponentsUnitTestEventListener() {} |
96 virtual ~ComponentsUnitTestEventListener() {} | 65 virtual ~ComponentsUnitTestEventListener() {} |
(...skipping 20 matching lines...) Expand all Loading... | |
117 // The listener will set up common test environment for all components unit | 86 // The listener will set up common test environment for all components unit |
118 // tests. | 87 // tests. |
119 testing::TestEventListeners& listeners = | 88 testing::TestEventListeners& listeners = |
120 testing::UnitTest::GetInstance()->listeners(); | 89 testing::UnitTest::GetInstance()->listeners(); |
121 listeners.Append(new ComponentsUnitTestEventListener()); | 90 listeners.Append(new ComponentsUnitTestEventListener()); |
122 | 91 |
123 return base::LaunchUnitTests( | 92 return base::LaunchUnitTests( |
124 argc, argv, base::Bind(&base::TestSuite::Run, | 93 argc, argv, base::Bind(&base::TestSuite::Run, |
125 base::Unretained(&test_suite))); | 94 base::Unretained(&test_suite))); |
126 } | 95 } |
OLD | NEW |