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

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

Issue 6226002: Blow away BackgroundContents when RenderView goes away. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/chrome
Patch Set: Removed queueing code in unit test Created 9 years, 11 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
« no previous file with comments | « chrome/browser/tab_contents/background_contents.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 b17132f14a1bdeff1d6c9b9d4153124a9a317f92..66c6ca3877f6b02186f36ead424c6f33a7793c41 100644
--- a/chrome/browser/task_manager/task_manager_browsertest.cc
+++ b/chrome/browser/task_manager/task_manager_browsertest.cc
@@ -68,6 +68,24 @@ class ResourceChangeObserver : public TaskManagerModelObserver {
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, NotificationType::BACKGROUND_CONTENTS_NAVIGATED,
+ Source<Profile>(profile));
+ }
+ virtual void Observe(NotificationType type,
+ const NotificationSource& source,
+ const NotificationDetails& details) {
+ // Quit once the BackgroundContents has been loaded.
+ if (type.value == NotificationType::BACKGROUND_CONTENTS_NAVIGATED)
+ MessageLoopForUI::current()->Quit();
+ }
+ private:
+ NotificationRegistrar registrar_;
+};
+
} // namespace
class TaskManagerBrowserTest : public ExtensionBrowserTest {
@@ -84,6 +102,12 @@ class TaskManagerBrowserTest : public ExtensionBrowserTest {
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
@@ -149,6 +173,45 @@ IN_PROC_BROWSER_TEST_F(TaskManagerBrowserTest, NoticeBGContentsChanges) {
WaitForResourceChange(2);
}
+IN_PROC_BROWSER_TEST_F(TaskManagerBrowserTest, KillBGContents) {
+ EXPECT_EQ(0, model()->ResourceCount());
+
+ // Show the task manager. This populates the model, and helps with debugging
+ // (you see the task manager).
+ browser()->window()->ShowTaskManager();
+
+ // Browser and the New Tab Page.
+ WaitForResourceChange(2);
+
+ // Open a new background contents and make sure we notice that.
+ GURL url(ui_test_utils::GetTestUrl(FilePath(FilePath::kCurrentDirectory),
+ FilePath(kTitle1File)));
+
+ BackgroundContentsService* service =
+ browser()->profile()->GetBackgroundContentsService();
+ string16 application_id(ASCIIToUTF16("test_app_id"));
+ service->LoadBackgroundContents(browser()->profile(),
+ url,
+ ASCIIToUTF16("background_page"),
+ application_id);
+ // Wait for the background contents process to finish loading.
+ WaitForBackgroundContents();
+ EXPECT_EQ(3, model()->ResourceCount());
+
+ // Kill the background contents process and verify that it disappears from the
+ // model.
+ bool found = false;
+ for (int i = 0; i < model()->ResourceCount(); ++i) {
+ if (model()->IsBackgroundResource(i)) {
+ TaskManager::GetInstance()->KillProcess(i);
+ found = true;
+ break;
+ }
+ }
+ ASSERT_TRUE(found);
+ WaitForResourceChange(2);
+}
+
IN_PROC_BROWSER_TEST_F(TaskManagerBrowserTest, NoticeExtensionChanges) {
EXPECT_EQ(0, model()->ResourceCount());
« no previous file with comments | « chrome/browser/tab_contents/background_contents.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698