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/automation_proxy.h" | 5 #include "chrome/test/automation/automation_proxy.h" |
6 | 6 |
7 #include <sstream> | 7 #include <sstream> |
8 | 8 |
9 #include "base/basictypes.h" | 9 #include "base/basictypes.h" |
10 #include "base/debug/trace_event.h" | 10 #include "base/debug/trace_event.h" |
(...skipping 244 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
255 | 255 |
256 bool AutomationProxy::WaitForWindowCountToBecome(int count) { | 256 bool AutomationProxy::WaitForWindowCountToBecome(int count) { |
257 bool wait_success = false; | 257 bool wait_success = false; |
258 if (!Send(new AutomationMsg_WaitForBrowserWindowCountToBecome( | 258 if (!Send(new AutomationMsg_WaitForBrowserWindowCountToBecome( |
259 count, &wait_success))) { | 259 count, &wait_success))) { |
260 return false; | 260 return false; |
261 } | 261 } |
262 return wait_success; | 262 return wait_success; |
263 } | 263 } |
264 | 264 |
265 bool AutomationProxy::GetShowingAppModalDialog(bool* showing_app_modal_dialog, | |
266 ui::DialogButton* button) { | |
267 if (!showing_app_modal_dialog || !button) { | |
268 NOTREACHED(); | |
269 return false; | |
270 } | |
271 | |
272 int button_int = 0; | |
273 | |
274 if (!Send(new AutomationMsg_ShowingAppModalDialog( | |
275 showing_app_modal_dialog, &button_int))) { | |
276 return false; | |
277 } | |
278 | |
279 *button = static_cast<ui::DialogButton>(button_int); | |
280 return true; | |
281 } | |
282 | |
283 bool AutomationProxy::ClickAppModalDialogButton(ui::DialogButton button) { | |
284 bool succeeded = false; | |
285 | |
286 if (!Send(new AutomationMsg_ClickAppModalDialogButton( | |
287 button, &succeeded))) { | |
288 return false; | |
289 } | |
290 | |
291 return succeeded; | |
292 } | |
293 | |
294 bool AutomationProxy::WaitForAppModalDialog() { | |
295 bool wait_success = false; | |
296 if (!Send(new AutomationMsg_WaitForAppModalDialogToBeShown(&wait_success))) | |
297 return false; | |
298 return wait_success; | |
299 } | |
300 | |
301 bool AutomationProxy::IsURLDisplayed(GURL url) { | 265 bool AutomationProxy::IsURLDisplayed(GURL url) { |
302 int window_count; | 266 int window_count; |
303 if (!GetBrowserWindowCount(&window_count)) | 267 if (!GetBrowserWindowCount(&window_count)) |
304 return false; | 268 return false; |
305 | 269 |
306 for (int i = 0; i < window_count; i++) { | 270 for (int i = 0; i < window_count; i++) { |
307 scoped_refptr<BrowserProxy> window = GetBrowserWindow(i); | 271 scoped_refptr<BrowserProxy> window = GetBrowserWindow(i); |
308 if (!window.get()) | 272 if (!window.get()) |
309 break; | 273 break; |
310 | 274 |
(...skipping 21 matching lines...) Expand all Loading... |
332 bool AutomationProxy::GetMetricEventDuration(const std::string& event_name, | 296 bool AutomationProxy::GetMetricEventDuration(const std::string& event_name, |
333 int* duration_ms) { | 297 int* duration_ms) { |
334 return Send(new AutomationMsg_GetMetricEventDuration(event_name, | 298 return Send(new AutomationMsg_GetMetricEventDuration(event_name, |
335 duration_ms)); | 299 duration_ms)); |
336 } | 300 } |
337 | 301 |
338 bool AutomationProxy::SetFilteredInet(bool enabled) { | 302 bool AutomationProxy::SetFilteredInet(bool enabled) { |
339 return Send(new AutomationMsg_SetFilteredInet(enabled)); | 303 return Send(new AutomationMsg_SetFilteredInet(enabled)); |
340 } | 304 } |
341 | 305 |
342 int AutomationProxy::GetFilteredInetHitCount() { | |
343 int hit_count; | |
344 if (!Send(new AutomationMsg_GetFilteredInetHitCount(&hit_count))) | |
345 return -1; | |
346 return hit_count; | |
347 } | |
348 | |
349 bool AutomationProxy::SendProxyConfig(const std::string& new_proxy_config) { | 306 bool AutomationProxy::SendProxyConfig(const std::string& new_proxy_config) { |
350 return Send(new AutomationMsg_SetProxyConfig(new_proxy_config)); | 307 return Send(new AutomationMsg_SetProxyConfig(new_proxy_config)); |
351 } | 308 } |
352 | 309 |
353 void AutomationProxy::Disconnect() { | 310 void AutomationProxy::Disconnect() { |
354 DCHECK(shutdown_event_.get() != NULL); | 311 DCHECK(shutdown_event_.get() != NULL); |
355 shutdown_event_->Signal(); | 312 shutdown_event_->Signal(); |
356 channel_.reset(); | 313 channel_.reset(); |
357 } | 314 } |
358 | 315 |
(...skipping 20 matching lines...) Expand all Loading... |
379 | 336 |
380 scoped_refptr<BrowserProxy> AutomationProxy::GetBrowserWindow( | 337 scoped_refptr<BrowserProxy> AutomationProxy::GetBrowserWindow( |
381 int window_index) { | 338 int window_index) { |
382 int handle = 0; | 339 int handle = 0; |
383 if (!Send(new AutomationMsg_BrowserWindow(window_index, &handle))) | 340 if (!Send(new AutomationMsg_BrowserWindow(window_index, &handle))) |
384 return NULL; | 341 return NULL; |
385 | 342 |
386 return ProxyObjectFromHandle<BrowserProxy>(handle); | 343 return ProxyObjectFromHandle<BrowserProxy>(handle); |
387 } | 344 } |
388 | 345 |
389 bool AutomationProxy::GetBrowserLocale(string16* locale) { | |
390 DCHECK(locale != NULL); | |
391 if (!Send(new AutomationMsg_GetBrowserLocale(locale))) | |
392 return false; | |
393 | |
394 return !locale->empty(); | |
395 } | |
396 | |
397 scoped_refptr<BrowserProxy> AutomationProxy::FindTabbedBrowserWindow() { | 346 scoped_refptr<BrowserProxy> AutomationProxy::FindTabbedBrowserWindow() { |
398 int handle = 0; | 347 int handle = 0; |
399 if (!Send(new AutomationMsg_FindTabbedBrowserWindow(&handle))) | 348 if (!Send(new AutomationMsg_FindTabbedBrowserWindow(&handle))) |
400 return NULL; | 349 return NULL; |
401 | 350 |
402 return ProxyObjectFromHandle<BrowserProxy>(handle); | 351 return ProxyObjectFromHandle<BrowserProxy>(handle); |
403 } | 352 } |
404 | 353 |
405 scoped_refptr<BrowserProxy> AutomationProxy::GetLastActiveBrowserWindow() { | |
406 int handle = 0; | |
407 if (!Send(new AutomationMsg_LastActiveBrowserWindow(&handle))) | |
408 return NULL; | |
409 | |
410 return ProxyObjectFromHandle<BrowserProxy>(handle); | |
411 } | |
412 | |
413 IPC::SyncChannel* AutomationProxy::channel() { | 354 IPC::SyncChannel* AutomationProxy::channel() { |
414 return channel_.get(); | 355 return channel_.get(); |
415 } | 356 } |
416 | 357 |
417 bool AutomationProxy::Send(IPC::Message* message) { | 358 bool AutomationProxy::Send(IPC::Message* message) { |
418 return Send(message, | 359 return Send(message, |
419 static_cast<int>(action_timeout_.InMilliseconds())); | 360 static_cast<int>(action_timeout_.InMilliseconds())); |
420 } | 361 } |
421 | 362 |
422 bool AutomationProxy::Send(IPC::Message* message, int timeout_ms) { | 363 bool AutomationProxy::Send(IPC::Message* message, int timeout_ms) { |
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
502 void AutomationProxy::SetChannel(IPC::Channel* channel) { | 443 void AutomationProxy::SetChannel(IPC::Channel* channel) { |
503 if (tracker_.get()) | 444 if (tracker_.get()) |
504 tracker_->put_channel(channel); | 445 tracker_->put_channel(channel); |
505 } | 446 } |
506 | 447 |
507 void AutomationProxy::ResetChannel() { | 448 void AutomationProxy::ResetChannel() { |
508 if (tracker_.get()) | 449 if (tracker_.get()) |
509 tracker_->put_channel(NULL); | 450 tracker_->put_channel(NULL); |
510 } | 451 } |
511 | 452 |
512 #if defined(OS_CHROMEOS) | |
513 bool AutomationProxy::LoginWithUserAndPass(const std::string& username, | |
514 const std::string& password) { | |
515 bool success; | |
516 bool sent = Send(new AutomationMsg_LoginWithUserAndPass(username, | |
517 password, | |
518 &success)); | |
519 // If message sending unsuccessful or test failed, return false. | |
520 return sent && success; | |
521 } | |
522 #endif | |
523 | |
524 bool AutomationProxy::BeginTracing(const std::string& categories) { | 453 bool AutomationProxy::BeginTracing(const std::string& categories) { |
525 bool result = false; | 454 bool result = false; |
526 bool send_success = Send(new AutomationMsg_BeginTracing(categories, | 455 bool send_success = Send(new AutomationMsg_BeginTracing(categories, |
527 &result)); | 456 &result)); |
528 return send_success && result; | 457 return send_success && result; |
529 } | 458 } |
530 | 459 |
531 bool AutomationProxy::EndTracing(std::string* json_trace_output) { | 460 bool AutomationProxy::EndTracing(std::string* json_trace_output) { |
532 bool success = false; | 461 bool success = false; |
533 size_t num_trace_chunks = 0; | 462 size_t num_trace_chunks = 0; |
(...skipping 29 matching lines...) Expand all Loading... |
563 } | 492 } |
564 | 493 |
565 bool AutomationProxy::SendJSONRequest(const std::string& request, | 494 bool AutomationProxy::SendJSONRequest(const std::string& request, |
566 int timeout_ms, | 495 int timeout_ms, |
567 std::string* response) { | 496 std::string* response) { |
568 bool result = false; | 497 bool result = false; |
569 if (!SendAutomationJSONRequest(this, request, timeout_ms, response, &result)) | 498 if (!SendAutomationJSONRequest(this, request, timeout_ms, response, &result)) |
570 return false; | 499 return false; |
571 return result; | 500 return result; |
572 } | 501 } |
OLD | NEW |