OLD | NEW |
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 #import "chrome/browser/cocoa/task_manager_mac.h" | 9 #import "chrome/browser/cocoa/task_manager_mac.h" |
9 #import "chrome/browser/cocoa/cocoa_test_helper.h" | 10 #import "chrome/browser/cocoa/cocoa_test_helper.h" |
| 11 #include "grit/generated_resources.h" |
10 #include "testing/gtest/include/gtest/gtest.h" | 12 #include "testing/gtest/include/gtest/gtest.h" |
11 #include "testing/platform_test.h" | 13 #include "testing/platform_test.h" |
12 | 14 |
13 namespace { | 15 namespace { |
14 | 16 |
15 class TaskManagerWindowControllerTest : public CocoaTest { | 17 class TestResource : public TaskManager::Resource { |
16 public: | 18 public: |
17 virtual void SetUp() { | 19 TestResource(const string16& title) : title_(title) {} |
18 CocoaTest::SetUp(); | 20 virtual std::wstring GetTitle() const { return UTF16ToWide(title_); } |
19 controller_ = [[TaskManagerWindowController alloc] init]; | 21 virtual SkBitmap GetIcon() const { return SkBitmap(); } |
| 22 virtual base::ProcessHandle GetProcess() const { |
| 23 return base::GetCurrentProcessHandle(); |
20 } | 24 } |
21 | 25 virtual bool SupportNetworkUsage() const { return false; } |
22 virtual void TearDown() { | 26 virtual void SetSupportNetworkUsage() { NOTREACHED(); } |
23 [controller_ close]; | 27 virtual void Refresh() {} |
24 CocoaTest::TearDown(); | 28 string16 title_; |
25 } | |
26 | |
27 TaskManagerWindowController *controller_; | |
28 }; | 29 }; |
29 | 30 |
30 // Test creation, to ensure nothing leaks or crashes | 31 } // namespace |
| 32 |
| 33 class TaskManagerWindowControllerTest : public CocoaTest { |
| 34 }; |
| 35 |
| 36 // Test creation, to ensure nothing leaks or crashes. |
31 TEST_F(TaskManagerWindowControllerTest, Init) { | 37 TEST_F(TaskManagerWindowControllerTest, Init) { |
| 38 TaskManager task_manager; |
| 39 TaskManagerMac* bridge(new TaskManagerMac(&task_manager)); |
| 40 TaskManagerWindowController* controller = bridge->cocoa_controller(); |
| 41 |
| 42 // Releases the controller, which in turn deletes |bridge|. |
| 43 [controller close]; |
32 } | 44 } |
33 | 45 |
34 // TODO(thakis): Add tests for more methods as they become implemented | 46 TEST_F(TaskManagerWindowControllerTest, Sort) { |
35 // (TaskManager::Show() etc). | 47 TaskManager task_manager; |
36 | 48 |
37 } // namespace | 49 TestResource resource1(UTF8ToUTF16("zzz")); |
| 50 TestResource resource2(UTF8ToUTF16("zza")); |
| 51 |
| 52 task_manager.AddResource(&resource1); |
| 53 task_manager.AddResource(&resource2); // Will be in the same group. |
| 54 |
| 55 TaskManagerMac* bridge(new TaskManagerMac(&task_manager)); |
| 56 TaskManagerWindowController* controller = bridge->cocoa_controller(); |
| 57 NSTableView* table = [controller tableView]; |
| 58 ASSERT_EQ(2, [controller numberOfRowsInTableView:table]); |
| 59 |
| 60 // Test that table is sorted on title. |
| 61 NSTableColumn* title_column = [table tableColumnWithIdentifier: |
| 62 [NSNumber numberWithInt:IDS_TASK_MANAGER_PAGE_COLUMN]]; |
| 63 NSCell* cell; |
| 64 cell = [controller tableView:table dataCellForTableColumn:title_column row:0]; |
| 65 EXPECT_TRUE([@"zza" isEqualToString:[cell title]]); |
| 66 cell = [controller tableView:table dataCellForTableColumn:title_column row:1]; |
| 67 EXPECT_TRUE([@"zzz" isEqualToString:[cell title]]); |
| 68 |
| 69 // Releases the controller, which in turn deletes |bridge|. |
| 70 [controller close]; |
| 71 |
| 72 task_manager.RemoveResource(&resource1); |
| 73 task_manager.RemoveResource(&resource2); |
| 74 } |
OLD | NEW |