task_manager_browsertest.cc revision 7d4cd473f85ac64c3747c96c277f9e506a0d2246
1// Copyright (c) 2012 The Chromium Authors. All rights reserved. 2// Use of this source code is governed by a BSD-style license that can be 3// found in the LICENSE file. 4 5#include "chrome/browser/task_manager/task_manager.h" 6 7#include "base/files/file_path.h" 8#include "base/strings/stringprintf.h" 9#include "base/strings/utf_string_conversions.h" 10#include "chrome/browser/background/background_contents_service.h" 11#include "chrome/browser/background/background_contents_service_factory.h" 12#include "chrome/browser/browser_process.h" 13#include "chrome/browser/extensions/extension_browsertest.h" 14#include "chrome/browser/extensions/extension_service.h" 15#include "chrome/browser/extensions/extension_system.h" 16#include "chrome/browser/infobars/confirm_infobar_delegate.h" 17#include "chrome/browser/infobars/infobar_service.h" 18#include "chrome/browser/notifications/desktop_notification_service.h" 19#include "chrome/browser/notifications/notification.h" 20#include "chrome/browser/notifications/notification_test_util.h" 21#include "chrome/browser/notifications/notification_ui_manager.h" 22#include "chrome/browser/profiles/profile.h" 23#include "chrome/browser/task_manager/resource_provider.h" 24#include "chrome/browser/task_manager/task_manager_browsertest_util.h" 25#include "chrome/browser/ui/browser.h" 26#include "chrome/browser/ui/browser_dialogs.h" 27#include "chrome/browser/ui/browser_navigator.h" 28#include "chrome/browser/ui/browser_window.h" 29#include "chrome/browser/ui/panels/panel.h" 30#include "chrome/browser/ui/panels/panel_manager.h" 31#include "chrome/browser/ui/tabs/tab_strip_model.h" 32#include "chrome/browser/web_applications/web_app.h" 33#include "chrome/common/chrome_notification_types.h" 34#include "chrome/common/chrome_switches.h" 35#include "chrome/common/extensions/extension.h" 36#include "chrome/test/base/in_process_browser_test.h" 37#include "chrome/test/base/ui_test_utils.h" 38#include "content/public/browser/notification_service.h" 39#include "content/public/common/content_switches.h" 40#include "content/public/common/page_transition_types.h" 41#include "content/public/test/browser_test_utils.h" 42#include "grit/generated_resources.h" 43#include "net/dns/mock_host_resolver.h" 44#include "testing/gtest/include/gtest/gtest.h" 45#include "ui/base/l10n/l10n_util.h" 46 47// http://crbug.com/31663 48// TODO(linux_aura) http://crbug.com/163931 49#if !(defined(OS_WIN) && defined(USE_AURA)) && !(defined(OS_LINUX) && !defined(OS_CHROMEOS) && defined(USE_AURA)) 50 51using content::WebContents; 52 53// On Linux this is crashing intermittently http://crbug/84719 54// In some environments this test fails about 1/6 http://crbug/84850 55#if defined(OS_LINUX) 56#define MAYBE_KillExtension DISABLED_KillExtension 57#else 58#define MAYBE_KillExtension KillExtension 59#endif 60 61namespace { 62 63const base::FilePath::CharType* kTitle1File = FILE_PATH_LITERAL("title1.html"); 64 65} // namespace 66 67class TaskManagerBrowserTest : public ExtensionBrowserTest { 68 public: 69 TaskManagerBrowserTest() {} 70 virtual ~TaskManagerBrowserTest() {} 71 72 TaskManagerModel* model() const { 73 return TaskManager::GetInstance()->model(); 74 } 75 76 virtual void SetUpOnMainThread() OVERRIDE { 77 ExtensionBrowserTest::SetUpOnMainThread(); 78 79 EXPECT_EQ(0, model()->ResourceCount()); 80 81 EXPECT_EQ(0, TaskManager::GetBackgroundPageCount()); 82 83 // Show the task manager. This populates the model, and helps with debugging 84 // (you see the task manager). 85 chrome::ShowTaskManager(browser(), false); 86 87 // New Tab Page. 88 TaskManagerBrowserTestUtil::WaitForWebResourceChange(1); 89 } 90 91 void Refresh() { 92 model()->Refresh(); 93 } 94 95 int GetUpdateTimeMs() { 96 return TaskManagerModel::kUpdateTimeMs; 97 } 98 99 protected: 100 virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE { 101 ExtensionBrowserTest::SetUpCommandLine(command_line); 102 103 // Do not prelaunch the GPU process and disable accelerated compositing 104 // for these tests as the GPU process will show up in task manager but 105 // whether it appears before or after the new tab renderer process is not 106 // well defined. 107 command_line->AppendSwitch(switches::kDisableGpuProcessPrelaunch); 108 command_line->AppendSwitch(switches::kDisableAcceleratedCompositing); 109 } 110 111 private: 112 DISALLOW_COPY_AND_ASSIGN(TaskManagerBrowserTest); 113}; 114 115#if defined(OS_MACOSX) || defined(OS_LINUX) 116#define MAYBE_ShutdownWhileOpen DISABLED_ShutdownWhileOpen 117#else 118#define MAYBE_ShutdownWhileOpen ShutdownWhileOpen 119#endif 120 121// Regression test for http://crbug.com/13361 122IN_PROC_BROWSER_TEST_F(TaskManagerBrowserTest, MAYBE_ShutdownWhileOpen) { 123 // Showing task manager handled by SetUp. 124} 125 126IN_PROC_BROWSER_TEST_F(TaskManagerBrowserTest, NoticeTabContentsChanges) { 127 int resource_count = TaskManager::GetInstance()->model()->ResourceCount(); 128 // Open a new tab and make sure we notice that. 129 GURL url(ui_test_utils::GetTestUrl(base::FilePath( 130 base::FilePath::kCurrentDirectory), base::FilePath(kTitle1File))); 131 AddTabAtIndex(0, url, content::PAGE_TRANSITION_TYPED); 132 TaskManagerBrowserTestUtil::WaitForWebResourceChange(2); 133 134 // Check that the last entry is a tab contents resource whose title starts 135 // starts with "Tab:". 136 ASSERT_TRUE(model()->GetResourceWebContents(resource_count) != NULL); 137 string16 prefix = l10n_util::GetStringFUTF16( 138 IDS_TASK_MANAGER_TAB_PREFIX, string16()); 139 ASSERT_TRUE(StartsWith(model()->GetResourceTitle(resource_count), prefix, 140 true)); 141 142 // Close the tab and verify that we notice. 143 browser()->tab_strip_model()->CloseWebContentsAt(0, 144 TabStripModel::CLOSE_NONE); 145 TaskManagerBrowserTestUtil::WaitForWebResourceChange(1); 146} 147 148#if defined(USE_ASH) 149// This test fails on Ash because task manager treats view type 150// Panels differently for Ash. 151#define MAYBE_NoticePanelChanges DISABLED_NoticePanelChanges 152#else 153#define MAYBE_NoticePanelChanges NoticePanelChanges 154#endif 155IN_PROC_BROWSER_TEST_F(TaskManagerBrowserTest, MAYBE_NoticePanelChanges) { 156 ASSERT_TRUE(LoadExtension( 157 test_data_dir_.AppendASCII("good").AppendASCII("Extensions") 158 .AppendASCII("behllobkkfkfnphdnhnkndlbkcpglgmj") 159 .AppendASCII("1.0.0.0"))); 160 161 // Browser, the New Tab Page and Extension background page. 162 TaskManagerBrowserTestUtil::WaitForWebResourceChange(2); 163 164 // Open a new panel to an extension url and make sure we notice that. 165 GURL url( 166 "chrome-extension://behllobkkfkfnphdnhnkndlbkcpglgmj/french_sentence.html"); 167 Panel* panel = PanelManager::GetInstance()->CreatePanel( 168 web_app::GenerateApplicationNameFromExtensionId( 169 last_loaded_extension_id_), 170 browser()->profile(), 171 url, 172 gfx::Rect(300, 400), 173 PanelManager::CREATE_AS_DOCKED); 174 TaskManagerBrowserTestUtil::WaitForWebResourceChange(3); 175 176 // Check that the fourth entry is a resource with the panel's web contents 177 // and whose title starts with "Extension:". 178 ASSERT_EQ(panel->GetWebContents(), model()->GetResourceWebContents(3)); 179 string16 prefix = l10n_util::GetStringFUTF16( 180 IDS_TASK_MANAGER_EXTENSION_PREFIX, string16()); 181 ASSERT_TRUE(StartsWith(model()->GetResourceTitle(3), prefix, true)); 182 183 // Close the panel and verify that we notice. 184 panel->Close(); 185 TaskManagerBrowserTestUtil::WaitForWebResourceChange(2); 186 187 // Unload extension to avoid crash on Windows. 188 UnloadExtension(last_loaded_extension_id_); 189 TaskManagerBrowserTestUtil::WaitForWebResourceChange(1); 190} 191 192IN_PROC_BROWSER_TEST_F(TaskManagerBrowserTest, NoticeBGContentsChanges) { 193 // Open a new background contents and make sure we notice that. 194 GURL url(ui_test_utils::GetTestUrl(base::FilePath( 195 base::FilePath::kCurrentDirectory), base::FilePath(kTitle1File))); 196 197 BackgroundContentsService* service = 198 BackgroundContentsServiceFactory::GetForProfile(browser()->profile()); 199 string16 application_id(ASCIIToUTF16("test_app_id")); 200 service->LoadBackgroundContents(browser()->profile(), 201 url, 202 ASCIIToUTF16("background_page"), 203 application_id); 204 TaskManagerBrowserTestUtil::WaitForWebResourceChange(2); 205 EXPECT_EQ(1, TaskManager::GetBackgroundPageCount()); 206 207 // Close the background contents and verify that we notice. 208 service->ShutdownAssociatedBackgroundContents(application_id); 209 TaskManagerBrowserTestUtil::WaitForWebResourceChange(1); 210 EXPECT_EQ(0, TaskManager::GetBackgroundPageCount()); 211} 212 213IN_PROC_BROWSER_TEST_F(TaskManagerBrowserTest, KillBGContents) { 214 int resource_count = TaskManager::GetInstance()->model()->ResourceCount(); 215 216 // Open a new background contents and make sure we notice that. 217 GURL url(ui_test_utils::GetTestUrl(base::FilePath( 218 base::FilePath::kCurrentDirectory), base::FilePath(kTitle1File))); 219 220 content::WindowedNotificationObserver observer( 221 chrome::NOTIFICATION_BACKGROUND_CONTENTS_NAVIGATED, 222 content::Source<Profile>(browser()->profile())); 223 224 BackgroundContentsService* service = 225 BackgroundContentsServiceFactory::GetForProfile(browser()->profile()); 226 string16 application_id(ASCIIToUTF16("test_app_id")); 227 service->LoadBackgroundContents(browser()->profile(), 228 url, 229 ASCIIToUTF16("background_page"), 230 application_id); 231 232 // Wait for the background contents process to finish loading. 233 observer.Wait(); 234 235 EXPECT_EQ(resource_count + 1, model()->ResourceCount()); 236 EXPECT_EQ(1, TaskManager::GetBackgroundPageCount()); 237 238 // Kill the background contents process and verify that it disappears from the 239 // model. 240 bool found = false; 241 for (int i = 0; i < model()->ResourceCount(); ++i) { 242 if (model()->IsBackgroundResource(i)) { 243 TaskManager::GetInstance()->KillProcess(i); 244 found = true; 245 break; 246 } 247 } 248 ASSERT_TRUE(found); 249 TaskManagerBrowserTestUtil::WaitForWebResourceChange(1); 250 EXPECT_EQ(0, TaskManager::GetBackgroundPageCount()); 251} 252 253#if defined(USE_ASH) || defined(OS_WIN) 254// This test fails on Ash because task manager treats view type 255// Panels differently for Ash. 256// This test also fails on Windows, win_rel trybot. http://crbug.com/166322 257#define MAYBE_KillPanelExtension DISABLED_KillPanelExtension 258#else 259#define MAYBE_KillPanelExtension KillPanelExtension 260#endif 261IN_PROC_BROWSER_TEST_F(TaskManagerBrowserTest, MAYBE_KillPanelExtension) { 262 int resource_count = TaskManager::GetInstance()->model()->ResourceCount(); 263 264 ASSERT_TRUE(LoadExtension( 265 test_data_dir_.AppendASCII("good").AppendASCII("Extensions") 266 .AppendASCII("behllobkkfkfnphdnhnkndlbkcpglgmj") 267 .AppendASCII("1.0.0.0"))); 268 269 // Browser, the New Tab Page and Extension background page. 270 TaskManagerBrowserTestUtil::WaitForWebResourceChange(2); 271 272 // Open a new panel to an extension url and make sure we notice that. 273 GURL url( 274 "chrome-extension://behllobkkfkfnphdnhnkndlbkcpglgmj/french_sentence.html"); 275 PanelManager::GetInstance()->CreatePanel( 276 web_app::GenerateApplicationNameFromExtensionId( 277 last_loaded_extension_id_), 278 browser()->profile(), 279 url, 280 gfx::Rect(300, 400), 281 PanelManager::CREATE_AS_DOCKED); 282 TaskManagerBrowserTestUtil::WaitForWebResourceChange(3); 283 284 // Kill the panel extension process and verify that it disappears from the 285 // model along with its panel. 286 ASSERT_TRUE(model()->IsBackgroundResource(resource_count)); 287 TaskManager::GetInstance()->KillProcess(resource_count); 288 TaskManagerBrowserTestUtil::WaitForWebResourceChange(1); 289} 290 291IN_PROC_BROWSER_TEST_F(TaskManagerBrowserTest, NoticeExtensionChanges) { 292 // Loading an extension with a background page should result in a new 293 // resource being created for it. 294 ASSERT_TRUE(LoadExtension( 295 test_data_dir_.AppendASCII("common").AppendASCII("background_page"))); 296 TaskManagerBrowserTestUtil::WaitForWebResourceChange(2); 297 EXPECT_EQ(1, TaskManager::GetBackgroundPageCount()); 298 299 // Unload extension to avoid crash on Windows (see http://crbug.com/31663). 300 UnloadExtension(last_loaded_extension_id_); 301 TaskManagerBrowserTestUtil::WaitForWebResourceChange(1); 302 EXPECT_EQ(0, TaskManager::GetBackgroundPageCount()); 303} 304 305IN_PROC_BROWSER_TEST_F(TaskManagerBrowserTest, NoticeExtensionTabs) { 306 int resource_count = TaskManager::GetInstance()->model()->ResourceCount(); 307 ASSERT_TRUE(LoadExtension( 308 test_data_dir_.AppendASCII("good").AppendASCII("Extensions") 309 .AppendASCII("behllobkkfkfnphdnhnkndlbkcpglgmj") 310 .AppendASCII("1.0.0.0"))); 311 312 // Browser, Extension background page, and the New Tab Page. 313 TaskManagerBrowserTestUtil::WaitForWebResourceChange(2); 314 315 // Open a new tab to an extension URL and make sure we notice that. 316 GURL url("chrome-extension://behllobkkfkfnphdnhnkndlbkcpglgmj/page.html"); 317 AddTabAtIndex(0, url, content::PAGE_TRANSITION_TYPED); 318 TaskManagerBrowserTestUtil::WaitForWebResourceChange(3); 319 320 // Check that the third entry (background) is an extension resource whose 321 // title starts with "Extension:". 322 ASSERT_EQ(task_manager::Resource::EXTENSION, model()->GetResourceType( 323 resource_count)); 324 ASSERT_TRUE(model()->GetResourceWebContents(resource_count) == NULL); 325 ASSERT_TRUE(model()->GetResourceExtension(resource_count) != NULL); 326 string16 prefix = l10n_util::GetStringFUTF16( 327 IDS_TASK_MANAGER_EXTENSION_PREFIX, string16()); 328 ASSERT_TRUE(StartsWith(model()->GetResourceTitle(resource_count), 329 prefix, true)); 330 331 // Check that the fourth entry (page.html) is of type extension and has both 332 // a tab contents and an extension. The title should start with "Extension:". 333 ASSERT_EQ(task_manager::Resource::EXTENSION, model()->GetResourceType( 334 resource_count + 1)); 335 ASSERT_TRUE(model()->GetResourceWebContents(resource_count + 1) != NULL); 336 ASSERT_TRUE(model()->GetResourceExtension(resource_count + 1) != NULL); 337 ASSERT_TRUE(StartsWith(model()->GetResourceTitle(resource_count + 1), 338 prefix, true)); 339 340 // Unload extension to avoid crash on Windows. 341 UnloadExtension(last_loaded_extension_id_); 342 TaskManagerBrowserTestUtil::WaitForWebResourceChange(1); 343} 344 345IN_PROC_BROWSER_TEST_F(TaskManagerBrowserTest, NoticeAppTabs) { 346 int resource_count = TaskManager::GetInstance()->model()->ResourceCount(); 347 ASSERT_TRUE(LoadExtension( 348 test_data_dir_.AppendASCII("packaged_app"))); 349 ExtensionService* service = extensions::ExtensionSystem::Get( 350 browser()->profile())->extension_service(); 351 const extensions::Extension* extension = 352 service->GetExtensionById(last_loaded_extension_id_, false); 353 354 // New Tab Page. 355 TaskManagerBrowserTestUtil::WaitForWebResourceChange(1); 356 357 // Open a new tab to the app's launch URL and make sure we notice that. 358 GURL url(extension->GetResourceURL("main.html")); 359 AddTabAtIndex(0, url, content::PAGE_TRANSITION_TYPED); 360 TaskManagerBrowserTestUtil::WaitForWebResourceChange(2); 361 362 // Check that the third entry (main.html) is of type extension and has both 363 // a tab contents and an extension. The title should start with "App:". 364 ASSERT_EQ(task_manager::Resource::EXTENSION, model()->GetResourceType( 365 resource_count)); 366 ASSERT_TRUE(model()->GetResourceWebContents(resource_count) != NULL); 367 ASSERT_TRUE(model()->GetResourceExtension(resource_count) == extension); 368 string16 prefix = l10n_util::GetStringFUTF16( 369 IDS_TASK_MANAGER_APP_PREFIX, string16()); 370 ASSERT_TRUE(StartsWith(model()->GetResourceTitle(resource_count), 371 prefix, true)); 372 373 // Unload extension to avoid crash on Windows. 374 UnloadExtension(last_loaded_extension_id_); 375 TaskManagerBrowserTestUtil::WaitForWebResourceChange(1); 376} 377 378IN_PROC_BROWSER_TEST_F(TaskManagerBrowserTest, NoticeHostedAppTabs) { 379 int resource_count = TaskManager::GetInstance()->model()->ResourceCount(); 380 381 // The app under test acts on URLs whose host is "localhost", 382 // so the URLs we navigate to must have host "localhost". 383 host_resolver()->AddRule("*", "127.0.0.1"); 384 ASSERT_TRUE(test_server()->Start()); 385 GURL::Replacements replace_host; 386 std::string host_str("localhost"); // must stay in scope with replace_host 387 replace_host.SetHostStr(host_str); 388 GURL base_url = test_server()->GetURL( 389 "files/extensions/api_test/app_process/"); 390 base_url = base_url.ReplaceComponents(replace_host); 391 392 // Open a new tab to an app URL before the app is loaded. 393 GURL url(base_url.Resolve("path1/empty.html")); 394 content::WindowedNotificationObserver observer( 395 content::NOTIFICATION_NAV_ENTRY_COMMITTED, 396 content::NotificationService::AllSources()); 397 AddTabAtIndex(0, url, content::PAGE_TRANSITION_TYPED); 398 observer.Wait(); 399 400 // Force the TaskManager to query the title. 401 Refresh(); 402 403 // Check that the third entry's title starts with "Tab:". 404 string16 tab_prefix = l10n_util::GetStringFUTF16( 405 IDS_TASK_MANAGER_TAB_PREFIX, string16()); 406 ASSERT_TRUE(StartsWith(model()->GetResourceTitle(resource_count), 407 tab_prefix, true)); 408 409 // Load the hosted app and make sure it still starts with "Tab:", 410 // since it hasn't changed to an app process yet. 411 ASSERT_TRUE(LoadExtension( 412 test_data_dir_.AppendASCII("api_test").AppendASCII("app_process"))); 413 // Force the TaskManager to query the title. 414 Refresh(); 415 ASSERT_TRUE(StartsWith(model()->GetResourceTitle(resource_count), 416 tab_prefix, true)); 417 418 // Now reload and check that the last entry's title now starts with "App:". 419 ui_test_utils::NavigateToURL(browser(), url); 420 // Force the TaskManager to query the title. 421 Refresh(); 422 string16 app_prefix = l10n_util::GetStringFUTF16( 423 IDS_TASK_MANAGER_APP_PREFIX, string16()); 424 ASSERT_TRUE(StartsWith(model()->GetResourceTitle(resource_count), 425 app_prefix, true)); 426 427 // Disable extension and reload page. 428 DisableExtension(last_loaded_extension_id_); 429 ui_test_utils::NavigateToURL(browser(), url); 430 431 // Force the TaskManager to query the title. 432 Refresh(); 433 434 // The third entry's title should be back to a normal tab. 435 ASSERT_TRUE(StartsWith(model()->GetResourceTitle(resource_count), 436 tab_prefix, true)); 437} 438 439IN_PROC_BROWSER_TEST_F(TaskManagerBrowserTest, MAYBE_KillExtension) { 440 int resource_count = TaskManager::GetInstance()->model()->ResourceCount(); 441 442 ASSERT_TRUE(LoadExtension( 443 test_data_dir_.AppendASCII("common").AppendASCII("background_page"))); 444 445 // Wait until we see the loaded extension in the task manager (the three 446 // resources are: the browser process, New Tab Page, and the extension). 447 TaskManagerBrowserTestUtil::WaitForWebResourceChange(2); 448 EXPECT_EQ(1, TaskManager::GetBackgroundPageCount()); 449 450 EXPECT_TRUE(model()->GetResourceExtension(0) == NULL); 451 EXPECT_TRUE(model()->GetResourceExtension(1) == NULL); 452 ASSERT_TRUE(model()->GetResourceExtension(resource_count) != NULL); 453 454 // Kill the extension process and make sure we notice it. 455 TaskManager::GetInstance()->KillProcess(resource_count); 456 TaskManagerBrowserTestUtil::WaitForWebResourceChange(1); 457 EXPECT_EQ(0, TaskManager::GetBackgroundPageCount()); 458} 459 460// Disabled, http://crbug.com/66957. 461IN_PROC_BROWSER_TEST_F(TaskManagerBrowserTest, 462 DISABLED_KillExtensionAndReload) { 463 ASSERT_TRUE(LoadExtension( 464 test_data_dir_.AppendASCII("common").AppendASCII("background_page"))); 465 466 // Wait until we see the loaded extension in the task manager (the three 467 // resources are: the browser process, New Tab Page, and the extension). 468 TaskManagerBrowserTestUtil::WaitForWebResourceChange(3); 469 470 EXPECT_TRUE(model()->GetResourceExtension(0) == NULL); 471 EXPECT_TRUE(model()->GetResourceExtension(1) == NULL); 472 ASSERT_TRUE(model()->GetResourceExtension(2) != NULL); 473 474 // Kill the extension process and make sure we notice it. 475 TaskManager::GetInstance()->KillProcess(2); 476 TaskManagerBrowserTestUtil::WaitForWebResourceChange(1); 477 478 // Reload the extension using the "crashed extension" infobar while the task 479 // manager is still visible. Make sure we don't crash and the extension 480 // gets reloaded and noticed in the task manager. 481 InfoBarService* infobar_service = InfoBarService::FromWebContents( 482 browser()->tab_strip_model()->GetActiveWebContents()); 483 ASSERT_EQ(1U, infobar_service->infobar_count()); 484 ConfirmInfoBarDelegate* delegate = 485 infobar_service->infobar_at(0)->AsConfirmInfoBarDelegate(); 486 ASSERT_TRUE(delegate); 487 delegate->Accept(); 488 TaskManagerBrowserTestUtil::WaitForWebResourceChange(3); 489} 490 491#if defined(OS_WIN) 492// http://crbug.com/93158. 493#define MAYBE_ReloadExtension DISABLED_ReloadExtension 494#else 495#define MAYBE_ReloadExtension ReloadExtension 496#endif 497 498// Regression test for http://crbug.com/18693. 499IN_PROC_BROWSER_TEST_F(TaskManagerBrowserTest, MAYBE_ReloadExtension) { 500 int resource_count = TaskManager::GetInstance()->model()->ResourceCount(); 501 LOG(INFO) << "loading extension"; 502 ASSERT_TRUE(LoadExtension( 503 test_data_dir_.AppendASCII("common").AppendASCII("background_page"))); 504 505 // Wait until we see the loaded extension in the task manager (the three 506 // resources are: the browser process, New Tab Page, and the extension). 507 LOG(INFO) << "waiting for resource change"; 508 TaskManagerBrowserTestUtil::WaitForWebResourceChange(2); 509 510 EXPECT_TRUE(model()->GetResourceExtension(0) == NULL); 511 EXPECT_TRUE(model()->GetResourceExtension(1) == NULL); 512 ASSERT_TRUE(model()->GetResourceExtension(resource_count) != NULL); 513 514 const extensions::Extension* extension = model()->GetResourceExtension( 515 resource_count); 516 ASSERT_TRUE(extension != NULL); 517 518 // Reload the extension a few times and make sure our resource count 519 // doesn't increase. 520 LOG(INFO) << "First extension reload"; 521 ReloadExtension(extension->id()); 522 TaskManagerBrowserTestUtil::WaitForWebResourceChange(2); 523 extension = model()->GetResourceExtension(resource_count); 524 ASSERT_TRUE(extension != NULL); 525 526 LOG(INFO) << "Second extension reload"; 527 ReloadExtension(extension->id()); 528 TaskManagerBrowserTestUtil::WaitForWebResourceChange(2); 529 extension = model()->GetResourceExtension(resource_count); 530 ASSERT_TRUE(extension != NULL); 531 532 LOG(INFO) << "Third extension reload"; 533 ReloadExtension(extension->id()); 534 TaskManagerBrowserTestUtil::WaitForWebResourceChange(2); 535} 536 537// Crashy, http://crbug.com/42301. 538IN_PROC_BROWSER_TEST_F(TaskManagerBrowserTest, 539 DISABLED_PopulateWebCacheFields) { 540 int resource_count = TaskManager::GetInstance()->model()->ResourceCount(); 541 542 // Open a new tab and make sure we notice that. 543 GURL url(ui_test_utils::GetTestUrl(base::FilePath( 544 base::FilePath::kCurrentDirectory), base::FilePath(kTitle1File))); 545 AddTabAtIndex(0, url, content::PAGE_TRANSITION_TYPED); 546 TaskManagerBrowserTestUtil::WaitForWebResourceChange(2); 547 548 // Check that we get some value for the cache columns. 549 DCHECK_NE(model()->GetResourceWebCoreImageCacheSize(resource_count), 550 l10n_util::GetStringUTF16(IDS_TASK_MANAGER_NA_CELL_TEXT)); 551 DCHECK_NE(model()->GetResourceWebCoreScriptsCacheSize(resource_count), 552 l10n_util::GetStringUTF16(IDS_TASK_MANAGER_NA_CELL_TEXT)); 553 DCHECK_NE(model()->GetResourceWebCoreCSSCacheSize(resource_count), 554 l10n_util::GetStringUTF16(IDS_TASK_MANAGER_NA_CELL_TEXT)); 555} 556 557// Checks that task manager counts a worker thread JS heap size. 558// http://crbug.com/241066 559IN_PROC_BROWSER_TEST_F(TaskManagerBrowserTest, WebWorkerJSHeapMemory) { 560 GURL url(ui_test_utils::GetTestUrl(base::FilePath( 561 base::FilePath::kCurrentDirectory), base::FilePath(kTitle1File))); 562 ui_test_utils::NavigateToURL(browser(), url); 563 const int extra_timeout_ms = 500; 564 size_t minimal_heap_size = 2 * 1024 * 1024 * sizeof(void*); 565 std::string test_js = base::StringPrintf( 566 "var blob = new Blob([\n" 567 " 'mem = new Array(%lu);',\n" 568 " 'for (var i = 0; i < mem.length; i += 16) mem[i] = i;',\n" 569 " 'postMessage();']);\n" 570 "blobURL = window.URL.createObjectURL(blob);\n" 571 "worker = new Worker(blobURL);\n" 572 "// Give the task manager few seconds to poll for JS heap sizes.\n" 573 "worker.onmessage = setTimeout.bind(\n" 574 " this,\n" 575 " function () { window.domAutomationController.send(true); },\n" 576 " %d);\n" 577 "worker.postMessage();\n", 578 static_cast<unsigned long>(minimal_heap_size), 579 GetUpdateTimeMs() + extra_timeout_ms); 580 bool ok; 581 ASSERT_TRUE(content::ExecuteScriptAndExtractBool( 582 browser()->tab_strip_model()->GetActiveWebContents(), test_js, &ok)); 583 ASSERT_TRUE(ok); 584 585 int resource_index = TaskManager::GetInstance()->model()->ResourceCount() - 1; 586 size_t result; 587 588 ASSERT_TRUE(model()->GetV8Memory(resource_index, &result)); 589 LOG(INFO) << "Got V8 Heap Size " << result << " bytes"; 590 EXPECT_GE(result, minimal_heap_size); 591 592 ASSERT_TRUE(model()->GetV8MemoryUsed(resource_index, &result)); 593 LOG(INFO) << "Got V8 Used Heap Size " << result << " bytes"; 594 EXPECT_GE(result, minimal_heap_size); 595} 596 597#endif 598