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

Side by Side Diff: chrome/browser/task_manager/task_manager_unittest.cc

Issue 7828007: Add Profile data to the Task Manager on OS Mac. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 9 years, 3 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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 #include "chrome/browser/task_manager/task_manager.h" 5 #include "chrome/browser/task_manager/task_manager.h"
6 6
7 #include <string> 7 #include <string>
8 8
9 #include "base/message_loop.h" 9 #include "base/message_loop.h"
10 #include "base/process_util.h" 10 #include "base/process_util.h"
(...skipping 15 matching lines...) Expand all
26 const char* kZeroCPUUsage = "0"; 26 const char* kZeroCPUUsage = "0";
27 #endif 27 #endif
28 28
29 class TestResource : public TaskManager::Resource { 29 class TestResource : public TaskManager::Resource {
30 public: 30 public:
31 TestResource() : refresh_called_(false) {} 31 TestResource() : refresh_called_(false) {}
32 32
33 virtual string16 GetTitle() const OVERRIDE { 33 virtual string16 GetTitle() const OVERRIDE {
34 return ASCIIToUTF16("test title"); 34 return ASCIIToUTF16("test title");
35 } 35 }
36 virtual string16 GetProfileName() const OVERRIDE {
37 return ASCIIToUTF16("test profile");
38 }
36 virtual SkBitmap GetIcon() const { return SkBitmap(); } 39 virtual SkBitmap GetIcon() const { return SkBitmap(); }
37 virtual base::ProcessHandle GetProcess() const { 40 virtual base::ProcessHandle GetProcess() const {
38 return base::GetCurrentProcessHandle(); 41 return base::GetCurrentProcessHandle();
39 } 42 }
40 virtual Type GetType() const { return RENDERER; } 43 virtual Type GetType() const { return RENDERER; }
41 virtual bool SupportNetworkUsage() const { return false; } 44 virtual bool SupportNetworkUsage() const { return false; }
42 virtual void SetSupportNetworkUsage() { NOTREACHED(); } 45 virtual void SetSupportNetworkUsage() { NOTREACHED(); }
43 virtual void Refresh() { refresh_called_ = true; } 46 virtual void Refresh() { refresh_called_ = true; }
44 bool refresh_called() const { return refresh_called_; } 47 bool refresh_called() const { return refresh_called_; }
45 void set_refresh_called(bool refresh_called) { 48 void set_refresh_called(bool refresh_called) {
(...skipping 18 matching lines...) Expand all
64 TEST_F(TaskManagerTest, Resources) { 67 TEST_F(TaskManagerTest, Resources) {
65 TaskManager task_manager; 68 TaskManager task_manager;
66 TaskManagerModel* model = task_manager.model_; 69 TaskManagerModel* model = task_manager.model_;
67 70
68 TestResource resource1, resource2; 71 TestResource resource1, resource2;
69 72
70 task_manager.AddResource(&resource1); 73 task_manager.AddResource(&resource1);
71 ASSERT_EQ(1, model->ResourceCount()); 74 ASSERT_EQ(1, model->ResourceCount());
72 EXPECT_TRUE(model->IsResourceFirstInGroup(0)); 75 EXPECT_TRUE(model->IsResourceFirstInGroup(0));
73 EXPECT_EQ(ASCIIToUTF16("test title"), model->GetResourceTitle(0)); 76 EXPECT_EQ(ASCIIToUTF16("test title"), model->GetResourceTitle(0));
77 EXPECT_EQ(ASCIIToUTF16("test profile"), model->GetResourceProfileName(0));
74 EXPECT_EQ(l10n_util::GetStringUTF16(IDS_TASK_MANAGER_NA_CELL_TEXT), 78 EXPECT_EQ(l10n_util::GetStringUTF16(IDS_TASK_MANAGER_NA_CELL_TEXT),
75 model->GetResourceNetworkUsage(0)); 79 model->GetResourceNetworkUsage(0));
76 EXPECT_EQ(ASCIIToUTF16(kZeroCPUUsage), model->GetResourceCPUUsage(0)); 80 EXPECT_EQ(ASCIIToUTF16(kZeroCPUUsage), model->GetResourceCPUUsage(0));
77 81
78 task_manager.AddResource(&resource2); // Will be in the same group. 82 task_manager.AddResource(&resource2); // Will be in the same group.
79 ASSERT_EQ(2, model->ResourceCount()); 83 ASSERT_EQ(2, model->ResourceCount());
80 EXPECT_TRUE(model->IsResourceFirstInGroup(0)); 84 EXPECT_TRUE(model->IsResourceFirstInGroup(0));
81 EXPECT_FALSE(model->IsResourceFirstInGroup(1)); 85 EXPECT_FALSE(model->IsResourceFirstInGroup(1));
82 EXPECT_EQ(ASCIIToUTF16("test title"), model->GetResourceTitle(1)); 86 EXPECT_EQ(ASCIIToUTF16("test title"), model->GetResourceTitle(1));
87 EXPECT_EQ(ASCIIToUTF16("test profile"), model->GetResourceProfileName(1));
83 EXPECT_EQ(l10n_util::GetStringUTF16(IDS_TASK_MANAGER_NA_CELL_TEXT).c_str(), 88 EXPECT_EQ(l10n_util::GetStringUTF16(IDS_TASK_MANAGER_NA_CELL_TEXT).c_str(),
84 model->GetResourceNetworkUsage(1)); 89 model->GetResourceNetworkUsage(1));
85 EXPECT_EQ(ASCIIToUTF16(kZeroCPUUsage), model->GetResourceCPUUsage(1)); 90 EXPECT_EQ(ASCIIToUTF16(kZeroCPUUsage), model->GetResourceCPUUsage(1));
86 91
87 task_manager.RemoveResource(&resource1); 92 task_manager.RemoveResource(&resource1);
88 // Now resource2 will be first in group. 93 // Now resource2 will be first in group.
89 ASSERT_EQ(1, model->ResourceCount()); 94 ASSERT_EQ(1, model->ResourceCount());
90 EXPECT_TRUE(model->IsResourceFirstInGroup(0)); 95 EXPECT_TRUE(model->IsResourceFirstInGroup(0));
91 EXPECT_EQ(ASCIIToUTF16("test title"), model->GetResourceTitle(0)); 96 EXPECT_EQ(ASCIIToUTF16("test title"), model->GetResourceTitle(0));
97 EXPECT_EQ(ASCIIToUTF16("test profile"), model->GetResourceProfileName(0));
92 EXPECT_EQ(l10n_util::GetStringUTF16(IDS_TASK_MANAGER_NA_CELL_TEXT), 98 EXPECT_EQ(l10n_util::GetStringUTF16(IDS_TASK_MANAGER_NA_CELL_TEXT),
93 model->GetResourceNetworkUsage(0)); 99 model->GetResourceNetworkUsage(0));
94 EXPECT_EQ(ASCIIToUTF16(kZeroCPUUsage), model->GetResourceCPUUsage(0)); 100 EXPECT_EQ(ASCIIToUTF16(kZeroCPUUsage), model->GetResourceCPUUsage(0));
95 101
96 task_manager.RemoveResource(&resource2); 102 task_manager.RemoveResource(&resource2);
97 EXPECT_EQ(0, model->ResourceCount()); 103 EXPECT_EQ(0, model->ResourceCount());
98 } 104 }
99 105
100 // Tests that the model is calling Refresh() on its resources. 106 // Tests that the model is calling Refresh() on its resources.
101 TEST_F(TaskManagerTest, RefreshCalled) { 107 TEST_F(TaskManagerTest, RefreshCalled) {
102 MessageLoop loop; 108 MessageLoop loop;
103 TaskManager task_manager; 109 TaskManager task_manager;
104 TaskManagerModel* model = task_manager.model_; 110 TaskManagerModel* model = task_manager.model_;
105 TestResource resource; 111 TestResource resource;
106 112
107 task_manager.AddResource(&resource); 113 task_manager.AddResource(&resource);
108 ASSERT_FALSE(resource.refresh_called()); 114 ASSERT_FALSE(resource.refresh_called());
109 model->update_state_ = TaskManagerModel::TASK_PENDING; 115 model->update_state_ = TaskManagerModel::TASK_PENDING;
110 model->Refresh(); 116 model->Refresh();
111 ASSERT_TRUE(resource.refresh_called()); 117 ASSERT_TRUE(resource.refresh_called());
112 task_manager.RemoveResource(&resource); 118 task_manager.RemoveResource(&resource);
113 } 119 }
OLDNEW
« no previous file with comments | « chrome/browser/task_manager/task_manager_resource_providers.cc ('k') | chrome/browser/ui/cocoa/task_manager_mac.mm » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698