| 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/compiler_specific.h" | 16 #include "base/compiler_specific.h" |
| 17 #include "base/memory/scoped_ptr.h" | 17 #include "base/memory/scoped_ptr.h" |
| 18 #include "base/message_loop.h" | 18 #include "base/message_loop.h" |
| 19 #include "base/process_util.h" | 19 #include "base/process_util.h" |
| 20 #include "base/time.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" |
| 26 #include "chrome_frame/utils.h" | 27 #include "chrome_frame/utils.h" |
| 27 | 28 |
| 28 #include "gtest/gtest.h" | 29 #include "gtest/gtest.h" |
| 29 | 30 |
| (...skipping 16 matching lines...) Expand all Loading... |
| 46 // The return value is the number of windows closed. | 47 // The return value is the number of windows closed. |
| 47 // @note: this function requires COM to be initialized on the calling thread. | 48 // @note: this function requires COM to be initialized on the calling thread. |
| 48 // Since the caller might be running in either MTA or STA, the function does | 49 // Since the caller might be running in either MTA or STA, the function does |
| 49 // not perform this initialization itself. | 50 // not perform this initialization itself. |
| 50 int CloseAllIEWindows(); | 51 int CloseAllIEWindows(); |
| 51 | 52 |
| 52 extern const wchar_t kIEImageName[]; | 53 extern const wchar_t kIEImageName[]; |
| 53 extern const wchar_t kIEBrokerImageName[]; | 54 extern const wchar_t kIEBrokerImageName[]; |
| 54 extern const char kChromeImageName[]; | 55 extern const char kChromeImageName[]; |
| 55 extern const wchar_t kChromeLauncher[]; | 56 extern const wchar_t kChromeLauncher[]; |
| 56 extern const int kChromeFrameLongNavigationTimeoutInSeconds; | 57 extern const base::TimeDelta kChromeFrameLongNavigationTimeout; |
| 57 extern const int kChromeFrameVeryLongNavigationTimeoutInSeconds; | 58 extern const base::TimeDelta kChromeFrameVeryLongNavigationTimeout; |
| 58 | 59 |
| 59 // Temporarily impersonate the current thread to low integrity for the lifetime | 60 // Temporarily impersonate the current thread to low integrity for the lifetime |
| 60 // of the object. Destructor will automatically revert integrity level. | 61 // of the object. Destructor will automatically revert integrity level. |
| 61 class LowIntegrityToken { | 62 class LowIntegrityToken { |
| 62 public: | 63 public: |
| 63 LowIntegrityToken(); | 64 LowIntegrityToken(); |
| 64 ~LowIntegrityToken(); | 65 ~LowIntegrityToken(); |
| 65 BOOL Impersonate(); | 66 BOOL Impersonate(); |
| 66 BOOL RevertToSelf(); | 67 BOOL RevertToSelf(); |
| 67 protected: | 68 protected: |
| (...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 184 base::win::ScopedComPtr<IMessageFilter> prev_filter_; | 185 base::win::ScopedComPtr<IMessageFilter> prev_filter_; |
| 185 }; | 186 }; |
| 186 | 187 |
| 187 // MessageLoopForUI wrapper that runs only for a limited time. | 188 // MessageLoopForUI wrapper that runs only for a limited time. |
| 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(base::TimeDelta duration) { |
| 195 QuitAfter(seconds); | 196 QuitAfter(duration); |
| 196 quit_loop_invoked_ = false; | 197 quit_loop_invoked_ = false; |
| 197 loop_.MessageLoop::Run(); | 198 loop_.MessageLoop::Run(); |
| 198 } | 199 } |
| 199 | 200 |
| 200 void PostTask(const tracked_objects::Location& from_here, | 201 void PostTask(const tracked_objects::Location& from_here, |
| 201 const base::Closure& task) { | 202 const base::Closure& task) { |
| 202 loop_.PostTask(from_here, task); | 203 loop_.PostTask(from_here, task); |
| 203 } | 204 } |
| 204 | 205 |
| 205 void PostDelayedTask(const tracked_objects::Location& from_here, | 206 void PostDelayedTask(const tracked_objects::Location& from_here, |
| 206 const base::Closure& task, int64 delay_ms) { | 207 const base::Closure& task, int64 delay_ms) { |
| 207 loop_.PostDelayedTask(from_here, task, delay_ms); | 208 loop_.PostDelayedTask(from_here, task, delay_ms); |
| 208 } | 209 } |
| 209 | 210 |
| 210 void Quit() { | 211 void Quit() { |
| 211 QuitAfter(0); | 212 QuitAfter(base::TimeDelta()); |
| 212 } | 213 } |
| 213 | 214 |
| 214 void QuitAfter(int seconds) { | 215 void QuitAfter(base::TimeDelta delay) { |
| 215 quit_loop_invoked_ = true; | 216 quit_loop_invoked_ = true; |
| 216 loop_.PostDelayedTask( | 217 loop_.PostDelayedTask(FROM_HERE, MessageLoop::QuitClosure(), delay); |
| 217 FROM_HERE, MessageLoop::QuitClosure(), 1000 * seconds); | |
| 218 } | 218 } |
| 219 | 219 |
| 220 bool WasTimedOut() const { | 220 bool WasTimedOut() const { |
| 221 return !quit_loop_invoked_; | 221 return !quit_loop_invoked_; |
| 222 } | 222 } |
| 223 | 223 |
| 224 private: | 224 private: |
| 225 MessageLoopForUI loop_; | 225 MessageLoopForUI loop_; |
| 226 bool quit_loop_invoked_; | 226 bool quit_loop_invoked_; |
| 227 }; | 227 }; |
| 228 | 228 |
| 229 // Saves typing. It's somewhat hard to create a wrapper around | 229 // Saves typing. It's somewhat hard to create a wrapper around |
| 230 // testing::InvokeWithoutArgs since it returns a | 230 // testing::InvokeWithoutArgs since it returns a |
| 231 // non-public (testing::internal) type. | 231 // non-public (testing::internal) type. |
| 232 #define QUIT_LOOP(loop) testing::InvokeWithoutArgs(\ | 232 #define QUIT_LOOP(loop) testing::InvokeWithoutArgs(\ |
| 233 testing::CreateFunctor(&loop, &chrome_frame_test::TimedMsgLoop::Quit)) | 233 testing::CreateFunctor(&loop, &chrome_frame_test::TimedMsgLoop::Quit)) |
| 234 | 234 |
| 235 #define QUIT_LOOP_SOON(loop, seconds) testing::InvokeWithoutArgs(\ | 235 #define QUIT_LOOP_SOON(loop, delay) testing::InvokeWithoutArgs(\ |
| 236 testing::CreateFunctor(&loop, &chrome_frame_test::TimedMsgLoop::QuitAfter, \ | 236 testing::CreateFunctor(&loop, &chrome_frame_test::TimedMsgLoop::QuitAfter, \ |
| 237 seconds)) | 237 delay)) |
| 238 | 238 |
| 239 // Launches IE as a COM server and returns the corresponding IWebBrowser2 | 239 // Launches IE as a COM server and returns the corresponding IWebBrowser2 |
| 240 // interface pointer. | 240 // interface pointer. |
| 241 // Returns S_OK on success. | 241 // Returns S_OK on success. |
| 242 HRESULT LaunchIEAsComServer(IWebBrowser2** web_browser); | 242 HRESULT LaunchIEAsComServer(IWebBrowser2** web_browser); |
| 243 | 243 |
| 244 FilePath GetProfilePath(const std::wstring& suffix); | 244 FilePath GetProfilePath(const std::wstring& suffix); |
| 245 | 245 |
| 246 // Returns the path of the exe passed in. | 246 // Returns the path of the exe passed in. |
| 247 std::wstring GetExecutableAppPath(const std::wstring& file); | 247 std::wstring GetExecutableAppPath(const std::wstring& file); |
| (...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 331 } // namespace chrome_frame_test | 331 } // namespace chrome_frame_test |
| 332 | 332 |
| 333 // TODO(tommi): This is a temporary workaround while we're getting our | 333 // TODO(tommi): This is a temporary workaround while we're getting our |
| 334 // Singleton story straight. Ideally each test should clear up any singletons | 334 // 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 | 335 // 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 | 336 // AtExitManager, so we have this workaround method for tests that depend on |
| 337 // "fresh" singletons. The implementation is in chrome_frame_unittest_main.cc. | 337 // "fresh" singletons. The implementation is in chrome_frame_unittest_main.cc. |
| 338 void DeleteAllSingletons(); | 338 void DeleteAllSingletons(); |
| 339 | 339 |
| 340 #endif // CHROME_FRAME_TEST_CHROME_FRAME_TEST_UTILS_H_ | 340 #endif // CHROME_FRAME_TEST_CHROME_FRAME_TEST_UTILS_H_ |
| OLD | NEW |