| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 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/files/file_path.h" | 7 #include "base/files/file_path.h" |
| 8 #include "base/strings/stringprintf.h" | 8 #include "base/strings/stringprintf.h" |
| 9 #include "base/strings/utf_string_conversions.h" | 9 #include "base/strings/utf_string_conversions.h" |
| 10 #include "chrome/browser/browser_process.h" | 10 #include "chrome/browser/browser_process.h" |
| (...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 112 }; | 112 }; |
| 113 | 113 |
| 114 class TaskManagerBrowserTest : public TaskManagerNoShowBrowserTest { | 114 class TaskManagerBrowserTest : public TaskManagerNoShowBrowserTest { |
| 115 public: | 115 public: |
| 116 TaskManagerBrowserTest() {} | 116 TaskManagerBrowserTest() {} |
| 117 virtual ~TaskManagerBrowserTest() {} | 117 virtual ~TaskManagerBrowserTest() {} |
| 118 | 118 |
| 119 virtual void SetUpOnMainThread() OVERRIDE { | 119 virtual void SetUpOnMainThread() OVERRIDE { |
| 120 TaskManagerNoShowBrowserTest::SetUpOnMainThread(); | 120 TaskManagerNoShowBrowserTest::SetUpOnMainThread(); |
| 121 TaskManagerNoShowBrowserTest::ShowTaskManager(); | 121 TaskManagerNoShowBrowserTest::ShowTaskManager(); |
| 122 |
| 123 // Wait for the InstantNTP prerendered contents to load. |
| 124 content::WindowedNotificationObserver observer( |
| 125 content::NOTIFICATION_LOAD_STOP, |
| 126 content::NotificationService::AllSources()); |
| 127 observer.Wait(); |
| 122 } | 128 } |
| 123 | 129 |
| 124 private: | 130 private: |
| 125 DISALLOW_COPY_AND_ASSIGN(TaskManagerBrowserTest); | 131 DISALLOW_COPY_AND_ASSIGN(TaskManagerBrowserTest); |
| 126 }; | 132 }; |
| 127 | 133 |
| 128 #if defined(OS_MACOSX) || defined(OS_LINUX) | 134 #if defined(OS_MACOSX) || defined(OS_LINUX) |
| 129 #define MAYBE_ShutdownWhileOpen DISABLED_ShutdownWhileOpen | 135 #define MAYBE_ShutdownWhileOpen DISABLED_ShutdownWhileOpen |
| 130 #else | 136 #else |
| 131 #define MAYBE_ShutdownWhileOpen ShutdownWhileOpen | 137 #define MAYBE_ShutdownWhileOpen ShutdownWhileOpen |
| 132 #endif | 138 #endif |
| 133 | 139 |
| 134 // Regression test for http://crbug.com/13361 | 140 // Regression test for http://crbug.com/13361 |
| 135 IN_PROC_BROWSER_TEST_F(TaskManagerBrowserTest, MAYBE_ShutdownWhileOpen) { | 141 IN_PROC_BROWSER_TEST_F(TaskManagerBrowserTest, MAYBE_ShutdownWhileOpen) { |
| 136 // Showing task manager handled by SetUp. | 142 // Showing task manager handled by SetUp. |
| 137 } | 143 } |
| 138 | 144 |
| 139 IN_PROC_BROWSER_TEST_F(TaskManagerBrowserTest, NoticeTabContentsChanges) { | 145 IN_PROC_BROWSER_TEST_F(TaskManagerBrowserTest, NoticeTabContentsChanges) { |
| 140 int resource_count = TaskManager::GetInstance()->model()->ResourceCount(); | 146 int resource_count = TaskManager::GetInstance()->model()->ResourceCount(); |
| 141 // Open a new tab and make sure we notice that. | 147 // Open a new tab and make sure we notice that. |
| 142 GURL url(ui_test_utils::GetTestUrl(base::FilePath( | 148 GURL url(ui_test_utils::GetTestUrl(base::FilePath( |
| 143 base::FilePath::kCurrentDirectory), base::FilePath(kTitle1File))); | 149 base::FilePath::kCurrentDirectory), base::FilePath(kTitle1File))); |
| 144 AddTabAtIndex(0, url, content::PAGE_TRANSITION_TYPED); | 150 AddTabAtIndex(0, url, content::PAGE_TRANSITION_TYPED); |
| 145 TaskManagerBrowserTestUtil::WaitForWebResourceChange(2); | 151 TaskManagerBrowserTestUtil::WaitForWebResourceChange(3); |
| 146 | 152 |
| 147 // Check that the last entry is a tab contents resource whose title starts | 153 // Check that the last entry is a tab contents resource whose title starts |
| 148 // starts with "Tab:". | 154 // starts with "Tab:". |
| 149 ASSERT_TRUE(model()->GetResourceWebContents(resource_count) != NULL); | 155 ASSERT_TRUE(model()->GetResourceWebContents(resource_count) != NULL); |
| 150 string16 prefix = l10n_util::GetStringFUTF16( | 156 string16 prefix = l10n_util::GetStringFUTF16( |
| 151 IDS_TASK_MANAGER_TAB_PREFIX, string16()); | 157 IDS_TASK_MANAGER_TAB_PREFIX, string16()); |
| 152 ASSERT_TRUE(StartsWith(model()->GetResourceTitle(resource_count), prefix, | 158 ASSERT_TRUE(StartsWith(model()->GetResourceTitle(resource_count), prefix, |
| 153 true)); | 159 true)); |
| 154 | 160 |
| 155 // Close the tab and verify that we notice. | 161 // Close the tab and verify that we notice. |
| 156 browser()->tab_strip_model()->CloseWebContentsAt(0, | 162 browser()->tab_strip_model()->CloseWebContentsAt(0, |
| 157 TabStripModel::CLOSE_NONE); | 163 TabStripModel::CLOSE_NONE); |
| 158 TaskManagerBrowserTestUtil::WaitForWebResourceChange(1); | 164 TaskManagerBrowserTestUtil::WaitForWebResourceChange(2); |
| 159 } | 165 } |
| 160 | 166 |
| 161 #if defined(USE_ASH) | 167 #if defined(USE_ASH) |
| 162 // This test fails on Ash because task manager treats view type | 168 // This test fails on Ash because task manager treats view type |
| 163 // Panels differently for Ash. | 169 // Panels differently for Ash. |
| 164 #define MAYBE_NoticePanelChanges DISABLED_NoticePanelChanges | 170 #define MAYBE_NoticePanelChanges DISABLED_NoticePanelChanges |
| 165 #else | 171 #else |
| 166 #define MAYBE_NoticePanelChanges NoticePanelChanges | 172 #define MAYBE_NoticePanelChanges NoticePanelChanges |
| 167 #endif | 173 #endif |
| 168 IN_PROC_BROWSER_TEST_F(TaskManagerBrowserTest, MAYBE_NoticePanelChanges) { | 174 IN_PROC_BROWSER_TEST_F(TaskManagerBrowserTest, MAYBE_NoticePanelChanges) { |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 240 TaskManagerBrowserTestUtil::WaitForWebResourceChange(1); | 246 TaskManagerBrowserTestUtil::WaitForWebResourceChange(1); |
| 241 } | 247 } |
| 242 | 248 |
| 243 IN_PROC_BROWSER_TEST_F(TaskManagerBrowserTest, NoticeExtensionTabs) { | 249 IN_PROC_BROWSER_TEST_F(TaskManagerBrowserTest, NoticeExtensionTabs) { |
| 244 int resource_count = TaskManager::GetInstance()->model()->ResourceCount(); | 250 int resource_count = TaskManager::GetInstance()->model()->ResourceCount(); |
| 245 ASSERT_TRUE(LoadExtension( | 251 ASSERT_TRUE(LoadExtension( |
| 246 test_data_dir_.AppendASCII("good").AppendASCII("Extensions") | 252 test_data_dir_.AppendASCII("good").AppendASCII("Extensions") |
| 247 .AppendASCII("behllobkkfkfnphdnhnkndlbkcpglgmj") | 253 .AppendASCII("behllobkkfkfnphdnhnkndlbkcpglgmj") |
| 248 .AppendASCII("1.0.0.0"))); | 254 .AppendASCII("1.0.0.0"))); |
| 249 | 255 |
| 250 // Browser, Extension background page, and the New Tab Page. | 256 // Browser, Extension background page, and the New Tab Page (visible, |
| 251 TaskManagerBrowserTestUtil::WaitForWebResourceChange(2); | 257 // prerenderd). |
| 258 TaskManagerBrowserTestUtil::WaitForWebResourceChange(3); |
| 252 | 259 |
| 253 // Open a new tab to an extension URL and make sure we notice that. | 260 // Open a new tab to an extension URL and make sure we notice that. |
| 254 GURL url("chrome-extension://behllobkkfkfnphdnhnkndlbkcpglgmj/page.html"); | 261 GURL url("chrome-extension://behllobkkfkfnphdnhnkndlbkcpglgmj/page.html"); |
| 255 AddTabAtIndex(0, url, content::PAGE_TRANSITION_TYPED); | 262 AddTabAtIndex(0, url, content::PAGE_TRANSITION_TYPED); |
| 256 TaskManagerBrowserTestUtil::WaitForWebResourceChange(3); | 263 TaskManagerBrowserTestUtil::WaitForWebResourceChange(4); |
| 257 | 264 |
| 258 // Check that the third entry (background) is an extension resource whose | 265 // Check that the third entry (background) is an extension resource whose |
| 259 // title starts with "Extension:". | 266 // title starts with "Extension:". |
| 260 ASSERT_EQ(task_manager::Resource::EXTENSION, model()->GetResourceType( | 267 ASSERT_EQ(task_manager::Resource::EXTENSION, model()->GetResourceType( |
| 261 resource_count)); | 268 resource_count)); |
| 262 ASSERT_TRUE(model()->GetResourceWebContents(resource_count) == NULL); | 269 ASSERT_TRUE(model()->GetResourceWebContents(resource_count) == NULL); |
| 263 ASSERT_TRUE(model()->GetResourceExtension(resource_count) != NULL); | 270 ASSERT_TRUE(model()->GetResourceExtension(resource_count) != NULL); |
| 264 string16 prefix = l10n_util::GetStringFUTF16( | 271 string16 prefix = l10n_util::GetStringFUTF16( |
| 265 IDS_TASK_MANAGER_EXTENSION_PREFIX, string16()); | 272 IDS_TASK_MANAGER_EXTENSION_PREFIX, string16()); |
| 266 ASSERT_TRUE(StartsWith(model()->GetResourceTitle(resource_count), | 273 ASSERT_TRUE(StartsWith(model()->GetResourceTitle(resource_count), |
| 267 prefix, true)); | 274 prefix, true)); |
| 268 | 275 |
| 269 // Check that the fourth entry (page.html) is of type extension and has both | 276 // Check that the fourth entry (page.html) is of type extension and has both |
| 270 // a tab contents and an extension. The title should start with "Extension:". | 277 // a tab contents and an extension. The title should start with "Extension:". |
| 271 ASSERT_EQ(task_manager::Resource::EXTENSION, model()->GetResourceType( | 278 ASSERT_EQ(task_manager::Resource::EXTENSION, model()->GetResourceType( |
| 272 resource_count + 1)); | 279 resource_count + 1)); |
| 273 ASSERT_TRUE(model()->GetResourceWebContents(resource_count + 1) != NULL); | 280 ASSERT_TRUE(model()->GetResourceWebContents(resource_count + 1) != NULL); |
| 274 ASSERT_TRUE(model()->GetResourceExtension(resource_count + 1) != NULL); | 281 ASSERT_TRUE(model()->GetResourceExtension(resource_count + 1) != NULL); |
| 275 ASSERT_TRUE(StartsWith(model()->GetResourceTitle(resource_count + 1), | 282 ASSERT_TRUE(StartsWith(model()->GetResourceTitle(resource_count + 1), |
| 276 prefix, true)); | 283 prefix, true)); |
| 277 | 284 |
| 278 // Unload extension to avoid crash on Windows. | 285 // Unload extension to avoid crash on Windows. |
| 279 UnloadExtension(last_loaded_extension_id_); | 286 UnloadExtension(last_loaded_extension_id_); |
| 280 TaskManagerBrowserTestUtil::WaitForWebResourceChange(1); | 287 TaskManagerBrowserTestUtil::WaitForWebResourceChange(2); |
| 281 } | 288 } |
| 282 | 289 |
| 283 IN_PROC_BROWSER_TEST_F(TaskManagerBrowserTest, NoticeAppTabs) { | 290 IN_PROC_BROWSER_TEST_F(TaskManagerBrowserTest, NoticeAppTabs) { |
| 284 int resource_count = TaskManager::GetInstance()->model()->ResourceCount(); | 291 int resource_count = TaskManager::GetInstance()->model()->ResourceCount(); |
| 285 ASSERT_TRUE(LoadExtension( | 292 ASSERT_TRUE(LoadExtension( |
| 286 test_data_dir_.AppendASCII("packaged_app"))); | 293 test_data_dir_.AppendASCII("packaged_app"))); |
| 287 ExtensionService* service = extensions::ExtensionSystem::Get( | 294 ExtensionService* service = extensions::ExtensionSystem::Get( |
| 288 browser()->profile())->extension_service(); | 295 browser()->profile())->extension_service(); |
| 289 const extensions::Extension* extension = | 296 const extensions::Extension* extension = |
| 290 service->GetExtensionById(last_loaded_extension_id_, false); | 297 service->GetExtensionById(last_loaded_extension_id_, false); |
| 291 | 298 |
| 292 // New Tab Page. | 299 // New Tab Page (visible and prerendered). |
| 293 TaskManagerBrowserTestUtil::WaitForWebResourceChange(1); | 300 TaskManagerBrowserTestUtil::WaitForWebResourceChange(2); |
| 294 | 301 |
| 295 // Open a new tab to the app's launch URL and make sure we notice that. | 302 // Open a new tab to the app's launch URL and make sure we notice that. |
| 296 GURL url(extension->GetResourceURL("main.html")); | 303 GURL url(extension->GetResourceURL("main.html")); |
| 297 AddTabAtIndex(0, url, content::PAGE_TRANSITION_TYPED); | 304 AddTabAtIndex(0, url, content::PAGE_TRANSITION_TYPED); |
| 298 TaskManagerBrowserTestUtil::WaitForWebResourceChange(2); | 305 TaskManagerBrowserTestUtil::WaitForWebResourceChange(3); |
| 299 | 306 |
| 300 // Check that the third entry (main.html) is of type extension and has both | 307 // Check that the third entry (main.html) is of type extension and has both |
| 301 // a tab contents and an extension. The title should start with "App:". | 308 // a tab contents and an extension. The title should start with "App:". |
| 302 ASSERT_EQ(task_manager::Resource::EXTENSION, model()->GetResourceType( | 309 ASSERT_EQ(task_manager::Resource::EXTENSION, model()->GetResourceType( |
| 303 resource_count)); | 310 resource_count)); |
| 304 ASSERT_TRUE(model()->GetResourceWebContents(resource_count) != NULL); | 311 ASSERT_TRUE(model()->GetResourceWebContents(resource_count) != NULL); |
| 305 ASSERT_TRUE(model()->GetResourceExtension(resource_count) == extension); | 312 ASSERT_TRUE(model()->GetResourceExtension(resource_count) == extension); |
| 306 string16 prefix = l10n_util::GetStringFUTF16( | 313 string16 prefix = l10n_util::GetStringFUTF16( |
| 307 IDS_TASK_MANAGER_APP_PREFIX, string16()); | 314 IDS_TASK_MANAGER_APP_PREFIX, string16()); |
| 308 ASSERT_TRUE(StartsWith(model()->GetResourceTitle(resource_count), | 315 ASSERT_TRUE(StartsWith(model()->GetResourceTitle(resource_count), |
| 309 prefix, true)); | 316 prefix, true)); |
| 310 | 317 |
| 311 // Unload extension to avoid crash on Windows. | 318 // Unload extension to avoid crash on Windows. |
| 312 UnloadExtension(last_loaded_extension_id_); | 319 UnloadExtension(last_loaded_extension_id_); |
| 313 TaskManagerBrowserTestUtil::WaitForWebResourceChange(1); | 320 TaskManagerBrowserTestUtil::WaitForWebResourceChange(2); |
| 314 } | 321 } |
| 315 | 322 |
| 316 IN_PROC_BROWSER_TEST_F(TaskManagerBrowserTest, NoticeHostedAppTabs) { | 323 IN_PROC_BROWSER_TEST_F(TaskManagerBrowserTest, NoticeHostedAppTabs) { |
| 317 int resource_count = TaskManager::GetInstance()->model()->ResourceCount(); | 324 int resource_count = TaskManager::GetInstance()->model()->ResourceCount(); |
| 318 | 325 |
| 319 // The app under test acts on URLs whose host is "localhost", | 326 // The app under test acts on URLs whose host is "localhost", |
| 320 // so the URLs we navigate to must have host "localhost". | 327 // so the URLs we navigate to must have host "localhost". |
| 321 host_resolver()->AddRule("*", "127.0.0.1"); | 328 host_resolver()->AddRule("*", "127.0.0.1"); |
| 322 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady()); | 329 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady()); |
| 323 GURL::Replacements replace_host; | 330 GURL::Replacements replace_host; |
| (...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 412 #define MAYBE_ReloadExtension ReloadExtension | 419 #define MAYBE_ReloadExtension ReloadExtension |
| 413 #endif | 420 #endif |
| 414 | 421 |
| 415 // Regression test for http://crbug.com/18693. | 422 // Regression test for http://crbug.com/18693. |
| 416 IN_PROC_BROWSER_TEST_F(TaskManagerBrowserTest, MAYBE_ReloadExtension) { | 423 IN_PROC_BROWSER_TEST_F(TaskManagerBrowserTest, MAYBE_ReloadExtension) { |
| 417 int resource_count = TaskManager::GetInstance()->model()->ResourceCount(); | 424 int resource_count = TaskManager::GetInstance()->model()->ResourceCount(); |
| 418 LOG(INFO) << "loading extension"; | 425 LOG(INFO) << "loading extension"; |
| 419 ASSERT_TRUE(LoadExtension( | 426 ASSERT_TRUE(LoadExtension( |
| 420 test_data_dir_.AppendASCII("common").AppendASCII("background_page"))); | 427 test_data_dir_.AppendASCII("common").AppendASCII("background_page"))); |
| 421 | 428 |
| 422 // Wait until we see the loaded extension in the task manager (the three | 429 // Wait until we see the loaded extension in the task manager (the four |
| 423 // resources are: the browser process, New Tab Page, and the extension). | 430 // resources are: the browser process, visible and prerendered New Tab Page, |
| 431 // and the extension). |
| 424 LOG(INFO) << "waiting for resource change"; | 432 LOG(INFO) << "waiting for resource change"; |
| 425 TaskManagerBrowserTestUtil::WaitForWebResourceChange(2); | 433 TaskManagerBrowserTestUtil::WaitForWebResourceChange(3); |
| 426 | 434 |
| 427 EXPECT_TRUE(model()->GetResourceExtension(0) == NULL); | 435 EXPECT_TRUE(model()->GetResourceExtension(0) == NULL); |
| 428 EXPECT_TRUE(model()->GetResourceExtension(1) == NULL); | 436 EXPECT_TRUE(model()->GetResourceExtension(1) == NULL); |
| 429 ASSERT_TRUE(model()->GetResourceExtension(resource_count) != NULL); | 437 ASSERT_TRUE(model()->GetResourceExtension(resource_count) != NULL); |
| 430 | 438 |
| 431 const extensions::Extension* extension = model()->GetResourceExtension( | 439 const extensions::Extension* extension = model()->GetResourceExtension( |
| 432 resource_count); | 440 resource_count); |
| 433 ASSERT_TRUE(extension != NULL); | 441 ASSERT_TRUE(extension != NULL); |
| 434 | 442 |
| 435 // Reload the extension a few times and make sure our resource count | 443 // Reload the extension a few times and make sure our resource count |
| 436 // doesn't increase. | 444 // doesn't increase. |
| 437 LOG(INFO) << "First extension reload"; | 445 LOG(INFO) << "First extension reload"; |
| 438 ReloadExtension(extension->id()); | 446 ReloadExtension(extension->id()); |
| 439 TaskManagerBrowserTestUtil::WaitForWebResourceChange(2); | 447 TaskManagerBrowserTestUtil::WaitForWebResourceChange(3); |
| 440 extension = model()->GetResourceExtension(resource_count); | 448 extension = model()->GetResourceExtension(resource_count); |
| 441 ASSERT_TRUE(extension != NULL); | 449 ASSERT_TRUE(extension != NULL); |
| 442 | 450 |
| 443 LOG(INFO) << "Second extension reload"; | 451 LOG(INFO) << "Second extension reload"; |
| 444 ReloadExtension(extension->id()); | 452 ReloadExtension(extension->id()); |
| 445 TaskManagerBrowserTestUtil::WaitForWebResourceChange(2); | 453 TaskManagerBrowserTestUtil::WaitForWebResourceChange(3); |
| 446 extension = model()->GetResourceExtension(resource_count); | 454 extension = model()->GetResourceExtension(resource_count); |
| 447 ASSERT_TRUE(extension != NULL); | 455 ASSERT_TRUE(extension != NULL); |
| 448 | 456 |
| 449 LOG(INFO) << "Third extension reload"; | 457 LOG(INFO) << "Third extension reload"; |
| 450 ReloadExtension(extension->id()); | 458 ReloadExtension(extension->id()); |
| 451 TaskManagerBrowserTestUtil::WaitForWebResourceChange(2); | 459 TaskManagerBrowserTestUtil::WaitForWebResourceChange(3); |
| 452 } | 460 } |
| 453 | 461 |
| 454 // Crashy, http://crbug.com/42301. | 462 // Crashy, http://crbug.com/42301. |
| 455 IN_PROC_BROWSER_TEST_F(TaskManagerBrowserTest, | 463 IN_PROC_BROWSER_TEST_F(TaskManagerBrowserTest, |
| 456 DISABLED_PopulateWebCacheFields) { | 464 DISABLED_PopulateWebCacheFields) { |
| 457 int resource_count = TaskManager::GetInstance()->model()->ResourceCount(); | 465 int resource_count = TaskManager::GetInstance()->model()->ResourceCount(); |
| 458 | 466 |
| 459 // Open a new tab and make sure we notice that. | 467 // Open a new tab and make sure we notice that. |
| 460 GURL url(ui_test_utils::GetTestUrl(base::FilePath( | 468 GURL url(ui_test_utils::GetTestUrl(base::FilePath( |
| 461 base::FilePath::kCurrentDirectory), base::FilePath(kTitle1File))); | 469 base::FilePath::kCurrentDirectory), base::FilePath(kTitle1File))); |
| (...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 540 // Now add showing the task manager to the queue, and watch for the right | 548 // Now add showing the task manager to the queue, and watch for the right |
| 541 // number of reources to show up. | 549 // number of reources to show up. |
| 542 base::MessageLoop::current()->PostTask( | 550 base::MessageLoop::current()->PostTask( |
| 543 FROM_HERE, | 551 FROM_HERE, |
| 544 base::Bind(&TaskManagerNoShowBrowserTest::ShowTaskManager, | 552 base::Bind(&TaskManagerNoShowBrowserTest::ShowTaskManager, |
| 545 base::Unretained(this))); | 553 base::Unretained(this))); |
| 546 TaskManagerBrowserTestUtil::WaitForWebResourceChange(2); | 554 TaskManagerBrowserTestUtil::WaitForWebResourceChange(2); |
| 547 } | 555 } |
| 548 | 556 |
| 549 #endif | 557 #endif |
| OLD | NEW |