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

Unified Diff: ui/base/models/list_selection_model_unittest.cc

Issue 851853002: It is time. (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: Trying to reup because the last upload failed. Created 5 years, 11 months 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « ui/base/models/list_selection_model.cc ('k') | ui/base/models/menu_model.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ui/base/models/list_selection_model_unittest.cc
diff --git a/ui/base/models/list_selection_model_unittest.cc b/ui/base/models/list_selection_model_unittest.cc
deleted file mode 100644
index 7f7a712a68c8b55ead2c6d17c86d5739a5328be3..0000000000000000000000000000000000000000
--- a/ui/base/models/list_selection_model_unittest.cc
+++ /dev/null
@@ -1,197 +0,0 @@
-// Copyright (c) 2012 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#include "ui/base/models/list_selection_model.h"
-
-#include <algorithm>
-#include <string>
-
-#include "base/strings/string_number_conversions.h"
-#include "testing/gtest/include/gtest/gtest.h"
-
-namespace ui {
-
-typedef testing::Test ListSelectionModelTest;
-
-// Returns the state of the selection model as a string. The format is:
-// 'active=X anchor=X selection=X X X...'.
-static std::string StateAsString(const ListSelectionModel& model) {
- std::string result = "active=" + base::IntToString(model.active()) +
- " anchor=" + base::IntToString(model.anchor()) +
- " selection=";
- const ListSelectionModel::SelectedIndices& selection(
- model.selected_indices());
- for (size_t i = 0; i < selection.size(); ++i) {
- if (i != 0)
- result += " ";
- result += base::IntToString(selection[i]);
- }
- return result;
-}
-
-TEST_F(ListSelectionModelTest, InitialState) {
- ListSelectionModel model;
- EXPECT_EQ("active=-1 anchor=-1 selection=", StateAsString(model));
- EXPECT_TRUE(model.empty());
-}
-
-TEST_F(ListSelectionModelTest, SetSelectedIndex) {
- ListSelectionModel model;
- model.SetSelectedIndex(2);
- EXPECT_EQ("active=2 anchor=2 selection=2", StateAsString(model));
- EXPECT_FALSE(model.empty());
-}
-
-TEST_F(ListSelectionModelTest, SetSelectedIndexToEmpty) {
- ListSelectionModel model;
- model.SetSelectedIndex(-1);
- EXPECT_EQ("active=-1 anchor=-1 selection=", StateAsString(model));
- EXPECT_TRUE(model.empty());
-}
-
-TEST_F(ListSelectionModelTest, IncrementFrom) {
- ListSelectionModel model;
- model.SetSelectedIndex(1);
- model.IncrementFrom(1);
- EXPECT_EQ("active=2 anchor=2 selection=2", StateAsString(model));
-
- // Increment from 4. This shouldn't effect the selection as its past the
- // end of the selection.
- model.IncrementFrom(4);
- EXPECT_EQ("active=2 anchor=2 selection=2", StateAsString(model));
-}
-
-TEST_F(ListSelectionModelTest, DecrementFrom) {
- ListSelectionModel model;
- model.SetSelectedIndex(2);
- model.DecrementFrom(0);
- EXPECT_EQ("active=1 anchor=1 selection=1", StateAsString(model));
-
- // Shift down from 1. As the selection as the index being removed, this should
- // clear the selection.
- model.DecrementFrom(1);
- EXPECT_EQ("active=-1 anchor=-1 selection=", StateAsString(model));
-
- // Reset the selection to 2, and shift down from 4. This shouldn't do
- // anything.
- model.SetSelectedIndex(2);
- model.DecrementFrom(4);
- EXPECT_EQ("active=2 anchor=2 selection=2", StateAsString(model));
-}
-
-TEST_F(ListSelectionModelTest, IsSelected) {
- ListSelectionModel model;
- model.SetSelectedIndex(2);
- EXPECT_FALSE(model.IsSelected(0));
- EXPECT_TRUE(model.IsSelected(2));
-}
-
-TEST_F(ListSelectionModelTest, AddIndexToSelected) {
- ListSelectionModel model;
- model.AddIndexToSelection(2);
- EXPECT_EQ("active=-1 anchor=-1 selection=2", StateAsString(model));
-
- model.AddIndexToSelection(4);
- EXPECT_EQ("active=-1 anchor=-1 selection=2 4", StateAsString(model));
-}
-
-TEST_F(ListSelectionModelTest, RemoveIndexFromSelection) {
- ListSelectionModel model;
- model.SetSelectedIndex(2);
- model.AddIndexToSelection(4);
- EXPECT_EQ("active=2 anchor=2 selection=2 4", StateAsString(model));
-
- model.RemoveIndexFromSelection(4);
- EXPECT_EQ("active=2 anchor=2 selection=2", StateAsString(model));
-
- model.RemoveIndexFromSelection(2);
- EXPECT_EQ("active=2 anchor=2 selection=", StateAsString(model));
-}
-
-TEST_F(ListSelectionModelTest, SetSelectionFromAnchorTo) {
- ListSelectionModel 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(ListSelectionModelTest, Clear) {
- ListSelectionModel model;
- model.SetSelectedIndex(2);
-
- model.Clear();
- EXPECT_EQ("active=-1 anchor=-1 selection=", StateAsString(model));
-}
-
-TEST_F(ListSelectionModelTest, MoveToLeft) {
- ListSelectionModel model;
- model.SetSelectedIndex(0);
- model.AddIndexToSelection(4);
- model.AddIndexToSelection(10);
- model.set_anchor(4);
- model.set_active(4);
- model.Move(4, 0);
- EXPECT_EQ("active=0 anchor=0 selection=0 1 10", StateAsString(model));
-}
-
-TEST_F(ListSelectionModelTest, MoveToRight) {
- ListSelectionModel model;
- model.SetSelectedIndex(0);
- model.AddIndexToSelection(4);
- model.AddIndexToSelection(10);
- model.set_anchor(0);
- model.set_active(0);
- model.Move(0, 3);
- EXPECT_EQ("active=3 anchor=3 selection=3 4 10", StateAsString(model));
-}
-
-TEST_F(ListSelectionModelTest, Copy) {
- ListSelectionModel model;
- model.SetSelectedIndex(0);
- model.AddIndexToSelection(4);
- model.AddIndexToSelection(10);
- EXPECT_EQ("active=0 anchor=0 selection=0 4 10", StateAsString(model));
- ListSelectionModel model2;
- model2.Copy(model);
- EXPECT_EQ("active=0 anchor=0 selection=0 4 10", StateAsString(model2));
-}
-
-TEST_F(ListSelectionModelTest, AddSelectionFromAnchorTo) {
- ListSelectionModel model;
- model.SetSelectedIndex(2);
-
- model.AddSelectionFromAnchorTo(4);
- EXPECT_EQ("active=4 anchor=2 selection=2 3 4", StateAsString(model));
-
- model.AddSelectionFromAnchorTo(0);
- EXPECT_EQ("active=0 anchor=2 selection=0 1 2 3 4", StateAsString(model));
-}
-
-TEST_F(ListSelectionModelTest, Equals) {
- ListSelectionModel model1;
- model1.SetSelectedIndex(0);
- model1.AddSelectionFromAnchorTo(4);
-
- ListSelectionModel model2;
- model2.SetSelectedIndex(0);
- model2.AddSelectionFromAnchorTo(4);
-
- EXPECT_TRUE(model1.Equals(model2));
- EXPECT_TRUE(model2.Equals(model1));
-
- model2.SetSelectedIndex(0);
- EXPECT_FALSE(model1.Equals(model2));
- EXPECT_FALSE(model2.Equals(model1));
-}
-
-} // namespace ui
« no previous file with comments | « ui/base/models/list_selection_model.cc ('k') | ui/base/models/menu_model.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698