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

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

Issue 10702029: Move tab functions off Browser into browser_tabstrip and browser_tabrestore. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 8 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) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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/basictypes.h" 7 #include "base/basictypes.h"
8 #include "base/logging.h" 8 #include "base/logging.h"
9 #include "base/message_loop.h" 9 #include "base/message_loop.h"
10 #include "base/stringprintf.h" 10 #include "base/stringprintf.h"
11 #include "base/utf_string_conversions.h" 11 #include "base/utf_string_conversions.h"
12 #include "base/values.h" 12 #include "base/values.h"
13 #include "chrome/browser/ui/browser.h" 13 #include "chrome/browser/ui/browser.h"
14 #include "chrome/browser/ui/browser_tabstrip.h"
14 #include "chrome/common/chrome_notification_types.h" 15 #include "chrome/common/chrome_notification_types.h"
15 #include "chrome/common/chrome_paths.h" 16 #include "chrome/common/chrome_paths.h"
16 #include "chrome/test/base/in_process_browser_test.h" 17 #include "chrome/test/base/in_process_browser_test.h"
17 #include "chrome/test/base/ui_test_utils.h" 18 #include "chrome/test/base/ui_test_utils.h"
18 #include "content/public/browser/dom_operation_notification_details.h" 19 #include "content/public/browser/dom_operation_notification_details.h"
19 #include "content/public/browser/notification_registrar.h" 20 #include "content/public/browser/notification_registrar.h"
20 #include "content/public/browser/notification_service.h" 21 #include "content/public/browser/notification_service.h"
21 #include "content/public/browser/render_view_host.h" 22 #include "content/public/browser/render_view_host.h"
22 #include "content/public/browser/render_widget_host_view.h" 23 #include "content/public/browser/render_widget_host_view.h"
23 #include "content/public/browser/web_contents.h" 24 #include "content/public/browser/web_contents.h"
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after
139 ui_test_utils::ClickOnView(browser(), vid); 140 ui_test_utils::ClickOnView(browser(), vid);
140 } 141 }
141 142
142 // Set the suppress flag of an event specified by |type|. If |suppress| is 143 // Set the suppress flag of an event specified by |type|. If |suppress| is
143 // true then the web page will suppress all events with |type|. Following 144 // true then the web page will suppress all events with |type|. Following
144 // event types are supported: keydown, keypress, keyup and textInput. 145 // event types are supported: keydown, keypress, keyup and textInput.
145 void SuppressEventByType(int tab_index, const wchar_t* type, bool suppress) { 146 void SuppressEventByType(int tab_index, const wchar_t* type, bool suppress) {
146 ASSERT_LT(tab_index, browser()->tab_count()); 147 ASSERT_LT(tab_index, browser()->tab_count());
147 bool actual; 148 bool actual;
148 ASSERT_TRUE(ui_test_utils::ExecuteJavaScriptAndExtractBool( 149 ASSERT_TRUE(ui_test_utils::ExecuteJavaScriptAndExtractBool(
149 browser()->GetWebContentsAt(tab_index)->GetRenderViewHost(), 150 chrome::GetWebContentsAt(browser(), tab_index)->GetRenderViewHost(),
150 L"", 151 L"",
151 base::StringPrintf(kSuppressEventJS, type, GetBoolString(!suppress)), 152 base::StringPrintf(kSuppressEventJS, type, GetBoolString(!suppress)),
152 &actual)); 153 &actual));
153 ASSERT_EQ(!suppress, actual); 154 ASSERT_EQ(!suppress, actual);
154 } 155 }
155 156
156 void SuppressEvents(int tab_index, bool keydown, bool keypress, 157 void SuppressEvents(int tab_index, bool keydown, bool keypress,
157 bool keyup, bool textinput) { 158 bool keyup, bool textinput) {
158 ASSERT_NO_FATAL_FAILURE( 159 ASSERT_NO_FATAL_FAILURE(
159 SuppressEventByType(tab_index, L"keydown", keydown)); 160 SuppressEventByType(tab_index, L"keydown", keydown));
160 ASSERT_NO_FATAL_FAILURE( 161 ASSERT_NO_FATAL_FAILURE(
161 SuppressEventByType(tab_index, L"keypress", keypress)); 162 SuppressEventByType(tab_index, L"keypress", keypress));
162 ASSERT_NO_FATAL_FAILURE( 163 ASSERT_NO_FATAL_FAILURE(
163 SuppressEventByType(tab_index, L"keyup", keyup)); 164 SuppressEventByType(tab_index, L"keyup", keyup));
164 ASSERT_NO_FATAL_FAILURE( 165 ASSERT_NO_FATAL_FAILURE(
165 SuppressEventByType(tab_index, L"textInput", textinput)); 166 SuppressEventByType(tab_index, L"textInput", textinput));
166 } 167 }
167 168
168 void SuppressAllEvents(int tab_index, bool suppress) { 169 void SuppressAllEvents(int tab_index, bool suppress) {
169 SuppressEvents(tab_index, suppress, suppress, suppress, suppress); 170 SuppressEvents(tab_index, suppress, suppress, suppress, suppress);
170 } 171 }
171 172
172 void GetResultLength(int tab_index, int* length) { 173 void GetResultLength(int tab_index, int* length) {
173 ASSERT_LT(tab_index, browser()->tab_count()); 174 ASSERT_LT(tab_index, browser()->tab_count());
174 ASSERT_TRUE(ui_test_utils::ExecuteJavaScriptAndExtractInt( 175 ASSERT_TRUE(ui_test_utils::ExecuteJavaScriptAndExtractInt(
175 browser()->GetWebContentsAt(tab_index)->GetRenderViewHost(), 176 chrome::GetWebContentsAt(browser(), tab_index)->GetRenderViewHost(),
176 L"", kGetResultLengthJS, length)); 177 L"", kGetResultLengthJS, length));
177 } 178 }
178 179
179 void CheckResult(int tab_index, int length, const char* const result[]) { 180 void CheckResult(int tab_index, int length, const char* const result[]) {
180 ASSERT_LT(tab_index, browser()->tab_count()); 181 ASSERT_LT(tab_index, browser()->tab_count());
181 int actual_length; 182 int actual_length;
182 ASSERT_NO_FATAL_FAILURE(GetResultLength(tab_index, &actual_length)); 183 ASSERT_NO_FATAL_FAILURE(GetResultLength(tab_index, &actual_length));
183 ASSERT_GE(actual_length, length); 184 ASSERT_GE(actual_length, length);
184 for (int i = 0; i < actual_length; ++i) { 185 for (int i = 0; i < actual_length; ++i) {
185 std::string actual; 186 std::string actual;
186 ASSERT_TRUE(ui_test_utils::ExecuteJavaScriptAndExtractString( 187 ASSERT_TRUE(ui_test_utils::ExecuteJavaScriptAndExtractString(
187 browser()->GetWebContentsAt(tab_index)->GetRenderViewHost(), 188 chrome::GetWebContentsAt(browser(), tab_index)->GetRenderViewHost(),
188 L"", base::StringPrintf(kGetResultJS, i), &actual)); 189 L"", base::StringPrintf(kGetResultJS, i), &actual));
189 190
190 // If more events were received than expected, then the additional events 191 // If more events were received than expected, then the additional events
191 // must be keyup events. 192 // must be keyup events.
192 if (i < length) 193 if (i < length)
193 ASSERT_STREQ(result[i], actual.c_str()); 194 ASSERT_STREQ(result[i], actual.c_str());
194 else 195 else
195 ASSERT_EQ('U', actual[0]); 196 ASSERT_EQ('U', actual[0]);
196 } 197 }
197 } 198 }
198 199
199 void CheckFocusedElement(int tab_index, const wchar_t* focused) { 200 void CheckFocusedElement(int tab_index, const wchar_t* focused) {
200 ASSERT_LT(tab_index, browser()->tab_count()); 201 ASSERT_LT(tab_index, browser()->tab_count());
201 std::string actual; 202 std::string actual;
202 ASSERT_TRUE(ui_test_utils::ExecuteJavaScriptAndExtractString( 203 ASSERT_TRUE(ui_test_utils::ExecuteJavaScriptAndExtractString(
203 browser()->GetWebContentsAt(tab_index)->GetRenderViewHost(), 204 chrome::GetWebContentsAt(browser(), tab_index)->GetRenderViewHost(),
204 L"", kGetFocusedElementJS, &actual)); 205 L"", kGetFocusedElementJS, &actual));
205 ASSERT_EQ(WideToUTF8(focused), actual); 206 ASSERT_EQ(WideToUTF8(focused), actual);
206 } 207 }
207 208
208 void SetFocusedElement(int tab_index, const wchar_t* focused) { 209 void SetFocusedElement(int tab_index, const wchar_t* focused) {
209 ASSERT_LT(tab_index, browser()->tab_count()); 210 ASSERT_LT(tab_index, browser()->tab_count());
210 bool actual; 211 bool actual;
211 ASSERT_TRUE(ui_test_utils::ExecuteJavaScriptAndExtractBool( 212 ASSERT_TRUE(ui_test_utils::ExecuteJavaScriptAndExtractBool(
212 browser()->GetWebContentsAt(tab_index)->GetRenderViewHost(), 213 chrome::GetWebContentsAt(browser(), tab_index)->GetRenderViewHost(),
213 L"", 214 L"",
214 base::StringPrintf(kSetFocusedElementJS, focused), 215 base::StringPrintf(kSetFocusedElementJS, focused),
215 &actual)); 216 &actual));
216 ASSERT_TRUE(actual); 217 ASSERT_TRUE(actual);
217 } 218 }
218 219
219 void CheckTextBoxValue(int tab_index, const wchar_t* id, 220 void CheckTextBoxValue(int tab_index, const wchar_t* id,
220 const wchar_t* value) { 221 const wchar_t* value) {
221 ASSERT_LT(tab_index, browser()->tab_count()); 222 ASSERT_LT(tab_index, browser()->tab_count());
222 std::string actual; 223 std::string actual;
223 ASSERT_TRUE(ui_test_utils::ExecuteJavaScriptAndExtractString( 224 ASSERT_TRUE(ui_test_utils::ExecuteJavaScriptAndExtractString(
224 browser()->GetWebContentsAt(tab_index)->GetRenderViewHost(), 225 chrome::GetWebContentsAt(browser(), tab_index)->GetRenderViewHost(),
225 L"", 226 L"",
226 base::StringPrintf(kGetTextBoxValueJS, id), 227 base::StringPrintf(kGetTextBoxValueJS, id),
227 &actual)); 228 &actual));
228 ASSERT_EQ(WideToUTF8(value), actual); 229 ASSERT_EQ(WideToUTF8(value), actual);
229 } 230 }
230 231
231 void SetTextBoxValue(int tab_index, const wchar_t* id, 232 void SetTextBoxValue(int tab_index, const wchar_t* id,
232 const wchar_t* value) { 233 const wchar_t* value) {
233 ASSERT_LT(tab_index, browser()->tab_count()); 234 ASSERT_LT(tab_index, browser()->tab_count());
234 std::string actual; 235 std::string actual;
235 ASSERT_TRUE(ui_test_utils::ExecuteJavaScriptAndExtractString( 236 ASSERT_TRUE(ui_test_utils::ExecuteJavaScriptAndExtractString(
236 browser()->GetWebContentsAt(tab_index)->GetRenderViewHost(), 237 chrome::GetWebContentsAt(browser(), tab_index)->GetRenderViewHost(),
237 L"", 238 L"",
238 base::StringPrintf(kSetTextBoxValueJS, id, value), 239 base::StringPrintf(kSetTextBoxValueJS, id, value),
239 &actual)); 240 &actual));
240 ASSERT_EQ(WideToUTF8(value), actual); 241 ASSERT_EQ(WideToUTF8(value), actual);
241 } 242 }
242 243
243 void StartTest(int tab_index, int result_length) { 244 void StartTest(int tab_index, int result_length) {
244 ASSERT_LT(tab_index, browser()->tab_count()); 245 ASSERT_LT(tab_index, browser()->tab_count());
245 bool actual; 246 bool actual;
246 ASSERT_TRUE(ui_test_utils::ExecuteJavaScriptAndExtractBool( 247 ASSERT_TRUE(ui_test_utils::ExecuteJavaScriptAndExtractBool(
247 browser()->GetWebContentsAt(tab_index)->GetRenderViewHost(), 248 chrome::GetWebContentsAt(browser(), tab_index)->GetRenderViewHost(),
248 L"", base::StringPrintf(kStartTestJS, result_length), &actual)); 249 L"", base::StringPrintf(kStartTestJS, result_length), &actual));
249 ASSERT_TRUE(actual); 250 ASSERT_TRUE(actual);
250 } 251 }
251 252
252 void TestKeyEvent(int tab_index, const KeyEventTestData& test) { 253 void TestKeyEvent(int tab_index, const KeyEventTestData& test) {
253 ASSERT_LT(tab_index, browser()->tab_count()); 254 ASSERT_LT(tab_index, browser()->tab_count());
254 ASSERT_EQ(tab_index, browser()->active_index()); 255 ASSERT_EQ(tab_index, browser()->active_index());
255 256
256 // Inform our testing web page that we are about to start testing a key 257 // Inform our testing web page that we are about to start testing a key
257 // event. 258 // event.
258 ASSERT_NO_FATAL_FAILURE(StartTest(tab_index, test.result_length)); 259 ASSERT_NO_FATAL_FAILURE(StartTest(tab_index, test.result_length));
259 ASSERT_NO_FATAL_FAILURE(SuppressEvents( 260 ASSERT_NO_FATAL_FAILURE(SuppressEvents(
260 tab_index, test.suppress_keydown, test.suppress_keypress, 261 tab_index, test.suppress_keydown, test.suppress_keypress,
261 test.suppress_keyup, test.suppress_textinput)); 262 test.suppress_keyup, test.suppress_textinput));
262 263
263 // We need to create a finish observer before sending the key event, 264 // We need to create a finish observer before sending the key event,
264 // because the test finished message might be arrived before returning 265 // because the test finished message might be arrived before returning
265 // from the SendKeyPressSync() method. 266 // from the SendKeyPressSync() method.
266 TestFinishObserver finish_observer( 267 TestFinishObserver finish_observer(
267 browser()->GetWebContentsAt(tab_index)->GetRenderViewHost()); 268 chrome::GetWebContentsAt(browser(), tab_index)->GetRenderViewHost());
268 269
269 ASSERT_TRUE(ui_test_utils::SendKeyPressSync( 270 ASSERT_TRUE(ui_test_utils::SendKeyPressSync(
270 browser(), test.key, test.ctrl, test.shift, test.alt, test.command)); 271 browser(), test.key, test.ctrl, test.shift, test.alt, test.command));
271 ASSERT_TRUE(finish_observer.WaitForFinish()); 272 ASSERT_TRUE(finish_observer.WaitForFinish());
272 ASSERT_NO_FATAL_FAILURE(CheckResult( 273 ASSERT_NO_FATAL_FAILURE(CheckResult(
273 tab_index, test.result_length, test.result)); 274 tab_index, test.result_length, test.result));
274 } 275 }
275 276
276 std::string GetTestDataDescription(const KeyEventTestData& data) { 277 std::string GetTestDataDescription(const KeyEventTestData& data) {
277 std::string desc = base::StringPrintf( 278 std::string desc = base::StringPrintf(
(...skipping 452 matching lines...) Expand 10 before | Expand all | Expand 10 after
730 731
731 // Make sure the focus is in the testing page. 732 // Make sure the focus is in the testing page.
732 ASSERT_NO_FATAL_FAILURE(ClickOnView(VIEW_ID_TAB_CONTAINER)); 733 ASSERT_NO_FATAL_FAILURE(ClickOnView(VIEW_ID_TAB_CONTAINER));
733 ASSERT_TRUE(IsViewFocused(VIEW_ID_TAB_CONTAINER)); 734 ASSERT_TRUE(IsViewFocused(VIEW_ID_TAB_CONTAINER));
734 735
735 // Reserved accelerators can't be suppressed. 736 // Reserved accelerators can't be suppressed.
736 ASSERT_NO_FATAL_FAILURE(SuppressAllEvents(1, true)); 737 ASSERT_NO_FATAL_FAILURE(SuppressAllEvents(1, true));
737 738
738 ui_test_utils::WindowedNotificationObserver wait_for_tab_closed( 739 ui_test_utils::WindowedNotificationObserver wait_for_tab_closed(
739 content::NOTIFICATION_WEB_CONTENTS_DESTROYED, 740 content::NOTIFICATION_WEB_CONTENTS_DESTROYED,
740 content::Source<content::WebContents>(browser()->GetWebContentsAt(1))); 741 content::Source<content::WebContents>(chrome::GetWebContentsAt(browser(), 1)));
741 742
742 // Press Ctrl/Cmd+W, which will close the tab. 743 // Press Ctrl/Cmd+W, which will close the tab.
743 #if defined(OS_MACOSX) 744 #if defined(OS_MACOSX)
744 ASSERT_TRUE(ui_test_utils::SendKeyPressSync( 745 ASSERT_TRUE(ui_test_utils::SendKeyPressSync(
745 browser(), ui::VKEY_W, false, false, false, true)); 746 browser(), ui::VKEY_W, false, false, false, true));
746 #else 747 #else
747 ASSERT_TRUE(ui_test_utils::SendKeyPressSync( 748 ASSERT_TRUE(ui_test_utils::SendKeyPressSync(
748 browser(), ui::VKEY_W, true, false, false, false)); 749 browser(), ui::VKEY_W, true, false, false, false));
749 #endif 750 #endif
750 751
(...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after
882 EXPECT_NO_FATAL_FAILURE(TestKeyEvent(tab_index, kTestAltKeySuppress)); 883 EXPECT_NO_FATAL_FAILURE(TestKeyEvent(tab_index, kTestAltKeySuppress));
883 ASSERT_TRUE(IsViewFocused(VIEW_ID_TAB_CONTAINER)); 884 ASSERT_TRUE(IsViewFocused(VIEW_ID_TAB_CONTAINER));
884 885
885 // Ctrl+Alt should have no effect. 886 // Ctrl+Alt should have no effect.
886 EXPECT_NO_FATAL_FAILURE(TestKeyEvent(tab_index, kTestCtrlAltKey)); 887 EXPECT_NO_FATAL_FAILURE(TestKeyEvent(tab_index, kTestCtrlAltKey));
887 ASSERT_TRUE(IsViewFocused(VIEW_ID_TAB_CONTAINER)); 888 ASSERT_TRUE(IsViewFocused(VIEW_ID_TAB_CONTAINER));
888 } 889 }
889 #endif 890 #endif
890 891
891 } // namespace 892 } // namespace
OLDNEW
« no previous file with comments | « chrome/browser/browser_focus_uitest.cc ('k') | chrome/browser/captive_portal/captive_portal_browsertest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698