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

Side by Side Diff: chrome/browser/browser_focus_uitest.cc

Issue 10795090: Move ExecuteJavaScript functions from ui_test_utils.h to browser_test_utils.h so they can be reused… (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Created 8 years, 5 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 | Annotate | Revision Log
OLDNEW
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 "build/build_config.h" 5 #include "build/build_config.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/file_util.h" 8 #include "base/file_util.h"
9 #include "base/format_macros.h" 9 #include "base/format_macros.h"
10 #include "base/message_loop.h" 10 #include "base/message_loop.h"
(...skipping 14 matching lines...) Expand all
25 #include "chrome/common/url_constants.h" 25 #include "chrome/common/url_constants.h"
26 #include "chrome/test/base/in_process_browser_test.h" 26 #include "chrome/test/base/in_process_browser_test.h"
27 #include "chrome/test/base/ui_test_utils.h" 27 #include "chrome/test/base/ui_test_utils.h"
28 #include "content/public/browser/interstitial_page.h" 28 #include "content/public/browser/interstitial_page.h"
29 #include "content/public/browser/interstitial_page_delegate.h" 29 #include "content/public/browser/interstitial_page_delegate.h"
30 #include "content/public/browser/notification_service.h" 30 #include "content/public/browser/notification_service.h"
31 #include "content/public/browser/render_view_host.h" 31 #include "content/public/browser/render_view_host.h"
32 #include "content/public/browser/render_widget_host_view.h" 32 #include "content/public/browser/render_widget_host_view.h"
33 #include "content/public/browser/web_contents.h" 33 #include "content/public/browser/web_contents.h"
34 #include "content/public/browser/web_contents_view.h" 34 #include "content/public/browser/web_contents_view.h"
35 #include "content/public/test/browser_test_utils.h"
35 #include "net/test/test_server.h" 36 #include "net/test/test_server.h"
36 37
37 #if defined(TOOLKIT_VIEWS) || defined(OS_WIN) 38 #if defined(TOOLKIT_VIEWS) || defined(OS_WIN)
38 #include "ui/views/focus/focus_manager.h" 39 #include "ui/views/focus/focus_manager.h"
39 #include "ui/views/view.h" 40 #include "ui/views/view.h"
40 #endif 41 #endif
41 42
42 #if defined(TOOLKIT_VIEWS) 43 #if defined(TOOLKIT_VIEWS)
43 #include "chrome/browser/ui/views/frame/browser_view.h" 44 #include "chrome/browser/ui/views/frame/browser_view.h"
44 #endif 45 #endif
(...skipping 411 matching lines...) Expand 10 before | Expand all | Expand 10 after
456 focused_browser = browser2; 457 focused_browser = browser2;
457 unfocused_browser = browser(); 458 unfocused_browser = browser();
458 #endif 459 #endif
459 460
460 GURL steal_focus_url = test_server()->GetURL(kStealFocusPage); 461 GURL steal_focus_url = test_server()->GetURL(kStealFocusPage);
461 ui_test_utils::NavigateToURL(unfocused_browser, steal_focus_url); 462 ui_test_utils::NavigateToURL(unfocused_browser, steal_focus_url);
462 463
463 // Activate the first browser. 464 // Activate the first browser.
464 focused_browser->window()->Activate(); 465 focused_browser->window()->Activate();
465 466
466 ASSERT_TRUE(ui_test_utils::ExecuteJavaScript( 467 ASSERT_TRUE(content::ExecuteJavaScript(
467 chrome::GetActiveWebContents(unfocused_browser)->GetRenderViewHost(), L"", 468 chrome::GetActiveWebContents(unfocused_browser)->GetRenderViewHost(), L"",
468 L"stealFocus();")); 469 L"stealFocus();"));
469 470
470 // Make sure the first browser is still active. 471 // Make sure the first browser is still active.
471 EXPECT_TRUE(focused_browser->window()->IsActive()); 472 EXPECT_TRUE(focused_browser->window()->IsActive());
472 } 473 }
473 474
474 // Page cannot steal focus when focus is on location bar. 475 // Page cannot steal focus when focus is on location bar.
475 IN_PROC_BROWSER_TEST_F(BrowserFocusTest, LocationBarLockFocus) { 476 IN_PROC_BROWSER_TEST_F(BrowserFocusTest, LocationBarLockFocus) {
476 ASSERT_TRUE(ui_test_utils::BringBrowserWindowToFront(browser())); 477 ASSERT_TRUE(ui_test_utils::BringBrowserWindowToFront(browser()));
477 ASSERT_TRUE(test_server()->Start()); 478 ASSERT_TRUE(test_server()->Start());
478 479
479 // Open the page that steals focus. 480 // Open the page that steals focus.
480 GURL url = test_server()->GetURL(kStealFocusPage); 481 GURL url = test_server()->GetURL(kStealFocusPage);
481 ui_test_utils::NavigateToURL(browser(), url); 482 ui_test_utils::NavigateToURL(browser(), url);
482 483
483 chrome::FocusLocationBar(browser()); 484 chrome::FocusLocationBar(browser());
484 485
485 ASSERT_TRUE(ui_test_utils::ExecuteJavaScript( 486 ASSERT_TRUE(content::ExecuteJavaScript(
486 chrome::GetActiveWebContents(browser())->GetRenderViewHost(), L"", 487 chrome::GetActiveWebContents(browser())->GetRenderViewHost(), L"",
487 L"stealFocus();")); 488 L"stealFocus();"));
488 489
489 // Make sure the location bar is still focused. 490 // Make sure the location bar is still focused.
490 ASSERT_TRUE(IsViewFocused(location_bar_focus_view_id_)); 491 ASSERT_TRUE(IsViewFocused(location_bar_focus_view_id_));
491 } 492 }
492 493
493 // Focus traversal on a regular page. 494 // Focus traversal on a regular page.
494 // Note that this test relies on a notification from the renderer that the 495 // Note that this test relies on a notification from the renderer that the
495 // focus has changed in the page. The notification in the renderer may change 496 // focus has changed in the page. The notification in the renderer may change
(...skipping 25 matching lines...) Expand all
521 522
522 // Move the caret to the end, otherwise the next Tab key may not move focus. 523 // Move the caret to the end, otherwise the next Tab key may not move focus.
523 ASSERT_TRUE(ui_test_utils::SendKeyPressSync( 524 ASSERT_TRUE(ui_test_utils::SendKeyPressSync(
524 browser(), ui::VKEY_END, false, false, false, false)); 525 browser(), ui::VKEY_END, false, false, false, false));
525 526
526 // Now let's press tab to move the focus. 527 // Now let's press tab to move the focus.
527 for (size_t j = 0; j < arraysize(kExpElementIDs); ++j) { 528 for (size_t j = 0; j < arraysize(kExpElementIDs); ++j) {
528 SCOPED_TRACE(base::StringPrintf("inner loop %" PRIuS, j)); 529 SCOPED_TRACE(base::StringPrintf("inner loop %" PRIuS, j));
529 // Let's make sure the focus is on the expected element in the page. 530 // Let's make sure the focus is on the expected element in the page.
530 std::string actual; 531 std::string actual;
531 ASSERT_TRUE(ui_test_utils::ExecuteJavaScriptAndExtractString( 532 ASSERT_TRUE(content::ExecuteJavaScriptAndExtractString(
532 chrome::GetActiveWebContents(browser())->GetRenderViewHost(), 533 chrome::GetActiveWebContents(browser())->GetRenderViewHost(),
533 L"", 534 L"",
534 L"window.domAutomationController.send(getFocusedElement());", 535 L"window.domAutomationController.send(getFocusedElement());",
535 &actual)); 536 &actual));
536 ASSERT_STREQ(kExpElementIDs[j], actual.c_str()); 537 ASSERT_STREQ(kExpElementIDs[j], actual.c_str());
537 538
538 if (j < arraysize(kExpElementIDs) - 1) { 539 if (j < arraysize(kExpElementIDs) - 1) {
539 // If the next element is the kTextElementID, we expect to be 540 // If the next element is the kTextElementID, we expect to be
540 // notified we have switched to an editable node. 541 // notified we have switched to an editable node.
541 bool is_editable_node = 542 bool is_editable_node =
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
594 } else { 595 } else {
595 // On the last tab key press, the focus returns to the browser. 596 // On the last tab key press, the focus returns to the browser.
596 ASSERT_TRUE(ui_test_utils::SendKeyPressAndWait( 597 ASSERT_TRUE(ui_test_utils::SendKeyPressAndWait(
597 browser(), ui::VKEY_TAB, false, true, false, false, 598 browser(), ui::VKEY_TAB, false, true, false, false,
598 chrome::NOTIFICATION_FOCUS_RETURNED_TO_BROWSER, 599 chrome::NOTIFICATION_FOCUS_RETURNED_TO_BROWSER,
599 content::NotificationSource(content::Source<Browser>(browser())))); 600 content::NotificationSource(content::Source<Browser>(browser()))));
600 } 601 }
601 602
602 // Let's make sure the focus is on the expected element in the page. 603 // Let's make sure the focus is on the expected element in the page.
603 std::string actual; 604 std::string actual;
604 ASSERT_TRUE(ui_test_utils::ExecuteJavaScriptAndExtractString( 605 ASSERT_TRUE(content::ExecuteJavaScriptAndExtractString(
605 chrome::GetActiveWebContents(browser())->GetRenderViewHost(), 606 chrome::GetActiveWebContents(browser())->GetRenderViewHost(),
606 L"", 607 L"",
607 L"window.domAutomationController.send(getFocusedElement());", 608 L"window.domAutomationController.send(getFocusedElement());",
608 &actual)); 609 &actual));
609 ASSERT_STREQ(next_element, actual.c_str()); 610 ASSERT_STREQ(next_element, actual.c_str());
610 } 611 }
611 612
612 // At this point the renderer has sent us a message asking to advance the 613 // At this point the renderer has sent us a message asking to advance the
613 // focus (as the end of the focus loop was reached in the renderer). 614 // focus (as the end of the focus loop was reached in the renderer).
614 // We need to run the message loop to process it. 615 // We need to run the message loop to process it.
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
653 ASSERT_TRUE(IsViewFocused(location_bar_focus_view_id_)); 654 ASSERT_TRUE(IsViewFocused(location_bar_focus_view_id_));
654 655
655 // Move the caret to the end, otherwise the next Tab key may not move focus. 656 // Move the caret to the end, otherwise the next Tab key may not move focus.
656 ASSERT_TRUE(ui_test_utils::SendKeyPressSync( 657 ASSERT_TRUE(ui_test_utils::SendKeyPressSync(
657 browser(), ui::VKEY_END, false, false, false, false)); 658 browser(), ui::VKEY_END, false, false, false, false));
658 659
659 // Now let's press tab to move the focus. 660 // Now let's press tab to move the focus.
660 for (size_t j = 0; j < 7; ++j) { 661 for (size_t j = 0; j < 7; ++j) {
661 // Let's make sure the focus is on the expected element in the page. 662 // Let's make sure the focus is on the expected element in the page.
662 std::string actual; 663 std::string actual;
663 ASSERT_TRUE(ui_test_utils::ExecuteJavaScriptAndExtractString( 664 ASSERT_TRUE(content::ExecuteJavaScriptAndExtractString(
664 interstitial_page->render_view_host(), L"", 665 interstitial_page->render_view_host(), L"",
665 L"window.domAutomationController.send(getFocusedElement());", 666 L"window.domAutomationController.send(getFocusedElement());",
666 &actual)); 667 &actual));
667 ASSERT_STREQ(kExpElementIDs[j], actual.c_str()); 668 ASSERT_STREQ(kExpElementIDs[j], actual.c_str());
668 669
669 int notification_type; 670 int notification_type;
670 content::NotificationSource notification_source = 671 content::NotificationSource notification_source =
671 content::NotificationService::AllSources(); 672 content::NotificationService::AllSources();
672 if (j < arraysize(kExpElementIDs) - 1) { 673 if (j < arraysize(kExpElementIDs) - 1) {
673 notification_type = content::NOTIFICATION_FOCUS_CHANGED_IN_PAGE; 674 notification_type = content::NOTIFICATION_FOCUS_CHANGED_IN_PAGE;
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
713 notification_type = chrome::NOTIFICATION_FOCUS_RETURNED_TO_BROWSER; 714 notification_type = chrome::NOTIFICATION_FOCUS_RETURNED_TO_BROWSER;
714 notification_source = content::Source<Browser>(browser()); 715 notification_source = content::Source<Browser>(browser());
715 } 716 }
716 717
717 ASSERT_TRUE(ui_test_utils::SendKeyPressAndWait( 718 ASSERT_TRUE(ui_test_utils::SendKeyPressAndWait(
718 browser(), ui::VKEY_TAB, false, true, false, false, 719 browser(), ui::VKEY_TAB, false, true, false, false,
719 notification_type, notification_source)); 720 notification_type, notification_source));
720 721
721 // Let's make sure the focus is on the expected element in the page. 722 // Let's make sure the focus is on the expected element in the page.
722 std::string actual; 723 std::string actual;
723 ASSERT_TRUE(ui_test_utils::ExecuteJavaScriptAndExtractString( 724 ASSERT_TRUE(content::ExecuteJavaScriptAndExtractString(
724 interstitial_page->render_view_host(), L"", 725 interstitial_page->render_view_host(), L"",
725 L"window.domAutomationController.send(getFocusedElement());", 726 L"window.domAutomationController.send(getFocusedElement());",
726 &actual)); 727 &actual));
727 ASSERT_STREQ(kExpElementIDs[6 - j], actual.c_str()); 728 ASSERT_STREQ(kExpElementIDs[6 - j], actual.c_str());
728 } 729 }
729 730
730 // At this point the renderer has sent us a message asking to advance the 731 // At this point the renderer has sent us a message asking to advance the
731 // focus (as the end of the focus loop was reached in the renderer). 732 // focus (as the end of the focus loop was reached in the renderer).
732 // We need to run the message loop to process it. 733 // We need to run the message loop to process it.
733 ui_test_utils::RunAllPendingInMessageLoop(); 734 ui_test_utils::RunAllPendingInMessageLoop();
(...skipping 190 matching lines...) Expand 10 before | Expand all | Expand 10 after
924 chrome::Reload(browser(), CURRENT_TAB); 925 chrome::Reload(browser(), CURRENT_TAB);
925 observer.Wait(); 926 observer.Wait();
926 } 927 }
927 928
928 // Focus should now be on the tab contents. 929 // Focus should now be on the tab contents.
929 chrome::ShowDownloads(browser()); 930 chrome::ShowDownloads(browser());
930 ASSERT_TRUE(IsViewFocused(VIEW_ID_TAB_CONTAINER)); 931 ASSERT_TRUE(IsViewFocused(VIEW_ID_TAB_CONTAINER));
931 } 932 }
932 933
933 } // namespace 934 } // namespace
OLDNEW
« no previous file with comments | « chrome/browser/automation/automation_tab_helper_browsertest.cc ('k') | chrome/browser/browser_keyevents_browsertest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698