| 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 233 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 244 ui::ET_MOUSE_RELEASED, point, point, ui::EventTimeForNow(), | 244 ui::ET_MOUSE_RELEASED, point, point, ui::EventTimeForNow(), |
| 245 ui::EF_LEFT_MOUSE_BUTTON, ui::EF_LEFT_MOUSE_BUTTON); | 245 ui::EF_LEFT_MOUSE_BUTTON, ui::EF_LEFT_MOUSE_BUTTON); |
| 246 widget_->OnMouseEvent(&released_event); | 246 widget_->OnMouseEvent(&released_event); |
| 247 } | 247 } |
| 248 | 248 |
| 249 // We need widget to populate wrapper class. | 249 // We need widget to populate wrapper class. |
| 250 Widget* widget_; | 250 Widget* widget_; |
| 251 | 251 |
| 252 // |combobox_| will be allocated InitCombobox() and then owned by |widget_|. | 252 // |combobox_| will be allocated InitCombobox() and then owned by |widget_|. |
| 253 TestCombobox* combobox_; | 253 TestCombobox* combobox_; |
| 254 scoped_ptr<ComboboxTestApi> test_api_; | 254 std::unique_ptr<ComboboxTestApi> test_api_; |
| 255 | 255 |
| 256 // Combobox does not take ownership of the model, hence it needs to be scoped. | 256 // Combobox does not take ownership of the model, hence it needs to be scoped. |
| 257 scoped_ptr<TestComboboxModel> model_; | 257 std::unique_ptr<TestComboboxModel> model_; |
| 258 | 258 |
| 259 private: | 259 private: |
| 260 DISALLOW_COPY_AND_ASSIGN(ComboboxTest); | 260 DISALLOW_COPY_AND_ASSIGN(ComboboxTest); |
| 261 }; | 261 }; |
| 262 | 262 |
| 263 TEST_F(ComboboxTest, KeyTest) { | 263 TEST_F(ComboboxTest, KeyTest) { |
| 264 InitCombobox(NULL); | 264 InitCombobox(NULL); |
| 265 SendKeyEvent(ui::VKEY_END); | 265 SendKeyEvent(ui::VKEY_END); |
| 266 EXPECT_EQ(combobox_->selected_index() + 1, model_->GetItemCount()); | 266 EXPECT_EQ(combobox_->selected_index() + 1, model_->GetItemCount()); |
| 267 SendKeyEvent(ui::VKEY_HOME); | 267 SendKeyEvent(ui::VKEY_HOME); |
| (...skipping 201 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 469 EXPECT_EQ(0, combobox_->selected_index()); | 469 EXPECT_EQ(0, combobox_->selected_index()); |
| 470 combobox_->SetSelectedIndex(3); | 470 combobox_->SetSelectedIndex(3); |
| 471 EXPECT_EQ(0, combobox_->selected_index()); | 471 EXPECT_EQ(0, combobox_->selected_index()); |
| 472 } | 472 } |
| 473 | 473 |
| 474 TEST_F(ComboboxTest, ListenerHandlesDelete) { | 474 TEST_F(ComboboxTest, ListenerHandlesDelete) { |
| 475 TestComboboxModel model; | 475 TestComboboxModel model; |
| 476 | 476 |
| 477 // |combobox| will be deleted on change. | 477 // |combobox| will be deleted on change. |
| 478 TestCombobox* combobox = new TestCombobox(&model); | 478 TestCombobox* combobox = new TestCombobox(&model); |
| 479 scoped_ptr<EvilListener> evil_listener(new EvilListener()); | 479 std::unique_ptr<EvilListener> evil_listener(new EvilListener()); |
| 480 combobox->set_listener(evil_listener.get()); | 480 combobox->set_listener(evil_listener.get()); |
| 481 ASSERT_NO_FATAL_FAILURE(ComboboxTestApi(combobox).PerformActionAt(2)); | 481 ASSERT_NO_FATAL_FAILURE(ComboboxTestApi(combobox).PerformActionAt(2)); |
| 482 EXPECT_TRUE(evil_listener->deleted()); | 482 EXPECT_TRUE(evil_listener->deleted()); |
| 483 | 483 |
| 484 // With STYLE_ACTION | 484 // With STYLE_ACTION |
| 485 // |combobox| will be deleted on change. | 485 // |combobox| will be deleted on change. |
| 486 combobox = new TestCombobox(&model); | 486 combobox = new TestCombobox(&model); |
| 487 evil_listener.reset(new EvilListener()); | 487 evil_listener.reset(new EvilListener()); |
| 488 combobox->set_listener(evil_listener.get()); | 488 combobox->set_listener(evil_listener.get()); |
| 489 combobox->SetStyle(Combobox::STYLE_ACTION); | 489 combobox->SetStyle(Combobox::STYLE_ACTION); |
| (...skipping 269 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 759 EXPECT_EQ(ASCIIToUTF16("JELLY"), menu_model->GetLabelAt(1)); | 759 EXPECT_EQ(ASCIIToUTF16("JELLY"), menu_model->GetLabelAt(1)); |
| 760 | 760 |
| 761 // Check that with STYLE_ACTION, the first item (only) is not shown. | 761 // Check that with STYLE_ACTION, the first item (only) is not shown. |
| 762 EXPECT_TRUE(menu_model->IsVisibleAt(0)); | 762 EXPECT_TRUE(menu_model->IsVisibleAt(0)); |
| 763 combobox_->SetStyle(Combobox::STYLE_ACTION); | 763 combobox_->SetStyle(Combobox::STYLE_ACTION); |
| 764 EXPECT_FALSE(menu_model->IsVisibleAt(0)); | 764 EXPECT_FALSE(menu_model->IsVisibleAt(0)); |
| 765 EXPECT_TRUE(menu_model->IsVisibleAt(1)); | 765 EXPECT_TRUE(menu_model->IsVisibleAt(1)); |
| 766 } | 766 } |
| 767 | 767 |
| 768 } // namespace views | 768 } // namespace views |
| OLD | NEW |