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

Side by Side Diff: chrome/test/automation/automation_proxy.cc

Issue 27060: Make basic bits of chrome/test/automation build on Linux. (Closed)
Patch Set: use base::kNoTimeout Created 11 years, 10 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
« no previous file with comments | « chrome/test/automation/automation_proxy.h ('k') | chrome/test/automation/browser_proxy.h » ('j') | 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 <sstream> 5 #include <sstream>
6 6
7 #include "chrome/test/automation/automation_proxy.h" 7 #include "chrome/test/automation/automation_proxy.h"
8 8
9 #include "base/basictypes.h"
9 #include "base/logging.h" 10 #include "base/logging.h"
11 #include "base/platform_thread.h"
12 #include "base/process_util.h"
10 #include "base/ref_counted.h" 13 #include "base/ref_counted.h"
14 #include "base/waitable_event.h"
11 #include "chrome/test/automation/automation_constants.h" 15 #include "chrome/test/automation/automation_constants.h"
12 #include "chrome/test/automation/automation_messages.h" 16 #include "chrome/test/automation/automation_messages.h"
13 #include "chrome/test/automation/browser_proxy.h" 17 #include "chrome/test/automation/browser_proxy.h"
14 #include "chrome/test/automation/tab_proxy.h" 18 #include "chrome/test/automation/tab_proxy.h"
15 #include "chrome/test/automation/window_proxy.h" 19 #include "chrome/test/automation/window_proxy.h"
20
21 #if defined(OS_WIN)
22 // TODO(port): Enable when dialog_delegate is ported.
16 #include "chrome/views/dialog_delegate.h" 23 #include "chrome/views/dialog_delegate.h"
24 #endif
17 25
18 using base::TimeDelta; 26 using base::TimeDelta;
19 using base::TimeTicks; 27 using base::TimeTicks;
20 28
21 // This class exists to group together the data and functionality used for 29 // This class exists to group together the data and functionality used for
22 // synchronous automation requests. 30 // synchronous automation requests.
23 class AutomationRequest : 31 class AutomationRequest :
24 public base::RefCountedThreadSafe<AutomationRequest> { 32 public base::RefCountedThreadSafe<AutomationRequest> {
25 public: 33 public:
26 AutomationRequest() { 34 AutomationRequest() : received_response_(true, false) {
27 static int32 routing_id = 0; 35 static int32 routing_id = 0;
28 routing_id_ = ++routing_id; 36 routing_id_ = ++routing_id;
29 received_response_ = ::CreateEvent(NULL, TRUE, FALSE, NULL);
30 DCHECK(received_response_);
31 }
32 ~AutomationRequest() {
33 DCHECK(received_response_);
34 ::CloseHandle(received_response_);
35 }
36
37 // This is called on the foreground thread to block while waiting for a
38 // response from the app.
39 // The function returns true if response is received, and returns false
40 // if there is a failure or timeout.
41 bool WaitForResponse(uint32 timeout_ms, bool* is_timeout) {
42 uint32 result = ::WaitForSingleObject(received_response_, timeout_ms);
43 if (is_timeout)
44 *is_timeout = (result == WAIT_TIMEOUT);
45
46 return result != WAIT_FAILED && result != WAIT_TIMEOUT;
47 } 37 }
48 38
49 // This is called on the background thread once the response has been 39 // This is called on the background thread once the response has been
50 // received and the foreground thread can resume execution. 40 // received and the foreground thread can resume execution.
51 bool SignalResponseReady(const IPC::Message& response) { 41 void SignalResponseReady(const IPC::Message& response) {
52 response_.reset(new IPC::Message(response)); 42 response_.reset(new IPC::Message(response));
53 43
54 DCHECK(received_response_); 44 received_response_.Signal();
55 return !!::SetEvent(received_response_);
56 } 45 }
57 46
58 // This can be used to take ownership of the response object that 47 // This can be used to take ownership of the response object that
59 // we've received, reducing the need to copy the message. 48 // we've received, reducing the need to copy the message.
60 void GrabResponse(IPC::Message** response) { 49 void GrabResponse(IPC::Message** response) {
61 DCHECK(response); 50 DCHECK(response);
62 *response = response_.get(); 51 *response = response_.get();
63 response_.release(); 52 response_.release();
64 } 53 }
65 54
66 int32 routing_id() { return routing_id_; } 55 int32 routing_id() { return routing_id_; }
67 56
68 const IPC::Message& response() { 57 const IPC::Message& response() {
69 DCHECK(response_.get()); 58 DCHECK(response_.get());
70 return *(response_.get()); 59 return *(response_.get());
71 } 60 }
72 61
73 private: 62 private:
74 DISALLOW_EVIL_CONSTRUCTORS(AutomationRequest); 63 DISALLOW_EVIL_CONSTRUCTORS(AutomationRequest);
75 64
76 int32 routing_id_; 65 int32 routing_id_;
77 scoped_ptr<IPC::Message> response_; 66 scoped_ptr<IPC::Message> response_;
78 HANDLE received_response_; 67 base::WaitableEvent received_response_;
79 }; 68 };
80 69
81 namespace { 70 namespace {
82 71
83 // This object allows messages received on the background thread to be 72 // This object allows messages received on the background thread to be
84 // properly triaged. 73 // properly triaged.
85 class AutomationMessageFilter : public IPC::ChannelProxy::MessageFilter { 74 class AutomationMessageFilter : public IPC::ChannelProxy::MessageFilter {
86 public: 75 public:
87 AutomationMessageFilter(AutomationProxy* server) : server_(server) {} 76 AutomationMessageFilter(AutomationProxy* server) : server_(server) {}
88 77
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
133 } 122 }
134 123
135 private: 124 private:
136 AutomationProxy* server_; 125 AutomationProxy* server_;
137 }; 126 };
138 127
139 } // anonymous namespace 128 } // anonymous namespace
140 129
141 130
142 AutomationProxy::AutomationProxy(int command_execution_timeout_ms) 131 AutomationProxy::AutomationProxy(int command_execution_timeout_ms)
143 : current_request_(NULL), 132 : app_launched_(true, false),
144 command_execution_timeout_ms_(command_execution_timeout_ms) { 133 initial_loads_complete_(true, false),
145 InitializeEvents(); 134 new_tab_ui_load_complete_(true, false),
135 shutdown_event_(new base::WaitableEvent(true, false)),
136 current_request_(NULL),
137 command_execution_timeout_(
138 TimeDelta::FromMilliseconds(command_execution_timeout_ms)) {
146 InitializeChannelID(); 139 InitializeChannelID();
147 InitializeHandleTracker(); 140 InitializeHandleTracker();
148 InitializeThread(); 141 InitializeThread();
149 InitializeChannel(); 142 InitializeChannel();
150 } 143 }
151 144
152 AutomationProxy::~AutomationProxy() { 145 AutomationProxy::~AutomationProxy() {
153 DCHECK(shutdown_event_.get() != NULL); 146 DCHECK(shutdown_event_.get() != NULL);
154 ::SetEvent(shutdown_event_->handle()); 147 shutdown_event_->Signal();
155 // Destruction order is important. Thread has to outlive the channel and 148 // Destruction order is important. Thread has to outlive the channel and
156 // tracker has to outlive the thread since we access the tracker inside 149 // tracker has to outlive the thread since we access the tracker inside
157 // AutomationMessageFilter::OnMessageReceived. 150 // AutomationMessageFilter::OnMessageReceived.
158 channel_.reset(); 151 channel_.reset();
159 thread_.reset(); 152 thread_.reset();
160 DCHECK(NULL == current_request_); 153 DCHECK(NULL == current_request_);
161 tracker_.reset(); 154 tracker_.reset();
162 ::CloseHandle(app_launched_);
163 ::CloseHandle(initial_loads_complete_);
164 ::CloseHandle(new_tab_ui_load_complete_);
165 }
166
167 void AutomationProxy::InitializeEvents() {
168 app_launched_ =
169 CreateEvent(NULL, // Handle cannot be inherited by child processes.
170 TRUE, // No automatic reset after a waiting thread released.
171 FALSE, // Initially not signalled.
172 NULL); // No name.
173 DCHECK(app_launched_);
174
175 // See the above call to CreateEvent to understand these parameters.
176 initial_loads_complete_ = CreateEvent(NULL, TRUE, FALSE, NULL);
177 DCHECK(initial_loads_complete_);
178
179 // See the above call to CreateEvent to understand these parameters.
180 new_tab_ui_load_complete_ = CreateEvent(NULL, TRUE, FALSE, NULL);
181 DCHECK(new_tab_ui_load_complete_);
182
183 shutdown_event_.reset(new base::WaitableEvent(true, false));
184 } 155 }
185 156
186 void AutomationProxy::InitializeChannelID() { 157 void AutomationProxy::InitializeChannelID() {
187 // The channel counter keeps us out of trouble if we create and destroy 158 // The channel counter keeps us out of trouble if we create and destroy
188 // several AutomationProxies sequentially over the course of a test run. 159 // several AutomationProxies sequentially over the course of a test run.
189 // (Creating the channel sometimes failed before when running a lot of 160 // (Creating the channel sometimes failed before when running a lot of
190 // tests in sequence, and our theory is that sometimes the channel ID 161 // tests in sequence, and our theory is that sometimes the channel ID
191 // wasn't getting freed up in time for the next test.) 162 // wasn't getting freed up in time for the next test.)
192 static int channel_counter = 0; 163 static int channel_counter = 0;
193 164
194 std::wostringstream buf; 165 std::wostringstream buf;
195 buf << L"ChromeTestingInterface:" << GetCurrentProcessId() << 166 buf << L"ChromeTestingInterface:" << base::GetCurrentProcId() <<
196 L"." << ++channel_counter; 167 L"." << ++channel_counter;
197 channel_id_ = buf.str(); 168 channel_id_ = buf.str();
198 } 169 }
199 170
200 void AutomationProxy::InitializeThread() { 171 void AutomationProxy::InitializeThread() {
201 scoped_ptr<base::Thread> thread( 172 scoped_ptr<base::Thread> thread(
202 new base::Thread("AutomationProxy_BackgroundThread")); 173 new base::Thread("AutomationProxy_BackgroundThread"));
203 base::Thread::Options options; 174 base::Thread::Options options;
204 options.message_loop_type = MessageLoop::TYPE_IO; 175 options.message_loop_type = MessageLoop::TYPE_IO;
205 bool thread_result = thread->StartWithOptions(options); 176 bool thread_result = thread->StartWithOptions(options);
(...skipping 16 matching lines...) Expand all
222 thread_->message_loop(), 193 thread_->message_loop(),
223 true, 194 true,
224 shutdown_event_.get())); 195 shutdown_event_.get()));
225 } 196 }
226 197
227 void AutomationProxy::InitializeHandleTracker() { 198 void AutomationProxy::InitializeHandleTracker() {
228 tracker_.reset(new AutomationHandleTracker(this)); 199 tracker_.reset(new AutomationHandleTracker(this));
229 } 200 }
230 201
231 bool AutomationProxy::WaitForAppLaunch() { 202 bool AutomationProxy::WaitForAppLaunch() {
232 return ::WaitForSingleObject(app_launched_, 203 return app_launched_.TimedWait(command_execution_timeout_);
233 command_execution_timeout_ms_) == WAIT_OBJECT_0;
234 } 204 }
235 205
236 void AutomationProxy::SignalAppLaunch() { 206 void AutomationProxy::SignalAppLaunch() {
237 ::SetEvent(app_launched_); 207 app_launched_.Signal();
238 } 208 }
239 209
240 bool AutomationProxy::WaitForInitialLoads() { 210 bool AutomationProxy::WaitForInitialLoads() {
241 return ::WaitForSingleObject(initial_loads_complete_, 211 return initial_loads_complete_.TimedWait(command_execution_timeout_);
242 command_execution_timeout_ms_) == WAIT_OBJECT_0;
243 } 212 }
244 213
245 bool AutomationProxy::WaitForInitialNewTabUILoad(int* load_time) { 214 bool AutomationProxy::WaitForInitialNewTabUILoad(int* load_time) {
246 if (::WaitForSingleObject(new_tab_ui_load_complete_, 215 if (new_tab_ui_load_complete_.TimedWait(command_execution_timeout_)) {
247 command_execution_timeout_ms_) == WAIT_OBJECT_0) {
248 *load_time = new_tab_ui_load_time_; 216 *load_time = new_tab_ui_load_time_;
249 ::ResetEvent(new_tab_ui_load_complete_); 217 new_tab_ui_load_complete_.Reset();
250 return true; 218 return true;
251 } 219 }
252 return false; 220 return false;
253 } 221 }
254 222
255 void AutomationProxy::SignalInitialLoads() { 223 void AutomationProxy::SignalInitialLoads() {
256 ::SetEvent(initial_loads_complete_); 224 initial_loads_complete_.Signal();
257 } 225 }
258 226
259 void AutomationProxy::SignalNewTabUITab(int load_time) { 227 void AutomationProxy::SignalNewTabUITab(int load_time) {
260 new_tab_ui_load_time_ = load_time; 228 new_tab_ui_load_time_ = load_time;
261 ::SetEvent(new_tab_ui_load_complete_); 229 new_tab_ui_load_complete_.Signal();
262 } 230 }
263 231
264 bool AutomationProxy::SavePackageShouldPromptUser(bool should_prompt) { 232 bool AutomationProxy::SavePackageShouldPromptUser(bool should_prompt) {
265 return Send(new AutomationMsg_SavePackageShouldPromptUser(0, should_prompt)); 233 return Send(new AutomationMsg_SavePackageShouldPromptUser(0, should_prompt));
266 } 234 }
267 235
268 bool AutomationProxy::GetBrowserWindowCount(int* num_windows) { 236 bool AutomationProxy::GetBrowserWindowCount(int* num_windows) {
269 if (!num_windows) { 237 if (!num_windows) {
270 NOTREACHED(); 238 NOTREACHED();
271 return false; 239 return false;
272 } 240 }
273 241
274 bool succeeded = SendWithTimeout( 242 bool succeeded = SendWithTimeout(
275 new AutomationMsg_BrowserWindowCount(0, num_windows), 243 new AutomationMsg_BrowserWindowCount(0, num_windows),
276 command_execution_timeout_ms_, NULL); 244 command_execution_timeout_ms(), NULL);
277 245
278 if (!succeeded) { 246 if (!succeeded) {
279 DLOG(ERROR) << "GetWindowCount did not complete in a timely fashion"; 247 DLOG(ERROR) << "GetWindowCount did not complete in a timely fashion";
280 return false; 248 return false;
281 } 249 }
282 250
283 return succeeded; 251 return succeeded;
284 } 252 }
285 253
286 bool AutomationProxy::WaitForWindowCountToChange(int count, int* new_count, 254 bool AutomationProxy::WaitForWindowCountToChange(int count, int* new_count,
287 int wait_timeout) { 255 int wait_timeout) {
288 const TimeTicks start = TimeTicks::Now(); 256 const TimeTicks start = TimeTicks::Now();
289 const TimeDelta timeout = TimeDelta::FromMilliseconds(wait_timeout); 257 const TimeDelta timeout = TimeDelta::FromMilliseconds(wait_timeout);
290 while (TimeTicks::Now() - start < timeout) { 258 while (TimeTicks::Now() - start < timeout) {
291 bool succeeded = GetBrowserWindowCount(new_count); 259 bool succeeded = GetBrowserWindowCount(new_count);
292 if (!succeeded) return false; 260 if (!succeeded) return false;
293 if (count != *new_count) return true; 261 if (count != *new_count) return true;
294 Sleep(automation::kSleepTime); 262 PlatformThread::Sleep(automation::kSleepTime);
295 } 263 }
296 // Window count never changed. 264 // Window count never changed.
297 return false; 265 return false;
298 } 266 }
299 267
300 bool AutomationProxy::WaitForWindowCountToBecome(int count, 268 bool AutomationProxy::WaitForWindowCountToBecome(int count,
301 int wait_timeout) { 269 int wait_timeout) {
302 const TimeTicks start = TimeTicks::Now(); 270 const TimeTicks start = TimeTicks::Now();
303 const TimeDelta timeout = TimeDelta::FromMilliseconds(wait_timeout); 271 const TimeDelta timeout = TimeDelta::FromMilliseconds(wait_timeout);
304 while (TimeTicks::Now() - start < timeout) { 272 while (TimeTicks::Now() - start < timeout) {
305 int new_count; 273 int new_count;
306 bool succeeded = GetBrowserWindowCount(&new_count); 274 bool succeeded = GetBrowserWindowCount(&new_count);
307 if (!succeeded) { 275 if (!succeeded) {
308 // Try again next round, but log it. 276 // Try again next round, but log it.
309 DLOG(ERROR) << "GetBrowserWindowCount returned false"; 277 DLOG(ERROR) << "GetBrowserWindowCount returned false";
310 } else if (count == new_count) { 278 } else if (count == new_count) {
311 return true; 279 return true;
312 } 280 }
313 Sleep(automation::kSleepTime); 281 PlatformThread::Sleep(automation::kSleepTime);
314 } 282 }
315 // Window count never reached the value we sought. 283 // Window count never reached the value we sought.
316 return false; 284 return false;
317 } 285 }
318 286
287 #if defined(OS_WIN)
288 // TODO(port): Port when DialogDelegate is ported.
319 bool AutomationProxy::GetShowingAppModalDialog( 289 bool AutomationProxy::GetShowingAppModalDialog(
320 bool* showing_app_modal_dialog, 290 bool* showing_app_modal_dialog,
321 views::DialogDelegate::DialogButton* button) { 291 views::DialogDelegate::DialogButton* button) {
322 if (!showing_app_modal_dialog || !button) { 292 if (!showing_app_modal_dialog || !button) {
323 NOTREACHED(); 293 NOTREACHED();
324 return false; 294 return false;
325 } 295 }
326 296
327 int button_int = 0; 297 int button_int = 0;
328 298
329 if (!SendWithTimeout( 299 if (!SendWithTimeout(
330 new AutomationMsg_ShowingAppModalDialog( 300 new AutomationMsg_ShowingAppModalDialog(
331 0, showing_app_modal_dialog, &button_int), 301 0, showing_app_modal_dialog, &button_int),
332 command_execution_timeout_ms_, NULL)) { 302 command_execution_timeout_ms(), NULL)) {
333 DLOG(ERROR) << "ShowingAppModalDialog did not complete in a timely fashion"; 303 DLOG(ERROR) << "ShowingAppModalDialog did not complete in a timely fashion";
334 return false; 304 return false;
335 } 305 }
336 306
337 *button = static_cast<views::DialogDelegate::DialogButton>(button_int); 307 *button = static_cast<views::DialogDelegate::DialogButton>(button_int);
338 return true; 308 return true;
339 } 309 }
340 310
341 bool AutomationProxy::ClickAppModalDialogButton( 311 bool AutomationProxy::ClickAppModalDialogButton(
342 views::DialogDelegate::DialogButton button) { 312 views::DialogDelegate::DialogButton button) {
343 bool succeeded = false; 313 bool succeeded = false;
344 314
345 if (!SendWithTimeout( 315 if (!SendWithTimeout(
346 new AutomationMsg_ClickAppModalDialogButton( 316 new AutomationMsg_ClickAppModalDialogButton(
347 0, button, &succeeded), command_execution_timeout_ms_, NULL)) { 317 0, button, &succeeded),
318 command_execution_timeout_ms(), NULL)) {
348 return false; 319 return false;
349 } 320 }
350 321
351 return succeeded; 322 return succeeded;
352 } 323 }
353 324
354 bool AutomationProxy::WaitForAppModalDialog(int wait_timeout) { 325 bool AutomationProxy::WaitForAppModalDialog(int wait_timeout) {
355 const TimeTicks start = TimeTicks::Now(); 326 const TimeTicks start = TimeTicks::Now();
356 const TimeDelta timeout = TimeDelta::FromMilliseconds(wait_timeout); 327 const TimeDelta timeout = TimeDelta::FromMilliseconds(wait_timeout);
357 while (TimeTicks::Now() - start < timeout) { 328 while (TimeTicks::Now() - start < timeout) {
358 bool dialog_shown = false; 329 bool dialog_shown = false;
359 views::DialogDelegate::DialogButton button = 330 views::DialogDelegate::DialogButton button =
360 views::DialogDelegate::DIALOGBUTTON_NONE; 331 views::DialogDelegate::DIALOGBUTTON_NONE;
361 bool succeeded = GetShowingAppModalDialog(&dialog_shown, &button); 332 bool succeeded = GetShowingAppModalDialog(&dialog_shown, &button);
362 if (!succeeded) { 333 if (!succeeded) {
363 // Try again next round, but log it. 334 // Try again next round, but log it.
364 DLOG(ERROR) << "GetShowingAppModalDialog returned false"; 335 DLOG(ERROR) << "GetShowingAppModalDialog returned false";
365 } else if (dialog_shown) { 336 } else if (dialog_shown) {
366 return true; 337 return true;
367 } 338 }
368 Sleep(automation::kSleepTime); 339 Sleep(automation::kSleepTime);
369 } 340 }
370 // Dialog never shown. 341 // Dialog never shown.
371 return false; 342 return false;
372 } 343 }
344 #endif // defined(OS_WIN)
373 345
374 bool AutomationProxy::SetFilteredInet(bool enabled) { 346 bool AutomationProxy::SetFilteredInet(bool enabled) {
375 return Send(new AutomationMsg_SetFilteredInet(0, enabled)); 347 return Send(new AutomationMsg_SetFilteredInet(0, enabled));
376 } 348 }
377 349
378 void AutomationProxy::Disconnect() { 350 void AutomationProxy::Disconnect() {
379 channel_.reset(); 351 channel_.reset();
380 } 352 }
381 353
382 void AutomationProxy::OnMessageReceived(const IPC::Message& msg) { 354 void AutomationProxy::OnMessageReceived(const IPC::Message& msg) {
383 // This won't get called unless AutomationProxy is run from 355 // This won't get called unless AutomationProxy is run from
384 // inside a message loop. 356 // inside a message loop.
385 NOTREACHED(); 357 NOTREACHED();
386 } 358 }
387 359
388 void AutomationProxy::OnChannelError() { 360 void AutomationProxy::OnChannelError() {
389 DLOG(ERROR) << "Channel error in AutomationProxy."; 361 DLOG(ERROR) << "Channel error in AutomationProxy.";
390 } 362 }
391 363
392 WindowProxy* AutomationProxy::GetActiveWindow() { 364 WindowProxy* AutomationProxy::GetActiveWindow() {
393 int handle = 0; 365 int handle = 0;
394 366
395 if (!SendWithTimeout(new AutomationMsg_ActiveWindow(0, &handle), 367 if (!SendWithTimeout(new AutomationMsg_ActiveWindow(0, &handle),
396 command_execution_timeout_ms_, NULL)) { 368 command_execution_timeout_ms(), NULL)) {
397 return NULL; 369 return NULL;
398 } 370 }
399 371
400 return new WindowProxy(this, tracker_.get(), handle); 372 return new WindowProxy(this, tracker_.get(), handle);
401 } 373 }
402 374
403 375
404 BrowserProxy* AutomationProxy::GetBrowserWindow(int window_index) { 376 BrowserProxy* AutomationProxy::GetBrowserWindow(int window_index) {
405 int handle = 0; 377 int handle = 0;
406 378
407 if (!SendWithTimeout(new AutomationMsg_BrowserWindow(0, window_index, 379 if (!SendWithTimeout(new AutomationMsg_BrowserWindow(0, window_index,
408 &handle), 380 &handle),
409 command_execution_timeout_ms_, NULL)) { 381 command_execution_timeout_ms(), NULL)) {
410 DLOG(ERROR) << "GetBrowserWindow did not complete in a timely fashion"; 382 DLOG(ERROR) << "GetBrowserWindow did not complete in a timely fashion";
411 return NULL; 383 return NULL;
412 } 384 }
413 385
414 if (handle == 0) { 386 if (handle == 0) {
415 return NULL; 387 return NULL;
416 } 388 }
417 389
418 return new BrowserProxy(this, tracker_.get(), handle); 390 return new BrowserProxy(this, tracker_.get(), handle);
419 } 391 }
420 392
421 BrowserProxy* AutomationProxy::GetLastActiveBrowserWindow() { 393 BrowserProxy* AutomationProxy::GetLastActiveBrowserWindow() {
422 int handle = 0; 394 int handle = 0;
423 395
424 if (!SendWithTimeout(new AutomationMsg_LastActiveBrowserWindow( 396 if (!SendWithTimeout(new AutomationMsg_LastActiveBrowserWindow(
425 0, &handle), command_execution_timeout_ms_, NULL)) { 397 0, &handle), command_execution_timeout_ms(), NULL)) {
426 DLOG(ERROR) << "GetLastActiveBrowserWindow did not complete in a timely fash ion"; 398 DLOG(ERROR) << "GetLastActiveBrowserWindow did not complete in a timely fash ion";
427 return NULL; 399 return NULL;
428 } 400 }
429 401
430 return new BrowserProxy(this, tracker_.get(), handle); 402 return new BrowserProxy(this, tracker_.get(), handle);
431 } 403 }
432 404
433 bool AutomationProxy::Send(IPC::Message* message) { 405 bool AutomationProxy::Send(IPC::Message* message) {
434 return SendWithTimeout(message, INFINITE, NULL); 406 return SendWithTimeout(message, base::kNoTimeout, NULL);
435 } 407 }
436 408
437 bool AutomationProxy::SendWithTimeout(IPC::Message* message, int timeout, 409 bool AutomationProxy::SendWithTimeout(IPC::Message* message, int timeout,
438 bool* is_timeout) { 410 bool* is_timeout) {
439 if (is_timeout) 411 if (is_timeout)
440 *is_timeout = false; 412 *is_timeout = false;
441 413
442 if (channel_.get()) { 414 if (channel_.get()) {
443 bool result = channel_->SendWithTimeout(message, timeout); 415 bool result = channel_->SendWithTimeout(message, timeout);
444 if (!result && is_timeout) 416 if (!result && is_timeout)
(...skipping 12 matching lines...) Expand all
457 429
458 if (message.ReadInt(&iter, &handle)) { 430 if (message.ReadInt(&iter, &handle)) {
459 tracker_->InvalidateHandle(handle); 431 tracker_->InvalidateHandle(handle);
460 } 432 }
461 } 433 }
462 434
463 bool AutomationProxy::OpenNewBrowserWindow(int show_command) { 435 bool AutomationProxy::OpenNewBrowserWindow(int show_command) {
464 return Send(new AutomationMsg_OpenNewBrowserWindow(0, show_command)); 436 return Send(new AutomationMsg_OpenNewBrowserWindow(0, show_command));
465 } 437 }
466 438
439 #if defined(OS_WIN)
440 // TODO(port): Replace HWNDs.
467 TabProxy* AutomationProxy::CreateExternalTab(HWND parent, 441 TabProxy* AutomationProxy::CreateExternalTab(HWND parent,
468 const gfx::Rect& dimensions, 442 const gfx::Rect& dimensions,
469 unsigned int style, 443 unsigned int style,
470 HWND* external_tab_container) { 444 HWND* external_tab_container) {
471 IPC::Message* response = NULL; 445 IPC::Message* response = NULL;
472 int handle = 0; 446 int handle = 0;
473 447
474 bool succeeded = 448 bool succeeded =
475 Send(new AutomationMsg_CreateExternalTab(0, parent, dimensions, style, 449 Send(new AutomationMsg_CreateExternalTab(0, parent, dimensions, style,
476 external_tab_container, 450 external_tab_container,
477 &handle)); 451 &handle));
478 if (!succeeded) { 452 if (!succeeded) {
479 return NULL; 453 return NULL;
480 } 454 }
481 455
482 DCHECK(IsWindow(*external_tab_container)); 456 DCHECK(IsWindow(*external_tab_container));
483 457
484 return new TabProxy(this, tracker_.get(), handle); 458 return new TabProxy(this, tracker_.get(), handle);
485 } 459 }
460 #endif // defined(OS_WIN)
OLDNEW
« no previous file with comments | « chrome/test/automation/automation_proxy.h ('k') | chrome/test/automation/browser_proxy.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698