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" |
| (...skipping 17 matching lines...) Expand all Loading... | |
| 28 namespace views { | 28 namespace views { |
| 29 | 29 |
| 30 using test::ComboboxTestApi; | 30 using test::ComboboxTestApi; |
| 31 | 31 |
| 32 namespace { | 32 namespace { |
| 33 | 33 |
| 34 // A wrapper of Combobox to intercept the result of OnKeyPressed() and | 34 // A wrapper of Combobox to intercept the result of OnKeyPressed() and |
| 35 // OnKeyReleased() methods. | 35 // OnKeyReleased() methods. |
| 36 class TestCombobox : public Combobox { | 36 class TestCombobox : public Combobox { |
| 37 public: | 37 public: |
| 38 explicit TestCombobox(ui::ComboboxModel* model) | 38 TestCombobox(ui::ComboboxModel* model, Combobox::Style style) |
| 39 : Combobox(model), | 39 : Combobox(model, style), key_handled_(false), key_received_(false) {} |
| 40 key_handled_(false), | |
| 41 key_received_(false) {} | |
| 42 | 40 |
| 43 bool OnKeyPressed(const ui::KeyEvent& e) override { | 41 bool OnKeyPressed(const ui::KeyEvent& e) override { |
| 44 key_received_ = true; | 42 key_received_ = true; |
| 45 key_handled_ = Combobox::OnKeyPressed(e); | 43 key_handled_ = Combobox::OnKeyPressed(e); |
| 46 return key_handled_; | 44 return key_handled_; |
| 47 } | 45 } |
| 48 | 46 |
| 49 bool OnKeyReleased(const ui::KeyEvent& e) override { | 47 bool OnKeyReleased(const ui::KeyEvent& e) override { |
| 50 key_received_ = true; | 48 key_received_ = true; |
| 51 key_handled_ = Combobox::OnKeyReleased(e); | 49 key_handled_ = Combobox::OnKeyReleased(e); |
| (...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 188 class ComboboxTest : public ViewsTestBase { | 186 class ComboboxTest : public ViewsTestBase { |
| 189 public: | 187 public: |
| 190 ComboboxTest() : widget_(NULL), combobox_(NULL) {} | 188 ComboboxTest() : widget_(NULL), combobox_(NULL) {} |
| 191 | 189 |
| 192 void TearDown() override { | 190 void TearDown() override { |
| 193 if (widget_) | 191 if (widget_) |
| 194 widget_->Close(); | 192 widget_->Close(); |
| 195 ViewsTestBase::TearDown(); | 193 ViewsTestBase::TearDown(); |
| 196 } | 194 } |
| 197 | 195 |
| 198 void InitCombobox(const std::set<int>* separators) { | 196 void InitCombobox(const std::set<int>* separators, Combobox::Style style) { |
|
sky
2016/05/17 16:49:21
If you're going to use a default for the construct
Elly Fong-Jones
2016/05/17 17:35:05
I left it un-defaulted to make sure I had updated
| |
| 199 model_.reset(new TestComboboxModel()); | 197 model_.reset(new TestComboboxModel()); |
| 200 | 198 |
| 201 if (separators) | 199 if (separators) |
| 202 model_->SetSeparators(*separators); | 200 model_->SetSeparators(*separators); |
| 203 | 201 |
| 204 ASSERT_FALSE(combobox_); | 202 ASSERT_FALSE(combobox_); |
| 205 combobox_ = new TestCombobox(model_.get()); | 203 combobox_ = new TestCombobox(model_.get(), style); |
| 206 test_api_.reset(new ComboboxTestApi(combobox_)); | 204 test_api_.reset(new ComboboxTestApi(combobox_)); |
| 207 combobox_->set_id(1); | 205 combobox_->set_id(1); |
| 208 | 206 |
| 209 widget_ = new Widget; | 207 widget_ = new Widget; |
| 210 Widget::InitParams params = CreateParams(Widget::InitParams::TYPE_POPUP); | 208 Widget::InitParams params = CreateParams(Widget::InitParams::TYPE_POPUP); |
| 211 params.bounds = gfx::Rect(200, 200, 200, 200); | 209 params.bounds = gfx::Rect(200, 200, 200, 200); |
| 212 widget_->Init(params); | 210 widget_->Init(params); |
| 213 View* container = new View(); | 211 View* container = new View(); |
| 214 widget_->SetContentsView(container); | 212 widget_->SetContentsView(container); |
| 215 container->AddChildView(combobox_); | 213 container->AddChildView(combobox_); |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 254 std::unique_ptr<ComboboxTestApi> test_api_; | 252 std::unique_ptr<ComboboxTestApi> test_api_; |
| 255 | 253 |
| 256 // Combobox does not take ownership of the model, hence it needs to be scoped. | 254 // Combobox does not take ownership of the model, hence it needs to be scoped. |
| 257 std::unique_ptr<TestComboboxModel> model_; | 255 std::unique_ptr<TestComboboxModel> model_; |
| 258 | 256 |
| 259 private: | 257 private: |
| 260 DISALLOW_COPY_AND_ASSIGN(ComboboxTest); | 258 DISALLOW_COPY_AND_ASSIGN(ComboboxTest); |
| 261 }; | 259 }; |
| 262 | 260 |
| 263 TEST_F(ComboboxTest, KeyTest) { | 261 TEST_F(ComboboxTest, KeyTest) { |
| 264 InitCombobox(NULL); | 262 InitCombobox(nullptr, Combobox::STYLE_NORMAL); |
| 265 SendKeyEvent(ui::VKEY_END); | 263 SendKeyEvent(ui::VKEY_END); |
| 266 EXPECT_EQ(combobox_->selected_index() + 1, model_->GetItemCount()); | 264 EXPECT_EQ(combobox_->selected_index() + 1, model_->GetItemCount()); |
| 267 SendKeyEvent(ui::VKEY_HOME); | 265 SendKeyEvent(ui::VKEY_HOME); |
| 268 EXPECT_EQ(combobox_->selected_index(), 0); | 266 EXPECT_EQ(combobox_->selected_index(), 0); |
| 269 SendKeyEvent(ui::VKEY_DOWN); | 267 SendKeyEvent(ui::VKEY_DOWN); |
| 270 SendKeyEvent(ui::VKEY_DOWN); | 268 SendKeyEvent(ui::VKEY_DOWN); |
| 271 EXPECT_EQ(combobox_->selected_index(), 2); | 269 EXPECT_EQ(combobox_->selected_index(), 2); |
| 272 SendKeyEvent(ui::VKEY_RIGHT); | 270 SendKeyEvent(ui::VKEY_RIGHT); |
| 273 EXPECT_EQ(combobox_->selected_index(), 2); | 271 EXPECT_EQ(combobox_->selected_index(), 2); |
| 274 SendKeyEvent(ui::VKEY_LEFT); | 272 SendKeyEvent(ui::VKEY_LEFT); |
| 275 EXPECT_EQ(combobox_->selected_index(), 2); | 273 EXPECT_EQ(combobox_->selected_index(), 2); |
| 276 SendKeyEvent(ui::VKEY_UP); | 274 SendKeyEvent(ui::VKEY_UP); |
| 277 EXPECT_EQ(combobox_->selected_index(), 1); | 275 EXPECT_EQ(combobox_->selected_index(), 1); |
| 278 SendKeyEvent(ui::VKEY_PRIOR); | 276 SendKeyEvent(ui::VKEY_PRIOR); |
| 279 EXPECT_EQ(combobox_->selected_index(), 0); | 277 EXPECT_EQ(combobox_->selected_index(), 0); |
| 280 SendKeyEvent(ui::VKEY_NEXT); | 278 SendKeyEvent(ui::VKEY_NEXT); |
| 281 EXPECT_EQ(combobox_->selected_index(), model_->GetItemCount() - 1); | 279 EXPECT_EQ(combobox_->selected_index(), model_->GetItemCount() - 1); |
| 282 } | 280 } |
| 283 | 281 |
| 284 // Check that if a combobox is disabled before it has a native wrapper, then the | 282 // Check that if a combobox is disabled before it has a native wrapper, then the |
| 285 // native wrapper inherits the disabled state when it gets created. | 283 // native wrapper inherits the disabled state when it gets created. |
| 286 TEST_F(ComboboxTest, DisabilityTest) { | 284 TEST_F(ComboboxTest, DisabilityTest) { |
| 287 model_.reset(new TestComboboxModel()); | 285 model_.reset(new TestComboboxModel()); |
| 288 | 286 |
| 289 ASSERT_FALSE(combobox_); | 287 ASSERT_FALSE(combobox_); |
| 290 combobox_ = new TestCombobox(model_.get()); | 288 combobox_ = new TestCombobox(model_.get(), Combobox::STYLE_NORMAL); |
| 291 combobox_->SetEnabled(false); | 289 combobox_->SetEnabled(false); |
| 292 | 290 |
| 293 widget_ = new Widget; | 291 widget_ = new Widget; |
| 294 Widget::InitParams params = CreateParams(Widget::InitParams::TYPE_POPUP); | 292 Widget::InitParams params = CreateParams(Widget::InitParams::TYPE_POPUP); |
| 295 params.bounds = gfx::Rect(100, 100, 100, 100); | 293 params.bounds = gfx::Rect(100, 100, 100, 100); |
| 296 widget_->Init(params); | 294 widget_->Init(params); |
| 297 View* container = new View(); | 295 View* container = new View(); |
| 298 widget_->SetContentsView(container); | 296 widget_->SetContentsView(container); |
| 299 container->AddChildView(combobox_); | 297 container->AddChildView(combobox_); |
| 300 EXPECT_FALSE(combobox_->enabled()); | 298 EXPECT_FALSE(combobox_->enabled()); |
| 301 } | 299 } |
| 302 | 300 |
| 303 // Verifies that we don't select a separator line in combobox when navigating | 301 // Verifies that we don't select a separator line in combobox when navigating |
| 304 // through keyboard. | 302 // through keyboard. |
| 305 TEST_F(ComboboxTest, SkipSeparatorSimple) { | 303 TEST_F(ComboboxTest, SkipSeparatorSimple) { |
| 306 std::set<int> separators; | 304 std::set<int> separators; |
| 307 separators.insert(2); | 305 separators.insert(2); |
| 308 InitCombobox(&separators); | 306 InitCombobox(&separators, Combobox::STYLE_NORMAL); |
| 309 EXPECT_EQ(0, combobox_->selected_index()); | 307 EXPECT_EQ(0, combobox_->selected_index()); |
| 310 SendKeyEvent(ui::VKEY_DOWN); | 308 SendKeyEvent(ui::VKEY_DOWN); |
| 311 EXPECT_EQ(1, combobox_->selected_index()); | 309 EXPECT_EQ(1, combobox_->selected_index()); |
| 312 SendKeyEvent(ui::VKEY_DOWN); | 310 SendKeyEvent(ui::VKEY_DOWN); |
| 313 EXPECT_EQ(3, combobox_->selected_index()); | 311 EXPECT_EQ(3, combobox_->selected_index()); |
| 314 SendKeyEvent(ui::VKEY_UP); | 312 SendKeyEvent(ui::VKEY_UP); |
| 315 EXPECT_EQ(1, combobox_->selected_index()); | 313 EXPECT_EQ(1, combobox_->selected_index()); |
| 316 SendKeyEvent(ui::VKEY_HOME); | 314 SendKeyEvent(ui::VKEY_HOME); |
| 317 EXPECT_EQ(0, combobox_->selected_index()); | 315 EXPECT_EQ(0, combobox_->selected_index()); |
| 318 SendKeyEvent(ui::VKEY_PRIOR); | 316 SendKeyEvent(ui::VKEY_PRIOR); |
| 319 EXPECT_EQ(0, combobox_->selected_index()); | 317 EXPECT_EQ(0, combobox_->selected_index()); |
| 320 SendKeyEvent(ui::VKEY_END); | 318 SendKeyEvent(ui::VKEY_END); |
| 321 EXPECT_EQ(9, combobox_->selected_index()); | 319 EXPECT_EQ(9, combobox_->selected_index()); |
| 322 } | 320 } |
| 323 | 321 |
| 324 // Verifies that we never select the separator that is in the beginning of the | 322 // Verifies that we never select the separator that is in the beginning of the |
| 325 // combobox list when navigating through keyboard. | 323 // combobox list when navigating through keyboard. |
| 326 TEST_F(ComboboxTest, SkipSeparatorBeginning) { | 324 TEST_F(ComboboxTest, SkipSeparatorBeginning) { |
| 327 std::set<int> separators; | 325 std::set<int> separators; |
| 328 separators.insert(0); | 326 separators.insert(0); |
| 329 InitCombobox(&separators); | 327 InitCombobox(&separators, Combobox::STYLE_NORMAL); |
| 330 EXPECT_EQ(1, combobox_->selected_index()); | 328 EXPECT_EQ(1, combobox_->selected_index()); |
| 331 SendKeyEvent(ui::VKEY_DOWN); | 329 SendKeyEvent(ui::VKEY_DOWN); |
| 332 EXPECT_EQ(2, combobox_->selected_index()); | 330 EXPECT_EQ(2, combobox_->selected_index()); |
| 333 SendKeyEvent(ui::VKEY_DOWN); | 331 SendKeyEvent(ui::VKEY_DOWN); |
| 334 EXPECT_EQ(3, combobox_->selected_index()); | 332 EXPECT_EQ(3, combobox_->selected_index()); |
| 335 SendKeyEvent(ui::VKEY_UP); | 333 SendKeyEvent(ui::VKEY_UP); |
| 336 EXPECT_EQ(2, combobox_->selected_index()); | 334 EXPECT_EQ(2, combobox_->selected_index()); |
| 337 SendKeyEvent(ui::VKEY_HOME); | 335 SendKeyEvent(ui::VKEY_HOME); |
| 338 EXPECT_EQ(1, combobox_->selected_index()); | 336 EXPECT_EQ(1, combobox_->selected_index()); |
| 339 SendKeyEvent(ui::VKEY_PRIOR); | 337 SendKeyEvent(ui::VKEY_PRIOR); |
| 340 EXPECT_EQ(1, combobox_->selected_index()); | 338 EXPECT_EQ(1, combobox_->selected_index()); |
| 341 SendKeyEvent(ui::VKEY_END); | 339 SendKeyEvent(ui::VKEY_END); |
| 342 EXPECT_EQ(9, combobox_->selected_index()); | 340 EXPECT_EQ(9, combobox_->selected_index()); |
| 343 } | 341 } |
| 344 | 342 |
| 345 // Verifies that we never select the separator that is in the end of the | 343 // Verifies that we never select the separator that is in the end of the |
| 346 // combobox list when navigating through keyboard. | 344 // combobox list when navigating through keyboard. |
| 347 TEST_F(ComboboxTest, SkipSeparatorEnd) { | 345 TEST_F(ComboboxTest, SkipSeparatorEnd) { |
| 348 std::set<int> separators; | 346 std::set<int> separators; |
| 349 separators.insert(TestComboboxModel::kItemCount - 1); | 347 separators.insert(TestComboboxModel::kItemCount - 1); |
| 350 InitCombobox(&separators); | 348 InitCombobox(&separators, Combobox::STYLE_NORMAL); |
| 351 combobox_->SetSelectedIndex(8); | 349 combobox_->SetSelectedIndex(8); |
| 352 SendKeyEvent(ui::VKEY_DOWN); | 350 SendKeyEvent(ui::VKEY_DOWN); |
| 353 EXPECT_EQ(8, combobox_->selected_index()); | 351 EXPECT_EQ(8, combobox_->selected_index()); |
| 354 SendKeyEvent(ui::VKEY_UP); | 352 SendKeyEvent(ui::VKEY_UP); |
| 355 EXPECT_EQ(7, combobox_->selected_index()); | 353 EXPECT_EQ(7, combobox_->selected_index()); |
| 356 SendKeyEvent(ui::VKEY_END); | 354 SendKeyEvent(ui::VKEY_END); |
| 357 EXPECT_EQ(8, combobox_->selected_index()); | 355 EXPECT_EQ(8, combobox_->selected_index()); |
| 358 } | 356 } |
| 359 | 357 |
| 360 // Verifies that we never select any of the adjacent separators (multiple | 358 // Verifies that we never select any of the adjacent separators (multiple |
| 361 // consecutive) that appear in the beginning of the combobox list when | 359 // consecutive) that appear in the beginning of the combobox list when |
| 362 // navigating through keyboard. | 360 // navigating through keyboard. |
| 363 TEST_F(ComboboxTest, SkipMultipleSeparatorsAtBeginning) { | 361 TEST_F(ComboboxTest, SkipMultipleSeparatorsAtBeginning) { |
| 364 std::set<int> separators; | 362 std::set<int> separators; |
| 365 separators.insert(0); | 363 separators.insert(0); |
| 366 separators.insert(1); | 364 separators.insert(1); |
| 367 separators.insert(2); | 365 separators.insert(2); |
| 368 InitCombobox(&separators); | 366 InitCombobox(&separators, Combobox::STYLE_NORMAL); |
| 369 EXPECT_EQ(3, combobox_->selected_index()); | 367 EXPECT_EQ(3, combobox_->selected_index()); |
| 370 SendKeyEvent(ui::VKEY_DOWN); | 368 SendKeyEvent(ui::VKEY_DOWN); |
| 371 EXPECT_EQ(4, combobox_->selected_index()); | 369 EXPECT_EQ(4, combobox_->selected_index()); |
| 372 SendKeyEvent(ui::VKEY_UP); | 370 SendKeyEvent(ui::VKEY_UP); |
| 373 EXPECT_EQ(3, combobox_->selected_index()); | 371 EXPECT_EQ(3, combobox_->selected_index()); |
| 374 SendKeyEvent(ui::VKEY_NEXT); | 372 SendKeyEvent(ui::VKEY_NEXT); |
| 375 EXPECT_EQ(9, combobox_->selected_index()); | 373 EXPECT_EQ(9, combobox_->selected_index()); |
| 376 SendKeyEvent(ui::VKEY_HOME); | 374 SendKeyEvent(ui::VKEY_HOME); |
| 377 EXPECT_EQ(3, combobox_->selected_index()); | 375 EXPECT_EQ(3, combobox_->selected_index()); |
| 378 SendKeyEvent(ui::VKEY_END); | 376 SendKeyEvent(ui::VKEY_END); |
| 379 EXPECT_EQ(9, combobox_->selected_index()); | 377 EXPECT_EQ(9, combobox_->selected_index()); |
| 380 SendKeyEvent(ui::VKEY_PRIOR); | 378 SendKeyEvent(ui::VKEY_PRIOR); |
| 381 EXPECT_EQ(3, combobox_->selected_index()); | 379 EXPECT_EQ(3, combobox_->selected_index()); |
| 382 } | 380 } |
| 383 | 381 |
| 384 // Verifies that we never select any of the adjacent separators (multiple | 382 // Verifies that we never select any of the adjacent separators (multiple |
| 385 // consecutive) that appear in the middle of the combobox list when navigating | 383 // consecutive) that appear in the middle of the combobox list when navigating |
| 386 // through keyboard. | 384 // through keyboard. |
| 387 TEST_F(ComboboxTest, SkipMultipleAdjacentSeparatorsAtMiddle) { | 385 TEST_F(ComboboxTest, SkipMultipleAdjacentSeparatorsAtMiddle) { |
| 388 std::set<int> separators; | 386 std::set<int> separators; |
| 389 separators.insert(4); | 387 separators.insert(4); |
| 390 separators.insert(5); | 388 separators.insert(5); |
| 391 separators.insert(6); | 389 separators.insert(6); |
| 392 InitCombobox(&separators); | 390 InitCombobox(&separators, Combobox::STYLE_NORMAL); |
| 393 combobox_->SetSelectedIndex(3); | 391 combobox_->SetSelectedIndex(3); |
| 394 SendKeyEvent(ui::VKEY_DOWN); | 392 SendKeyEvent(ui::VKEY_DOWN); |
| 395 EXPECT_EQ(7, combobox_->selected_index()); | 393 EXPECT_EQ(7, combobox_->selected_index()); |
| 396 SendKeyEvent(ui::VKEY_UP); | 394 SendKeyEvent(ui::VKEY_UP); |
| 397 EXPECT_EQ(3, combobox_->selected_index()); | 395 EXPECT_EQ(3, combobox_->selected_index()); |
| 398 } | 396 } |
| 399 | 397 |
| 400 // Verifies that we never select any of the adjacent separators (multiple | 398 // Verifies that we never select any of the adjacent separators (multiple |
| 401 // consecutive) that appear in the end of the combobox list when navigating | 399 // consecutive) that appear in the end of the combobox list when navigating |
| 402 // through keyboard. | 400 // through keyboard. |
| 403 TEST_F(ComboboxTest, SkipMultipleSeparatorsAtEnd) { | 401 TEST_F(ComboboxTest, SkipMultipleSeparatorsAtEnd) { |
| 404 std::set<int> separators; | 402 std::set<int> separators; |
| 405 separators.insert(7); | 403 separators.insert(7); |
| 406 separators.insert(8); | 404 separators.insert(8); |
| 407 separators.insert(9); | 405 separators.insert(9); |
| 408 InitCombobox(&separators); | 406 InitCombobox(&separators, Combobox::STYLE_NORMAL); |
| 409 combobox_->SetSelectedIndex(6); | 407 combobox_->SetSelectedIndex(6); |
| 410 SendKeyEvent(ui::VKEY_DOWN); | 408 SendKeyEvent(ui::VKEY_DOWN); |
| 411 EXPECT_EQ(6, combobox_->selected_index()); | 409 EXPECT_EQ(6, combobox_->selected_index()); |
| 412 SendKeyEvent(ui::VKEY_UP); | 410 SendKeyEvent(ui::VKEY_UP); |
| 413 EXPECT_EQ(5, combobox_->selected_index()); | 411 EXPECT_EQ(5, combobox_->selected_index()); |
| 414 SendKeyEvent(ui::VKEY_HOME); | 412 SendKeyEvent(ui::VKEY_HOME); |
| 415 EXPECT_EQ(0, combobox_->selected_index()); | 413 EXPECT_EQ(0, combobox_->selected_index()); |
| 416 SendKeyEvent(ui::VKEY_NEXT); | 414 SendKeyEvent(ui::VKEY_NEXT); |
| 417 EXPECT_EQ(6, combobox_->selected_index()); | 415 EXPECT_EQ(6, combobox_->selected_index()); |
| 418 SendKeyEvent(ui::VKEY_PRIOR); | 416 SendKeyEvent(ui::VKEY_PRIOR); |
| 419 EXPECT_EQ(0, combobox_->selected_index()); | 417 EXPECT_EQ(0, combobox_->selected_index()); |
| 420 SendKeyEvent(ui::VKEY_END); | 418 SendKeyEvent(ui::VKEY_END); |
| 421 EXPECT_EQ(6, combobox_->selected_index()); | 419 EXPECT_EQ(6, combobox_->selected_index()); |
| 422 } | 420 } |
| 423 | 421 |
| 424 TEST_F(ComboboxTest, GetTextForRowTest) { | 422 TEST_F(ComboboxTest, GetTextForRowTest) { |
| 425 std::set<int> separators; | 423 std::set<int> separators; |
| 426 separators.insert(0); | 424 separators.insert(0); |
| 427 separators.insert(1); | 425 separators.insert(1); |
| 428 separators.insert(9); | 426 separators.insert(9); |
| 429 InitCombobox(&separators); | 427 InitCombobox(&separators, Combobox::STYLE_NORMAL); |
| 430 for (int i = 0; i < combobox_->GetRowCount(); ++i) { | 428 for (int i = 0; i < combobox_->GetRowCount(); ++i) { |
| 431 if (separators.count(i) != 0) { | 429 if (separators.count(i) != 0) { |
| 432 EXPECT_TRUE(combobox_->GetTextForRow(i).empty()) << i; | 430 EXPECT_TRUE(combobox_->GetTextForRow(i).empty()) << i; |
| 433 } else { | 431 } else { |
| 434 EXPECT_EQ(ASCIIToUTF16(i % 2 == 0 ? "PEANUT BUTTER" : "JELLY"), | 432 EXPECT_EQ(ASCIIToUTF16(i % 2 == 0 ? "PEANUT BUTTER" : "JELLY"), |
| 435 combobox_->GetTextForRow(i)) << i; | 433 combobox_->GetTextForRow(i)) << i; |
| 436 } | 434 } |
| 437 } | 435 } |
| 438 } | 436 } |
| 439 | 437 |
| 440 // Verifies selecting the first matching value (and returning whether found). | 438 // Verifies selecting the first matching value (and returning whether found). |
| 441 TEST_F(ComboboxTest, SelectValue) { | 439 TEST_F(ComboboxTest, SelectValue) { |
| 442 InitCombobox(NULL); | 440 InitCombobox(nullptr, Combobox::STYLE_NORMAL); |
| 443 ASSERT_EQ(model_->GetDefaultIndex(), combobox_->selected_index()); | 441 ASSERT_EQ(model_->GetDefaultIndex(), combobox_->selected_index()); |
| 444 EXPECT_TRUE(combobox_->SelectValue(ASCIIToUTF16("PEANUT BUTTER"))); | 442 EXPECT_TRUE(combobox_->SelectValue(ASCIIToUTF16("PEANUT BUTTER"))); |
| 445 EXPECT_EQ(0, combobox_->selected_index()); | 443 EXPECT_EQ(0, combobox_->selected_index()); |
| 446 EXPECT_TRUE(combobox_->SelectValue(ASCIIToUTF16("JELLY"))); | 444 EXPECT_TRUE(combobox_->SelectValue(ASCIIToUTF16("JELLY"))); |
| 447 EXPECT_EQ(1, combobox_->selected_index()); | 445 EXPECT_EQ(1, combobox_->selected_index()); |
| 448 EXPECT_FALSE(combobox_->SelectValue(ASCIIToUTF16("BANANAS"))); | 446 EXPECT_FALSE(combobox_->SelectValue(ASCIIToUTF16("BANANAS"))); |
| 449 EXPECT_EQ(1, combobox_->selected_index()); | 447 EXPECT_EQ(1, combobox_->selected_index()); |
| 448 } | |
| 450 | 449 |
| 450 TEST_F(ComboboxTest, SelectValueActionStyle) { | |
| 451 // With the action style, the selected index is always 0. | 451 // With the action style, the selected index is always 0. |
| 452 combobox_->SetStyle(Combobox::STYLE_ACTION); | 452 InitCombobox(nullptr, Combobox::STYLE_ACTION); |
| 453 EXPECT_FALSE(combobox_->SelectValue(ASCIIToUTF16("PEANUT BUTTER"))); | 453 EXPECT_FALSE(combobox_->SelectValue(ASCIIToUTF16("PEANUT BUTTER"))); |
| 454 EXPECT_EQ(0, combobox_->selected_index()); | 454 EXPECT_EQ(0, combobox_->selected_index()); |
| 455 EXPECT_FALSE(combobox_->SelectValue(ASCIIToUTF16("JELLY"))); | 455 EXPECT_FALSE(combobox_->SelectValue(ASCIIToUTF16("JELLY"))); |
| 456 EXPECT_EQ(0, combobox_->selected_index()); | 456 EXPECT_EQ(0, combobox_->selected_index()); |
| 457 EXPECT_FALSE(combobox_->SelectValue(ASCIIToUTF16("BANANAS"))); | 457 EXPECT_FALSE(combobox_->SelectValue(ASCIIToUTF16("BANANAS"))); |
| 458 EXPECT_EQ(0, combobox_->selected_index()); | 458 EXPECT_EQ(0, combobox_->selected_index()); |
| 459 } | 459 } |
| 460 | 460 |
| 461 TEST_F(ComboboxTest, SelectIndexActionStyle) { | 461 TEST_F(ComboboxTest, SelectIndexActionStyle) { |
| 462 InitCombobox(NULL); | 462 InitCombobox(nullptr, Combobox::STYLE_ACTION); |
| 463 | 463 |
| 464 // With the action style, the selected index is always 0. | 464 // With the action style, the selected index is always 0. |
| 465 combobox_->SetStyle(Combobox::STYLE_ACTION); | |
| 466 combobox_->SetSelectedIndex(1); | 465 combobox_->SetSelectedIndex(1); |
| 467 EXPECT_EQ(0, combobox_->selected_index()); | 466 EXPECT_EQ(0, combobox_->selected_index()); |
| 468 combobox_->SetSelectedIndex(2); | 467 combobox_->SetSelectedIndex(2); |
| 469 EXPECT_EQ(0, combobox_->selected_index()); | 468 EXPECT_EQ(0, combobox_->selected_index()); |
| 470 combobox_->SetSelectedIndex(3); | 469 combobox_->SetSelectedIndex(3); |
| 471 EXPECT_EQ(0, combobox_->selected_index()); | 470 EXPECT_EQ(0, combobox_->selected_index()); |
| 472 } | 471 } |
| 473 | 472 |
| 474 TEST_F(ComboboxTest, ListenerHandlesDelete) { | 473 TEST_F(ComboboxTest, ListenerHandlesDelete) { |
| 475 TestComboboxModel model; | 474 TestComboboxModel model; |
| 476 | 475 |
| 477 // |combobox| will be deleted on change. | 476 // |combobox| will be deleted on change. |
| 478 TestCombobox* combobox = new TestCombobox(&model); | 477 TestCombobox* combobox = new TestCombobox(&model, Combobox::STYLE_NORMAL); |
| 479 std::unique_ptr<EvilListener> evil_listener(new EvilListener()); | 478 std::unique_ptr<EvilListener> evil_listener(new EvilListener()); |
| 480 combobox->set_listener(evil_listener.get()); | 479 combobox->set_listener(evil_listener.get()); |
| 481 ASSERT_NO_FATAL_FAILURE(ComboboxTestApi(combobox).PerformActionAt(2)); | 480 ASSERT_NO_FATAL_FAILURE(ComboboxTestApi(combobox).PerformActionAt(2)); |
| 482 EXPECT_TRUE(evil_listener->deleted()); | 481 EXPECT_TRUE(evil_listener->deleted()); |
| 483 | 482 |
| 484 // With STYLE_ACTION | 483 // With STYLE_ACTION |
| 485 // |combobox| will be deleted on change. | 484 // |combobox| will be deleted on change. |
| 486 combobox = new TestCombobox(&model); | 485 combobox = new TestCombobox(&model, Combobox::STYLE_ACTION); |
| 487 evil_listener.reset(new EvilListener()); | 486 evil_listener.reset(new EvilListener()); |
| 488 combobox->set_listener(evil_listener.get()); | 487 combobox->set_listener(evil_listener.get()); |
| 489 combobox->SetStyle(Combobox::STYLE_ACTION); | |
| 490 ASSERT_NO_FATAL_FAILURE(ComboboxTestApi(combobox).PerformActionAt(2)); | 488 ASSERT_NO_FATAL_FAILURE(ComboboxTestApi(combobox).PerformActionAt(2)); |
| 491 EXPECT_TRUE(evil_listener->deleted()); | 489 EXPECT_TRUE(evil_listener->deleted()); |
| 492 } | 490 } |
| 493 | 491 |
| 494 TEST_F(ComboboxTest, Click) { | 492 TEST_F(ComboboxTest, Click) { |
| 495 InitCombobox(NULL); | 493 InitCombobox(nullptr, Combobox::STYLE_NORMAL); |
| 496 | 494 |
| 497 TestComboboxListener listener; | 495 TestComboboxListener listener; |
| 498 combobox_->set_listener(&listener); | 496 combobox_->set_listener(&listener); |
| 499 | 497 |
| 500 combobox_->Layout(); | 498 combobox_->Layout(); |
| 501 int menu_show_count = 0; | 499 int menu_show_count = 0; |
| 502 test_api_->InstallTestMenuRunner(&menu_show_count); | 500 test_api_->InstallTestMenuRunner(&menu_show_count); |
| 503 | 501 |
| 504 // Click the left side. The menu is shown. | 502 // Click the left side. The menu is shown. |
| 505 EXPECT_EQ(0, menu_show_count); | 503 EXPECT_EQ(0, menu_show_count); |
| 506 PerformClick(gfx::Point(combobox_->x() + 1, | 504 PerformClick(gfx::Point(combobox_->x() + 1, |
| 507 combobox_->y() + combobox_->height() / 2)); | 505 combobox_->y() + combobox_->height() / 2)); |
| 508 EXPECT_FALSE(listener.on_perform_action_called()); | 506 EXPECT_FALSE(listener.on_perform_action_called()); |
| 509 EXPECT_EQ(1, menu_show_count); | 507 EXPECT_EQ(1, menu_show_count); |
| 510 } | 508 } |
| 511 | 509 |
| 512 TEST_F(ComboboxTest, ClickButDisabled) { | 510 TEST_F(ComboboxTest, ClickButDisabled) { |
| 513 InitCombobox(NULL); | 511 InitCombobox(nullptr, Combobox::STYLE_NORMAL); |
| 514 | 512 |
| 515 TestComboboxListener listener; | 513 TestComboboxListener listener; |
| 516 combobox_->set_listener(&listener); | 514 combobox_->set_listener(&listener); |
| 517 | 515 |
| 518 combobox_->Layout(); | 516 combobox_->Layout(); |
| 519 combobox_->SetEnabled(false); | 517 combobox_->SetEnabled(false); |
| 520 | 518 |
| 521 // Click the left side, but nothing happens since the combobox is disabled. | 519 // Click the left side, but nothing happens since the combobox is disabled. |
| 522 int menu_show_count = 0; | 520 int menu_show_count = 0; |
| 523 test_api_->InstallTestMenuRunner(&menu_show_count); | 521 test_api_->InstallTestMenuRunner(&menu_show_count); |
| 524 PerformClick(gfx::Point(combobox_->x() + 1, | 522 PerformClick(gfx::Point(combobox_->x() + 1, |
| 525 combobox_->y() + combobox_->height() / 2)); | 523 combobox_->y() + combobox_->height() / 2)); |
| 526 EXPECT_FALSE(listener.on_perform_action_called()); | 524 EXPECT_FALSE(listener.on_perform_action_called()); |
| 527 EXPECT_EQ(0, menu_show_count); | 525 EXPECT_EQ(0, menu_show_count); |
| 528 } | 526 } |
| 529 | 527 |
| 530 TEST_F(ComboboxTest, NotifyOnClickWithReturnKey) { | 528 TEST_F(ComboboxTest, NotifyOnClickWithReturnKey) { |
| 531 InitCombobox(NULL); | 529 InitCombobox(nullptr, Combobox::STYLE_NORMAL); |
| 532 | 530 |
| 533 TestComboboxListener listener; | 531 TestComboboxListener listener; |
| 534 combobox_->set_listener(&listener); | 532 combobox_->set_listener(&listener); |
| 535 | 533 |
| 536 // With STYLE_NORMAL, the click event is ignored. | 534 // With STYLE_NORMAL, the click event is ignored. |
| 537 SendKeyEvent(ui::VKEY_RETURN); | 535 SendKeyEvent(ui::VKEY_RETURN); |
| 538 EXPECT_FALSE(listener.on_perform_action_called()); | 536 EXPECT_FALSE(listener.on_perform_action_called()); |
| 537 } | |
| 538 | |
| 539 TEST_F(ComboboxTest, NotifyOnClickWithReturnKeyActionStyle) { | |
| 540 InitCombobox(nullptr, Combobox::STYLE_ACTION); | |
| 541 | |
| 542 TestComboboxListener listener; | |
| 543 combobox_->set_listener(&listener); | |
| 539 | 544 |
| 540 // With STYLE_ACTION, the click event is notified. | 545 // With STYLE_ACTION, the click event is notified. |
| 541 combobox_->SetStyle(Combobox::STYLE_ACTION); | |
| 542 SendKeyEvent(ui::VKEY_RETURN); | 546 SendKeyEvent(ui::VKEY_RETURN); |
| 543 EXPECT_TRUE(listener.on_perform_action_called()); | 547 EXPECT_TRUE(listener.on_perform_action_called()); |
| 544 EXPECT_EQ(0, listener.perform_action_index()); | 548 EXPECT_EQ(0, listener.perform_action_index()); |
| 545 } | 549 } |
| 546 | 550 |
| 547 TEST_F(ComboboxTest, NotifyOnClickWithSpaceKey) { | 551 TEST_F(ComboboxTest, NotifyOnClickWithSpaceKey) { |
| 548 InitCombobox(NULL); | 552 InitCombobox(nullptr, Combobox::STYLE_NORMAL); |
| 549 | 553 |
| 550 TestComboboxListener listener; | 554 TestComboboxListener listener; |
| 551 combobox_->set_listener(&listener); | 555 combobox_->set_listener(&listener); |
| 552 | 556 |
| 553 // With STYLE_NORMAL, the click event is ignored. | 557 // With STYLE_NORMAL, the click event is ignored. |
| 554 SendKeyEvent(ui::VKEY_SPACE); | 558 SendKeyEvent(ui::VKEY_SPACE); |
| 555 EXPECT_FALSE(listener.on_perform_action_called()); | 559 EXPECT_FALSE(listener.on_perform_action_called()); |
| 556 SendKeyEventWithType(ui::VKEY_SPACE, ui::ET_KEY_RELEASED); | 560 SendKeyEventWithType(ui::VKEY_SPACE, ui::ET_KEY_RELEASED); |
| 557 EXPECT_FALSE(listener.on_perform_action_called()); | 561 EXPECT_FALSE(listener.on_perform_action_called()); |
| 562 } | |
| 563 | |
| 564 TEST_F(ComboboxTest, NotifyOnClickWithSpaceKeyActionStyle) { | |
| 565 InitCombobox(nullptr, Combobox::STYLE_ACTION); | |
| 566 | |
| 567 TestComboboxListener listener; | |
| 568 combobox_->set_listener(&listener); | |
| 558 | 569 |
| 559 // With STYLE_ACTION, the click event is notified after releasing. | 570 // With STYLE_ACTION, the click event is notified after releasing. |
| 560 combobox_->SetStyle(Combobox::STYLE_ACTION); | |
| 561 SendKeyEvent(ui::VKEY_SPACE); | 571 SendKeyEvent(ui::VKEY_SPACE); |
| 562 EXPECT_FALSE(listener.on_perform_action_called()); | 572 EXPECT_FALSE(listener.on_perform_action_called()); |
| 563 SendKeyEventWithType(ui::VKEY_SPACE, ui::ET_KEY_RELEASED); | 573 SendKeyEventWithType(ui::VKEY_SPACE, ui::ET_KEY_RELEASED); |
| 564 EXPECT_TRUE(listener.on_perform_action_called()); | 574 EXPECT_TRUE(listener.on_perform_action_called()); |
| 565 EXPECT_EQ(0, listener.perform_action_index()); | 575 EXPECT_EQ(0, listener.perform_action_index()); |
| 566 } | 576 } |
| 567 | 577 |
| 568 TEST_F(ComboboxTest, NotifyOnClickWithMouse) { | 578 TEST_F(ComboboxTest, NotifyOnClickWithMouse) { |
| 569 InitCombobox(NULL); | 579 InitCombobox(nullptr, Combobox::STYLE_ACTION); |
| 570 | 580 |
| 571 TestComboboxListener listener; | 581 TestComboboxListener listener; |
| 572 combobox_->set_listener(&listener); | 582 combobox_->set_listener(&listener); |
| 573 | 583 |
| 574 combobox_->SetStyle(Combobox::STYLE_ACTION); | |
| 575 combobox_->Layout(); | 584 combobox_->Layout(); |
| 576 | 585 |
| 577 // Click the right side (arrow button). The menu is shown. | 586 // Click the right side (arrow button). The menu is shown. |
| 578 int menu_show_count = 0; | 587 int menu_show_count = 0; |
| 579 test_api_->InstallTestMenuRunner(&menu_show_count); | 588 test_api_->InstallTestMenuRunner(&menu_show_count); |
| 580 EXPECT_EQ(0, menu_show_count); | 589 EXPECT_EQ(0, menu_show_count); |
| 581 PerformClick(gfx::Point(combobox_->x() + combobox_->width() - 1, | 590 PerformClick(gfx::Point(combobox_->x() + combobox_->width() - 1, |
| 582 combobox_->y() + combobox_->height() / 2)); | 591 combobox_->y() + combobox_->height() / 2)); |
| 583 EXPECT_FALSE(listener.on_perform_action_called()); | 592 EXPECT_FALSE(listener.on_perform_action_called()); |
| 584 EXPECT_EQ(1, menu_show_count); | 593 EXPECT_EQ(1, menu_show_count); |
| 585 | 594 |
| 586 // Click the left side (text button). The click event is notified. | 595 // Click the left side (text button). The click event is notified. |
| 587 test_api_->InstallTestMenuRunner(&menu_show_count); | 596 test_api_->InstallTestMenuRunner(&menu_show_count); |
| 588 PerformClick(gfx::Point(combobox_->x() + 1, | 597 PerformClick(gfx::Point(combobox_->x() + 1, |
| 589 combobox_->y() + combobox_->height() / 2)); | 598 combobox_->y() + combobox_->height() / 2)); |
| 590 EXPECT_TRUE(listener.on_perform_action_called()); | 599 EXPECT_TRUE(listener.on_perform_action_called()); |
| 591 EXPECT_EQ(1, menu_show_count); // Unchanged. | 600 EXPECT_EQ(1, menu_show_count); // Unchanged. |
| 592 EXPECT_EQ(0, listener.perform_action_index()); | 601 EXPECT_EQ(0, listener.perform_action_index()); |
| 593 } | 602 } |
| 594 | 603 |
| 595 TEST_F(ComboboxTest, ConsumingPressKeyEvents) { | 604 TEST_F(ComboboxTest, ConsumingPressKeyEvents) { |
| 596 InitCombobox(NULL); | 605 InitCombobox(nullptr, Combobox::STYLE_NORMAL); |
| 597 | 606 |
| 598 EXPECT_FALSE(combobox_->OnKeyPressed( | 607 EXPECT_FALSE(combobox_->OnKeyPressed( |
| 599 ui::KeyEvent(ui::ET_KEY_PRESSED, ui::VKEY_RETURN, ui::EF_NONE))); | 608 ui::KeyEvent(ui::ET_KEY_PRESSED, ui::VKEY_RETURN, ui::EF_NONE))); |
| 600 EXPECT_FALSE(combobox_->OnKeyPressed( | 609 EXPECT_FALSE(combobox_->OnKeyPressed( |
| 601 ui::KeyEvent(ui::ET_KEY_PRESSED, ui::VKEY_SPACE, ui::EF_NONE))); | 610 ui::KeyEvent(ui::ET_KEY_PRESSED, ui::VKEY_SPACE, ui::EF_NONE))); |
| 611 } | |
| 602 | 612 |
| 613 TEST_F(ComboboxTest, ConsumingKeyPressEventsActionStyle) { | |
| 603 // When the combobox's style is STYLE_ACTION, pressing events of a space key | 614 // When the combobox's style is STYLE_ACTION, pressing events of a space key |
| 604 // or an enter key will be consumed. | 615 // or an enter key will be consumed. |
| 605 combobox_->SetStyle(Combobox::STYLE_ACTION); | 616 InitCombobox(nullptr, Combobox::STYLE_ACTION); |
| 606 EXPECT_TRUE(combobox_->OnKeyPressed( | 617 EXPECT_TRUE(combobox_->OnKeyPressed( |
| 607 ui::KeyEvent(ui::ET_KEY_PRESSED, ui::VKEY_RETURN, ui::EF_NONE))); | 618 ui::KeyEvent(ui::ET_KEY_PRESSED, ui::VKEY_RETURN, ui::EF_NONE))); |
| 608 EXPECT_TRUE(combobox_->OnKeyPressed( | 619 EXPECT_TRUE(combobox_->OnKeyPressed( |
| 609 ui::KeyEvent(ui::ET_KEY_PRESSED, ui::VKEY_SPACE, ui::EF_NONE))); | 620 ui::KeyEvent(ui::ET_KEY_PRESSED, ui::VKEY_SPACE, ui::EF_NONE))); |
| 610 } | 621 } |
| 611 | 622 |
| 612 TEST_F(ComboboxTest, ContentWidth) { | 623 TEST_F(ComboboxTest, ContentWidth) { |
| 613 std::vector<std::string> values; | 624 std::vector<std::string> values; |
| 614 VectorComboboxModel model(&values); | 625 VectorComboboxModel model(&values); |
| 615 TestCombobox combobox(&model); | 626 TestCombobox combobox(&model, Combobox::STYLE_NORMAL); |
| 627 TestCombobox action_combobox(&model, Combobox::STYLE_ACTION); | |
| 616 ComboboxTestApi test_api(&combobox); | 628 ComboboxTestApi test_api(&combobox); |
| 629 ComboboxTestApi action_test_api(&action_combobox); | |
| 617 | 630 |
| 618 std::string long_item = "this is the long item"; | 631 std::string long_item = "this is the long item"; |
| 619 std::string short_item = "s"; | 632 std::string short_item = "s"; |
| 620 | 633 |
| 621 values.resize(1); | 634 values.resize(1); |
| 622 values[0] = long_item; | 635 values[0] = long_item; |
| 623 combobox.ModelChanged(); | 636 combobox.ModelChanged(); |
| 637 action_combobox.ModelChanged(); | |
| 624 | 638 |
| 625 const int long_item_width = test_api.content_size().width(); | 639 const int long_item_width = test_api.content_size().width(); |
| 626 | 640 |
| 627 values[0] = short_item; | 641 values[0] = short_item; |
| 628 combobox.ModelChanged(); | 642 combobox.ModelChanged(); |
| 643 action_combobox.ModelChanged(); | |
| 629 | 644 |
| 630 const int short_item_width = test_api.content_size().width(); | 645 const int short_item_width = test_api.content_size().width(); |
| 631 | 646 |
| 632 values.resize(2); | 647 values.resize(2); |
| 633 values[0] = short_item; | 648 values[0] = short_item; |
| 634 values[1] = long_item; | 649 values[1] = long_item; |
| 635 combobox.ModelChanged(); | 650 combobox.ModelChanged(); |
| 651 action_combobox.ModelChanged(); | |
| 636 | 652 |
| 637 // When the style is STYLE_NORMAL, the width will fit with the longest item. | 653 // When the style is STYLE_NORMAL, the width will fit with the longest item. |
| 638 combobox.SetStyle(Combobox::STYLE_NORMAL); | |
| 639 EXPECT_EQ(long_item_width, test_api.content_size().width()); | 654 EXPECT_EQ(long_item_width, test_api.content_size().width()); |
| 640 | 655 |
| 641 // When the style is STYLE_ACTION, the width will fit with the selected item's | 656 // When the style is STYLE_ACTION, the width will fit with the selected item's |
| 642 // width. | 657 // width. |
| 643 combobox.SetStyle(Combobox::STYLE_ACTION); | 658 EXPECT_EQ(short_item_width, action_test_api.content_size().width()); |
| 644 EXPECT_EQ(short_item_width, test_api.content_size().width()); | |
| 645 } | 659 } |
| 646 | 660 |
| 647 // Test that model updates preserve the selected index, so long as it is in | 661 // Test that model updates preserve the selected index, so long as it is in |
| 648 // range. | 662 // range. |
| 649 TEST_F(ComboboxTest, ModelChanged) { | 663 TEST_F(ComboboxTest, ModelChanged) { |
| 650 InitCombobox(nullptr); | 664 InitCombobox(nullptr, Combobox::STYLE_NORMAL); |
| 651 | 665 |
| 652 EXPECT_EQ(0, combobox_->GetSelectedRow()); | 666 EXPECT_EQ(0, combobox_->GetSelectedRow()); |
| 653 EXPECT_EQ(10, combobox_->GetRowCount()); | 667 EXPECT_EQ(10, combobox_->GetRowCount()); |
| 654 | 668 |
| 655 combobox_->SetSelectedIndex(4); | 669 combobox_->SetSelectedIndex(4); |
| 656 EXPECT_EQ(4, combobox_->GetSelectedRow()); | 670 EXPECT_EQ(4, combobox_->GetSelectedRow()); |
| 657 | 671 |
| 658 model_->set_item_count(5); | 672 model_->set_item_count(5); |
| 659 combobox_->ModelChanged(); | 673 combobox_->ModelChanged(); |
| 660 EXPECT_EQ(5, combobox_->GetRowCount()); | 674 EXPECT_EQ(5, combobox_->GetRowCount()); |
| (...skipping 21 matching lines...) Expand all Loading... | |
| 682 EXPECT_EQ(1, combobox_->GetSelectedRow()); | 696 EXPECT_EQ(1, combobox_->GetSelectedRow()); |
| 683 | 697 |
| 684 // Test an empty model. | 698 // Test an empty model. |
| 685 model_->set_item_count(0); | 699 model_->set_item_count(0); |
| 686 combobox_->ModelChanged(); | 700 combobox_->ModelChanged(); |
| 687 EXPECT_EQ(0, combobox_->GetRowCount()); | 701 EXPECT_EQ(0, combobox_->GetRowCount()); |
| 688 EXPECT_EQ(0, combobox_->GetSelectedRow()); // Resets. | 702 EXPECT_EQ(0, combobox_->GetSelectedRow()); // Resets. |
| 689 } | 703 } |
| 690 | 704 |
| 691 TEST_F(ComboboxTest, TypingPrefixNotifiesListener) { | 705 TEST_F(ComboboxTest, TypingPrefixNotifiesListener) { |
| 692 InitCombobox(NULL); | 706 InitCombobox(nullptr, Combobox::STYLE_NORMAL); |
| 693 | 707 |
| 694 TestComboboxListener listener; | 708 TestComboboxListener listener; |
| 695 combobox_->set_listener(&listener); | 709 combobox_->set_listener(&listener); |
| 696 ui::TextInputClient* input_client = | 710 ui::TextInputClient* input_client = |
| 697 widget_->GetInputMethod()->GetTextInputClient(); | 711 widget_->GetInputMethod()->GetTextInputClient(); |
| 698 | 712 |
| 699 // Type the first character of the second menu item ("JELLY"). | 713 // Type the first character of the second menu item ("JELLY"). |
| 700 ui::KeyEvent key_event(ui::ET_KEY_PRESSED, ui::VKEY_J, ui::DomCode::US_J, 0, | 714 ui::KeyEvent key_event(ui::ET_KEY_PRESSED, ui::VKEY_J, ui::DomCode::US_J, 0, |
| 701 ui::DomKey::FromCharacter('J'), ui::EventTimeForNow()); | 715 ui::DomKey::FromCharacter('J'), ui::EventTimeForNow()); |
| 702 | 716 |
| (...skipping 22 matching lines...) Expand all Loading... | |
| 725 input_client->InsertChar(key_event); | 739 input_client->InsertChar(key_event); |
| 726 EXPECT_EQ(2, listener.actions_performed()); | 740 EXPECT_EQ(2, listener.actions_performed()); |
| 727 EXPECT_EQ(2, listener.perform_action_index()); | 741 EXPECT_EQ(2, listener.perform_action_index()); |
| 728 } | 742 } |
| 729 | 743 |
| 730 // Test properties on the Combobox menu model. | 744 // Test properties on the Combobox menu model. |
| 731 TEST_F(ComboboxTest, MenuModel) { | 745 TEST_F(ComboboxTest, MenuModel) { |
| 732 const int kSeparatorIndex = 3; | 746 const int kSeparatorIndex = 3; |
| 733 std::set<int> separators; | 747 std::set<int> separators; |
| 734 separators.insert(kSeparatorIndex); | 748 separators.insert(kSeparatorIndex); |
| 735 InitCombobox(&separators); | 749 InitCombobox(&separators, Combobox::STYLE_NORMAL); |
| 736 | 750 |
| 737 ui::MenuModel* menu_model = test_api_->menu_model(); | 751 ui::MenuModel* menu_model = test_api_->menu_model(); |
| 738 | 752 |
| 739 EXPECT_EQ(TestComboboxModel::kItemCount, menu_model->GetItemCount()); | 753 EXPECT_EQ(TestComboboxModel::kItemCount, menu_model->GetItemCount()); |
| 740 EXPECT_EQ(ui::MenuModel::TYPE_SEPARATOR, | 754 EXPECT_EQ(ui::MenuModel::TYPE_SEPARATOR, |
| 741 menu_model->GetTypeAt(kSeparatorIndex)); | 755 menu_model->GetTypeAt(kSeparatorIndex)); |
| 742 | 756 |
| 743 #if defined(OS_MACOSX) | 757 #if defined(OS_MACOSX) |
| 744 // Comboboxes on Mac should have checkmarks, with the selected item checked, | 758 // Comboboxes on Mac should have checkmarks, with the selected item checked, |
| 745 EXPECT_EQ(ui::MenuModel::TYPE_CHECK, menu_model->GetTypeAt(0)); | 759 EXPECT_EQ(ui::MenuModel::TYPE_CHECK, menu_model->GetTypeAt(0)); |
| 746 EXPECT_EQ(ui::MenuModel::TYPE_CHECK, menu_model->GetTypeAt(1)); | 760 EXPECT_EQ(ui::MenuModel::TYPE_CHECK, menu_model->GetTypeAt(1)); |
| 747 EXPECT_TRUE(menu_model->IsItemCheckedAt(0)); | 761 EXPECT_TRUE(menu_model->IsItemCheckedAt(0)); |
| 748 EXPECT_FALSE(menu_model->IsItemCheckedAt(1)); | 762 EXPECT_FALSE(menu_model->IsItemCheckedAt(1)); |
| 749 | 763 |
| 750 combobox_->SetSelectedIndex(1); | 764 combobox_->SetSelectedIndex(1); |
| 751 EXPECT_FALSE(menu_model->IsItemCheckedAt(0)); | 765 EXPECT_FALSE(menu_model->IsItemCheckedAt(0)); |
| 752 EXPECT_TRUE(menu_model->IsItemCheckedAt(1)); | 766 EXPECT_TRUE(menu_model->IsItemCheckedAt(1)); |
| 753 #else | 767 #else |
| 754 EXPECT_EQ(ui::MenuModel::TYPE_COMMAND, menu_model->GetTypeAt(0)); | 768 EXPECT_EQ(ui::MenuModel::TYPE_COMMAND, menu_model->GetTypeAt(0)); |
| 755 EXPECT_EQ(ui::MenuModel::TYPE_COMMAND, menu_model->GetTypeAt(1)); | 769 EXPECT_EQ(ui::MenuModel::TYPE_COMMAND, menu_model->GetTypeAt(1)); |
| 756 #endif | 770 #endif |
| 757 | 771 |
| 758 EXPECT_EQ(ASCIIToUTF16("PEANUT BUTTER"), menu_model->GetLabelAt(0)); | 772 EXPECT_EQ(ASCIIToUTF16("PEANUT BUTTER"), menu_model->GetLabelAt(0)); |
| 759 EXPECT_EQ(ASCIIToUTF16("JELLY"), menu_model->GetLabelAt(1)); | 773 EXPECT_EQ(ASCIIToUTF16("JELLY"), menu_model->GetLabelAt(1)); |
| 760 | 774 |
| 761 // Check that with STYLE_ACTION, the first item (only) is not shown. | |
| 762 EXPECT_TRUE(menu_model->IsVisibleAt(0)); | 775 EXPECT_TRUE(menu_model->IsVisibleAt(0)); |
| 763 combobox_->SetStyle(Combobox::STYLE_ACTION); | 776 } |
| 777 | |
| 778 // Check that with STYLE_ACTION, the first item (only) is not shown. | |
| 779 TEST_F(ComboboxTest, MenuModelActionStyleMac) { | |
| 780 const int kSeparatorIndex = 3; | |
| 781 std::set<int> separators; | |
| 782 separators.insert(kSeparatorIndex); | |
| 783 InitCombobox(&separators, Combobox::STYLE_ACTION); | |
| 784 | |
| 785 ui::MenuModel* menu_model = test_api_->menu_model(); | |
| 786 | |
| 787 EXPECT_EQ(TestComboboxModel::kItemCount, menu_model->GetItemCount()); | |
| 788 EXPECT_EQ(ui::MenuModel::TYPE_SEPARATOR, | |
| 789 menu_model->GetTypeAt(kSeparatorIndex)); | |
| 790 | |
| 791 EXPECT_EQ(ui::MenuModel::TYPE_COMMAND, menu_model->GetTypeAt(0)); | |
| 792 EXPECT_EQ(ui::MenuModel::TYPE_COMMAND, menu_model->GetTypeAt(1)); | |
| 793 | |
| 794 EXPECT_EQ(ASCIIToUTF16("PEANUT BUTTER"), menu_model->GetLabelAt(0)); | |
| 795 EXPECT_EQ(ASCIIToUTF16("JELLY"), menu_model->GetLabelAt(1)); | |
| 764 EXPECT_FALSE(menu_model->IsVisibleAt(0)); | 796 EXPECT_FALSE(menu_model->IsVisibleAt(0)); |
| 765 EXPECT_TRUE(menu_model->IsVisibleAt(1)); | 797 EXPECT_TRUE(menu_model->IsVisibleAt(1)); |
| 766 } | 798 } |
| 767 | 799 |
| 768 } // namespace views | 800 } // namespace views |
| OLD | NEW |