This source file includes following definitions.
- GetPaintRegion
- visible_col_count
- header
- AddRow
- RemoveRow
- ChangeRow
- RowCount
- GetText
- SetObserver
- CompareValues
- GetViewToModelAsString
- GetModelToViewAsString
- HasFocus
- SetUp
- ClickOnRow
- TapOnRow
- SelectionStateAsString
- PressKey
- TEST_F
- TEST_F
- TEST_F
- TEST_F
- TEST_F
- TEST_F
- SetRanges
- GetGroupRange
- TEST_F
- GetChangedCountAndClear
- OnSelectionChanged
- TEST_F
- TEST_F
- TEST_F
- TEST_F
- TEST_F
- TEST_F
#include "ui/views/controls/table/table_view.h"
#include "base/strings/string_number_conversions.h"
#include "base/strings/utf_string_conversions.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "ui/views/controls/table/table_grouper.h"
#include "ui/views/controls/table/table_header.h"
#include "ui/views/controls/table/table_view_observer.h"
namespace views {
class TableViewTestHelper {
public:
explicit TableViewTestHelper(TableView* table) : table_(table) {}
std::string GetPaintRegion(const gfx::Rect& bounds) {
TableView::PaintRegion region(table_->GetPaintRegion(bounds));
return "rows=" + base::IntToString(region.min_row) + " " +
base::IntToString(region.max_row) + " cols=" +
base::IntToString(region.min_column) + " " +
base::IntToString(region.max_column);
}
size_t visible_col_count() {
return table_->visible_columns().size();
}
TableHeader* header() { return table_->header_; }
private:
TableView* table_;
DISALLOW_COPY_AND_ASSIGN(TableViewTestHelper);
};
namespace {
class TestTableModel2 : public ui::TableModel {
public:
TestTableModel2();
void AddRow(int row, int c1_value, int c2_value);
void RemoveRow(int row);
void ChangeRow(int row, int c1_value, int c2_value);
virtual int RowCount() OVERRIDE;
virtual base::string16 GetText(int row, int column_id) OVERRIDE;
virtual void SetObserver(ui::TableModelObserver* observer) OVERRIDE;
virtual int CompareValues(int row1, int row2, int column_id) OVERRIDE;
private:
ui::TableModelObserver* observer_;
std::vector<std::vector<int> > rows_;
DISALLOW_COPY_AND_ASSIGN(TestTableModel2);
};
TestTableModel2::TestTableModel2() : observer_(NULL) {
AddRow(0, 0, 1);
AddRow(1, 1, 1);
AddRow(2, 2, 2);
AddRow(3, 3, 0);
}
void TestTableModel2::AddRow(int row, int c1_value, int c2_value) {
DCHECK(row >= 0 && row <= static_cast<int>(rows_.size()));
std::vector<int> new_row;
new_row.push_back(c1_value);
new_row.push_back(c2_value);
rows_.insert(rows_.begin() + row, new_row);
if (observer_)
observer_->OnItemsAdded(row, 1);
}
void TestTableModel2::RemoveRow(int row) {
DCHECK(row >= 0 && row <= static_cast<int>(rows_.size()));
rows_.erase(rows_.begin() + row);
if (observer_)
observer_->OnItemsRemoved(row, 1);
}
void TestTableModel2::ChangeRow(int row, int c1_value, int c2_value) {
DCHECK(row >= 0 && row < static_cast<int>(rows_.size()));
rows_[row][0] = c1_value;
rows_[row][1] = c2_value;
if (observer_)
observer_->OnItemsChanged(row, 1);
}
int TestTableModel2::RowCount() {
return static_cast<int>(rows_.size());
}
base::string16 TestTableModel2::GetText(int row, int column_id) {
return base::IntToString16(rows_[row][column_id]);
}
void TestTableModel2::SetObserver(ui::TableModelObserver* observer) {
observer_ = observer;
}
int TestTableModel2::CompareValues(int row1, int row2, int column_id) {
return rows_[row1][column_id] - rows_[row2][column_id];
}
std::string GetViewToModelAsString(TableView* table) {
std::string result;
for (int i = 0; i < table->RowCount(); ++i) {
if (i != 0)
result += " ";
result += base::IntToString(table->ViewToModel(i));
}
return result;
}
std::string GetModelToViewAsString(TableView* table) {
std::string result;
for (int i = 0; i < table->RowCount(); ++i) {
if (i != 0)
result += " ";
result += base::IntToString(table->ModelToView(i));
}
return result;
}
class TestTableView : public TableView {
public:
TestTableView(ui::TableModel* model,
const std::vector<ui::TableColumn>& columns)
: TableView(model, columns, TEXT_ONLY, false) {
}
virtual bool HasFocus() const OVERRIDE {
return true;
}
private:
DISALLOW_COPY_AND_ASSIGN(TestTableView);
};
}
class TableViewTest : public testing::Test {
public:
TableViewTest() : table_(NULL) {}
virtual void SetUp() OVERRIDE {
model_.reset(new TestTableModel2);
std::vector<ui::TableColumn> columns(2);
columns[0].title = base::ASCIIToUTF16("Title Column 0");
columns[0].sortable = true;
columns[1].title = base::ASCIIToUTF16("Title Column 1");
columns[1].id = 1;
columns[1].sortable = true;
table_ = new TestTableView(model_.get(), columns);
parent_.reset(table_->CreateParentIfNecessary());
parent_->SetBounds(0, 0, 10000, 10000);
parent_->Layout();
helper_.reset(new TableViewTestHelper(table_));
}
void ClickOnRow(int row, int flags) {
const int y = row * table_->row_height();
const ui::MouseEvent pressed(ui::ET_MOUSE_PRESSED, gfx::Point(0, y),
gfx::Point(0, y),
ui::EF_LEFT_MOUSE_BUTTON | flags,
ui::EF_LEFT_MOUSE_BUTTON);
table_->OnMousePressed(pressed);
}
void TapOnRow(int row) {
const int y = row * table_->row_height();
const ui::GestureEventDetails event_details(ui::ET_GESTURE_TAP,
.0f, .0f);
ui::GestureEvent tap(ui::ET_GESTURE_TAP, 0, y, 0, base::TimeDelta(),
event_details, 1);
table_->OnGestureEvent(&tap);
}
std::string SelectionStateAsString() const {
const ui::ListSelectionModel& model(table_->selection_model());
std::string result = "active=" + base::IntToString(model.active()) +
" anchor=" + base::IntToString(model.anchor()) +
" selection=";
const ui::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;
}
void PressKey(ui::KeyboardCode code) {
ui::KeyEvent event(ui::ET_KEY_PRESSED, code, 0, false);
table_->OnKeyPressed(event);
}
protected:
scoped_ptr<TestTableModel2> model_;
TableView* table_;
scoped_ptr<TableViewTestHelper> helper_;
private:
scoped_ptr<View> parent_;
DISALLOW_COPY_AND_ASSIGN(TableViewTest);
};
TEST_F(TableViewTest, GetPaintRegion) {
EXPECT_EQ(2u, helper_->visible_col_count());
EXPECT_EQ("rows=0 4 cols=0 2", helper_->GetPaintRegion(table_->bounds()));
EXPECT_EQ("rows=0 4 cols=0 1",
helper_->GetPaintRegion(gfx::Rect(0, 0, 1, table_->height())));
}
TEST_F(TableViewTest, ColumnVisibility) {
EXPECT_EQ(2u, helper_->visible_col_count());
table_->SetColumnVisibility(0, true);
EXPECT_EQ(2u, helper_->visible_col_count());
table_->SetColumnVisibility(0, false);
ASSERT_EQ(1u, helper_->visible_col_count());
EXPECT_EQ(1, table_->visible_columns()[0].column.id);
EXPECT_EQ("rows=0 4 cols=0 1", helper_->GetPaintRegion(table_->bounds()));
table_->SetColumnVisibility(1, false);
EXPECT_EQ(0u, helper_->visible_col_count());
table_->SetColumnVisibility(1, true);
ASSERT_EQ(1u, helper_->visible_col_count());
EXPECT_EQ(1, table_->visible_columns()[0].column.id);
EXPECT_EQ("rows=0 4 cols=0 1", helper_->GetPaintRegion(table_->bounds()));
table_->SetColumnVisibility(0, true);
ASSERT_EQ(2u, helper_->visible_col_count());
EXPECT_EQ(1, table_->visible_columns()[0].column.id);
EXPECT_EQ(0, table_->visible_columns()[1].column.id);
EXPECT_EQ("rows=0 4 cols=0 2", helper_->GetPaintRegion(table_->bounds()));
}
TEST_F(TableViewTest, Resize) {
const int x = table_->visible_columns()[0].width;
EXPECT_NE(0, x);
const ui::MouseEvent pressed(ui::ET_MOUSE_PRESSED, gfx::Point(x, 0),
gfx::Point(x, 0), ui::EF_LEFT_MOUSE_BUTTON,
ui::EF_LEFT_MOUSE_BUTTON);
helper_->header()->OnMousePressed(pressed);
const ui::MouseEvent dragged(ui::ET_MOUSE_DRAGGED, gfx::Point(x - 1, 0),
gfx::Point(x - 1, 0), ui::EF_LEFT_MOUSE_BUTTON,
0);
helper_->header()->OnMouseDragged(dragged);
EXPECT_EQ(x - 1, table_->visible_columns()[0].width);
EXPECT_EQ(x - 1, table_->visible_columns()[1].x);
}
TEST_F(TableViewTest, ResizeViaGesture) {
const int x = table_->visible_columns()[0].width;
EXPECT_NE(0, x);
const ui::GestureEventDetails event_details(ui::ET_GESTURE_SCROLL_BEGIN,
.0f, .0f);
ui::GestureEvent scroll_begin(ui::ET_GESTURE_SCROLL_BEGIN, x, 0, 0,
base::TimeDelta(), event_details, 1);
helper_->header()->OnGestureEvent(&scroll_begin);
ui::GestureEvent scroll_update(ui::ET_GESTURE_SCROLL_UPDATE, x - 1, 0,
0, base::TimeDelta(), event_details, 1);
helper_->header()->OnGestureEvent(&scroll_update);
EXPECT_EQ(x - 1, table_->visible_columns()[0].width);
EXPECT_EQ(x - 1, table_->visible_columns()[1].x);
}
TEST_F(TableViewTest, Sort) {
table_->ToggleSortOrder(0);
ASSERT_EQ(1u, table_->sort_descriptors().size());
EXPECT_EQ(0, table_->sort_descriptors()[0].column_id);
EXPECT_TRUE(table_->sort_descriptors()[0].ascending);
EXPECT_EQ("0 1 2 3", GetViewToModelAsString(table_));
EXPECT_EQ("0 1 2 3", GetModelToViewAsString(table_));
table_->ToggleSortOrder(0);
ASSERT_EQ(1u, table_->sort_descriptors().size());
EXPECT_EQ(0, table_->sort_descriptors()[0].column_id);
EXPECT_FALSE(table_->sort_descriptors()[0].ascending);
EXPECT_EQ("3 2 1 0", GetViewToModelAsString(table_));
EXPECT_EQ("3 2 1 0", GetModelToViewAsString(table_));
model_->ChangeRow(3, -1, 0);
ASSERT_EQ(1u, table_->sort_descriptors().size());
EXPECT_EQ(0, table_->sort_descriptors()[0].column_id);
EXPECT_FALSE(table_->sort_descriptors()[0].ascending);
EXPECT_EQ("2 1 0 3", GetViewToModelAsString(table_));
EXPECT_EQ("2 1 0 3", GetModelToViewAsString(table_));
table_->ToggleSortOrder(0);
ASSERT_EQ(1u, table_->sort_descriptors().size());
EXPECT_EQ(0, table_->sort_descriptors()[0].column_id);
EXPECT_TRUE(table_->sort_descriptors()[0].ascending);
EXPECT_EQ("3 0 1 2", GetViewToModelAsString(table_));
EXPECT_EQ("1 2 3 0", GetModelToViewAsString(table_));
model_->AddRow(1, 3, 4);
ASSERT_EQ(1u, table_->sort_descriptors().size());
EXPECT_EQ(0, table_->sort_descriptors()[0].column_id);
EXPECT_TRUE(table_->sort_descriptors()[0].ascending);
EXPECT_EQ("4 0 2 3 1", GetViewToModelAsString(table_));
EXPECT_EQ("1 4 2 3 0", GetModelToViewAsString(table_));
model_->RemoveRow(0);
ASSERT_EQ(1u, table_->sort_descriptors().size());
EXPECT_EQ(0, table_->sort_descriptors()[0].column_id);
EXPECT_TRUE(table_->sort_descriptors()[0].ascending);
EXPECT_EQ("3 1 2 0", GetViewToModelAsString(table_));
EXPECT_EQ("3 1 2 0", GetModelToViewAsString(table_));
}
TEST_F(TableViewTest, SortOnMouse) {
EXPECT_TRUE(table_->sort_descriptors().empty());
const int x = table_->visible_columns()[0].width / 2;
EXPECT_NE(0, x);
const ui::MouseEvent pressed(ui::ET_MOUSE_PRESSED, gfx::Point(x, 0),
gfx::Point(x, 0), ui::EF_LEFT_MOUSE_BUTTON,
ui::EF_LEFT_MOUSE_BUTTON);
EXPECT_TRUE(helper_->header()->OnMousePressed(pressed));
const ui::MouseEvent release(ui::ET_MOUSE_RELEASED, gfx::Point(x, 0),
gfx::Point(x, 0), ui::EF_LEFT_MOUSE_BUTTON,
ui::EF_LEFT_MOUSE_BUTTON);
helper_->header()->OnMouseReleased(release);
ASSERT_EQ(1u, table_->sort_descriptors().size());
EXPECT_EQ(0, table_->sort_descriptors()[0].column_id);
EXPECT_TRUE(table_->sort_descriptors()[0].ascending);
}
namespace {
class TableGrouperImpl : public TableGrouper {
public:
TableGrouperImpl() {}
void SetRanges(const std::vector<int>& ranges) {
ranges_ = ranges;
}
virtual void GetGroupRange(int model_index, GroupRange* range) OVERRIDE {
int offset = 0;
size_t range_index = 0;
for (; range_index < ranges_.size() && offset < model_index; ++range_index)
offset += ranges_[range_index];
if (offset == model_index) {
range->start = model_index;
range->length = ranges_[range_index];
} else {
range->start = offset - ranges_[range_index - 1];
range->length = ranges_[range_index - 1];
}
}
private:
std::vector<int> ranges_;
DISALLOW_COPY_AND_ASSIGN(TableGrouperImpl);
};
}
TEST_F(TableViewTest, Grouping) {
TableGrouperImpl grouper;
std::vector<int> ranges;
ranges.push_back(2);
ranges.push_back(2);
grouper.SetRanges(ranges);
table_->SetGrouper(&grouper);
table_->ToggleSortOrder(0);
ASSERT_EQ(1u, table_->sort_descriptors().size());
EXPECT_EQ(0, table_->sort_descriptors()[0].column_id);
EXPECT_TRUE(table_->sort_descriptors()[0].ascending);
EXPECT_EQ("0 1 2 3", GetViewToModelAsString(table_));
EXPECT_EQ("0 1 2 3", GetModelToViewAsString(table_));
table_->ToggleSortOrder(0);
ASSERT_EQ(1u, table_->sort_descriptors().size());
EXPECT_EQ(0, table_->sort_descriptors()[0].column_id);
EXPECT_FALSE(table_->sort_descriptors()[0].ascending);
EXPECT_EQ("2 3 0 1", GetViewToModelAsString(table_));
EXPECT_EQ("2 3 0 1", GetModelToViewAsString(table_));
model_->ChangeRow(3, -1, 0);
ASSERT_EQ(1u, table_->sort_descriptors().size());
EXPECT_EQ(0, table_->sort_descriptors()[0].column_id);
EXPECT_FALSE(table_->sort_descriptors()[0].ascending);
EXPECT_EQ("2 3 0 1", GetViewToModelAsString(table_));
EXPECT_EQ("2 3 0 1", GetModelToViewAsString(table_));
model_->ChangeRow(2, -1, 0);
ASSERT_EQ(1u, table_->sort_descriptors().size());
EXPECT_EQ(0, table_->sort_descriptors()[0].column_id);
EXPECT_FALSE(table_->sort_descriptors()[0].ascending);
EXPECT_EQ("0 1 2 3", GetViewToModelAsString(table_));
EXPECT_EQ("0 1 2 3", GetModelToViewAsString(table_));
table_->ToggleSortOrder(0);
ASSERT_EQ(1u, table_->sort_descriptors().size());
EXPECT_EQ(0, table_->sort_descriptors()[0].column_id);
EXPECT_TRUE(table_->sort_descriptors()[0].ascending);
EXPECT_EQ("2 3 0 1", GetViewToModelAsString(table_));
EXPECT_EQ("2 3 0 1", GetModelToViewAsString(table_));
}
namespace {
class TableViewObserverImpl : public TableViewObserver {
public:
TableViewObserverImpl() : selection_changed_count_(0) {}
int GetChangedCountAndClear() {
const int count = selection_changed_count_;
selection_changed_count_ = 0;
return count;
}
virtual void OnSelectionChanged() OVERRIDE {
selection_changed_count_++;
}
private:
int selection_changed_count_;
DISALLOW_COPY_AND_ASSIGN(TableViewObserverImpl);
};
}
TEST_F(TableViewTest, Selection) {
TableViewObserverImpl observer;
table_->SetObserver(&observer);
EXPECT_EQ("active=-1 anchor=-1 selection=", SelectionStateAsString());
table_->Select(3);
EXPECT_EQ(1, observer.GetChangedCountAndClear());
EXPECT_EQ("active=3 anchor=3 selection=3", SelectionStateAsString());
table_->ToggleSortOrder(0);
table_->ToggleSortOrder(0);
EXPECT_EQ(0, observer.GetChangedCountAndClear());
EXPECT_EQ("active=3 anchor=3 selection=3", SelectionStateAsString());
model_->RemoveRow(3);
EXPECT_EQ(1, observer.GetChangedCountAndClear());
EXPECT_EQ("active=2 anchor=2 selection=2", SelectionStateAsString());
model_->AddRow(0, 1, 2);
EXPECT_EQ(0, observer.GetChangedCountAndClear());
EXPECT_EQ("active=3 anchor=3 selection=3", SelectionStateAsString());
table_->SetObserver(NULL);
}
TEST_F(TableViewTest, SelectOnTap) {
EXPECT_EQ("active=-1 anchor=-1 selection=", SelectionStateAsString());
TableViewObserverImpl observer;
table_->SetObserver(&observer);
TapOnRow(0);
EXPECT_EQ(1, observer.GetChangedCountAndClear());
EXPECT_EQ("active=0 anchor=0 selection=0", SelectionStateAsString());
table_->SetObserver(NULL);
}
TEST_F(TableViewTest, KeyUpDown) {
model_->AddRow(2, 5, 0);
TableGrouperImpl grouper;
std::vector<int> ranges;
ranges.push_back(2);
ranges.push_back(1);
ranges.push_back(2);
grouper.SetRanges(ranges);
table_->SetGrouper(&grouper);
TableViewObserverImpl observer;
table_->SetObserver(&observer);
EXPECT_EQ("active=-1 anchor=-1 selection=", SelectionStateAsString());
PressKey(ui::VKEY_DOWN);
EXPECT_EQ(1, observer.GetChangedCountAndClear());
EXPECT_EQ("active=0 anchor=0 selection=0 1", SelectionStateAsString());
PressKey(ui::VKEY_DOWN);
EXPECT_EQ(1, observer.GetChangedCountAndClear());
EXPECT_EQ("active=1 anchor=1 selection=0 1", SelectionStateAsString());
PressKey(ui::VKEY_DOWN);
EXPECT_EQ(1, observer.GetChangedCountAndClear());
EXPECT_EQ("active=2 anchor=2 selection=2", SelectionStateAsString());
PressKey(ui::VKEY_DOWN);
EXPECT_EQ(1, observer.GetChangedCountAndClear());
EXPECT_EQ("active=3 anchor=3 selection=3 4", SelectionStateAsString());
PressKey(ui::VKEY_DOWN);
EXPECT_EQ(1, observer.GetChangedCountAndClear());
EXPECT_EQ("active=4 anchor=4 selection=3 4", SelectionStateAsString());
PressKey(ui::VKEY_DOWN);
EXPECT_EQ(0, observer.GetChangedCountAndClear());
EXPECT_EQ("active=4 anchor=4 selection=3 4", SelectionStateAsString());
PressKey(ui::VKEY_UP);
EXPECT_EQ(1, observer.GetChangedCountAndClear());
EXPECT_EQ("active=3 anchor=3 selection=3 4", SelectionStateAsString());
PressKey(ui::VKEY_UP);
EXPECT_EQ(1, observer.GetChangedCountAndClear());
EXPECT_EQ("active=2 anchor=2 selection=2", SelectionStateAsString());
PressKey(ui::VKEY_UP);
EXPECT_EQ(1, observer.GetChangedCountAndClear());
EXPECT_EQ("active=1 anchor=1 selection=0 1", SelectionStateAsString());
PressKey(ui::VKEY_UP);
EXPECT_EQ(1, observer.GetChangedCountAndClear());
EXPECT_EQ("active=0 anchor=0 selection=0 1", SelectionStateAsString());
PressKey(ui::VKEY_UP);
EXPECT_EQ(0, observer.GetChangedCountAndClear());
EXPECT_EQ("active=0 anchor=0 selection=0 1", SelectionStateAsString());
table_->ToggleSortOrder(0);
table_->ToggleSortOrder(0);
EXPECT_EQ("2 3 4 0 1", GetViewToModelAsString(table_));
table_->Select(-1);
EXPECT_EQ("active=-1 anchor=-1 selection=", SelectionStateAsString());
observer.GetChangedCountAndClear();
PressKey(ui::VKEY_UP);
EXPECT_EQ(1, observer.GetChangedCountAndClear());
EXPECT_EQ("active=2 anchor=2 selection=2", SelectionStateAsString());
PressKey(ui::VKEY_DOWN);
EXPECT_EQ(1, observer.GetChangedCountAndClear());
EXPECT_EQ("active=3 anchor=3 selection=3 4", SelectionStateAsString());
PressKey(ui::VKEY_DOWN);
EXPECT_EQ(1, observer.GetChangedCountAndClear());
EXPECT_EQ("active=4 anchor=4 selection=3 4", SelectionStateAsString());
PressKey(ui::VKEY_DOWN);
EXPECT_EQ(1, observer.GetChangedCountAndClear());
EXPECT_EQ("active=0 anchor=0 selection=0 1", SelectionStateAsString());
PressKey(ui::VKEY_DOWN);
EXPECT_EQ(1, observer.GetChangedCountAndClear());
EXPECT_EQ("active=1 anchor=1 selection=0 1", SelectionStateAsString());
PressKey(ui::VKEY_DOWN);
EXPECT_EQ(0, observer.GetChangedCountAndClear());
EXPECT_EQ("active=1 anchor=1 selection=0 1", SelectionStateAsString());
PressKey(ui::VKEY_UP);
EXPECT_EQ(1, observer.GetChangedCountAndClear());
EXPECT_EQ("active=0 anchor=0 selection=0 1", SelectionStateAsString());
PressKey(ui::VKEY_UP);
EXPECT_EQ(1, observer.GetChangedCountAndClear());
EXPECT_EQ("active=4 anchor=4 selection=3 4", SelectionStateAsString());
PressKey(ui::VKEY_UP);
EXPECT_EQ(1, observer.GetChangedCountAndClear());
EXPECT_EQ("active=3 anchor=3 selection=3 4", SelectionStateAsString());
PressKey(ui::VKEY_UP);
EXPECT_EQ(1, observer.GetChangedCountAndClear());
EXPECT_EQ("active=2 anchor=2 selection=2", SelectionStateAsString());
PressKey(ui::VKEY_UP);
EXPECT_EQ(0, observer.GetChangedCountAndClear());
EXPECT_EQ("active=2 anchor=2 selection=2", SelectionStateAsString());
table_->SetObserver(NULL);
}
TEST_F(TableViewTest, HomeEnd) {
model_->AddRow(2, 5, 0);
TableGrouperImpl grouper;
std::vector<int> ranges;
ranges.push_back(2);
ranges.push_back(1);
ranges.push_back(2);
grouper.SetRanges(ranges);
table_->SetGrouper(&grouper);
TableViewObserverImpl observer;
table_->SetObserver(&observer);
EXPECT_EQ("active=-1 anchor=-1 selection=", SelectionStateAsString());
PressKey(ui::VKEY_HOME);
EXPECT_EQ(1, observer.GetChangedCountAndClear());
EXPECT_EQ("active=0 anchor=0 selection=0 1", SelectionStateAsString());
PressKey(ui::VKEY_END);
EXPECT_EQ(1, observer.GetChangedCountAndClear());
EXPECT_EQ("active=4 anchor=4 selection=3 4", SelectionStateAsString());
table_->SetObserver(NULL);
}
TEST_F(TableViewTest, Multiselection) {
model_->AddRow(2, 5, 0);
TableGrouperImpl grouper;
std::vector<int> ranges;
ranges.push_back(2);
ranges.push_back(1);
ranges.push_back(2);
grouper.SetRanges(ranges);
table_->SetGrouper(&grouper);
EXPECT_EQ("active=-1 anchor=-1 selection=", SelectionStateAsString());
TableViewObserverImpl observer;
table_->SetObserver(&observer);
ClickOnRow(0, 0);
EXPECT_EQ(1, observer.GetChangedCountAndClear());
EXPECT_EQ("active=0 anchor=0 selection=0 1", SelectionStateAsString());
ClickOnRow(4, 0);
EXPECT_EQ(1, observer.GetChangedCountAndClear());
EXPECT_EQ("active=4 anchor=4 selection=3 4", SelectionStateAsString());
ClickOnRow(2, ui::EF_SHIFT_DOWN);
EXPECT_EQ(1, observer.GetChangedCountAndClear());
EXPECT_EQ("active=2 anchor=4 selection=2 3 4", SelectionStateAsString());
ClickOnRow(2, ui::EF_CONTROL_DOWN);
EXPECT_EQ(1, observer.GetChangedCountAndClear());
EXPECT_EQ("active=2 anchor=2 selection=3 4", SelectionStateAsString());
ClickOnRow(1, ui::EF_CONTROL_DOWN | ui::EF_SHIFT_DOWN);
EXPECT_EQ(1, observer.GetChangedCountAndClear());
EXPECT_EQ("active=1 anchor=2 selection=0 1 2 3 4", SelectionStateAsString());
ClickOnRow(4, 0);
EXPECT_EQ(1, observer.GetChangedCountAndClear());
EXPECT_EQ("active=4 anchor=4 selection=3 4", SelectionStateAsString());
table_->SetObserver(NULL);
}
TEST_F(TableViewTest, MultiselectionWithSort) {
model_->AddRow(2, 5, 0);
TableGrouperImpl grouper;
std::vector<int> ranges;
ranges.push_back(2);
ranges.push_back(1);
ranges.push_back(2);
grouper.SetRanges(ranges);
table_->SetGrouper(&grouper);
table_->ToggleSortOrder(0);
table_->ToggleSortOrder(0);
EXPECT_EQ("active=-1 anchor=-1 selection=", SelectionStateAsString());
TableViewObserverImpl observer;
table_->SetObserver(&observer);
ClickOnRow(2, 0);
EXPECT_EQ(1, observer.GetChangedCountAndClear());
EXPECT_EQ("active=4 anchor=4 selection=3 4", SelectionStateAsString());
ClickOnRow(0, ui::EF_SHIFT_DOWN);
EXPECT_EQ(1, observer.GetChangedCountAndClear());
EXPECT_EQ("active=2 anchor=4 selection=2 3 4", SelectionStateAsString());
table_->SetObserver(NULL);
}
}