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 #include "ui/views/controls/table/table_view.h" | 5 #include "ui/views/controls/table/table_view.h" |
6 | 6 |
7 #include "base/strings/string_number_conversions.h" | 7 #include "base/strings/string_number_conversions.h" |
8 #include "base/strings/utf_string_conversions.h" | 8 #include "base/strings/utf_string_conversions.h" |
9 #include "testing/gtest/include/gtest/gtest.h" | 9 #include "testing/gtest/include/gtest/gtest.h" |
10 #include "ui/events/event_utils.h" | 10 #include "ui/events/event_utils.h" |
(...skipping 180 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
191 columns[1].sortable = true; | 191 columns[1].sortable = true; |
192 table_ = new TestTableView(model_.get(), columns); | 192 table_ = new TestTableView(model_.get(), columns); |
193 parent_.reset(table_->CreateParentIfNecessary()); | 193 parent_.reset(table_->CreateParentIfNecessary()); |
194 parent_->SetBounds(0, 0, 10000, 10000); | 194 parent_->SetBounds(0, 0, 10000, 10000); |
195 parent_->Layout(); | 195 parent_->Layout(); |
196 helper_.reset(new TableViewTestHelper(table_)); | 196 helper_.reset(new TableViewTestHelper(table_)); |
197 } | 197 } |
198 | 198 |
199 void ClickOnRow(int row, int flags) { | 199 void ClickOnRow(int row, int flags) { |
200 const int y = row * table_->row_height(); | 200 const int y = row * table_->row_height(); |
201 const ui::MouseEvent pressed(ui::ET_MOUSE_PRESSED, gfx::Point(0, y), | 201 const ui::MouseEvent pressed( |
202 gfx::Point(0, y), ui::EventTimeForNow(), | 202 ui::ET_MOUSE_PRESSED, gfx::Point(0, y), gfx::Point(0, y), |
203 ui::EF_LEFT_MOUSE_BUTTON | flags, | 203 ui::EventTimeForNow(), ui::EF_LEFT_MOUSE_BUTTON | flags, |
204 ui::EF_LEFT_MOUSE_BUTTON); | 204 ui::EF_LEFT_MOUSE_BUTTON, |
| 205 ui::PointerEventDetails(ui::EventPointerType::POINTER_TYPE_MOUSE)); |
205 table_->OnMousePressed(pressed); | 206 table_->OnMousePressed(pressed); |
206 } | 207 } |
207 | 208 |
208 void TapOnRow(int row) { | 209 void TapOnRow(int row) { |
209 const int y = row * table_->row_height(); | 210 const int y = row * table_->row_height(); |
210 const ui::GestureEventDetails event_details(ui::ET_GESTURE_TAP); | 211 const ui::GestureEventDetails event_details(ui::ET_GESTURE_TAP); |
211 ui::GestureEvent tap(0, y, 0, base::TimeDelta(), event_details); | 212 ui::GestureEvent tap(0, y, 0, base::TimeDelta(), event_details); |
212 table_->OnGestureEvent(&tap); | 213 table_->OnGestureEvent(&tap); |
213 } | 214 } |
214 | 215 |
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
289 EXPECT_EQ(1, table_->visible_columns()[0].column.id); | 290 EXPECT_EQ(1, table_->visible_columns()[0].column.id); |
290 EXPECT_EQ(0, table_->visible_columns()[1].column.id); | 291 EXPECT_EQ(0, table_->visible_columns()[1].column.id); |
291 EXPECT_EQ("rows=0 4 cols=0 2", helper_->GetPaintRegion(table_->bounds())); | 292 EXPECT_EQ("rows=0 4 cols=0 2", helper_->GetPaintRegion(table_->bounds())); |
292 } | 293 } |
293 | 294 |
294 // Verifies resizing a column works. | 295 // Verifies resizing a column works. |
295 TEST_F(TableViewTest, Resize) { | 296 TEST_F(TableViewTest, Resize) { |
296 const int x = table_->visible_columns()[0].width; | 297 const int x = table_->visible_columns()[0].width; |
297 EXPECT_NE(0, x); | 298 EXPECT_NE(0, x); |
298 // Drag the mouse 1 pixel to the left. | 299 // Drag the mouse 1 pixel to the left. |
299 const ui::MouseEvent pressed(ui::ET_MOUSE_PRESSED, gfx::Point(x, 0), | 300 const ui::MouseEvent pressed( |
300 gfx::Point(x, 0), ui::EventTimeForNow(), | 301 ui::ET_MOUSE_PRESSED, gfx::Point(x, 0), gfx::Point(x, 0), |
301 ui::EF_LEFT_MOUSE_BUTTON, | 302 ui::EventTimeForNow(), ui::EF_LEFT_MOUSE_BUTTON, ui::EF_LEFT_MOUSE_BUTTON, |
302 ui::EF_LEFT_MOUSE_BUTTON); | 303 ui::PointerEventDetails(ui::EventPointerType::POINTER_TYPE_MOUSE)); |
303 helper_->header()->OnMousePressed(pressed); | 304 helper_->header()->OnMousePressed(pressed); |
304 const ui::MouseEvent dragged(ui::ET_MOUSE_DRAGGED, gfx::Point(x - 1, 0), | 305 const ui::MouseEvent dragged( |
305 gfx::Point(x - 1, 0), ui::EventTimeForNow(), | 306 ui::ET_MOUSE_DRAGGED, gfx::Point(x - 1, 0), gfx::Point(x - 1, 0), |
306 ui::EF_LEFT_MOUSE_BUTTON, 0); | 307 ui::EventTimeForNow(), ui::EF_LEFT_MOUSE_BUTTON, 0, |
| 308 ui::PointerEventDetails(ui::EventPointerType::POINTER_TYPE_MOUSE)); |
307 helper_->header()->OnMouseDragged(dragged); | 309 helper_->header()->OnMouseDragged(dragged); |
308 | 310 |
309 // This should shrink the first column and pull the second column in. | 311 // This should shrink the first column and pull the second column in. |
310 EXPECT_EQ(x - 1, table_->visible_columns()[0].width); | 312 EXPECT_EQ(x - 1, table_->visible_columns()[0].width); |
311 EXPECT_EQ(x - 1, table_->visible_columns()[1].x); | 313 EXPECT_EQ(x - 1, table_->visible_columns()[1].x); |
312 } | 314 } |
313 | 315 |
314 // Verifies resizing a column works with a gesture. | 316 // Verifies resizing a column works with a gesture. |
315 TEST_F(TableViewTest, ResizeViaGesture) { | 317 TEST_F(TableViewTest, ResizeViaGesture) { |
316 const int x = table_->visible_columns()[0].width; | 318 const int x = table_->visible_columns()[0].width; |
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
387 EXPECT_EQ("3 1 2 0", GetModelToViewAsString(table_)); | 389 EXPECT_EQ("3 1 2 0", GetModelToViewAsString(table_)); |
388 } | 390 } |
389 | 391 |
390 // Verfies clicking on the header sorts. | 392 // Verfies clicking on the header sorts. |
391 TEST_F(TableViewTest, SortOnMouse) { | 393 TEST_F(TableViewTest, SortOnMouse) { |
392 EXPECT_TRUE(table_->sort_descriptors().empty()); | 394 EXPECT_TRUE(table_->sort_descriptors().empty()); |
393 | 395 |
394 const int x = table_->visible_columns()[0].width / 2; | 396 const int x = table_->visible_columns()[0].width / 2; |
395 EXPECT_NE(0, x); | 397 EXPECT_NE(0, x); |
396 // Press and release the mouse. | 398 // Press and release the mouse. |
397 const ui::MouseEvent pressed(ui::ET_MOUSE_PRESSED, gfx::Point(x, 0), | 399 const ui::MouseEvent pressed( |
398 gfx::Point(x, 0), ui::EventTimeForNow(), | 400 ui::ET_MOUSE_PRESSED, gfx::Point(x, 0), gfx::Point(x, 0), |
399 ui::EF_LEFT_MOUSE_BUTTON, | 401 ui::EventTimeForNow(), ui::EF_LEFT_MOUSE_BUTTON, ui::EF_LEFT_MOUSE_BUTTON, |
400 ui::EF_LEFT_MOUSE_BUTTON); | 402 ui::PointerEventDetails(ui::EventPointerType::POINTER_TYPE_MOUSE)); |
401 // The header must return true, else it won't normally get the release. | 403 // The header must return true, else it won't normally get the release. |
402 EXPECT_TRUE(helper_->header()->OnMousePressed(pressed)); | 404 EXPECT_TRUE(helper_->header()->OnMousePressed(pressed)); |
403 const ui::MouseEvent release(ui::ET_MOUSE_RELEASED, gfx::Point(x, 0), | 405 const ui::MouseEvent release( |
404 gfx::Point(x, 0), ui::EventTimeForNow(), | 406 ui::ET_MOUSE_RELEASED, gfx::Point(x, 0), gfx::Point(x, 0), |
405 ui::EF_LEFT_MOUSE_BUTTON, | 407 ui::EventTimeForNow(), ui::EF_LEFT_MOUSE_BUTTON, ui::EF_LEFT_MOUSE_BUTTON, |
406 ui::EF_LEFT_MOUSE_BUTTON); | 408 ui::PointerEventDetails(ui::EventPointerType::POINTER_TYPE_MOUSE)); |
407 helper_->header()->OnMouseReleased(release); | 409 helper_->header()->OnMouseReleased(release); |
408 | 410 |
409 ASSERT_EQ(1u, table_->sort_descriptors().size()); | 411 ASSERT_EQ(1u, table_->sort_descriptors().size()); |
410 EXPECT_EQ(0, table_->sort_descriptors()[0].column_id); | 412 EXPECT_EQ(0, table_->sort_descriptors()[0].column_id); |
411 EXPECT_TRUE(table_->sort_descriptors()[0].ascending); | 413 EXPECT_TRUE(table_->sort_descriptors()[0].ascending); |
412 } | 414 } |
413 | 415 |
414 namespace { | 416 namespace { |
415 | 417 |
416 class TableGrouperImpl : public TableGrouper { | 418 class TableGrouperImpl : public TableGrouper { |
(...skipping 444 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
861 new_selection.AddIndexToSelection(0); | 863 new_selection.AddIndexToSelection(0); |
862 new_selection.AddIndexToSelection(1); | 864 new_selection.AddIndexToSelection(1); |
863 new_selection.set_active(0); | 865 new_selection.set_active(0); |
864 new_selection.set_anchor(0); | 866 new_selection.set_anchor(0); |
865 helper_->SetSelectionModel(new_selection); | 867 helper_->SetSelectionModel(new_selection); |
866 model_->RemoveRow(0); | 868 model_->RemoveRow(0); |
867 helper_->OnFocus(); | 869 helper_->OnFocus(); |
868 } | 870 } |
869 | 871 |
870 } // namespace views | 872 } // namespace views |
OLD | NEW |