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

Side by Side 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « chrome/browser/tab_contents/background_contents.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/browser/task_manager/task_manager.h" 5 #include "chrome/browser/task_manager/task_manager.h"
6 6
7 #include "app/l10n_util.h" 7 #include "app/l10n_util.h"
8 #include "base/file_path.h" 8 #include "base/file_path.h"
9 #include "base/utf_string_conversions.h" 9 #include "base/utf_string_conversions.h"
10 #include "chrome/browser/background_contents_service.h" 10 #include "chrome/browser/background_contents_service.h"
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
61 private: 61 private:
62 void OnResourceChange() { 62 void OnResourceChange() {
63 if (model_->ResourceCount() == target_resource_count_) 63 if (model_->ResourceCount() == target_resource_count_)
64 MessageLoopForUI::current()->Quit(); 64 MessageLoopForUI::current()->Quit();
65 } 65 }
66 66
67 const TaskManagerModel* model_; 67 const TaskManagerModel* model_;
68 const int target_resource_count_; 68 const int target_resource_count_;
69 }; 69 };
70 70
71 // Helper class used to wait for a BackgroundContents to finish loading.
72 class BackgroundContentsListener : public NotificationObserver {
73 public:
74 explicit BackgroundContentsListener(Profile* profile) {
75 registrar_.Add(this, NotificationType::BACKGROUND_CONTENTS_NAVIGATED,
76 Source<Profile>(profile));
77 }
78 virtual void Observe(NotificationType type,
79 const NotificationSource& source,
80 const NotificationDetails& details) {
81 // Quit once the BackgroundContents has been loaded.
82 if (type.value == NotificationType::BACKGROUND_CONTENTS_NAVIGATED)
83 MessageLoopForUI::current()->Quit();
84 }
85 private:
86 NotificationRegistrar registrar_;
87 };
88
71 } // namespace 89 } // namespace
72 90
73 class TaskManagerBrowserTest : public ExtensionBrowserTest { 91 class TaskManagerBrowserTest : public ExtensionBrowserTest {
74 public: 92 public:
75 TaskManagerModel* model() const { 93 TaskManagerModel* model() const {
76 return TaskManager::GetInstance()->model(); 94 return TaskManager::GetInstance()->model();
77 } 95 }
78 96
79 void WaitForResourceChange(int target_count) { 97 void WaitForResourceChange(int target_count) {
80 if (model()->ResourceCount() == target_count) 98 if (model()->ResourceCount() == target_count)
81 return; 99 return;
82 ResourceChangeObserver observer(model(), target_count); 100 ResourceChangeObserver observer(model(), target_count);
83 model()->AddObserver(&observer); 101 model()->AddObserver(&observer);
84 ui_test_utils::RunMessageLoop(); 102 ui_test_utils::RunMessageLoop();
85 model()->RemoveObserver(&observer); 103 model()->RemoveObserver(&observer);
86 } 104 }
105
106 // Wait for any pending BackgroundContents to finish starting up.
107 void WaitForBackgroundContents() {
108 BackgroundContentsListener listener(browser()->profile());
109 ui_test_utils::RunMessageLoop();
110 }
87 }; 111 };
88 112
89 // Regression test for http://crbug.com/13361 113 // Regression test for http://crbug.com/13361
90 IN_PROC_BROWSER_TEST_F(TaskManagerBrowserTest, ShutdownWhileOpen) { 114 IN_PROC_BROWSER_TEST_F(TaskManagerBrowserTest, ShutdownWhileOpen) {
91 browser()->window()->ShowTaskManager(); 115 browser()->window()->ShowTaskManager();
92 } 116 }
93 117
94 IN_PROC_BROWSER_TEST_F(TaskManagerBrowserTest, NoticeTabContentsChanges) { 118 IN_PROC_BROWSER_TEST_F(TaskManagerBrowserTest, NoticeTabContentsChanges) {
95 EXPECT_EQ(0, model()->ResourceCount()); 119 EXPECT_EQ(0, model()->ResourceCount());
96 120
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
142 url, 166 url,
143 ASCIIToUTF16("background_page"), 167 ASCIIToUTF16("background_page"),
144 application_id); 168 application_id);
145 WaitForResourceChange(3); 169 WaitForResourceChange(3);
146 170
147 // Close the background contents and verify that we notice. 171 // Close the background contents and verify that we notice.
148 service->ShutdownAssociatedBackgroundContents(application_id); 172 service->ShutdownAssociatedBackgroundContents(application_id);
149 WaitForResourceChange(2); 173 WaitForResourceChange(2);
150 } 174 }
151 175
176 IN_PROC_BROWSER_TEST_F(TaskManagerBrowserTest, KillBGContents) {
177 EXPECT_EQ(0, model()->ResourceCount());
178
179 // Show the task manager. This populates the model, and helps with debugging
180 // (you see the task manager).
181 browser()->window()->ShowTaskManager();
182
183 // Browser and the New Tab Page.
184 WaitForResourceChange(2);
185
186 // Open a new background contents and make sure we notice that.
187 GURL url(ui_test_utils::GetTestUrl(FilePath(FilePath::kCurrentDirectory),
188 FilePath(kTitle1File)));
189
190 BackgroundContentsService* service =
191 browser()->profile()->GetBackgroundContentsService();
192 string16 application_id(ASCIIToUTF16("test_app_id"));
193 service->LoadBackgroundContents(browser()->profile(),
194 url,
195 ASCIIToUTF16("background_page"),
196 application_id);
197 // Wait for the background contents process to finish loading.
198 WaitForBackgroundContents();
199 EXPECT_EQ(3, model()->ResourceCount());
200
201 // Kill the background contents process and verify that it disappears from the
202 // model.
203 bool found = false;
204 for (int i = 0; i < model()->ResourceCount(); ++i) {
205 if (model()->IsBackgroundResource(i)) {
206 TaskManager::GetInstance()->KillProcess(i);
207 found = true;
208 break;
209 }
210 }
211 ASSERT_TRUE(found);
212 WaitForResourceChange(2);
213 }
214
152 IN_PROC_BROWSER_TEST_F(TaskManagerBrowserTest, NoticeExtensionChanges) { 215 IN_PROC_BROWSER_TEST_F(TaskManagerBrowserTest, NoticeExtensionChanges) {
153 EXPECT_EQ(0, model()->ResourceCount()); 216 EXPECT_EQ(0, model()->ResourceCount());
154 217
155 // Show the task manager. This populates the model, and helps with debugging 218 // Show the task manager. This populates the model, and helps with debugging
156 // (you see the task manager). 219 // (you see the task manager).
157 browser()->window()->ShowTaskManager(); 220 browser()->window()->ShowTaskManager();
158 221
159 // Browser and the New Tab Page. 222 // Browser and the New Tab Page.
160 WaitForResourceChange(2); 223 WaitForResourceChange(2);
161 224
(...skipping 231 matching lines...) Expand 10 before | Expand all | Expand 10 after
393 WaitForResourceChange(3); 456 WaitForResourceChange(3);
394 457
395 // Check that we get some value for the cache columns. 458 // Check that we get some value for the cache columns.
396 DCHECK_NE(model()->GetResourceWebCoreImageCacheSize(2), 459 DCHECK_NE(model()->GetResourceWebCoreImageCacheSize(2),
397 l10n_util::GetStringUTF16(IDS_TASK_MANAGER_NA_CELL_TEXT)); 460 l10n_util::GetStringUTF16(IDS_TASK_MANAGER_NA_CELL_TEXT));
398 DCHECK_NE(model()->GetResourceWebCoreScriptsCacheSize(2), 461 DCHECK_NE(model()->GetResourceWebCoreScriptsCacheSize(2),
399 l10n_util::GetStringUTF16(IDS_TASK_MANAGER_NA_CELL_TEXT)); 462 l10n_util::GetStringUTF16(IDS_TASK_MANAGER_NA_CELL_TEXT));
400 DCHECK_NE(model()->GetResourceWebCoreCSSCacheSize(2), 463 DCHECK_NE(model()->GetResourceWebCoreCSSCacheSize(2),
401 l10n_util::GetStringUTF16(IDS_TASK_MANAGER_NA_CELL_TEXT)); 464 l10n_util::GetStringUTF16(IDS_TASK_MANAGER_NA_CELL_TEXT));
402 } 465 }
OLDNEW
« 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