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

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
« no previous file with comments | « chrome/browser/browser_browsertest.cc ('k') | chrome/browser/browser_keyevents_browsertest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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"
11 #include "base/stringprintf.h" 11 #include "base/stringprintf.h"
12 #include "base/string_number_conversions.h" 12 #include "base/string_number_conversions.h"
13 #include "base/utf_string_conversions.h" 13 #include "base/utf_string_conversions.h"
14 #include "chrome/browser/tabs/tab_strip_model.h" 14 #include "chrome/browser/tabs/tab_strip_model.h"
15 #include "chrome/browser/ui/browser.h" 15 #include "chrome/browser/ui/browser.h"
16 #include "chrome/browser/ui/browser_window.h" 16 #include "chrome/browser/ui/browser_window.h"
17 #include "chrome/browser/ui/view_ids.h" 17 #include "chrome/browser/ui/view_ids.h"
18 #include "chrome/common/chrome_notification_types.h"
18 #include "chrome/common/chrome_paths.h" 19 #include "chrome/common/chrome_paths.h"
19 #include "chrome/common/url_constants.h" 20 #include "chrome/common/url_constants.h"
20 #include "chrome/test/in_process_browser_test.h" 21 #include "chrome/test/in_process_browser_test.h"
21 #include "chrome/test/ui_test_utils.h" 22 #include "chrome/test/ui_test_utils.h"
22 #include "content/browser/renderer_host/render_view_host.h" 23 #include "content/browser/renderer_host/render_view_host.h"
23 #include "content/browser/renderer_host/render_widget_host_view.h" 24 #include "content/browser/renderer_host/render_widget_host_view.h"
24 #include "content/browser/tab_contents/interstitial_page.h" 25 #include "content/browser/tab_contents/interstitial_page.h"
25 #include "content/browser/tab_contents/tab_contents.h" 26 #include "content/browser/tab_contents/tab_contents.h"
26 #include "content/browser/tab_contents/tab_contents_view.h" 27 #include "content/browser/tab_contents/tab_contents_view.h"
27 #include "content/common/view_messages.h" 28 #include "content/common/view_messages.h"
(...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after
174 bool handled = true; 175 bool handled = true;
175 IPC_BEGIN_MESSAGE_MAP(TestInterstitialPage, message) 176 IPC_BEGIN_MESSAGE_MAP(TestInterstitialPage, message)
176 IPC_MESSAGE_HANDLER(ViewHostMsg_FocusedNodeChanged, OnFocusedNodeChanged) 177 IPC_MESSAGE_HANDLER(ViewHostMsg_FocusedNodeChanged, OnFocusedNodeChanged)
177 IPC_MESSAGE_UNHANDLED(handled = false) 178 IPC_MESSAGE_UNHANDLED(handled = false)
178 IPC_END_MESSAGE_MAP() 179 IPC_END_MESSAGE_MAP()
179 return handled; 180 return handled;
180 } 181 }
181 182
182 void OnFocusedNodeChanged(bool is_editable_node) { 183 void OnFocusedNodeChanged(bool is_editable_node) {
183 NotificationService::current()->Notify( 184 NotificationService::current()->Notify(
184 NotificationType::FOCUS_CHANGED_IN_PAGE, 185 content::NOTIFICATION_FOCUS_CHANGED_IN_PAGE,
185 Source<TabContents>(tab()), 186 Source<TabContents>(tab()),
186 Details<const bool>(&is_editable_node)); 187 Details<const bool>(&is_editable_node));
187 } 188 }
188 189
189 private: 190 private:
190 std::string html_contents_; 191 std::string html_contents_;
191 }; 192 };
192 193
193 IN_PROC_BROWSER_TEST_F(BrowserFocusTest, ClickingMovesFocus) { 194 IN_PROC_BROWSER_TEST_F(BrowserFocusTest, ClickingMovesFocus) {
194 ASSERT_TRUE(ui_test_utils::BringBrowserWindowToFront(browser())); 195 ASSERT_TRUE(ui_test_utils::BringBrowserWindowToFront(browser()));
(...skipping 302 matching lines...) Expand 10 before | Expand all | Expand 10 after
497 498
498 if (j < arraysize(kExpElementIDs) - 1) { 499 if (j < arraysize(kExpElementIDs) - 1) {
499 // If the next element is the kTextElementID, we expect to be 500 // If the next element is the kTextElementID, we expect to be
500 // notified we have switched to an editable node. 501 // notified we have switched to an editable node.
501 bool is_editable_node = 502 bool is_editable_node =
502 (strcmp(kTextElementID, kExpElementIDs[j + 1]) == 0); 503 (strcmp(kTextElementID, kExpElementIDs[j + 1]) == 0);
503 Details<bool> details(&is_editable_node); 504 Details<bool> details(&is_editable_node);
504 505
505 ASSERT_TRUE(ui_test_utils::SendKeyPressAndWaitWithDetails( 506 ASSERT_TRUE(ui_test_utils::SendKeyPressAndWaitWithDetails(
506 browser(), ui::VKEY_TAB, false, false, false, false, 507 browser(), ui::VKEY_TAB, false, false, false, false,
507 NotificationType::FOCUS_CHANGED_IN_PAGE, 508 content::NOTIFICATION_FOCUS_CHANGED_IN_PAGE,
508 NotificationSource(Source<TabContents>( 509 NotificationSource(Source<TabContents>(
509 browser()->GetSelectedTabContents())), 510 browser()->GetSelectedTabContents())),
510 details)); 511 details));
511 } else { 512 } else {
512 // On the last tab key press, the focus returns to the browser. 513 // On the last tab key press, the focus returns to the browser.
513 ASSERT_TRUE(ui_test_utils::SendKeyPressAndWait( 514 ASSERT_TRUE(ui_test_utils::SendKeyPressAndWait(
514 browser(), ui::VKEY_TAB, false, false, false, false, 515 browser(), ui::VKEY_TAB, false, false, false, false,
515 NotificationType::FOCUS_RETURNED_TO_BROWSER, 516 chrome::NOTIFICATION_FOCUS_RETURNED_TO_BROWSER,
516 NotificationSource(Source<Browser>(browser())))); 517 NotificationSource(Source<Browser>(browser()))));
517 } 518 }
518 } 519 }
519 520
520 // At this point the renderer has sent us a message asking to advance the 521 // 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). 522 // focus (as the end of the focus loop was reached in the renderer).
522 // We need to run the message loop to process it. 523 // We need to run the message loop to process it.
523 ui_test_utils::RunAllPendingInMessageLoop(); 524 ui_test_utils::RunAllPendingInMessageLoop();
524 } 525 }
525 526
(...skipping 14 matching lines...) Expand all
540 kExpElementIDs[arraysize(kExpElementIDs) - 1 - j]; 541 kExpElementIDs[arraysize(kExpElementIDs) - 1 - j];
541 542
542 if (j < arraysize(kExpElementIDs) - 1) { 543 if (j < arraysize(kExpElementIDs) - 1) {
543 // If the next element is the kTextElementID, we expect to be 544 // If the next element is the kTextElementID, we expect to be
544 // notified we have switched to an editable node. 545 // notified we have switched to an editable node.
545 bool is_editable_node = (strcmp(kTextElementID, next_element) == 0); 546 bool is_editable_node = (strcmp(kTextElementID, next_element) == 0);
546 Details<bool> details(&is_editable_node); 547 Details<bool> details(&is_editable_node);
547 548
548 ASSERT_TRUE(ui_test_utils::SendKeyPressAndWaitWithDetails( 549 ASSERT_TRUE(ui_test_utils::SendKeyPressAndWaitWithDetails(
549 browser(), ui::VKEY_TAB, false, true, false, false, 550 browser(), ui::VKEY_TAB, false, true, false, false,
550 NotificationType::FOCUS_CHANGED_IN_PAGE, 551 content::NOTIFICATION_FOCUS_CHANGED_IN_PAGE,
551 NotificationSource(Source<TabContents>( 552 NotificationSource(Source<TabContents>(
552 browser()->GetSelectedTabContents())), 553 browser()->GetSelectedTabContents())),
553 details)); 554 details));
554 } else { 555 } else {
555 // On the last tab key press, the focus returns to the browser. 556 // On the last tab key press, the focus returns to the browser.
556 ASSERT_TRUE(ui_test_utils::SendKeyPressAndWait( 557 ASSERT_TRUE(ui_test_utils::SendKeyPressAndWait(
557 browser(), ui::VKEY_TAB, false, true, false, false, 558 browser(), ui::VKEY_TAB, false, true, false, false,
558 NotificationType::FOCUS_RETURNED_TO_BROWSER, 559 chrome::NOTIFICATION_FOCUS_RETURNED_TO_BROWSER,
559 NotificationSource(Source<Browser>(browser())))); 560 NotificationSource(Source<Browser>(browser()))));
560 } 561 }
561 562
562 // Let's make sure the focus is on the expected element in the page. 563 // Let's make sure the focus is on the expected element in the page.
563 std::string actual; 564 std::string actual;
564 ASSERT_TRUE(ui_test_utils::ExecuteJavaScriptAndExtractString( 565 ASSERT_TRUE(ui_test_utils::ExecuteJavaScriptAndExtractString(
565 browser()->GetSelectedTabContents()->render_view_host(), 566 browser()->GetSelectedTabContents()->render_view_host(),
566 L"", 567 L"",
567 L"window.domAutomationController.send(getFocusedElement());", 568 L"window.domAutomationController.send(getFocusedElement());",
568 &actual)); 569 &actual));
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
620 // Now let's press tab to move the focus. 621 // Now let's press tab to move the focus.
621 for (size_t j = 0; j < 7; ++j) { 622 for (size_t j = 0; j < 7; ++j) {
622 // Let's make sure the focus is on the expected element in the page. 623 // Let's make sure the focus is on the expected element in the page.
623 std::string actual; 624 std::string actual;
624 ASSERT_TRUE(ui_test_utils::ExecuteJavaScriptAndExtractString( 625 ASSERT_TRUE(ui_test_utils::ExecuteJavaScriptAndExtractString(
625 interstitial_page->render_view_host(), L"", 626 interstitial_page->render_view_host(), L"",
626 L"window.domAutomationController.send(getFocusedElement());", 627 L"window.domAutomationController.send(getFocusedElement());",
627 &actual)); 628 &actual));
628 ASSERT_STREQ(kExpElementIDs[j], actual.c_str()); 629 ASSERT_STREQ(kExpElementIDs[j], actual.c_str());
629 630
630 NotificationType::Type notification_type; 631 int notification_type;
631 NotificationSource notification_source = 632 NotificationSource notification_source =
632 NotificationService::AllSources(); 633 NotificationService::AllSources();
633 if (j < arraysize(kExpElementIDs) - 1) { 634 if (j < arraysize(kExpElementIDs) - 1) {
634 notification_type = NotificationType::FOCUS_CHANGED_IN_PAGE; 635 notification_type = content::NOTIFICATION_FOCUS_CHANGED_IN_PAGE;
635 notification_source = Source<TabContents>( 636 notification_source = Source<TabContents>(
636 interstitial_page->tab()); 637 interstitial_page->tab());
637 } else { 638 } else {
638 // On the last tab key press, the focus returns to the browser. 639 // On the last tab key press, the focus returns to the browser.
639 notification_type = NotificationType::FOCUS_RETURNED_TO_BROWSER; 640 notification_type = chrome::NOTIFICATION_FOCUS_RETURNED_TO_BROWSER;
640 notification_source = Source<Browser>(browser()); 641 notification_source = Source<Browser>(browser());
641 } 642 }
642 643
643 ASSERT_TRUE(ui_test_utils::SendKeyPressAndWait( 644 ASSERT_TRUE(ui_test_utils::SendKeyPressAndWait(
644 browser(), ui::VKEY_TAB, false, false, false, false, 645 browser(), ui::VKEY_TAB, false, false, false, false,
645 notification_type, notification_source)); 646 notification_type, notification_source));
646 } 647 }
647 648
648 // At this point the renderer has sent us a message asking to advance the 649 // 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). 650 // focus (as the end of the focus loop was reached in the renderer).
650 // We need to run the message loop to process it. 651 // We need to run the message loop to process it.
651 ui_test_utils::RunAllPendingInMessageLoop(); 652 ui_test_utils::RunAllPendingInMessageLoop();
652 } 653 }
653 654
654 // Now let's try reverse focus traversal. 655 // Now let's try reverse focus traversal.
655 for (int i = 0; i < 2; ++i) { 656 for (int i = 0; i < 2; ++i) {
656 // Location bar should be focused. 657 // Location bar should be focused.
657 ASSERT_TRUE(IsViewFocused(VIEW_ID_LOCATION_BAR)); 658 ASSERT_TRUE(IsViewFocused(VIEW_ID_LOCATION_BAR));
658 659
659 // Move the caret to the end, otherwise the next Tab key may not move focus. 660 // Move the caret to the end, otherwise the next Tab key may not move focus.
660 ASSERT_TRUE(ui_test_utils::SendKeyPressSync( 661 ASSERT_TRUE(ui_test_utils::SendKeyPressSync(
661 browser(), ui::VKEY_END, false, false, false, false)); 662 browser(), ui::VKEY_END, false, false, false, false));
662 663
663 // Now let's press shift-tab to move the focus in reverse. 664 // Now let's press shift-tab to move the focus in reverse.
664 for (size_t j = 0; j < 7; ++j) { 665 for (size_t j = 0; j < 7; ++j) {
665 NotificationType::Type notification_type; 666 int notification_type;
666 NotificationSource notification_source = 667 NotificationSource notification_source =
667 NotificationService::AllSources(); 668 NotificationService::AllSources();
668 if (j < arraysize(kExpElementIDs) - 1) { 669 if (j < arraysize(kExpElementIDs) - 1) {
669 notification_type = NotificationType::FOCUS_CHANGED_IN_PAGE; 670 notification_type = content::NOTIFICATION_FOCUS_CHANGED_IN_PAGE;
670 notification_source = Source<TabContents>( 671 notification_source = Source<TabContents>(
671 interstitial_page->tab()); 672 interstitial_page->tab());
672 } else { 673 } else {
673 // On the last tab key press, the focus returns to the browser. 674 // On the last tab key press, the focus returns to the browser.
674 notification_type = NotificationType::FOCUS_RETURNED_TO_BROWSER; 675 notification_type = chrome::NOTIFICATION_FOCUS_RETURNED_TO_BROWSER;
675 notification_source = Source<Browser>(browser()); 676 notification_source = Source<Browser>(browser());
676 } 677 }
677 678
678 ASSERT_TRUE(ui_test_utils::SendKeyPressAndWait( 679 ASSERT_TRUE(ui_test_utils::SendKeyPressAndWait(
679 browser(), ui::VKEY_TAB, false, true, false, false, 680 browser(), ui::VKEY_TAB, false, true, false, false,
680 notification_type, notification_source)); 681 notification_type, notification_source));
681 682
682 // Let's make sure the focus is on the expected element in the page. 683 // Let's make sure the focus is on the expected element in the page.
683 std::string actual; 684 std::string actual;
684 ASSERT_TRUE(ui_test_utils::ExecuteJavaScriptAndExtractString( 685 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()); 876 ui_test_utils::CrashTab(browser()->GetSelectedTabContents());
876 browser()->Reload(CURRENT_TAB); 877 browser()->Reload(CURRENT_TAB);
877 ASSERT_TRUE(ui_test_utils::WaitForNavigationInCurrentTab(browser())); 878 ASSERT_TRUE(ui_test_utils::WaitForNavigationInCurrentTab(browser()));
878 879
879 // Focus should now be on the tab contents. 880 // Focus should now be on the tab contents.
880 browser()->ShowDownloadsTab(); 881 browser()->ShowDownloadsTab();
881 ASSERT_TRUE(IsViewFocused(VIEW_ID_TAB_CONTAINER_FOCUS_VIEW)); 882 ASSERT_TRUE(IsViewFocused(VIEW_ID_TAB_CONTAINER_FOCUS_VIEW));
882 } 883 }
883 884
884 } // namespace 885 } // namespace
OLDNEW
« no previous file with comments | « chrome/browser/browser_browsertest.cc ('k') | chrome/browser/browser_keyevents_browsertest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698