| Index: ui/views/controls/combobox/combobox_unittest.cc
|
| diff --git a/ui/views/controls/combobox/combobox_unittest.cc b/ui/views/controls/combobox/combobox_unittest.cc
|
| index 580b79f0245801a02b90f94d66efced477dc7ec6..da7bed704efc9c1117b7fbfa6c4296a0664fb996 100644
|
| --- a/ui/views/controls/combobox/combobox_unittest.cc
|
| +++ b/ui/views/controls/combobox/combobox_unittest.cc
|
| @@ -117,6 +117,29 @@ class TestComboboxModel : public ui::ComboboxModel {
|
| DISALLOW_COPY_AND_ASSIGN(TestComboboxModel);
|
| };
|
|
|
| +// A combobox model which refers to a vector.
|
| +class VectorComboboxModel : public ui::ComboboxModel {
|
| + public:
|
| + VectorComboboxModel(std::vector<std::string>* values)
|
| + : values_(values) {
|
| + }
|
| + virtual ~VectorComboboxModel() {}
|
| +
|
| + // ui::ComboboxModel:
|
| + virtual int GetItemCount() const OVERRIDE {
|
| + return values_->size();
|
| + }
|
| + virtual base::string16 GetItemAt(int index) OVERRIDE {
|
| + return ASCIIToUTF16(values_->at(index));
|
| + }
|
| + virtual bool IsItemSeparatorAt(int index) OVERRIDE {
|
| + return false;
|
| + }
|
| +
|
| + private:
|
| + std::vector<std::string>* values_;
|
| +};
|
| +
|
| class EvilListener : public ComboboxListener {
|
| public:
|
| EvilListener() : deleted_(false) {};
|
| @@ -556,4 +579,40 @@ TEST_F(ComboboxTest, ConsumingPressKeyEvents) {
|
| ui::KeyEvent(ui::ET_KEY_PRESSED, ui::VKEY_SPACE, 0, false)));
|
| }
|
|
|
| +TEST_F(ComboboxTest, ContentWidth) {
|
| + std::vector<std::string> values;
|
| +
|
| + scoped_ptr<VectorComboboxModel> model(new VectorComboboxModel(&values));
|
| + combobox_ = new TestCombobox(model.get());
|
| +
|
| + std::string long_item = "this is the long item";
|
| + std::string short_item = "s";
|
| +
|
| + values.resize(1);
|
| + values[0] = long_item;
|
| + combobox_->ModelChanged();
|
| +
|
| + const int long_item_width = combobox_->content_size_.width();
|
| +
|
| + values[0] = short_item;
|
| + combobox_->ModelChanged();
|
| +
|
| + const int short_item_width = combobox_->content_size_.width();
|
| +
|
| + values.resize(2);
|
| + values[0] = short_item;
|
| + values[1] = long_item;
|
| + combobox_->ModelChanged();
|
| +
|
| + // When the style is STYLE_SHOW_DROP_DOWN_ON_CLICK, the width will fit with
|
| + // the longest item.
|
| + combobox_->SetStyle(Combobox::STYLE_SHOW_DROP_DOWN_ON_CLICK);
|
| + EXPECT_EQ(long_item_width, combobox_->content_size_.width());
|
| +
|
| + // When the style is STYLE_NOTIFY_ON_CLICK, the width will fit with the first
|
| + // items' width.
|
| + combobox_->SetStyle(Combobox::STYLE_NOTIFY_ON_CLICK);
|
| + EXPECT_EQ(short_item_width, combobox_->content_size_.width());
|
| +}
|
| +
|
| } // namespace views
|
|
|