diff options
-rw-r--r-- | chrome/browser/task_manager.h | 4 | ||||
-rw-r--r-- | chrome/browser/task_manager_unittest.cc | 80 | ||||
-rw-r--r-- | chrome/chrome.gyp | 2 | ||||
-rw-r--r-- | chrome/test/unit/unittests.vcproj | 4 |
4 files changed, 90 insertions, 0 deletions
diff --git a/chrome/browser/task_manager.h b/chrome/browser/task_manager.h index 717dcf2..866246c 100644 --- a/chrome/browser/task_manager.h +++ b/chrome/browser/task_manager.h @@ -18,6 +18,7 @@ #include "chrome/views/controls/table/group_table_view.h" #include "chrome/views/window/dialog_delegate.h" #include "net/url_request/url_request_job_tracker.h" +#include "testing/gtest/include/gtest/gtest_prod.h" class MessageLoop; class ModelEntry; @@ -136,6 +137,9 @@ class TaskManager : public views::DialogDelegate { virtual views::View* GetContentsView(); private: + FRIEND_TEST(TaskManagerTest, Basic); + FRIEND_TEST(TaskManagerTest, Resources); + // Obtain an instance via GetInstance(). TaskManager(); friend DefaultSingletonTraits<TaskManager>; diff --git a/chrome/browser/task_manager_unittest.cc b/chrome/browser/task_manager_unittest.cc new file mode 100644 index 0000000..e72e98c --- /dev/null +++ b/chrome/browser/task_manager_unittest.cc @@ -0,0 +1,80 @@ +// Copyright (c) 2009 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 "chrome/browser/task_manager.h" + +#include <string> + +#include "chrome/views/controls/table/table_view.h" +#include "grit/chromium_strings.h" +#include "grit/generated_resources.h" +#include "testing/gtest/include/gtest/gtest.h" + +namespace { + +class TestResource : public TaskManager::Resource { + public: + virtual std::wstring GetTitle() const { return L"test title"; } + virtual SkBitmap GetIcon() const { return SkBitmap(); } + virtual HANDLE GetProcess() const { return NULL; } + virtual bool SupportNetworkUsage() const { return false; } + virtual void SetSupportNetworkUsage() { NOTREACHED(); } +}; + +} // namespace + +class TaskManagerTest : public testing::Test, + public views::TableModelObserver { + public: + // TableModelObserver + virtual void OnModelChanged() {} + virtual void OnItemsChanged(int start, int length) {} + virtual void OnItemsAdded(int start, int length) {} + virtual void OnItemsRemoved(int start, int length) {} +}; + +TEST_F(TaskManagerTest, Basic) { + TaskManager task_manager; + TaskManagerTableModel* model = task_manager.table_model_; + EXPECT_FALSE(task_manager.BrowserProcessIsSelected()); + EXPECT_EQ(0, model->RowCount()); +} + +TEST_F(TaskManagerTest, Resources) { + TaskManager task_manager; + TaskManagerTableModel* model = task_manager.table_model_; + model->SetObserver(this); + + TestResource resource1, resource2; + + task_manager.AddResource(&resource1); + ASSERT_EQ(1, model->RowCount()); + EXPECT_STREQ(L"test title", + model->GetText(0, IDS_TASK_MANAGER_PAGE_COLUMN).c_str()); + EXPECT_STREQ(l10n_util::GetString(IDS_TASK_MANAGER_NA_CELL_TEXT).c_str(), + model->GetText(0, IDS_TASK_MANAGER_NET_COLUMN).c_str()); + EXPECT_STREQ(L"0", + model->GetText(0, IDS_TASK_MANAGER_CPU_COLUMN).c_str()); + + task_manager.AddResource(&resource2); // Will be in the same group. + ASSERT_EQ(2, model->RowCount()); + EXPECT_STREQ(L"test title", + model->GetText(1, IDS_TASK_MANAGER_PAGE_COLUMN).c_str()); + EXPECT_STREQ(l10n_util::GetString(IDS_TASK_MANAGER_NA_CELL_TEXT).c_str(), + model->GetText(1, IDS_TASK_MANAGER_NET_COLUMN).c_str()); + EXPECT_STREQ(L"", model->GetText(1, IDS_TASK_MANAGER_CPU_COLUMN).c_str()); + + task_manager.RemoveResource(&resource1); + // Now resource2 will be first in group. + ASSERT_EQ(1, model->RowCount()); + EXPECT_STREQ(L"test title", + model->GetText(0, IDS_TASK_MANAGER_PAGE_COLUMN).c_str()); + EXPECT_STREQ(l10n_util::GetString(IDS_TASK_MANAGER_NA_CELL_TEXT).c_str(), + model->GetText(0, IDS_TASK_MANAGER_NET_COLUMN).c_str()); + EXPECT_STREQ(L"0", + model->GetText(0, IDS_TASK_MANAGER_CPU_COLUMN).c_str()); + + task_manager.RemoveResource(&resource2); + EXPECT_EQ(0, model->RowCount()); +} diff --git a/chrome/chrome.gyp b/chrome/chrome.gyp index 6c7aeaf..2aee355 100644 --- a/chrome/chrome.gyp +++ b/chrome/chrome.gyp @@ -2291,6 +2291,7 @@ 'browser/tab_contents/render_view_host_manager_unittest.cc', 'browser/tab_contents/web_contents_unittest.cc', 'browser/tabs/tab_strip_model_unittest.cc', + 'browser/task_manager_unittest.cc', 'browser/theme_resources_util_unittest.cc', 'browser/views/bookmark_editor_view_unittest.cc', 'browser/views/find_bar_win_unittest.cc', @@ -2434,6 +2435,7 @@ 'browser/rlz/rlz_unittest.cc', 'browser/sessions/session_service_unittest.cc', 'browser/tabs/tab_strip_model_unittest.cc', + 'browser/task_manager_unittest.cc', 'browser/views/bookmark_editor_view_unittest.cc', 'browser/views/find_bar_win_unittest.cc', 'browser/views/keyword_editor_view_unittest.cc', diff --git a/chrome/test/unit/unittests.vcproj b/chrome/test/unit/unittests.vcproj index 85ca286..631b37c 100644 --- a/chrome/test/unit/unittests.vcproj +++ b/chrome/test/unit/unittests.vcproj @@ -724,6 +724,10 @@ > </File> <File + RelativePath="..\..\browser\task_manager_unittest.cc" + > + </File> + <File RelativePath="..\..\browser\search_engines\template_url_model_unittest.cc" > </File> |