| 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); |
| 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_ = |
| 223 base::MakeUnique<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 18 matching lines...) Expand all Loading... |
| 260 // |combobox_| will be allocated InitCombobox() and then owned by |widget_|. | 262 // |combobox_| will be allocated InitCombobox() and then owned by |widget_|. |
| 261 TestCombobox* combobox_ = nullptr; | 263 TestCombobox* combobox_ = nullptr; |
| 262 std::unique_ptr<ComboboxTestApi> test_api_; | 264 std::unique_ptr<ComboboxTestApi> test_api_; |
| 263 | 265 |
| 264 // Combobox does not take ownership of the model, hence it needs to be scoped. | 266 // Combobox does not take ownership of the model, hence it needs to be scoped. |
| 265 std::unique_ptr<TestComboboxModel> model_; | 267 std::unique_ptr<TestComboboxModel> model_; |
| 266 | 268 |
| 267 // The current menu show count. | 269 // The current menu show count. |
| 268 int menu_show_count_ = 0; | 270 int menu_show_count_ = 0; |
| 269 | 271 |
| 272 std::unique_ptr<ui::test::EventGenerator> event_generator_; |
| 273 |
| 270 private: | 274 private: |
| 271 DISALLOW_COPY_AND_ASSIGN(ComboboxTest); | 275 DISALLOW_COPY_AND_ASSIGN(ComboboxTest); |
| 272 }; | 276 }; |
| 273 | 277 |
| 274 TEST_F(ComboboxTest, KeyTest) { | 278 TEST_F(ComboboxTest, KeyTest) { |
| 275 InitCombobox(nullptr, Combobox::STYLE_NORMAL); | 279 InitCombobox(nullptr, Combobox::STYLE_NORMAL); |
| 276 SendKeyEvent(ui::VKEY_END); | 280 PressKey(ui::VKEY_END); |
| 277 EXPECT_EQ(combobox_->selected_index() + 1, model_->GetItemCount()); | 281 EXPECT_EQ(combobox_->selected_index() + 1, model_->GetItemCount()); |
| 278 SendKeyEvent(ui::VKEY_HOME); | 282 PressKey(ui::VKEY_HOME); |
| 279 EXPECT_EQ(combobox_->selected_index(), 0); | 283 EXPECT_EQ(combobox_->selected_index(), 0); |
| 280 SendKeyEvent(ui::VKEY_DOWN); | 284 PressKey(ui::VKEY_DOWN); |
| 281 SendKeyEvent(ui::VKEY_DOWN); | 285 PressKey(ui::VKEY_DOWN); |
| 282 EXPECT_EQ(combobox_->selected_index(), 2); | 286 EXPECT_EQ(combobox_->selected_index(), 2); |
| 283 SendKeyEvent(ui::VKEY_RIGHT); | 287 PressKey(ui::VKEY_RIGHT); |
| 284 EXPECT_EQ(combobox_->selected_index(), 2); | 288 EXPECT_EQ(combobox_->selected_index(), 2); |
| 285 SendKeyEvent(ui::VKEY_LEFT); | 289 PressKey(ui::VKEY_LEFT); |
| 286 EXPECT_EQ(combobox_->selected_index(), 2); | 290 EXPECT_EQ(combobox_->selected_index(), 2); |
| 287 SendKeyEvent(ui::VKEY_UP); | 291 PressKey(ui::VKEY_UP); |
| 288 EXPECT_EQ(combobox_->selected_index(), 1); | 292 EXPECT_EQ(combobox_->selected_index(), 1); |
| 289 SendKeyEvent(ui::VKEY_PRIOR); | 293 PressKey(ui::VKEY_PRIOR); |
| 290 EXPECT_EQ(combobox_->selected_index(), 0); | 294 EXPECT_EQ(combobox_->selected_index(), 0); |
| 291 SendKeyEvent(ui::VKEY_NEXT); | 295 PressKey(ui::VKEY_NEXT); |
| 292 EXPECT_EQ(combobox_->selected_index(), model_->GetItemCount() - 1); | 296 EXPECT_EQ(combobox_->selected_index(), model_->GetItemCount() - 1); |
| 293 } | 297 } |
| 294 | 298 |
| 295 // Check that if a combobox is disabled before it has a native wrapper, then the | 299 // Check that if a combobox is disabled before it has a native wrapper, then the |
| 296 // native wrapper inherits the disabled state when it gets created. | 300 // native wrapper inherits the disabled state when it gets created. |
| 297 TEST_F(ComboboxTest, DisabilityTest) { | 301 TEST_F(ComboboxTest, DisabilityTest) { |
| 298 model_.reset(new TestComboboxModel()); | 302 model_.reset(new TestComboboxModel()); |
| 299 | 303 |
| 300 ASSERT_FALSE(combobox_); | 304 ASSERT_FALSE(combobox_); |
| 301 combobox_ = new TestCombobox(model_.get(), Combobox::STYLE_NORMAL); | 305 combobox_ = new TestCombobox(model_.get(), Combobox::STYLE_NORMAL); |
| 302 combobox_->SetEnabled(false); | 306 combobox_->SetEnabled(false); |
| 303 | 307 |
| 304 widget_ = new Widget; | 308 widget_ = new Widget; |
| 305 Widget::InitParams params = CreateParams(Widget::InitParams::TYPE_POPUP); | 309 Widget::InitParams params = |
| 310 CreateParams(Widget::InitParams::TYPE_WINDOW_FRAMELESS); |
| 306 params.bounds = gfx::Rect(100, 100, 100, 100); | 311 params.bounds = gfx::Rect(100, 100, 100, 100); |
| 307 widget_->Init(params); | 312 widget_->Init(params); |
| 308 View* container = new View(); | 313 View* container = new View(); |
| 309 widget_->SetContentsView(container); | 314 widget_->SetContentsView(container); |
| 310 container->AddChildView(combobox_); | 315 container->AddChildView(combobox_); |
| 311 EXPECT_FALSE(combobox_->enabled()); | 316 EXPECT_FALSE(combobox_->enabled()); |
| 312 } | 317 } |
| 313 | 318 |
| 314 // Verifies that we don't select a separator line in combobox when navigating | 319 // Verifies that we don't select a separator line in combobox when navigating |
| 315 // through keyboard. | 320 // through keyboard. |
| 316 TEST_F(ComboboxTest, SkipSeparatorSimple) { | 321 TEST_F(ComboboxTest, SkipSeparatorSimple) { |
| 317 std::set<int> separators; | 322 std::set<int> separators; |
| 318 separators.insert(2); | 323 separators.insert(2); |
| 319 InitCombobox(&separators, Combobox::STYLE_NORMAL); | 324 InitCombobox(&separators, Combobox::STYLE_NORMAL); |
| 320 EXPECT_EQ(0, combobox_->selected_index()); | 325 EXPECT_EQ(0, combobox_->selected_index()); |
| 321 SendKeyEvent(ui::VKEY_DOWN); | 326 PressKey(ui::VKEY_DOWN); |
| 322 EXPECT_EQ(1, combobox_->selected_index()); | 327 EXPECT_EQ(1, combobox_->selected_index()); |
| 323 SendKeyEvent(ui::VKEY_DOWN); | 328 PressKey(ui::VKEY_DOWN); |
| 324 EXPECT_EQ(3, combobox_->selected_index()); | 329 EXPECT_EQ(3, combobox_->selected_index()); |
| 325 SendKeyEvent(ui::VKEY_UP); | 330 PressKey(ui::VKEY_UP); |
| 326 EXPECT_EQ(1, combobox_->selected_index()); | 331 EXPECT_EQ(1, combobox_->selected_index()); |
| 327 SendKeyEvent(ui::VKEY_HOME); | 332 PressKey(ui::VKEY_HOME); |
| 328 EXPECT_EQ(0, combobox_->selected_index()); | 333 EXPECT_EQ(0, combobox_->selected_index()); |
| 329 SendKeyEvent(ui::VKEY_PRIOR); | 334 PressKey(ui::VKEY_PRIOR); |
| 330 EXPECT_EQ(0, combobox_->selected_index()); | 335 EXPECT_EQ(0, combobox_->selected_index()); |
| 331 SendKeyEvent(ui::VKEY_END); | 336 PressKey(ui::VKEY_END); |
| 332 EXPECT_EQ(9, combobox_->selected_index()); | 337 EXPECT_EQ(9, combobox_->selected_index()); |
| 333 } | 338 } |
| 334 | 339 |
| 335 // Verifies that we never select the separator that is in the beginning of the | 340 // Verifies that we never select the separator that is in the beginning of the |
| 336 // combobox list when navigating through keyboard. | 341 // combobox list when navigating through keyboard. |
| 337 TEST_F(ComboboxTest, SkipSeparatorBeginning) { | 342 TEST_F(ComboboxTest, SkipSeparatorBeginning) { |
| 338 std::set<int> separators; | 343 std::set<int> separators; |
| 339 separators.insert(0); | 344 separators.insert(0); |
| 340 InitCombobox(&separators, Combobox::STYLE_NORMAL); | 345 InitCombobox(&separators, Combobox::STYLE_NORMAL); |
| 341 EXPECT_EQ(1, combobox_->selected_index()); | 346 EXPECT_EQ(1, combobox_->selected_index()); |
| 342 SendKeyEvent(ui::VKEY_DOWN); | 347 PressKey(ui::VKEY_DOWN); |
| 343 EXPECT_EQ(2, combobox_->selected_index()); | 348 EXPECT_EQ(2, combobox_->selected_index()); |
| 344 SendKeyEvent(ui::VKEY_DOWN); | 349 PressKey(ui::VKEY_DOWN); |
| 345 EXPECT_EQ(3, combobox_->selected_index()); | 350 EXPECT_EQ(3, combobox_->selected_index()); |
| 346 SendKeyEvent(ui::VKEY_UP); | 351 PressKey(ui::VKEY_UP); |
| 347 EXPECT_EQ(2, combobox_->selected_index()); | 352 EXPECT_EQ(2, combobox_->selected_index()); |
| 348 SendKeyEvent(ui::VKEY_HOME); | 353 PressKey(ui::VKEY_HOME); |
| 349 EXPECT_EQ(1, combobox_->selected_index()); | 354 EXPECT_EQ(1, combobox_->selected_index()); |
| 350 SendKeyEvent(ui::VKEY_PRIOR); | 355 PressKey(ui::VKEY_PRIOR); |
| 351 EXPECT_EQ(1, combobox_->selected_index()); | 356 EXPECT_EQ(1, combobox_->selected_index()); |
| 352 SendKeyEvent(ui::VKEY_END); | 357 PressKey(ui::VKEY_END); |
| 353 EXPECT_EQ(9, combobox_->selected_index()); | 358 EXPECT_EQ(9, combobox_->selected_index()); |
| 354 } | 359 } |
| 355 | 360 |
| 356 // Verifies that we never select the separator that is in the end of the | 361 // Verifies that we never select the separator that is in the end of the |
| 357 // combobox list when navigating through keyboard. | 362 // combobox list when navigating through keyboard. |
| 358 TEST_F(ComboboxTest, SkipSeparatorEnd) { | 363 TEST_F(ComboboxTest, SkipSeparatorEnd) { |
| 359 std::set<int> separators; | 364 std::set<int> separators; |
| 360 separators.insert(TestComboboxModel::kItemCount - 1); | 365 separators.insert(TestComboboxModel::kItemCount - 1); |
| 361 InitCombobox(&separators, Combobox::STYLE_NORMAL); | 366 InitCombobox(&separators, Combobox::STYLE_NORMAL); |
| 362 combobox_->SetSelectedIndex(8); | 367 combobox_->SetSelectedIndex(8); |
| 363 SendKeyEvent(ui::VKEY_DOWN); | 368 PressKey(ui::VKEY_DOWN); |
| 364 EXPECT_EQ(8, combobox_->selected_index()); | 369 EXPECT_EQ(8, combobox_->selected_index()); |
| 365 SendKeyEvent(ui::VKEY_UP); | 370 PressKey(ui::VKEY_UP); |
| 366 EXPECT_EQ(7, combobox_->selected_index()); | 371 EXPECT_EQ(7, combobox_->selected_index()); |
| 367 SendKeyEvent(ui::VKEY_END); | 372 PressKey(ui::VKEY_END); |
| 368 EXPECT_EQ(8, combobox_->selected_index()); | 373 EXPECT_EQ(8, combobox_->selected_index()); |
| 369 } | 374 } |
| 370 | 375 |
| 371 // Verifies that we never select any of the adjacent separators (multiple | 376 // Verifies that we never select any of the adjacent separators (multiple |
| 372 // consecutive) that appear in the beginning of the combobox list when | 377 // consecutive) that appear in the beginning of the combobox list when |
| 373 // navigating through keyboard. | 378 // navigating through keyboard. |
| 374 TEST_F(ComboboxTest, SkipMultipleSeparatorsAtBeginning) { | 379 TEST_F(ComboboxTest, SkipMultipleSeparatorsAtBeginning) { |
| 375 std::set<int> separators; | 380 std::set<int> separators; |
| 376 separators.insert(0); | 381 separators.insert(0); |
| 377 separators.insert(1); | 382 separators.insert(1); |
| 378 separators.insert(2); | 383 separators.insert(2); |
| 379 InitCombobox(&separators, Combobox::STYLE_NORMAL); | 384 InitCombobox(&separators, Combobox::STYLE_NORMAL); |
| 380 EXPECT_EQ(3, combobox_->selected_index()); | 385 EXPECT_EQ(3, combobox_->selected_index()); |
| 381 SendKeyEvent(ui::VKEY_DOWN); | 386 PressKey(ui::VKEY_DOWN); |
| 382 EXPECT_EQ(4, combobox_->selected_index()); | 387 EXPECT_EQ(4, combobox_->selected_index()); |
| 383 SendKeyEvent(ui::VKEY_UP); | 388 PressKey(ui::VKEY_UP); |
| 384 EXPECT_EQ(3, combobox_->selected_index()); | 389 EXPECT_EQ(3, combobox_->selected_index()); |
| 385 SendKeyEvent(ui::VKEY_NEXT); | 390 PressKey(ui::VKEY_NEXT); |
| 386 EXPECT_EQ(9, combobox_->selected_index()); | 391 EXPECT_EQ(9, combobox_->selected_index()); |
| 387 SendKeyEvent(ui::VKEY_HOME); | 392 PressKey(ui::VKEY_HOME); |
| 388 EXPECT_EQ(3, combobox_->selected_index()); | 393 EXPECT_EQ(3, combobox_->selected_index()); |
| 389 SendKeyEvent(ui::VKEY_END); | 394 PressKey(ui::VKEY_END); |
| 390 EXPECT_EQ(9, combobox_->selected_index()); | 395 EXPECT_EQ(9, combobox_->selected_index()); |
| 391 SendKeyEvent(ui::VKEY_PRIOR); | 396 PressKey(ui::VKEY_PRIOR); |
| 392 EXPECT_EQ(3, combobox_->selected_index()); | 397 EXPECT_EQ(3, combobox_->selected_index()); |
| 393 } | 398 } |
| 394 | 399 |
| 395 // Verifies that we never select any of the adjacent separators (multiple | 400 // Verifies that we never select any of the adjacent separators (multiple |
| 396 // consecutive) that appear in the middle of the combobox list when navigating | 401 // consecutive) that appear in the middle of the combobox list when navigating |
| 397 // through keyboard. | 402 // through keyboard. |
| 398 TEST_F(ComboboxTest, SkipMultipleAdjacentSeparatorsAtMiddle) { | 403 TEST_F(ComboboxTest, SkipMultipleAdjacentSeparatorsAtMiddle) { |
| 399 std::set<int> separators; | 404 std::set<int> separators; |
| 400 separators.insert(4); | 405 separators.insert(4); |
| 401 separators.insert(5); | 406 separators.insert(5); |
| 402 separators.insert(6); | 407 separators.insert(6); |
| 403 InitCombobox(&separators, Combobox::STYLE_NORMAL); | 408 InitCombobox(&separators, Combobox::STYLE_NORMAL); |
| 404 combobox_->SetSelectedIndex(3); | 409 combobox_->SetSelectedIndex(3); |
| 405 SendKeyEvent(ui::VKEY_DOWN); | 410 PressKey(ui::VKEY_DOWN); |
| 406 EXPECT_EQ(7, combobox_->selected_index()); | 411 EXPECT_EQ(7, combobox_->selected_index()); |
| 407 SendKeyEvent(ui::VKEY_UP); | 412 PressKey(ui::VKEY_UP); |
| 408 EXPECT_EQ(3, combobox_->selected_index()); | 413 EXPECT_EQ(3, combobox_->selected_index()); |
| 409 } | 414 } |
| 410 | 415 |
| 411 // Verifies that we never select any of the adjacent separators (multiple | 416 // Verifies that we never select any of the adjacent separators (multiple |
| 412 // consecutive) that appear in the end of the combobox list when navigating | 417 // consecutive) that appear in the end of the combobox list when navigating |
| 413 // through keyboard. | 418 // through keyboard. |
| 414 TEST_F(ComboboxTest, SkipMultipleSeparatorsAtEnd) { | 419 TEST_F(ComboboxTest, SkipMultipleSeparatorsAtEnd) { |
| 415 std::set<int> separators; | 420 std::set<int> separators; |
| 416 separators.insert(7); | 421 separators.insert(7); |
| 417 separators.insert(8); | 422 separators.insert(8); |
| 418 separators.insert(9); | 423 separators.insert(9); |
| 419 InitCombobox(&separators, Combobox::STYLE_NORMAL); | 424 InitCombobox(&separators, Combobox::STYLE_NORMAL); |
| 420 combobox_->SetSelectedIndex(6); | 425 combobox_->SetSelectedIndex(6); |
| 421 SendKeyEvent(ui::VKEY_DOWN); | 426 PressKey(ui::VKEY_DOWN); |
| 422 EXPECT_EQ(6, combobox_->selected_index()); | 427 EXPECT_EQ(6, combobox_->selected_index()); |
| 423 SendKeyEvent(ui::VKEY_UP); | 428 PressKey(ui::VKEY_UP); |
| 424 EXPECT_EQ(5, combobox_->selected_index()); | 429 EXPECT_EQ(5, combobox_->selected_index()); |
| 425 SendKeyEvent(ui::VKEY_HOME); | 430 PressKey(ui::VKEY_HOME); |
| 426 EXPECT_EQ(0, combobox_->selected_index()); | 431 EXPECT_EQ(0, combobox_->selected_index()); |
| 427 SendKeyEvent(ui::VKEY_NEXT); | 432 PressKey(ui::VKEY_NEXT); |
| 428 EXPECT_EQ(6, combobox_->selected_index()); | 433 EXPECT_EQ(6, combobox_->selected_index()); |
| 429 SendKeyEvent(ui::VKEY_PRIOR); | 434 PressKey(ui::VKEY_PRIOR); |
| 430 EXPECT_EQ(0, combobox_->selected_index()); | 435 EXPECT_EQ(0, combobox_->selected_index()); |
| 431 SendKeyEvent(ui::VKEY_END); | 436 PressKey(ui::VKEY_END); |
| 432 EXPECT_EQ(6, combobox_->selected_index()); | 437 EXPECT_EQ(6, combobox_->selected_index()); |
| 433 } | 438 } |
| 434 | 439 |
| 435 TEST_F(ComboboxTest, GetTextForRowTest) { | 440 TEST_F(ComboboxTest, GetTextForRowTest) { |
| 436 std::set<int> separators; | 441 std::set<int> separators; |
| 437 separators.insert(0); | 442 separators.insert(0); |
| 438 separators.insert(1); | 443 separators.insert(1); |
| 439 separators.insert(9); | 444 separators.insert(9); |
| 440 InitCombobox(&separators, Combobox::STYLE_NORMAL); | 445 InitCombobox(&separators, Combobox::STYLE_NORMAL); |
| 441 for (int i = 0; i < combobox_->GetRowCount(); ++i) { | 446 for (int i = 0; i < combobox_->GetRowCount(); ++i) { |
| (...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 533 EXPECT_EQ(0, menu_show_count_); | 538 EXPECT_EQ(0, menu_show_count_); |
| 534 } | 539 } |
| 535 | 540 |
| 536 TEST_F(ComboboxTest, NotifyOnClickWithReturnKey) { | 541 TEST_F(ComboboxTest, NotifyOnClickWithReturnKey) { |
| 537 InitCombobox(nullptr, Combobox::STYLE_NORMAL); | 542 InitCombobox(nullptr, Combobox::STYLE_NORMAL); |
| 538 | 543 |
| 539 TestComboboxListener listener; | 544 TestComboboxListener listener; |
| 540 combobox_->set_listener(&listener); | 545 combobox_->set_listener(&listener); |
| 541 | 546 |
| 542 // With STYLE_NORMAL, the click event is ignored. Instead the menu is shown. | 547 // With STYLE_NORMAL, the click event is ignored. Instead the menu is shown. |
| 543 SendKeyEvent(ui::VKEY_RETURN); | 548 PressKey(ui::VKEY_RETURN); |
| 544 EXPECT_EQ(1, menu_show_count_); | 549 EXPECT_EQ(1, menu_show_count_); |
| 545 EXPECT_FALSE(listener.on_perform_action_called()); | 550 EXPECT_FALSE(listener.on_perform_action_called()); |
| 546 } | 551 } |
| 547 | 552 |
| 548 TEST_F(ComboboxTest, NotifyOnClickWithReturnKeyActionStyle) { | 553 TEST_F(ComboboxTest, NotifyOnClickWithReturnKeyActionStyle) { |
| 549 InitCombobox(nullptr, Combobox::STYLE_ACTION); | 554 InitCombobox(nullptr, Combobox::STYLE_ACTION); |
| 550 | 555 |
| 551 TestComboboxListener listener; | 556 TestComboboxListener listener; |
| 552 combobox_->set_listener(&listener); | 557 combobox_->set_listener(&listener); |
| 553 | 558 |
| 554 // With STYLE_ACTION, the click event is notified and the menu is not shown. | 559 // With STYLE_ACTION, the click event is notified and the menu is not shown. |
| 555 SendKeyEvent(ui::VKEY_RETURN); | 560 PressKey(ui::VKEY_RETURN); |
| 556 EXPECT_EQ(0, menu_show_count_); | 561 EXPECT_EQ(0, menu_show_count_); |
| 557 EXPECT_TRUE(listener.on_perform_action_called()); | 562 EXPECT_TRUE(listener.on_perform_action_called()); |
| 558 EXPECT_EQ(0, listener.perform_action_index()); | 563 EXPECT_EQ(0, listener.perform_action_index()); |
| 559 } | 564 } |
| 560 | 565 |
| 561 TEST_F(ComboboxTest, NotifyOnClickWithSpaceKey) { | 566 TEST_F(ComboboxTest, NotifyOnClickWithSpaceKey) { |
| 562 InitCombobox(nullptr, Combobox::STYLE_NORMAL); | 567 InitCombobox(nullptr, Combobox::STYLE_NORMAL); |
| 563 | 568 |
| 564 TestComboboxListener listener; | 569 TestComboboxListener listener; |
| 565 combobox_->set_listener(&listener); | 570 combobox_->set_listener(&listener); |
| 566 | 571 |
| 567 // With STYLE_NORMAL, the click event is ignored. Instead the menu is shwon. | 572 // With STYLE_NORMAL, the click event is ignored. Instead the menu is shwon. |
| 568 SendKeyEvent(ui::VKEY_SPACE); | 573 PressKey(ui::VKEY_SPACE); |
| 569 EXPECT_EQ(1, menu_show_count_); | 574 EXPECT_EQ(1, menu_show_count_); |
| 570 EXPECT_FALSE(listener.on_perform_action_called()); | 575 EXPECT_FALSE(listener.on_perform_action_called()); |
| 571 | 576 |
| 572 SendKeyEventWithType(ui::VKEY_SPACE, ui::ET_KEY_RELEASED); | 577 ReleaseKey(ui::VKEY_SPACE); |
| 573 EXPECT_EQ(1, menu_show_count_); | 578 EXPECT_EQ(1, menu_show_count_); |
| 574 EXPECT_FALSE(listener.on_perform_action_called()); | 579 EXPECT_FALSE(listener.on_perform_action_called()); |
| 575 } | 580 } |
| 576 | 581 |
| 577 TEST_F(ComboboxTest, NotifyOnClickWithSpaceKeyActionStyle) { | 582 TEST_F(ComboboxTest, NotifyOnClickWithSpaceKeyActionStyle) { |
| 578 InitCombobox(nullptr, Combobox::STYLE_ACTION); | 583 InitCombobox(nullptr, Combobox::STYLE_ACTION); |
| 579 | 584 |
| 580 TestComboboxListener listener; | 585 TestComboboxListener listener; |
| 581 combobox_->set_listener(&listener); | 586 combobox_->set_listener(&listener); |
| 582 | 587 |
| 583 // With STYLE_ACTION, the click event is notified after releasing and the menu | 588 // With STYLE_ACTION, the click event is notified after releasing and the menu |
| 584 // is not shown. | 589 // is not shown. |
| 585 SendKeyEvent(ui::VKEY_SPACE); | 590 PressKey(ui::VKEY_SPACE); |
| 586 EXPECT_EQ(0, menu_show_count_); | 591 EXPECT_EQ(0, menu_show_count_); |
| 587 EXPECT_FALSE(listener.on_perform_action_called()); | 592 EXPECT_FALSE(listener.on_perform_action_called()); |
| 588 | 593 |
| 589 SendKeyEventWithType(ui::VKEY_SPACE, ui::ET_KEY_RELEASED); | 594 ReleaseKey(ui::VKEY_SPACE); |
| 590 EXPECT_EQ(0, menu_show_count_); | 595 EXPECT_EQ(0, menu_show_count_); |
| 591 EXPECT_TRUE(listener.on_perform_action_called()); | 596 EXPECT_TRUE(listener.on_perform_action_called()); |
| 592 EXPECT_EQ(0, listener.perform_action_index()); | 597 EXPECT_EQ(0, listener.perform_action_index()); |
| 593 } | 598 } |
| 594 | 599 |
| 595 TEST_F(ComboboxTest, NotifyOnClickWithMouse) { | 600 TEST_F(ComboboxTest, NotifyOnClickWithMouse) { |
| 596 InitCombobox(nullptr, Combobox::STYLE_ACTION); | 601 InitCombobox(nullptr, Combobox::STYLE_ACTION); |
| 597 | 602 |
| 598 TestComboboxListener listener; | 603 TestComboboxListener listener; |
| 599 combobox_->set_listener(&listener); | 604 combobox_->set_listener(&listener); |
| (...skipping 224 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 824 EXPECT_EQ(ui::MenuModel::TYPE_COMMAND, menu_model->GetTypeAt(0)); | 829 EXPECT_EQ(ui::MenuModel::TYPE_COMMAND, menu_model->GetTypeAt(0)); |
| 825 EXPECT_EQ(ui::MenuModel::TYPE_COMMAND, menu_model->GetTypeAt(1)); | 830 EXPECT_EQ(ui::MenuModel::TYPE_COMMAND, menu_model->GetTypeAt(1)); |
| 826 | 831 |
| 827 EXPECT_EQ(ASCIIToUTF16("PEANUT BUTTER"), menu_model->GetLabelAt(0)); | 832 EXPECT_EQ(ASCIIToUTF16("PEANUT BUTTER"), menu_model->GetLabelAt(0)); |
| 828 EXPECT_EQ(ASCIIToUTF16("JELLY"), menu_model->GetLabelAt(1)); | 833 EXPECT_EQ(ASCIIToUTF16("JELLY"), menu_model->GetLabelAt(1)); |
| 829 EXPECT_FALSE(menu_model->IsVisibleAt(0)); | 834 EXPECT_FALSE(menu_model->IsVisibleAt(0)); |
| 830 EXPECT_TRUE(menu_model->IsVisibleAt(1)); | 835 EXPECT_TRUE(menu_model->IsVisibleAt(1)); |
| 831 } | 836 } |
| 832 | 837 |
| 833 } // namespace views | 838 } // namespace views |
| OLD | NEW |