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