Chromium Code Reviews| 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 168 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 199 if (separators) | 200 if (separators) |
| 200 model_->SetSeparators(*separators); | 201 model_->SetSeparators(*separators); |
| 201 | 202 |
| 202 ASSERT_FALSE(combobox_); | 203 ASSERT_FALSE(combobox_); |
| 203 combobox_ = new TestCombobox(model_.get(), style); | 204 combobox_ = new TestCombobox(model_.get(), style); |
| 204 test_api_.reset(new ComboboxTestApi(combobox_)); | 205 test_api_.reset(new ComboboxTestApi(combobox_)); |
| 205 test_api_->InstallTestMenuRunner(&menu_show_count_); | 206 test_api_->InstallTestMenuRunner(&menu_show_count_); |
| 206 combobox_->set_id(1); | 207 combobox_->set_id(1); |
| 207 | 208 |
| 208 widget_ = new Widget; | 209 widget_ = new Widget; |
| 209 Widget::InitParams params = CreateParams(Widget::InitParams::TYPE_POPUP); | 210 Widget::InitParams params = |
| 211 CreateParams(Widget::InitParams::TYPE_WINDOW_FRAMELESS); | |
|
karandeepb
2017/01/11 08:16:20
Did not look into it, but tests fail with the Even
tapted
2017/01/11 14:54:20
I think popups have can_activate = false by defaul
karandeepb
2017/01/13 03:13:38
Acknowledged.
| |
| 210 params.bounds = gfx::Rect(200, 200, 200, 200); | 212 params.bounds = gfx::Rect(200, 200, 200, 200); |
| 211 widget_->Init(params); | 213 widget_->Init(params); |
| 212 View* container = new View(); | 214 View* container = new View(); |
| 213 widget_->SetContentsView(container); | 215 widget_->SetContentsView(container); |
| 214 container->AddChildView(combobox_); | 216 container->AddChildView(combobox_); |
| 215 widget_->Show(); | 217 widget_->Show(); |
| 216 | 218 |
| 217 combobox_->RequestFocus(); | 219 combobox_->RequestFocus(); |
| 218 combobox_->SizeToPreferredSize(); | 220 combobox_->SizeToPreferredSize(); |
| 221 | |
| 222 event_generator_.reset( | |
|
tapted
2017/01/11 14:54:20
event_generator_ = base::MakeUnique<..EventGenerat
karandeepb
2017/01/13 03:13:38
Done.
| |
| 223 new ui::test::EventGenerator(widget_->GetNativeWindow())); | |
| 224 event_generator_->set_target(ui::test::EventGenerator::Target::WINDOW); | |
| 219 } | 225 } |
| 220 | 226 |
| 221 protected: | 227 protected: |
| 222 void SendKeyEvent(ui::KeyboardCode key_code) { | 228 void PressKey(ui::KeyboardCode key_code) { |
| 223 SendKeyEventWithType(key_code, ui::ET_KEY_PRESSED); | 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 = |
| 312 CreateParams(Widget::InitParams::TYPE_WINDOW_FRAMELESS); | |
| 308 params.bounds = gfx::Rect(100, 100, 100, 100); | 313 params.bounds = gfx::Rect(100, 100, 100, 100); |
| 309 widget_->Init(params); | 314 widget_->Init(params); |
| 310 View* container = new View(); | 315 View* container = new View(); |
| 311 widget_->SetContentsView(container); | 316 widget_->SetContentsView(container); |
| 312 container->AddChildView(combobox_); | 317 container->AddChildView(combobox_); |
| 313 EXPECT_FALSE(combobox_->enabled()); | 318 EXPECT_FALSE(combobox_->enabled()); |
| 314 } | 319 } |
| 315 | 320 |
| 316 // Verifies that we don't select a separator line in combobox when navigating | 321 // Verifies that we don't select a separator line in combobox when navigating |
| 317 // through keyboard. | 322 // through keyboard. |
| 318 TEST_F(ComboboxTest, SkipSeparatorSimple) { | 323 TEST_F(ComboboxTest, SkipSeparatorSimple) { |
| 319 std::set<int> separators; | 324 std::set<int> separators; |
| 320 separators.insert(2); | 325 separators.insert(2); |
| 321 InitCombobox(&separators, Combobox::STYLE_NORMAL); | 326 InitCombobox(&separators, Combobox::STYLE_NORMAL); |
| 322 EXPECT_EQ(0, combobox_->selected_index()); | 327 EXPECT_EQ(0, combobox_->selected_index()); |
| 323 SendKeyEvent(ui::VKEY_DOWN); | 328 PressKey(ui::VKEY_DOWN); |
| 324 EXPECT_EQ(1, combobox_->selected_index()); | 329 EXPECT_EQ(1, combobox_->selected_index()); |
| 325 SendKeyEvent(ui::VKEY_DOWN); | 330 PressKey(ui::VKEY_DOWN); |
| 326 EXPECT_EQ(3, combobox_->selected_index()); | 331 EXPECT_EQ(3, combobox_->selected_index()); |
| 327 SendKeyEvent(ui::VKEY_UP); | 332 PressKey(ui::VKEY_UP); |
| 328 EXPECT_EQ(1, combobox_->selected_index()); | 333 EXPECT_EQ(1, combobox_->selected_index()); |
| 329 SendKeyEvent(ui::VKEY_HOME); | 334 PressKey(ui::VKEY_HOME); |
| 330 EXPECT_EQ(0, combobox_->selected_index()); | 335 EXPECT_EQ(0, combobox_->selected_index()); |
| 331 SendKeyEvent(ui::VKEY_PRIOR); | 336 PressKey(ui::VKEY_PRIOR); |
| 332 EXPECT_EQ(0, combobox_->selected_index()); | 337 EXPECT_EQ(0, combobox_->selected_index()); |
| 333 SendKeyEvent(ui::VKEY_END); | 338 PressKey(ui::VKEY_END); |
| 334 EXPECT_EQ(9, combobox_->selected_index()); | 339 EXPECT_EQ(9, combobox_->selected_index()); |
| 335 } | 340 } |
| 336 | 341 |
| 337 // Verifies that we never select the separator that is in the beginning of the | 342 // Verifies that we never select the separator that is in the beginning of the |
| 338 // combobox list when navigating through keyboard. | 343 // combobox list when navigating through keyboard. |
| 339 TEST_F(ComboboxTest, SkipSeparatorBeginning) { | 344 TEST_F(ComboboxTest, SkipSeparatorBeginning) { |
| 340 std::set<int> separators; | 345 std::set<int> separators; |
| 341 separators.insert(0); | 346 separators.insert(0); |
| 342 InitCombobox(&separators, Combobox::STYLE_NORMAL); | 347 InitCombobox(&separators, Combobox::STYLE_NORMAL); |
| 343 EXPECT_EQ(1, combobox_->selected_index()); | 348 EXPECT_EQ(1, combobox_->selected_index()); |
| 344 SendKeyEvent(ui::VKEY_DOWN); | 349 PressKey(ui::VKEY_DOWN); |
| 345 EXPECT_EQ(2, combobox_->selected_index()); | 350 EXPECT_EQ(2, combobox_->selected_index()); |
| 346 SendKeyEvent(ui::VKEY_DOWN); | 351 PressKey(ui::VKEY_DOWN); |
| 347 EXPECT_EQ(3, combobox_->selected_index()); | 352 EXPECT_EQ(3, combobox_->selected_index()); |
| 348 SendKeyEvent(ui::VKEY_UP); | 353 PressKey(ui::VKEY_UP); |
| 349 EXPECT_EQ(2, combobox_->selected_index()); | 354 EXPECT_EQ(2, combobox_->selected_index()); |
| 350 SendKeyEvent(ui::VKEY_HOME); | 355 PressKey(ui::VKEY_HOME); |
| 351 EXPECT_EQ(1, combobox_->selected_index()); | 356 EXPECT_EQ(1, combobox_->selected_index()); |
| 352 SendKeyEvent(ui::VKEY_PRIOR); | 357 PressKey(ui::VKEY_PRIOR); |
| 353 EXPECT_EQ(1, combobox_->selected_index()); | 358 EXPECT_EQ(1, combobox_->selected_index()); |
| 354 SendKeyEvent(ui::VKEY_END); | 359 PressKey(ui::VKEY_END); |
| 355 EXPECT_EQ(9, combobox_->selected_index()); | 360 EXPECT_EQ(9, combobox_->selected_index()); |
| 356 } | 361 } |
| 357 | 362 |
| 358 // Verifies that we never select the separator that is in the end of the | 363 // Verifies that we never select the separator that is in the end of the |
| 359 // combobox list when navigating through keyboard. | 364 // combobox list when navigating through keyboard. |
| 360 TEST_F(ComboboxTest, SkipSeparatorEnd) { | 365 TEST_F(ComboboxTest, SkipSeparatorEnd) { |
| 361 std::set<int> separators; | 366 std::set<int> separators; |
| 362 separators.insert(TestComboboxModel::kItemCount - 1); | 367 separators.insert(TestComboboxModel::kItemCount - 1); |
| 363 InitCombobox(&separators, Combobox::STYLE_NORMAL); | 368 InitCombobox(&separators, Combobox::STYLE_NORMAL); |
| 364 combobox_->SetSelectedIndex(8); | 369 combobox_->SetSelectedIndex(8); |
| 365 SendKeyEvent(ui::VKEY_DOWN); | 370 PressKey(ui::VKEY_DOWN); |
| 366 EXPECT_EQ(8, combobox_->selected_index()); | 371 EXPECT_EQ(8, combobox_->selected_index()); |
| 367 SendKeyEvent(ui::VKEY_UP); | 372 PressKey(ui::VKEY_UP); |
| 368 EXPECT_EQ(7, combobox_->selected_index()); | 373 EXPECT_EQ(7, combobox_->selected_index()); |
| 369 SendKeyEvent(ui::VKEY_END); | 374 PressKey(ui::VKEY_END); |
| 370 EXPECT_EQ(8, combobox_->selected_index()); | 375 EXPECT_EQ(8, combobox_->selected_index()); |
| 371 } | 376 } |
| 372 | 377 |
| 373 // Verifies that we never select any of the adjacent separators (multiple | 378 // Verifies that we never select any of the adjacent separators (multiple |
| 374 // consecutive) that appear in the beginning of the combobox list when | 379 // consecutive) that appear in the beginning of the combobox list when |
| 375 // navigating through keyboard. | 380 // navigating through keyboard. |
| 376 TEST_F(ComboboxTest, SkipMultipleSeparatorsAtBeginning) { | 381 TEST_F(ComboboxTest, SkipMultipleSeparatorsAtBeginning) { |
| 377 std::set<int> separators; | 382 std::set<int> separators; |
| 378 separators.insert(0); | 383 separators.insert(0); |
| 379 separators.insert(1); | 384 separators.insert(1); |
| 380 separators.insert(2); | 385 separators.insert(2); |
| 381 InitCombobox(&separators, Combobox::STYLE_NORMAL); | 386 InitCombobox(&separators, Combobox::STYLE_NORMAL); |
| 382 EXPECT_EQ(3, combobox_->selected_index()); | 387 EXPECT_EQ(3, combobox_->selected_index()); |
| 383 SendKeyEvent(ui::VKEY_DOWN); | 388 PressKey(ui::VKEY_DOWN); |
| 384 EXPECT_EQ(4, combobox_->selected_index()); | 389 EXPECT_EQ(4, combobox_->selected_index()); |
| 385 SendKeyEvent(ui::VKEY_UP); | 390 PressKey(ui::VKEY_UP); |
| 386 EXPECT_EQ(3, combobox_->selected_index()); | 391 EXPECT_EQ(3, combobox_->selected_index()); |
| 387 SendKeyEvent(ui::VKEY_NEXT); | 392 PressKey(ui::VKEY_NEXT); |
| 388 EXPECT_EQ(9, combobox_->selected_index()); | 393 EXPECT_EQ(9, combobox_->selected_index()); |
| 389 SendKeyEvent(ui::VKEY_HOME); | 394 PressKey(ui::VKEY_HOME); |
| 390 EXPECT_EQ(3, combobox_->selected_index()); | 395 EXPECT_EQ(3, combobox_->selected_index()); |
| 391 SendKeyEvent(ui::VKEY_END); | 396 PressKey(ui::VKEY_END); |
| 392 EXPECT_EQ(9, combobox_->selected_index()); | 397 EXPECT_EQ(9, combobox_->selected_index()); |
| 393 SendKeyEvent(ui::VKEY_PRIOR); | 398 PressKey(ui::VKEY_PRIOR); |
| 394 EXPECT_EQ(3, combobox_->selected_index()); | 399 EXPECT_EQ(3, combobox_->selected_index()); |
| 395 } | 400 } |
| 396 | 401 |
| 397 // Verifies that we never select any of the adjacent separators (multiple | 402 // Verifies that we never select any of the adjacent separators (multiple |
| 398 // consecutive) that appear in the middle of the combobox list when navigating | 403 // consecutive) that appear in the middle of the combobox list when navigating |
| 399 // through keyboard. | 404 // through keyboard. |
| 400 TEST_F(ComboboxTest, SkipMultipleAdjacentSeparatorsAtMiddle) { | 405 TEST_F(ComboboxTest, SkipMultipleAdjacentSeparatorsAtMiddle) { |
| 401 std::set<int> separators; | 406 std::set<int> separators; |
| 402 separators.insert(4); | 407 separators.insert(4); |
| 403 separators.insert(5); | 408 separators.insert(5); |
| 404 separators.insert(6); | 409 separators.insert(6); |
| 405 InitCombobox(&separators, Combobox::STYLE_NORMAL); | 410 InitCombobox(&separators, Combobox::STYLE_NORMAL); |
| 406 combobox_->SetSelectedIndex(3); | 411 combobox_->SetSelectedIndex(3); |
| 407 SendKeyEvent(ui::VKEY_DOWN); | 412 PressKey(ui::VKEY_DOWN); |
| 408 EXPECT_EQ(7, combobox_->selected_index()); | 413 EXPECT_EQ(7, combobox_->selected_index()); |
| 409 SendKeyEvent(ui::VKEY_UP); | 414 PressKey(ui::VKEY_UP); |
| 410 EXPECT_EQ(3, combobox_->selected_index()); | 415 EXPECT_EQ(3, combobox_->selected_index()); |
| 411 } | 416 } |
| 412 | 417 |
| 413 // Verifies that we never select any of the adjacent separators (multiple | 418 // Verifies that we never select any of the adjacent separators (multiple |
| 414 // consecutive) that appear in the end of the combobox list when navigating | 419 // consecutive) that appear in the end of the combobox list when navigating |
| 415 // through keyboard. | 420 // through keyboard. |
| 416 TEST_F(ComboboxTest, SkipMultipleSeparatorsAtEnd) { | 421 TEST_F(ComboboxTest, SkipMultipleSeparatorsAtEnd) { |
| 417 std::set<int> separators; | 422 std::set<int> separators; |
| 418 separators.insert(7); | 423 separators.insert(7); |
| 419 separators.insert(8); | 424 separators.insert(8); |
| 420 separators.insert(9); | 425 separators.insert(9); |
| 421 InitCombobox(&separators, Combobox::STYLE_NORMAL); | 426 InitCombobox(&separators, Combobox::STYLE_NORMAL); |
| 422 combobox_->SetSelectedIndex(6); | 427 combobox_->SetSelectedIndex(6); |
| 423 SendKeyEvent(ui::VKEY_DOWN); | 428 PressKey(ui::VKEY_DOWN); |
| 424 EXPECT_EQ(6, combobox_->selected_index()); | 429 EXPECT_EQ(6, combobox_->selected_index()); |
| 425 SendKeyEvent(ui::VKEY_UP); | 430 PressKey(ui::VKEY_UP); |
| 426 EXPECT_EQ(5, combobox_->selected_index()); | 431 EXPECT_EQ(5, combobox_->selected_index()); |
| 427 SendKeyEvent(ui::VKEY_HOME); | 432 PressKey(ui::VKEY_HOME); |
| 428 EXPECT_EQ(0, combobox_->selected_index()); | 433 EXPECT_EQ(0, combobox_->selected_index()); |
| 429 SendKeyEvent(ui::VKEY_NEXT); | 434 PressKey(ui::VKEY_NEXT); |
| 430 EXPECT_EQ(6, combobox_->selected_index()); | 435 EXPECT_EQ(6, combobox_->selected_index()); |
| 431 SendKeyEvent(ui::VKEY_PRIOR); | 436 PressKey(ui::VKEY_PRIOR); |
| 432 EXPECT_EQ(0, combobox_->selected_index()); | 437 EXPECT_EQ(0, combobox_->selected_index()); |
| 433 SendKeyEvent(ui::VKEY_END); | 438 PressKey(ui::VKEY_END); |
| 434 EXPECT_EQ(6, combobox_->selected_index()); | 439 EXPECT_EQ(6, combobox_->selected_index()); |
| 435 } | 440 } |
| 436 | 441 |
| 437 TEST_F(ComboboxTest, GetTextForRowTest) { | 442 TEST_F(ComboboxTest, GetTextForRowTest) { |
| 438 std::set<int> separators; | 443 std::set<int> separators; |
| 439 separators.insert(0); | 444 separators.insert(0); |
| 440 separators.insert(1); | 445 separators.insert(1); |
| 441 separators.insert(9); | 446 separators.insert(9); |
| 442 InitCombobox(&separators, Combobox::STYLE_NORMAL); | 447 InitCombobox(&separators, Combobox::STYLE_NORMAL); |
| 443 for (int i = 0; i < combobox_->GetRowCount(); ++i) { | 448 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()); | 540 EXPECT_EQ(0, menu_show_count()); |
| 536 } | 541 } |
| 537 | 542 |
| 538 TEST_F(ComboboxTest, NotifyOnClickWithReturnKey) { | 543 TEST_F(ComboboxTest, NotifyOnClickWithReturnKey) { |
| 539 InitCombobox(nullptr, Combobox::STYLE_NORMAL); | 544 InitCombobox(nullptr, Combobox::STYLE_NORMAL); |
| 540 | 545 |
| 541 TestComboboxListener listener; | 546 TestComboboxListener listener; |
| 542 combobox_->set_listener(&listener); | 547 combobox_->set_listener(&listener); |
| 543 | 548 |
| 544 // With STYLE_NORMAL, the click event is ignored. Instead the menu is shown. | 549 // With STYLE_NORMAL, the click event is ignored. Instead the menu is shown. |
| 545 SendKeyEvent(ui::VKEY_RETURN); | 550 PressKey(ui::VKEY_RETURN); |
| 546 EXPECT_EQ(1, menu_show_count()); | 551 EXPECT_EQ(1, menu_show_count()); |
| 547 EXPECT_FALSE(listener.on_perform_action_called()); | 552 EXPECT_FALSE(listener.on_perform_action_called()); |
| 548 } | 553 } |
| 549 | 554 |
| 550 TEST_F(ComboboxTest, NotifyOnClickWithReturnKeyActionStyle) { | 555 TEST_F(ComboboxTest, NotifyOnClickWithReturnKeyActionStyle) { |
| 551 InitCombobox(nullptr, Combobox::STYLE_ACTION); | 556 InitCombobox(nullptr, Combobox::STYLE_ACTION); |
| 552 | 557 |
| 553 TestComboboxListener listener; | 558 TestComboboxListener listener; |
| 554 combobox_->set_listener(&listener); | 559 combobox_->set_listener(&listener); |
| 555 | 560 |
| 556 // With STYLE_ACTION, the click event is notified and the menu is not shown. | 561 // With STYLE_ACTION, the click event is notified and the menu is not shown. |
| 557 SendKeyEvent(ui::VKEY_RETURN); | 562 PressKey(ui::VKEY_RETURN); |
| 558 EXPECT_EQ(0, menu_show_count()); | 563 EXPECT_EQ(0, menu_show_count()); |
| 559 EXPECT_TRUE(listener.on_perform_action_called()); | 564 EXPECT_TRUE(listener.on_perform_action_called()); |
| 560 EXPECT_EQ(0, listener.perform_action_index()); | 565 EXPECT_EQ(0, listener.perform_action_index()); |
| 561 } | 566 } |
| 562 | 567 |
| 563 TEST_F(ComboboxTest, NotifyOnClickWithSpaceKey) { | 568 TEST_F(ComboboxTest, NotifyOnClickWithSpaceKey) { |
| 564 InitCombobox(nullptr, Combobox::STYLE_NORMAL); | 569 InitCombobox(nullptr, Combobox::STYLE_NORMAL); |
| 565 | 570 |
| 566 TestComboboxListener listener; | 571 TestComboboxListener listener; |
| 567 combobox_->set_listener(&listener); | 572 combobox_->set_listener(&listener); |
| 568 | 573 |
| 569 // With STYLE_NORMAL, the click event is ignored. Instead the menu is shwon. | 574 // With STYLE_NORMAL, the click event is ignored. Instead the menu is shwon. |
| 570 SendKeyEvent(ui::VKEY_SPACE); | 575 PressKey(ui::VKEY_SPACE); |
| 571 EXPECT_EQ(1, menu_show_count()); | 576 EXPECT_EQ(1, menu_show_count()); |
| 572 EXPECT_FALSE(listener.on_perform_action_called()); | 577 EXPECT_FALSE(listener.on_perform_action_called()); |
| 573 | 578 |
| 574 SendKeyEventWithType(ui::VKEY_SPACE, ui::ET_KEY_RELEASED); | 579 ReleaseKey(ui::VKEY_SPACE); |
| 575 EXPECT_EQ(1, menu_show_count()); | 580 EXPECT_EQ(1, menu_show_count()); |
| 576 EXPECT_FALSE(listener.on_perform_action_called()); | 581 EXPECT_FALSE(listener.on_perform_action_called()); |
| 577 } | 582 } |
| 578 | 583 |
| 579 TEST_F(ComboboxTest, NotifyOnClickWithSpaceKeyActionStyle) { | 584 TEST_F(ComboboxTest, NotifyOnClickWithSpaceKeyActionStyle) { |
| 580 InitCombobox(nullptr, Combobox::STYLE_ACTION); | 585 InitCombobox(nullptr, Combobox::STYLE_ACTION); |
| 581 | 586 |
| 582 TestComboboxListener listener; | 587 TestComboboxListener listener; |
| 583 combobox_->set_listener(&listener); | 588 combobox_->set_listener(&listener); |
| 584 | 589 |
| 585 // With STYLE_ACTION, the click event is notified after releasing and the menu | 590 // With STYLE_ACTION, the click event is notified after releasing and the menu |
| 586 // is not shown. | 591 // is not shown. |
| 587 SendKeyEvent(ui::VKEY_SPACE); | 592 PressKey(ui::VKEY_SPACE); |
| 588 EXPECT_EQ(0, menu_show_count()); | 593 EXPECT_EQ(0, menu_show_count()); |
| 589 EXPECT_FALSE(listener.on_perform_action_called()); | 594 EXPECT_FALSE(listener.on_perform_action_called()); |
| 590 | 595 |
| 591 SendKeyEventWithType(ui::VKEY_SPACE, ui::ET_KEY_RELEASED); | 596 ReleaseKey(ui::VKEY_SPACE); |
| 592 EXPECT_EQ(0, menu_show_count()); | 597 EXPECT_EQ(0, menu_show_count()); |
| 593 EXPECT_TRUE(listener.on_perform_action_called()); | 598 EXPECT_TRUE(listener.on_perform_action_called()); |
| 594 EXPECT_EQ(0, listener.perform_action_index()); | 599 EXPECT_EQ(0, listener.perform_action_index()); |
| 595 } | 600 } |
| 596 | 601 |
| 597 TEST_F(ComboboxTest, NotifyOnClickWithMouse) { | 602 TEST_F(ComboboxTest, NotifyOnClickWithMouse) { |
| 598 InitCombobox(nullptr, Combobox::STYLE_ACTION); | 603 InitCombobox(nullptr, Combobox::STYLE_ACTION); |
| 599 | 604 |
| 600 TestComboboxListener listener; | 605 TestComboboxListener listener; |
| 601 combobox_->set_listener(&listener); | 606 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)); | 831 EXPECT_EQ(ui::MenuModel::TYPE_COMMAND, menu_model->GetTypeAt(0)); |
| 827 EXPECT_EQ(ui::MenuModel::TYPE_COMMAND, menu_model->GetTypeAt(1)); | 832 EXPECT_EQ(ui::MenuModel::TYPE_COMMAND, menu_model->GetTypeAt(1)); |
| 828 | 833 |
| 829 EXPECT_EQ(ASCIIToUTF16("PEANUT BUTTER"), menu_model->GetLabelAt(0)); | 834 EXPECT_EQ(ASCIIToUTF16("PEANUT BUTTER"), menu_model->GetLabelAt(0)); |
| 830 EXPECT_EQ(ASCIIToUTF16("JELLY"), menu_model->GetLabelAt(1)); | 835 EXPECT_EQ(ASCIIToUTF16("JELLY"), menu_model->GetLabelAt(1)); |
| 831 EXPECT_FALSE(menu_model->IsVisibleAt(0)); | 836 EXPECT_FALSE(menu_model->IsVisibleAt(0)); |
| 832 EXPECT_TRUE(menu_model->IsVisibleAt(1)); | 837 EXPECT_TRUE(menu_model->IsVisibleAt(1)); |
| 833 } | 838 } |
| 834 | 839 |
| 835 } // namespace views | 840 } // namespace views |
| OLD | NEW |