Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(33)

Side by Side Diff: chrome/browser/ui/views/new_task_manager_view_browsertest.cc

Issue 1332083002: Task Manager Should remember the most recently enabled columns. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@2490
Patch Set: Created 5 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « chrome/browser/ui/views/new_task_manager_view.cc ('k') | chrome/chrome_tests.gypi » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(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 void TearDownOnMainThread() override {
23 // Make sure the task manager is closed (if any).
24 chrome::HideTaskManager();
25 content::RunAllPendingInMessageLoop();
26 ASSERT_FALSE(GetView());
27
28 InProcessBrowserTest::TearDownOnMainThread();
29 }
30
31 NewTaskManagerView* GetView() const {
32 return NewTaskManagerView::GetInstanceForTests();
33 }
34
35 views::TableView* GetTable() const {
36 return GetView() ? GetView()->tab_table_ : nullptr;
37 }
38
39 void ClearStoredColumnSettings() const {
40 PrefService* local_state = g_browser_process->local_state();
41 if (!local_state)
42 FAIL();
43
44 DictionaryPrefUpdate dict_update(local_state,
45 prefs::kTaskManagerColumnVisibility);
46 dict_update->Clear();
47 }
48
49 void ToggleColumnVisibility(NewTaskManagerView* view, int col_id) {
50 DCHECK(view);
51 view->ToggleColumnVisibility(col_id);
52 }
53
54 private:
55 DISALLOW_COPY_AND_ASSIGN(NewTaskManagerViewTest);
56 };
57
58 // Tests that all defined columns have a corresponding string IDs for keying
59 // into the user preferences dictionary.
60 IN_PROC_BROWSER_TEST_F(NewTaskManagerViewTest, AllColumnsHaveStringIds) {
61 for (size_t i = 0; i < kColumnsSize; ++i)
62 EXPECT_NE("", GetColumnIdAsString(kColumns[i].id));
63 }
64
65 // In the case of no settings stored in the user preferences local store, test
66 // that the task manager table starts with the default columns visibility as
67 // stored in |kColumns|.
68 IN_PROC_BROWSER_TEST_F(NewTaskManagerViewTest, TableStartsWithDefaultColumns) {
69 ASSERT_NO_FATAL_FAILURE(ClearStoredColumnSettings());
70
71 chrome::ShowTaskManager(browser());
72 views::TableView* table = GetTable();
73 ASSERT_TRUE(table);
74
75 EXPECT_FALSE(table->is_sorted());
76 for (size_t i = 0; i < kColumnsSize; ++i) {
77 EXPECT_EQ(kColumns[i].default_visibility,
78 table->IsColumnVisible(kColumns[i].id));
79 }
80 }
81
82 // Tests that changing columns visibility and sort order will be stored upon
83 // closing the task manager view and restored when re-opened.
84 IN_PROC_BROWSER_TEST_F(NewTaskManagerViewTest, ColumnsSettingsAreRestored) {
85 ASSERT_NO_FATAL_FAILURE(ClearStoredColumnSettings());
86
87 chrome::ShowTaskManager(browser());
88 NewTaskManagerView* view = GetView();
89 ASSERT_TRUE(view);
90 views::TableView* table = GetTable();
91 ASSERT_TRUE(table);
92
93 // Toggle the visibility of all columns.
94 EXPECT_FALSE(table->is_sorted());
95 for (size_t i = 0; i < kColumnsSize; ++i) {
96 EXPECT_EQ(kColumns[i].default_visibility,
97 table->IsColumnVisible(kColumns[i].id));
98 ToggleColumnVisibility(view, kColumns[i].id);
99 }
100
101 // Sort by the first visible and initially ascending sortable column.
102 bool is_sorted = false;
103 int sorted_col_id = -1;
104 for (size_t i = 0; i < table->visible_columns().size(); ++i) {
105 const ui::TableColumn& column = table->visible_columns()[i].column;
106 if (column.sortable && column.initial_sort_is_ascending) {
107 // Toggle the sort twice for a descending sort.
108 table->ToggleSortOrder(static_cast<int>(i));
109 table->ToggleSortOrder(static_cast<int>(i));
110 is_sorted = true;
111 return;
112 }
113 }
114
115 if (is_sorted) {
116 EXPECT_TRUE(table->is_sorted());
117 EXPECT_FALSE(table->sort_descriptors().front().ascending);
118 EXPECT_EQ(table->sort_descriptors().front().column_id, sorted_col_id);
119 }
120
121 // Close the task manager view and re-open. Expect the inverse of the default
122 // visibility, and the last sort order.
123 chrome::HideTaskManager();
124 content::RunAllPendingInMessageLoop();
125 ASSERT_FALSE(GetView());
126 chrome::ShowTaskManager(browser());
127 view = GetView();
128 ASSERT_TRUE(view);
129 table = GetTable();
130 ASSERT_TRUE(table);
131
132 if (is_sorted) {
133 EXPECT_TRUE(table->is_sorted());
134 EXPECT_FALSE(table->sort_descriptors().front().ascending);
135 EXPECT_EQ(table->sort_descriptors().front().column_id, sorted_col_id);
136 }
137 for (size_t i = 0; i < kColumnsSize; ++i) {
138 EXPECT_EQ(!kColumns[i].default_visibility,
139 table->IsColumnVisible(kColumns[i].id));
140 }
141 }
142
143 } // namespace task_management
144
OLDNEW
« no previous file with comments | « chrome/browser/ui/views/new_task_manager_view.cc ('k') | chrome/chrome_tests.gypi » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698