OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 "ui/views/controls/combobox/combobox.h" | 5 #include "ui/views/controls/combobox/combobox.h" |
6 | 6 |
7 #include <set> | 7 #include <set> |
8 | 8 |
9 #include "base/macros.h" | 9 #include "base/macros.h" |
10 #include "base/strings/utf_string_conversions.h" | 10 #include "base/strings/utf_string_conversions.h" |
11 #include "build/build_config.h" | 11 #include "build/build_config.h" |
12 #include "ui/base/ime/input_method.h" | 12 #include "ui/base/ime/input_method.h" |
13 #include "ui/base/ime/text_input_client.h" | 13 #include "ui/base/ime/text_input_client.h" |
14 #include "ui/base/models/combobox_model.h" | 14 #include "ui/base/models/combobox_model.h" |
15 #include "ui/base/models/menu_model.h" | 15 #include "ui/base/models/menu_model.h" |
16 #include "ui/events/event.h" | 16 #include "ui/events/event.h" |
17 #include "ui/events/event_constants.h" | 17 #include "ui/events/event_constants.h" |
18 #include "ui/events/event_utils.h" | 18 #include "ui/events/event_utils.h" |
19 #include "ui/events/keycodes/dom/dom_code.h" | 19 #include "ui/events/keycodes/dom/dom_code.h" |
20 #include "ui/events/keycodes/keyboard_codes.h" | 20 #include "ui/events/keycodes/keyboard_codes.h" |
| 21 #include "ui/events/test/event_generator.h" |
21 #include "ui/views/controls/combobox/combobox_listener.h" | 22 #include "ui/views/controls/combobox/combobox_listener.h" |
22 #include "ui/views/test/combobox_test_api.h" | 23 #include "ui/views/test/combobox_test_api.h" |
23 #include "ui/views/test/views_test_base.h" | 24 #include "ui/views/test/views_test_base.h" |
24 #include "ui/views/widget/widget.h" | 25 #include "ui/views/widget/widget.h" |
25 | 26 |
26 using base::ASCIIToUTF16; | 27 using base::ASCIIToUTF16; |
27 | 28 |
28 namespace views { | 29 namespace views { |
29 | 30 |
30 using test::ComboboxTestApi; | 31 using test::ComboboxTestApi; |
(...skipping 178 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
209 Widget::InitParams params = CreateParams(Widget::InitParams::TYPE_POPUP); | 210 Widget::InitParams params = CreateParams(Widget::InitParams::TYPE_POPUP); |
210 params.bounds = gfx::Rect(200, 200, 200, 200); | 211 params.bounds = gfx::Rect(200, 200, 200, 200); |
211 widget_->Init(params); | 212 widget_->Init(params); |
212 View* container = new View(); | 213 View* container = new View(); |
213 widget_->SetContentsView(container); | 214 widget_->SetContentsView(container); |
214 container->AddChildView(combobox_); | 215 container->AddChildView(combobox_); |
215 widget_->Show(); | 216 widget_->Show(); |
216 | 217 |
217 combobox_->RequestFocus(); | 218 combobox_->RequestFocus(); |
218 combobox_->SizeToPreferredSize(); | 219 combobox_->SizeToPreferredSize(); |
| 220 |
| 221 event_generator_.reset( |
| 222 new ui::test::EventGenerator(widget_->GetNativeWindow())); |
| 223 event_generator_->set_target(ui::test::EventGenerator::Target::WINDOW); |
219 } | 224 } |
220 | 225 |
221 protected: | 226 protected: |
222 void SendKeyEvent(ui::KeyboardCode key_code) { | 227 |
223 SendKeyEventWithType(key_code, ui::ET_KEY_PRESSED); | 228 void PressKey(ui::KeyboardCode key_code) { |
| 229 event_generator_->PressKey(key_code, ui::EF_NONE); |
224 } | 230 } |
225 | 231 |
226 void SendKeyEventWithType(ui::KeyboardCode key_code, ui::EventType type) { | 232 void ReleaseKey(ui::KeyboardCode key_code) { |
227 ui::KeyEvent event(type, key_code, ui::EF_NONE); | 233 event_generator_->ReleaseKey(key_code, ui::EF_NONE); |
228 FocusManager* focus_manager = widget_->GetFocusManager(); | |
229 widget_->OnKeyEvent(&event); | |
230 if (!event.handled() && focus_manager) | |
231 focus_manager->OnKeyEvent(event); | |
232 } | 234 } |
233 | 235 |
234 View* GetFocusedView() { | 236 View* GetFocusedView() { |
235 return widget_->GetFocusManager()->GetFocusedView(); | 237 return widget_->GetFocusManager()->GetFocusedView(); |
236 } | 238 } |
237 | 239 |
238 void PerformMousePress(const gfx::Point& point) { | 240 void PerformMousePress(const gfx::Point& point) { |
239 ui::MouseEvent pressed_event = ui::MouseEvent( | 241 ui::MouseEvent pressed_event = ui::MouseEvent( |
240 ui::ET_MOUSE_PRESSED, point, point, ui::EventTimeForNow(), | 242 ui::ET_MOUSE_PRESSED, point, point, ui::EventTimeForNow(), |
241 ui::EF_LEFT_MOUSE_BUTTON, ui::EF_LEFT_MOUSE_BUTTON); | 243 ui::EF_LEFT_MOUSE_BUTTON, ui::EF_LEFT_MOUSE_BUTTON); |
(...skipping 20 matching lines...) Expand all Loading... |
262 // |combobox_| will be allocated InitCombobox() and then owned by |widget_|. | 264 // |combobox_| will be allocated InitCombobox() and then owned by |widget_|. |
263 TestCombobox* combobox_; | 265 TestCombobox* combobox_; |
264 std::unique_ptr<ComboboxTestApi> test_api_; | 266 std::unique_ptr<ComboboxTestApi> test_api_; |
265 | 267 |
266 // Combobox does not take ownership of the model, hence it needs to be scoped. | 268 // Combobox does not take ownership of the model, hence it needs to be scoped. |
267 std::unique_ptr<TestComboboxModel> model_; | 269 std::unique_ptr<TestComboboxModel> model_; |
268 | 270 |
269 // The current menu show count. | 271 // The current menu show count. |
270 int menu_show_count_; | 272 int menu_show_count_; |
271 | 273 |
| 274 std::unique_ptr<ui::test::EventGenerator> event_generator_; |
| 275 |
272 private: | 276 private: |
273 DISALLOW_COPY_AND_ASSIGN(ComboboxTest); | 277 DISALLOW_COPY_AND_ASSIGN(ComboboxTest); |
274 }; | 278 }; |
275 | 279 |
276 TEST_F(ComboboxTest, KeyTest) { | 280 TEST_F(ComboboxTest, KeyTest) { |
277 InitCombobox(nullptr, Combobox::STYLE_NORMAL); | 281 InitCombobox(nullptr, Combobox::STYLE_NORMAL); |
278 SendKeyEvent(ui::VKEY_END); | 282 PressKey(ui::VKEY_END); |
279 EXPECT_EQ(combobox_->selected_index() + 1, model_->GetItemCount()); | 283 EXPECT_EQ(combobox_->selected_index() + 1, model_->GetItemCount()); |
280 SendKeyEvent(ui::VKEY_HOME); | 284 PressKey(ui::VKEY_HOME); |
281 EXPECT_EQ(combobox_->selected_index(), 0); | 285 EXPECT_EQ(combobox_->selected_index(), 0); |
282 SendKeyEvent(ui::VKEY_DOWN); | 286 PressKey(ui::VKEY_DOWN); |
283 SendKeyEvent(ui::VKEY_DOWN); | 287 PressKey(ui::VKEY_DOWN); |
284 EXPECT_EQ(combobox_->selected_index(), 2); | 288 EXPECT_EQ(combobox_->selected_index(), 2); |
285 SendKeyEvent(ui::VKEY_RIGHT); | 289 PressKey(ui::VKEY_RIGHT); |
286 EXPECT_EQ(combobox_->selected_index(), 2); | 290 EXPECT_EQ(combobox_->selected_index(), 2); |
287 SendKeyEvent(ui::VKEY_LEFT); | 291 PressKey(ui::VKEY_LEFT); |
288 EXPECT_EQ(combobox_->selected_index(), 2); | 292 EXPECT_EQ(combobox_->selected_index(), 2); |
289 SendKeyEvent(ui::VKEY_UP); | 293 PressKey(ui::VKEY_UP); |
290 EXPECT_EQ(combobox_->selected_index(), 1); | 294 EXPECT_EQ(combobox_->selected_index(), 1); |
291 SendKeyEvent(ui::VKEY_PRIOR); | 295 PressKey(ui::VKEY_PRIOR); |
292 EXPECT_EQ(combobox_->selected_index(), 0); | 296 EXPECT_EQ(combobox_->selected_index(), 0); |
293 SendKeyEvent(ui::VKEY_NEXT); | 297 PressKey(ui::VKEY_NEXT); |
294 EXPECT_EQ(combobox_->selected_index(), model_->GetItemCount() - 1); | 298 EXPECT_EQ(combobox_->selected_index(), model_->GetItemCount() - 1); |
295 } | 299 } |
296 | 300 |
297 // Check that if a combobox is disabled before it has a native wrapper, then the | 301 // Check that if a combobox is disabled before it has a native wrapper, then the |
298 // native wrapper inherits the disabled state when it gets created. | 302 // native wrapper inherits the disabled state when it gets created. |
299 TEST_F(ComboboxTest, DisabilityTest) { | 303 TEST_F(ComboboxTest, DisabilityTest) { |
300 model_.reset(new TestComboboxModel()); | 304 model_.reset(new TestComboboxModel()); |
301 | 305 |
302 ASSERT_FALSE(combobox_); | 306 ASSERT_FALSE(combobox_); |
303 combobox_ = new TestCombobox(model_.get(), Combobox::STYLE_NORMAL); | 307 combobox_ = new TestCombobox(model_.get(), Combobox::STYLE_NORMAL); |
304 combobox_->SetEnabled(false); | 308 combobox_->SetEnabled(false); |
305 | 309 |
306 widget_ = new Widget; | 310 widget_ = new Widget; |
307 Widget::InitParams params = CreateParams(Widget::InitParams::TYPE_POPUP); | 311 Widget::InitParams params = CreateParams(Widget::InitParams::TYPE_POPUP); |
308 params.bounds = gfx::Rect(100, 100, 100, 100); | 312 params.bounds = gfx::Rect(100, 100, 100, 100); |
309 widget_->Init(params); | 313 widget_->Init(params); |
310 View* container = new View(); | 314 View* container = new View(); |
311 widget_->SetContentsView(container); | 315 widget_->SetContentsView(container); |
312 container->AddChildView(combobox_); | 316 container->AddChildView(combobox_); |
313 EXPECT_FALSE(combobox_->enabled()); | 317 EXPECT_FALSE(combobox_->enabled()); |
314 } | 318 } |
315 | 319 |
316 // Verifies that we don't select a separator line in combobox when navigating | 320 // Verifies that we don't select a separator line in combobox when navigating |
317 // through keyboard. | 321 // through keyboard. |
318 TEST_F(ComboboxTest, SkipSeparatorSimple) { | 322 TEST_F(ComboboxTest, SkipSeparatorSimple) { |
319 std::set<int> separators; | 323 std::set<int> separators; |
320 separators.insert(2); | 324 separators.insert(2); |
321 InitCombobox(&separators, Combobox::STYLE_NORMAL); | 325 InitCombobox(&separators, Combobox::STYLE_NORMAL); |
322 EXPECT_EQ(0, combobox_->selected_index()); | 326 EXPECT_EQ(0, combobox_->selected_index()); |
323 SendKeyEvent(ui::VKEY_DOWN); | 327 PressKey(ui::VKEY_DOWN); |
324 EXPECT_EQ(1, combobox_->selected_index()); | 328 EXPECT_EQ(1, combobox_->selected_index()); |
325 SendKeyEvent(ui::VKEY_DOWN); | 329 PressKey(ui::VKEY_DOWN); |
326 EXPECT_EQ(3, combobox_->selected_index()); | 330 EXPECT_EQ(3, combobox_->selected_index()); |
327 SendKeyEvent(ui::VKEY_UP); | 331 PressKey(ui::VKEY_UP); |
328 EXPECT_EQ(1, combobox_->selected_index()); | 332 EXPECT_EQ(1, combobox_->selected_index()); |
329 SendKeyEvent(ui::VKEY_HOME); | 333 PressKey(ui::VKEY_HOME); |
330 EXPECT_EQ(0, combobox_->selected_index()); | 334 EXPECT_EQ(0, combobox_->selected_index()); |
331 SendKeyEvent(ui::VKEY_PRIOR); | 335 PressKey(ui::VKEY_PRIOR); |
332 EXPECT_EQ(0, combobox_->selected_index()); | 336 EXPECT_EQ(0, combobox_->selected_index()); |
333 SendKeyEvent(ui::VKEY_END); | 337 PressKey(ui::VKEY_END); |
334 EXPECT_EQ(9, combobox_->selected_index()); | 338 EXPECT_EQ(9, combobox_->selected_index()); |
335 } | 339 } |
336 | 340 |
337 // Verifies that we never select the separator that is in the beginning of the | 341 // Verifies that we never select the separator that is in the beginning of the |
338 // combobox list when navigating through keyboard. | 342 // combobox list when navigating through keyboard. |
339 TEST_F(ComboboxTest, SkipSeparatorBeginning) { | 343 TEST_F(ComboboxTest, SkipSeparatorBeginning) { |
340 std::set<int> separators; | 344 std::set<int> separators; |
341 separators.insert(0); | 345 separators.insert(0); |
342 InitCombobox(&separators, Combobox::STYLE_NORMAL); | 346 InitCombobox(&separators, Combobox::STYLE_NORMAL); |
343 EXPECT_EQ(1, combobox_->selected_index()); | 347 EXPECT_EQ(1, combobox_->selected_index()); |
344 SendKeyEvent(ui::VKEY_DOWN); | 348 PressKey(ui::VKEY_DOWN); |
345 EXPECT_EQ(2, combobox_->selected_index()); | 349 EXPECT_EQ(2, combobox_->selected_index()); |
346 SendKeyEvent(ui::VKEY_DOWN); | 350 PressKey(ui::VKEY_DOWN); |
347 EXPECT_EQ(3, combobox_->selected_index()); | 351 EXPECT_EQ(3, combobox_->selected_index()); |
348 SendKeyEvent(ui::VKEY_UP); | 352 PressKey(ui::VKEY_UP); |
349 EXPECT_EQ(2, combobox_->selected_index()); | 353 EXPECT_EQ(2, combobox_->selected_index()); |
350 SendKeyEvent(ui::VKEY_HOME); | 354 PressKey(ui::VKEY_HOME); |
351 EXPECT_EQ(1, combobox_->selected_index()); | 355 EXPECT_EQ(1, combobox_->selected_index()); |
352 SendKeyEvent(ui::VKEY_PRIOR); | 356 PressKey(ui::VKEY_PRIOR); |
353 EXPECT_EQ(1, combobox_->selected_index()); | 357 EXPECT_EQ(1, combobox_->selected_index()); |
354 SendKeyEvent(ui::VKEY_END); | 358 PressKey(ui::VKEY_END); |
355 EXPECT_EQ(9, combobox_->selected_index()); | 359 EXPECT_EQ(9, combobox_->selected_index()); |
356 } | 360 } |
357 | 361 |
358 // Verifies that we never select the separator that is in the end of the | 362 // Verifies that we never select the separator that is in the end of the |
359 // combobox list when navigating through keyboard. | 363 // combobox list when navigating through keyboard. |
360 TEST_F(ComboboxTest, SkipSeparatorEnd) { | 364 TEST_F(ComboboxTest, SkipSeparatorEnd) { |
361 std::set<int> separators; | 365 std::set<int> separators; |
362 separators.insert(TestComboboxModel::kItemCount - 1); | 366 separators.insert(TestComboboxModel::kItemCount - 1); |
363 InitCombobox(&separators, Combobox::STYLE_NORMAL); | 367 InitCombobox(&separators, Combobox::STYLE_NORMAL); |
364 combobox_->SetSelectedIndex(8); | 368 combobox_->SetSelectedIndex(8); |
365 SendKeyEvent(ui::VKEY_DOWN); | 369 PressKey(ui::VKEY_DOWN); |
366 EXPECT_EQ(8, combobox_->selected_index()); | 370 EXPECT_EQ(8, combobox_->selected_index()); |
367 SendKeyEvent(ui::VKEY_UP); | 371 PressKey(ui::VKEY_UP); |
368 EXPECT_EQ(7, combobox_->selected_index()); | 372 EXPECT_EQ(7, combobox_->selected_index()); |
369 SendKeyEvent(ui::VKEY_END); | 373 PressKey(ui::VKEY_END); |
370 EXPECT_EQ(8, combobox_->selected_index()); | 374 EXPECT_EQ(8, combobox_->selected_index()); |
371 } | 375 } |
372 | 376 |
373 // Verifies that we never select any of the adjacent separators (multiple | 377 // Verifies that we never select any of the adjacent separators (multiple |
374 // consecutive) that appear in the beginning of the combobox list when | 378 // consecutive) that appear in the beginning of the combobox list when |
375 // navigating through keyboard. | 379 // navigating through keyboard. |
376 TEST_F(ComboboxTest, SkipMultipleSeparatorsAtBeginning) { | 380 TEST_F(ComboboxTest, SkipMultipleSeparatorsAtBeginning) { |
377 std::set<int> separators; | 381 std::set<int> separators; |
378 separators.insert(0); | 382 separators.insert(0); |
379 separators.insert(1); | 383 separators.insert(1); |
380 separators.insert(2); | 384 separators.insert(2); |
381 InitCombobox(&separators, Combobox::STYLE_NORMAL); | 385 InitCombobox(&separators, Combobox::STYLE_NORMAL); |
382 EXPECT_EQ(3, combobox_->selected_index()); | 386 EXPECT_EQ(3, combobox_->selected_index()); |
383 SendKeyEvent(ui::VKEY_DOWN); | 387 PressKey(ui::VKEY_DOWN); |
384 EXPECT_EQ(4, combobox_->selected_index()); | 388 EXPECT_EQ(4, combobox_->selected_index()); |
385 SendKeyEvent(ui::VKEY_UP); | 389 PressKey(ui::VKEY_UP); |
386 EXPECT_EQ(3, combobox_->selected_index()); | 390 EXPECT_EQ(3, combobox_->selected_index()); |
387 SendKeyEvent(ui::VKEY_NEXT); | 391 PressKey(ui::VKEY_NEXT); |
388 EXPECT_EQ(9, combobox_->selected_index()); | 392 EXPECT_EQ(9, combobox_->selected_index()); |
389 SendKeyEvent(ui::VKEY_HOME); | 393 PressKey(ui::VKEY_HOME); |
390 EXPECT_EQ(3, combobox_->selected_index()); | 394 EXPECT_EQ(3, combobox_->selected_index()); |
391 SendKeyEvent(ui::VKEY_END); | 395 PressKey(ui::VKEY_END); |
392 EXPECT_EQ(9, combobox_->selected_index()); | 396 EXPECT_EQ(9, combobox_->selected_index()); |
393 SendKeyEvent(ui::VKEY_PRIOR); | 397 PressKey(ui::VKEY_PRIOR); |
394 EXPECT_EQ(3, combobox_->selected_index()); | 398 EXPECT_EQ(3, combobox_->selected_index()); |
395 } | 399 } |
396 | 400 |
397 // Verifies that we never select any of the adjacent separators (multiple | 401 // Verifies that we never select any of the adjacent separators (multiple |
398 // consecutive) that appear in the middle of the combobox list when navigating | 402 // consecutive) that appear in the middle of the combobox list when navigating |
399 // through keyboard. | 403 // through keyboard. |
400 TEST_F(ComboboxTest, SkipMultipleAdjacentSeparatorsAtMiddle) { | 404 TEST_F(ComboboxTest, SkipMultipleAdjacentSeparatorsAtMiddle) { |
401 std::set<int> separators; | 405 std::set<int> separators; |
402 separators.insert(4); | 406 separators.insert(4); |
403 separators.insert(5); | 407 separators.insert(5); |
404 separators.insert(6); | 408 separators.insert(6); |
405 InitCombobox(&separators, Combobox::STYLE_NORMAL); | 409 InitCombobox(&separators, Combobox::STYLE_NORMAL); |
406 combobox_->SetSelectedIndex(3); | 410 combobox_->SetSelectedIndex(3); |
407 SendKeyEvent(ui::VKEY_DOWN); | 411 PressKey(ui::VKEY_DOWN); |
408 EXPECT_EQ(7, combobox_->selected_index()); | 412 EXPECT_EQ(7, combobox_->selected_index()); |
409 SendKeyEvent(ui::VKEY_UP); | 413 PressKey(ui::VKEY_UP); |
410 EXPECT_EQ(3, combobox_->selected_index()); | 414 EXPECT_EQ(3, combobox_->selected_index()); |
411 } | 415 } |
412 | 416 |
413 // Verifies that we never select any of the adjacent separators (multiple | 417 // Verifies that we never select any of the adjacent separators (multiple |
414 // consecutive) that appear in the end of the combobox list when navigating | 418 // consecutive) that appear in the end of the combobox list when navigating |
415 // through keyboard. | 419 // through keyboard. |
416 TEST_F(ComboboxTest, SkipMultipleSeparatorsAtEnd) { | 420 TEST_F(ComboboxTest, SkipMultipleSeparatorsAtEnd) { |
417 std::set<int> separators; | 421 std::set<int> separators; |
418 separators.insert(7); | 422 separators.insert(7); |
419 separators.insert(8); | 423 separators.insert(8); |
420 separators.insert(9); | 424 separators.insert(9); |
421 InitCombobox(&separators, Combobox::STYLE_NORMAL); | 425 InitCombobox(&separators, Combobox::STYLE_NORMAL); |
422 combobox_->SetSelectedIndex(6); | 426 combobox_->SetSelectedIndex(6); |
423 SendKeyEvent(ui::VKEY_DOWN); | 427 PressKey(ui::VKEY_DOWN); |
424 EXPECT_EQ(6, combobox_->selected_index()); | 428 EXPECT_EQ(6, combobox_->selected_index()); |
425 SendKeyEvent(ui::VKEY_UP); | 429 PressKey(ui::VKEY_UP); |
426 EXPECT_EQ(5, combobox_->selected_index()); | 430 EXPECT_EQ(5, combobox_->selected_index()); |
427 SendKeyEvent(ui::VKEY_HOME); | 431 PressKey(ui::VKEY_HOME); |
428 EXPECT_EQ(0, combobox_->selected_index()); | 432 EXPECT_EQ(0, combobox_->selected_index()); |
429 SendKeyEvent(ui::VKEY_NEXT); | 433 PressKey(ui::VKEY_NEXT); |
430 EXPECT_EQ(6, combobox_->selected_index()); | 434 EXPECT_EQ(6, combobox_->selected_index()); |
431 SendKeyEvent(ui::VKEY_PRIOR); | 435 PressKey(ui::VKEY_PRIOR); |
432 EXPECT_EQ(0, combobox_->selected_index()); | 436 EXPECT_EQ(0, combobox_->selected_index()); |
433 SendKeyEvent(ui::VKEY_END); | 437 PressKey(ui::VKEY_END); |
434 EXPECT_EQ(6, combobox_->selected_index()); | 438 EXPECT_EQ(6, combobox_->selected_index()); |
435 } | 439 } |
436 | 440 |
437 TEST_F(ComboboxTest, GetTextForRowTest) { | 441 TEST_F(ComboboxTest, GetTextForRowTest) { |
438 std::set<int> separators; | 442 std::set<int> separators; |
439 separators.insert(0); | 443 separators.insert(0); |
440 separators.insert(1); | 444 separators.insert(1); |
441 separators.insert(9); | 445 separators.insert(9); |
442 InitCombobox(&separators, Combobox::STYLE_NORMAL); | 446 InitCombobox(&separators, Combobox::STYLE_NORMAL); |
443 for (int i = 0; i < combobox_->GetRowCount(); ++i) { | 447 for (int i = 0; i < combobox_->GetRowCount(); ++i) { |
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
535 EXPECT_EQ(0, menu_show_count()); | 539 EXPECT_EQ(0, menu_show_count()); |
536 } | 540 } |
537 | 541 |
538 TEST_F(ComboboxTest, NotifyOnClickWithReturnKey) { | 542 TEST_F(ComboboxTest, NotifyOnClickWithReturnKey) { |
539 InitCombobox(nullptr, Combobox::STYLE_NORMAL); | 543 InitCombobox(nullptr, Combobox::STYLE_NORMAL); |
540 | 544 |
541 TestComboboxListener listener; | 545 TestComboboxListener listener; |
542 combobox_->set_listener(&listener); | 546 combobox_->set_listener(&listener); |
543 | 547 |
544 // With STYLE_NORMAL, the click event is ignored. Instead the menu is shown. | 548 // With STYLE_NORMAL, the click event is ignored. Instead the menu is shown. |
545 SendKeyEvent(ui::VKEY_RETURN); | 549 PressKey(ui::VKEY_RETURN); |
546 EXPECT_EQ(1, menu_show_count()); | 550 EXPECT_EQ(1, menu_show_count()); |
547 EXPECT_FALSE(listener.on_perform_action_called()); | 551 EXPECT_FALSE(listener.on_perform_action_called()); |
548 } | 552 } |
549 | 553 |
550 TEST_F(ComboboxTest, NotifyOnClickWithReturnKeyActionStyle) { | 554 TEST_F(ComboboxTest, NotifyOnClickWithReturnKeyActionStyle) { |
551 InitCombobox(nullptr, Combobox::STYLE_ACTION); | 555 InitCombobox(nullptr, Combobox::STYLE_ACTION); |
552 | 556 |
553 TestComboboxListener listener; | 557 TestComboboxListener listener; |
554 combobox_->set_listener(&listener); | 558 combobox_->set_listener(&listener); |
555 | 559 |
556 // With STYLE_ACTION, the click event is notified and the menu is not shown. | 560 // With STYLE_ACTION, the click event is notified and the menu is not shown. |
557 SendKeyEvent(ui::VKEY_RETURN); | 561 PressKey(ui::VKEY_RETURN); |
558 EXPECT_EQ(0, menu_show_count()); | 562 EXPECT_EQ(0, menu_show_count()); |
559 EXPECT_TRUE(listener.on_perform_action_called()); | 563 EXPECT_TRUE(listener.on_perform_action_called()); |
560 EXPECT_EQ(0, listener.perform_action_index()); | 564 EXPECT_EQ(0, listener.perform_action_index()); |
561 } | 565 } |
562 | 566 |
563 TEST_F(ComboboxTest, NotifyOnClickWithSpaceKey) { | 567 TEST_F(ComboboxTest, NotifyOnClickWithSpaceKey) { |
564 InitCombobox(nullptr, Combobox::STYLE_NORMAL); | 568 InitCombobox(nullptr, Combobox::STYLE_NORMAL); |
565 | 569 |
566 TestComboboxListener listener; | 570 TestComboboxListener listener; |
567 combobox_->set_listener(&listener); | 571 combobox_->set_listener(&listener); |
568 | 572 |
569 // With STYLE_NORMAL, the click event is ignored. Instead the menu is shwon. | 573 // With STYLE_NORMAL, the click event is ignored. Instead the menu is shwon. |
570 SendKeyEvent(ui::VKEY_SPACE); | 574 PressKey(ui::VKEY_SPACE); |
571 EXPECT_EQ(1, menu_show_count()); | 575 EXPECT_EQ(1, menu_show_count()); |
572 EXPECT_FALSE(listener.on_perform_action_called()); | 576 EXPECT_FALSE(listener.on_perform_action_called()); |
573 | 577 |
574 SendKeyEventWithType(ui::VKEY_SPACE, ui::ET_KEY_RELEASED); | 578 ReleaseKey(ui::VKEY_SPACE); |
575 EXPECT_EQ(1, menu_show_count()); | 579 EXPECT_EQ(1, menu_show_count()); |
576 EXPECT_FALSE(listener.on_perform_action_called()); | 580 EXPECT_FALSE(listener.on_perform_action_called()); |
577 } | 581 } |
578 | 582 |
579 TEST_F(ComboboxTest, NotifyOnClickWithSpaceKeyActionStyle) { | 583 TEST_F(ComboboxTest, NotifyOnClickWithSpaceKeyActionStyle) { |
580 InitCombobox(nullptr, Combobox::STYLE_ACTION); | 584 InitCombobox(nullptr, Combobox::STYLE_ACTION); |
581 | 585 |
582 TestComboboxListener listener; | 586 TestComboboxListener listener; |
583 combobox_->set_listener(&listener); | 587 combobox_->set_listener(&listener); |
584 | 588 |
585 // With STYLE_ACTION, the click event is notified after releasing and the menu | 589 // With STYLE_ACTION, the click event is notified after releasing and the menu |
586 // is not shown. | 590 // is not shown. |
587 SendKeyEvent(ui::VKEY_SPACE); | 591 PressKey(ui::VKEY_SPACE); |
588 EXPECT_EQ(0, menu_show_count()); | 592 EXPECT_EQ(0, menu_show_count()); |
589 EXPECT_FALSE(listener.on_perform_action_called()); | 593 EXPECT_FALSE(listener.on_perform_action_called()); |
590 | 594 |
591 SendKeyEventWithType(ui::VKEY_SPACE, ui::ET_KEY_RELEASED); | 595 ReleaseKey(ui::VKEY_SPACE); |
592 EXPECT_EQ(0, menu_show_count()); | 596 EXPECT_EQ(0, menu_show_count()); |
593 EXPECT_TRUE(listener.on_perform_action_called()); | 597 EXPECT_TRUE(listener.on_perform_action_called()); |
594 EXPECT_EQ(0, listener.perform_action_index()); | 598 EXPECT_EQ(0, listener.perform_action_index()); |
595 } | 599 } |
596 | 600 |
597 TEST_F(ComboboxTest, NotifyOnClickWithMouse) { | 601 TEST_F(ComboboxTest, NotifyOnClickWithMouse) { |
598 InitCombobox(nullptr, Combobox::STYLE_ACTION); | 602 InitCombobox(nullptr, Combobox::STYLE_ACTION); |
599 | 603 |
600 TestComboboxListener listener; | 604 TestComboboxListener listener; |
601 combobox_->set_listener(&listener); | 605 combobox_->set_listener(&listener); |
(...skipping 224 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
826 EXPECT_EQ(ui::MenuModel::TYPE_COMMAND, menu_model->GetTypeAt(0)); | 830 EXPECT_EQ(ui::MenuModel::TYPE_COMMAND, menu_model->GetTypeAt(0)); |
827 EXPECT_EQ(ui::MenuModel::TYPE_COMMAND, menu_model->GetTypeAt(1)); | 831 EXPECT_EQ(ui::MenuModel::TYPE_COMMAND, menu_model->GetTypeAt(1)); |
828 | 832 |
829 EXPECT_EQ(ASCIIToUTF16("PEANUT BUTTER"), menu_model->GetLabelAt(0)); | 833 EXPECT_EQ(ASCIIToUTF16("PEANUT BUTTER"), menu_model->GetLabelAt(0)); |
830 EXPECT_EQ(ASCIIToUTF16("JELLY"), menu_model->GetLabelAt(1)); | 834 EXPECT_EQ(ASCIIToUTF16("JELLY"), menu_model->GetLabelAt(1)); |
831 EXPECT_FALSE(menu_model->IsVisibleAt(0)); | 835 EXPECT_FALSE(menu_model->IsVisibleAt(0)); |
832 EXPECT_TRUE(menu_model->IsVisibleAt(1)); | 836 EXPECT_TRUE(menu_model->IsVisibleAt(1)); |
833 } | 837 } |
834 | 838 |
835 } // namespace views | 839 } // namespace views |
OLD | NEW |