Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(327)

Side by Side Diff: base/test/test_support_android.cc

Issue 2043803003: 👔 Reland #2: Move side-loaded test data /sdcard -> /sdcard/gtestdata (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebase atop https://codereview.chromium.org/2041723006 Created 4 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 <stdarg.h> 5 #include <stdarg.h>
6 #include <string.h> 6 #include <string.h>
7 7
8 #include "base/android/path_utils.h" 8 #include "base/android/path_utils.h"
9 #include "base/files/file_path.h" 9 #include "base/files/file_path.h"
10 #include "base/logging.h" 10 #include "base/logging.h"
11 #include "base/macros.h" 11 #include "base/macros.h"
12 #include "base/memory/singleton.h" 12 #include "base/memory/singleton.h"
13 #include "base/message_loop/message_loop.h" 13 #include "base/message_loop/message_loop.h"
14 #include "base/message_loop/message_pump_android.h" 14 #include "base/message_loop/message_pump_android.h"
15 #include "base/path_service.h" 15 #include "base/path_service.h"
16 #include "base/synchronization/waitable_event.h" 16 #include "base/synchronization/waitable_event.h"
17 #include "base/test/multiprocess_test.h" 17 #include "base/test/multiprocess_test.h"
18 18
19 namespace { 19 namespace {
20 20
21 base::FilePath* g_test_data_dir = nullptr;
22
21 struct RunState { 23 struct RunState {
22 RunState(base::MessagePump::Delegate* delegate, int run_depth) 24 RunState(base::MessagePump::Delegate* delegate, int run_depth)
23 : delegate(delegate), 25 : delegate(delegate),
24 run_depth(run_depth), 26 run_depth(run_depth),
25 should_quit(false) { 27 should_quit(false) {
26 } 28 }
27 29
28 base::MessagePump::Delegate* delegate; 30 base::MessagePump::Delegate* delegate;
29 31
30 // Used to count how many Run() invocations are on the stack. 32 // Used to count how many Run() invocations are on the stack.
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after
125 127
126 void ScheduleDelayedWork(const base::TimeTicks& delayed_work_time) override { 128 void ScheduleDelayedWork(const base::TimeTicks& delayed_work_time) override {
127 Waitable::GetInstance()->Signal(); 129 Waitable::GetInstance()->Signal();
128 } 130 }
129 }; 131 };
130 132
131 std::unique_ptr<base::MessagePump> CreateMessagePumpForUIStub() { 133 std::unique_ptr<base::MessagePump> CreateMessagePumpForUIStub() {
132 return std::unique_ptr<base::MessagePump>(new MessagePumpForUIStub()); 134 return std::unique_ptr<base::MessagePump>(new MessagePumpForUIStub());
133 }; 135 };
134 136
135 // Provides the test path for DIR_MODULE and DIR_ANDROID_APP_DATA. 137 // Provides the test path for DIR_SOURCE_ROOT and DIR_ANDROID_APP_DATA.
136 bool GetTestProviderPath(int key, base::FilePath* result) { 138 bool GetTestProviderPath(int key, base::FilePath* result) {
137 switch (key) { 139 switch (key) {
138 case base::DIR_ANDROID_APP_DATA: { 140 // TODO(agrieve): Stop overriding DIR_ANDROID_APP_DATA.
139 // For tests, app data is put in external storage. 141 // https://crbug.com/617734
140 return base::android::GetExternalStorageDirectory(result); 142 case base::DIR_ANDROID_APP_DATA:
jbudorick 2016/06/07 14:31:01 Hm, the salient bit of code here is https://codese
agrieve 2016/06/07 14:46:24 Responded to this comment here: https://bugs.chrom
jbudorick 2016/06/07 15:05:48 Replied there too. Not sure either will work.
141 } 143 case base::DIR_SOURCE_ROOT:
144 CHECK(g_test_data_dir != nullptr);
145 *result = *g_test_data_dir;
146 return true;
142 default: 147 default:
143 return false; 148 return false;
144 } 149 }
145 } 150 }
146 151
147 void InitPathProvider(int key) { 152 void InitPathProvider(int key) {
148 base::FilePath path; 153 base::FilePath path;
149 // If failed to override the key, that means the way has not been registered. 154 // If failed to override the key, that means the way has not been registered.
150 if (GetTestProviderPath(key, &path) && !PathService::Override(key, path)) 155 if (GetTestProviderPath(key, &path) && !PathService::Override(key, path))
151 PathService::RegisterProvider(&GetTestProviderPath, key, key + 1); 156 PathService::RegisterProvider(&GetTestProviderPath, key, key + 1);
152 } 157 }
153 158
154 } // namespace 159 } // namespace
155 160
156 namespace base { 161 namespace base {
157 162
158 void InitAndroidTestLogging() { 163 void InitAndroidTestLogging() {
159 logging::LoggingSettings settings; 164 logging::LoggingSettings settings;
160 settings.logging_dest = logging::LOG_TO_SYSTEM_DEBUG_LOG; 165 settings.logging_dest = logging::LOG_TO_SYSTEM_DEBUG_LOG;
161 logging::InitLogging(settings); 166 logging::InitLogging(settings);
162 // To view log output with IDs and timestamps use "adb logcat -v threadtime". 167 // To view log output with IDs and timestamps use "adb logcat -v threadtime".
163 logging::SetLogItems(false, // Process ID 168 logging::SetLogItems(false, // Process ID
164 false, // Thread ID 169 false, // Thread ID
165 false, // Timestamp 170 false, // Timestamp
166 false); // Tick count 171 false); // Tick count
167 } 172 }
168 173
169 void InitAndroidTestPaths() { 174 void InitAndroidTestPaths(const FilePath& test_data_dir) {
170 InitPathProvider(DIR_MODULE); 175 if (g_test_data_dir) {
176 CHECK(test_data_dir == *g_test_data_dir);
177 return;
178 }
179 g_test_data_dir = new FilePath(test_data_dir);
180 InitPathProvider(DIR_SOURCE_ROOT);
171 InitPathProvider(DIR_ANDROID_APP_DATA); 181 InitPathProvider(DIR_ANDROID_APP_DATA);
172 } 182 }
173 183
174 void InitAndroidTestMessageLoop() { 184 void InitAndroidTestMessageLoop() {
175 if (!MessageLoop::InitMessagePumpForUIFactory(&CreateMessagePumpForUIStub)) 185 if (!MessageLoop::InitMessagePumpForUIFactory(&CreateMessagePumpForUIStub))
176 LOG(INFO) << "MessagePumpForUIFactory already set, unable to override."; 186 LOG(INFO) << "MessagePumpForUIFactory already set, unable to override.";
177 } 187 }
178 188
179 void InitAndroidTest() { 189 void InitAndroidTest() {
180 if (!base::AndroidIsChildProcess()) { 190 if (!base::AndroidIsChildProcess()) {
181 InitAndroidTestLogging(); 191 InitAndroidTestLogging();
182 InitAndroidTestPaths();
183 } 192 }
184 InitAndroidTestMessageLoop(); 193 InitAndroidTestMessageLoop();
185 } 194 }
186 } // namespace base 195 } // namespace base
OLDNEW
« no previous file with comments | « base/test/test_support_android.h ('k') | build/android/pylib/local/device/local_device_gtest_run.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698