| 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 <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include "base/macros.h" | 9 #include "base/macros.h" |
| 10 #include "base/strings/string_number_conversions.h" | 10 #include "base/strings/string_number_conversions.h" |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 44 } | 44 } |
| 45 | 45 |
| 46 private: | 46 private: |
| 47 TableView* table_; | 47 TableView* table_; |
| 48 | 48 |
| 49 DISALLOW_COPY_AND_ASSIGN(TableViewTestHelper); | 49 DISALLOW_COPY_AND_ASSIGN(TableViewTestHelper); |
| 50 }; | 50 }; |
| 51 | 51 |
| 52 namespace { | 52 namespace { |
| 53 | 53 |
| 54 #if defined(OS_MACOSX) |
| 55 constexpr int kCtrlOrCmdMask = ui::EF_COMMAND_DOWN; |
| 56 #else |
| 57 constexpr int kCtrlOrCmdMask = ui::EF_CONTROL_DOWN; |
| 58 #endif |
| 59 |
| 54 // TestTableModel2 ------------------------------------------------------------- | 60 // TestTableModel2 ------------------------------------------------------------- |
| 55 | 61 |
| 56 // Trivial TableModel implementation that is backed by a vector of vectors. | 62 // Trivial TableModel implementation that is backed by a vector of vectors. |
| 57 // Provides methods for adding/removing/changing the contents that notify the | 63 // Provides methods for adding/removing/changing the contents that notify the |
| 58 // observer appropriately. | 64 // observer appropriately. |
| 59 // | 65 // |
| 60 // Initial contents are: | 66 // Initial contents are: |
| 61 // 0, 1 | 67 // 0, 1 |
| 62 // 1, 1 | 68 // 1, 1 |
| 63 // 2, 2 | 69 // 2, 2 |
| (...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 213 widget_->Show(); | 219 widget_->Show(); |
| 214 } | 220 } |
| 215 | 221 |
| 216 void TearDown() override { | 222 void TearDown() override { |
| 217 widget_.reset(); | 223 widget_.reset(); |
| 218 ViewsTestBase::TearDown(); | 224 ViewsTestBase::TearDown(); |
| 219 } | 225 } |
| 220 | 226 |
| 221 void ClickOnRow(int row, int flags) { | 227 void ClickOnRow(int row, int flags) { |
| 222 ui::test::EventGenerator generator(widget_->GetNativeWindow()); | 228 ui::test::EventGenerator generator(widget_->GetNativeWindow()); |
| 229 generator.set_assume_window_at_origin(false); |
| 223 generator.set_flags(flags); | 230 generator.set_flags(flags); |
| 224 generator.set_current_location(GetPointForRow(row)); | 231 generator.set_current_location(GetPointForRow(row)); |
| 225 generator.PressLeftButton(); | 232 generator.PressLeftButton(); |
| 226 } | 233 } |
| 227 | 234 |
| 228 void TapOnRow(int row) { | 235 void TapOnRow(int row) { |
| 229 ui::test::EventGenerator generator(widget_->GetNativeWindow()); | 236 ui::test::EventGenerator generator(widget_->GetNativeWindow()); |
| 230 generator.GestureTapAt(GetPointForRow(row)); | 237 generator.GestureTapAt(GetPointForRow(row)); |
| 231 } | 238 } |
| 232 | 239 |
| (...skipping 673 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 906 EXPECT_EQ(1, observer.GetChangedCountAndClear()); | 913 EXPECT_EQ(1, observer.GetChangedCountAndClear()); |
| 907 EXPECT_EQ("active=4 anchor=4 selection=3 4", SelectionStateAsString()); | 914 EXPECT_EQ("active=4 anchor=4 selection=3 4", SelectionStateAsString()); |
| 908 | 915 |
| 909 PressKey(ui::VKEY_HOME); | 916 PressKey(ui::VKEY_HOME); |
| 910 EXPECT_EQ(1, observer.GetChangedCountAndClear()); | 917 EXPECT_EQ(1, observer.GetChangedCountAndClear()); |
| 911 EXPECT_EQ("active=0 anchor=0 selection=0 1", SelectionStateAsString()); | 918 EXPECT_EQ("active=0 anchor=0 selection=0 1", SelectionStateAsString()); |
| 912 | 919 |
| 913 table_->set_observer(NULL); | 920 table_->set_observer(NULL); |
| 914 } | 921 } |
| 915 | 922 |
| 916 // TODO(tapted): enable these tests on Mac. | |
| 917 #if !defined(OS_MACOSX) | |
| 918 // Verifies multiple selection gestures work (control-click, shift-click ...). | 923 // Verifies multiple selection gestures work (control-click, shift-click ...). |
| 919 TEST_F(TableViewTest, Multiselection) { | 924 TEST_F(TableViewTest, Multiselection) { |
| 920 // Configure the grouper so that there are three groups: | 925 // Configure the grouper so that there are three groups: |
| 921 // A 0 | 926 // A 0 |
| 922 // 1 | 927 // 1 |
| 923 // B 5 | 928 // B 5 |
| 924 // C 2 | 929 // C 2 |
| 925 // 3 | 930 // 3 |
| 926 model_->AddRow(2, 5, 0); | 931 model_->AddRow(2, 5, 0); |
| 927 TableGrouperImpl grouper; | 932 TableGrouperImpl grouper; |
| (...skipping 19 matching lines...) Expand all Loading... |
| 947 ClickOnRow(4, 0); | 952 ClickOnRow(4, 0); |
| 948 EXPECT_EQ(1, observer.GetChangedCountAndClear()); | 953 EXPECT_EQ(1, observer.GetChangedCountAndClear()); |
| 949 EXPECT_EQ("active=4 anchor=4 selection=3 4", SelectionStateAsString()); | 954 EXPECT_EQ("active=4 anchor=4 selection=3 4", SelectionStateAsString()); |
| 950 | 955 |
| 951 // Shift click on the third row, should extend selection to it. | 956 // Shift click on the third row, should extend selection to it. |
| 952 ClickOnRow(2, ui::EF_SHIFT_DOWN); | 957 ClickOnRow(2, ui::EF_SHIFT_DOWN); |
| 953 EXPECT_EQ(1, observer.GetChangedCountAndClear()); | 958 EXPECT_EQ(1, observer.GetChangedCountAndClear()); |
| 954 EXPECT_EQ("active=2 anchor=4 selection=2 3 4", SelectionStateAsString()); | 959 EXPECT_EQ("active=2 anchor=4 selection=2 3 4", SelectionStateAsString()); |
| 955 | 960 |
| 956 // Control click on third row, should toggle it. | 961 // Control click on third row, should toggle it. |
| 957 ClickOnRow(2, ui::EF_CONTROL_DOWN); | 962 ClickOnRow(2, kCtrlOrCmdMask); |
| 958 EXPECT_EQ(1, observer.GetChangedCountAndClear()); | 963 EXPECT_EQ(1, observer.GetChangedCountAndClear()); |
| 959 EXPECT_EQ("active=2 anchor=2 selection=3 4", SelectionStateAsString()); | 964 EXPECT_EQ("active=2 anchor=2 selection=3 4", SelectionStateAsString()); |
| 960 | 965 |
| 961 // Control-shift click on second row, should extend selection to it. | 966 // Control-shift click on second row, should extend selection to it. |
| 962 ClickOnRow(1, ui::EF_CONTROL_DOWN | ui::EF_SHIFT_DOWN); | 967 ClickOnRow(1, kCtrlOrCmdMask | ui::EF_SHIFT_DOWN); |
| 963 EXPECT_EQ(1, observer.GetChangedCountAndClear()); | 968 EXPECT_EQ(1, observer.GetChangedCountAndClear()); |
| 964 EXPECT_EQ("active=1 anchor=2 selection=0 1 2 3 4", SelectionStateAsString()); | 969 EXPECT_EQ("active=1 anchor=2 selection=0 1 2 3 4", SelectionStateAsString()); |
| 965 | 970 |
| 966 // Click on last row again. | 971 // Click on last row again. |
| 967 ClickOnRow(4, 0); | 972 ClickOnRow(4, 0); |
| 968 EXPECT_EQ(1, observer.GetChangedCountAndClear()); | 973 EXPECT_EQ(1, observer.GetChangedCountAndClear()); |
| 969 EXPECT_EQ("active=4 anchor=4 selection=3 4", SelectionStateAsString()); | 974 EXPECT_EQ("active=4 anchor=4 selection=3 4", SelectionStateAsString()); |
| 970 | 975 |
| 971 table_->set_observer(NULL); | 976 table_->set_observer(NULL); |
| 972 } | 977 } |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1008 EXPECT_EQ(1, observer.GetChangedCountAndClear()); | 1013 EXPECT_EQ(1, observer.GetChangedCountAndClear()); |
| 1009 EXPECT_EQ("active=4 anchor=4 selection=3 4", SelectionStateAsString()); | 1014 EXPECT_EQ("active=4 anchor=4 selection=3 4", SelectionStateAsString()); |
| 1010 | 1015 |
| 1011 // Extend selection to first row. | 1016 // Extend selection to first row. |
| 1012 ClickOnRow(0, ui::EF_SHIFT_DOWN); | 1017 ClickOnRow(0, ui::EF_SHIFT_DOWN); |
| 1013 EXPECT_EQ(1, observer.GetChangedCountAndClear()); | 1018 EXPECT_EQ(1, observer.GetChangedCountAndClear()); |
| 1014 EXPECT_EQ("active=2 anchor=4 selection=2 3 4", SelectionStateAsString()); | 1019 EXPECT_EQ("active=2 anchor=4 selection=2 3 4", SelectionStateAsString()); |
| 1015 | 1020 |
| 1016 table_->set_observer(NULL); | 1021 table_->set_observer(NULL); |
| 1017 } | 1022 } |
| 1018 #endif | |
| 1019 | 1023 |
| 1020 // Verifies we don't crash after removing the selected row when there is | 1024 // Verifies we don't crash after removing the selected row when there is |
| 1021 // sorting and the anchor/active index also match the selected row. | 1025 // sorting and the anchor/active index also match the selected row. |
| 1022 TEST_F(TableViewTest, FocusAfterRemovingAnchor) { | 1026 TEST_F(TableViewTest, FocusAfterRemovingAnchor) { |
| 1023 table_->ToggleSortOrder(0); | 1027 table_->ToggleSortOrder(0); |
| 1024 | 1028 |
| 1025 ui::ListSelectionModel new_selection; | 1029 ui::ListSelectionModel new_selection; |
| 1026 new_selection.AddIndexToSelection(0); | 1030 new_selection.AddIndexToSelection(0); |
| 1027 new_selection.AddIndexToSelection(1); | 1031 new_selection.AddIndexToSelection(1); |
| 1028 new_selection.set_active(0); | 1032 new_selection.set_active(0); |
| 1029 new_selection.set_anchor(0); | 1033 new_selection.set_anchor(0); |
| 1030 helper_->SetSelectionModel(new_selection); | 1034 helper_->SetSelectionModel(new_selection); |
| 1031 model_->RemoveRow(0); | 1035 model_->RemoveRow(0); |
| 1032 table_->RequestFocus(); | 1036 table_->RequestFocus(); |
| 1033 } | 1037 } |
| 1034 | 1038 |
| 1035 } // namespace views | 1039 } // namespace views |
| OLD | NEW |