| 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 #ifndef CHROME_FRAME_TEST_CHROME_FRAME_TEST_UTILS_H_ | 5 #ifndef CHROME_FRAME_TEST_CHROME_FRAME_TEST_UTILS_H_ |
| 6 #define CHROME_FRAME_TEST_CHROME_FRAME_TEST_UTILS_H_ | 6 #define CHROME_FRAME_TEST_CHROME_FRAME_TEST_UTILS_H_ |
| 7 | 7 |
| 8 #include <windows.h> | 8 #include <windows.h> |
| 9 | 9 |
| 10 #include <atlbase.h> | 10 #include <atlbase.h> |
| 11 #include <atlwin.h> | 11 #include <atlwin.h> |
| 12 | 12 |
| 13 #include <string> | 13 #include <string> |
| 14 | 14 |
| 15 #include "base/basictypes.h" | 15 #include "base/basictypes.h" |
| 16 #include "base/cancelable_callback.h" |
| 16 #include "base/compiler_specific.h" | 17 #include "base/compiler_specific.h" |
| 17 #include "base/memory/scoped_ptr.h" | 18 #include "base/memory/scoped_ptr.h" |
| 18 #include "base/message_loop.h" | 19 #include "base/message_loop.h" |
| 19 #include "base/process_util.h" | 20 #include "base/process_util.h" |
| 20 #include "base/test/test_reg_util_win.h" | 21 #include "base/test/test_reg_util_win.h" |
| 21 #include "base/win/registry.h" | 22 #include "base/win/registry.h" |
| 22 #include "base/win/scoped_comptr.h" | 23 #include "base/win/scoped_comptr.h" |
| 23 #include "chrome_frame/chrome_tab.h" | 24 #include "chrome_frame/chrome_tab.h" |
| 24 #include "chrome_frame/test/simulate_input.h" | 25 #include "chrome_frame/test/simulate_input.h" |
| 25 #include "chrome_frame/test_utils.h" | 26 #include "chrome_frame/test_utils.h" |
| (...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 188 // We need a UI message loop in the main thread. | 189 // We need a UI message loop in the main thread. |
| 189 class TimedMsgLoop { | 190 class TimedMsgLoop { |
| 190 public: | 191 public: |
| 191 TimedMsgLoop() : quit_loop_invoked_(false) { | 192 TimedMsgLoop() : quit_loop_invoked_(false) { |
| 192 } | 193 } |
| 193 | 194 |
| 194 void RunFor(int seconds) { | 195 void RunFor(int seconds) { |
| 195 QuitAfter(seconds); | 196 QuitAfter(seconds); |
| 196 quit_loop_invoked_ = false; | 197 quit_loop_invoked_ = false; |
| 197 loop_.MessageLoop::Run(); | 198 loop_.MessageLoop::Run(); |
| 199 quit_closure_.Cancel(); |
| 198 } | 200 } |
| 199 | 201 |
| 200 void PostTask(const tracked_objects::Location& from_here, | 202 void PostTask(const tracked_objects::Location& from_here, |
| 201 const base::Closure& task) { | 203 const base::Closure& task) { |
| 202 loop_.PostTask(from_here, task); | 204 loop_.PostTask(from_here, task); |
| 203 } | 205 } |
| 204 | 206 |
| 205 void PostDelayedTask(const tracked_objects::Location& from_here, | 207 void PostDelayedTask(const tracked_objects::Location& from_here, |
| 206 const base::Closure& task, int64 delay_ms) { | 208 const base::Closure& task, int64 delay_ms) { |
| 207 loop_.PostDelayedTask(from_here, task, delay_ms); | 209 loop_.PostDelayedTask(from_here, task, delay_ms); |
| 208 } | 210 } |
| 209 | 211 |
| 210 void Quit() { | 212 void Quit() { |
| 211 QuitAfter(0); | 213 QuitAfter(0); |
| 212 } | 214 } |
| 213 | 215 |
| 214 void QuitAfter(int seconds) { | 216 void QuitAfter(int seconds) { |
| 217 quit_closure_.Reset(MessageLoop::QuitClosure()); |
| 215 quit_loop_invoked_ = true; | 218 quit_loop_invoked_ = true; |
| 216 loop_.PostDelayedTask( | 219 loop_.PostDelayedTask( |
| 217 FROM_HERE, MessageLoop::QuitClosure(), 1000 * seconds); | 220 FROM_HERE, quit_closure_.callback(), 1000 * seconds); |
| 218 } | 221 } |
| 219 | 222 |
| 220 bool WasTimedOut() const { | 223 bool WasTimedOut() const { |
| 221 return !quit_loop_invoked_; | 224 return !quit_loop_invoked_; |
| 222 } | 225 } |
| 223 | 226 |
| 227 void RunAllPending() { |
| 228 loop_.RunAllPending(); |
| 229 } |
| 230 |
| 224 private: | 231 private: |
| 225 MessageLoopForUI loop_; | 232 MessageLoopForUI loop_; |
| 233 base::CancelableClosure quit_closure_; |
| 226 bool quit_loop_invoked_; | 234 bool quit_loop_invoked_; |
| 227 }; | 235 }; |
| 228 | 236 |
| 229 // Saves typing. It's somewhat hard to create a wrapper around | 237 // Saves typing. It's somewhat hard to create a wrapper around |
| 230 // testing::InvokeWithoutArgs since it returns a | 238 // testing::InvokeWithoutArgs since it returns a |
| 231 // non-public (testing::internal) type. | 239 // non-public (testing::internal) type. |
| 232 #define QUIT_LOOP(loop) testing::InvokeWithoutArgs(\ | 240 #define QUIT_LOOP(loop) testing::InvokeWithoutArgs(\ |
| 233 testing::CreateFunctor(&loop, &chrome_frame_test::TimedMsgLoop::Quit)) | 241 testing::CreateFunctor(&loop, &chrome_frame_test::TimedMsgLoop::Quit)) |
| 234 | 242 |
| 235 #define QUIT_LOOP_SOON(loop, seconds) testing::InvokeWithoutArgs(\ | 243 #define QUIT_LOOP_SOON(loop, seconds) testing::InvokeWithoutArgs(\ |
| (...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 331 } // namespace chrome_frame_test | 339 } // namespace chrome_frame_test |
| 332 | 340 |
| 333 // TODO(tommi): This is a temporary workaround while we're getting our | 341 // TODO(tommi): This is a temporary workaround while we're getting our |
| 334 // Singleton story straight. Ideally each test should clear up any singletons | 342 // Singleton story straight. Ideally each test should clear up any singletons |
| 335 // it might have created, but test cases do not implicitly have their own | 343 // it might have created, but test cases do not implicitly have their own |
| 336 // AtExitManager, so we have this workaround method for tests that depend on | 344 // AtExitManager, so we have this workaround method for tests that depend on |
| 337 // "fresh" singletons. The implementation is in chrome_frame_unittest_main.cc. | 345 // "fresh" singletons. The implementation is in chrome_frame_unittest_main.cc. |
| 338 void DeleteAllSingletons(); | 346 void DeleteAllSingletons(); |
| 339 | 347 |
| 340 #endif // CHROME_FRAME_TEST_CHROME_FRAME_TEST_UTILS_H_ | 348 #endif // CHROME_FRAME_TEST_CHROME_FRAME_TEST_UTILS_H_ |
| OLD | NEW |