Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(120)

Side by Side Diff: chrome_frame/test/chrome_frame_test_utils.h

Issue 10007043: Attempt to fix ChromeFrameTestWithWebServer tests. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Added retry logic for WidgetModeIE_Version. Created 8 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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"
22 #include "base/time.h"
20 #include "base/test/test_reg_util_win.h" 23 #include "base/test/test_reg_util_win.h"
24 #include "base/time.h"
21 #include "base/win/registry.h" 25 #include "base/win/registry.h"
22 #include "base/win/scoped_comptr.h" 26 #include "base/win/scoped_comptr.h"
27 #include "chrome/test/base/ui_test_utils.h"
23 #include "chrome_frame/chrome_tab.h" 28 #include "chrome_frame/chrome_tab.h"
24 #include "chrome_frame/test/simulate_input.h" 29 #include "chrome_frame/test/simulate_input.h"
25 #include "chrome_frame/test_utils.h" 30 #include "chrome_frame/test_utils.h"
26 #include "chrome_frame/utils.h" 31 #include "chrome_frame/utils.h"
27 32
28 #include "gtest/gtest.h" 33 #include "gtest/gtest.h"
29 34
30 // Needed for CreateFunctor. 35 // Needed for CreateFunctor.
31 #define GMOCK_MUTANT_INCLUDE_LATE_OBJECT_BINDING 36 #define GMOCK_MUTANT_INCLUDE_LATE_OBJECT_BINDING
32 #include "testing/gmock_mutant.h" 37 #include "testing/gmock_mutant.h"
(...skipping 13 matching lines...) Expand all
46 // The return value is the number of windows closed. 51 // The return value is the number of windows closed.
47 // @note: this function requires COM to be initialized on the calling thread. 52 // @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 53 // Since the caller might be running in either MTA or STA, the function does
49 // not perform this initialization itself. 54 // not perform this initialization itself.
50 int CloseAllIEWindows(); 55 int CloseAllIEWindows();
51 56
52 extern const wchar_t kIEImageName[]; 57 extern const wchar_t kIEImageName[];
53 extern const wchar_t kIEBrokerImageName[]; 58 extern const wchar_t kIEBrokerImageName[];
54 extern const char kChromeImageName[]; 59 extern const char kChromeImageName[];
55 extern const wchar_t kChromeLauncher[]; 60 extern const wchar_t kChromeLauncher[];
56 extern const int kChromeFrameLongNavigationTimeoutInSeconds; 61 extern const base::TimeDelta kChromeFrameLongNavigationTimeout;
57 extern const int kChromeFrameVeryLongNavigationTimeoutInSeconds; 62 extern const base::TimeDelta kChromeFrameVeryLongNavigationTimeout;
58 63
59 // Temporarily impersonate the current thread to low integrity for the lifetime 64 // Temporarily impersonate the current thread to low integrity for the lifetime
60 // of the object. Destructor will automatically revert integrity level. 65 // of the object. Destructor will automatically revert integrity level.
61 class LowIntegrityToken { 66 class LowIntegrityToken {
62 public: 67 public:
63 LowIntegrityToken(); 68 LowIntegrityToken();
64 ~LowIntegrityToken(); 69 ~LowIntegrityToken();
65 BOOL Impersonate(); 70 BOOL Impersonate();
66 BOOL RevertToSelf(); 71 BOOL RevertToSelf();
67 protected: 72 protected:
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after
181 186
182 // used to detect if outgoing COM calls hung. 187 // used to detect if outgoing COM calls hung.
183 bool is_hung_; 188 bool is_hung_;
184 base::win::ScopedComPtr<IMessageFilter> prev_filter_; 189 base::win::ScopedComPtr<IMessageFilter> prev_filter_;
185 }; 190 };
186 191
187 // MessageLoopForUI wrapper that runs only for a limited time. 192 // MessageLoopForUI wrapper that runs only for a limited time.
188 // We need a UI message loop in the main thread. 193 // We need a UI message loop in the main thread.
189 class TimedMsgLoop { 194 class TimedMsgLoop {
190 public: 195 public:
191 TimedMsgLoop() : quit_loop_invoked_(false) { 196 TimedMsgLoop() : snapshot_on_timeout_(false), quit_loop_invoked_(false) {
192 } 197 }
193 198
194 void RunFor(int seconds) { 199 void set_snapshot_on_timeout(bool value) {
195 QuitAfter(seconds); 200 snapshot_on_timeout_ = value;
201 }
202
203 void RunFor(base::TimeDelta duration) {
196 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);
197 loop_.MessageLoop::Run(); 210 loop_.MessageLoop::Run();
211 timeout_closure_.Cancel();
198 } 212 }
199 213
200 void PostTask(const tracked_objects::Location& from_here, 214 void PostTask(const tracked_objects::Location& from_here,
201 const base::Closure& task) { 215 const base::Closure& task) {
202 loop_.PostTask(from_here, task); 216 loop_.PostTask(from_here, task);
203 } 217 }
204 218
205 void PostDelayedTask(const tracked_objects::Location& from_here, 219 void PostDelayedTask(const tracked_objects::Location& from_here,
206 const base::Closure& task, int64 delay_ms) { 220 const base::Closure& task, int64 delay_ms) {
207 loop_.PostDelayedTask(from_here, task, delay_ms); 221 loop_.PostDelayedTask(from_here, task, delay_ms);
208 } 222 }
209 223
210 void Quit() { 224 void Quit() {
211 QuitAfter(0); 225 QuitAfter(base::TimeDelta());
robertshield 2012/04/11 17:03:36 nit: add a comment to indicate that this means "qu
grt (UTC plus 2) 2012/04/11 17:33:08 Done.
212 } 226 }
213 227
214 void QuitAfter(int seconds) { 228 void QuitAfter(base::TimeDelta delay) {
229 timeout_closure_.Cancel();
215 quit_loop_invoked_ = true; 230 quit_loop_invoked_ = true;
216 loop_.PostDelayedTask( 231 loop_.PostDelayedTask(FROM_HERE, MessageLoop::QuitClosure(), delay);
217 FROM_HERE, MessageLoop::QuitClosure(), 1000 * seconds);
218 } 232 }
219 233
220 bool WasTimedOut() const { 234 bool WasTimedOut() const {
221 return !quit_loop_invoked_; 235 return !quit_loop_invoked_;
222 } 236 }
223 237
238 void RunAllPending() {
239 loop_.RunAllPending();
240 }
241
224 private: 242 private:
243 static void SnapshotAndQuit() {
244 FilePath snapshot;
245 if (ui_test_utils::SaveScreenSnapshotToDesktop(&snapshot)) {
246 testing::UnitTest* unit_test = testing::UnitTest::GetInstance();
247 const testing::TestInfo* test_info = unit_test->current_test_info();
248 std::string name;
249 if (test_info != NULL) {
250 name.append(test_info->test_case_name())
251 .append(1, '.')
252 .append(test_info->name());
253 } else {
254 name = "unknown test";
255 }
256 LOG(ERROR) << name << " timed out. Screen snapshot saved to "
257 << snapshot.value();
258 }
259 MessageLoop::current()->Quit();
260 }
261
225 MessageLoopForUI loop_; 262 MessageLoopForUI loop_;
263 base::CancelableClosure timeout_closure_;
264 bool snapshot_on_timeout_;
226 bool quit_loop_invoked_; 265 bool quit_loop_invoked_;
227 }; 266 };
228 267
229 // Saves typing. It's somewhat hard to create a wrapper around 268 // Saves typing. It's somewhat hard to create a wrapper around
230 // testing::InvokeWithoutArgs since it returns a 269 // testing::InvokeWithoutArgs since it returns a
231 // non-public (testing::internal) type. 270 // non-public (testing::internal) type.
232 #define QUIT_LOOP(loop) testing::InvokeWithoutArgs(\ 271 #define QUIT_LOOP(loop) testing::InvokeWithoutArgs(\
233 testing::CreateFunctor(&loop, &chrome_frame_test::TimedMsgLoop::Quit)) 272 testing::CreateFunctor(&loop, &chrome_frame_test::TimedMsgLoop::Quit))
234 273
235 #define QUIT_LOOP_SOON(loop, seconds) testing::InvokeWithoutArgs(\ 274 #define QUIT_LOOP_SOON(loop, delay) testing::InvokeWithoutArgs(\
236 testing::CreateFunctor(&loop, &chrome_frame_test::TimedMsgLoop::QuitAfter, \ 275 testing::CreateFunctor(&loop, &chrome_frame_test::TimedMsgLoop::QuitAfter, \
237 seconds)) 276 delay))
238 277
239 // Launches IE as a COM server and returns the corresponding IWebBrowser2 278 // Launches IE as a COM server and returns the corresponding IWebBrowser2
240 // interface pointer. 279 // interface pointer.
241 // Returns S_OK on success. 280 // Returns S_OK on success.
242 HRESULT LaunchIEAsComServer(IWebBrowser2** web_browser); 281 HRESULT LaunchIEAsComServer(IWebBrowser2** web_browser);
243 282
244 FilePath GetProfilePath(const std::wstring& suffix); 283 FilePath GetProfilePath(const std::wstring& suffix);
245 284
246 // Returns the path of the exe passed in. 285 // Returns the path of the exe passed in.
247 std::wstring GetExecutableAppPath(const std::wstring& file); 286 std::wstring GetExecutableAppPath(const std::wstring& file);
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
321 // KillProcesses. Takes in the wait flag as a parameter. 360 // KillProcesses. Takes in the wait flag as a parameter.
322 bool KillProcesses(const std::wstring& executable_name, int exit_code, 361 bool KillProcesses(const std::wstring& executable_name, int exit_code,
323 bool wait); 362 bool wait);
324 363
325 // Returns the type of test bed, PER_USER or SYSTEM_LEVEL. 364 // Returns the type of test bed, PER_USER or SYSTEM_LEVEL.
326 ScopedChromeFrameRegistrar::RegistrationType GetTestBedType(); 365 ScopedChromeFrameRegistrar::RegistrationType GetTestBedType();
327 366
328 // Clears IE8 session restore history. 367 // Clears IE8 session restore history.
329 void ClearIESessionHistory(); 368 void ClearIESessionHistory();
330 369
370 // Returns a local IPv4 address for the current machine. The address
371 // corresponding to a NIC is preferred over the loopback address.
372 std::string GetLocalIPv4Address();
373
331 } // namespace chrome_frame_test 374 } // namespace chrome_frame_test
332 375
333 // TODO(tommi): This is a temporary workaround while we're getting our 376 // TODO(tommi): This is a temporary workaround while we're getting our
334 // Singleton story straight. Ideally each test should clear up any singletons 377 // 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 378 // 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 379 // AtExitManager, so we have this workaround method for tests that depend on
337 // "fresh" singletons. The implementation is in chrome_frame_unittest_main.cc. 380 // "fresh" singletons. The implementation is in chrome_frame_unittest_main.cc.
338 void DeleteAllSingletons(); 381 void DeleteAllSingletons();
339 382
340 #endif // CHROME_FRAME_TEST_CHROME_FRAME_TEST_UTILS_H_ 383 #endif // CHROME_FRAME_TEST_CHROME_FRAME_TEST_UTILS_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698