summaryrefslogtreecommitdiffstats
path: root/chrome/browser/task_manager
diff options
context:
space:
mode:
authoryoshiki@chromium.org <yoshiki@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-10-18 02:26:04 +0000
committeryoshiki@chromium.org <yoshiki@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-10-18 02:26:04 +0000
commitc29240a21de2e855328792ae5b755c026cfc80eb (patch)
tree3dcfbc8890920bf7306265f5a838f83d4627376e /chrome/browser/task_manager
parent6be08ae197f90f71e3804ff1e842000a5db2af20 (diff)
downloadchromium_src-c29240a21de2e855328792ae5b755c026cfc80eb.zip
chromium_src-c29240a21de2e855328792ae5b755c026cfc80eb.tar.gz
chromium_src-c29240a21de2e855328792ae5b755c026cfc80eb.tar.bz2
Fixed crashes in webui taskmanager and tests on Win.
BUG=100431 TEST=run browser_test manually Review URL: http://codereview.chromium.org/8336002 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@106004 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/task_manager')
-rw-r--r--chrome/browser/task_manager/task_manager_browsertest_util.cc11
-rw-r--r--chrome/browser/task_manager/task_manager_notification_browsertest.cc58
2 files changed, 15 insertions, 54 deletions
diff --git a/chrome/browser/task_manager/task_manager_browsertest_util.cc b/chrome/browser/task_manager/task_manager_browsertest_util.cc
index c0e6d75..6dd16a7 100644
--- a/chrome/browser/task_manager/task_manager_browsertest_util.cc
+++ b/chrome/browser/task_manager/task_manager_browsertest_util.cc
@@ -55,10 +55,17 @@ class ResourceChangeObserver : public TaskManagerModelObserver {
void TaskManagerBrowserTestUtil::WaitForResourceChange(int target_count) {
TaskManagerModel* model = TaskManager::GetInstance()->model();
- if (model->ResourceCount() == target_count)
- return;
ResourceChangeObserver observer(model, target_count);
model->AddObserver(&observer);
+
+ // Checks that the condition has not been satisfied yet.
+ // This check has to be placed after the installation of the observer,
+ // because resources may change before that.
+ if (model->ResourceCount() == target_count) {
+ model->RemoveObserver(&observer);
+ return;
+ }
+
ui_test_utils::RunMessageLoop();
model->RemoveObserver(&observer);
}
diff --git a/chrome/browser/task_manager/task_manager_notification_browsertest.cc b/chrome/browser/task_manager/task_manager_notification_browsertest.cc
index 137448a..46a02b5 100644
--- a/chrome/browser/task_manager/task_manager_notification_browsertest.cc
+++ b/chrome/browser/task_manager/task_manager_notification_browsertest.cc
@@ -11,64 +11,18 @@
#include "chrome/browser/notifications/notification.h"
#include "chrome/browser/notifications/notification_test_util.h"
#include "chrome/browser/notifications/notification_ui_manager.h"
+#include "chrome/browser/task_manager/task_manager_browsertest_util.h"
#include "chrome/browser/ui/browser.h"
#include "chrome/browser/ui/browser_window.h"
#include "chrome/test/base/in_process_browser_test.h"
#include "chrome/test/base/ui_test_utils.h"
#include "testing/gtest/include/gtest/gtest.h"
-namespace {
-
-class ResourceChangeObserver : public TaskManagerModelObserver {
- public:
- ResourceChangeObserver(const TaskManagerModel* model,
- int target_resource_count)
- : model_(model),
- target_resource_count_(target_resource_count) {
- }
-
- virtual void OnModelChanged() {
- OnResourceChange();
- }
-
- virtual void OnItemsChanged(int start, int length) {
- OnResourceChange();
- }
-
- virtual void OnItemsAdded(int start, int length) {
- OnResourceChange();
- }
-
- virtual void OnItemsRemoved(int start, int length) {
- OnResourceChange();
- }
-
- private:
- void OnResourceChange() {
- if (model_->ResourceCount() == target_resource_count_)
- MessageLoopForUI::current()->Quit();
- }
-
- const TaskManagerModel* model_;
- const int target_resource_count_;
-};
-
-} // namespace
-
class TaskManagerNotificationBrowserTest : public ExtensionBrowserTest {
public:
TaskManagerModel* model() const {
return TaskManager::GetInstance()->model();
}
-
- void WaitForResourceChange(int target_count) {
- if (model()->ResourceCount() == target_count)
- return;
- ResourceChangeObserver observer(model(), target_count);
- model()->AddObserver(&observer);
- ui_test_utils::RunMessageLoop();
- model()->RemoveObserver(&observer);
- }
};
IN_PROC_BROWSER_TEST_F(TaskManagerNotificationBrowserTest,
@@ -78,7 +32,7 @@ IN_PROC_BROWSER_TEST_F(TaskManagerNotificationBrowserTest,
// Show the task manager.
browser()->window()->ShowTaskManager();
// Expect to see the browser and the New Tab Page renderer.
- WaitForResourceChange(2);
+ TaskManagerBrowserTestUtil::WaitForResourceChange(2);
// Show a notification.
NotificationUIManager* notifications =
@@ -96,11 +50,11 @@ IN_PROC_BROWSER_TEST_F(TaskManagerNotificationBrowserTest,
GURL(), GURL(content), ASCIIToUTF16("Test 2"), string16(), del2.get());
notifications->Add(n1, browser()->profile());
- WaitForResourceChange(3);
+ TaskManagerBrowserTestUtil::WaitForResourceChange(3);
notifications->Add(n2, browser()->profile());
- WaitForResourceChange(4);
+ TaskManagerBrowserTestUtil::WaitForResourceChange(4);
notifications->CancelById(n1.notification_id());
- WaitForResourceChange(3);
+ TaskManagerBrowserTestUtil::WaitForResourceChange(3);
notifications->CancelById(n2.notification_id());
- WaitForResourceChange(2);
+ TaskManagerBrowserTestUtil::WaitForResourceChange(2);
}