OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/file_util.h" | 7 #include "base/file_util.h" |
8 #include "base/format_macros.h" | 8 #include "base/format_macros.h" |
9 #include "base/message_loop.h" | 9 #include "base/message_loop.h" |
10 #include "base/path_service.h" | 10 #include "base/path_service.h" |
(...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
147 file_path = file_path.AppendASCII("focus"); | 147 file_path = file_path.AppendASCII("focus"); |
148 file_path = file_path.AppendASCII(kTypicalPageName); | 148 file_path = file_path.AppendASCII(kTypicalPageName); |
149 r = file_util::ReadFileToString(file_path, &html_contents_); | 149 r = file_util::ReadFileToString(file_path, &html_contents_); |
150 EXPECT_TRUE(r); | 150 EXPECT_TRUE(r); |
151 } | 151 } |
152 | 152 |
153 virtual std::string GetHTMLContents() { | 153 virtual std::string GetHTMLContents() { |
154 return html_contents_; | 154 return html_contents_; |
155 } | 155 } |
156 | 156 |
157 // Exposing render_view_host() to be public; it is declared as protected in | 157 // Exposing render_view_host() and tab() to be public; they are declared as |
158 // the superclass. | 158 // protected in the superclass. |
159 virtual RenderViewHost* render_view_host() { | 159 virtual RenderViewHost* render_view_host() { |
160 return InterstitialPage::render_view_host(); | 160 return InterstitialPage::render_view_host(); |
161 } | 161 } |
162 | 162 |
| 163 virtual TabContents* tab() { |
| 164 return InterstitialPage::tab(); |
| 165 } |
| 166 |
163 bool HasFocus() { | 167 bool HasFocus() { |
164 return render_view_host()->view()->HasFocus(); | 168 return render_view_host()->view()->HasFocus(); |
165 } | 169 } |
166 | 170 |
167 protected: | 171 protected: |
168 virtual void FocusedNodeChanged(bool is_editable_node) { | 172 virtual void FocusedNodeChanged(bool is_editable_node) { |
169 NotificationService::current()->Notify( | 173 NotificationService::current()->Notify( |
170 NotificationType::FOCUS_CHANGED_IN_PAGE, | 174 NotificationType::FOCUS_CHANGED_IN_PAGE, |
171 Source<RenderViewHost>(render_view_host()), | 175 Source<TabContents>(tab()), |
172 Details<const bool>(&is_editable_node)); | 176 Details<const bool>(&is_editable_node)); |
173 } | 177 } |
174 | 178 |
175 private: | 179 private: |
176 std::string html_contents_; | 180 std::string html_contents_; |
177 }; | 181 }; |
178 | 182 |
179 IN_PROC_BROWSER_TEST_F(BrowserFocusTest, ClickingMovesFocus) { | 183 IN_PROC_BROWSER_TEST_F(BrowserFocusTest, ClickingMovesFocus) { |
180 ASSERT_TRUE(ui_test_utils::BringBrowserWindowToFront(browser())); | 184 ASSERT_TRUE(ui_test_utils::BringBrowserWindowToFront(browser())); |
181 #if defined(OS_POSIX) | 185 #if defined(OS_POSIX) |
(...skipping 298 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
480 if (j < arraysize(kExpElementIDs) - 1) { | 484 if (j < arraysize(kExpElementIDs) - 1) { |
481 // If the next element is the kTextElementID, we expect to be | 485 // If the next element is the kTextElementID, we expect to be |
482 // notified we have switched to an editable node. | 486 // notified we have switched to an editable node. |
483 bool is_editable_node = | 487 bool is_editable_node = |
484 (strcmp(kTextElementID, kExpElementIDs[j + 1]) == 0); | 488 (strcmp(kTextElementID, kExpElementIDs[j + 1]) == 0); |
485 Details<bool> details(&is_editable_node); | 489 Details<bool> details(&is_editable_node); |
486 | 490 |
487 ASSERT_TRUE(ui_test_utils::SendKeyPressAndWaitWithDetails( | 491 ASSERT_TRUE(ui_test_utils::SendKeyPressAndWaitWithDetails( |
488 browser(), ui::VKEY_TAB, false, false, false, false, | 492 browser(), ui::VKEY_TAB, false, false, false, false, |
489 NotificationType::FOCUS_CHANGED_IN_PAGE, | 493 NotificationType::FOCUS_CHANGED_IN_PAGE, |
490 NotificationSource(Source<RenderViewHost>( | 494 NotificationSource(Source<TabContents>( |
491 browser()->GetSelectedTabContents()->render_view_host())), | 495 browser()->GetSelectedTabContents())), |
492 details)); | 496 details)); |
493 } else { | 497 } else { |
494 // On the last tab key press, the focus returns to the browser. | 498 // On the last tab key press, the focus returns to the browser. |
495 ASSERT_TRUE(ui_test_utils::SendKeyPressAndWait( | 499 ASSERT_TRUE(ui_test_utils::SendKeyPressAndWait( |
496 browser(), ui::VKEY_TAB, false, false, false, false, | 500 browser(), ui::VKEY_TAB, false, false, false, false, |
497 NotificationType::FOCUS_RETURNED_TO_BROWSER, | 501 NotificationType::FOCUS_RETURNED_TO_BROWSER, |
498 NotificationSource(Source<Browser>(browser())))); | 502 NotificationSource(Source<Browser>(browser())))); |
499 } | 503 } |
500 } | 504 } |
501 | 505 |
(...skipping 17 matching lines...) Expand all Loading... |
519 | 523 |
520 if (j < arraysize(kExpElementIDs) - 1) { | 524 if (j < arraysize(kExpElementIDs) - 1) { |
521 // If the next element is the kTextElementID, we expect to be | 525 // If the next element is the kTextElementID, we expect to be |
522 // notified we have switched to an editable node. | 526 // notified we have switched to an editable node. |
523 bool is_editable_node = (strcmp(kTextElementID, next_element) == 0); | 527 bool is_editable_node = (strcmp(kTextElementID, next_element) == 0); |
524 Details<bool> details(&is_editable_node); | 528 Details<bool> details(&is_editable_node); |
525 | 529 |
526 ASSERT_TRUE(ui_test_utils::SendKeyPressAndWaitWithDetails( | 530 ASSERT_TRUE(ui_test_utils::SendKeyPressAndWaitWithDetails( |
527 browser(), ui::VKEY_TAB, false, true, false, false, | 531 browser(), ui::VKEY_TAB, false, true, false, false, |
528 NotificationType::FOCUS_CHANGED_IN_PAGE, | 532 NotificationType::FOCUS_CHANGED_IN_PAGE, |
529 NotificationSource(Source<RenderViewHost>( | 533 NotificationSource(Source<TabContents>( |
530 browser()->GetSelectedTabContents()->render_view_host())), | 534 browser()->GetSelectedTabContents())), |
531 details)); | 535 details)); |
532 } else { | 536 } else { |
533 // On the last tab key press, the focus returns to the browser. | 537 // On the last tab key press, the focus returns to the browser. |
534 ASSERT_TRUE(ui_test_utils::SendKeyPressAndWait( | 538 ASSERT_TRUE(ui_test_utils::SendKeyPressAndWait( |
535 browser(), ui::VKEY_TAB, false, true, false, false, | 539 browser(), ui::VKEY_TAB, false, true, false, false, |
536 NotificationType::FOCUS_RETURNED_TO_BROWSER, | 540 NotificationType::FOCUS_RETURNED_TO_BROWSER, |
537 NotificationSource(Source<Browser>(browser())))); | 541 NotificationSource(Source<Browser>(browser())))); |
538 } | 542 } |
539 | 543 |
540 // Let's make sure the focus is on the expected element in the page. | 544 // Let's make sure the focus is on the expected element in the page. |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
599 interstitial_page->render_view_host(), L"", | 603 interstitial_page->render_view_host(), L"", |
600 L"window.domAutomationController.send(getFocusedElement());", | 604 L"window.domAutomationController.send(getFocusedElement());", |
601 &actual)); | 605 &actual)); |
602 ASSERT_STREQ(kExpElementIDs[j], actual.c_str()); | 606 ASSERT_STREQ(kExpElementIDs[j], actual.c_str()); |
603 | 607 |
604 NotificationType::Type notification_type; | 608 NotificationType::Type notification_type; |
605 NotificationSource notification_source = | 609 NotificationSource notification_source = |
606 NotificationService::AllSources(); | 610 NotificationService::AllSources(); |
607 if (j < arraysize(kExpElementIDs) - 1) { | 611 if (j < arraysize(kExpElementIDs) - 1) { |
608 notification_type = NotificationType::FOCUS_CHANGED_IN_PAGE; | 612 notification_type = NotificationType::FOCUS_CHANGED_IN_PAGE; |
609 notification_source = Source<RenderViewHost>( | 613 notification_source = Source<TabContents>( |
610 interstitial_page->render_view_host()); | 614 interstitial_page->tab()); |
611 } else { | 615 } else { |
612 // On the last tab key press, the focus returns to the browser. | 616 // On the last tab key press, the focus returns to the browser. |
613 notification_type = NotificationType::FOCUS_RETURNED_TO_BROWSER; | 617 notification_type = NotificationType::FOCUS_RETURNED_TO_BROWSER; |
614 notification_source = Source<Browser>(browser()); | 618 notification_source = Source<Browser>(browser()); |
615 } | 619 } |
616 | 620 |
617 ASSERT_TRUE(ui_test_utils::SendKeyPressAndWait( | 621 ASSERT_TRUE(ui_test_utils::SendKeyPressAndWait( |
618 browser(), ui::VKEY_TAB, false, false, false, false, | 622 browser(), ui::VKEY_TAB, false, false, false, false, |
619 notification_type, notification_source)); | 623 notification_type, notification_source)); |
620 } | 624 } |
621 | 625 |
622 // At this point the renderer has sent us a message asking to advance the | 626 // At this point the renderer has sent us a message asking to advance the |
623 // focus (as the end of the focus loop was reached in the renderer). | 627 // focus (as the end of the focus loop was reached in the renderer). |
624 // We need to run the message loop to process it. | 628 // We need to run the message loop to process it. |
625 ui_test_utils::RunAllPendingInMessageLoop(); | 629 ui_test_utils::RunAllPendingInMessageLoop(); |
626 } | 630 } |
627 | 631 |
628 // Now let's try reverse focus traversal. | 632 // Now let's try reverse focus traversal. |
629 for (int i = 0; i < 2; ++i) { | 633 for (int i = 0; i < 2; ++i) { |
630 // Location bar should be focused. | 634 // Location bar should be focused. |
631 ASSERT_TRUE(IsViewFocused(VIEW_ID_LOCATION_BAR)); | 635 ASSERT_TRUE(IsViewFocused(VIEW_ID_LOCATION_BAR)); |
632 | 636 |
633 // Now let's press shift-tab to move the focus in reverse. | 637 // Now let's press shift-tab to move the focus in reverse. |
634 for (size_t j = 0; j < 7; ++j) { | 638 for (size_t j = 0; j < 7; ++j) { |
635 NotificationType::Type notification_type; | 639 NotificationType::Type notification_type; |
636 NotificationSource notification_source = | 640 NotificationSource notification_source = |
637 NotificationService::AllSources(); | 641 NotificationService::AllSources(); |
638 if (j < arraysize(kExpElementIDs) - 1) { | 642 if (j < arraysize(kExpElementIDs) - 1) { |
639 notification_type = NotificationType::FOCUS_CHANGED_IN_PAGE; | 643 notification_type = NotificationType::FOCUS_CHANGED_IN_PAGE; |
640 notification_source = Source<RenderViewHost>( | 644 notification_source = Source<TabContents>( |
641 interstitial_page->render_view_host()); | 645 interstitial_page->tab()); |
642 } else { | 646 } else { |
643 // On the last tab key press, the focus returns to the browser. | 647 // On the last tab key press, the focus returns to the browser. |
644 notification_type = NotificationType::FOCUS_RETURNED_TO_BROWSER; | 648 notification_type = NotificationType::FOCUS_RETURNED_TO_BROWSER; |
645 notification_source = Source<Browser>(browser()); | 649 notification_source = Source<Browser>(browser()); |
646 } | 650 } |
647 | 651 |
648 ASSERT_TRUE(ui_test_utils::SendKeyPressAndWait( | 652 ASSERT_TRUE(ui_test_utils::SendKeyPressAndWait( |
649 browser(), ui::VKEY_TAB, false, true, false, false, | 653 browser(), ui::VKEY_TAB, false, true, false, false, |
650 notification_type, notification_source)); | 654 notification_type, notification_source)); |
651 | 655 |
(...skipping 182 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
834 ui_test_utils::CrashTab(browser()->GetSelectedTabContents()); | 838 ui_test_utils::CrashTab(browser()->GetSelectedTabContents()); |
835 browser()->Reload(CURRENT_TAB); | 839 browser()->Reload(CURRENT_TAB); |
836 ASSERT_TRUE(ui_test_utils::WaitForNavigationInCurrentTab(browser())); | 840 ASSERT_TRUE(ui_test_utils::WaitForNavigationInCurrentTab(browser())); |
837 | 841 |
838 // Focus should now be on the tab contents. | 842 // Focus should now be on the tab contents. |
839 browser()->ShowDownloadsTab(); | 843 browser()->ShowDownloadsTab(); |
840 ASSERT_TRUE(IsViewFocused(VIEW_ID_TAB_CONTAINER_FOCUS_VIEW)); | 844 ASSERT_TRUE(IsViewFocused(VIEW_ID_TAB_CONTAINER_FOCUS_VIEW)); |
841 } | 845 } |
842 | 846 |
843 } // namespace | 847 } // namespace |
OLD | NEW |