| Index: chrome/browser/task_manager/task_manager_browsertest.cc
|
| diff --git a/chrome/browser/task_manager/task_manager_browsertest.cc b/chrome/browser/task_manager/task_manager_browsertest.cc
|
| index cd3b1570214477cdd8db22d529eb988281c11414..ee0e8fc6c77a349df68a0835abbb126d4db6b443 100644
|
| --- a/chrome/browser/task_manager/task_manager_browsertest.cc
|
| +++ b/chrome/browser/task_manager/task_manager_browsertest.cc
|
| @@ -18,6 +18,7 @@
|
| #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"
|
| @@ -46,58 +47,6 @@ namespace {
|
|
|
| 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 {
|
| @@ -105,21 +54,6 @@ class TaskManagerBrowserTest : public ExtensionBrowserTest {
|
| 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
|
| @@ -135,13 +69,13 @@ IN_PROC_BROWSER_TEST_F(TaskManagerBrowserTest, NoticeTabContentsChanges) {
|
| browser()->window()->ShowTaskManager();
|
|
|
| // Browser and the New Tab Page.
|
| - WaitForResourceChange(2);
|
| + TaskManagerBrowserTestUtil::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);
|
| - WaitForResourceChange(3);
|
| + TaskManagerBrowserTestUtil::WaitForResourceChange(3);
|
|
|
| // Check that the third entry is a tab contents resource whose title starts
|
| // starts with "Tab:".
|
| @@ -154,7 +88,7 @@ IN_PROC_BROWSER_TEST_F(TaskManagerBrowserTest, NoticeTabContentsChanges) {
|
| TabContents* first_tab = browser()->GetTabContentsAt(0);
|
| ASSERT_TRUE(first_tab);
|
| browser()->CloseTabContents(first_tab);
|
| - WaitForResourceChange(2);
|
| + TaskManagerBrowserTestUtil::WaitForResourceChange(2);
|
| }
|
|
|
| IN_PROC_BROWSER_TEST_F(TaskManagerBrowserTest, NoticeBGContentsChanges) {
|
| @@ -166,7 +100,7 @@ IN_PROC_BROWSER_TEST_F(TaskManagerBrowserTest, NoticeBGContentsChanges) {
|
| browser()->window()->ShowTaskManager();
|
|
|
| // Browser and the New Tab Page.
|
| - WaitForResourceChange(2);
|
| + TaskManagerBrowserTestUtil::WaitForResourceChange(2);
|
|
|
| // Open a new background contents and make sure we notice that.
|
| GURL url(ui_test_utils::GetTestUrl(FilePath(FilePath::kCurrentDirectory),
|
| @@ -179,12 +113,12 @@ IN_PROC_BROWSER_TEST_F(TaskManagerBrowserTest, NoticeBGContentsChanges) {
|
| url,
|
| ASCIIToUTF16("background_page"),
|
| application_id);
|
| - WaitForResourceChange(3);
|
| + TaskManagerBrowserTestUtil::WaitForResourceChange(3);
|
| EXPECT_EQ(1, TaskManager::GetBackgroundPageCount());
|
|
|
| // Close the background contents and verify that we notice.
|
| service->ShutdownAssociatedBackgroundContents(application_id);
|
| - WaitForResourceChange(2);
|
| + TaskManagerBrowserTestUtil::WaitForResourceChange(2);
|
| EXPECT_EQ(0, TaskManager::GetBackgroundPageCount());
|
| }
|
|
|
| @@ -197,12 +131,16 @@ IN_PROC_BROWSER_TEST_F(TaskManagerBrowserTest, KillBGContents) {
|
| browser()->window()->ShowTaskManager();
|
|
|
| // Browser and the New Tab Page.
|
| - WaitForResourceChange(2);
|
| + TaskManagerBrowserTestUtil::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"));
|
| @@ -210,8 +148,10 @@ IN_PROC_BROWSER_TEST_F(TaskManagerBrowserTest, KillBGContents) {
|
| url,
|
| ASCIIToUTF16("background_page"),
|
| application_id);
|
| +
|
| // Wait for the background contents process to finish loading.
|
| - WaitForBackgroundContents();
|
| + observer.Wait();
|
| +
|
| EXPECT_EQ(3, model()->ResourceCount());
|
| EXPECT_EQ(1, TaskManager::GetBackgroundPageCount());
|
|
|
| @@ -226,7 +166,7 @@ IN_PROC_BROWSER_TEST_F(TaskManagerBrowserTest, KillBGContents) {
|
| }
|
| }
|
| ASSERT_TRUE(found);
|
| - WaitForResourceChange(2);
|
| + TaskManagerBrowserTestUtil::WaitForResourceChange(2);
|
| EXPECT_EQ(0, TaskManager::GetBackgroundPageCount());
|
| }
|
|
|
| @@ -239,18 +179,18 @@ IN_PROC_BROWSER_TEST_F(TaskManagerBrowserTest, NoticeExtensionChanges) {
|
| browser()->window()->ShowTaskManager();
|
|
|
| // Browser and the New Tab Page.
|
| - WaitForResourceChange(2);
|
| + TaskManagerBrowserTestUtil::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")));
|
| - WaitForResourceChange(3);
|
| + TaskManagerBrowserTestUtil::WaitForResourceChange(3);
|
| EXPECT_EQ(1, TaskManager::GetBackgroundPageCount());
|
|
|
| // Unload extension to avoid crash on Windows (see http://crbug.com/31663).
|
| UnloadExtension(last_loaded_extension_id_);
|
| - WaitForResourceChange(2);
|
| + TaskManagerBrowserTestUtil::WaitForResourceChange(2);
|
| EXPECT_EQ(0, TaskManager::GetBackgroundPageCount());
|
| }
|
|
|
| @@ -265,12 +205,12 @@ IN_PROC_BROWSER_TEST_F(TaskManagerBrowserTest, NoticeExtensionTabs) {
|
| .AppendASCII("1.0.0.0")));
|
|
|
| // Browser, Extension background page, and the New Tab Page.
|
| - WaitForResourceChange(3);
|
| + TaskManagerBrowserTestUtil::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);
|
| - WaitForResourceChange(4);
|
| + TaskManagerBrowserTestUtil::WaitForResourceChange(4);
|
|
|
| // Check that the third entry (background) is an extension resource whose
|
| // title starts with "Extension:".
|
| @@ -290,7 +230,7 @@ IN_PROC_BROWSER_TEST_F(TaskManagerBrowserTest, NoticeExtensionTabs) {
|
|
|
| // Unload extension to avoid crash on Windows.
|
| UnloadExtension(last_loaded_extension_id_);
|
| - WaitForResourceChange(2);
|
| + TaskManagerBrowserTestUtil::WaitForResourceChange(2);
|
| }
|
|
|
| IN_PROC_BROWSER_TEST_F(TaskManagerBrowserTest, NoticeAppTabs) {
|
| @@ -305,12 +245,12 @@ IN_PROC_BROWSER_TEST_F(TaskManagerBrowserTest, NoticeAppTabs) {
|
| service->GetExtensionById(last_loaded_extension_id_, false);
|
|
|
| // Browser and the New Tab Page.
|
| - WaitForResourceChange(2);
|
| + TaskManagerBrowserTestUtil::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);
|
| - WaitForResourceChange(3);
|
| + TaskManagerBrowserTestUtil::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:".
|
| @@ -323,7 +263,7 @@ IN_PROC_BROWSER_TEST_F(TaskManagerBrowserTest, NoticeAppTabs) {
|
|
|
| // Unload extension to avoid crash on Windows.
|
| UnloadExtension(last_loaded_extension_id_);
|
| - WaitForResourceChange(2);
|
| + TaskManagerBrowserTestUtil::WaitForResourceChange(2);
|
| }
|
|
|
| IN_PROC_BROWSER_TEST_F(TaskManagerBrowserTest, NoticeHostedAppTabs) {
|
| @@ -332,7 +272,7 @@ IN_PROC_BROWSER_TEST_F(TaskManagerBrowserTest, NoticeHostedAppTabs) {
|
| browser()->window()->ShowTaskManager();
|
|
|
| // Browser and the New Tab Page.
|
| - WaitForResourceChange(2);
|
| + TaskManagerBrowserTestUtil::WaitForResourceChange(2);
|
|
|
| // The app under test acts on URLs whose host is "localhost",
|
| // so the URLs we navigate to must have host "localhost".
|
| @@ -387,7 +327,7 @@ IN_PROC_BROWSER_TEST_F(TaskManagerBrowserTest, MAYBE_KillExtension) {
|
|
|
| // Wait until we see the loaded extension in the task manager (the three
|
| // resources are: the browser process, New Tab Page, and the extension).
|
| - WaitForResourceChange(3);
|
| + TaskManagerBrowserTestUtil::WaitForResourceChange(3);
|
| EXPECT_EQ(1, TaskManager::GetBackgroundPageCount());
|
|
|
| EXPECT_TRUE(model()->GetResourceExtension(0) == NULL);
|
| @@ -396,7 +336,7 @@ IN_PROC_BROWSER_TEST_F(TaskManagerBrowserTest, MAYBE_KillExtension) {
|
|
|
| // Kill the extension process and make sure we notice it.
|
| TaskManager::GetInstance()->KillProcess(2);
|
| - WaitForResourceChange(2);
|
| + TaskManagerBrowserTestUtil::WaitForResourceChange(2);
|
| EXPECT_EQ(0, TaskManager::GetBackgroundPageCount());
|
| }
|
|
|
| @@ -412,7 +352,7 @@ IN_PROC_BROWSER_TEST_F(TaskManagerBrowserTest,
|
|
|
| // Wait until we see the loaded extension in the task manager (the three
|
| // resources are: the browser process, New Tab Page, and the extension).
|
| - WaitForResourceChange(3);
|
| + TaskManagerBrowserTestUtil::WaitForResourceChange(3);
|
|
|
| EXPECT_TRUE(model()->GetResourceExtension(0) == NULL);
|
| EXPECT_TRUE(model()->GetResourceExtension(1) == NULL);
|
| @@ -420,7 +360,7 @@ IN_PROC_BROWSER_TEST_F(TaskManagerBrowserTest,
|
|
|
| // Kill the extension process and make sure we notice it.
|
| TaskManager::GetInstance()->KillProcess(2);
|
| - WaitForResourceChange(2);
|
| + TaskManagerBrowserTestUtil::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
|
| @@ -431,7 +371,7 @@ IN_PROC_BROWSER_TEST_F(TaskManagerBrowserTest,
|
| current_tab->GetInfoBarDelegateAt(0)->AsConfirmInfoBarDelegate();
|
| ASSERT_TRUE(delegate);
|
| delegate->Accept();
|
| - WaitForResourceChange(3);
|
| + TaskManagerBrowserTestUtil::WaitForResourceChange(3);
|
| }
|
|
|
| // Regression test for http://crbug.com/18693.
|
| @@ -447,7 +387,7 @@ IN_PROC_BROWSER_TEST_F(TaskManagerBrowserTest, ReloadExtension) {
|
| // 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";
|
| - WaitForResourceChange(3);
|
| + TaskManagerBrowserTestUtil::WaitForResourceChange(3);
|
|
|
| EXPECT_TRUE(model()->GetResourceExtension(0) == NULL);
|
| EXPECT_TRUE(model()->GetResourceExtension(1) == NULL);
|
| @@ -460,19 +400,19 @@ IN_PROC_BROWSER_TEST_F(TaskManagerBrowserTest, ReloadExtension) {
|
| // doesn't increase.
|
| LOG(INFO) << "First extension reload";
|
| ReloadExtension(extension->id());
|
| - WaitForResourceChange(3);
|
| + TaskManagerBrowserTestUtil::WaitForResourceChange(3);
|
| extension = model()->GetResourceExtension(2);
|
| ASSERT_TRUE(extension != NULL);
|
|
|
| LOG(INFO) << "Second extension reload";
|
| ReloadExtension(extension->id());
|
| - WaitForResourceChange(3);
|
| + TaskManagerBrowserTestUtil::WaitForResourceChange(3);
|
| extension = model()->GetResourceExtension(2);
|
| ASSERT_TRUE(extension != NULL);
|
|
|
| LOG(INFO) << "Third extension reload";
|
| ReloadExtension(extension->id());
|
| - WaitForResourceChange(3);
|
| + TaskManagerBrowserTestUtil::WaitForResourceChange(3);
|
| }
|
|
|
| // Crashy, http://crbug.com/42301.
|
| @@ -485,13 +425,13 @@ IN_PROC_BROWSER_TEST_F(TaskManagerBrowserTest,
|
| browser()->window()->ShowTaskManager();
|
|
|
| // Browser and the New Tab Page.
|
| - WaitForResourceChange(2);
|
| + TaskManagerBrowserTestUtil::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);
|
| - WaitForResourceChange(3);
|
| + TaskManagerBrowserTestUtil::WaitForResourceChange(3);
|
|
|
| // Check that we get some value for the cache columns.
|
| DCHECK_NE(model()->GetResourceWebCoreImageCacheSize(2),
|
|
|