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

Side by Side Diff: chrome/browser/cocoa/task_manager_mac_unittest.mm

Issue 3029041: Mac: Keep groups when sorting task manager, like windows does. (Closed)
Patch Set: '' Created 10 years, 4 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/cocoa/task_manager_mac.mm ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #import <Cocoa/Cocoa.h> 5 #import <Cocoa/Cocoa.h>
6 6
7 #include "base/scoped_nsobject.h" 7 #include "base/scoped_nsobject.h"
8 #include "base/utf_string_conversions.h" 8 #include "base/utf_string_conversions.h"
9 #import "chrome/browser/cocoa/task_manager_mac.h" 9 #import "chrome/browser/cocoa/task_manager_mac.h"
10 #import "chrome/browser/cocoa/cocoa_test_helper.h" 10 #import "chrome/browser/cocoa/cocoa_test_helper.h"
11 #include "grit/generated_resources.h" 11 #include "grit/generated_resources.h"
12 #include "testing/gtest/include/gtest/gtest.h" 12 #include "testing/gtest/include/gtest/gtest.h"
13 #include "testing/platform_test.h" 13 #include "testing/platform_test.h"
14 14
15 namespace { 15 namespace {
16 16
17 class TestResource : public TaskManager::Resource { 17 class TestResource : public TaskManager::Resource {
18 public: 18 public:
19 TestResource(const string16& title) : title_(title) {} 19 TestResource(const string16& title, pid_t pid) : title_(title), pid_(pid) {}
20 virtual std::wstring GetTitle() const { return UTF16ToWide(title_); } 20 virtual std::wstring GetTitle() const { return UTF16ToWide(title_); }
21 virtual SkBitmap GetIcon() const { return SkBitmap(); } 21 virtual SkBitmap GetIcon() const { return SkBitmap(); }
22 virtual base::ProcessHandle GetProcess() const { 22 virtual base::ProcessHandle GetProcess() const { return pid_; }
23 return base::GetCurrentProcessHandle();
24 }
25 virtual bool SupportNetworkUsage() const { return false; } 23 virtual bool SupportNetworkUsage() const { return false; }
26 virtual void SetSupportNetworkUsage() { NOTREACHED(); } 24 virtual void SetSupportNetworkUsage() { NOTREACHED(); }
27 virtual void Refresh() {} 25 virtual void Refresh() {}
28 string16 title_; 26 string16 title_;
27 pid_t pid_;
29 }; 28 };
30 29
31 } // namespace 30 } // namespace
32 31
33 class TaskManagerWindowControllerTest : public CocoaTest { 32 class TaskManagerWindowControllerTest : public CocoaTest {
34 }; 33 };
35 34
36 // Test creation, to ensure nothing leaks or crashes. 35 // Test creation, to ensure nothing leaks or crashes.
37 TEST_F(TaskManagerWindowControllerTest, Init) { 36 TEST_F(TaskManagerWindowControllerTest, Init) {
38 TaskManager task_manager; 37 TaskManager task_manager;
39 TaskManagerMac* bridge(new TaskManagerMac(&task_manager)); 38 TaskManagerMac* bridge(new TaskManagerMac(&task_manager));
40 TaskManagerWindowController* controller = bridge->cocoa_controller(); 39 TaskManagerWindowController* controller = bridge->cocoa_controller();
41 40
42 // Releases the controller, which in turn deletes |bridge|. 41 // Releases the controller, which in turn deletes |bridge|.
43 [controller close]; 42 [controller close];
44 } 43 }
45 44
46 TEST_F(TaskManagerWindowControllerTest, Sort) { 45 TEST_F(TaskManagerWindowControllerTest, Sort) {
47 TaskManager task_manager; 46 TaskManager task_manager;
48 47
49 TestResource resource1(UTF8ToUTF16("zzz")); 48 TestResource resource1(UTF8ToUTF16("zzz"), 1);
50 TestResource resource2(UTF8ToUTF16("zza")); 49 TestResource resource2(UTF8ToUTF16("zzb"), 2);
50 TestResource resource3(UTF8ToUTF16("zza"), 2);
51 51
52 task_manager.AddResource(&resource1); 52 task_manager.AddResource(&resource1);
53 task_manager.AddResource(&resource2); // Will be in the same group. 53 task_manager.AddResource(&resource2);
54 task_manager.AddResource(&resource3); // Will be in the same group as 2.
54 55
55 TaskManagerMac* bridge(new TaskManagerMac(&task_manager)); 56 TaskManagerMac* bridge(new TaskManagerMac(&task_manager));
56 TaskManagerWindowController* controller = bridge->cocoa_controller(); 57 TaskManagerWindowController* controller = bridge->cocoa_controller();
57 NSTableView* table = [controller tableView]; 58 NSTableView* table = [controller tableView];
58 ASSERT_EQ(2, [controller numberOfRowsInTableView:table]); 59 ASSERT_EQ(3, [controller numberOfRowsInTableView:table]);
59 60
60 // Test that table is sorted on title. 61 // Test that table is sorted on title.
61 NSTableColumn* title_column = [table tableColumnWithIdentifier: 62 NSTableColumn* title_column = [table tableColumnWithIdentifier:
62 [NSNumber numberWithInt:IDS_TASK_MANAGER_PAGE_COLUMN]]; 63 [NSNumber numberWithInt:IDS_TASK_MANAGER_PAGE_COLUMN]];
63 NSCell* cell; 64 NSCell* cell;
64 cell = [controller tableView:table dataCellForTableColumn:title_column row:0]; 65 cell = [controller tableView:table dataCellForTableColumn:title_column row:0];
66 EXPECT_TRUE([@"zzb" isEqualToString:[cell title]]);
67 cell = [controller tableView:table dataCellForTableColumn:title_column row:1];
65 EXPECT_TRUE([@"zza" isEqualToString:[cell title]]); 68 EXPECT_TRUE([@"zza" isEqualToString:[cell title]]);
66 cell = [controller tableView:table dataCellForTableColumn:title_column row:1]; 69 cell = [controller tableView:table dataCellForTableColumn:title_column row:2];
67 EXPECT_TRUE([@"zzz" isEqualToString:[cell title]]); 70 EXPECT_TRUE([@"zzz" isEqualToString:[cell title]]);
68 71
69 // Releases the controller, which in turn deletes |bridge|. 72 // Releases the controller, which in turn deletes |bridge|.
70 [controller close]; 73 [controller close];
71 74
72 task_manager.RemoveResource(&resource1); 75 task_manager.RemoveResource(&resource1);
73 task_manager.RemoveResource(&resource2); 76 task_manager.RemoveResource(&resource2);
77 task_manager.RemoveResource(&resource3);
74 } 78 }
OLDNEW
« no previous file with comments | « chrome/browser/cocoa/task_manager_mac.mm ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698