| 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 16 matching lines...) Expand all Loading... |
| 27 base::IntToString(region.min_column) + " " + | 27 base::IntToString(region.min_column) + " " + |
| 28 base::IntToString(region.max_column); | 28 base::IntToString(region.max_column); |
| 29 } | 29 } |
| 30 | 30 |
| 31 size_t visible_col_count() { | 31 size_t visible_col_count() { |
| 32 return table_->visible_columns().size(); | 32 return table_->visible_columns().size(); |
| 33 } | 33 } |
| 34 | 34 |
| 35 TableHeader* header() { return table_->header_; } | 35 TableHeader* header() { return table_->header_; } |
| 36 | 36 |
| 37 void SetSelectionModel(const ui::ListSelectionModel& new_selection) { |
| 38 table_->SetSelectionModel(new_selection); |
| 39 } |
| 40 |
| 41 void OnFocus() { |
| 42 table_->OnFocus(); |
| 43 } |
| 44 |
| 37 private: | 45 private: |
| 38 TableView* table_; | 46 TableView* table_; |
| 39 | 47 |
| 40 DISALLOW_COPY_AND_ASSIGN(TableViewTestHelper); | 48 DISALLOW_COPY_AND_ASSIGN(TableViewTestHelper); |
| 41 }; | 49 }; |
| 42 | 50 |
| 43 namespace { | 51 namespace { |
| 44 | 52 |
| 45 // TestTableModel2 ------------------------------------------------------------- | 53 // TestTableModel2 ------------------------------------------------------------- |
| 46 | 54 |
| (...skipping 790 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 837 EXPECT_EQ("active=4 anchor=4 selection=3 4", SelectionStateAsString()); | 845 EXPECT_EQ("active=4 anchor=4 selection=3 4", SelectionStateAsString()); |
| 838 | 846 |
| 839 // Extend selection to first row. | 847 // Extend selection to first row. |
| 840 ClickOnRow(0, ui::EF_SHIFT_DOWN); | 848 ClickOnRow(0, ui::EF_SHIFT_DOWN); |
| 841 EXPECT_EQ(1, observer.GetChangedCountAndClear()); | 849 EXPECT_EQ(1, observer.GetChangedCountAndClear()); |
| 842 EXPECT_EQ("active=2 anchor=4 selection=2 3 4", SelectionStateAsString()); | 850 EXPECT_EQ("active=2 anchor=4 selection=2 3 4", SelectionStateAsString()); |
| 843 | 851 |
| 844 table_->SetObserver(NULL); | 852 table_->SetObserver(NULL); |
| 845 } | 853 } |
| 846 | 854 |
| 855 // Verifies we don't crash after removing the selected row when there is |
| 856 // sorting and the anchor/active index also match the selected row. |
| 857 TEST_F(TableViewTest, FocusAfterRemovingAnchor) { |
| 858 table_->ToggleSortOrder(0); |
| 859 |
| 860 ui::ListSelectionModel new_selection; |
| 861 new_selection.AddIndexToSelection(0); |
| 862 new_selection.AddIndexToSelection(1); |
| 863 new_selection.set_active(0); |
| 864 new_selection.set_anchor(0); |
| 865 helper_->SetSelectionModel(new_selection); |
| 866 model_->RemoveRow(0); |
| 867 helper_->OnFocus(); |
| 868 } |
| 869 |
| 847 } // namespace views | 870 } // namespace views |
| OLD | NEW |