Add new certificateProvider extension API.
[chromium-blink-merge.git] / chrome / browser / ui / views / new_task_manager_view_browsertest.cc
blob2e27afb5e689e780e1f4275c03167d84fc2fe4a5
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.
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"
15 namespace task_management {
17 class NewTaskManagerViewTest : public InProcessBrowserTest {
18 public:
19 NewTaskManagerViewTest() {}
20 ~NewTaskManagerViewTest() override {}
22 void TearDownOnMainThread() override {
23 // Make sure the task manager is closed (if any).
24 chrome::HideTaskManager();
25 content::RunAllPendingInMessageLoop();
26 ASSERT_FALSE(GetView());
28 InProcessBrowserTest::TearDownOnMainThread();
31 NewTaskManagerView* GetView() const {
32 return NewTaskManagerView::GetInstanceForTests();
35 views::TableView* GetTable() const {
36 return GetView() ? GetView()->tab_table_ : nullptr;
39 void ClearStoredColumnSettings() const {
40 PrefService* local_state = g_browser_process->local_state();
41 if (!local_state)
42 FAIL();
44 DictionaryPrefUpdate dict_update(local_state,
45 prefs::kTaskManagerColumnVisibility);
46 dict_update->Clear();
49 void ToggleColumnVisibility(NewTaskManagerView* view, int col_id) {
50 DCHECK(view);
51 view->ToggleColumnVisibility(col_id);
54 private:
55 DISALLOW_COPY_AND_ASSIGN(NewTaskManagerViewTest);
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));
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());
71 chrome::ShowTaskManager(browser());
72 views::TableView* table = GetTable();
73 ASSERT_TRUE(table);
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));
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());
87 chrome::ShowTaskManager(browser());
88 NewTaskManagerView* view = GetView();
89 ASSERT_TRUE(view);
90 views::TableView* table = GetTable();
91 ASSERT_TRUE(table);
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);
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;
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);
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);
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);
137 for (size_t i = 0; i < kColumnsSize; ++i) {
138 EXPECT_EQ(!kColumns[i].default_visibility,
139 table->IsColumnVisible(kColumns[i].id));
143 } // namespace task_management