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/strings/utf_string_conversions.h" | 9 #include "base/strings/utf_string_conversions.h" |
10 #include "ui/base/models/combobox_model.h" | 10 #include "ui/base/models/combobox_model.h" |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
56 class TestComboboxModel : public ui::ComboboxModel { | 56 class TestComboboxModel : public ui::ComboboxModel { |
57 public: | 57 public: |
58 TestComboboxModel() {} | 58 TestComboboxModel() {} |
59 virtual ~TestComboboxModel() {} | 59 virtual ~TestComboboxModel() {} |
60 | 60 |
61 // ui::ComboboxModel: | 61 // ui::ComboboxModel: |
62 virtual int GetItemCount() const OVERRIDE { | 62 virtual int GetItemCount() const OVERRIDE { |
63 return 10; | 63 return 10; |
64 } | 64 } |
65 virtual string16 GetItemAt(int index) OVERRIDE { | 65 virtual string16 GetItemAt(int index) OVERRIDE { |
66 return string16(); | 66 DCHECK(!IsItemSeparatorAt(index)); |
67 return ASCIIToUTF16(IsItemSeparatorAt(index) ? "SEPARATOR" : "ITEM"); | |
67 } | 68 } |
68 virtual bool IsItemSeparatorAt(int index) OVERRIDE { | 69 virtual bool IsItemSeparatorAt(int index) OVERRIDE { |
69 return separators_.find(index) != separators_.end(); | 70 return separators_.find(index) != separators_.end(); |
70 } | 71 } |
71 | 72 |
72 void SetSeparators(const std::set<int>& separators) { | 73 void SetSeparators(const std::set<int>& separators) { |
73 separators_ = separators; | 74 separators_ = separators; |
74 } | 75 } |
75 | 76 |
76 private: | 77 private: |
(...skipping 223 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
300 SendKeyEvent(ui::VKEY_HOME); | 301 SendKeyEvent(ui::VKEY_HOME); |
301 EXPECT_EQ(0, combobox_->selected_index()); | 302 EXPECT_EQ(0, combobox_->selected_index()); |
302 SendKeyEvent(ui::VKEY_NEXT); | 303 SendKeyEvent(ui::VKEY_NEXT); |
303 EXPECT_EQ(6, combobox_->selected_index()); | 304 EXPECT_EQ(6, combobox_->selected_index()); |
304 SendKeyEvent(ui::VKEY_PRIOR); | 305 SendKeyEvent(ui::VKEY_PRIOR); |
305 EXPECT_EQ(0, combobox_->selected_index()); | 306 EXPECT_EQ(0, combobox_->selected_index()); |
306 SendKeyEvent(ui::VKEY_END); | 307 SendKeyEvent(ui::VKEY_END); |
307 EXPECT_EQ(6, combobox_->selected_index()); | 308 EXPECT_EQ(6, combobox_->selected_index()); |
308 } | 309 } |
309 | 310 |
311 TEST_F(ComboboxTest, GetTextForRowTest) { | |
312 InitCombobox(); | |
313 std::set<int> separators; | |
314 separators.insert(0); | |
315 separators.insert(1); | |
316 separators.insert(9); | |
317 model_->SetSeparators(separators); | |
318 for (int i = 0; i < combobox_->GetRowCount(); ++i) { | |
319 if (separators.count(i) != 0) | |
320 EXPECT_TRUE(combobox_->GetTextForRow(i).empty()); | |
sky
2013/10/18 00:35:24
For loops like this it's best to have << i (or som
msw
2013/10/18 01:07:58
Done.
| |
321 else | |
322 EXPECT_EQ(ASCIIToUTF16("ITEM"), combobox_->GetTextForRow(i)); | |
323 } | |
324 } | |
325 | |
310 } // namespace views | 326 } // namespace views |
OLD | NEW |