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 180 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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 ui::EF_LEFT_MOUSE_BUTTON); |
196 table_->OnMousePressed(pressed); | 196 table_->OnMousePressed(pressed); |
197 } | 197 } |
198 | 198 |
199 void TapOnRow(int row) { | 199 void TapOnRow(int row) { |
200 const int y = row * table_->row_height(); | 200 const int y = row * table_->row_height(); |
201 const ui::GestureEventDetails event_details(ui::ET_GESTURE_TAP, | 201 const ui::GestureEventDetails event_details(ui::ET_GESTURE_TAP); |
202 .0f, .0f); | |
203 ui::GestureEvent tap(0, y, 0, base::TimeDelta(), event_details); | 202 ui::GestureEvent tap(0, y, 0, base::TimeDelta(), event_details); |
204 table_->OnGestureEvent(&tap); | 203 table_->OnGestureEvent(&tap); |
205 } | 204 } |
206 | 205 |
207 // Returns the state of the selection model as a string. The format is: | 206 // Returns the state of the selection model as a string. The format is: |
208 // 'active=X anchor=X selection=X X X...'. | 207 // 'active=X anchor=X selection=X X X...'. |
209 std::string SelectionStateAsString() const { | 208 std::string SelectionStateAsString() const { |
210 const ui::ListSelectionModel& model(table_->selection_model()); | 209 const ui::ListSelectionModel& model(table_->selection_model()); |
211 std::string result = "active=" + base::IntToString(model.active()) + | 210 std::string result = "active=" + base::IntToString(model.active()) + |
212 " anchor=" + base::IntToString(model.anchor()) + | 211 " anchor=" + base::IntToString(model.anchor()) + |
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
305 // Verifies resizing a column works with a gesture. | 304 // Verifies resizing a column works with a gesture. |
306 TEST_F(TableViewTest, ResizeViaGesture) { | 305 TEST_F(TableViewTest, ResizeViaGesture) { |
307 const int x = table_->visible_columns()[0].width; | 306 const int x = table_->visible_columns()[0].width; |
308 EXPECT_NE(0, x); | 307 EXPECT_NE(0, x); |
309 // Drag the mouse 1 pixel to the left. | 308 // Drag the mouse 1 pixel to the left. |
310 ui::GestureEvent scroll_begin( | 309 ui::GestureEvent scroll_begin( |
311 x, | 310 x, |
312 0, | 311 0, |
313 0, | 312 0, |
314 base::TimeDelta(), | 313 base::TimeDelta(), |
315 ui::GestureEventDetails(ui::ET_GESTURE_SCROLL_BEGIN, .0f, .0f)); | 314 ui::GestureEventDetails(ui::ET_GESTURE_SCROLL_BEGIN)); |
316 helper_->header()->OnGestureEvent(&scroll_begin); | 315 helper_->header()->OnGestureEvent(&scroll_begin); |
317 ui::GestureEvent scroll_update( | 316 ui::GestureEvent scroll_update( |
318 x - 1, | 317 x - 1, |
319 0, | 318 0, |
320 0, | 319 0, |
321 base::TimeDelta(), | 320 base::TimeDelta(), |
322 ui::GestureEventDetails(ui::ET_GESTURE_SCROLL_UPDATE, .0f, .0f)); | 321 ui::GestureEventDetails(ui::ET_GESTURE_SCROLL_UPDATE)); |
323 helper_->header()->OnGestureEvent(&scroll_update); | 322 helper_->header()->OnGestureEvent(&scroll_update); |
324 | 323 |
325 // This should shrink the first column and pull the second column in. | 324 // This should shrink the first column and pull the second column in. |
326 EXPECT_EQ(x - 1, table_->visible_columns()[0].width); | 325 EXPECT_EQ(x - 1, table_->visible_columns()[0].width); |
327 EXPECT_EQ(x - 1, table_->visible_columns()[1].x); | 326 EXPECT_EQ(x - 1, table_->visible_columns()[1].x); |
328 } | 327 } |
329 | 328 |
330 // Assertions for table sorting. | 329 // Assertions for table sorting. |
331 TEST_F(TableViewTest, Sort) { | 330 TEST_F(TableViewTest, Sort) { |
332 // Toggle the sort order of the first column, shouldn't change anything. | 331 // Toggle the sort order of the first column, shouldn't change anything. |
(...skipping 504 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
837 | 836 |
838 // Extend selection to first row. | 837 // Extend selection to first row. |
839 ClickOnRow(0, ui::EF_SHIFT_DOWN); | 838 ClickOnRow(0, ui::EF_SHIFT_DOWN); |
840 EXPECT_EQ(1, observer.GetChangedCountAndClear()); | 839 EXPECT_EQ(1, observer.GetChangedCountAndClear()); |
841 EXPECT_EQ("active=2 anchor=4 selection=2 3 4", SelectionStateAsString()); | 840 EXPECT_EQ("active=2 anchor=4 selection=2 3 4", SelectionStateAsString()); |
842 | 841 |
843 table_->SetObserver(NULL); | 842 table_->SetObserver(NULL); |
844 } | 843 } |
845 | 844 |
846 } // namespace views | 845 } // namespace views |
OLD | NEW |