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

Side by Side 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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 "base/file_path.h" 7 #include "base/file_path.h"
8 #include "base/utf_string_conversions.h" 8 #include "base/utf_string_conversions.h"
9 #include "chrome/browser/background/background_contents_service.h" 9 #include "chrome/browser/background/background_contents_service.h"
10 #include "chrome/browser/background/background_contents_service_factory.h" 10 #include "chrome/browser/background/background_contents_service_factory.h"
11 #include "chrome/browser/browser_process.h" 11 #include "chrome/browser/browser_process.h"
12 #include "chrome/browser/extensions/extension_browsertest.h" 12 #include "chrome/browser/extensions/extension_browsertest.h"
13 #include "chrome/browser/extensions/extension_service.h" 13 #include "chrome/browser/extensions/extension_service.h"
14 #include "chrome/browser/notifications/desktop_notification_service.h" 14 #include "chrome/browser/notifications/desktop_notification_service.h"
15 #include "chrome/browser/notifications/notification.h" 15 #include "chrome/browser/notifications/notification.h"
16 #include "chrome/browser/notifications/notification_test_util.h" 16 #include "chrome/browser/notifications/notification_test_util.h"
17 #include "chrome/browser/notifications/notification_ui_manager.h" 17 #include "chrome/browser/notifications/notification_ui_manager.h"
18 #include "chrome/browser/profiles/profile.h" 18 #include "chrome/browser/profiles/profile.h"
19 #include "chrome/browser/tab_contents/confirm_infobar_delegate.h" 19 #include "chrome/browser/tab_contents/confirm_infobar_delegate.h"
20 #include "chrome/browser/tabs/tab_strip_model.h" 20 #include "chrome/browser/tabs/tab_strip_model.h"
21 #include "chrome/browser/task_manager/task_manager_browsertest_util.h"
22 #include "chrome/browser/ui/browser.h" 21 #include "chrome/browser/ui/browser.h"
23 #include "chrome/browser/ui/browser_navigator.h" 22 #include "chrome/browser/ui/browser_navigator.h"
24 #include "chrome/browser/ui/browser_window.h" 23 #include "chrome/browser/ui/browser_window.h"
25 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" 24 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h"
26 #include "chrome/common/chrome_notification_types.h" 25 #include "chrome/common/chrome_notification_types.h"
27 #include "chrome/common/extensions/extension.h" 26 #include "chrome/common/extensions/extension.h"
28 #include "chrome/test/in_process_browser_test.h" 27 #include "chrome/test/in_process_browser_test.h"
29 #include "chrome/test/ui_test_utils.h" 28 #include "chrome/test/ui_test_utils.h"
30 #include "content/common/page_transition_types.h" 29 #include "content/common/page_transition_types.h"
31 #include "grit/generated_resources.h" 30 #include "grit/generated_resources.h"
32 #include "net/base/mock_host_resolver.h" 31 #include "net/base/mock_host_resolver.h"
33 #include "testing/gtest/include/gtest/gtest.h" 32 #include "testing/gtest/include/gtest/gtest.h"
34 #include "ui/base/l10n/l10n_util.h" 33 #include "ui/base/l10n/l10n_util.h"
35 34
36 // On Linux this is crashing intermittently http://crbug/84719 35 // On Linux this is crashing intermittently http://crbug/84719
37 // In some environments this test fails about 1/6 http://crbug/84850 36 // In some environments this test fails about 1/6 http://crbug/84850
38 #if defined(OS_LINUX) 37 #if defined(OS_LINUX)
39 #define MAYBE_KillExtension DISABLED_KillExtension 38 #define MAYBE_KillExtension DISABLED_KillExtension
40 #elif defined(TOUCH_UI) 39 #elif defined(TOUCH_UI)
41 #define MAYBE_KillExtension FLAKY_KillExtension 40 #define MAYBE_KillExtension FLAKY_KillExtension
42 #else 41 #else
43 #define MAYBE_KillExtension KillExtension 42 #define MAYBE_KillExtension KillExtension
44 #endif 43 #endif
45 44
46 namespace { 45 namespace {
47 46
48 const FilePath::CharType* kTitle1File = FILE_PATH_LITERAL("title1.html"); 47 const FilePath::CharType* kTitle1File = FILE_PATH_LITERAL("title1.html");
49 48
49 class ResourceChangeObserver : public TaskManagerModelObserver {
50 public:
51 ResourceChangeObserver(const TaskManagerModel* model,
52 int target_resource_count)
53 : model_(model),
54 target_resource_count_(target_resource_count) {
55 }
56
57 virtual void OnModelChanged() {
58 OnResourceChange();
59 }
60
61 virtual void OnItemsChanged(int start, int length) {
62 OnResourceChange();
63 }
64
65 virtual void OnItemsAdded(int start, int length) {
66 OnResourceChange();
67 }
68
69 virtual void OnItemsRemoved(int start, int length) {
70 OnResourceChange();
71 }
72
73 private:
74 void OnResourceChange() {
75 if (model_->ResourceCount() == target_resource_count_)
76 MessageLoopForUI::current()->Quit();
77 }
78
79 const TaskManagerModel* model_;
80 const int target_resource_count_;
81 };
82
83 // Helper class used to wait for a BackgroundContents to finish loading.
84 class BackgroundContentsListener : public NotificationObserver {
85 public:
86 explicit BackgroundContentsListener(Profile* profile) {
87 registrar_.Add(this, chrome::NOTIFICATION_BACKGROUND_CONTENTS_NAVIGATED,
88 Source<Profile>(profile));
89 }
90 virtual void Observe(int type,
91 const NotificationSource& source,
92 const NotificationDetails& details) {
93 // Quit once the BackgroundContents has been loaded.
94 if (type == chrome::NOTIFICATION_BACKGROUND_CONTENTS_NAVIGATED)
95 MessageLoopForUI::current()->Quit();
96 }
97 private:
98 NotificationRegistrar registrar_;
99 };
100
50 } // namespace 101 } // namespace
51 102
52 class TaskManagerBrowserTest : public ExtensionBrowserTest { 103 class TaskManagerBrowserTest : public ExtensionBrowserTest {
53 public: 104 public:
54 TaskManagerModel* model() const { 105 TaskManagerModel* model() const {
55 return TaskManager::GetInstance()->model(); 106 return TaskManager::GetInstance()->model();
56 } 107 }
108
109 void WaitForResourceChange(int target_count) {
110 if (model()->ResourceCount() == target_count)
111 return;
112 ResourceChangeObserver observer(model(), target_count);
113 model()->AddObserver(&observer);
114 ui_test_utils::RunMessageLoop();
115 model()->RemoveObserver(&observer);
116 }
117
118 // Wait for any pending BackgroundContents to finish starting up.
119 void WaitForBackgroundContents() {
120 BackgroundContentsListener listener(browser()->profile());
121 ui_test_utils::RunMessageLoop();
122 }
57 }; 123 };
58 124
59 // Regression test for http://crbug.com/13361 125 // Regression test for http://crbug.com/13361
60 IN_PROC_BROWSER_TEST_F(TaskManagerBrowserTest, ShutdownWhileOpen) { 126 IN_PROC_BROWSER_TEST_F(TaskManagerBrowserTest, ShutdownWhileOpen) {
61 browser()->window()->ShowTaskManager(); 127 browser()->window()->ShowTaskManager();
62 } 128 }
63 129
64 IN_PROC_BROWSER_TEST_F(TaskManagerBrowserTest, NoticeTabContentsChanges) { 130 IN_PROC_BROWSER_TEST_F(TaskManagerBrowserTest, NoticeTabContentsChanges) {
65 EXPECT_EQ(0, model()->ResourceCount()); 131 EXPECT_EQ(0, model()->ResourceCount());
66 132
67 // Show the task manager. This populates the model, and helps with debugging 133 // Show the task manager. This populates the model, and helps with debugging
68 // (you see the task manager). 134 // (you see the task manager).
69 browser()->window()->ShowTaskManager(); 135 browser()->window()->ShowTaskManager();
70 136
71 // Browser and the New Tab Page. 137 // Browser and the New Tab Page.
72 TaskManagerBrowserTestUtil::WaitForResourceChange(2); 138 WaitForResourceChange(2);
73 139
74 // Open a new tab and make sure we notice that. 140 // Open a new tab and make sure we notice that.
75 GURL url(ui_test_utils::GetTestUrl(FilePath(FilePath::kCurrentDirectory), 141 GURL url(ui_test_utils::GetTestUrl(FilePath(FilePath::kCurrentDirectory),
76 FilePath(kTitle1File))); 142 FilePath(kTitle1File)));
77 AddTabAtIndex(0, url, PageTransition::TYPED); 143 AddTabAtIndex(0, url, PageTransition::TYPED);
78 TaskManagerBrowserTestUtil::WaitForResourceChange(3); 144 WaitForResourceChange(3);
79 145
80 // Check that the third entry is a tab contents resource whose title starts 146 // Check that the third entry is a tab contents resource whose title starts
81 // starts with "Tab:". 147 // starts with "Tab:".
82 ASSERT_TRUE(model()->GetResourceTabContents(2) != NULL); 148 ASSERT_TRUE(model()->GetResourceTabContents(2) != NULL);
83 string16 prefix = l10n_util::GetStringFUTF16( 149 string16 prefix = l10n_util::GetStringFUTF16(
84 IDS_TASK_MANAGER_TAB_PREFIX, string16()); 150 IDS_TASK_MANAGER_TAB_PREFIX, string16());
85 ASSERT_TRUE(StartsWith(model()->GetResourceTitle(2), prefix, true)); 151 ASSERT_TRUE(StartsWith(model()->GetResourceTitle(2), prefix, true));
86 152
87 // Close the tab and verify that we notice. 153 // Close the tab and verify that we notice.
88 TabContents* first_tab = browser()->GetTabContentsAt(0); 154 TabContents* first_tab = browser()->GetTabContentsAt(0);
89 ASSERT_TRUE(first_tab); 155 ASSERT_TRUE(first_tab);
90 browser()->CloseTabContents(first_tab); 156 browser()->CloseTabContents(first_tab);
91 TaskManagerBrowserTestUtil::WaitForResourceChange(2); 157 WaitForResourceChange(2);
92 } 158 }
93 159
94 IN_PROC_BROWSER_TEST_F(TaskManagerBrowserTest, NoticeBGContentsChanges) { 160 IN_PROC_BROWSER_TEST_F(TaskManagerBrowserTest, NoticeBGContentsChanges) {
95 EXPECT_EQ(0, model()->ResourceCount()); 161 EXPECT_EQ(0, model()->ResourceCount());
96 EXPECT_EQ(0, TaskManager::GetBackgroundPageCount()); 162 EXPECT_EQ(0, TaskManager::GetBackgroundPageCount());
97 163
98 // Show the task manager. This populates the model, and helps with debugging 164 // Show the task manager. This populates the model, and helps with debugging
99 // (you see the task manager). 165 // (you see the task manager).
100 browser()->window()->ShowTaskManager(); 166 browser()->window()->ShowTaskManager();
101 167
102 // Browser and the New Tab Page. 168 // Browser and the New Tab Page.
103 TaskManagerBrowserTestUtil::WaitForResourceChange(2); 169 WaitForResourceChange(2);
104 170
105 // Open a new background contents and make sure we notice that. 171 // Open a new background contents and make sure we notice that.
106 GURL url(ui_test_utils::GetTestUrl(FilePath(FilePath::kCurrentDirectory), 172 GURL url(ui_test_utils::GetTestUrl(FilePath(FilePath::kCurrentDirectory),
107 FilePath(kTitle1File))); 173 FilePath(kTitle1File)));
108 174
109 BackgroundContentsService* service = 175 BackgroundContentsService* service =
110 BackgroundContentsServiceFactory::GetForProfile(browser()->profile()); 176 BackgroundContentsServiceFactory::GetForProfile(browser()->profile());
111 string16 application_id(ASCIIToUTF16("test_app_id")); 177 string16 application_id(ASCIIToUTF16("test_app_id"));
112 service->LoadBackgroundContents(browser()->profile(), 178 service->LoadBackgroundContents(browser()->profile(),
113 url, 179 url,
114 ASCIIToUTF16("background_page"), 180 ASCIIToUTF16("background_page"),
115 application_id); 181 application_id);
116 TaskManagerBrowserTestUtil::WaitForResourceChange(3); 182 WaitForResourceChange(3);
117 EXPECT_EQ(1, TaskManager::GetBackgroundPageCount()); 183 EXPECT_EQ(1, TaskManager::GetBackgroundPageCount());
118 184
119 // Close the background contents and verify that we notice. 185 // Close the background contents and verify that we notice.
120 service->ShutdownAssociatedBackgroundContents(application_id); 186 service->ShutdownAssociatedBackgroundContents(application_id);
121 TaskManagerBrowserTestUtil::WaitForResourceChange(2); 187 WaitForResourceChange(2);
122 EXPECT_EQ(0, TaskManager::GetBackgroundPageCount()); 188 EXPECT_EQ(0, TaskManager::GetBackgroundPageCount());
123 } 189 }
124 190
125 IN_PROC_BROWSER_TEST_F(TaskManagerBrowserTest, KillBGContents) { 191 IN_PROC_BROWSER_TEST_F(TaskManagerBrowserTest, KillBGContents) {
126 EXPECT_EQ(0, model()->ResourceCount()); 192 EXPECT_EQ(0, model()->ResourceCount());
127 EXPECT_EQ(0, TaskManager::GetBackgroundPageCount()); 193 EXPECT_EQ(0, TaskManager::GetBackgroundPageCount());
128 194
129 // Show the task manager. This populates the model, and helps with debugging 195 // Show the task manager. This populates the model, and helps with debugging
130 // (you see the task manager). 196 // (you see the task manager).
131 browser()->window()->ShowTaskManager(); 197 browser()->window()->ShowTaskManager();
132 198
133 // Browser and the New Tab Page. 199 // Browser and the New Tab Page.
134 TaskManagerBrowserTestUtil::WaitForResourceChange(2); 200 WaitForResourceChange(2);
135 201
136 // Open a new background contents and make sure we notice that. 202 // Open a new background contents and make sure we notice that.
137 GURL url(ui_test_utils::GetTestUrl(FilePath(FilePath::kCurrentDirectory), 203 GURL url(ui_test_utils::GetTestUrl(FilePath(FilePath::kCurrentDirectory),
138 FilePath(kTitle1File))); 204 FilePath(kTitle1File)));
139 205
140 ui_test_utils::WindowedNotificationObserver observer(
141 chrome::NOTIFICATION_BACKGROUND_CONTENTS_NAVIGATED,
142 Source<Profile>(browser()->profile()));
143
144 BackgroundContentsService* service = 206 BackgroundContentsService* service =
145 BackgroundContentsServiceFactory::GetForProfile(browser()->profile()); 207 BackgroundContentsServiceFactory::GetForProfile(browser()->profile());
146 string16 application_id(ASCIIToUTF16("test_app_id")); 208 string16 application_id(ASCIIToUTF16("test_app_id"));
147 service->LoadBackgroundContents(browser()->profile(), 209 service->LoadBackgroundContents(browser()->profile(),
148 url, 210 url,
149 ASCIIToUTF16("background_page"), 211 ASCIIToUTF16("background_page"),
150 application_id); 212 application_id);
151
152 // Wait for the background contents process to finish loading. 213 // Wait for the background contents process to finish loading.
153 observer.Wait(); 214 WaitForBackgroundContents();
154
155 EXPECT_EQ(3, model()->ResourceCount()); 215 EXPECT_EQ(3, model()->ResourceCount());
156 EXPECT_EQ(1, TaskManager::GetBackgroundPageCount()); 216 EXPECT_EQ(1, TaskManager::GetBackgroundPageCount());
157 217
158 // Kill the background contents process and verify that it disappears from the 218 // Kill the background contents process and verify that it disappears from the
159 // model. 219 // model.
160 bool found = false; 220 bool found = false;
161 for (int i = 0; i < model()->ResourceCount(); ++i) { 221 for (int i = 0; i < model()->ResourceCount(); ++i) {
162 if (model()->IsBackgroundResource(i)) { 222 if (model()->IsBackgroundResource(i)) {
163 TaskManager::GetInstance()->KillProcess(i); 223 TaskManager::GetInstance()->KillProcess(i);
164 found = true; 224 found = true;
165 break; 225 break;
166 } 226 }
167 } 227 }
168 ASSERT_TRUE(found); 228 ASSERT_TRUE(found);
169 TaskManagerBrowserTestUtil::WaitForResourceChange(2); 229 WaitForResourceChange(2);
170 EXPECT_EQ(0, TaskManager::GetBackgroundPageCount()); 230 EXPECT_EQ(0, TaskManager::GetBackgroundPageCount());
171 } 231 }
172 232
173 IN_PROC_BROWSER_TEST_F(TaskManagerBrowserTest, NoticeExtensionChanges) { 233 IN_PROC_BROWSER_TEST_F(TaskManagerBrowserTest, NoticeExtensionChanges) {
174 EXPECT_EQ(0, model()->ResourceCount()); 234 EXPECT_EQ(0, model()->ResourceCount());
175 EXPECT_EQ(0, TaskManager::GetBackgroundPageCount()); 235 EXPECT_EQ(0, TaskManager::GetBackgroundPageCount());
176 236
177 // Show the task manager. This populates the model, and helps with debugging 237 // Show the task manager. This populates the model, and helps with debugging
178 // (you see the task manager). 238 // (you see the task manager).
179 browser()->window()->ShowTaskManager(); 239 browser()->window()->ShowTaskManager();
180 240
181 // Browser and the New Tab Page. 241 // Browser and the New Tab Page.
182 TaskManagerBrowserTestUtil::WaitForResourceChange(2); 242 WaitForResourceChange(2);
183 243
184 // Loading an extension with a background page should result in a new 244 // Loading an extension with a background page should result in a new
185 // resource being created for it. 245 // resource being created for it.
186 ASSERT_TRUE(LoadExtension( 246 ASSERT_TRUE(LoadExtension(
187 test_data_dir_.AppendASCII("common").AppendASCII("background_page"))); 247 test_data_dir_.AppendASCII("common").AppendASCII("background_page")));
188 TaskManagerBrowserTestUtil::WaitForResourceChange(3); 248 WaitForResourceChange(3);
189 EXPECT_EQ(1, TaskManager::GetBackgroundPageCount()); 249 EXPECT_EQ(1, TaskManager::GetBackgroundPageCount());
190 250
191 // Unload extension to avoid crash on Windows (see http://crbug.com/31663). 251 // Unload extension to avoid crash on Windows (see http://crbug.com/31663).
192 UnloadExtension(last_loaded_extension_id_); 252 UnloadExtension(last_loaded_extension_id_);
193 TaskManagerBrowserTestUtil::WaitForResourceChange(2); 253 WaitForResourceChange(2);
194 EXPECT_EQ(0, TaskManager::GetBackgroundPageCount()); 254 EXPECT_EQ(0, TaskManager::GetBackgroundPageCount());
195 } 255 }
196 256
197 IN_PROC_BROWSER_TEST_F(TaskManagerBrowserTest, NoticeExtensionTabs) { 257 IN_PROC_BROWSER_TEST_F(TaskManagerBrowserTest, NoticeExtensionTabs) {
198 // Show the task manager. This populates the model, and helps with debugging 258 // Show the task manager. This populates the model, and helps with debugging
199 // (you see the task manager). 259 // (you see the task manager).
200 browser()->window()->ShowTaskManager(); 260 browser()->window()->ShowTaskManager();
201 261
202 ASSERT_TRUE(LoadExtension( 262 ASSERT_TRUE(LoadExtension(
203 test_data_dir_.AppendASCII("good").AppendASCII("Extensions") 263 test_data_dir_.AppendASCII("good").AppendASCII("Extensions")
204 .AppendASCII("behllobkkfkfnphdnhnkndlbkcpglgmj") 264 .AppendASCII("behllobkkfkfnphdnhnkndlbkcpglgmj")
205 .AppendASCII("1.0.0.0"))); 265 .AppendASCII("1.0.0.0")));
206 266
207 // Browser, Extension background page, and the New Tab Page. 267 // Browser, Extension background page, and the New Tab Page.
208 TaskManagerBrowserTestUtil::WaitForResourceChange(3); 268 WaitForResourceChange(3);
209 269
210 // Open a new tab to an extension URL and make sure we notice that. 270 // Open a new tab to an extension URL and make sure we notice that.
211 GURL url("chrome-extension://behllobkkfkfnphdnhnkndlbkcpglgmj/page.html"); 271 GURL url("chrome-extension://behllobkkfkfnphdnhnkndlbkcpglgmj/page.html");
212 AddTabAtIndex(0, url, PageTransition::TYPED); 272 AddTabAtIndex(0, url, PageTransition::TYPED);
213 TaskManagerBrowserTestUtil::WaitForResourceChange(4); 273 WaitForResourceChange(4);
214 274
215 // Check that the third entry (background) is an extension resource whose 275 // Check that the third entry (background) is an extension resource whose
216 // title starts with "Extension:". 276 // title starts with "Extension:".
217 ASSERT_EQ(TaskManager::Resource::EXTENSION, model()->GetResourceType(2)); 277 ASSERT_EQ(TaskManager::Resource::EXTENSION, model()->GetResourceType(2));
218 ASSERT_TRUE(model()->GetResourceTabContents(2) == NULL); 278 ASSERT_TRUE(model()->GetResourceTabContents(2) == NULL);
219 ASSERT_TRUE(model()->GetResourceExtension(2) != NULL); 279 ASSERT_TRUE(model()->GetResourceExtension(2) != NULL);
220 string16 prefix = l10n_util::GetStringFUTF16( 280 string16 prefix = l10n_util::GetStringFUTF16(
221 IDS_TASK_MANAGER_EXTENSION_PREFIX, string16()); 281 IDS_TASK_MANAGER_EXTENSION_PREFIX, string16());
222 ASSERT_TRUE(StartsWith(model()->GetResourceTitle(2), prefix, true)); 282 ASSERT_TRUE(StartsWith(model()->GetResourceTitle(2), prefix, true));
223 283
224 // Check that the fourth entry (page.html) is of type extension and has both 284 // Check that the fourth entry (page.html) is of type extension and has both
225 // a tab contents and an extension. The title should start with "Extension:". 285 // a tab contents and an extension. The title should start with "Extension:".
226 ASSERT_EQ(TaskManager::Resource::EXTENSION, model()->GetResourceType(3)); 286 ASSERT_EQ(TaskManager::Resource::EXTENSION, model()->GetResourceType(3));
227 ASSERT_TRUE(model()->GetResourceTabContents(3) != NULL); 287 ASSERT_TRUE(model()->GetResourceTabContents(3) != NULL);
228 ASSERT_TRUE(model()->GetResourceExtension(3) != NULL); 288 ASSERT_TRUE(model()->GetResourceExtension(3) != NULL);
229 ASSERT_TRUE(StartsWith(model()->GetResourceTitle(3), prefix, true)); 289 ASSERT_TRUE(StartsWith(model()->GetResourceTitle(3), prefix, true));
230 290
231 // Unload extension to avoid crash on Windows. 291 // Unload extension to avoid crash on Windows.
232 UnloadExtension(last_loaded_extension_id_); 292 UnloadExtension(last_loaded_extension_id_);
233 TaskManagerBrowserTestUtil::WaitForResourceChange(2); 293 WaitForResourceChange(2);
234 } 294 }
235 295
236 IN_PROC_BROWSER_TEST_F(TaskManagerBrowserTest, NoticeAppTabs) { 296 IN_PROC_BROWSER_TEST_F(TaskManagerBrowserTest, NoticeAppTabs) {
237 // Show the task manager. This populates the model, and helps with debugging 297 // Show the task manager. This populates the model, and helps with debugging
238 // (you see the task manager). 298 // (you see the task manager).
239 browser()->window()->ShowTaskManager(); 299 browser()->window()->ShowTaskManager();
240 300
241 ASSERT_TRUE(LoadExtension( 301 ASSERT_TRUE(LoadExtension(
242 test_data_dir_.AppendASCII("packaged_app"))); 302 test_data_dir_.AppendASCII("packaged_app")));
243 ExtensionService* service = browser()->profile()->GetExtensionService(); 303 ExtensionService* service = browser()->profile()->GetExtensionService();
244 const Extension* extension = 304 const Extension* extension =
245 service->GetExtensionById(last_loaded_extension_id_, false); 305 service->GetExtensionById(last_loaded_extension_id_, false);
246 306
247 // Browser and the New Tab Page. 307 // Browser and the New Tab Page.
248 TaskManagerBrowserTestUtil::WaitForResourceChange(2); 308 WaitForResourceChange(2);
249 309
250 // Open a new tab to the app's launch URL and make sure we notice that. 310 // Open a new tab to the app's launch URL and make sure we notice that.
251 GURL url(extension->GetResourceURL("main.html")); 311 GURL url(extension->GetResourceURL("main.html"));
252 AddTabAtIndex(0, url, PageTransition::TYPED); 312 AddTabAtIndex(0, url, PageTransition::TYPED);
253 TaskManagerBrowserTestUtil::WaitForResourceChange(3); 313 WaitForResourceChange(3);
254 314
255 // Check that the third entry (main.html) is of type extension and has both 315 // Check that the third entry (main.html) is of type extension and has both
256 // a tab contents and an extension. The title should start with "App:". 316 // a tab contents and an extension. The title should start with "App:".
257 ASSERT_EQ(TaskManager::Resource::EXTENSION, model()->GetResourceType(2)); 317 ASSERT_EQ(TaskManager::Resource::EXTENSION, model()->GetResourceType(2));
258 ASSERT_TRUE(model()->GetResourceTabContents(2) != NULL); 318 ASSERT_TRUE(model()->GetResourceTabContents(2) != NULL);
259 ASSERT_TRUE(model()->GetResourceExtension(2) == extension); 319 ASSERT_TRUE(model()->GetResourceExtension(2) == extension);
260 string16 prefix = l10n_util::GetStringFUTF16( 320 string16 prefix = l10n_util::GetStringFUTF16(
261 IDS_TASK_MANAGER_APP_PREFIX, string16()); 321 IDS_TASK_MANAGER_APP_PREFIX, string16());
262 ASSERT_TRUE(StartsWith(model()->GetResourceTitle(2), prefix, true)); 322 ASSERT_TRUE(StartsWith(model()->GetResourceTitle(2), prefix, true));
263 323
264 // Unload extension to avoid crash on Windows. 324 // Unload extension to avoid crash on Windows.
265 UnloadExtension(last_loaded_extension_id_); 325 UnloadExtension(last_loaded_extension_id_);
266 TaskManagerBrowserTestUtil::WaitForResourceChange(2); 326 WaitForResourceChange(2);
267 } 327 }
268 328
269 IN_PROC_BROWSER_TEST_F(TaskManagerBrowserTest, NoticeHostedAppTabs) { 329 IN_PROC_BROWSER_TEST_F(TaskManagerBrowserTest, NoticeHostedAppTabs) {
270 // Show the task manager. This populates the model, and helps with debugging 330 // Show the task manager. This populates the model, and helps with debugging
271 // (you see the task manager). 331 // (you see the task manager).
272 browser()->window()->ShowTaskManager(); 332 browser()->window()->ShowTaskManager();
273 333
274 // Browser and the New Tab Page. 334 // Browser and the New Tab Page.
275 TaskManagerBrowserTestUtil::WaitForResourceChange(2); 335 WaitForResourceChange(2);
276 336
277 // The app under test acts on URLs whose host is "localhost", 337 // The app under test acts on URLs whose host is "localhost",
278 // so the URLs we navigate to must have host "localhost". 338 // so the URLs we navigate to must have host "localhost".
279 host_resolver()->AddRule("*", "127.0.0.1"); 339 host_resolver()->AddRule("*", "127.0.0.1");
280 ASSERT_TRUE(test_server()->Start()); 340 ASSERT_TRUE(test_server()->Start());
281 GURL::Replacements replace_host; 341 GURL::Replacements replace_host;
282 std::string host_str("localhost"); // must stay in scope with replace_host 342 std::string host_str("localhost"); // must stay in scope with replace_host
283 replace_host.SetHostStr(host_str); 343 replace_host.SetHostStr(host_str);
284 GURL base_url = test_server()->GetURL( 344 GURL base_url = test_server()->GetURL(
285 "files/extensions/api_test/app_process/"); 345 "files/extensions/api_test/app_process/");
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
320 EXPECT_EQ(0, TaskManager::GetBackgroundPageCount()); 380 EXPECT_EQ(0, TaskManager::GetBackgroundPageCount());
321 // Show the task manager. This populates the model, and helps with debugging 381 // Show the task manager. This populates the model, and helps with debugging
322 // (you see the task manager). 382 // (you see the task manager).
323 browser()->window()->ShowTaskManager(); 383 browser()->window()->ShowTaskManager();
324 384
325 ASSERT_TRUE(LoadExtension( 385 ASSERT_TRUE(LoadExtension(
326 test_data_dir_.AppendASCII("common").AppendASCII("background_page"))); 386 test_data_dir_.AppendASCII("common").AppendASCII("background_page")));
327 387
328 // Wait until we see the loaded extension in the task manager (the three 388 // Wait until we see the loaded extension in the task manager (the three
329 // resources are: the browser process, New Tab Page, and the extension). 389 // resources are: the browser process, New Tab Page, and the extension).
330 TaskManagerBrowserTestUtil::WaitForResourceChange(3); 390 WaitForResourceChange(3);
331 EXPECT_EQ(1, TaskManager::GetBackgroundPageCount()); 391 EXPECT_EQ(1, TaskManager::GetBackgroundPageCount());
332 392
333 EXPECT_TRUE(model()->GetResourceExtension(0) == NULL); 393 EXPECT_TRUE(model()->GetResourceExtension(0) == NULL);
334 EXPECT_TRUE(model()->GetResourceExtension(1) == NULL); 394 EXPECT_TRUE(model()->GetResourceExtension(1) == NULL);
335 ASSERT_TRUE(model()->GetResourceExtension(2) != NULL); 395 ASSERT_TRUE(model()->GetResourceExtension(2) != NULL);
336 396
337 // Kill the extension process and make sure we notice it. 397 // Kill the extension process and make sure we notice it.
338 TaskManager::GetInstance()->KillProcess(2); 398 TaskManager::GetInstance()->KillProcess(2);
339 TaskManagerBrowserTestUtil::WaitForResourceChange(2); 399 WaitForResourceChange(2);
340 EXPECT_EQ(0, TaskManager::GetBackgroundPageCount()); 400 EXPECT_EQ(0, TaskManager::GetBackgroundPageCount());
341 } 401 }
342 402
343 // Disabled, http://crbug.com/66957. 403 // Disabled, http://crbug.com/66957.
344 IN_PROC_BROWSER_TEST_F(TaskManagerBrowserTest, 404 IN_PROC_BROWSER_TEST_F(TaskManagerBrowserTest,
345 DISABLED_KillExtensionAndReload) { 405 DISABLED_KillExtensionAndReload) {
346 // Show the task manager. This populates the model, and helps with debugging 406 // Show the task manager. This populates the model, and helps with debugging
347 // (you see the task manager). 407 // (you see the task manager).
348 browser()->window()->ShowTaskManager(); 408 browser()->window()->ShowTaskManager();
349 409
350 ASSERT_TRUE(LoadExtension( 410 ASSERT_TRUE(LoadExtension(
351 test_data_dir_.AppendASCII("common").AppendASCII("background_page"))); 411 test_data_dir_.AppendASCII("common").AppendASCII("background_page")));
352 412
353 // Wait until we see the loaded extension in the task manager (the three 413 // Wait until we see the loaded extension in the task manager (the three
354 // resources are: the browser process, New Tab Page, and the extension). 414 // resources are: the browser process, New Tab Page, and the extension).
355 TaskManagerBrowserTestUtil::WaitForResourceChange(3); 415 WaitForResourceChange(3);
356 416
357 EXPECT_TRUE(model()->GetResourceExtension(0) == NULL); 417 EXPECT_TRUE(model()->GetResourceExtension(0) == NULL);
358 EXPECT_TRUE(model()->GetResourceExtension(1) == NULL); 418 EXPECT_TRUE(model()->GetResourceExtension(1) == NULL);
359 ASSERT_TRUE(model()->GetResourceExtension(2) != NULL); 419 ASSERT_TRUE(model()->GetResourceExtension(2) != NULL);
360 420
361 // Kill the extension process and make sure we notice it. 421 // Kill the extension process and make sure we notice it.
362 TaskManager::GetInstance()->KillProcess(2); 422 TaskManager::GetInstance()->KillProcess(2);
363 TaskManagerBrowserTestUtil::WaitForResourceChange(2); 423 WaitForResourceChange(2);
364 424
365 // Reload the extension using the "crashed extension" infobar while the task 425 // Reload the extension using the "crashed extension" infobar while the task
366 // manager is still visible. Make sure we don't crash and the extension 426 // manager is still visible. Make sure we don't crash and the extension
367 // gets reloaded and noticed in the task manager. 427 // gets reloaded and noticed in the task manager.
368 TabContentsWrapper* current_tab = browser()->GetSelectedTabContentsWrapper(); 428 TabContentsWrapper* current_tab = browser()->GetSelectedTabContentsWrapper();
369 ASSERT_EQ(1U, current_tab->infobar_count()); 429 ASSERT_EQ(1U, current_tab->infobar_count());
370 ConfirmInfoBarDelegate* delegate = 430 ConfirmInfoBarDelegate* delegate =
371 current_tab->GetInfoBarDelegateAt(0)->AsConfirmInfoBarDelegate(); 431 current_tab->GetInfoBarDelegateAt(0)->AsConfirmInfoBarDelegate();
372 ASSERT_TRUE(delegate); 432 ASSERT_TRUE(delegate);
373 delegate->Accept(); 433 delegate->Accept();
374 TaskManagerBrowserTestUtil::WaitForResourceChange(3); 434 WaitForResourceChange(3);
375 } 435 }
376 436
377 // Regression test for http://crbug.com/18693. 437 // Regression test for http://crbug.com/18693.
378 // 438 //
379 // This test is crashy. See http://crbug.com/42315. 439 // This test is crashy. See http://crbug.com/42315.
380 IN_PROC_BROWSER_TEST_F(TaskManagerBrowserTest, DISABLED_ReloadExtension) { 440 IN_PROC_BROWSER_TEST_F(TaskManagerBrowserTest, DISABLED_ReloadExtension) {
381 // Show the task manager. This populates the model, and helps with debugging 441 // Show the task manager. This populates the model, and helps with debugging
382 // (you see the task manager). 442 // (you see the task manager).
383 browser()->window()->ShowTaskManager(); 443 browser()->window()->ShowTaskManager();
384 444
385 LOG(INFO) << "loading extension"; 445 LOG(INFO) << "loading extension";
386 ASSERT_TRUE(LoadExtension( 446 ASSERT_TRUE(LoadExtension(
387 test_data_dir_.AppendASCII("common").AppendASCII("background_page"))); 447 test_data_dir_.AppendASCII("common").AppendASCII("background_page")));
388 448
389 // Wait until we see the loaded extension in the task manager (the three 449 // Wait until we see the loaded extension in the task manager (the three
390 // resources are: the browser process, New Tab Page, and the extension). 450 // resources are: the browser process, New Tab Page, and the extension).
391 LOG(INFO) << "waiting for resource change"; 451 LOG(INFO) << "waiting for resource change";
392 TaskManagerBrowserTestUtil::WaitForResourceChange(3); 452 WaitForResourceChange(3);
393 453
394 EXPECT_TRUE(model()->GetResourceExtension(0) == NULL); 454 EXPECT_TRUE(model()->GetResourceExtension(0) == NULL);
395 EXPECT_TRUE(model()->GetResourceExtension(1) == NULL); 455 EXPECT_TRUE(model()->GetResourceExtension(1) == NULL);
396 ASSERT_TRUE(model()->GetResourceExtension(2) != NULL); 456 ASSERT_TRUE(model()->GetResourceExtension(2) != NULL);
397 457
398 const Extension* extension = model()->GetResourceExtension(2); 458 const Extension* extension = model()->GetResourceExtension(2);
399 ASSERT_TRUE(extension != NULL); 459 ASSERT_TRUE(extension != NULL);
400 460
401 // Reload the extension a few times and make sure our resource count 461 // Reload the extension a few times and make sure our resource count
402 // doesn't increase. 462 // doesn't increase.
403 LOG(INFO) << "First extension reload"; 463 LOG(INFO) << "First extension reload";
404 ReloadExtension(extension->id()); 464 ReloadExtension(extension->id());
405 TaskManagerBrowserTestUtil::WaitForResourceChange(3); 465 WaitForResourceChange(3);
406 extension = model()->GetResourceExtension(2); 466 extension = model()->GetResourceExtension(2);
407 ASSERT_TRUE(extension != NULL); 467 ASSERT_TRUE(extension != NULL);
408 468
409 LOG(INFO) << "Second extension reload"; 469 LOG(INFO) << "Second extension reload";
410 ReloadExtension(extension->id()); 470 ReloadExtension(extension->id());
411 TaskManagerBrowserTestUtil::WaitForResourceChange(3); 471 WaitForResourceChange(3);
412 extension = model()->GetResourceExtension(2); 472 extension = model()->GetResourceExtension(2);
413 ASSERT_TRUE(extension != NULL); 473 ASSERT_TRUE(extension != NULL);
414 474
415 LOG(INFO) << "Third extension reload"; 475 LOG(INFO) << "Third extension reload";
416 ReloadExtension(extension->id()); 476 ReloadExtension(extension->id());
417 TaskManagerBrowserTestUtil::WaitForResourceChange(3); 477 WaitForResourceChange(3);
418 } 478 }
419 479
420 // Crashy, http://crbug.com/42301. 480 // Crashy, http://crbug.com/42301.
421 IN_PROC_BROWSER_TEST_F(TaskManagerBrowserTest, 481 IN_PROC_BROWSER_TEST_F(TaskManagerBrowserTest,
422 DISABLED_PopulateWebCacheFields) { 482 DISABLED_PopulateWebCacheFields) {
423 EXPECT_EQ(0, model()->ResourceCount()); 483 EXPECT_EQ(0, model()->ResourceCount());
424 484
425 // Show the task manager. This populates the model, and helps with debugging 485 // Show the task manager. This populates the model, and helps with debugging
426 // (you see the task manager). 486 // (you see the task manager).
427 browser()->window()->ShowTaskManager(); 487 browser()->window()->ShowTaskManager();
428 488
429 // Browser and the New Tab Page. 489 // Browser and the New Tab Page.
430 TaskManagerBrowserTestUtil::WaitForResourceChange(2); 490 WaitForResourceChange(2);
431 491
432 // Open a new tab and make sure we notice that. 492 // Open a new tab and make sure we notice that.
433 GURL url(ui_test_utils::GetTestUrl(FilePath(FilePath::kCurrentDirectory), 493 GURL url(ui_test_utils::GetTestUrl(FilePath(FilePath::kCurrentDirectory),
434 FilePath(kTitle1File))); 494 FilePath(kTitle1File)));
435 AddTabAtIndex(0, url, PageTransition::TYPED); 495 AddTabAtIndex(0, url, PageTransition::TYPED);
436 TaskManagerBrowserTestUtil::WaitForResourceChange(3); 496 WaitForResourceChange(3);
437 497
438 // Check that we get some value for the cache columns. 498 // Check that we get some value for the cache columns.
439 DCHECK_NE(model()->GetResourceWebCoreImageCacheSize(2), 499 DCHECK_NE(model()->GetResourceWebCoreImageCacheSize(2),
440 l10n_util::GetStringUTF16(IDS_TASK_MANAGER_NA_CELL_TEXT)); 500 l10n_util::GetStringUTF16(IDS_TASK_MANAGER_NA_CELL_TEXT));
441 DCHECK_NE(model()->GetResourceWebCoreScriptsCacheSize(2), 501 DCHECK_NE(model()->GetResourceWebCoreScriptsCacheSize(2),
442 l10n_util::GetStringUTF16(IDS_TASK_MANAGER_NA_CELL_TEXT)); 502 l10n_util::GetStringUTF16(IDS_TASK_MANAGER_NA_CELL_TEXT));
443 DCHECK_NE(model()->GetResourceWebCoreCSSCacheSize(2), 503 DCHECK_NE(model()->GetResourceWebCoreCSSCacheSize(2),
444 l10n_util::GetStringUTF16(IDS_TASK_MANAGER_NA_CELL_TEXT)); 504 l10n_util::GetStringUTF16(IDS_TASK_MANAGER_NA_CELL_TEXT));
445 } 505 }
OLDNEW
« 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