Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(500)

Side by Side Diff: ui/views/controls/combobox/combobox_unittest.cc

Issue 104573003: Make ComboboxListener work around being deleted from OnSelectedIndexChanged(). (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: , Created 7 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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"
11 #include "ui/events/event.h" 11 #include "ui/events/event.h"
12 #include "ui/events/keycodes/keyboard_codes.h" 12 #include "ui/events/keycodes/keyboard_codes.h"
13 #include "ui/views/controls/combobox/combobox_listener.h"
13 #include "ui/views/ime/mock_input_method.h" 14 #include "ui/views/ime/mock_input_method.h"
14 #include "ui/views/test/views_test_base.h" 15 #include "ui/views/test/views_test_base.h"
15 #include "ui/views/widget/widget.h" 16 #include "ui/views/widget/widget.h"
16 17
17 namespace { 18 namespace {
18 19
19 // A wrapper of Combobox to intercept the result of OnKeyPressed() and 20 // A wrapper of Combobox to intercept the result of OnKeyPressed() and
20 // OnKeyReleased() methods. 21 // OnKeyReleased() methods.
21 class TestCombobox : public views::Combobox { 22 class TestCombobox : public views::Combobox {
22 public: 23 public:
(...skipping 310 matching lines...) Expand 10 before | Expand all | Expand 10 after
333 InitCombobox(); 334 InitCombobox();
334 ASSERT_EQ(model_->GetDefaultIndex(), combobox_->selected_index()); 335 ASSERT_EQ(model_->GetDefaultIndex(), combobox_->selected_index());
335 EXPECT_TRUE(combobox_->SelectValue(ASCIIToUTF16("PEANUT BUTTER"))); 336 EXPECT_TRUE(combobox_->SelectValue(ASCIIToUTF16("PEANUT BUTTER")));
336 EXPECT_EQ(0, combobox_->selected_index()); 337 EXPECT_EQ(0, combobox_->selected_index());
337 EXPECT_TRUE(combobox_->SelectValue(ASCIIToUTF16("JELLY"))); 338 EXPECT_TRUE(combobox_->SelectValue(ASCIIToUTF16("JELLY")));
338 EXPECT_EQ(1, combobox_->selected_index()); 339 EXPECT_EQ(1, combobox_->selected_index());
339 EXPECT_FALSE(combobox_->SelectValue(ASCIIToUTF16("BANANAS"))); 340 EXPECT_FALSE(combobox_->SelectValue(ASCIIToUTF16("BANANAS")));
340 EXPECT_EQ(1, combobox_->selected_index()); 341 EXPECT_EQ(1, combobox_->selected_index());
341 } 342 }
342 343
344 class EvilListener : public ComboboxListener {
345 public:
346 EvilListener() : deleted_(false) {};
347 virtual ~EvilListener() {};
348
349 // ComboboxListener:
350 virtual void OnSelectedIndexChanged(Combobox* combobox) OVERRIDE {
351 delete combobox;
352 deleted_ = true;
353 }
354
355 bool deleted() const { return deleted_; }
356
357 private:
358 bool deleted_;
359 };
sky 2013/12/05 04:07:30 nit: DISALLOW...
Dan Beam 2013/12/05 17:05:33 Done.
360
361 TEST_F(ComboboxTest, ListenerHandlesDelete) {
362 TestComboboxModel model;
363 TestCombobox* combobox = new TestCombobox(&model); // Deleted on change.
364 EvilListener evil_listener;
365 combobox->set_listener(&evil_listener);
366 ASSERT_NO_FATAL_FAILURE(combobox->ExecuteCommand(2));
367 EXPECT_TRUE(evil_listener.deleted());
368 }
369
343 } // namespace views 370 } // namespace views
OLDNEW
« ui/views/controls/combobox/combobox.cc ('K') | « ui/views/controls/combobox/combobox.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698