| 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" |
| 18 #include "base/file_path.h" |
| 17 #include "base/memory/scoped_ptr.h" | 19 #include "base/memory/scoped_ptr.h" |
| 18 #include "base/message_loop.h" | 20 #include "base/message_loop.h" |
| 19 #include "base/process_util.h" | 21 #include "base/process_util.h" |
| 20 #include "base/time.h" | 22 #include "base/time.h" |
| 21 #include "base/test/test_reg_util_win.h" | 23 #include "base/test/test_reg_util_win.h" |
| 24 #include "base/time.h" |
| 22 #include "base/win/registry.h" | 25 #include "base/win/registry.h" |
| 23 #include "base/win/scoped_comptr.h" | 26 #include "base/win/scoped_comptr.h" |
| 27 #include "chrome/test/base/ui_test_utils.h" |
| 24 #include "chrome_frame/chrome_tab.h" | 28 #include "chrome_frame/chrome_tab.h" |
| 25 #include "chrome_frame/test/simulate_input.h" | 29 #include "chrome_frame/test/simulate_input.h" |
| 26 #include "chrome_frame/test_utils.h" | 30 #include "chrome_frame/test_utils.h" |
| 27 #include "chrome_frame/utils.h" | 31 #include "chrome_frame/utils.h" |
| 28 | 32 |
| 29 #include "gtest/gtest.h" | 33 #include "gtest/gtest.h" |
| 30 | 34 |
| 31 // Needed for CreateFunctor. | 35 // Needed for CreateFunctor. |
| 32 #define GMOCK_MUTANT_INCLUDE_LATE_OBJECT_BINDING | 36 #define GMOCK_MUTANT_INCLUDE_LATE_OBJECT_BINDING |
| 33 #include "testing/gmock_mutant.h" | 37 #include "testing/gmock_mutant.h" |
| (...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 182 | 186 |
| 183 // used to detect if outgoing COM calls hung. | 187 // used to detect if outgoing COM calls hung. |
| 184 bool is_hung_; | 188 bool is_hung_; |
| 185 base::win::ScopedComPtr<IMessageFilter> prev_filter_; | 189 base::win::ScopedComPtr<IMessageFilter> prev_filter_; |
| 186 }; | 190 }; |
| 187 | 191 |
| 188 // MessageLoopForUI wrapper that runs only for a limited time. | 192 // MessageLoopForUI wrapper that runs only for a limited time. |
| 189 // We need a UI message loop in the main thread. | 193 // We need a UI message loop in the main thread. |
| 190 class TimedMsgLoop { | 194 class TimedMsgLoop { |
| 191 public: | 195 public: |
| 192 TimedMsgLoop() : quit_loop_invoked_(false) { | 196 TimedMsgLoop() : snapshot_on_timeout_(false), quit_loop_invoked_(false) { |
| 197 } |
| 198 |
| 199 void set_snapshot_on_timeout(bool value) { |
| 200 snapshot_on_timeout_ = value; |
| 193 } | 201 } |
| 194 | 202 |
| 195 void RunFor(base::TimeDelta duration) { | 203 void RunFor(base::TimeDelta duration) { |
| 196 QuitAfter(duration); | |
| 197 quit_loop_invoked_ = false; | 204 quit_loop_invoked_ = false; |
| 205 if (snapshot_on_timeout_) |
| 206 timeout_closure_.Reset(base::Bind(&TimedMsgLoop::SnapshotAndQuit)); |
| 207 else |
| 208 timeout_closure_.Reset(MessageLoop::QuitClosure()); |
| 209 loop_.PostDelayedTask(FROM_HERE, timeout_closure_.callback(), duration); |
| 198 loop_.MessageLoop::Run(); | 210 loop_.MessageLoop::Run(); |
| 211 timeout_closure_.Cancel(); |
| 199 } | 212 } |
| 200 | 213 |
| 201 void PostTask(const tracked_objects::Location& from_here, | 214 void PostTask(const tracked_objects::Location& from_here, |
| 202 const base::Closure& task) { | 215 const base::Closure& task) { |
| 203 loop_.PostTask(from_here, task); | 216 loop_.PostTask(from_here, task); |
| 204 } | 217 } |
| 205 | 218 |
| 206 void PostDelayedTask(const tracked_objects::Location& from_here, | 219 void PostDelayedTask(const tracked_objects::Location& from_here, |
| 207 const base::Closure& task, int64 delay_ms) { | 220 const base::Closure& task, int64 delay_ms) { |
| 208 loop_.PostDelayedTask(from_here, task, delay_ms); | 221 loop_.PostDelayedTask(from_here, task, delay_ms); |
| 209 } | 222 } |
| 210 | 223 |
| 211 void Quit() { | 224 void Quit() { |
| 225 // Quit after no delay. |
| 212 QuitAfter(base::TimeDelta()); | 226 QuitAfter(base::TimeDelta()); |
| 213 } | 227 } |
| 214 | 228 |
| 215 void QuitAfter(base::TimeDelta delay) { | 229 void QuitAfter(base::TimeDelta delay) { |
| 230 timeout_closure_.Cancel(); |
| 216 quit_loop_invoked_ = true; | 231 quit_loop_invoked_ = true; |
| 217 loop_.PostDelayedTask(FROM_HERE, MessageLoop::QuitClosure(), delay); | 232 loop_.PostDelayedTask(FROM_HERE, MessageLoop::QuitClosure(), delay); |
| 218 } | 233 } |
| 219 | 234 |
| 220 bool WasTimedOut() const { | 235 bool WasTimedOut() const { |
| 221 return !quit_loop_invoked_; | 236 return !quit_loop_invoked_; |
| 222 } | 237 } |
| 223 | 238 |
| 239 void RunAllPending() { |
| 240 loop_.RunAllPending(); |
| 241 } |
| 242 |
| 224 private: | 243 private: |
| 244 static void SnapshotAndQuit() { |
| 245 FilePath snapshot; |
| 246 if (ui_test_utils::SaveScreenSnapshotToDesktop(&snapshot)) { |
| 247 testing::UnitTest* unit_test = testing::UnitTest::GetInstance(); |
| 248 const testing::TestInfo* test_info = unit_test->current_test_info(); |
| 249 std::string name; |
| 250 if (test_info != NULL) { |
| 251 name.append(test_info->test_case_name()) |
| 252 .append(1, '.') |
| 253 .append(test_info->name()); |
| 254 } else { |
| 255 name = "unknown test"; |
| 256 } |
| 257 LOG(ERROR) << name << " timed out. Screen snapshot saved to " |
| 258 << snapshot.value(); |
| 259 } |
| 260 MessageLoop::current()->Quit(); |
| 261 } |
| 262 |
| 225 MessageLoopForUI loop_; | 263 MessageLoopForUI loop_; |
| 264 base::CancelableClosure timeout_closure_; |
| 265 bool snapshot_on_timeout_; |
| 226 bool quit_loop_invoked_; | 266 bool quit_loop_invoked_; |
| 227 }; | 267 }; |
| 228 | 268 |
| 229 // Saves typing. It's somewhat hard to create a wrapper around | 269 // Saves typing. It's somewhat hard to create a wrapper around |
| 230 // testing::InvokeWithoutArgs since it returns a | 270 // testing::InvokeWithoutArgs since it returns a |
| 231 // non-public (testing::internal) type. | 271 // non-public (testing::internal) type. |
| 232 #define QUIT_LOOP(loop) testing::InvokeWithoutArgs(\ | 272 #define QUIT_LOOP(loop) testing::InvokeWithoutArgs(\ |
| 233 testing::CreateFunctor(&loop, &chrome_frame_test::TimedMsgLoop::Quit)) | 273 testing::CreateFunctor(&loop, &chrome_frame_test::TimedMsgLoop::Quit)) |
| 234 | 274 |
| 235 #define QUIT_LOOP_SOON(loop, delay) testing::InvokeWithoutArgs(\ | 275 #define QUIT_LOOP_SOON(loop, delay) testing::InvokeWithoutArgs(\ |
| (...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 321 // KillProcesses. Takes in the wait flag as a parameter. | 361 // KillProcesses. Takes in the wait flag as a parameter. |
| 322 bool KillProcesses(const std::wstring& executable_name, int exit_code, | 362 bool KillProcesses(const std::wstring& executable_name, int exit_code, |
| 323 bool wait); | 363 bool wait); |
| 324 | 364 |
| 325 // Returns the type of test bed, PER_USER or SYSTEM_LEVEL. | 365 // Returns the type of test bed, PER_USER or SYSTEM_LEVEL. |
| 326 ScopedChromeFrameRegistrar::RegistrationType GetTestBedType(); | 366 ScopedChromeFrameRegistrar::RegistrationType GetTestBedType(); |
| 327 | 367 |
| 328 // Clears IE8 session restore history. | 368 // Clears IE8 session restore history. |
| 329 void ClearIESessionHistory(); | 369 void ClearIESessionHistory(); |
| 330 | 370 |
| 371 // Returns a local IPv4 address for the current machine. The address |
| 372 // corresponding to a NIC is preferred over the loopback address. |
| 373 std::string GetLocalIPv4Address(); |
| 374 |
| 331 } // namespace chrome_frame_test | 375 } // namespace chrome_frame_test |
| 332 | 376 |
| 333 // TODO(tommi): This is a temporary workaround while we're getting our | 377 // TODO(tommi): This is a temporary workaround while we're getting our |
| 334 // Singleton story straight. Ideally each test should clear up any singletons | 378 // 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 | 379 // 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 | 380 // AtExitManager, so we have this workaround method for tests that depend on |
| 337 // "fresh" singletons. The implementation is in chrome_frame_unittest_main.cc. | 381 // "fresh" singletons. The implementation is in chrome_frame_unittest_main.cc. |
| 338 void DeleteAllSingletons(); | 382 void DeleteAllSingletons(); |
| 339 | 383 |
| 340 #endif // CHROME_FRAME_TEST_CHROME_FRAME_TEST_UTILS_H_ | 384 #endif // CHROME_FRAME_TEST_CHROME_FRAME_TEST_UTILS_H_ |
| OLD | NEW |