| OLD | NEW |
| 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 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 "base/keyboard_codes.h" |
| 5 #include "base/message_loop.h" | 6 #include "base/message_loop.h" |
| 6 #include "base/ref_counted.h" | 7 #include "base/ref_counted.h" |
| 7 #include "chrome/browser/automation/ui_controls.h" | 8 #include "chrome/browser/automation/ui_controls.h" |
| 8 #include "chrome/browser/browser.h" | 9 #include "chrome/browser/browser.h" |
| 9 #include "chrome/browser/renderer_host/render_widget_host_view.h" | 10 #include "chrome/browser/renderer_host/render_widget_host_view.h" |
| 10 #include "chrome/browser/tab_contents/interstitial_page.h" | 11 #include "chrome/browser/tab_contents/interstitial_page.h" |
| 11 #include "chrome/browser/view_ids.h" | 12 #include "chrome/browser/view_ids.h" |
| 12 #include "chrome/browser/views/frame/browser_view.h" | 13 #include "chrome/browser/views/frame/browser_view.h" |
| 13 #include "chrome/browser/views/location_bar_view.h" | 14 #include "chrome/browser/views/location_bar_view.h" |
| 14 #include "chrome/browser/views/tab_contents/tab_contents_container.h" | 15 #include "chrome/browser/views/tab_contents/tab_contents_container.h" |
| (...skipping 368 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 383 for (int j = 0; j < 7; ++j) { | 384 for (int j = 0; j < 7; ++j) { |
| 384 // Let's make sure the focus is on the expected element in the page. | 385 // Let's make sure the focus is on the expected element in the page. |
| 385 std::string actual; | 386 std::string actual; |
| 386 ASSERT_TRUE(ui_test_utils::ExecuteJavaScriptAndExtractString( | 387 ASSERT_TRUE(ui_test_utils::ExecuteJavaScriptAndExtractString( |
| 387 browser()->GetSelectedTabContents()->render_view_host(), | 388 browser()->GetSelectedTabContents()->render_view_host(), |
| 388 L"", | 389 L"", |
| 389 L"window.domAutomationController.send(getFocusedElement());", | 390 L"window.domAutomationController.send(getFocusedElement());", |
| 390 &actual)); | 391 &actual)); |
| 391 ASSERT_STREQ(kExpElementIDs[j], actual.c_str()); | 392 ASSERT_STREQ(kExpElementIDs[j], actual.c_str()); |
| 392 | 393 |
| 393 ui_controls::SendKeyPressNotifyWhenDone(L'\t', false, false, false, | 394 ui_controls::SendKeyPressNotifyWhenDone(NULL, base::VKEY_TAB, false, |
| 395 false, false, |
| 394 new MessageLoop::QuitTask()); | 396 new MessageLoop::QuitTask()); |
| 395 ui_test_utils::RunMessageLoop(); | 397 ui_test_utils::RunMessageLoop(); |
| 396 // Ideally, we wouldn't sleep here and instead would use the event | 398 // Ideally, we wouldn't sleep here and instead would use the event |
| 397 // processed ack notification from the renderer. I am reluctant to create | 399 // processed ack notification from the renderer. I am reluctant to create |
| 398 // a new notification/callback for that purpose just for this test. | 400 // a new notification/callback for that purpose just for this test. |
| 399 ::Sleep(kActionDelayMs); | 401 ::Sleep(kActionDelayMs); |
| 400 } | 402 } |
| 401 | 403 |
| 402 // At this point the renderer has sent us a message asking to advance the | 404 // At this point the renderer has sent us a message asking to advance the |
| 403 // focus (as the end of the focus loop was reached in the renderer). | 405 // focus (as the end of the focus loop was reached in the renderer). |
| 404 // We need to run the message loop to process it. | 406 // We need to run the message loop to process it. |
| 405 MessageLoop::current()->PostTask(FROM_HERE, new MessageLoop::QuitTask()); | 407 MessageLoop::current()->PostTask(FROM_HERE, new MessageLoop::QuitTask()); |
| 406 ui_test_utils::RunMessageLoop(); | 408 ui_test_utils::RunMessageLoop(); |
| 407 } | 409 } |
| 408 | 410 |
| 409 // Now let's try reverse focus traversal. | 411 // Now let's try reverse focus traversal. |
| 410 for (int i = 0; i < 3; ++i) { | 412 for (int i = 0; i < 3; ++i) { |
| 411 // Location bar should be focused. | 413 // Location bar should be focused. |
| 412 EXPECT_EQ(location_bar, focus_manager->GetFocusedView()); | 414 EXPECT_EQ(location_bar, focus_manager->GetFocusedView()); |
| 413 | 415 |
| 414 // Now let's press shift-tab to move the focus in reverse. | 416 // Now let's press shift-tab to move the focus in reverse. |
| 415 for (int j = 0; j < 7; ++j) { | 417 for (int j = 0; j < 7; ++j) { |
| 416 ui_controls::SendKeyPressNotifyWhenDone(L'\t', false, true, false, | 418 ui_controls::SendKeyPressNotifyWhenDone(NULL, base::VKEY_TAB, false, |
| 419 true, false, |
| 417 new MessageLoop::QuitTask()); | 420 new MessageLoop::QuitTask()); |
| 418 ui_test_utils::RunMessageLoop(); | 421 ui_test_utils::RunMessageLoop(); |
| 419 ::Sleep(kActionDelayMs); | 422 ::Sleep(kActionDelayMs); |
| 420 | 423 |
| 421 // Let's make sure the focus is on the expected element in the page. | 424 // Let's make sure the focus is on the expected element in the page. |
| 422 std::string actual; | 425 std::string actual; |
| 423 ASSERT_TRUE(ui_test_utils::ExecuteJavaScriptAndExtractString( | 426 ASSERT_TRUE(ui_test_utils::ExecuteJavaScriptAndExtractString( |
| 424 browser()->GetSelectedTabContents()->render_view_host(), | 427 browser()->GetSelectedTabContents()->render_view_host(), |
| 425 L"", | 428 L"", |
| 426 L"window.domAutomationController.send(getFocusedElement());", | 429 L"window.domAutomationController.send(getFocusedElement());", |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 483 for (int i = 0; i < 2; ++i) { | 486 for (int i = 0; i < 2; ++i) { |
| 484 // Location bar should be focused. | 487 // Location bar should be focused. |
| 485 EXPECT_EQ(location_bar, focus_manager->GetFocusedView()); | 488 EXPECT_EQ(location_bar, focus_manager->GetFocusedView()); |
| 486 | 489 |
| 487 // Now let's press tab to move the focus. | 490 // Now let's press tab to move the focus. |
| 488 for (int j = 0; j < 7; ++j) { | 491 for (int j = 0; j < 7; ++j) { |
| 489 // Let's make sure the focus is on the expected element in the page. | 492 // Let's make sure the focus is on the expected element in the page. |
| 490 std::string actual = interstitial_page->GetFocusedElement(); | 493 std::string actual = interstitial_page->GetFocusedElement(); |
| 491 ASSERT_STREQ(kExpElementIDs[j], actual.c_str()); | 494 ASSERT_STREQ(kExpElementIDs[j], actual.c_str()); |
| 492 | 495 |
| 493 ui_controls::SendKeyPressNotifyWhenDone(L'\t', false, false, false, | 496 ui_controls::SendKeyPressNotifyWhenDone(NULL, base::VKEY_TAB, false, |
| 497 false, false, |
| 494 new MessageLoop::QuitTask()); | 498 new MessageLoop::QuitTask()); |
| 495 ui_test_utils::RunMessageLoop(); | 499 ui_test_utils::RunMessageLoop(); |
| 496 // Ideally, we wouldn't sleep here and instead would use the event | 500 // Ideally, we wouldn't sleep here and instead would use the event |
| 497 // processed ack notification from the renderer. I am reluctant to create | 501 // processed ack notification from the renderer. I am reluctant to create |
| 498 // a new notification/callback for that purpose just for this test. | 502 // a new notification/callback for that purpose just for this test. |
| 499 ::Sleep(kActionDelayMs); | 503 ::Sleep(kActionDelayMs); |
| 500 } | 504 } |
| 501 | 505 |
| 502 // At this point the renderer has sent us a message asking to advance the | 506 // At this point the renderer has sent us a message asking to advance the |
| 503 // focus (as the end of the focus loop was reached in the renderer). | 507 // focus (as the end of the focus loop was reached in the renderer). |
| 504 // We need to run the message loop to process it. | 508 // We need to run the message loop to process it. |
| 505 MessageLoop::current()->PostTask(FROM_HERE, new MessageLoop::QuitTask()); | 509 MessageLoop::current()->PostTask(FROM_HERE, new MessageLoop::QuitTask()); |
| 506 ui_test_utils::RunMessageLoop(); | 510 ui_test_utils::RunMessageLoop(); |
| 507 } | 511 } |
| 508 | 512 |
| 509 // Now let's try reverse focus traversal. | 513 // Now let's try reverse focus traversal. |
| 510 for (int i = 0; i < 2; ++i) { | 514 for (int i = 0; i < 2; ++i) { |
| 511 // Location bar should be focused. | 515 // Location bar should be focused. |
| 512 EXPECT_EQ(location_bar, focus_manager->GetFocusedView()); | 516 EXPECT_EQ(location_bar, focus_manager->GetFocusedView()); |
| 513 | 517 |
| 514 // Now let's press shift-tab to move the focus in reverse. | 518 // Now let's press shift-tab to move the focus in reverse. |
| 515 for (int j = 0; j < 7; ++j) { | 519 for (int j = 0; j < 7; ++j) { |
| 516 ui_controls::SendKeyPressNotifyWhenDone(L'\t', false, true, false, | 520 ui_controls::SendKeyPressNotifyWhenDone(NULL, base::VKEY_TAB, false, |
| 521 true, false, |
| 517 new MessageLoop::QuitTask()); | 522 new MessageLoop::QuitTask()); |
| 518 ui_test_utils::RunMessageLoop(); | 523 ui_test_utils::RunMessageLoop(); |
| 519 ::Sleep(kActionDelayMs); | 524 ::Sleep(kActionDelayMs); |
| 520 | 525 |
| 521 // Let's make sure the focus is on the expected element in the page. | 526 // Let's make sure the focus is on the expected element in the page. |
| 522 std::string actual = interstitial_page->GetFocusedElement(); | 527 std::string actual = interstitial_page->GetFocusedElement(); |
| 523 ASSERT_STREQ(kExpElementIDs[6 - j], actual.c_str()); | 528 ASSERT_STREQ(kExpElementIDs[6 - j], actual.c_str()); |
| 524 } | 529 } |
| 525 | 530 |
| 526 // At this point the renderer has sent us a message asking to advance the | 531 // At this point the renderer has sent us a message asking to advance the |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 584 GURL url = server->TestServerPageW(kTypicalPage); | 589 GURL url = server->TestServerPageW(kTypicalPage); |
| 585 ui_test_utils::NavigateToURL(browser(), url); | 590 ui_test_utils::NavigateToURL(browser(), url); |
| 586 | 591 |
| 587 HWND hwnd = reinterpret_cast<HWND>(browser()->window()->GetNativeHandle()); | 592 HWND hwnd = reinterpret_cast<HWND>(browser()->window()->GetNativeHandle()); |
| 588 BrowserView* browser_view = BrowserView::GetBrowserViewForNativeWindow(hwnd); | 593 BrowserView* browser_view = BrowserView::GetBrowserViewForNativeWindow(hwnd); |
| 589 views::FocusManager* focus_manager = | 594 views::FocusManager* focus_manager = |
| 590 views::FocusManager::GetFocusManagerForNativeView(hwnd); | 595 views::FocusManager::GetFocusManagerForNativeView(hwnd); |
| 591 LocationBarView* location_bar = browser_view->GetLocationBarView(); | 596 LocationBarView* location_bar = browser_view->GetLocationBarView(); |
| 592 | 597 |
| 593 // Press Ctrl+F, which will make the Find box open and request focus. | 598 // Press Ctrl+F, which will make the Find box open and request focus. |
| 594 static const int VK_F = 0x46; | 599 ui_controls::SendKeyPressNotifyWhenDone(NULL, base::VKEY_F, true, |
| 595 ui_controls::SendKeyPressNotifyWhenDone(L'F', true, false, false, | 600 false, false, |
| 596 new MessageLoop::QuitTask()); | 601 new MessageLoop::QuitTask()); |
| 597 ui_test_utils::RunMessageLoop(); | 602 ui_test_utils::RunMessageLoop(); |
| 598 | 603 |
| 599 // Ideally, we wouldn't sleep here and instead would intercept the | 604 // Ideally, we wouldn't sleep here and instead would intercept the |
| 600 // RenderViewHostDelegate::HandleKeyboardEvent() callback. To do that, we | 605 // RenderViewHostDelegate::HandleKeyboardEvent() callback. To do that, we |
| 601 // could create a RenderViewHostDelegate wrapper and hook-it up by either: | 606 // could create a RenderViewHostDelegate wrapper and hook-it up by either: |
| 602 // - creating a factory used to create the delegate | 607 // - creating a factory used to create the delegate |
| 603 // - making the test a private and overwriting the delegate member directly. | 608 // - making the test a private and overwriting the delegate member directly. |
| 604 ::Sleep(kActionDelayMs); | 609 ::Sleep(kActionDelayMs); |
| 605 MessageLoop::current()->PostTask(FROM_HERE, new MessageLoop::QuitTask()); | 610 MessageLoop::current()->PostTask(FROM_HERE, new MessageLoop::QuitTask()); |
| 606 ui_test_utils::RunMessageLoop(); | 611 ui_test_utils::RunMessageLoop(); |
| 607 | 612 |
| 608 views::View* focused_view = focus_manager->GetFocusedView(); | 613 views::View* focused_view = focus_manager->GetFocusedView(); |
| 609 ASSERT_TRUE(focused_view != NULL); | 614 ASSERT_TRUE(focused_view != NULL); |
| 610 EXPECT_EQ(VIEW_ID_FIND_IN_PAGE_TEXT_FIELD, focused_view->GetID()); | 615 EXPECT_EQ(VIEW_ID_FIND_IN_PAGE_TEXT_FIELD, focused_view->GetID()); |
| 611 | 616 |
| 612 // Click on the location bar. | 617 // Click on the location bar. |
| 613 ui_controls::MoveMouseToCenterAndPress(location_bar, | 618 ui_controls::MoveMouseToCenterAndPress(location_bar, |
| 614 ui_controls::LEFT, | 619 ui_controls::LEFT, |
| 615 ui_controls::DOWN | ui_controls::UP, | 620 ui_controls::DOWN | ui_controls::UP, |
| 616 new MessageLoop::QuitTask()); | 621 new MessageLoop::QuitTask()); |
| 617 ui_test_utils::RunMessageLoop(); | 622 ui_test_utils::RunMessageLoop(); |
| 618 | 623 |
| 619 // Make sure the location bar is focused. | 624 // Make sure the location bar is focused. |
| 620 EXPECT_EQ(location_bar, focus_manager->GetFocusedView()); | 625 EXPECT_EQ(location_bar, focus_manager->GetFocusedView()); |
| 621 | 626 |
| 622 // Now press Ctrl+F again and focus should move to the Find box. | 627 // Now press Ctrl+F again and focus should move to the Find box. |
| 623 ui_controls::SendKeyPressNotifyWhenDone(L'F', true, false, false, | 628 ui_controls::SendKeyPressNotifyWhenDone(NULL, base::VKEY_F, true, |
| 629 false, false, |
| 624 new MessageLoop::QuitTask()); | 630 new MessageLoop::QuitTask()); |
| 625 ui_test_utils::RunMessageLoop(); | 631 ui_test_utils::RunMessageLoop(); |
| 626 focused_view = focus_manager->GetFocusedView(); | 632 focused_view = focus_manager->GetFocusedView(); |
| 627 ASSERT_TRUE(focused_view != NULL); | 633 ASSERT_TRUE(focused_view != NULL); |
| 628 EXPECT_EQ(VIEW_ID_FIND_IN_PAGE_TEXT_FIELD, focused_view->GetID()); | 634 EXPECT_EQ(VIEW_ID_FIND_IN_PAGE_TEXT_FIELD, focused_view->GetID()); |
| 629 | 635 |
| 630 // Set focus to the page. | 636 // Set focus to the page. |
| 631 ui_controls::MoveMouseToCenterAndPress( | 637 ui_controls::MoveMouseToCenterAndPress( |
| 632 browser_view->GetTabContentsContainerView(), | 638 browser_view->GetTabContentsContainerView(), |
| 633 ui_controls::LEFT, | 639 ui_controls::LEFT, |
| 634 ui_controls::DOWN | ui_controls::UP, | 640 ui_controls::DOWN | ui_controls::UP, |
| 635 new MessageLoop::QuitTask()); | 641 new MessageLoop::QuitTask()); |
| 636 ui_test_utils::RunMessageLoop(); | 642 ui_test_utils::RunMessageLoop(); |
| 637 EXPECT_EQ(browser_view->GetTabContentsContainerView(), | 643 EXPECT_EQ(browser_view->GetTabContentsContainerView(), |
| 638 focus_manager->GetFocusedView()); | 644 focus_manager->GetFocusedView()); |
| 639 | 645 |
| 640 // Now press Ctrl+F again and focus should move to the Find box. | 646 // Now press Ctrl+F again and focus should move to the Find box. |
| 641 ui_controls::SendKeyPressNotifyWhenDone(VK_F, true, false, false, | 647 ui_controls::SendKeyPressNotifyWhenDone(NULL, base::VKEY_F, true, false, |
| 642 new MessageLoop::QuitTask()); | 648 false, new MessageLoop::QuitTask()); |
| 643 ui_test_utils::RunMessageLoop(); | 649 ui_test_utils::RunMessageLoop(); |
| 644 | 650 |
| 645 // See remark above on why we wait. | 651 // See remark above on why we wait. |
| 646 ::Sleep(kActionDelayMs); | 652 ::Sleep(kActionDelayMs); |
| 647 MessageLoop::current()->PostTask(FROM_HERE, new MessageLoop::QuitTask()); | 653 MessageLoop::current()->PostTask(FROM_HERE, new MessageLoop::QuitTask()); |
| 648 ui_test_utils::RunMessageLoop(); | 654 ui_test_utils::RunMessageLoop(); |
| 649 | 655 |
| 650 focused_view = focus_manager->GetFocusedView(); | 656 focused_view = focus_manager->GetFocusedView(); |
| 651 ASSERT_TRUE(focused_view != NULL); | 657 ASSERT_TRUE(focused_view != NULL); |
| 652 EXPECT_EQ(VIEW_ID_FIND_IN_PAGE_TEXT_FIELD, focused_view->GetID()); | 658 EXPECT_EQ(VIEW_ID_FIND_IN_PAGE_TEXT_FIELD, focused_view->GetID()); |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 721 // Open a regular page, crash, reload. | 727 // Open a regular page, crash, reload. |
| 722 ui_test_utils::NavigateToURL(browser(), server->TestServerPageW(kSimplePage)); | 728 ui_test_utils::NavigateToURL(browser(), server->TestServerPageW(kSimplePage)); |
| 723 ui_test_utils::CrashTab(browser()->GetSelectedTabContents()); | 729 ui_test_utils::CrashTab(browser()->GetSelectedTabContents()); |
| 724 browser()->Reload(); | 730 browser()->Reload(); |
| 725 ASSERT_TRUE(ui_test_utils::WaitForNavigationInCurrentTab(browser())); | 731 ASSERT_TRUE(ui_test_utils::WaitForNavigationInCurrentTab(browser())); |
| 726 // Focus should now be on the tab contents. | 732 // Focus should now be on the tab contents. |
| 727 EXPECT_EQ(browser_view->GetTabContentsContainerView(), | 733 EXPECT_EQ(browser_view->GetTabContentsContainerView(), |
| 728 focus_manager->GetFocusedView()); | 734 focus_manager->GetFocusedView()); |
| 729 } | 735 } |
| 730 #endif // defined(OS_WIN) | 736 #endif // defined(OS_WIN) |
| OLD | NEW |