| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/compiler_specific.h" | 7 #include "base/compiler_specific.h" |
| 8 #include "base/memory/scoped_nsobject.h" | 8 #include "base/memory/scoped_nsobject.h" |
| 9 #include "base/strings/utf_string_conversions.h" | 9 #include "base/strings/utf_string_conversions.h" |
| 10 #include "chrome/browser/task_manager/resource_provider.h" | 10 #include "chrome/browser/task_manager/resource_provider.h" |
| (...skipping 29 matching lines...) Expand all Loading... |
| 40 }; | 40 }; |
| 41 | 41 |
| 42 } // namespace | 42 } // namespace |
| 43 | 43 |
| 44 class TaskManagerWindowControllerTest : public CocoaTest { | 44 class TaskManagerWindowControllerTest : public CocoaTest { |
| 45 }; | 45 }; |
| 46 | 46 |
| 47 // Test creation, to ensure nothing leaks or crashes. | 47 // Test creation, to ensure nothing leaks or crashes. |
| 48 TEST_F(TaskManagerWindowControllerTest, Init) { | 48 TEST_F(TaskManagerWindowControllerTest, Init) { |
| 49 TaskManager task_manager; | 49 TaskManager task_manager; |
| 50 TaskManagerMac* bridge(new TaskManagerMac(&task_manager, false)); | 50 TaskManagerMac* bridge(new TaskManagerMac(&task_manager)); |
| 51 TaskManagerWindowController* controller = bridge->cocoa_controller(); | 51 TaskManagerWindowController* controller = bridge->cocoa_controller(); |
| 52 | 52 |
| 53 // Releases the controller, which in turn deletes |bridge|. | 53 // Releases the controller, which in turn deletes |bridge|. |
| 54 [controller close]; | 54 [controller close]; |
| 55 } | 55 } |
| 56 | 56 |
| 57 TEST_F(TaskManagerWindowControllerTest, Sort) { | 57 TEST_F(TaskManagerWindowControllerTest, Sort) { |
| 58 TaskManager task_manager; | 58 TaskManager task_manager; |
| 59 | 59 |
| 60 TestResource resource1(UTF8ToUTF16("zzz"), 1); | 60 TestResource resource1(UTF8ToUTF16("zzz"), 1); |
| 61 TestResource resource2(UTF8ToUTF16("zzb"), 2); | 61 TestResource resource2(UTF8ToUTF16("zzb"), 2); |
| 62 TestResource resource3(UTF8ToUTF16("zza"), 2); | 62 TestResource resource3(UTF8ToUTF16("zza"), 2); |
| 63 | 63 |
| 64 task_manager.AddResource(&resource1); | 64 task_manager.AddResource(&resource1); |
| 65 task_manager.AddResource(&resource2); | 65 task_manager.AddResource(&resource2); |
| 66 task_manager.AddResource(&resource3); // Will be in the same group as 2. | 66 task_manager.AddResource(&resource3); // Will be in the same group as 2. |
| 67 | 67 |
| 68 TaskManagerMac* bridge(new TaskManagerMac(&task_manager, false)); | 68 TaskManagerMac* bridge(new TaskManagerMac(&task_manager)); |
| 69 TaskManagerWindowController* controller = bridge->cocoa_controller(); | 69 TaskManagerWindowController* controller = bridge->cocoa_controller(); |
| 70 NSTableView* table = [controller tableView]; | 70 NSTableView* table = [controller tableView]; |
| 71 ASSERT_EQ(3, [controller numberOfRowsInTableView:table]); | 71 ASSERT_EQ(3, [controller numberOfRowsInTableView:table]); |
| 72 | 72 |
| 73 // Test that table is sorted on title. | 73 // Test that table is sorted on title. |
| 74 NSTableColumn* title_column = [table tableColumnWithIdentifier: | 74 NSTableColumn* title_column = [table tableColumnWithIdentifier: |
| 75 [NSString stringWithFormat:@"%d", IDS_TASK_MANAGER_TASK_COLUMN]]; | 75 [NSString stringWithFormat:@"%d", IDS_TASK_MANAGER_TASK_COLUMN]]; |
| 76 NSCell* cell; | 76 NSCell* cell; |
| 77 cell = [controller tableView:table dataCellForTableColumn:title_column row:0]; | 77 cell = [controller tableView:table dataCellForTableColumn:title_column row:0]; |
| 78 EXPECT_NSEQ(@"zzb", [cell title]); | 78 EXPECT_NSEQ(@"zzb", [cell title]); |
| (...skipping 12 matching lines...) Expand all Loading... |
| 91 | 91 |
| 92 TEST_F(TaskManagerWindowControllerTest, SelectionAdaptsToSorting) { | 92 TEST_F(TaskManagerWindowControllerTest, SelectionAdaptsToSorting) { |
| 93 TaskManager task_manager; | 93 TaskManager task_manager; |
| 94 | 94 |
| 95 TestResource resource1(UTF8ToUTF16("yyy"), 1); | 95 TestResource resource1(UTF8ToUTF16("yyy"), 1); |
| 96 TestResource resource2(UTF8ToUTF16("aaa"), 2); | 96 TestResource resource2(UTF8ToUTF16("aaa"), 2); |
| 97 | 97 |
| 98 task_manager.AddResource(&resource1); | 98 task_manager.AddResource(&resource1); |
| 99 task_manager.AddResource(&resource2); | 99 task_manager.AddResource(&resource2); |
| 100 | 100 |
| 101 TaskManagerMac* bridge(new TaskManagerMac(&task_manager, false)); | 101 TaskManagerMac* bridge(new TaskManagerMac(&task_manager)); |
| 102 TaskManagerWindowController* controller = bridge->cocoa_controller(); | 102 TaskManagerWindowController* controller = bridge->cocoa_controller(); |
| 103 NSTableView* table = [controller tableView]; | 103 NSTableView* table = [controller tableView]; |
| 104 ASSERT_EQ(2, [controller numberOfRowsInTableView:table]); | 104 ASSERT_EQ(2, [controller numberOfRowsInTableView:table]); |
| 105 | 105 |
| 106 // Select row 0 in the table (corresponds to row 1 in the model). | 106 // Select row 0 in the table (corresponds to row 1 in the model). |
| 107 [table selectRowIndexes:[NSIndexSet indexSetWithIndex:0] | 107 [table selectRowIndexes:[NSIndexSet indexSetWithIndex:0] |
| 108 byExtendingSelection:NO]; | 108 byExtendingSelection:NO]; |
| 109 | 109 |
| 110 // Change the name of resource2 so that it becomes row 1 in the table. | 110 // Change the name of resource2 so that it becomes row 1 in the table. |
| 111 resource2.title_ = UTF8ToUTF16("zzz"); | 111 resource2.title_ = UTF8ToUTF16("zzz"); |
| 112 bridge->task_manager()->model()->Refresh(); | 112 bridge->task_manager()->model()->Refresh(); |
| 113 bridge->OnItemsChanged(1, 1); | 113 bridge->OnItemsChanged(1, 1); |
| 114 | 114 |
| 115 // Check that the selection has moved to row 1. | 115 // Check that the selection has moved to row 1. |
| 116 NSIndexSet* selection = [table selectedRowIndexes]; | 116 NSIndexSet* selection = [table selectedRowIndexes]; |
| 117 ASSERT_EQ(1u, [selection count]); | 117 ASSERT_EQ(1u, [selection count]); |
| 118 EXPECT_EQ(1u, [selection firstIndex]); | 118 EXPECT_EQ(1u, [selection firstIndex]); |
| 119 | 119 |
| 120 // Releases the controller, which in turn deletes |bridge|. | 120 // Releases the controller, which in turn deletes |bridge|. |
| 121 [controller close]; | 121 [controller close]; |
| 122 | 122 |
| 123 task_manager.RemoveResource(&resource1); | 123 task_manager.RemoveResource(&resource1); |
| 124 task_manager.RemoveResource(&resource2); | 124 task_manager.RemoveResource(&resource2); |
| 125 } | 125 } |
| OLD | NEW |