This repository has been archived by the owner on Apr 3, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 211
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Task Manager Should remember the most recently enabled columns.
This CL: 1- Makes adding and removing columns to the task manager a lot easier and cleaner. 2- Stores/retrieves the columns visibility to/from the local state prefs. 3- Stores/retrieves the sorted column and the sort order. [email protected] BUG=452521 TEST=browser_tests --gtest_filter=NewTaskManagerViewTest.* Committed: https://crrev.com/4e16add803fbb0ed18413496d3fb4424fa4957c6 Cr-Commit-Position: refs/heads/master@{#346524} Review URL: https://codereview.chromium.org/1320563002 Cr-Commit-Position: refs/heads/master@{#346734} (cherry picked from commit 4780b87) Review URL: https://codereview.chromium.org/1332083002 . Cr-Commit-Position: refs/branch-heads/2490@{#228} Cr-Branched-From: 7790a35-refs/heads/master@{#344925}
- Loading branch information
Ahmed Fakhry
committed
Sep 10, 2015
1 parent
e26a292
commit 66147f6
Showing
8 changed files
with
438 additions
and
144 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
144 changes: 144 additions & 0 deletions
144
chrome/browser/ui/views/new_task_manager_view_browsertest.cc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,144 @@ | ||
// Copyright 2015 The Chromium Authors. All rights reserved. | ||
// Use of this source code is governed by a BSD-style license that can be | ||
// found in the LICENSE file. | ||
|
||
#include "base/prefs/pref_service.h" | ||
#include "base/prefs/scoped_user_pref_update.h" | ||
#include "chrome/browser/browser_process.h" | ||
#include "chrome/browser/ui/browser_dialogs.h" | ||
#include "chrome/browser/ui/views/new_task_manager_view.h" | ||
#include "chrome/common/pref_names.h" | ||
#include "chrome/test/base/in_process_browser_test.h" | ||
#include "content/public/test/test_utils.h" | ||
#include "ui/views/controls/table/table_view.h" | ||
|
||
namespace task_management { | ||
|
||
class NewTaskManagerViewTest : public InProcessBrowserTest { | ||
public: | ||
NewTaskManagerViewTest() {} | ||
~NewTaskManagerViewTest() override {} | ||
|
||
void TearDownOnMainThread() override { | ||
// Make sure the task manager is closed (if any). | ||
chrome::HideTaskManager(); | ||
content::RunAllPendingInMessageLoop(); | ||
ASSERT_FALSE(GetView()); | ||
|
||
InProcessBrowserTest::TearDownOnMainThread(); | ||
} | ||
|
||
NewTaskManagerView* GetView() const { | ||
return NewTaskManagerView::GetInstanceForTests(); | ||
} | ||
|
||
views::TableView* GetTable() const { | ||
return GetView() ? GetView()->tab_table_ : nullptr; | ||
} | ||
|
||
void ClearStoredColumnSettings() const { | ||
PrefService* local_state = g_browser_process->local_state(); | ||
if (!local_state) | ||
FAIL(); | ||
|
||
DictionaryPrefUpdate dict_update(local_state, | ||
prefs::kTaskManagerColumnVisibility); | ||
dict_update->Clear(); | ||
} | ||
|
||
void ToggleColumnVisibility(NewTaskManagerView* view, int col_id) { | ||
DCHECK(view); | ||
view->ToggleColumnVisibility(col_id); | ||
} | ||
|
||
private: | ||
DISALLOW_COPY_AND_ASSIGN(NewTaskManagerViewTest); | ||
}; | ||
|
||
// Tests that all defined columns have a corresponding string IDs for keying | ||
// into the user preferences dictionary. | ||
IN_PROC_BROWSER_TEST_F(NewTaskManagerViewTest, AllColumnsHaveStringIds) { | ||
for (size_t i = 0; i < kColumnsSize; ++i) | ||
EXPECT_NE("", GetColumnIdAsString(kColumns[i].id)); | ||
} | ||
|
||
// In the case of no settings stored in the user preferences local store, test | ||
// that the task manager table starts with the default columns visibility as | ||
// stored in |kColumns|. | ||
IN_PROC_BROWSER_TEST_F(NewTaskManagerViewTest, TableStartsWithDefaultColumns) { | ||
ASSERT_NO_FATAL_FAILURE(ClearStoredColumnSettings()); | ||
|
||
chrome::ShowTaskManager(browser()); | ||
views::TableView* table = GetTable(); | ||
ASSERT_TRUE(table); | ||
|
||
EXPECT_FALSE(table->is_sorted()); | ||
for (size_t i = 0; i < kColumnsSize; ++i) { | ||
EXPECT_EQ(kColumns[i].default_visibility, | ||
table->IsColumnVisible(kColumns[i].id)); | ||
} | ||
} | ||
|
||
// Tests that changing columns visibility and sort order will be stored upon | ||
// closing the task manager view and restored when re-opened. | ||
IN_PROC_BROWSER_TEST_F(NewTaskManagerViewTest, ColumnsSettingsAreRestored) { | ||
ASSERT_NO_FATAL_FAILURE(ClearStoredColumnSettings()); | ||
|
||
chrome::ShowTaskManager(browser()); | ||
NewTaskManagerView* view = GetView(); | ||
ASSERT_TRUE(view); | ||
views::TableView* table = GetTable(); | ||
ASSERT_TRUE(table); | ||
|
||
// Toggle the visibility of all columns. | ||
EXPECT_FALSE(table->is_sorted()); | ||
for (size_t i = 0; i < kColumnsSize; ++i) { | ||
EXPECT_EQ(kColumns[i].default_visibility, | ||
table->IsColumnVisible(kColumns[i].id)); | ||
ToggleColumnVisibility(view, kColumns[i].id); | ||
} | ||
|
||
// Sort by the first visible and initially ascending sortable column. | ||
bool is_sorted = false; | ||
int sorted_col_id = -1; | ||
for (size_t i = 0; i < table->visible_columns().size(); ++i) { | ||
const ui::TableColumn& column = table->visible_columns()[i].column; | ||
if (column.sortable && column.initial_sort_is_ascending) { | ||
// Toggle the sort twice for a descending sort. | ||
table->ToggleSortOrder(static_cast<int>(i)); | ||
table->ToggleSortOrder(static_cast<int>(i)); | ||
is_sorted = true; | ||
return; | ||
} | ||
} | ||
|
||
if (is_sorted) { | ||
EXPECT_TRUE(table->is_sorted()); | ||
EXPECT_FALSE(table->sort_descriptors().front().ascending); | ||
EXPECT_EQ(table->sort_descriptors().front().column_id, sorted_col_id); | ||
} | ||
|
||
// Close the task manager view and re-open. Expect the inverse of the default | ||
// visibility, and the last sort order. | ||
chrome::HideTaskManager(); | ||
content::RunAllPendingInMessageLoop(); | ||
ASSERT_FALSE(GetView()); | ||
chrome::ShowTaskManager(browser()); | ||
view = GetView(); | ||
ASSERT_TRUE(view); | ||
table = GetTable(); | ||
ASSERT_TRUE(table); | ||
|
||
if (is_sorted) { | ||
EXPECT_TRUE(table->is_sorted()); | ||
EXPECT_FALSE(table->sort_descriptors().front().ascending); | ||
EXPECT_EQ(table->sort_descriptors().front().column_id, sorted_col_id); | ||
} | ||
for (size_t i = 0; i < kColumnsSize; ++i) { | ||
EXPECT_EQ(!kColumns[i].default_visibility, | ||
table->IsColumnVisible(kColumns[i].id)); | ||
} | ||
} | ||
|
||
} // namespace task_management | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters