| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 |
| 7 #include "build/build_config.h" | 7 #include "build/build_config.h" |
| 8 | 8 |
| 9 #include <atlbase.h> // NOLINT | 9 #include <atlbase.h> // NOLINT |
| 10 #include <atlwin.h> // NOLINT | 10 #include <atlwin.h> // NOLINT |
| 11 #include <vector> // NOLINT | 11 #include <vector> // NOLINT |
| 12 | 12 |
| 13 #include "base/compiler_specific.h" | 13 #include "base/compiler_specific.h" |
| 14 #include "base/message_loop.h" | 14 #include "base/message_loop.h" |
| 15 #include "base/string_number_conversions.h" | 15 #include "base/string_number_conversions.h" |
| 16 #include "base/utf_string_conversions.h" | 16 #include "base/utf_string_conversions.h" |
| 17 #include "testing/gtest/include/gtest/gtest.h" | 17 #include "testing/gtest/include/gtest/gtest.h" |
| 18 #include "ui/base/models/table_model.h" | 18 #include "ui/base/models/table_model.h" |
| 19 #include "ui/base/models/table_model_observer.h" | 19 #include "ui/base/models/table_model_observer.h" |
| 20 #include "ui/base/win/scoped_ole_initializer.h" | |
| 21 #include "ui/views/controls/table/table_view.h" | 20 #include "ui/views/controls/table/table_view.h" |
| 21 #include "ui/views/test/views_test_base.h" |
| 22 #include "ui/views/widget/widget.h" | 22 #include "ui/views/widget/widget.h" |
| 23 #include "ui/views/widget/widget_delegate.h" | 23 #include "ui/views/widget/widget_delegate.h" |
| 24 | 24 |
| 25 // Put the tests in the views namespace to make it easier to declare them as | 25 // Put the tests in the views namespace to make it easier to declare them as |
| 26 // friend classes. | 26 // friend classes. |
| 27 namespace views { | 27 namespace views { |
| 28 | 28 |
| 29 // TestTableModel -------------------------------------------------------------- | 29 // TestTableModel -------------------------------------------------------------- |
| 30 | 30 |
| 31 // Trivial TableModel implementation that is backed by a vector of vectors. | 31 // Trivial TableModel implementation that is backed by a vector of vectors. |
| (...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 126 void TestTableModel::SetObserver(ui::TableModelObserver* observer) { | 126 void TestTableModel::SetObserver(ui::TableModelObserver* observer) { |
| 127 observer_ = observer; | 127 observer_ = observer; |
| 128 } | 128 } |
| 129 | 129 |
| 130 int TestTableModel::CompareValues(int row1, int row2, int column_id) { | 130 int TestTableModel::CompareValues(int row1, int row2, int column_id) { |
| 131 return rows_[row1][column_id] - rows_[row2][column_id]; | 131 return rows_[row1][column_id] - rows_[row2][column_id]; |
| 132 } | 132 } |
| 133 | 133 |
| 134 // TableViewTest --------------------------------------------------------------- | 134 // TableViewTest --------------------------------------------------------------- |
| 135 | 135 |
| 136 class TableViewTest : public testing::Test, views::WidgetDelegate { | 136 class TableViewTest : public ViewsTestBase, views::WidgetDelegate { |
| 137 public: | 137 public: |
| 138 virtual void SetUp() OVERRIDE; | 138 virtual void SetUp() OVERRIDE; |
| 139 virtual void TearDown() OVERRIDE; | 139 virtual void TearDown() OVERRIDE; |
| 140 | 140 |
| 141 virtual views::View* GetContentsView() OVERRIDE { | 141 virtual views::View* GetContentsView() OVERRIDE { |
| 142 return table_; | 142 return table_; |
| 143 } | 143 } |
| 144 virtual views::Widget* GetWidget() OVERRIDE { | 144 virtual views::Widget* GetWidget() OVERRIDE { |
| 145 return table_->GetWidget(); | 145 return table_->GetWidget(); |
| 146 } | 146 } |
| (...skipping 19 matching lines...) Expand all Loading... |
| 166 // This selects model rows 0 and 1, and if |sort| is true the first column | 166 // This selects model rows 0 and 1, and if |sort| is true the first column |
| 167 // is sorted in descending order. | 167 // is sorted in descending order. |
| 168 void SetUpMultiSelectTestState(bool sort); | 168 void SetUpMultiSelectTestState(bool sort); |
| 169 | 169 |
| 170 scoped_ptr<TestTableModel> model_; | 170 scoped_ptr<TestTableModel> model_; |
| 171 | 171 |
| 172 // The table. This is owned by the window. | 172 // The table. This is owned by the window. |
| 173 TableView* table_; | 173 TableView* table_; |
| 174 | 174 |
| 175 private: | 175 private: |
| 176 MessageLoopForUI message_loop_; | |
| 177 views::Widget* window_; | 176 views::Widget* window_; |
| 178 ui::ScopedOleInitializer ole_initializer_; | |
| 179 }; | 177 }; |
| 180 | 178 |
| 181 void TableViewTest::SetUp() { | 179 void TableViewTest::SetUp() { |
| 180 ViewsTestBase::SetUp(); |
| 181 |
| 182 model_.reset(CreateModel()); | 182 model_.reset(CreateModel()); |
| 183 std::vector<ui::TableColumn> columns; | 183 std::vector<ui::TableColumn> columns; |
| 184 columns.resize(2); | 184 columns.resize(2); |
| 185 columns[0].id = 0; | 185 columns[0].id = 0; |
| 186 columns[1].id = 1; | 186 columns[1].id = 1; |
| 187 |
| 188 // TODO(erg): This crashes on windows. Try making this derive from ViewsTests. |
| 187 table_ = new TableView(model_.get(), columns, views::ICON_AND_TEXT, | 189 table_ = new TableView(model_.get(), columns, views::ICON_AND_TEXT, |
| 188 false, false, false); | 190 false, false, false); |
| 189 window_ = views::Widget::CreateWindowWithBounds( | 191 window_ = views::Widget::CreateWindowWithContextAndBounds( |
| 190 this, | 192 this, GetContext(), gfx::Rect(100, 100, 512, 512)); |
| 191 gfx::Rect(100, 100, 512, 512)); | |
| 192 } | 193 } |
| 193 | 194 |
| 194 void TableViewTest::TearDown() { | 195 void TableViewTest::TearDown() { |
| 195 window_->Close(); | 196 window_->Close(); |
| 196 // Temporary workaround to avoid leak of RootView::pending_paint_task_. | 197 |
| 197 message_loop_.RunUntilIdle(); | 198 ViewsTestBase::TearDown(); |
| 198 } | 199 } |
| 199 | 200 |
| 200 void TableViewTest::VerifyViewOrder(int first, ...) { | 201 void TableViewTest::VerifyViewOrder(int first, ...) { |
| 201 va_list marker; | 202 va_list marker; |
| 202 va_start(marker, first); | 203 va_start(marker, first); |
| 203 int value = first; | 204 int value = first; |
| 204 int index = 0; | 205 int index = 0; |
| 205 for (int value = first, index = 0; value != -1; index++) { | 206 for (int value = first, index = 0; value != -1; index++) { |
| 206 ASSERT_EQ(value, table_->ViewToModel(index)); | 207 ASSERT_EQ(value, table_->ViewToModel(index)); |
| 207 value = va_arg(marker, int); | 208 value = va_arg(marker, int); |
| (...skipping 246 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 454 VerifySelectedRows(2, 0, -1); | 455 VerifySelectedRows(2, 0, -1); |
| 455 } | 456 } |
| 456 | 457 |
| 457 // Crashing: http://crbug.com/45015 | 458 // Crashing: http://crbug.com/45015 |
| 458 TEST_F(NullModelTableViewTest, DISABLED_NullModel) { | 459 TEST_F(NullModelTableViewTest, DISABLED_NullModel) { |
| 459 // There's nothing explicit to test. If there is a bug in TableView relating | 460 // There's nothing explicit to test. If there is a bug in TableView relating |
| 460 // to a NULL model we'll crash. | 461 // to a NULL model we'll crash. |
| 461 } | 462 } |
| 462 | 463 |
| 463 } // namespace views | 464 } // namespace views |
| OLD | NEW |