| OLD | NEW |
| 1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 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 <vector> | 5 #include <vector> |
| 6 | 6 |
| 7 #include "app/table_model.h" |
| 8 #include "app/table_model_observer.h" |
| 7 #include "base/message_loop.h" | 9 #include "base/message_loop.h" |
| 8 #include "base/string_util.h" | 10 #include "base/string_util.h" |
| 9 #include "testing/gtest/include/gtest/gtest.h" | 11 #include "testing/gtest/include/gtest/gtest.h" |
| 10 #include "views/controls/table/table_model.h" | |
| 11 #include "views/controls/table/table_view.h" | 12 #include "views/controls/table/table_view.h" |
| 12 #include "views/window/window_delegate.h" | 13 #include "views/window/window_delegate.h" |
| 13 #include "views/window/window_win.h" | 14 #include "views/window/window_win.h" |
| 14 | 15 |
| 15 using views::TableView; | 16 using views::TableView; |
| 16 | 17 |
| 17 // TestTableModel -------------------------------------------------------------- | 18 // TestTableModel -------------------------------------------------------------- |
| 18 | 19 |
| 19 // Trivial TableModel implementation that is backed by a vector of vectors. | 20 // Trivial TableModel implementation that is backed by a vector of vectors. |
| 20 // Provides methods for adding/removing/changing the contents that notify the | 21 // Provides methods for adding/removing/changing the contents that notify the |
| 21 // observer appropriately. | 22 // observer appropriately. |
| 22 // | 23 // |
| 23 // Initial contents are: | 24 // Initial contents are: |
| 24 // 0, 1 | 25 // 0, 1 |
| 25 // 1, 1 | 26 // 1, 1 |
| 26 // 2, 2 | 27 // 2, 2 |
| 27 class TestTableModel : public views::TableModel { | 28 class TestTableModel : public TableModel { |
| 28 public: | 29 public: |
| 29 TestTableModel(); | 30 TestTableModel(); |
| 30 | 31 |
| 31 // Adds a new row at index |row| with values |c1_value| and |c2_value|. | 32 // Adds a new row at index |row| with values |c1_value| and |c2_value|. |
| 32 void AddRow(int row, int c1_value, int c2_value); | 33 void AddRow(int row, int c1_value, int c2_value); |
| 33 | 34 |
| 34 // Removes the row at index |row|. | 35 // Removes the row at index |row|. |
| 35 void RemoveRow(int row); | 36 void RemoveRow(int row); |
| 36 | 37 |
| 37 // Changes the values of the row at |row|. | 38 // Changes the values of the row at |row|. |
| 38 void ChangeRow(int row, int c1_value, int c2_value); | 39 void ChangeRow(int row, int c1_value, int c2_value); |
| 39 | 40 |
| 40 // TableModel | 41 // TableModel |
| 41 virtual int RowCount(); | 42 virtual int RowCount(); |
| 42 virtual std::wstring GetText(int row, int column_id); | 43 virtual std::wstring GetText(int row, int column_id); |
| 43 virtual void SetObserver(views::TableModelObserver* observer); | 44 virtual void SetObserver(TableModelObserver* observer); |
| 44 virtual int CompareValues(int row1, int row2, int column_id); | 45 virtual int CompareValues(int row1, int row2, int column_id); |
| 45 | 46 |
| 46 private: | 47 private: |
| 47 views::TableModelObserver* observer_; | 48 TableModelObserver* observer_; |
| 48 | 49 |
| 49 // The data. | 50 // The data. |
| 50 std::vector<std::vector<int>> rows_; | 51 std::vector<std::vector<int>> rows_; |
| 51 | 52 |
| 52 DISALLOW_COPY_AND_ASSIGN(TestTableModel); | 53 DISALLOW_COPY_AND_ASSIGN(TestTableModel); |
| 53 }; | 54 }; |
| 54 | 55 |
| 55 TestTableModel::TestTableModel() : observer_(NULL) { | 56 TestTableModel::TestTableModel() : observer_(NULL) { |
| 56 AddRow(0, 0, 1); | 57 AddRow(0, 0, 1); |
| 57 AddRow(1, 1, 1); | 58 AddRow(1, 1, 1); |
| (...skipping 25 matching lines...) Expand all Loading... |
| 83 } | 84 } |
| 84 | 85 |
| 85 int TestTableModel::RowCount() { | 86 int TestTableModel::RowCount() { |
| 86 return static_cast<int>(rows_.size()); | 87 return static_cast<int>(rows_.size()); |
| 87 } | 88 } |
| 88 | 89 |
| 89 std::wstring TestTableModel::GetText(int row, int column_id) { | 90 std::wstring TestTableModel::GetText(int row, int column_id) { |
| 90 return IntToWString(rows_[row][column_id]); | 91 return IntToWString(rows_[row][column_id]); |
| 91 } | 92 } |
| 92 | 93 |
| 93 void TestTableModel::SetObserver(views::TableModelObserver* observer) { | 94 void TestTableModel::SetObserver(TableModelObserver* observer) { |
| 94 observer_ = observer; | 95 observer_ = observer; |
| 95 } | 96 } |
| 96 | 97 |
| 97 int TestTableModel::CompareValues(int row1, int row2, int column_id) { | 98 int TestTableModel::CompareValues(int row1, int row2, int column_id) { |
| 98 return rows_[row1][column_id] - rows_[row2][column_id]; | 99 return rows_[row1][column_id] - rows_[row2][column_id]; |
| 99 } | 100 } |
| 100 | 101 |
| 101 // TableViewTest --------------------------------------------------------------- | 102 // TableViewTest --------------------------------------------------------------- |
| 102 | 103 |
| 103 class TableViewTest : public testing::Test, views::WindowDelegate { | 104 class TableViewTest : public testing::Test, views::WindowDelegate { |
| (...skipping 30 matching lines...) Expand all Loading... |
| 134 TableView* table_; | 135 TableView* table_; |
| 135 | 136 |
| 136 private: | 137 private: |
| 137 MessageLoopForUI message_loop_; | 138 MessageLoopForUI message_loop_; |
| 138 views::Window* window_; | 139 views::Window* window_; |
| 139 }; | 140 }; |
| 140 | 141 |
| 141 void TableViewTest::SetUp() { | 142 void TableViewTest::SetUp() { |
| 142 OleInitialize(NULL); | 143 OleInitialize(NULL); |
| 143 model_.reset(CreateModel()); | 144 model_.reset(CreateModel()); |
| 144 std::vector<views::TableColumn> columns; | 145 std::vector<TableColumn> columns; |
| 145 columns.resize(2); | 146 columns.resize(2); |
| 146 columns[0].id = 0; | 147 columns[0].id = 0; |
| 147 columns[1].id = 1; | 148 columns[1].id = 1; |
| 148 table_ = new TableView(model_.get(), columns, views::ICON_AND_TEXT, | 149 table_ = new TableView(model_.get(), columns, views::ICON_AND_TEXT, |
| 149 false, false, false); | 150 false, false, false); |
| 150 window_ = | 151 window_ = |
| 151 views::Window::CreateChromeWindow(NULL, | 152 views::Window::CreateChromeWindow(NULL, |
| 152 gfx::Rect(100, 100, 512, 512), | 153 gfx::Rect(100, 100, 512, 512), |
| 153 this); | 154 this); |
| 154 } | 155 } |
| (...skipping 218 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 373 | 374 |
| 374 model_->AddRow(3, 4, 4); | 375 model_->AddRow(3, 4, 4); |
| 375 | 376 |
| 376 VerifySelectedRows(1, 0, -1); | 377 VerifySelectedRows(1, 0, -1); |
| 377 } | 378 } |
| 378 | 379 |
| 379 TEST_F(NullModelTableViewTest, NullModel) { | 380 TEST_F(NullModelTableViewTest, NullModel) { |
| 380 // There's nothing explicit to test. If there is a bug in TableView relating | 381 // There's nothing explicit to test. If there is a bug in TableView relating |
| 381 // to a NULL model we'll crash. | 382 // to a NULL model we'll crash. |
| 382 } | 383 } |
| OLD | NEW |