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 | |
15 #if defined(OS_MACOSX) | |
16 #include "base/mac/bundle_locations.h" | |
17 #endif | |
18 | 14 |
19 #if !defined(OS_IOS) | 15 #if !defined(OS_IOS) |
20 #include "ui/gl/gl_surface.h" | 16 #include "ui/gl/gl_surface.h" |
21 #endif | 17 #endif |
22 | 18 |
23 #if defined(OS_ANDROID) | 19 #if defined(OS_ANDROID) |
24 #include "base/android/jni_android.h" | 20 #include "base/android/jni_android.h" |
25 #include "ui/base/android/ui_base_jni_registrar.h" | 21 #include "ui/base/android/ui_base_jni_registrar.h" |
26 #include "ui/gfx/android/gfx_jni_registrar.h" | 22 #include "ui/gfx/android/gfx_jni_registrar.h" |
27 #endif | 23 #endif |
(...skipping 10 matching lines...) Expand all Loading... | |
38 #if !defined(OS_IOS) | 34 #if !defined(OS_IOS) |
39 gfx::GLSurface::InitializeOneOffForTests(); | 35 gfx::GLSurface::InitializeOneOffForTests(); |
40 #endif | 36 #endif |
41 #if defined(OS_ANDROID) | 37 #if defined(OS_ANDROID) |
42 // Register JNI bindings for android. | 38 // Register JNI bindings for android. |
43 JNIEnv* env = base::android::AttachCurrentThread(); | 39 JNIEnv* env = base::android::AttachCurrentThread(); |
44 gfx::android::RegisterJni(env); | 40 gfx::android::RegisterJni(env); |
45 ui::android::RegisterJni(env); | 41 ui::android::RegisterJni(env); |
46 #endif | 42 #endif |
47 | 43 |
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(); | |
69 | |
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; | 44 base::FilePath resources_pack_path; |
74 PathService::Get(base::DIR_MODULE, &resources_pack_path); | 45 PathService::Get(base::DIR_MODULE, &resources_pack_path); |
75 ui::ResourceBundle::GetSharedInstance().AddDataPackFromPath( | 46 ui::ResourceBundle::InitSharedInstanceWithPakPath( |
76 resources_pack_path.AppendASCII("resources.pak"), | 47 resources_pack_path.AppendASCII("components_unittests_resources.pak")); |
Yaron
2014/05/06 17:50:58
There's an example of doing a similar pattern in c
tfarina
2014/05/06 18:03:09
Are you sure that above example works without the
| |
77 ui::SCALE_FACTOR_NONE); | |
78 } | 48 } |
79 | 49 |
80 virtual void Shutdown() OVERRIDE { | 50 virtual void Shutdown() OVERRIDE { |
81 ui::ResourceBundle::CleanupSharedInstance(); | 51 ui::ResourceBundle::CleanupSharedInstance(); |
82 | 52 |
83 #if defined(OS_MACOSX) && !defined(OS_IOS) | |
84 base::mac::SetOverrideFrameworkBundle(NULL); | |
85 #endif | |
86 | |
87 base::TestSuite::Shutdown(); | 53 base::TestSuite::Shutdown(); |
88 } | 54 } |
89 | 55 |
90 DISALLOW_COPY_AND_ASSIGN(ComponentsTestSuite); | 56 DISALLOW_COPY_AND_ASSIGN(ComponentsTestSuite); |
91 }; | 57 }; |
92 | 58 |
93 class ComponentsUnitTestEventListener : public testing::EmptyTestEventListener { | 59 class ComponentsUnitTestEventListener : public testing::EmptyTestEventListener { |
94 public: | 60 public: |
95 ComponentsUnitTestEventListener() {} | 61 ComponentsUnitTestEventListener() {} |
96 virtual ~ComponentsUnitTestEventListener() {} | 62 virtual ~ComponentsUnitTestEventListener() {} |
(...skipping 20 matching lines...) Expand all Loading... | |
117 // The listener will set up common test environment for all components unit | 83 // The listener will set up common test environment for all components unit |
118 // tests. | 84 // tests. |
119 testing::TestEventListeners& listeners = | 85 testing::TestEventListeners& listeners = |
120 testing::UnitTest::GetInstance()->listeners(); | 86 testing::UnitTest::GetInstance()->listeners(); |
121 listeners.Append(new ComponentsUnitTestEventListener()); | 87 listeners.Append(new ComponentsUnitTestEventListener()); |
122 | 88 |
123 return base::LaunchUnitTests( | 89 return base::LaunchUnitTests( |
124 argc, argv, base::Bind(&base::TestSuite::Run, | 90 argc, argv, base::Bind(&base::TestSuite::Run, |
125 base::Unretained(&test_suite))); | 91 base::Unretained(&test_suite))); |
126 } | 92 } |
OLD | NEW |