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

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

Issue 7327007: Moving notification types which are chrome specific to a new header file chrome_notification_type... (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: '' Created 9 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) 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 163 matching lines...) Expand 10 before | Expand all | Expand 10 after
174 bool handled = true; 174 bool handled = true;
175 IPC_BEGIN_MESSAGE_MAP(TestInterstitialPage, message) 175 IPC_BEGIN_MESSAGE_MAP(TestInterstitialPage, message)
176 IPC_MESSAGE_HANDLER(ViewHostMsg_FocusedNodeChanged, OnFocusedNodeChanged) 176 IPC_MESSAGE_HANDLER(ViewHostMsg_FocusedNodeChanged, OnFocusedNodeChanged)
177 IPC_MESSAGE_UNHANDLED(handled = false) 177 IPC_MESSAGE_UNHANDLED(handled = false)
178 IPC_END_MESSAGE_MAP() 178 IPC_END_MESSAGE_MAP()
179 return handled; 179 return handled;
180 } 180 }
181 181
182 void OnFocusedNodeChanged(bool is_editable_node) { 182 void OnFocusedNodeChanged(bool is_editable_node) {
183 NotificationService::current()->Notify( 183 NotificationService::current()->Notify(
184 NotificationType::FOCUS_CHANGED_IN_PAGE, 184 chrome::FOCUS_CHANGED_IN_PAGE,
185 Source<TabContents>(tab()), 185 Source<TabContents>(tab()),
186 Details<const bool>(&is_editable_node)); 186 Details<const bool>(&is_editable_node));
187 } 187 }
188 188
189 private: 189 private:
190 std::string html_contents_; 190 std::string html_contents_;
191 }; 191 };
192 192
193 IN_PROC_BROWSER_TEST_F(BrowserFocusTest, ClickingMovesFocus) { 193 IN_PROC_BROWSER_TEST_F(BrowserFocusTest, ClickingMovesFocus) {
194 ASSERT_TRUE(ui_test_utils::BringBrowserWindowToFront(browser())); 194 ASSERT_TRUE(ui_test_utils::BringBrowserWindowToFront(browser()));
(...skipping 302 matching lines...) Expand 10 before | Expand all | Expand 10 after
497 497
498 if (j < arraysize(kExpElementIDs) - 1) { 498 if (j < arraysize(kExpElementIDs) - 1) {
499 // If the next element is the kTextElementID, we expect to be 499 // If the next element is the kTextElementID, we expect to be
500 // notified we have switched to an editable node. 500 // notified we have switched to an editable node.
501 bool is_editable_node = 501 bool is_editable_node =
502 (strcmp(kTextElementID, kExpElementIDs[j + 1]) == 0); 502 (strcmp(kTextElementID, kExpElementIDs[j + 1]) == 0);
503 Details<bool> details(&is_editable_node); 503 Details<bool> details(&is_editable_node);
504 504
505 ASSERT_TRUE(ui_test_utils::SendKeyPressAndWaitWithDetails( 505 ASSERT_TRUE(ui_test_utils::SendKeyPressAndWaitWithDetails(
506 browser(), ui::VKEY_TAB, false, false, false, false, 506 browser(), ui::VKEY_TAB, false, false, false, false,
507 NotificationType::FOCUS_CHANGED_IN_PAGE, 507 chrome::FOCUS_CHANGED_IN_PAGE,
508 NotificationSource(Source<TabContents>( 508 NotificationSource(Source<TabContents>(
509 browser()->GetSelectedTabContents())), 509 browser()->GetSelectedTabContents())),
510 details)); 510 details));
511 } else { 511 } else {
512 // On the last tab key press, the focus returns to the browser. 512 // On the last tab key press, the focus returns to the browser.
513 ASSERT_TRUE(ui_test_utils::SendKeyPressAndWait( 513 ASSERT_TRUE(ui_test_utils::SendKeyPressAndWait(
514 browser(), ui::VKEY_TAB, false, false, false, false, 514 browser(), ui::VKEY_TAB, false, false, false, false,
515 NotificationType::FOCUS_RETURNED_TO_BROWSER, 515 chrome::FOCUS_RETURNED_TO_BROWSER,
516 NotificationSource(Source<Browser>(browser())))); 516 NotificationSource(Source<Browser>(browser()))));
517 } 517 }
518 } 518 }
519 519
520 // At this point the renderer has sent us a message asking to advance the 520 // At this point the renderer has sent us a message asking to advance the
521 // focus (as the end of the focus loop was reached in the renderer). 521 // focus (as the end of the focus loop was reached in the renderer).
522 // We need to run the message loop to process it. 522 // We need to run the message loop to process it.
523 ui_test_utils::RunAllPendingInMessageLoop(); 523 ui_test_utils::RunAllPendingInMessageLoop();
524 } 524 }
525 525
(...skipping 14 matching lines...) Expand all
540 kExpElementIDs[arraysize(kExpElementIDs) - 1 - j]; 540 kExpElementIDs[arraysize(kExpElementIDs) - 1 - j];
541 541
542 if (j < arraysize(kExpElementIDs) - 1) { 542 if (j < arraysize(kExpElementIDs) - 1) {
543 // If the next element is the kTextElementID, we expect to be 543 // If the next element is the kTextElementID, we expect to be
544 // notified we have switched to an editable node. 544 // notified we have switched to an editable node.
545 bool is_editable_node = (strcmp(kTextElementID, next_element) == 0); 545 bool is_editable_node = (strcmp(kTextElementID, next_element) == 0);
546 Details<bool> details(&is_editable_node); 546 Details<bool> details(&is_editable_node);
547 547
548 ASSERT_TRUE(ui_test_utils::SendKeyPressAndWaitWithDetails( 548 ASSERT_TRUE(ui_test_utils::SendKeyPressAndWaitWithDetails(
549 browser(), ui::VKEY_TAB, false, true, false, false, 549 browser(), ui::VKEY_TAB, false, true, false, false,
550 NotificationType::FOCUS_CHANGED_IN_PAGE, 550 chrome::FOCUS_CHANGED_IN_PAGE,
551 NotificationSource(Source<TabContents>( 551 NotificationSource(Source<TabContents>(
552 browser()->GetSelectedTabContents())), 552 browser()->GetSelectedTabContents())),
553 details)); 553 details));
554 } else { 554 } else {
555 // On the last tab key press, the focus returns to the browser. 555 // On the last tab key press, the focus returns to the browser.
556 ASSERT_TRUE(ui_test_utils::SendKeyPressAndWait( 556 ASSERT_TRUE(ui_test_utils::SendKeyPressAndWait(
557 browser(), ui::VKEY_TAB, false, true, false, false, 557 browser(), ui::VKEY_TAB, false, true, false, false,
558 NotificationType::FOCUS_RETURNED_TO_BROWSER, 558 chrome::FOCUS_RETURNED_TO_BROWSER,
559 NotificationSource(Source<Browser>(browser())))); 559 NotificationSource(Source<Browser>(browser()))));
560 } 560 }
561 561
562 // Let's make sure the focus is on the expected element in the page. 562 // Let's make sure the focus is on the expected element in the page.
563 std::string actual; 563 std::string actual;
564 ASSERT_TRUE(ui_test_utils::ExecuteJavaScriptAndExtractString( 564 ASSERT_TRUE(ui_test_utils::ExecuteJavaScriptAndExtractString(
565 browser()->GetSelectedTabContents()->render_view_host(), 565 browser()->GetSelectedTabContents()->render_view_host(),
566 L"", 566 L"",
567 L"window.domAutomationController.send(getFocusedElement());", 567 L"window.domAutomationController.send(getFocusedElement());",
568 &actual)); 568 &actual));
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
620 // Now let's press tab to move the focus. 620 // Now let's press tab to move the focus.
621 for (size_t j = 0; j < 7; ++j) { 621 for (size_t j = 0; j < 7; ++j) {
622 // Let's make sure the focus is on the expected element in the page. 622 // Let's make sure the focus is on the expected element in the page.
623 std::string actual; 623 std::string actual;
624 ASSERT_TRUE(ui_test_utils::ExecuteJavaScriptAndExtractString( 624 ASSERT_TRUE(ui_test_utils::ExecuteJavaScriptAndExtractString(
625 interstitial_page->render_view_host(), L"", 625 interstitial_page->render_view_host(), L"",
626 L"window.domAutomationController.send(getFocusedElement());", 626 L"window.domAutomationController.send(getFocusedElement());",
627 &actual)); 627 &actual));
628 ASSERT_STREQ(kExpElementIDs[j], actual.c_str()); 628 ASSERT_STREQ(kExpElementIDs[j], actual.c_str());
629 629
630 NotificationType::Type notification_type; 630 chrome::Type notification_type;
631 NotificationSource notification_source = 631 NotificationSource notification_source =
632 NotificationService::AllSources(); 632 NotificationService::AllSources();
633 if (j < arraysize(kExpElementIDs) - 1) { 633 if (j < arraysize(kExpElementIDs) - 1) {
634 notification_type = NotificationType::FOCUS_CHANGED_IN_PAGE; 634 notification_type = chrome::FOCUS_CHANGED_IN_PAGE;
635 notification_source = Source<TabContents>( 635 notification_source = Source<TabContents>(
636 interstitial_page->tab()); 636 interstitial_page->tab());
637 } else { 637 } else {
638 // On the last tab key press, the focus returns to the browser. 638 // On the last tab key press, the focus returns to the browser.
639 notification_type = NotificationType::FOCUS_RETURNED_TO_BROWSER; 639 notification_type = chrome::FOCUS_RETURNED_TO_BROWSER;
640 notification_source = Source<Browser>(browser()); 640 notification_source = Source<Browser>(browser());
641 } 641 }
642 642
643 ASSERT_TRUE(ui_test_utils::SendKeyPressAndWait( 643 ASSERT_TRUE(ui_test_utils::SendKeyPressAndWait(
644 browser(), ui::VKEY_TAB, false, false, false, false, 644 browser(), ui::VKEY_TAB, false, false, false, false,
645 notification_type, notification_source)); 645 notification_type, notification_source));
646 } 646 }
647 647
648 // At this point the renderer has sent us a message asking to advance the 648 // At this point the renderer has sent us a message asking to advance the
649 // focus (as the end of the focus loop was reached in the renderer). 649 // focus (as the end of the focus loop was reached in the renderer).
650 // We need to run the message loop to process it. 650 // We need to run the message loop to process it.
651 ui_test_utils::RunAllPendingInMessageLoop(); 651 ui_test_utils::RunAllPendingInMessageLoop();
652 } 652 }
653 653
654 // Now let's try reverse focus traversal. 654 // Now let's try reverse focus traversal.
655 for (int i = 0; i < 2; ++i) { 655 for (int i = 0; i < 2; ++i) {
656 // Location bar should be focused. 656 // Location bar should be focused.
657 ASSERT_TRUE(IsViewFocused(VIEW_ID_LOCATION_BAR)); 657 ASSERT_TRUE(IsViewFocused(VIEW_ID_LOCATION_BAR));
658 658
659 // Move the caret to the end, otherwise the next Tab key may not move focus. 659 // Move the caret to the end, otherwise the next Tab key may not move focus.
660 ASSERT_TRUE(ui_test_utils::SendKeyPressSync( 660 ASSERT_TRUE(ui_test_utils::SendKeyPressSync(
661 browser(), ui::VKEY_END, false, false, false, false)); 661 browser(), ui::VKEY_END, false, false, false, false));
662 662
663 // Now let's press shift-tab to move the focus in reverse. 663 // Now let's press shift-tab to move the focus in reverse.
664 for (size_t j = 0; j < 7; ++j) { 664 for (size_t j = 0; j < 7; ++j) {
665 NotificationType::Type notification_type; 665 chrome::Type notification_type;
666 NotificationSource notification_source = 666 NotificationSource notification_source =
667 NotificationService::AllSources(); 667 NotificationService::AllSources();
668 if (j < arraysize(kExpElementIDs) - 1) { 668 if (j < arraysize(kExpElementIDs) - 1) {
669 notification_type = NotificationType::FOCUS_CHANGED_IN_PAGE; 669 notification_type = chrome::FOCUS_CHANGED_IN_PAGE;
670 notification_source = Source<TabContents>( 670 notification_source = Source<TabContents>(
671 interstitial_page->tab()); 671 interstitial_page->tab());
672 } else { 672 } else {
673 // On the last tab key press, the focus returns to the browser. 673 // On the last tab key press, the focus returns to the browser.
674 notification_type = NotificationType::FOCUS_RETURNED_TO_BROWSER; 674 notification_type = chrome::FOCUS_RETURNED_TO_BROWSER;
675 notification_source = Source<Browser>(browser()); 675 notification_source = Source<Browser>(browser());
676 } 676 }
677 677
678 ASSERT_TRUE(ui_test_utils::SendKeyPressAndWait( 678 ASSERT_TRUE(ui_test_utils::SendKeyPressAndWait(
679 browser(), ui::VKEY_TAB, false, true, false, false, 679 browser(), ui::VKEY_TAB, false, true, false, false,
680 notification_type, notification_source)); 680 notification_type, notification_source));
681 681
682 // Let's make sure the focus is on the expected element in the page. 682 // Let's make sure the focus is on the expected element in the page.
683 std::string actual; 683 std::string actual;
684 ASSERT_TRUE(ui_test_utils::ExecuteJavaScriptAndExtractString( 684 ASSERT_TRUE(ui_test_utils::ExecuteJavaScriptAndExtractString(
(...skipping 190 matching lines...) Expand 10 before | Expand all | Expand 10 after
875 ui_test_utils::CrashTab(browser()->GetSelectedTabContents()); 875 ui_test_utils::CrashTab(browser()->GetSelectedTabContents());
876 browser()->Reload(CURRENT_TAB); 876 browser()->Reload(CURRENT_TAB);
877 ASSERT_TRUE(ui_test_utils::WaitForNavigationInCurrentTab(browser())); 877 ASSERT_TRUE(ui_test_utils::WaitForNavigationInCurrentTab(browser()));
878 878
879 // Focus should now be on the tab contents. 879 // Focus should now be on the tab contents.
880 browser()->ShowDownloadsTab(); 880 browser()->ShowDownloadsTab();
881 ASSERT_TRUE(IsViewFocused(VIEW_ID_TAB_CONTAINER_FOCUS_VIEW)); 881 ASSERT_TRUE(IsViewFocused(VIEW_ID_TAB_CONTAINER_FOCUS_VIEW));
882 } 882 }
883 883
884 } // namespace 884 } // namespace
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698