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 #include "chrome/test/automation/browser_proxy.h" | 5 #include "chrome/test/automation/browser_proxy.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 | 8 |
9 #include "base/json/json_reader.h" | 9 #include "base/json/json_reader.h" |
10 #include "base/logging.h" | 10 #include "base/logging.h" |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
63 if (!is_valid()) | 63 if (!is_valid()) |
64 return false; | 64 return false; |
65 | 65 |
66 int append_tab_response = -1; | 66 int append_tab_response = -1; |
67 | 67 |
68 sender_->Send(new AutomationMsg_AppendTab(handle_, tab_url, | 68 sender_->Send(new AutomationMsg_AppendTab(handle_, tab_url, |
69 &append_tab_response)); | 69 &append_tab_response)); |
70 return append_tab_response >= 0; | 70 return append_tab_response >= 0; |
71 } | 71 } |
72 | 72 |
73 bool BrowserProxy::AppendBackgroundTab(const GURL& tab_url) { | |
74 if (!is_valid()) | |
75 return false; | |
76 | |
77 int append_tab_response = -1; | |
78 | |
79 sender_->Send(new AutomationMsg_AppendBackgroundTab(handle_, tab_url, | |
80 &append_tab_response)); | |
81 return append_tab_response >= 0; | |
82 } | |
83 | |
84 bool BrowserProxy::GetActiveTabIndex(int* active_tab_index) const { | 73 bool BrowserProxy::GetActiveTabIndex(int* active_tab_index) const { |
85 if (!is_valid()) | 74 if (!is_valid()) |
86 return false; | 75 return false; |
87 | 76 |
88 if (!active_tab_index) { | 77 if (!active_tab_index) { |
89 NOTREACHED(); | 78 NOTREACHED(); |
90 return false; | 79 return false; |
91 } | 80 } |
92 | 81 |
93 int active_tab_index_response = -1; | 82 int active_tab_index_response = -1; |
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
168 } | 157 } |
169 | 158 |
170 int type_as_int; | 159 int type_as_int; |
171 if (!sender_->Send(new AutomationMsg_Type(handle_, &type_as_int))) | 160 if (!sender_->Send(new AutomationMsg_Type(handle_, &type_as_int))) |
172 return false; | 161 return false; |
173 | 162 |
174 *type = static_cast<Browser::Type>(type_as_int); | 163 *type = static_cast<Browser::Type>(type_as_int); |
175 return true; | 164 return true; |
176 } | 165 } |
177 | 166 |
178 bool BrowserProxy::IsApplication(bool* is_application) { | |
179 DCHECK(is_application); | |
180 | |
181 if (!is_valid()) | |
182 return false; | |
183 | |
184 bool success = false; | |
185 if (!sender_->Send(new AutomationMsg_IsBrowserInApplicationMode( | |
186 handle_, is_application, &success))) { | |
187 return false; | |
188 } | |
189 | |
190 return success; | |
191 } | |
192 | |
193 bool BrowserProxy::ApplyAccelerator(int id) { | 167 bool BrowserProxy::ApplyAccelerator(int id) { |
194 return RunCommandAsync(id); | 168 return RunCommandAsync(id); |
195 } | 169 } |
196 | 170 |
197 bool BrowserProxy::SimulateDrag(const gfx::Point& start, | 171 bool BrowserProxy::SimulateDrag(const gfx::Point& start, |
198 const gfx::Point& end, | 172 const gfx::Point& end, |
199 int flags, | 173 int flags, |
200 bool press_escape_en_route) { | 174 bool press_escape_en_route) { |
201 if (!is_valid()) | 175 if (!is_valid()) |
202 return false; | 176 return false; |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
241 } | 215 } |
242 | 216 |
243 bool BrowserProxy::OpenFindInPage() { | 217 bool BrowserProxy::OpenFindInPage() { |
244 if (!is_valid()) | 218 if (!is_valid()) |
245 return false; | 219 return false; |
246 | 220 |
247 return sender_->Send(new AutomationMsg_OpenFindInPage(handle_)); | 221 return sender_->Send(new AutomationMsg_OpenFindInPage(handle_)); |
248 // This message expects no response. | 222 // This message expects no response. |
249 } | 223 } |
250 | 224 |
251 bool BrowserProxy::GetFindWindowLocation(int* x, int* y) { | |
252 if (!is_valid() || !x || !y) | |
253 return false; | |
254 | |
255 return sender_->Send(new AutomationMsg_FindWindowLocation(handle_, x, y)); | |
256 } | |
257 | |
258 bool BrowserProxy::IsFindWindowFullyVisible(bool* is_visible) { | 225 bool BrowserProxy::IsFindWindowFullyVisible(bool* is_visible) { |
259 if (!is_valid()) | 226 if (!is_valid()) |
260 return false; | 227 return false; |
261 | 228 |
262 if (!is_visible) { | 229 if (!is_visible) { |
263 NOTREACHED(); | 230 NOTREACHED(); |
264 return false; | 231 return false; |
265 } | 232 } |
266 | 233 |
267 return sender_->Send( | 234 return sender_->Send( |
(...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
411 } | 378 } |
412 | 379 |
413 bool BrowserProxy::SetShelfVisible(bool is_visible) { | 380 bool BrowserProxy::SetShelfVisible(bool is_visible) { |
414 if (!is_valid()) | 381 if (!is_valid()) |
415 return false; | 382 return false; |
416 | 383 |
417 return sender_->Send(new AutomationMsg_SetShelfVisibility(handle_, | 384 return sender_->Send(new AutomationMsg_SetShelfVisibility(handle_, |
418 is_visible)); | 385 is_visible)); |
419 } | 386 } |
420 | 387 |
421 bool BrowserProxy::SetIntPreference(const std::string& name, int value) { | |
422 if (!is_valid()) | |
423 return false; | |
424 | |
425 bool result = false; | |
426 | |
427 sender_->Send(new AutomationMsg_SetIntPreference(handle_, name, value, | |
428 &result)); | |
429 return result; | |
430 } | |
431 | |
432 bool BrowserProxy::SetStringPreference(const std::string& name, | |
433 const std::string& value) { | |
434 if (!is_valid()) | |
435 return false; | |
436 | |
437 bool result = false; | |
438 | |
439 sender_->Send(new AutomationMsg_SetStringPreference(handle_, name, value, | |
440 &result)); | |
441 return result; | |
442 } | |
443 | |
444 bool BrowserProxy::GetBooleanPreference(const std::string& name, | |
445 bool* value) { | |
446 if (!is_valid()) | |
447 return false; | |
448 | |
449 bool result = false; | |
450 | |
451 sender_->Send(new AutomationMsg_GetBooleanPreference(handle_, name, value, | |
452 &result)); | |
453 return result; | |
454 } | |
455 | |
456 bool BrowserProxy::SetBooleanPreference(const std::string& name, | |
457 bool value) { | |
458 if (!is_valid()) | |
459 return false; | |
460 | |
461 bool result = false; | |
462 | |
463 sender_->Send(new AutomationMsg_SetBooleanPreference(handle_, name, | |
464 value, &result)); | |
465 return result; | |
466 } | |
467 | |
468 bool BrowserProxy::SetDefaultContentSetting(ContentSettingsType content_type, | |
469 ContentSetting setting) { | |
470 return SetContentSetting(std::string(), content_type, setting); | |
471 } | |
472 | |
473 bool BrowserProxy::SetContentSetting(const std::string& host, | |
474 ContentSettingsType content_type, | |
475 ContentSetting setting) { | |
476 if (!is_valid()) | |
477 return false; | |
478 | |
479 bool result = false; | |
480 | |
481 sender_->Send(new AutomationMsg_SetContentSetting(handle_, host, | |
482 content_type, setting, | |
483 &result)); | |
484 return result; | |
485 } | |
486 | |
487 bool BrowserProxy::TerminateSession() { | 388 bool BrowserProxy::TerminateSession() { |
488 if (!is_valid()) | 389 if (!is_valid()) |
489 return false; | 390 return false; |
490 | 391 |
491 bool result = false; | 392 bool result = false; |
492 | 393 |
493 sender_->Send(new AutomationMsg_TerminateSession(handle_, &result)); | 394 sender_->Send(new AutomationMsg_TerminateSession(handle_, &result)); |
494 | 395 |
495 return result; | 396 return result; |
496 } | 397 } |
(...skipping 16 matching lines...) Expand all Loading... |
513 window = new WindowProxy(sender_, tracker_, window_handle); | 414 window = new WindowProxy(sender_, tracker_, window_handle); |
514 window->AddRef(); | 415 window->AddRef(); |
515 } | 416 } |
516 | 417 |
517 // Since there is no scoped_refptr::attach. | 418 // Since there is no scoped_refptr::attach. |
518 scoped_refptr<WindowProxy> result; | 419 scoped_refptr<WindowProxy> result; |
519 result.swap(&window); | 420 result.swap(&window); |
520 return result; | 421 return result; |
521 } | 422 } |
522 | 423 |
523 bool BrowserProxy::IsFullscreen(bool* is_fullscreen) { | |
524 DCHECK(is_fullscreen); | |
525 | |
526 if (!is_valid()) | |
527 return false; | |
528 | |
529 return sender_->Send(new AutomationMsg_IsFullscreen(handle_, is_fullscreen)); | |
530 } | |
531 | |
532 bool BrowserProxy::IsFullscreenBubbleVisible(bool* is_visible) { | |
533 DCHECK(is_visible); | |
534 | |
535 if (!is_valid()) | |
536 return false; | |
537 | |
538 return sender_->Send(new AutomationMsg_IsFullscreenBubbleVisible(handle_, | |
539 is_visible)); | |
540 } | |
541 | |
542 bool BrowserProxy::ShutdownSessionService() { | |
543 bool did_shutdown = false; | |
544 bool succeeded = sender_->Send( | |
545 new AutomationMsg_ShutdownSessionService(handle_, &did_shutdown)); | |
546 | |
547 if (!succeeded) { | |
548 DLOG(ERROR) << | |
549 "ShutdownSessionService did not complete in a timely fashion"; | |
550 return false; | |
551 } | |
552 | |
553 return did_shutdown; | |
554 } | |
555 | |
556 bool BrowserProxy::SendJSONRequest(const std::string& request, | 424 bool BrowserProxy::SendJSONRequest(const std::string& request, |
557 int timeout_ms, | 425 int timeout_ms, |
558 std::string* response) { | 426 std::string* response) { |
559 if (!is_valid()) | 427 if (!is_valid()) |
560 return false; | 428 return false; |
561 | 429 |
562 bool result = false; | 430 bool result = false; |
563 if (!sender_->Send(new AutomationMsg_SendJSONRequest(handle_, | 431 if (!sender_->Send(new AutomationMsg_SendJSONRequest(handle_, |
564 request, | 432 request, |
565 response, | 433 response, |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
621 if (i == 0) | 489 if (i == 0) |
622 *min_start_time = start_ms; | 490 *min_start_time = start_ms; |
623 | 491 |
624 *min_start_time = std::min(start_ms, *min_start_time); | 492 *min_start_time = std::min(start_ms, *min_start_time); |
625 *max_stop_time = std::max(stop_ms, *max_stop_time); | 493 *max_stop_time = std::max(stop_ms, *max_stop_time); |
626 stop_times->push_back(stop_ms); | 494 stop_times->push_back(stop_ms); |
627 } | 495 } |
628 std::sort(stop_times->begin(), stop_times->end()); | 496 std::sort(stop_times->begin(), stop_times->end()); |
629 return true; | 497 return true; |
630 } | 498 } |
OLD | NEW |