| OLD | NEW |
| (Empty) |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "base/prefs/pref_service.h" | |
| 6 #include "base/prefs/scoped_user_pref_update.h" | |
| 7 #include "chrome/browser/browser_process.h" | |
| 8 #include "chrome/browser/ui/browser_dialogs.h" | |
| 9 #include "chrome/browser/ui/views/new_task_manager_view.h" | |
| 10 #include "chrome/common/pref_names.h" | |
| 11 #include "chrome/test/base/in_process_browser_test.h" | |
| 12 #include "ui/views/controls/table/table_view.h" | |
| 13 | |
| 14 namespace task_management { | |
| 15 | |
| 16 class NewTaskManagerViewTest : public InProcessBrowserTest { | |
| 17 public: | |
| 18 NewTaskManagerViewTest() {} | |
| 19 ~NewTaskManagerViewTest() override {} | |
| 20 | |
| 21 NewTaskManagerView* GetView() const { | |
| 22 return NewTaskManagerView::GetInstanceForTests(); | |
| 23 } | |
| 24 | |
| 25 views::TableView* GetTable() const { | |
| 26 return GetView() ? GetView()->tab_table_ : nullptr; | |
| 27 } | |
| 28 | |
| 29 void ClearStoredColumnSettings() const { | |
| 30 PrefService* local_state = g_browser_process->local_state(); | |
| 31 if (!local_state) | |
| 32 FAIL(); | |
| 33 | |
| 34 DictionaryPrefUpdate dict_update(local_state, | |
| 35 prefs::kTaskManagerColumnVisibility); | |
| 36 dict_update->Clear(); | |
| 37 } | |
| 38 | |
| 39 void ToggleColumnVisibility(NewTaskManagerView* view, int col_id) { | |
| 40 DCHECK(view); | |
| 41 view->ToggleColumnVisibility(col_id); | |
| 42 } | |
| 43 | |
| 44 private: | |
| 45 DISALLOW_COPY_AND_ASSIGN(NewTaskManagerViewTest); | |
| 46 }; | |
| 47 | |
| 48 // Tests that all defined columns have a corresponding string IDs for keying | |
| 49 // into the user preferences dictionary. | |
| 50 IN_PROC_BROWSER_TEST_F(NewTaskManagerViewTest, AllColumnsHaveStringIds) { | |
| 51 for (size_t i = 0; i < kColumnsSize; ++i) | |
| 52 EXPECT_NE("", GetColumnIdAsString(kColumns[i].id)); | |
| 53 } | |
| 54 | |
| 55 // In the case of no settings stored in the user preferences local store, test | |
| 56 // that the task manager table starts with the default columns visibility as | |
| 57 // stored in |kColumns|. | |
| 58 IN_PROC_BROWSER_TEST_F(NewTaskManagerViewTest, TableStartsWithDefaultColumns) { | |
| 59 ASSERT_NO_FATAL_FAILURE(ClearStoredColumnSettings()); | |
| 60 | |
| 61 chrome::ShowTaskManager(browser()); | |
| 62 views::TableView* table = GetTable(); | |
| 63 ASSERT_TRUE(table); | |
| 64 | |
| 65 EXPECT_FALSE(table->is_sorted()); | |
| 66 for (size_t i = 0; i < kColumnsSize; ++i) { | |
| 67 EXPECT_EQ(kColumns[i].default_visibility, | |
| 68 table->IsColumnVisible(kColumns[i].id)); | |
| 69 } | |
| 70 } | |
| 71 | |
| 72 // Tests that changing columns visibility and sort order will be stored upon | |
| 73 // closing the task manager view and restored when re-opened. | |
| 74 IN_PROC_BROWSER_TEST_F(NewTaskManagerViewTest, ColumnsSettingsAreRestored) { | |
| 75 ASSERT_NO_FATAL_FAILURE(ClearStoredColumnSettings()); | |
| 76 | |
| 77 chrome::ShowTaskManager(browser()); | |
| 78 NewTaskManagerView* view = GetView(); | |
| 79 ASSERT_TRUE(view); | |
| 80 views::TableView* table = GetTable(); | |
| 81 ASSERT_TRUE(table); | |
| 82 | |
| 83 // Toggle the visibility of all columns. | |
| 84 EXPECT_FALSE(table->is_sorted()); | |
| 85 for (size_t i = 0; i < kColumnsSize; ++i) { | |
| 86 EXPECT_EQ(kColumns[i].default_visibility, | |
| 87 table->IsColumnVisible(kColumns[i].id)); | |
| 88 ToggleColumnVisibility(view, kColumns[i].id); | |
| 89 } | |
| 90 | |
| 91 // Sort by the first visible and initially ascending sortable column. | |
| 92 bool is_sorted = false; | |
| 93 int sorted_col_id = -1; | |
| 94 for (size_t i = 0; i < table->visible_columns().size(); ++i) { | |
| 95 const ui::TableColumn& column = table->visible_columns()[i].column; | |
| 96 if (column.sortable && column.initial_sort_is_ascending) { | |
| 97 // Toggle the sort twice for a descending sort. | |
| 98 table->ToggleSortOrder(static_cast<int>(i)); | |
| 99 table->ToggleSortOrder(static_cast<int>(i)); | |
| 100 is_sorted = true; | |
| 101 return; | |
| 102 } | |
| 103 } | |
| 104 | |
| 105 if (is_sorted) { | |
| 106 EXPECT_TRUE(table->is_sorted()); | |
| 107 EXPECT_FALSE(table->sort_descriptors().front().ascending); | |
| 108 EXPECT_EQ(table->sort_descriptors().front().column_id, sorted_col_id); | |
| 109 } | |
| 110 | |
| 111 // Close the task manager view and re-open. Expect the inverse of the default | |
| 112 // visibility, and the last sort order. | |
| 113 chrome::HideTaskManager(); | |
| 114 ASSERT_FALSE(GetView()); | |
| 115 chrome::ShowTaskManager(browser()); | |
| 116 view = GetView(); | |
| 117 ASSERT_TRUE(view); | |
| 118 table = GetTable(); | |
| 119 ASSERT_TRUE(table); | |
| 120 | |
| 121 if (is_sorted) { | |
| 122 EXPECT_TRUE(table->is_sorted()); | |
| 123 EXPECT_FALSE(table->sort_descriptors().front().ascending); | |
| 124 EXPECT_EQ(table->sort_descriptors().front().column_id, sorted_col_id); | |
| 125 } | |
| 126 for (size_t i = 0; i < kColumnsSize; ++i) { | |
| 127 EXPECT_EQ(!kColumns[i].default_visibility, | |
| 128 table->IsColumnVisible(kColumns[i].id)); | |
| 129 } | |
| 130 } | |
| 131 | |
| 132 } // namespace task_management | |
| 133 | |
| OLD | NEW |