OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 // For WinDDK ATL compatibility, these ATL headers must come first. | 5 // For WinDDK ATL compatibility, these ATL headers must come first. |
| 6 |
6 #include "build/build_config.h" | 7 #include "build/build_config.h" |
| 8 |
7 #if defined(OS_WIN) | 9 #if defined(OS_WIN) |
8 #include <atlbase.h> // NOLINT | 10 #include <atlbase.h> // NOLINT |
9 #include <atlwin.h> // NOLINT | 11 #include <atlwin.h> // NOLINT |
10 #endif | 12 #endif |
11 | 13 |
12 #include <vector> // NOLINT | 14 #include <vector> // NOLINT |
13 | 15 |
14 #include "base/compiler_specific.h" | 16 #include "base/compiler_specific.h" |
15 #include "base/message_loop.h" | 17 #include "base/message_loop.h" |
16 #include "base/string_number_conversions.h" | 18 #include "base/string_number_conversions.h" |
17 #include "base/utf_string_conversions.h" | 19 #include "base/utf_string_conversions.h" |
18 #include "testing/gtest/include/gtest/gtest.h" | 20 #include "testing/gtest/include/gtest/gtest.h" |
19 #include "ui/base/models/table_model.h" | 21 #include "ui/base/models/table_model.h" |
20 #include "ui/base/models/table_model_observer.h" | 22 #include "ui/base/models/table_model_observer.h" |
21 #include "views/controls/table/table_view.h" | 23 #include "views/controls/table/table_view.h" |
22 #include "views/controls/table/table_view2.h" | 24 #include "views/controls/table/table_view2.h" |
23 #include "views/widget/widget.h" | 25 #include "views/widget/widget.h" |
24 #include "views/widget/widget_delegate.h" | 26 #include "views/widget/widget_delegate.h" |
25 | 27 |
26 using ui::TableModel; | |
27 using ui::TableModelObserver; // TODO(beng): remove these | |
28 | |
29 // Put the tests in the views namespace to make it easier to declare them as | 28 // Put the tests in the views namespace to make it easier to declare them as |
30 // friend classes. | 29 // friend classes. |
31 namespace views { | 30 namespace views { |
32 | 31 |
33 // TestTableModel -------------------------------------------------------------- | 32 // TestTableModel -------------------------------------------------------------- |
34 | 33 |
35 // Trivial TableModel implementation that is backed by a vector of vectors. | 34 // Trivial TableModel implementation that is backed by a vector of vectors. |
36 // Provides methods for adding/removing/changing the contents that notify the | 35 // Provides methods for adding/removing/changing the contents that notify the |
37 // observer appropriately. | 36 // observer appropriately. |
38 // | 37 // |
39 // Initial contents are: | 38 // Initial contents are: |
40 // 0, 1 | 39 // 0, 1 |
41 // 1, 1 | 40 // 1, 1 |
42 // 2, 2 | 41 // 2, 2 |
43 class TestTableModel : public TableModel { | 42 class TestTableModel : public ui::TableModel { |
44 public: | 43 public: |
45 TestTableModel(); | 44 TestTableModel(); |
46 | 45 |
47 // Adds a new row at index |row| with values |c1_value| and |c2_value|. | 46 // Adds a new row at index |row| with values |c1_value| and |c2_value|. |
48 void AddRow(int row, int c1_value, int c2_value); | 47 void AddRow(int row, int c1_value, int c2_value); |
49 | 48 |
50 // Removes the row at index |row|. | 49 // Removes the row at index |row|. |
51 void RemoveRow(int row); | 50 void RemoveRow(int row); |
52 | 51 |
53 // Changes the values of the row at |row|. | 52 // Changes the values of the row at |row|. |
54 void ChangeRow(int row, int c1_value, int c2_value); | 53 void ChangeRow(int row, int c1_value, int c2_value); |
55 | 54 |
56 // TableModel | 55 // ui::TableModel: |
57 virtual int RowCount() OVERRIDE; | 56 virtual int RowCount() OVERRIDE; |
58 virtual string16 GetText(int row, int column_id) OVERRIDE; | 57 virtual string16 GetText(int row, int column_id) OVERRIDE; |
59 virtual void SetObserver(TableModelObserver* observer) OVERRIDE; | 58 virtual void SetObserver(ui::TableModelObserver* observer) OVERRIDE; |
60 virtual int CompareValues(int row1, int row2, int column_id) OVERRIDE; | 59 virtual int CompareValues(int row1, int row2, int column_id) OVERRIDE; |
61 | 60 |
62 private: | 61 private: |
63 TableModelObserver* observer_; | 62 ui::TableModelObserver* observer_; |
64 | 63 |
65 // The data. | 64 // The data. |
66 std::vector<std::vector<int> > rows_; | 65 std::vector<std::vector<int> > rows_; |
67 | 66 |
68 DISALLOW_COPY_AND_ASSIGN(TestTableModel); | 67 DISALLOW_COPY_AND_ASSIGN(TestTableModel); |
69 }; | 68 }; |
70 | 69 |
71 // Same behavior as TestTableModel, except even items are in one group, while | 70 // Same behavior as TestTableModel, except even items are in one group, while |
72 // odd items are put in a different group. | 71 // odd items are put in a different group. |
73 class GroupTestTableModel : public TestTableModel { | 72 class GroupTestTableModel : public TestTableModel { |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
120 } | 119 } |
121 | 120 |
122 int TestTableModel::RowCount() { | 121 int TestTableModel::RowCount() { |
123 return static_cast<int>(rows_.size()); | 122 return static_cast<int>(rows_.size()); |
124 } | 123 } |
125 | 124 |
126 string16 TestTableModel::GetText(int row, int column_id) { | 125 string16 TestTableModel::GetText(int row, int column_id) { |
127 return UTF8ToUTF16(base::IntToString(rows_[row][column_id])); | 126 return UTF8ToUTF16(base::IntToString(rows_[row][column_id])); |
128 } | 127 } |
129 | 128 |
130 void TestTableModel::SetObserver(TableModelObserver* observer) { | 129 void TestTableModel::SetObserver(ui::TableModelObserver* observer) { |
131 observer_ = observer; | 130 observer_ = observer; |
132 } | 131 } |
133 | 132 |
134 int TestTableModel::CompareValues(int row1, int row2, int column_id) { | 133 int TestTableModel::CompareValues(int row1, int row2, int column_id) { |
135 return rows_[row1][column_id] - rows_[row2][column_id]; | 134 return rows_[row1][column_id] - rows_[row2][column_id]; |
136 } | 135 } |
137 | 136 |
138 #if defined(OS_WIN) | 137 #if defined(OS_WIN) |
139 | 138 |
140 // TableViewTest --------------------------------------------------------------- | 139 // TableViewTest --------------------------------------------------------------- |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
179 TableView* table_; | 178 TableView* table_; |
180 | 179 |
181 private: | 180 private: |
182 MessageLoopForUI message_loop_; | 181 MessageLoopForUI message_loop_; |
183 views::Widget* window_; | 182 views::Widget* window_; |
184 }; | 183 }; |
185 | 184 |
186 void TableViewTest::SetUp() { | 185 void TableViewTest::SetUp() { |
187 OleInitialize(NULL); | 186 OleInitialize(NULL); |
188 model_.reset(CreateModel()); | 187 model_.reset(CreateModel()); |
189 std::vector<TableColumn> columns; | 188 std::vector<ui::TableColumn> columns; |
190 columns.resize(2); | 189 columns.resize(2); |
191 columns[0].id = 0; | 190 columns[0].id = 0; |
192 columns[1].id = 1; | 191 columns[1].id = 1; |
193 table_ = new TableView(model_.get(), columns, views::ICON_AND_TEXT, | 192 table_ = new TableView(model_.get(), columns, views::ICON_AND_TEXT, |
194 false, false, false); | 193 false, false, false); |
195 window_ = views::Widget::CreateWindowWithBounds( | 194 window_ = views::Widget::CreateWindowWithBounds( |
196 this, | 195 this, |
197 gfx::Rect(100, 100, 512, 512)); | 196 gfx::Rect(100, 100, 512, 512)); |
198 } | 197 } |
199 | 198 |
(...skipping 306 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
506 private: | 505 private: |
507 MessageLoopForUI message_loop_; | 506 MessageLoopForUI message_loop_; |
508 views::Widget* window_; | 507 views::Widget* window_; |
509 }; | 508 }; |
510 | 509 |
511 void TableView2Test::SetUp() { | 510 void TableView2Test::SetUp() { |
512 #if defined(OS_WIN) | 511 #if defined(OS_WIN) |
513 OleInitialize(NULL); | 512 OleInitialize(NULL); |
514 #endif | 513 #endif |
515 model_.reset(CreateModel()); | 514 model_.reset(CreateModel()); |
516 std::vector<TableColumn> columns; | 515 std::vector<ui::TableColumn> columns; |
517 columns.resize(2); | 516 columns.resize(2); |
518 columns[0].id = 0; | 517 columns[0].id = 0; |
519 columns[1].id = 1; | 518 columns[1].id = 1; |
520 table_ = new views::TableView2(model_.get(), columns, GetTableType(), | 519 table_ = new views::TableView2(model_.get(), columns, GetTableType(), |
521 views::TableView2::NONE); | 520 views::TableView2::NONE); |
522 window_ = views::Widget::CreateWindowWithBounds( | 521 window_ = views::Widget::CreateWindowWithBounds( |
523 this, | 522 this, |
524 gfx::Rect(100, 100, 512, 512)); | 523 gfx::Rect(100, 100, 512, 512)); |
525 window_->Show(); | 524 window_->Show(); |
526 } | 525 } |
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
639 | 638 |
640 table_->FocusRow(2); | 639 table_->FocusRow(2); |
641 EXPECT_EQ(2, table_->GetFirstFocusedRow()); | 640 EXPECT_EQ(2, table_->GetFirstFocusedRow()); |
642 | 641 |
643 table_->ClearRowFocus(); | 642 table_->ClearRowFocus(); |
644 EXPECT_EQ(-1, table_->GetFirstSelectedRow()); | 643 EXPECT_EQ(-1, table_->GetFirstSelectedRow()); |
645 } | 644 } |
646 #endif | 645 #endif |
647 | 646 |
648 } // namespace views | 647 } // namespace views |
OLD | NEW |