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/base/ui_test_utils.h" | 5 #include "chrome/test/base/ui_test_utils.h" |
6 | 6 |
7 #if defined(OS_WIN) | 7 #if defined(OS_WIN) |
8 #include <windows.h> | 8 #include <windows.h> |
9 #endif | 9 #endif |
10 | 10 |
(...skipping 22 matching lines...) Expand all Loading... |
33 #include "chrome/browser/profiles/profile.h" | 33 #include "chrome/browser/profiles/profile.h" |
34 #include "chrome/browser/search_engines/template_url_service.h" | 34 #include "chrome/browser/search_engines/template_url_service.h" |
35 #include "chrome/browser/search_engines/template_url_service_test_util.h" | 35 #include "chrome/browser/search_engines/template_url_service_test_util.h" |
36 #include "chrome/browser/tab_contents/thumbnail_generator.h" | 36 #include "chrome/browser/tab_contents/thumbnail_generator.h" |
37 #include "chrome/browser/ui/app_modal_dialogs/app_modal_dialog.h" | 37 #include "chrome/browser/ui/app_modal_dialogs/app_modal_dialog.h" |
38 #include "chrome/browser/ui/browser.h" | 38 #include "chrome/browser/ui/browser.h" |
39 #include "chrome/browser/ui/browser_commands.h" | 39 #include "chrome/browser/ui/browser_commands.h" |
40 #include "chrome/browser/ui/browser_finder.h" | 40 #include "chrome/browser/ui/browser_finder.h" |
41 #include "chrome/browser/ui/browser_list.h" | 41 #include "chrome/browser/ui/browser_list.h" |
42 #include "chrome/browser/ui/browser_navigator.h" | 42 #include "chrome/browser/ui/browser_navigator.h" |
| 43 #include "chrome/browser/ui/browser_tabstrip.h" |
43 #include "chrome/browser/ui/browser_window.h" | 44 #include "chrome/browser/ui/browser_window.h" |
44 #include "chrome/browser/ui/find_bar/find_notification_details.h" | 45 #include "chrome/browser/ui/find_bar/find_notification_details.h" |
45 #include "chrome/browser/ui/find_bar/find_tab_helper.h" | 46 #include "chrome/browser/ui/find_bar/find_tab_helper.h" |
46 #include "chrome/browser/ui/tab_contents/tab_contents.h" | 47 #include "chrome/browser/ui/tab_contents/tab_contents.h" |
47 #include "chrome/common/chrome_notification_types.h" | 48 #include "chrome/common/chrome_notification_types.h" |
48 #include "chrome/common/chrome_paths.h" | 49 #include "chrome/common/chrome_paths.h" |
49 #include "chrome/common/extensions/extension_action.h" | 50 #include "chrome/common/extensions/extension_action.h" |
50 #include "chrome/test/automation/javascript_execution_controller.h" | 51 #include "chrome/test/automation/javascript_execution_controller.h" |
51 #include "chrome/test/base/bookmark_load_observer.h" | 52 #include "chrome/test/base/bookmark_load_observer.h" |
52 #include "content/public/browser/dom_operation_notification_details.h" | 53 #include "content/public/browser/dom_operation_notification_details.h" |
(...skipping 286 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
339 } | 340 } |
340 | 341 |
341 base::RunLoop run_loop; | 342 base::RunLoop run_loop; |
342 content::BrowserThread::PostTask(thread_id, FROM_HERE, | 343 content::BrowserThread::PostTask(thread_id, FROM_HERE, |
343 base::Bind(&RunAllPendingMessageAndSendQuit, current_thread_id, | 344 base::Bind(&RunAllPendingMessageAndSendQuit, current_thread_id, |
344 run_loop.QuitClosure())); | 345 run_loop.QuitClosure())); |
345 ui_test_utils::RunThisRunLoop(&run_loop); | 346 ui_test_utils::RunThisRunLoop(&run_loop); |
346 } | 347 } |
347 | 348 |
348 bool GetCurrentTabTitle(const Browser* browser, string16* title) { | 349 bool GetCurrentTabTitle(const Browser* browser, string16* title) { |
349 WebContents* web_contents = browser->GetActiveWebContents(); | 350 WebContents* web_contents = chrome::GetActiveWebContents(browser); |
350 if (!web_contents) | 351 if (!web_contents) |
351 return false; | 352 return false; |
352 NavigationEntry* last_entry = web_contents->GetController().GetActiveEntry(); | 353 NavigationEntry* last_entry = web_contents->GetController().GetActiveEntry(); |
353 if (!last_entry) | 354 if (!last_entry) |
354 return false; | 355 return false; |
355 title->assign(last_entry->GetTitleForDisplay("")); | 356 title->assign(last_entry->GetTitleForDisplay("")); |
356 return true; | 357 return true; |
357 } | 358 } |
358 | 359 |
359 void WaitForNavigations(NavigationController* controller, | 360 void WaitForNavigations(NavigationController* controller, |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
393 // The new browser should never be in |excluded_browsers|. | 394 // The new browser should never be in |excluded_browsers|. |
394 DCHECK(!ContainsKey(excluded_browsers, new_browser)); | 395 DCHECK(!ContainsKey(excluded_browsers, new_browser)); |
395 } | 396 } |
396 return new_browser; | 397 return new_browser; |
397 } | 398 } |
398 | 399 |
399 void OpenURLOffTheRecord(Profile* profile, const GURL& url) { | 400 void OpenURLOffTheRecord(Profile* profile, const GURL& url) { |
400 chrome::OpenURLOffTheRecord(profile, url); | 401 chrome::OpenURLOffTheRecord(profile, url); |
401 Browser* browser = browser::FindTabbedBrowser( | 402 Browser* browser = browser::FindTabbedBrowser( |
402 profile->GetOffTheRecordProfile(), false); | 403 profile->GetOffTheRecordProfile(), false); |
403 WaitForNavigations(&browser->GetActiveWebContents()->GetController(), 1); | 404 WaitForNavigations(&chrome::GetActiveWebContents(browser)->GetController(), |
| 405 1); |
404 } | 406 } |
405 | 407 |
406 void NavigateToURL(browser::NavigateParams* params) { | 408 void NavigateToURL(browser::NavigateParams* params) { |
407 content::TestNavigationObserver observer( | 409 content::TestNavigationObserver observer( |
408 content::NotificationService::AllSources(), NULL, 1); | 410 content::NotificationService::AllSources(), NULL, 1); |
409 browser::Navigate(params); | 411 browser::Navigate(params); |
410 base::RunLoop run_loop; | 412 base::RunLoop run_loop; |
411 observer.WaitForObservation( | 413 observer.WaitForObservation( |
412 base::Bind(&ui_test_utils::RunThisRunLoop, base::Unretained(&run_loop)), | 414 base::Bind(&ui_test_utils::RunThisRunLoop, base::Unretained(&run_loop)), |
413 ui_test_utils::GetQuitTaskForRunLoop(&run_loop)); | 415 ui_test_utils::GetQuitTaskForRunLoop(&run_loop)); |
414 } | 416 } |
415 | 417 |
416 void NavigateToURL(Browser* browser, const GURL& url) { | 418 void NavigateToURL(Browser* browser, const GURL& url) { |
417 NavigateToURLWithDisposition(browser, url, CURRENT_TAB, | 419 NavigateToURLWithDisposition(browser, url, CURRENT_TAB, |
418 BROWSER_TEST_WAIT_FOR_NAVIGATION); | 420 BROWSER_TEST_WAIT_FOR_NAVIGATION); |
419 } | 421 } |
420 | 422 |
421 // Navigates the specified tab (via |disposition|) of |browser| to |url|, | 423 // Navigates the specified tab (via |disposition|) of |browser| to |url|, |
422 // blocking until the |number_of_navigations| specified complete. | 424 // blocking until the |number_of_navigations| specified complete. |
423 // |disposition| indicates what tab the download occurs in, and | 425 // |disposition| indicates what tab the download occurs in, and |
424 // |browser_test_flags| controls what to wait for before continuing. | 426 // |browser_test_flags| controls what to wait for before continuing. |
425 static void NavigateToURLWithDispositionBlockUntilNavigationsComplete( | 427 static void NavigateToURLWithDispositionBlockUntilNavigationsComplete( |
426 Browser* browser, | 428 Browser* browser, |
427 const GURL& url, | 429 const GURL& url, |
428 int number_of_navigations, | 430 int number_of_navigations, |
429 WindowOpenDisposition disposition, | 431 WindowOpenDisposition disposition, |
430 int browser_test_flags) { | 432 int browser_test_flags) { |
431 if (disposition == CURRENT_TAB && browser->GetActiveWebContents()) | 433 if (disposition == CURRENT_TAB && chrome::GetActiveWebContents(browser)) |
432 WaitForLoadStop(browser->GetActiveWebContents()); | 434 WaitForLoadStop(chrome::GetActiveWebContents(browser)); |
433 NavigationController* controller = | 435 NavigationController* controller = |
434 browser->GetActiveWebContents() ? | 436 chrome::GetActiveWebContents(browser) ? |
435 &browser->GetActiveWebContents()->GetController() : NULL; | 437 &chrome::GetActiveWebContents(browser)->GetController() : NULL; |
436 content::TestNavigationObserver same_tab_observer( | 438 content::TestNavigationObserver same_tab_observer( |
437 content::Source<NavigationController>(controller), | 439 content::Source<NavigationController>(controller), |
438 NULL, | 440 NULL, |
439 number_of_navigations); | 441 number_of_navigations); |
440 | 442 |
441 std::set<Browser*> initial_browsers; | 443 std::set<Browser*> initial_browsers; |
442 for (std::vector<Browser*>::const_iterator iter = BrowserList::begin(); | 444 for (std::vector<Browser*>::const_iterator iter = BrowserList::begin(); |
443 iter != BrowserList::end(); | 445 iter != BrowserList::end(); |
444 ++iter) { | 446 ++iter) { |
445 initial_browsers.insert(*iter); | 447 initial_browsers.insert(*iter); |
(...skipping 15 matching lines...) Expand all Loading... |
461 tab_added_observer.Wait(); | 463 tab_added_observer.Wait(); |
462 if (browser_test_flags & BROWSER_TEST_WAIT_FOR_AUTH) | 464 if (browser_test_flags & BROWSER_TEST_WAIT_FOR_AUTH) |
463 auth_observer.Wait(); | 465 auth_observer.Wait(); |
464 if (!(browser_test_flags & BROWSER_TEST_WAIT_FOR_NAVIGATION)) { | 466 if (!(browser_test_flags & BROWSER_TEST_WAIT_FOR_NAVIGATION)) { |
465 // Some other flag caused the wait prior to this. | 467 // Some other flag caused the wait prior to this. |
466 return; | 468 return; |
467 } | 469 } |
468 WebContents* web_contents = NULL; | 470 WebContents* web_contents = NULL; |
469 if (disposition == NEW_BACKGROUND_TAB) { | 471 if (disposition == NEW_BACKGROUND_TAB) { |
470 // We've opened up a new tab, but not selected it. | 472 // We've opened up a new tab, but not selected it. |
471 web_contents = browser->GetWebContentsAt(browser->active_index() + 1); | 473 web_contents = |
| 474 chrome::GetWebContentsAt(browser, browser->active_index() + 1); |
472 EXPECT_TRUE(web_contents != NULL) | 475 EXPECT_TRUE(web_contents != NULL) |
473 << " Unable to wait for navigation to \"" << url.spec() | 476 << " Unable to wait for navigation to \"" << url.spec() |
474 << "\" because the new tab is not available yet"; | 477 << "\" because the new tab is not available yet"; |
475 return; | 478 return; |
476 } else if ((disposition == CURRENT_TAB) || | 479 } else if ((disposition == CURRENT_TAB) || |
477 (disposition == NEW_FOREGROUND_TAB) || | 480 (disposition == NEW_FOREGROUND_TAB) || |
478 (disposition == SINGLETON_TAB)) { | 481 (disposition == SINGLETON_TAB)) { |
479 // The currently selected tab is the right one. | 482 // The currently selected tab is the right one. |
480 web_contents = browser->GetActiveWebContents(); | 483 web_contents = chrome::GetActiveWebContents(browser); |
481 } | 484 } |
482 if (disposition == CURRENT_TAB) { | 485 if (disposition == CURRENT_TAB) { |
483 base::RunLoop run_loop; | 486 base::RunLoop run_loop; |
484 same_tab_observer.WaitForObservation( | 487 same_tab_observer.WaitForObservation( |
485 base::Bind(&ui_test_utils::RunThisRunLoop, base::Unretained(&run_loop)), | 488 base::Bind(&ui_test_utils::RunThisRunLoop, base::Unretained(&run_loop)), |
486 ui_test_utils::GetQuitTaskForRunLoop(&run_loop)); | 489 ui_test_utils::GetQuitTaskForRunLoop(&run_loop)); |
487 return; | 490 return; |
488 } else if (web_contents) { | 491 } else if (web_contents) { |
489 NavigationController* controller = &web_contents->GetController(); | 492 NavigationController* controller = &web_contents->GetController(); |
490 WaitForNavigations(controller, number_of_navigations); | 493 WaitForNavigations(controller, number_of_navigations); |
(...skipping 23 matching lines...) Expand all Loading... |
514 browser, | 517 browser, |
515 url, | 518 url, |
516 number_of_navigations, | 519 number_of_navigations, |
517 CURRENT_TAB, | 520 CURRENT_TAB, |
518 BROWSER_TEST_WAIT_FOR_NAVIGATION); | 521 BROWSER_TEST_WAIT_FOR_NAVIGATION); |
519 } | 522 } |
520 | 523 |
521 DOMElementProxyRef GetActiveDOMDocument(Browser* browser) { | 524 DOMElementProxyRef GetActiveDOMDocument(Browser* browser) { |
522 JavaScriptExecutionController* executor = | 525 JavaScriptExecutionController* executor = |
523 new InProcessJavaScriptExecutionController( | 526 new InProcessJavaScriptExecutionController( |
524 browser->GetActiveWebContents()->GetRenderViewHost()); | 527 chrome::GetActiveWebContents(browser)->GetRenderViewHost()); |
525 int element_handle; | 528 int element_handle; |
526 executor->ExecuteJavaScriptAndGetReturn("document;", &element_handle); | 529 executor->ExecuteJavaScriptAndGetReturn("document;", &element_handle); |
527 return executor->GetObjectProxy<DOMElementProxy>(element_handle); | 530 return executor->GetObjectProxy<DOMElementProxy>(element_handle); |
528 } | 531 } |
529 | 532 |
530 bool ExecuteJavaScript(RenderViewHost* render_view_host, | 533 bool ExecuteJavaScript(RenderViewHost* render_view_host, |
531 const std::wstring& frame_xpath, | 534 const std::wstring& frame_xpath, |
532 const std::wstring& original_script) { | 535 const std::wstring& original_script) { |
533 std::wstring script = | 536 std::wstring script = |
534 original_script + L";window.domAutomationController.send(0);"; | 537 original_script + L";window.domAutomationController.send(0);"; |
(...skipping 751 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1286 int state, | 1289 int state, |
1287 const base::Closure& followup) { | 1290 const base::Closure& followup) { |
1288 if (!followup.is_null()) | 1291 if (!followup.is_null()) |
1289 ui_controls::SendMouseEventsNotifyWhenDone(button, state, followup); | 1292 ui_controls::SendMouseEventsNotifyWhenDone(button, state, followup); |
1290 else | 1293 else |
1291 ui_controls::SendMouseEvents(button, state); | 1294 ui_controls::SendMouseEvents(button, state); |
1292 } | 1295 } |
1293 | 1296 |
1294 } // namespace internal | 1297 } // namespace internal |
1295 } // namespace ui_test_utils | 1298 } // namespace ui_test_utils |
OLD | NEW |