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/cancelable_callback.h" |
17 #include "base/compiler_specific.h" | 17 #include "base/compiler_specific.h" |
18 #include "base/files/file_path.h" | 18 #include "base/files/file_path.h" |
19 #include "base/memory/scoped_ptr.h" | 19 #include "base/memory/scoped_ptr.h" |
20 #include "base/message_loop.h" | 20 #include "base/message_loop.h" |
21 #include "base/process_util.h" | 21 #include "base/process_util.h" |
22 #include "base/run_loop.h" | 22 #include "base/run_loop.h" |
23 #include "base/test/test_reg_util_win.h" | 23 #include "base/test/test_reg_util_win.h" |
24 #include "base/time.h" | 24 #include "base/time.h" |
25 #include "base/time.h" | 25 #include "base/time.h" |
26 #include "base/win/registry.h" | 26 #include "base/win/registry.h" |
27 #include "base/win/scoped_comptr.h" | 27 #include "base/win/scoped_comptr.h" |
28 #include "chrome/test/base/ui_test_utils.h" | |
29 #include "chrome_frame/chrome_tab.h" | 28 #include "chrome_frame/chrome_tab.h" |
30 #include "chrome_frame/test/simulate_input.h" | 29 #include "chrome_frame/test/simulate_input.h" |
31 #include "chrome_frame/test_utils.h" | 30 #include "chrome_frame/test_utils.h" |
32 #include "chrome_frame/utils.h" | 31 #include "chrome_frame/utils.h" |
33 | 32 |
34 #include "gtest/gtest.h" | 33 #include "gtest/gtest.h" |
35 | 34 |
36 // Needed for CreateFunctor. | 35 // Needed for CreateFunctor. |
37 #define GMOCK_MUTANT_INCLUDE_LATE_OBJECT_BINDING | 36 #define GMOCK_MUTANT_INCLUDE_LATE_OBJECT_BINDING |
38 #include "testing/gmock_mutant.h" | 37 #include "testing/gmock_mutant.h" |
(...skipping 12 matching lines...) Expand all Loading... |
51 base::ProcessHandle LaunchChrome(const std::wstring& url, | 50 base::ProcessHandle LaunchChrome(const std::wstring& url, |
52 const base::FilePath& user_data_dir); | 51 const base::FilePath& user_data_dir); |
53 | 52 |
54 // Attempts to close all open IE windows. | 53 // Attempts to close all open IE windows. |
55 // The return value is the number of windows closed. | 54 // The return value is the number of windows closed. |
56 // @note: this function requires COM to be initialized on the calling thread. | 55 // @note: this function requires COM to be initialized on the calling thread. |
57 // Since the caller might be running in either MTA or STA, the function does | 56 // Since the caller might be running in either MTA or STA, the function does |
58 // not perform this initialization itself. | 57 // not perform this initialization itself. |
59 int CloseAllIEWindows(); | 58 int CloseAllIEWindows(); |
60 | 59 |
| 60 // Saves a screen snapshot to the desktop and logs its location. |
| 61 bool TakeSnapshotAndLog(); |
| 62 |
61 extern const wchar_t kIEImageName[]; | 63 extern const wchar_t kIEImageName[]; |
62 extern const wchar_t kIEBrokerImageName[]; | 64 extern const wchar_t kIEBrokerImageName[]; |
63 extern const char kChromeImageName[]; | 65 extern const char kChromeImageName[]; |
64 extern const wchar_t kChromeLauncher[]; | 66 extern const wchar_t kChromeLauncher[]; |
65 extern const base::TimeDelta kChromeFrameLongNavigationTimeout; | 67 extern const base::TimeDelta kChromeFrameLongNavigationTimeout; |
66 extern const base::TimeDelta kChromeFrameVeryLongNavigationTimeout; | 68 extern const base::TimeDelta kChromeFrameVeryLongNavigationTimeout; |
67 | 69 |
68 // Temporarily impersonate the current thread to low integrity for the lifetime | 70 // Temporarily impersonate the current thread to low integrity for the lifetime |
69 // of the object. Destructor will automatically revert integrity level. | 71 // of the object. Destructor will automatically revert integrity level. |
70 class LowIntegrityToken { | 72 class LowIntegrityToken { |
(...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
239 bool WasTimedOut() const { | 241 bool WasTimedOut() const { |
240 return !quit_loop_invoked_; | 242 return !quit_loop_invoked_; |
241 } | 243 } |
242 | 244 |
243 void RunUntilIdle() { | 245 void RunUntilIdle() { |
244 loop_.RunUntilIdle(); | 246 loop_.RunUntilIdle(); |
245 } | 247 } |
246 | 248 |
247 private: | 249 private: |
248 static void SnapshotAndQuit() { | 250 static void SnapshotAndQuit() { |
249 base::FilePath snapshot; | 251 TakeSnapshotAndLog(); |
250 if (ui_test_utils::SaveScreenSnapshotToDesktop(&snapshot)) { | |
251 testing::UnitTest* unit_test = testing::UnitTest::GetInstance(); | |
252 const testing::TestInfo* test_info = unit_test->current_test_info(); | |
253 std::string name; | |
254 if (test_info != NULL) { | |
255 name.append(test_info->test_case_name()) | |
256 .append(1, '.') | |
257 .append(test_info->name()); | |
258 } else { | |
259 name = "unknown test"; | |
260 } | |
261 LOG(ERROR) << name << " timed out. Screen snapshot saved to " | |
262 << snapshot.value(); | |
263 } | |
264 MessageLoop::current()->Quit(); | 252 MessageLoop::current()->Quit(); |
265 } | 253 } |
266 | 254 |
267 MessageLoopForUI loop_; | 255 MessageLoopForUI loop_; |
268 base::CancelableClosure timeout_closure_; | 256 base::CancelableClosure timeout_closure_; |
269 bool snapshot_on_timeout_; | 257 bool snapshot_on_timeout_; |
270 bool quit_loop_invoked_; | 258 bool quit_loop_invoked_; |
271 }; | 259 }; |
272 | 260 |
273 // Saves typing. It's somewhat hard to create a wrapper around | 261 // Saves typing. It's somewhat hard to create a wrapper around |
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
377 } // namespace chrome_frame_test | 365 } // namespace chrome_frame_test |
378 | 366 |
379 // TODO(tommi): This is a temporary workaround while we're getting our | 367 // TODO(tommi): This is a temporary workaround while we're getting our |
380 // Singleton story straight. Ideally each test should clear up any singletons | 368 // Singleton story straight. Ideally each test should clear up any singletons |
381 // it might have created, but test cases do not implicitly have their own | 369 // it might have created, but test cases do not implicitly have their own |
382 // AtExitManager, so we have this workaround method for tests that depend on | 370 // AtExitManager, so we have this workaround method for tests that depend on |
383 // "fresh" singletons. The implementation is in chrome_frame_unittest_main.cc. | 371 // "fresh" singletons. The implementation is in chrome_frame_unittest_main.cc. |
384 void DeleteAllSingletons(); | 372 void DeleteAllSingletons(); |
385 | 373 |
386 #endif // CHROME_FRAME_TEST_CHROME_FRAME_TEST_UTILS_H_ | 374 #endif // CHROME_FRAME_TEST_CHROME_FRAME_TEST_UTILS_H_ |
OLD | NEW |