| 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 <stdarg.h> | 5 #include <stdarg.h> |
| 6 #include <string.h> | 6 #include <string.h> |
| 7 | 7 |
| 8 #include "base/file_path.h" | 8 #include "base/file_path.h" |
| 9 #include "base/logging.h" | 9 #include "base/logging.h" |
| 10 #include "base/memory/singleton.h" | 10 #include "base/memory/singleton.h" |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 61 } | 61 } |
| 62 | 62 |
| 63 private: | 63 private: |
| 64 friend struct DefaultSingletonTraits<Waitable>; | 64 friend struct DefaultSingletonTraits<Waitable>; |
| 65 | 65 |
| 66 Waitable() | 66 Waitable() |
| 67 : waitable_event_(false, false) { | 67 : waitable_event_(false, false) { |
| 68 } | 68 } |
| 69 | 69 |
| 70 base::WaitableEvent waitable_event_; | 70 base::WaitableEvent waitable_event_; |
| 71 |
| 72 DISALLOW_COPY_AND_ASSIGN(Waitable); |
| 71 }; | 73 }; |
| 72 | 74 |
| 73 // The MessagePumpForUI implementation for test purpose. | 75 // The MessagePumpForUI implementation for test purpose. |
| 74 class MessagePumpForUIStub : public base::MessagePumpForUI { | 76 class MessagePumpForUIStub : public base::MessagePumpForUI { |
| 75 void Start(base::MessagePump::Delegate* delegate) { | 77 virtual void Start(base::MessagePump::Delegate* delegate) OVERRIDE { |
| 76 NOTREACHED() << "The Start() method shouldn't be called in test, using" | 78 NOTREACHED() << "The Start() method shouldn't be called in test, using" |
| 77 " Run() method should be used."; | 79 " Run() method should be used."; |
| 78 } | 80 } |
| 79 | 81 |
| 80 void Run(base::MessagePump::Delegate* delegate) { | 82 virtual void Run(base::MessagePump::Delegate* delegate) OVERRIDE { |
| 81 // The following was based on message_pump_glib.cc, except we're using a | 83 // The following was based on message_pump_glib.cc, except we're using a |
| 82 // WaitableEvent since there are no native message loop to use. | 84 // WaitableEvent since there are no native message loop to use. |
| 83 RunState state(delegate, g_state ? g_state->run_depth + 1 : 1); | 85 RunState state(delegate, g_state ? g_state->run_depth + 1 : 1); |
| 84 | 86 |
| 85 RunState* previous_state = g_state; | 87 RunState* previous_state = g_state; |
| 86 g_state = &state; | 88 g_state = &state; |
| 87 | 89 |
| 88 bool more_work_is_plausible = true; | 90 bool more_work_is_plausible = true; |
| 89 | 91 |
| 90 for (;;) { | 92 for (;;) { |
| (...skipping 19 matching lines...) Expand all Loading... |
| 110 more_work_is_plausible = g_state->delegate->DoIdleWork(); | 112 more_work_is_plausible = g_state->delegate->DoIdleWork(); |
| 111 if (g_state->should_quit) | 113 if (g_state->should_quit) |
| 112 break; | 114 break; |
| 113 | 115 |
| 114 more_work_is_plausible |= !delayed_work_time.is_null(); | 116 more_work_is_plausible |= !delayed_work_time.is_null(); |
| 115 } | 117 } |
| 116 | 118 |
| 117 g_state = previous_state; | 119 g_state = previous_state; |
| 118 } | 120 } |
| 119 | 121 |
| 120 void Quit() { | 122 virtual void Quit() OVERRIDE { |
| 121 Waitable::GetInstance()->Quit(); | 123 Waitable::GetInstance()->Quit(); |
| 122 } | 124 } |
| 123 | 125 |
| 124 void ScheduleWork() { | 126 virtual void ScheduleWork() OVERRIDE { |
| 125 Waitable::GetInstance()->Signal(); | 127 Waitable::GetInstance()->Signal(); |
| 126 } | 128 } |
| 127 | 129 |
| 128 void ScheduleDelayedWork(const base::TimeTicks& delayed_work_time) { | 130 virtual void ScheduleDelayedWork( |
| 131 const base::TimeTicks& delayed_work_time) OVERRIDE { |
| 129 Waitable::GetInstance()->Signal(); | 132 Waitable::GetInstance()->Signal(); |
| 130 } | 133 } |
| 131 }; | 134 }; |
| 132 | 135 |
| 136 base::MessagePump* CreateMessagePumpForUIStub() { |
| 137 return new MessagePumpForUIStub(); |
| 138 }; |
| 139 |
| 133 // Provides the test path for DIR_MODULE, DIR_CACHE and DIR_ANDROID_APP_DATA. | 140 // Provides the test path for DIR_MODULE, DIR_CACHE and DIR_ANDROID_APP_DATA. |
| 134 bool PathTestProviderAndroid(int key, FilePath* result) { | 141 bool GetTestProviderPath(int key, FilePath* result) { |
| 135 switch (key) { | 142 switch (key) { |
| 136 case base::DIR_MODULE: { | 143 case base::DIR_MODULE: { |
| 137 *result = FilePath(kAndroidTestTempDirectory); | 144 *result = FilePath(kAndroidTestTempDirectory); |
| 138 return true; | 145 return true; |
| 139 } | 146 } |
| 140 #if !defined(ANDROID_APK_TEST_TARGET) | 147 #if !defined(ANDROID_APK_TEST_TARGET) |
| 141 // When running as executable we need to use /data/local/tmp as the | 148 // When running as executable we need to use /data/local/tmp as the |
| 142 // cache directory. | 149 // cache directory. |
| 143 case base::DIR_CACHE: { | 150 case base::DIR_CACHE: { |
| 144 *result = FilePath(kAndroidTestTempDirectory); | 151 *result = FilePath(kAndroidTestTempDirectory); |
| 145 return true; | 152 return true; |
| 146 } | 153 } |
| 147 #endif // !defined(ANDROID_APK_TEST_TARGET) | 154 #endif // !defined(ANDROID_APK_TEST_TARGET) |
| 148 case base::DIR_ANDROID_APP_DATA: { | 155 case base::DIR_ANDROID_APP_DATA: { |
| 149 *result = FilePath(kAndroidTestTempDirectory); | 156 *result = FilePath(kAndroidTestTempDirectory); |
| 150 return true; | 157 return true; |
| 151 } | 158 } |
| 152 default: | 159 default: |
| 153 return false; | 160 return false; |
| 154 } | 161 } |
| 155 } | 162 } |
| 156 | 163 |
| 157 // The factory method to create a MessagePumpForUI. | 164 void InitPathProvider(int key) { |
| 158 base::MessagePump* CreateMessagePumpForUIStub() { | 165 FilePath path; |
| 159 return new MessagePumpForUIStub(); | 166 // If failed to override the key, that means the way has not been registered. |
| 167 if (GetTestProviderPath(key, &path) && !PathService::Override(key, path)) |
| 168 PathService::RegisterProvider(&GetTestProviderPath, key, key + 1); |
| 160 } | 169 } |
| 161 | 170 |
| 162 } // namespace | 171 } // namespace |
| 163 | 172 |
| 164 void InitAndroidOSPathStub() { | 173 void InitAndroidTestLogging() { |
| 165 PathService::Override(base::DIR_MODULE, FilePath(kAndroidTestTempDirectory)); | |
| 166 PathService::Override(base::DIR_CACHE, FilePath(kAndroidTestTempDirectory)); | |
| 167 PathService::Override(base::DIR_ANDROID_APP_DATA, | |
| 168 FilePath(kAndroidTestTempDirectory)); | |
| 169 } | |
| 170 | |
| 171 void InitAndroidTestStub() { | |
| 172 logging::InitLogging(NULL, | 174 logging::InitLogging(NULL, |
| 173 logging::LOG_ONLY_TO_SYSTEM_DEBUG_LOG, | 175 logging::LOG_ONLY_TO_SYSTEM_DEBUG_LOG, |
| 174 logging::DONT_LOCK_LOG_FILE, | 176 logging::DONT_LOCK_LOG_FILE, |
| 175 logging::DELETE_OLD_LOG_FILE, | 177 logging::DELETE_OLD_LOG_FILE, |
| 176 logging::ENABLE_DCHECK_FOR_NON_OFFICIAL_RELEASE_BUILDS); | 178 logging::ENABLE_DCHECK_FOR_NON_OFFICIAL_RELEASE_BUILDS); |
| 177 // To view log output with IDs and timestamps use "adb logcat -v threadtime". | 179 // To view log output with IDs and timestamps use "adb logcat -v threadtime". |
| 178 logging::SetLogItems(false, // Process ID | 180 logging::SetLogItems(false, // Process ID |
| 179 false, // Thread ID | 181 false, // Thread ID |
| 180 false, // Timestamp | 182 false, // Timestamp |
| 181 false); // Tick count | 183 false); // Tick count |
| 184 } |
| 182 | 185 |
| 183 PathService::RegisterProvider(&PathTestProviderAndroid, base::DIR_MODULE, | 186 void InitAndroidTestPaths() { |
| 184 base::DIR_MODULE + 1); | 187 InitPathProvider(base::DIR_MODULE); |
| 185 PathService::RegisterProvider(&PathTestProviderAndroid, base::DIR_CACHE, | 188 InitPathProvider(base::DIR_CACHE); |
| 186 base::DIR_CACHE + 1); | 189 InitPathProvider(base::DIR_ANDROID_APP_DATA); |
| 187 PathService::RegisterProvider(&PathTestProviderAndroid, | 190 } |
| 188 base::DIR_ANDROID_APP_DATA, base::DIR_ANDROID_APP_DATA + 1); | |
| 189 | 191 |
| 192 void InitAndroidTestMessageLoop() { |
| 190 MessageLoop::InitMessagePumpForUIFactory(&CreateMessagePumpForUIStub); | 193 MessageLoop::InitMessagePumpForUIFactory(&CreateMessagePumpForUIStub); |
| 191 } | 194 } |
| 195 |
| 196 void InitAndroidTest() { |
| 197 InitAndroidTestLogging(); |
| 198 InitAndroidTestPaths(); |
| 199 InitAndroidTestMessageLoop(); |
| 200 } |
| OLD | NEW |