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

Side by Side Diff: chrome/test/interactive_ui/view_event_test_base.cc

Issue 355024: Addin a time-out to view base tests to prevent them from... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 11 years, 1 month 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
« no previous file with comments | « chrome/test/interactive_ui/view_event_test_base.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2006-2008 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 #include "chrome/test/interactive_ui/view_event_test_base.h" 5 #include "chrome/test/interactive_ui/view_event_test_base.h"
6 6
7 #if defined(OS_WIN) 7 #if defined(OS_WIN)
8 #include <ole2.h> 8 #include <ole2.h>
9 #endif 9 #endif
10 10
11 #include "base/compiler_specific.h"
11 #include "base/message_loop.h" 12 #include "base/message_loop.h"
13 #include "base/string_util.h"
12 #include "chrome/browser/automation/ui_controls.h" 14 #include "chrome/browser/automation/ui_controls.h"
13 #include "views/view.h" 15 #include "views/view.h"
14 #include "views/window/window.h" 16 #include "views/window/window.h"
15 17
16 namespace { 18 namespace {
17 19
20 // Default delay for the time-out at which we stop message loop.
21 const int kTimeoutInMS = 20000;
22
18 // View subclass that allows you to specify the preferred size. 23 // View subclass that allows you to specify the preferred size.
19 class TestView : public views::View { 24 class TestView : public views::View {
20 public: 25 public:
21 TestView() {} 26 TestView() {}
22 27
23 void SetPreferredSize(const gfx::Size& size) { 28 void SetPreferredSize(const gfx::Size& size) {
24 preferred_size_ = size; 29 preferred_size_ = size;
25 PreferredSizeChanged(); 30 PreferredSizeChanged();
26 } 31 }
27 32
(...skipping 12 matching lines...) Expand all
40 gfx::Size preferred_size_; 45 gfx::Size preferred_size_;
41 46
42 DISALLOW_COPY_AND_ASSIGN(TestView); 47 DISALLOW_COPY_AND_ASSIGN(TestView);
43 }; 48 };
44 49
45 // Delay in background thread before posting mouse move. 50 // Delay in background thread before posting mouse move.
46 const int kMouseMoveDelayMS = 200; 51 const int kMouseMoveDelayMS = 200;
47 52
48 } // namespace 53 } // namespace
49 54
50 ViewEventTestBase::ViewEventTestBase() : window_(NULL), content_view_(NULL) { } 55 ViewEventTestBase::ViewEventTestBase()
56 : window_(NULL),
57 content_view_(NULL),
58 ALLOW_THIS_IN_INITIALIZER_LIST(method_factory_(this)) {
59 }
51 60
52 void ViewEventTestBase::Done() { 61 void ViewEventTestBase::Done() {
62 // Cancel the pending time-out.
63 method_factory_.RevokeAll();
64
53 MessageLoop::current()->Quit(); 65 MessageLoop::current()->Quit();
54 66
55 #if defined(OS_WIN) 67 #if defined(OS_WIN)
56 // We need to post a message to tickle the Dispatcher getting called and 68 // We need to post a message to tickle the Dispatcher getting called and
57 // exiting out of the nested loop. Without this the quit never runs. 69 // exiting out of the nested loop. Without this the quit never runs.
58 PostMessage(window_->GetNativeWindow(), WM_USER, 0, 0); 70 PostMessage(window_->GetNativeWindow(), WM_USER, 0, 0);
59 #endif 71 #endif
60 72
61 // If we're in a nested message loop, as is the case with menus, we need 73 // If we're in a nested message loop, as is the case with menus, we need
62 // to quit twice. The second quit does that for us. 74 // to quit twice. The second quit does that for us.
63 MessageLoop::current()->PostDelayedTask( 75 MessageLoop::current()->PostTask(FROM_HERE, new MessageLoop::QuitTask());
64 FROM_HERE, new MessageLoop::QuitTask(), 0);
65 } 76 }
66 77
67 void ViewEventTestBase::SetUp() { 78 void ViewEventTestBase::SetUp() {
68 #if defined(OS_WIN) 79 #if defined(OS_WIN)
69 OleInitialize(NULL); 80 OleInitialize(NULL);
70 #endif 81 #endif
71 window_ = views::Window::CreateChromeWindow(NULL, gfx::Rect(), this); 82 window_ = views::Window::CreateChromeWindow(NULL, gfx::Rect(), this);
72 } 83 }
73 84
74 void ViewEventTestBase::TearDown() { 85 void ViewEventTestBase::TearDown() {
(...skipping 28 matching lines...) Expand all
103 // mouse events are going to be targeted correctly. 114 // mouse events are going to be targeted correctly.
104 #if defined(OS_WIN) 115 #if defined(OS_WIN)
105 SetForegroundWindow(window_->GetNativeWindow()); 116 SetForegroundWindow(window_->GetNativeWindow());
106 #endif 117 #endif
107 118
108 // Flush any pending events to make sure we start with a clean slate. 119 // Flush any pending events to make sure we start with a clean slate.
109 MessageLoop::current()->RunAllPending(); 120 MessageLoop::current()->RunAllPending();
110 121
111 // Schedule a task that starts the test. Need to do this as we're going to 122 // Schedule a task that starts the test. Need to do this as we're going to
112 // run the message loop. 123 // run the message loop.
113 MessageLoop::current()->PostDelayedTask( 124 MessageLoop::current()->PostTask(
114 FROM_HERE, 125 FROM_HERE,
115 NewRunnableMethod(this, &ViewEventTestBase::DoTestOnMessageLoop), 0); 126 NewRunnableMethod(this, &ViewEventTestBase::DoTestOnMessageLoop));
127
128 // Start the timeout timer to prevent hangs.
129 MessageLoop::current()->PostDelayedTask(FROM_HERE,
130 method_factory_.NewRunnableMethod(&ViewEventTestBase::TimedOut),
131 kTimeoutInMS);
116 132
117 MessageLoop::current()->Run(); 133 MessageLoop::current()->Run();
118 } 134 }
119 135
120 gfx::Size ViewEventTestBase::GetPreferredSize() { 136 gfx::Size ViewEventTestBase::GetPreferredSize() {
121 return gfx::Size(); 137 return gfx::Size();
122 } 138 }
123 139
124 void ViewEventTestBase::ScheduleMouseMoveInBackground(int x, int y) { 140 void ViewEventTestBase::ScheduleMouseMoveInBackground(int x, int y) {
125 if (!dnd_thread_.get()) { 141 if (!dnd_thread_.get()) {
(...skipping 10 matching lines...) Expand all
136 } 152 }
137 153
138 void ViewEventTestBase::RunTestMethod(Task* task) { 154 void ViewEventTestBase::RunTestMethod(Task* task) {
139 StopBackgroundThread(); 155 StopBackgroundThread();
140 156
141 scoped_ptr<Task> task_deleter(task); 157 scoped_ptr<Task> task_deleter(task);
142 task->Run(); 158 task->Run();
143 if (HasFatalFailure()) 159 if (HasFatalFailure())
144 Done(); 160 Done();
145 } 161 }
162
163 void ViewEventTestBase::TimedOut() {
164 std::string error_message = "Test timed out. Each test runs for a max of ";
165 error_message += IntToString(kTimeoutInMS);
166 error_message += " ms (kTimeoutInMS).";
167
168 GTEST_NONFATAL_FAILURE_(error_message.c_str());
169
170 Done();
171 }
OLDNEW
« no previous file with comments | « chrome/test/interactive_ui/view_event_test_base.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698