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/views/controls/table/table_grouper.h" | 10 #include "ui/views/controls/table/table_grouper.h" |
(...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
184 parent_.reset(table_->CreateParentIfNecessary()); | 184 parent_.reset(table_->CreateParentIfNecessary()); |
185 parent_->SetBounds(0, 0, 10000, 10000); | 185 parent_->SetBounds(0, 0, 10000, 10000); |
186 parent_->Layout(); | 186 parent_->Layout(); |
187 helper_.reset(new TableViewTestHelper(table_)); | 187 helper_.reset(new TableViewTestHelper(table_)); |
188 } | 188 } |
189 | 189 |
190 void ClickOnRow(int row, int flags) { | 190 void ClickOnRow(int row, int flags) { |
191 const int y = row * table_->row_height(); | 191 const int y = row * table_->row_height(); |
192 const ui::MouseEvent pressed(ui::ET_MOUSE_PRESSED, gfx::Point(0, y), | 192 const ui::MouseEvent pressed(ui::ET_MOUSE_PRESSED, gfx::Point(0, y), |
193 gfx::Point(0, y), | 193 gfx::Point(0, y), |
194 ui::EF_LEFT_MOUSE_BUTTON | flags); | 194 ui::EF_LEFT_MOUSE_BUTTON | flags, |
| 195 ui::EF_LEFT_MOUSE_BUTTON); |
195 table_->OnMousePressed(pressed); | 196 table_->OnMousePressed(pressed); |
196 } | 197 } |
197 | 198 |
198 void TapOnRow(int row) { | 199 void TapOnRow(int row) { |
199 const int y = row * table_->row_height(); | 200 const int y = row * table_->row_height(); |
200 const ui::GestureEventDetails event_details(ui::ET_GESTURE_TAP, | 201 const ui::GestureEventDetails event_details(ui::ET_GESTURE_TAP, |
201 .0f, .0f); | 202 .0f, .0f); |
202 ui::GestureEvent tap(ui::ET_GESTURE_TAP, 0, y, 0, base::TimeDelta(), | 203 ui::GestureEvent tap(ui::ET_GESTURE_TAP, 0, y, 0, base::TimeDelta(), |
203 event_details, 1); | 204 event_details, 1); |
204 table_->OnGestureEvent(&tap); | 205 table_->OnGestureEvent(&tap); |
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
282 EXPECT_EQ(0, table_->visible_columns()[1].column.id); | 283 EXPECT_EQ(0, table_->visible_columns()[1].column.id); |
283 EXPECT_EQ("rows=0 4 cols=0 2", helper_->GetPaintRegion(table_->bounds())); | 284 EXPECT_EQ("rows=0 4 cols=0 2", helper_->GetPaintRegion(table_->bounds())); |
284 } | 285 } |
285 | 286 |
286 // Verifies resizing a column works. | 287 // Verifies resizing a column works. |
287 TEST_F(TableViewTest, Resize) { | 288 TEST_F(TableViewTest, Resize) { |
288 const int x = table_->visible_columns()[0].width; | 289 const int x = table_->visible_columns()[0].width; |
289 EXPECT_NE(0, x); | 290 EXPECT_NE(0, x); |
290 // Drag the mouse 1 pixel to the left. | 291 // Drag the mouse 1 pixel to the left. |
291 const ui::MouseEvent pressed(ui::ET_MOUSE_PRESSED, gfx::Point(x, 0), | 292 const ui::MouseEvent pressed(ui::ET_MOUSE_PRESSED, gfx::Point(x, 0), |
292 gfx::Point(x, 0), ui::EF_LEFT_MOUSE_BUTTON); | 293 gfx::Point(x, 0), ui::EF_LEFT_MOUSE_BUTTON, |
| 294 ui::EF_LEFT_MOUSE_BUTTON); |
293 helper_->header()->OnMousePressed(pressed); | 295 helper_->header()->OnMousePressed(pressed); |
294 const ui::MouseEvent dragged(ui::ET_MOUSE_DRAGGED, gfx::Point(x - 1, 0), | 296 const ui::MouseEvent dragged(ui::ET_MOUSE_DRAGGED, gfx::Point(x - 1, 0), |
295 gfx::Point(x - 1, 0), ui::EF_LEFT_MOUSE_BUTTON); | 297 gfx::Point(x - 1, 0), ui::EF_LEFT_MOUSE_BUTTON, |
| 298 0); |
296 helper_->header()->OnMouseDragged(dragged); | 299 helper_->header()->OnMouseDragged(dragged); |
297 | 300 |
298 // This should shrink the first column and pull the second column in. | 301 // This should shrink the first column and pull the second column in. |
299 EXPECT_EQ(x - 1, table_->visible_columns()[0].width); | 302 EXPECT_EQ(x - 1, table_->visible_columns()[0].width); |
300 EXPECT_EQ(x - 1, table_->visible_columns()[1].x); | 303 EXPECT_EQ(x - 1, table_->visible_columns()[1].x); |
301 } | 304 } |
302 | 305 |
303 // Verifies resizing a column works with a gesture. | 306 // Verifies resizing a column works with a gesture. |
304 TEST_F(TableViewTest, ResizeViaGesture) { | 307 TEST_F(TableViewTest, ResizeViaGesture) { |
305 const int x = table_->visible_columns()[0].width; | 308 const int x = table_->visible_columns()[0].width; |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
371 } | 374 } |
372 | 375 |
373 // Verfies clicking on the header sorts. | 376 // Verfies clicking on the header sorts. |
374 TEST_F(TableViewTest, SortOnMouse) { | 377 TEST_F(TableViewTest, SortOnMouse) { |
375 EXPECT_TRUE(table_->sort_descriptors().empty()); | 378 EXPECT_TRUE(table_->sort_descriptors().empty()); |
376 | 379 |
377 const int x = table_->visible_columns()[0].width / 2; | 380 const int x = table_->visible_columns()[0].width / 2; |
378 EXPECT_NE(0, x); | 381 EXPECT_NE(0, x); |
379 // Press and release the mouse. | 382 // Press and release the mouse. |
380 const ui::MouseEvent pressed(ui::ET_MOUSE_PRESSED, gfx::Point(x, 0), | 383 const ui::MouseEvent pressed(ui::ET_MOUSE_PRESSED, gfx::Point(x, 0), |
381 gfx::Point(x, 0), ui::EF_LEFT_MOUSE_BUTTON); | 384 gfx::Point(x, 0), ui::EF_LEFT_MOUSE_BUTTON, |
| 385 ui::EF_LEFT_MOUSE_BUTTON); |
382 // The header must return true, else it won't normally get the release. | 386 // The header must return true, else it won't normally get the release. |
383 EXPECT_TRUE(helper_->header()->OnMousePressed(pressed)); | 387 EXPECT_TRUE(helper_->header()->OnMousePressed(pressed)); |
384 const ui::MouseEvent release(ui::ET_MOUSE_RELEASED, gfx::Point(x, 0), | 388 const ui::MouseEvent release(ui::ET_MOUSE_RELEASED, gfx::Point(x, 0), |
385 gfx::Point(x, 0), ui::EF_LEFT_MOUSE_BUTTON); | 389 gfx::Point(x, 0), ui::EF_LEFT_MOUSE_BUTTON, |
| 390 ui::EF_LEFT_MOUSE_BUTTON); |
386 helper_->header()->OnMouseReleased(release); | 391 helper_->header()->OnMouseReleased(release); |
387 | 392 |
388 ASSERT_EQ(1u, table_->sort_descriptors().size()); | 393 ASSERT_EQ(1u, table_->sort_descriptors().size()); |
389 EXPECT_EQ(0, table_->sort_descriptors()[0].column_id); | 394 EXPECT_EQ(0, table_->sort_descriptors()[0].column_id); |
390 EXPECT_TRUE(table_->sort_descriptors()[0].ascending); | 395 EXPECT_TRUE(table_->sort_descriptors()[0].ascending); |
391 } | 396 } |
392 | 397 |
393 namespace { | 398 namespace { |
394 | 399 |
395 class TableGrouperImpl : public TableGrouper { | 400 class TableGrouperImpl : public TableGrouper { |
(...skipping 431 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
827 | 832 |
828 // Extend selection to first row. | 833 // Extend selection to first row. |
829 ClickOnRow(0, ui::EF_SHIFT_DOWN); | 834 ClickOnRow(0, ui::EF_SHIFT_DOWN); |
830 EXPECT_EQ(1, observer.GetChangedCountAndClear()); | 835 EXPECT_EQ(1, observer.GetChangedCountAndClear()); |
831 EXPECT_EQ("active=2 anchor=4 selection=2 3 4", SelectionStateAsString()); | 836 EXPECT_EQ("active=2 anchor=4 selection=2 3 4", SelectionStateAsString()); |
832 | 837 |
833 table_->SetObserver(NULL); | 838 table_->SetObserver(NULL); |
834 } | 839 } |
835 | 840 |
836 } // namespace views | 841 } // namespace views |
OLD | NEW |