OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 <gtest/gtest.h> | 7 #include <gtest/gtest.h> |
8 | 8 |
9 #include <sstream> | 9 #include <sstream> |
10 | 10 |
(...skipping 209 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
220 void AutomationProxy::SignalInitialLoads() { | 220 void AutomationProxy::SignalInitialLoads() { |
221 initial_loads_complete_.Signal(); | 221 initial_loads_complete_.Signal(); |
222 } | 222 } |
223 | 223 |
224 void AutomationProxy::SignalNewTabUITab(int load_time) { | 224 void AutomationProxy::SignalNewTabUITab(int load_time) { |
225 new_tab_ui_load_time_ = load_time; | 225 new_tab_ui_load_time_ = load_time; |
226 new_tab_ui_load_complete_.Signal(); | 226 new_tab_ui_load_complete_.Signal(); |
227 } | 227 } |
228 | 228 |
229 bool AutomationProxy::SavePackageShouldPromptUser(bool should_prompt) { | 229 bool AutomationProxy::SavePackageShouldPromptUser(bool should_prompt) { |
230 return Send(new AutomationMsg_SavePackageShouldPromptUser(0, should_prompt)); | 230 return Send(new AutomationMsg_SavePackageShouldPromptUser(should_prompt)); |
231 } | 231 } |
232 | 232 |
233 scoped_refptr<ExtensionProxy> AutomationProxy::InstallExtension( | 233 scoped_refptr<ExtensionProxy> AutomationProxy::InstallExtension( |
234 const FilePath& crx_file, bool with_ui) { | 234 const FilePath& crx_file, bool with_ui) { |
235 int handle = 0; | 235 int handle = 0; |
236 if (!Send(new AutomationMsg_InstallExtensionAndGetHandle(0, crx_file, with_ui, | 236 if (!Send(new AutomationMsg_InstallExtensionAndGetHandle(crx_file, with_ui, |
237 &handle))) | 237 &handle))) |
238 return NULL; | 238 return NULL; |
239 | 239 |
240 return ProxyObjectFromHandle<ExtensionProxy>(handle); | 240 return ProxyObjectFromHandle<ExtensionProxy>(handle); |
241 } | 241 } |
242 | 242 |
243 void AutomationProxy::EnsureExtensionTestResult() { | 243 void AutomationProxy::EnsureExtensionTestResult() { |
244 bool result; | 244 bool result; |
245 std::string message; | 245 std::string message; |
246 if (!Send(new AutomationMsg_WaitForExtensionTestResult(0, &result, | 246 if (!Send(new AutomationMsg_WaitForExtensionTestResult(&result, |
247 &message))) { | 247 &message))) { |
248 FAIL() << "Could not send WaitForExtensionTestResult message"; | 248 FAIL() << "Could not send WaitForExtensionTestResult message"; |
249 return; | 249 return; |
250 } | 250 } |
251 ASSERT_TRUE(result) << "Extension test message: " << message; | 251 ASSERT_TRUE(result) << "Extension test message: " << message; |
252 } | 252 } |
253 | 253 |
254 bool AutomationProxy::GetEnabledExtensions( | 254 bool AutomationProxy::GetEnabledExtensions( |
255 std::vector<FilePath>* extension_directories) { | 255 std::vector<FilePath>* extension_directories) { |
256 return Send(new AutomationMsg_GetEnabledExtensions( | 256 return Send(new AutomationMsg_GetEnabledExtensions(extension_directories)); |
257 0, extension_directories)); | |
258 } | 257 } |
259 | 258 |
260 bool AutomationProxy::GetBrowserWindowCount(int* num_windows) { | 259 bool AutomationProxy::GetBrowserWindowCount(int* num_windows) { |
261 if (!num_windows) { | 260 if (!num_windows) { |
262 NOTREACHED(); | 261 NOTREACHED(); |
263 return false; | 262 return false; |
264 } | 263 } |
265 | 264 |
266 return Send(new AutomationMsg_BrowserWindowCount(0, num_windows)); | 265 return Send(new AutomationMsg_BrowserWindowCount(num_windows)); |
267 } | 266 } |
268 | 267 |
269 bool AutomationProxy::GetNormalBrowserWindowCount(int* num_windows) { | 268 bool AutomationProxy::GetNormalBrowserWindowCount(int* num_windows) { |
270 if (!num_windows) { | 269 if (!num_windows) { |
271 NOTREACHED(); | 270 NOTREACHED(); |
272 return false; | 271 return false; |
273 } | 272 } |
274 | 273 |
275 return Send(new AutomationMsg_NormalBrowserWindowCount(0, num_windows)); | 274 return Send(new AutomationMsg_NormalBrowserWindowCount(num_windows)); |
276 } | 275 } |
277 | 276 |
278 bool AutomationProxy::WaitForWindowCountToBecome(int count) { | 277 bool AutomationProxy::WaitForWindowCountToBecome(int count) { |
279 bool wait_success = false; | 278 bool wait_success = false; |
280 if (!Send(new AutomationMsg_WaitForBrowserWindowCountToBecome( | 279 if (!Send(new AutomationMsg_WaitForBrowserWindowCountToBecome( |
281 0, count, &wait_success))) { | 280 count, &wait_success))) { |
282 return false; | 281 return false; |
283 } | 282 } |
284 return wait_success; | 283 return wait_success; |
285 } | 284 } |
286 | 285 |
287 bool AutomationProxy::GetShowingAppModalDialog( | 286 bool AutomationProxy::GetShowingAppModalDialog( |
288 bool* showing_app_modal_dialog, | 287 bool* showing_app_modal_dialog, |
289 MessageBoxFlags::DialogButton* button) { | 288 MessageBoxFlags::DialogButton* button) { |
290 if (!showing_app_modal_dialog || !button) { | 289 if (!showing_app_modal_dialog || !button) { |
291 NOTREACHED(); | 290 NOTREACHED(); |
292 return false; | 291 return false; |
293 } | 292 } |
294 | 293 |
295 int button_int = 0; | 294 int button_int = 0; |
296 | 295 |
297 if (!Send(new AutomationMsg_ShowingAppModalDialog( | 296 if (!Send(new AutomationMsg_ShowingAppModalDialog( |
298 0, showing_app_modal_dialog, &button_int))) { | 297 showing_app_modal_dialog, &button_int))) { |
299 return false; | 298 return false; |
300 } | 299 } |
301 | 300 |
302 *button = static_cast<MessageBoxFlags::DialogButton>(button_int); | 301 *button = static_cast<MessageBoxFlags::DialogButton>(button_int); |
303 return true; | 302 return true; |
304 } | 303 } |
305 | 304 |
306 bool AutomationProxy::ClickAppModalDialogButton( | 305 bool AutomationProxy::ClickAppModalDialogButton( |
307 MessageBoxFlags::DialogButton button) { | 306 MessageBoxFlags::DialogButton button) { |
308 bool succeeded = false; | 307 bool succeeded = false; |
309 | 308 |
310 if (!Send(new AutomationMsg_ClickAppModalDialogButton( | 309 if (!Send(new AutomationMsg_ClickAppModalDialogButton( |
311 0, button, &succeeded))) { | 310 button, &succeeded))) { |
312 return false; | 311 return false; |
313 } | 312 } |
314 | 313 |
315 return succeeded; | 314 return succeeded; |
316 } | 315 } |
317 | 316 |
318 bool AutomationProxy::WaitForAppModalDialog() { | 317 bool AutomationProxy::WaitForAppModalDialog() { |
319 bool wait_success = false; | 318 bool wait_success = false; |
320 if (!Send(new AutomationMsg_WaitForAppModalDialogToBeShown(0, &wait_success))) | 319 if (!Send(new AutomationMsg_WaitForAppModalDialogToBeShown(&wait_success))) |
321 return false; | 320 return false; |
322 return wait_success; | 321 return wait_success; |
323 } | 322 } |
324 | 323 |
325 bool AutomationProxy::IsURLDisplayed(GURL url) { | 324 bool AutomationProxy::IsURLDisplayed(GURL url) { |
326 int window_count; | 325 int window_count; |
327 if (!GetBrowserWindowCount(&window_count)) | 326 if (!GetBrowserWindowCount(&window_count)) |
328 return false; | 327 return false; |
329 | 328 |
330 for (int i = 0; i < window_count; i++) { | 329 for (int i = 0; i < window_count; i++) { |
(...skipping 17 matching lines...) Expand all Loading... |
348 if (tab_url == url) | 347 if (tab_url == url) |
349 return true; | 348 return true; |
350 } | 349 } |
351 } | 350 } |
352 | 351 |
353 return false; | 352 return false; |
354 } | 353 } |
355 | 354 |
356 bool AutomationProxy::GetMetricEventDuration(const std::string& event_name, | 355 bool AutomationProxy::GetMetricEventDuration(const std::string& event_name, |
357 int* duration_ms) { | 356 int* duration_ms) { |
358 return Send(new AutomationMsg_GetMetricEventDuration(0, event_name, | 357 return Send(new AutomationMsg_GetMetricEventDuration(event_name, |
359 duration_ms)); | 358 duration_ms)); |
360 } | 359 } |
361 | 360 |
362 bool AutomationProxy::SetFilteredInet(bool enabled) { | 361 bool AutomationProxy::SetFilteredInet(bool enabled) { |
363 return Send(new AutomationMsg_SetFilteredInet(0, enabled)); | 362 return Send(new AutomationMsg_SetFilteredInet(enabled)); |
364 } | 363 } |
365 | 364 |
366 int AutomationProxy::GetFilteredInetHitCount() { | 365 int AutomationProxy::GetFilteredInetHitCount() { |
367 int hit_count; | 366 int hit_count; |
368 if (!Send(new AutomationMsg_GetFilteredInetHitCount(0, &hit_count))) | 367 if (!Send(new AutomationMsg_GetFilteredInetHitCount(&hit_count))) |
369 return -1; | 368 return -1; |
370 return hit_count; | 369 return hit_count; |
371 } | 370 } |
372 | 371 |
373 bool AutomationProxy::SendProxyConfig(const std::string& new_proxy_config) { | 372 bool AutomationProxy::SendProxyConfig(const std::string& new_proxy_config) { |
374 return Send(new AutomationMsg_SetProxyConfig(0, new_proxy_config)); | 373 return Send(new AutomationMsg_SetProxyConfig(new_proxy_config)); |
375 } | 374 } |
376 | 375 |
377 void AutomationProxy::Disconnect() { | 376 void AutomationProxy::Disconnect() { |
378 DCHECK(shutdown_event_.get() != NULL); | 377 DCHECK(shutdown_event_.get() != NULL); |
379 shutdown_event_->Signal(); | 378 shutdown_event_->Signal(); |
380 channel_.reset(); | 379 channel_.reset(); |
381 } | 380 } |
382 | 381 |
383 void AutomationProxy::OnMessageReceived(const IPC::Message& msg) { | 382 void AutomationProxy::OnMessageReceived(const IPC::Message& msg) { |
384 // This won't get called unless AutomationProxy is run from | 383 // This won't get called unless AutomationProxy is run from |
385 // inside a message loop. | 384 // inside a message loop. |
386 NOTREACHED(); | 385 NOTREACHED(); |
387 } | 386 } |
388 | 387 |
389 void AutomationProxy::OnChannelError() { | 388 void AutomationProxy::OnChannelError() { |
390 LOG(ERROR) << "Channel error in AutomationProxy."; | 389 LOG(ERROR) << "Channel error in AutomationProxy."; |
391 if (disconnect_on_failure_) | 390 if (disconnect_on_failure_) |
392 Disconnect(); | 391 Disconnect(); |
393 } | 392 } |
394 | 393 |
395 scoped_refptr<WindowProxy> AutomationProxy::GetActiveWindow() { | 394 scoped_refptr<WindowProxy> AutomationProxy::GetActiveWindow() { |
396 int handle = 0; | 395 int handle = 0; |
397 if (!Send(new AutomationMsg_ActiveWindow(0, &handle))) | 396 if (!Send(new AutomationMsg_ActiveWindow(&handle))) |
398 return NULL; | 397 return NULL; |
399 | 398 |
400 return ProxyObjectFromHandle<WindowProxy>(handle); | 399 return ProxyObjectFromHandle<WindowProxy>(handle); |
401 } | 400 } |
402 | 401 |
403 scoped_refptr<BrowserProxy> AutomationProxy::GetBrowserWindow( | 402 scoped_refptr<BrowserProxy> AutomationProxy::GetBrowserWindow( |
404 int window_index) { | 403 int window_index) { |
405 int handle = 0; | 404 int handle = 0; |
406 if (!Send(new AutomationMsg_BrowserWindow(0, window_index, &handle))) | 405 if (!Send(new AutomationMsg_BrowserWindow(window_index, &handle))) |
407 return NULL; | 406 return NULL; |
408 | 407 |
409 return ProxyObjectFromHandle<BrowserProxy>(handle); | 408 return ProxyObjectFromHandle<BrowserProxy>(handle); |
410 } | 409 } |
411 | 410 |
412 bool AutomationProxy::GetBrowserLocale(string16* locale) { | 411 bool AutomationProxy::GetBrowserLocale(string16* locale) { |
413 DCHECK(locale != NULL); | 412 DCHECK(locale != NULL); |
414 if (!Send(new AutomationMsg_GetBrowserLocale(0, locale))) | 413 if (!Send(new AutomationMsg_GetBrowserLocale(locale))) |
415 return false; | 414 return false; |
416 | 415 |
417 return !locale->empty(); | 416 return !locale->empty(); |
418 } | 417 } |
419 | 418 |
420 scoped_refptr<BrowserProxy> AutomationProxy::FindNormalBrowserWindow() { | 419 scoped_refptr<BrowserProxy> AutomationProxy::FindNormalBrowserWindow() { |
421 int handle = 0; | 420 int handle = 0; |
422 if (!Send(new AutomationMsg_FindNormalBrowserWindow(0, &handle))) | 421 if (!Send(new AutomationMsg_FindNormalBrowserWindow(&handle))) |
423 return NULL; | 422 return NULL; |
424 | 423 |
425 return ProxyObjectFromHandle<BrowserProxy>(handle); | 424 return ProxyObjectFromHandle<BrowserProxy>(handle); |
426 } | 425 } |
427 | 426 |
428 scoped_refptr<BrowserProxy> AutomationProxy::GetLastActiveBrowserWindow() { | 427 scoped_refptr<BrowserProxy> AutomationProxy::GetLastActiveBrowserWindow() { |
429 int handle = 0; | 428 int handle = 0; |
430 if (!Send(new AutomationMsg_LastActiveBrowserWindow(0, &handle))) | 429 if (!Send(new AutomationMsg_LastActiveBrowserWindow(&handle))) |
431 return NULL; | 430 return NULL; |
432 | 431 |
433 return ProxyObjectFromHandle<BrowserProxy>(handle); | 432 return ProxyObjectFromHandle<BrowserProxy>(handle); |
434 } | 433 } |
435 | 434 |
436 #if defined(OS_POSIX) | 435 #if defined(OS_POSIX) |
437 base::file_handle_mapping_vector AutomationProxy::fds_to_map() const { | 436 base::file_handle_mapping_vector AutomationProxy::fds_to_map() const { |
438 base::file_handle_mapping_vector map; | 437 base::file_handle_mapping_vector map; |
439 const int ipcfd = channel_->GetClientFileDescriptor(); | 438 const int ipcfd = channel_->GetClientFileDescriptor(); |
440 if (ipcfd > -1) | 439 if (ipcfd > -1) |
(...skipping 27 matching lines...) Expand all Loading... |
468 void AutomationProxy::InvalidateHandle(const IPC::Message& message) { | 467 void AutomationProxy::InvalidateHandle(const IPC::Message& message) { |
469 void* iter = NULL; | 468 void* iter = NULL; |
470 int handle; | 469 int handle; |
471 | 470 |
472 if (message.ReadInt(&iter, &handle)) { | 471 if (message.ReadInt(&iter, &handle)) { |
473 tracker_->InvalidateHandle(handle); | 472 tracker_->InvalidateHandle(handle); |
474 } | 473 } |
475 } | 474 } |
476 | 475 |
477 bool AutomationProxy::OpenNewBrowserWindow(Browser::Type type, bool show) { | 476 bool AutomationProxy::OpenNewBrowserWindow(Browser::Type type, bool show) { |
478 if (type == Browser::TYPE_NORMAL) | |
479 return Send(new AutomationMsg_OpenNewBrowserWindow(0, show)); | |
480 return Send( | 477 return Send( |
481 new AutomationMsg_OpenNewBrowserWindowOfType(0, static_cast<int>(type), | 478 new AutomationMsg_OpenNewBrowserWindowOfType(static_cast<int>(type), |
482 show)); | 479 show)); |
483 } | 480 } |
484 | 481 |
485 scoped_refptr<TabProxy> AutomationProxy::CreateExternalTab( | 482 scoped_refptr<TabProxy> AutomationProxy::CreateExternalTab( |
486 const IPC::ExternalTabSettings& settings, | 483 const ExternalTabSettings& settings, |
487 gfx::NativeWindow* external_tab_container, | 484 gfx::NativeWindow* external_tab_container, |
488 gfx::NativeWindow* tab) { | 485 gfx::NativeWindow* tab) { |
489 int handle = 0; | 486 int handle = 0; |
490 int session_id = 0; | 487 int session_id = 0; |
491 bool succeeded = | 488 bool succeeded = |
492 Send(new AutomationMsg_CreateExternalTab(0, settings, | 489 Send(new AutomationMsg_CreateExternalTab(settings, |
493 external_tab_container, | 490 external_tab_container, |
494 tab, | 491 tab, |
495 &handle, | 492 &handle, |
496 &session_id)); | 493 &session_id)); |
497 if (!succeeded) { | 494 if (!succeeded) { |
498 return NULL; | 495 return NULL; |
499 } | 496 } |
500 | 497 |
501 #if defined(OS_WIN) | 498 #if defined(OS_WIN) |
502 DCHECK(IsWindow(*external_tab_container)); | 499 DCHECK(IsWindow(*external_tab_container)); |
(...skipping 29 matching lines...) Expand all Loading... |
532 | 529 |
533 void AutomationProxy::ResetChannel() { | 530 void AutomationProxy::ResetChannel() { |
534 if (tracker_.get()) | 531 if (tracker_.get()) |
535 tracker_->put_channel(NULL); | 532 tracker_->put_channel(NULL); |
536 } | 533 } |
537 | 534 |
538 #if defined(OS_CHROMEOS) | 535 #if defined(OS_CHROMEOS) |
539 bool AutomationProxy::LoginWithUserAndPass(const std::string& username, | 536 bool AutomationProxy::LoginWithUserAndPass(const std::string& username, |
540 const std::string& password) { | 537 const std::string& password) { |
541 bool success; | 538 bool success; |
542 bool sent = Send(new AutomationMsg_LoginWithUserAndPass(0, username, | 539 bool sent = Send(new AutomationMsg_LoginWithUserAndPass(username, |
543 password, | 540 password, |
544 &success)); | 541 &success)); |
545 // If message sending unsuccessful or test failed, return false. | 542 // If message sending unsuccessful or test failed, return false. |
546 return sent && success; | 543 return sent && success; |
547 } | 544 } |
548 #endif | 545 #endif |
549 | 546 |
550 bool AutomationProxy::ResetToDefaultTheme() { | 547 bool AutomationProxy::ResetToDefaultTheme() { |
551 return Send(new AutomationMsg_ResetToDefaultTheme(0)); | 548 return Send(new AutomationMsg_ResetToDefaultTheme()); |
552 } | 549 } |
OLD | NEW |