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

Unified Diff: chrome/browser/task_manager/task_manager_browsertest.cc

Issue 7491086: This will cause build failed since a include file does not exist. (Closed) Base URL: svn://svn.chromium.org/chrome/branches/835/src/
Patch Set: Created 9 years, 4 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/task_manager/task_manager_browsertest.cc
===================================================================
--- chrome/browser/task_manager/task_manager_browsertest.cc (revision 95777)
+++ chrome/browser/task_manager/task_manager_browsertest.cc (working copy)
@@ -18,7 +18,6 @@
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/tab_contents/confirm_infobar_delegate.h"
#include "chrome/browser/tabs/tab_strip_model.h"
-#include "chrome/browser/task_manager/task_manager_browsertest_util.h"
#include "chrome/browser/ui/browser.h"
#include "chrome/browser/ui/browser_navigator.h"
#include "chrome/browser/ui/browser_window.h"
@@ -47,6 +46,58 @@
const FilePath::CharType* kTitle1File = FILE_PATH_LITERAL("title1.html");
+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_;
+};
+
+// Helper class used to wait for a BackgroundContents to finish loading.
+class BackgroundContentsListener : public NotificationObserver {
+ public:
+ explicit BackgroundContentsListener(Profile* profile) {
+ registrar_.Add(this, chrome::NOTIFICATION_BACKGROUND_CONTENTS_NAVIGATED,
+ Source<Profile>(profile));
+ }
+ virtual void Observe(int type,
+ const NotificationSource& source,
+ const NotificationDetails& details) {
+ // Quit once the BackgroundContents has been loaded.
+ if (type == chrome::NOTIFICATION_BACKGROUND_CONTENTS_NAVIGATED)
+ MessageLoopForUI::current()->Quit();
+ }
+ private:
+ NotificationRegistrar registrar_;
+};
+
} // namespace
class TaskManagerBrowserTest : public ExtensionBrowserTest {
@@ -54,6 +105,21 @@
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);
+ }
+
+ // Wait for any pending BackgroundContents to finish starting up.
+ void WaitForBackgroundContents() {
+ BackgroundContentsListener listener(browser()->profile());
+ ui_test_utils::RunMessageLoop();
+ }
};
// Regression test for http://crbug.com/13361
@@ -69,13 +135,13 @@
browser()->window()->ShowTaskManager();
// Browser and the New Tab Page.
- TaskManagerBrowserTestUtil::WaitForResourceChange(2);
+ WaitForResourceChange(2);
// Open a new tab and make sure we notice that.
GURL url(ui_test_utils::GetTestUrl(FilePath(FilePath::kCurrentDirectory),
FilePath(kTitle1File)));
AddTabAtIndex(0, url, PageTransition::TYPED);
- TaskManagerBrowserTestUtil::WaitForResourceChange(3);
+ WaitForResourceChange(3);
// Check that the third entry is a tab contents resource whose title starts
// starts with "Tab:".
@@ -88,7 +154,7 @@
TabContents* first_tab = browser()->GetTabContentsAt(0);
ASSERT_TRUE(first_tab);
browser()->CloseTabContents(first_tab);
- TaskManagerBrowserTestUtil::WaitForResourceChange(2);
+ WaitForResourceChange(2);
}
IN_PROC_BROWSER_TEST_F(TaskManagerBrowserTest, NoticeBGContentsChanges) {
@@ -100,7 +166,7 @@
browser()->window()->ShowTaskManager();
// Browser and the New Tab Page.
- TaskManagerBrowserTestUtil::WaitForResourceChange(2);
+ WaitForResourceChange(2);
// Open a new background contents and make sure we notice that.
GURL url(ui_test_utils::GetTestUrl(FilePath(FilePath::kCurrentDirectory),
@@ -113,12 +179,12 @@
url,
ASCIIToUTF16("background_page"),
application_id);
- TaskManagerBrowserTestUtil::WaitForResourceChange(3);
+ WaitForResourceChange(3);
EXPECT_EQ(1, TaskManager::GetBackgroundPageCount());
// Close the background contents and verify that we notice.
service->ShutdownAssociatedBackgroundContents(application_id);
- TaskManagerBrowserTestUtil::WaitForResourceChange(2);
+ WaitForResourceChange(2);
EXPECT_EQ(0, TaskManager::GetBackgroundPageCount());
}
@@ -131,16 +197,12 @@
browser()->window()->ShowTaskManager();
// Browser and the New Tab Page.
- TaskManagerBrowserTestUtil::WaitForResourceChange(2);
+ WaitForResourceChange(2);
// Open a new background contents and make sure we notice that.
GURL url(ui_test_utils::GetTestUrl(FilePath(FilePath::kCurrentDirectory),
FilePath(kTitle1File)));
- ui_test_utils::WindowedNotificationObserver observer(
- chrome::NOTIFICATION_BACKGROUND_CONTENTS_NAVIGATED,
- Source<Profile>(browser()->profile()));
-
BackgroundContentsService* service =
BackgroundContentsServiceFactory::GetForProfile(browser()->profile());
string16 application_id(ASCIIToUTF16("test_app_id"));
@@ -148,10 +210,8 @@
url,
ASCIIToUTF16("background_page"),
application_id);
-
// Wait for the background contents process to finish loading.
- observer.Wait();
-
+ WaitForBackgroundContents();
EXPECT_EQ(3, model()->ResourceCount());
EXPECT_EQ(1, TaskManager::GetBackgroundPageCount());
@@ -166,7 +226,7 @@
}
}
ASSERT_TRUE(found);
- TaskManagerBrowserTestUtil::WaitForResourceChange(2);
+ WaitForResourceChange(2);
EXPECT_EQ(0, TaskManager::GetBackgroundPageCount());
}
@@ -179,18 +239,18 @@
browser()->window()->ShowTaskManager();
// Browser and the New Tab Page.
- TaskManagerBrowserTestUtil::WaitForResourceChange(2);
+ WaitForResourceChange(2);
// Loading an extension with a background page should result in a new
// resource being created for it.
ASSERT_TRUE(LoadExtension(
test_data_dir_.AppendASCII("common").AppendASCII("background_page")));
- TaskManagerBrowserTestUtil::WaitForResourceChange(3);
+ WaitForResourceChange(3);
EXPECT_EQ(1, TaskManager::GetBackgroundPageCount());
// Unload extension to avoid crash on Windows (see http://crbug.com/31663).
UnloadExtension(last_loaded_extension_id_);
- TaskManagerBrowserTestUtil::WaitForResourceChange(2);
+ WaitForResourceChange(2);
EXPECT_EQ(0, TaskManager::GetBackgroundPageCount());
}
@@ -205,12 +265,12 @@
.AppendASCII("1.0.0.0")));
// Browser, Extension background page, and the New Tab Page.
- TaskManagerBrowserTestUtil::WaitForResourceChange(3);
+ WaitForResourceChange(3);
// Open a new tab to an extension URL and make sure we notice that.
GURL url("chrome-extension://behllobkkfkfnphdnhnkndlbkcpglgmj/page.html");
AddTabAtIndex(0, url, PageTransition::TYPED);
- TaskManagerBrowserTestUtil::WaitForResourceChange(4);
+ WaitForResourceChange(4);
// Check that the third entry (background) is an extension resource whose
// title starts with "Extension:".
@@ -230,7 +290,7 @@
// Unload extension to avoid crash on Windows.
UnloadExtension(last_loaded_extension_id_);
- TaskManagerBrowserTestUtil::WaitForResourceChange(2);
+ WaitForResourceChange(2);
}
IN_PROC_BROWSER_TEST_F(TaskManagerBrowserTest, NoticeAppTabs) {
@@ -245,12 +305,12 @@
service->GetExtensionById(last_loaded_extension_id_, false);
// Browser and the New Tab Page.
- TaskManagerBrowserTestUtil::WaitForResourceChange(2);
+ WaitForResourceChange(2);
// Open a new tab to the app's launch URL and make sure we notice that.
GURL url(extension->GetResourceURL("main.html"));
AddTabAtIndex(0, url, PageTransition::TYPED);
- TaskManagerBrowserTestUtil::WaitForResourceChange(3);
+ WaitForResourceChange(3);
// Check that the third entry (main.html) is of type extension and has both
// a tab contents and an extension. The title should start with "App:".
@@ -263,7 +323,7 @@
// Unload extension to avoid crash on Windows.
UnloadExtension(last_loaded_extension_id_);
- TaskManagerBrowserTestUtil::WaitForResourceChange(2);
+ WaitForResourceChange(2);
}
IN_PROC_BROWSER_TEST_F(TaskManagerBrowserTest, NoticeHostedAppTabs) {
@@ -272,7 +332,7 @@
browser()->window()->ShowTaskManager();
// Browser and the New Tab Page.
- TaskManagerBrowserTestUtil::WaitForResourceChange(2);
+ WaitForResourceChange(2);
// The app under test acts on URLs whose host is "localhost",
// so the URLs we navigate to must have host "localhost".
@@ -327,7 +387,7 @@
// Wait until we see the loaded extension in the task manager (the three
// resources are: the browser process, New Tab Page, and the extension).
- TaskManagerBrowserTestUtil::WaitForResourceChange(3);
+ WaitForResourceChange(3);
EXPECT_EQ(1, TaskManager::GetBackgroundPageCount());
EXPECT_TRUE(model()->GetResourceExtension(0) == NULL);
@@ -336,7 +396,7 @@
// Kill the extension process and make sure we notice it.
TaskManager::GetInstance()->KillProcess(2);
- TaskManagerBrowserTestUtil::WaitForResourceChange(2);
+ WaitForResourceChange(2);
EXPECT_EQ(0, TaskManager::GetBackgroundPageCount());
}
@@ -352,7 +412,7 @@
// Wait until we see the loaded extension in the task manager (the three
// resources are: the browser process, New Tab Page, and the extension).
- TaskManagerBrowserTestUtil::WaitForResourceChange(3);
+ WaitForResourceChange(3);
EXPECT_TRUE(model()->GetResourceExtension(0) == NULL);
EXPECT_TRUE(model()->GetResourceExtension(1) == NULL);
@@ -360,7 +420,7 @@
// Kill the extension process and make sure we notice it.
TaskManager::GetInstance()->KillProcess(2);
- TaskManagerBrowserTestUtil::WaitForResourceChange(2);
+ WaitForResourceChange(2);
// Reload the extension using the "crashed extension" infobar while the task
// manager is still visible. Make sure we don't crash and the extension
@@ -371,7 +431,7 @@
current_tab->GetInfoBarDelegateAt(0)->AsConfirmInfoBarDelegate();
ASSERT_TRUE(delegate);
delegate->Accept();
- TaskManagerBrowserTestUtil::WaitForResourceChange(3);
+ WaitForResourceChange(3);
}
// Regression test for http://crbug.com/18693.
@@ -389,7 +449,7 @@
// Wait until we see the loaded extension in the task manager (the three
// resources are: the browser process, New Tab Page, and the extension).
LOG(INFO) << "waiting for resource change";
- TaskManagerBrowserTestUtil::WaitForResourceChange(3);
+ WaitForResourceChange(3);
EXPECT_TRUE(model()->GetResourceExtension(0) == NULL);
EXPECT_TRUE(model()->GetResourceExtension(1) == NULL);
@@ -402,19 +462,19 @@
// doesn't increase.
LOG(INFO) << "First extension reload";
ReloadExtension(extension->id());
- TaskManagerBrowserTestUtil::WaitForResourceChange(3);
+ WaitForResourceChange(3);
extension = model()->GetResourceExtension(2);
ASSERT_TRUE(extension != NULL);
LOG(INFO) << "Second extension reload";
ReloadExtension(extension->id());
- TaskManagerBrowserTestUtil::WaitForResourceChange(3);
+ WaitForResourceChange(3);
extension = model()->GetResourceExtension(2);
ASSERT_TRUE(extension != NULL);
LOG(INFO) << "Third extension reload";
ReloadExtension(extension->id());
- TaskManagerBrowserTestUtil::WaitForResourceChange(3);
+ WaitForResourceChange(3);
}
// Crashy, http://crbug.com/42301.
@@ -427,13 +487,13 @@
browser()->window()->ShowTaskManager();
// Browser and the New Tab Page.
- TaskManagerBrowserTestUtil::WaitForResourceChange(2);
+ WaitForResourceChange(2);
// Open a new tab and make sure we notice that.
GURL url(ui_test_utils::GetTestUrl(FilePath(FilePath::kCurrentDirectory),
FilePath(kTitle1File)));
AddTabAtIndex(0, url, PageTransition::TYPED);
- TaskManagerBrowserTestUtil::WaitForResourceChange(3);
+ WaitForResourceChange(3);
// Check that we get some value for the cache columns.
DCHECK_NE(model()->GetResourceWebCoreImageCacheSize(2),
« no previous file with comments | « chrome/browser/prerender/prerender_browsertest.cc ('k') | chrome/browser/task_manager/task_manager_browsertest_util.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698