Commit 3c59cb9f authored by dpapad@chromium.org's avatar dpapad@chromium.org

Multi-tab: Fixing TabStripSelectionModel::SetSelectedIndex corner case.

BUG=Invoking SetSelectedIndex(-1) results in stack overflow.
TEST=NONE


Review URL: http://codereview.chromium.org/7140001

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@88433 0039d316-1c4b-4281-b951-d872f2087c98
parent a8af1ee5
...@@ -59,7 +59,9 @@ void TabStripSelectionModel::DecrementFrom(int index) { ...@@ -59,7 +59,9 @@ void TabStripSelectionModel::DecrementFrom(int index) {
void TabStripSelectionModel::SetSelectedIndex(int index) { void TabStripSelectionModel::SetSelectedIndex(int index) {
anchor_ = active_ = index; anchor_ = active_ = index;
SetSelectionFromAnchorTo(index); selected_indices_.clear();
if (index != kUnselectedIndex)
selected_indices_.push_back(index);
} }
bool TabStripSelectionModel::IsSelected(int index) const { bool TabStripSelectionModel::IsSelected(int index) const {
......
...@@ -40,6 +40,13 @@ TEST_F(TabStripSelectionModelTest, SetSelectedIndex) { ...@@ -40,6 +40,13 @@ TEST_F(TabStripSelectionModelTest, SetSelectedIndex) {
EXPECT_FALSE(model.empty()); EXPECT_FALSE(model.empty());
} }
TEST_F(TabStripSelectionModelTest, SetSelectedIndexToEmpty) {
TabStripSelectionModel model;
model.SetSelectedIndex(-1);
EXPECT_EQ("active=-1 anchor=-1 selection=", StateAsString(model));
EXPECT_TRUE(model.empty());
}
TEST_F(TabStripSelectionModelTest, IncrementFrom) { TEST_F(TabStripSelectionModelTest, IncrementFrom) {
TabStripSelectionModel model; TabStripSelectionModel model;
model.SetSelectedIndex(1); model.SetSelectedIndex(1);
...@@ -99,6 +106,22 @@ TEST_F(TabStripSelectionModelTest, RemoveIndexFromSelection) { ...@@ -99,6 +106,22 @@ TEST_F(TabStripSelectionModelTest, RemoveIndexFromSelection) {
EXPECT_EQ("active=2 anchor=2 selection=", StateAsString(model)); EXPECT_EQ("active=2 anchor=2 selection=", StateAsString(model));
} }
TEST_F(TabStripSelectionModelTest, SetSelectionFromAnchorTo) {
TabStripSelectionModel model;
model.SetSelectedIndex(2);
model.SetSelectionFromAnchorTo(7);
EXPECT_EQ("active=7 anchor=2 selection=2 3 4 5 6 7", StateAsString(model));
model.Clear();
model.SetSelectedIndex(7);
model.SetSelectionFromAnchorTo(2);
EXPECT_EQ("active=2 anchor=7 selection=2 3 4 5 6 7", StateAsString(model));
model.Clear();
model.SetSelectionFromAnchorTo(7);
EXPECT_EQ("active=7 anchor=7 selection=7", StateAsString(model));
}
TEST_F(TabStripSelectionModelTest, Clear) { TEST_F(TabStripSelectionModelTest, Clear) {
TabStripSelectionModel model; TabStripSelectionModel model;
model.SetSelectedIndex(2); model.SetSelectedIndex(2);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment