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

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

Issue 8907029: AURA/X11: Handle VKEY_MENU accelerator on content area (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: " Created 9 years 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/bind.h"
7 #include "base/file_util.h" 8 #include "base/file_util.h"
8 #include "base/format_macros.h" 9 #include "base/format_macros.h"
9 #include "base/message_loop.h" 10 #include "base/message_loop.h"
10 #include "base/path_service.h" 11 #include "base/path_service.h"
11 #include "base/string_number_conversions.h" 12 #include "base/string_number_conversions.h"
12 #include "base/stringprintf.h" 13 #include "base/stringprintf.h"
13 #include "base/utf_string_conversions.h" 14 #include "base/utf_string_conversions.h"
14 #include "chrome/browser/tabs/tab_strip_model.h" 15 #include "chrome/browser/tabs/tab_strip_model.h"
15 #include "chrome/browser/ui/browser.h" 16 #include "chrome/browser/ui/browser.h"
16 #include "chrome/browser/ui/browser_window.h" 17 #include "chrome/browser/ui/browser_window.h"
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
67 // Flaky, http://crbug.com/62537. 68 // Flaky, http://crbug.com/62537.
68 #define MAYBE_TabsRememberFocusFindInPage FLAKY_TabsRememberFocusFindInPage 69 #define MAYBE_TabsRememberFocusFindInPage FLAKY_TabsRememberFocusFindInPage
69 #endif 70 #endif
70 71
71 namespace { 72 namespace {
72 73
73 // The delay waited in some cases where we don't have a notifications for an 74 // The delay waited in some cases where we don't have a notifications for an
74 // action we take. 75 // action we take.
75 const int kActionDelayMs = 500; 76 const int kActionDelayMs = 500;
76 77
78 // Maxiumum time to wait until the focus is moved to expected view.
79 const int kFocusChangeTimeoutMs = 500;
80
77 const char kSimplePage[] = "files/focus/page_with_focus.html"; 81 const char kSimplePage[] = "files/focus/page_with_focus.html";
78 const char kStealFocusPage[] = "files/focus/page_steals_focus.html"; 82 const char kStealFocusPage[] = "files/focus/page_steals_focus.html";
79 const char kTypicalPage[] = "files/focus/typical_page.html"; 83 const char kTypicalPage[] = "files/focus/typical_page.html";
80 const char kTypicalPageName[] = "typical_page.html"; 84 const char kTypicalPageName[] = "typical_page.html";
81 85
82 // Test to make sure Chrome is in the foreground as we start testing. This is 86 // Test to make sure Chrome is in the foreground as we start testing. This is
83 // required for tests that synthesize input to the Chrome window. 87 // required for tests that synthesize input to the Chrome window.
84 bool ChromeInForeground() { 88 bool ChromeInForeground() {
85 #if defined(OS_WIN) 89 #if defined(OS_WIN)
86 HWND window = ::GetForegroundWindow(); 90 HWND window = ::GetForegroundWindow();
(...skipping 29 matching lines...) Expand all
116 << "Process in foreground: " << filename.c_str() << "\n" 120 << "Process in foreground: " << filename.c_str() << "\n"
117 << "Window: " << window << "\n" 121 << "Window: " << window << "\n"
118 << "Caption: " << caption.c_str(); 122 << "Caption: " << caption.c_str();
119 return chrome_window_in_foreground; 123 return chrome_window_in_foreground;
120 #else 124 #else
121 // Windows only at the moment. 125 // Windows only at the moment.
122 return true; 126 return true;
123 #endif 127 #endif
124 } 128 }
125 129
130 // Wait the focus change in message loop.
131 void CheckFocus(Browser* browser, ViewID id, const base::Time& timeout) {
132 if (ui_test_utils::IsViewFocused(browser, id) ||
133 base::Time::Now() > timeout) {
134 MessageLoop::current()->PostTask(FROM_HERE, MessageLoop::QuitClosure());
135 } else {
136 MessageLoop::current()->PostDelayedTask(
137 FROM_HERE,
138 base::Bind(&CheckFocus, browser, id, timeout),
139 10);
140 }
141 };
142
126 class BrowserFocusTest : public InProcessBrowserTest { 143 class BrowserFocusTest : public InProcessBrowserTest {
127 public: 144 public:
128 BrowserFocusTest() : 145 BrowserFocusTest() :
129 #if defined(USE_AURA) 146 #if defined(USE_AURA)
130 location_bar_focus_view_id_(VIEW_ID_OMNIBOX) 147 location_bar_focus_view_id_(VIEW_ID_OMNIBOX)
131 #else 148 #else
132 location_bar_focus_view_id_(VIEW_ID_LOCATION_BAR) 149 location_bar_focus_view_id_(VIEW_ID_LOCATION_BAR)
133 #endif 150 #endif
134 { 151 {
135 set_show_window(true); 152 set_show_window(true);
136 EnableDOMAutomation(); 153 EnableDOMAutomation();
137 } 154 }
138 155
139 bool IsViewFocused(ViewID vid) { 156 bool IsViewFocused(ViewID vid) {
140 return ui_test_utils::IsViewFocused(browser(), vid); 157 return ui_test_utils::IsViewFocused(browser(), vid);
141 } 158 }
142 159
143 void ClickOnView(ViewID vid) { 160 void ClickOnView(ViewID vid) {
144 ui_test_utils::ClickOnView(browser(), vid); 161 ui_test_utils::ClickOnView(browser(), vid);
145 } 162 }
146 163
164 bool WaitForFocusChange(ViewID vid) {
165 const base::Time timeout = base::Time::Now() +
166 base::TimeDelta::FromMilliseconds(kFocusChangeTimeoutMs);
167 MessageLoop::current()->PostTask(
168 FROM_HERE,
169 base::Bind(&CheckFocus, browser(), vid, timeout));
170 ui_test_utils::RunMessageLoop();
171 return IsViewFocused(vid);
172 }
173
147 ViewID location_bar_focus_view_id_; 174 ViewID location_bar_focus_view_id_;
148 }; 175 };
149 176
150 class TestInterstitialPage : public InterstitialPage { 177 class TestInterstitialPage : public InterstitialPage {
151 public: 178 public:
152 TestInterstitialPage(TabContents* tab, bool new_navigation, const GURL& url) 179 TestInterstitialPage(TabContents* tab, bool new_navigation, const GURL& url)
153 : InterstitialPage(tab, new_navigation, url) { 180 : InterstitialPage(tab, new_navigation, url) {
154 FilePath file_path; 181 FilePath file_path;
155 bool r = PathService::Get(chrome::DIR_TEST_DATA, &file_path); 182 bool r = PathService::Get(chrome::DIR_TEST_DATA, &file_path);
156 EXPECT_TRUE(r); 183 EXPECT_TRUE(r);
(...skipping 593 matching lines...) Expand 10 before | Expand all | Expand 10 after
750 #if defined(OS_MACOSX) 777 #if defined(OS_MACOSX)
751 // Press Cmd+F, which will make the Find box open and request focus. 778 // Press Cmd+F, which will make the Find box open and request focus.
752 ASSERT_TRUE(ui_test_utils::SendKeyPressSync( 779 ASSERT_TRUE(ui_test_utils::SendKeyPressSync(
753 browser(), ui::VKEY_F, false, false, false, true)); 780 browser(), ui::VKEY_F, false, false, false, true));
754 #else 781 #else
755 // Press Ctrl+F, which will make the Find box open and request focus. 782 // Press Ctrl+F, which will make the Find box open and request focus.
756 ASSERT_TRUE(ui_test_utils::SendKeyPressSync( 783 ASSERT_TRUE(ui_test_utils::SendKeyPressSync(
757 browser(), ui::VKEY_F, true, false, false, false)); 784 browser(), ui::VKEY_F, true, false, false, false));
758 #endif 785 #endif
759 786
760 // Ideally, we wouldn't sleep here and instead would intercept the 787 ASSERT_TRUE(WaitForFocusChange(VIEW_ID_FIND_IN_PAGE_TEXT_FIELD));
761 // RenderViewHostDelegate::HandleKeyboardEvent() callback. To do that, we
762 // could create a RenderViewHostDelegate wrapper and hook-it up by either:
763 // - creating a factory used to create the delegate
764 // - making the test a private and overwriting the delegate member directly.
765 MessageLoop::current()->PostDelayedTask(
766 FROM_HERE, MessageLoop::QuitClosure(), kActionDelayMs);
767 ui_test_utils::RunMessageLoop();
768
769 ASSERT_TRUE(IsViewFocused(VIEW_ID_FIND_IN_PAGE_TEXT_FIELD));
770 788
771 browser()->FocusLocationBar(); 789 browser()->FocusLocationBar();
772 ASSERT_TRUE(IsViewFocused(location_bar_focus_view_id_)); 790 ASSERT_TRUE(IsViewFocused(location_bar_focus_view_id_));
773 791
774 // Now press Ctrl+F again and focus should move to the Find box. 792 // Now press Ctrl+F again and focus should move to the Find box.
775 #if defined(OS_MACOSX) 793 #if defined(OS_MACOSX)
776 ASSERT_TRUE(ui_test_utils::SendKeyPressSync( 794 ASSERT_TRUE(ui_test_utils::SendKeyPressSync(
777 browser(), ui::VKEY_F, false, false, false, true)); 795 browser(), ui::VKEY_F, false, false, false, true));
778 #else 796 #else
779 ASSERT_TRUE(ui_test_utils::SendKeyPressSync( 797 ASSERT_TRUE(ui_test_utils::SendKeyPressSync(
780 browser(), ui::VKEY_F, true, false, false, false)); 798 browser(), ui::VKEY_F, true, false, false, false));
781 #endif 799 #endif
782 ASSERT_TRUE(IsViewFocused(VIEW_ID_FIND_IN_PAGE_TEXT_FIELD)); 800 ASSERT_TRUE(IsViewFocused(VIEW_ID_FIND_IN_PAGE_TEXT_FIELD));
783 801
784 // Set focus to the page. 802 // Set focus to the page.
785 ClickOnView(VIEW_ID_TAB_CONTAINER); 803 ClickOnView(VIEW_ID_TAB_CONTAINER);
786 ASSERT_TRUE(IsViewFocused(VIEW_ID_TAB_CONTAINER_FOCUS_VIEW)); 804 ASSERT_TRUE(IsViewFocused(VIEW_ID_TAB_CONTAINER_FOCUS_VIEW));
787 805
788 // Now press Ctrl+F again and focus should move to the Find box. 806 // Now press Ctrl+F again and focus should move to the Find box.
789 #if defined(OS_MACOSX) 807 #if defined(OS_MACOSX)
790 ASSERT_TRUE(ui_test_utils::SendKeyPressSync( 808 ASSERT_TRUE(ui_test_utils::SendKeyPressSync(
791 browser(), ui::VKEY_F, false, false, false, true)); 809 browser(), ui::VKEY_F, false, false, false, true));
792 #else 810 #else
793 ASSERT_TRUE(ui_test_utils::SendKeyPressSync( 811 ASSERT_TRUE(ui_test_utils::SendKeyPressSync(
794 browser(), ui::VKEY_F, true, false, false, false)); 812 browser(), ui::VKEY_F, true, false, false, false));
795 #endif 813 #endif
796 814
797 // See remark above on why we wait. 815 ASSERT_TRUE(WaitForFocusChange(VIEW_ID_FIND_IN_PAGE_TEXT_FIELD));
798 MessageLoop::current()->PostDelayedTask(
799 FROM_HERE, MessageLoop::QuitClosure(), kActionDelayMs);
800 ui_test_utils::RunMessageLoop();
801 ASSERT_TRUE(IsViewFocused(VIEW_ID_FIND_IN_PAGE_TEXT_FIELD));
802 } 816 }
803 817
804 // Makes sure the focus is in the right location when opening the different 818 // Makes sure the focus is in the right location when opening the different
805 // types of tabs. 819 // types of tabs.
806 // Flaky, http://crbug.com/62539. 820 // Flaky, http://crbug.com/62539.
807 IN_PROC_BROWSER_TEST_F(BrowserFocusTest, FLAKY_TabInitialFocus) { 821 IN_PROC_BROWSER_TEST_F(BrowserFocusTest, FLAKY_TabInitialFocus) {
808 ASSERT_TRUE(ui_test_utils::BringBrowserWindowToFront(browser())); 822 ASSERT_TRUE(ui_test_utils::BringBrowserWindowToFront(browser()));
809 823
810 // Open the history tab, focus should be on the tab contents. 824 // Open the history tab, focus should be on the tab contents.
811 browser()->ShowHistoryTab(); 825 browser()->ShowHistoryTab();
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after
896 browser()->Reload(CURRENT_TAB); 910 browser()->Reload(CURRENT_TAB);
897 observer.Wait(); 911 observer.Wait();
898 } 912 }
899 913
900 // Focus should now be on the tab contents. 914 // Focus should now be on the tab contents.
901 browser()->ShowDownloadsTab(); 915 browser()->ShowDownloadsTab();
902 ASSERT_TRUE(IsViewFocused(VIEW_ID_TAB_CONTAINER_FOCUS_VIEW)); 916 ASSERT_TRUE(IsViewFocused(VIEW_ID_TAB_CONTAINER_FOCUS_VIEW));
903 } 917 }
904 918
905 } // namespace 919 } // namespace
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698