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 "base/location.h" | 5 #include "base/location.h" |
6 #include "base/path_service.h" | 6 #include "base/path_service.h" |
7 #include "base/single_thread_task_runner.h" | 7 #include "base/single_thread_task_runner.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 "base/thread_task_runner_handle.h" | 10 #include "base/thread_task_runner_handle.h" |
11 #include "build/build_config.h" | 11 #include "build/build_config.h" |
12 #include "chrome/browser/background/background_contents_service.h" | 12 #include "chrome/browser/background/background_contents_service.h" |
13 #include "chrome/browser/background/background_contents_service_factory.h" | 13 #include "chrome/browser/background/background_contents_service_factory.h" |
14 #include "chrome/browser/background/background_mode_manager.h" | 14 #include "chrome/browser/background/background_mode_manager.h" |
15 #include "chrome/browser/browser_process.h" | 15 #include "chrome/browser/browser_process.h" |
16 #include "chrome/browser/extensions/extension_apitest.h" | 16 #include "chrome/browser/extensions/extension_apitest.h" |
17 #include "chrome/browser/extensions/extension_service.h" | 17 #include "chrome/browser/extensions/extension_service.h" |
18 #include "chrome/browser/profiles/profile.h" | 18 #include "chrome/browser/profiles/profile.h" |
19 #include "chrome/browser/task_manager/task_manager_browsertest_util.h" | |
20 #include "chrome/browser/ui/browser.h" | 19 #include "chrome/browser/ui/browser.h" |
21 #include "chrome/browser/ui/browser_dialogs.h" | 20 #include "chrome/browser/ui/browser_dialogs.h" |
22 #include "chrome/browser/ui/browser_window.h" | 21 #include "chrome/browser/ui/browser_window.h" |
23 #include "chrome/browser/ui/extensions/application_launch.h" | 22 #include "chrome/browser/ui/extensions/application_launch.h" |
24 #include "chrome/common/chrome_paths.h" | 23 #include "chrome/common/chrome_paths.h" |
25 #include "chrome/common/chrome_switches.h" | 24 #include "chrome/common/chrome_switches.h" |
26 #include "content/public/browser/notification_service.h" | 25 #include "content/public/browser/notification_service.h" |
27 #include "content/public/test/test_notification_tracker.h" | 26 #include "content/public/test/test_notification_tracker.h" |
28 #include "content/public/test/test_utils.h" | 27 #include "content/public/test/test_utils.h" |
29 #include "extensions/browser/process_manager.h" | 28 #include "extensions/browser/process_manager.h" |
30 #include "extensions/common/extension.h" | 29 #include "extensions/common/extension.h" |
31 #include "extensions/common/switches.h" | 30 #include "extensions/common/switches.h" |
32 #include "extensions/test/extension_test_message_listener.h" | 31 #include "extensions/test/extension_test_message_listener.h" |
33 #include "net/dns/mock_host_resolver.h" | 32 #include "net/dns/mock_host_resolver.h" |
34 #include "net/test/embedded_test_server/embedded_test_server.h" | 33 #include "net/test/embedded_test_server/embedded_test_server.h" |
35 | 34 |
36 #if !defined(DISABLE_NACL) | 35 #if !defined(DISABLE_NACL) |
37 #include "components/nacl/browser/nacl_process_host.h" | 36 #include "components/nacl/browser/nacl_process_host.h" |
38 #endif | 37 #endif |
39 | 38 |
40 #if defined(OS_MACOSX) | 39 #if defined(OS_MACOSX) |
41 #include "base/mac/scoped_nsautorelease_pool.h" | 40 #include "base/mac/scoped_nsautorelease_pool.h" |
| 41 #include "chrome/browser/task_manager/task_manager_browsertest_util.h" |
42 #endif | 42 #endif |
43 | 43 |
44 using base::ASCIIToUTF16; | 44 using base::ASCIIToUTF16; |
45 using extensions::Extension; | 45 using extensions::Extension; |
46 | 46 |
47 class AppBackgroundPageApiTest : public ExtensionApiTest { | 47 class AppBackgroundPageApiTest : public ExtensionApiTest { |
48 public: | 48 public: |
49 void SetUpCommandLine(base::CommandLine* command_line) override { | 49 void SetUpCommandLine(base::CommandLine* command_line) override { |
50 ExtensionApiTest::SetUpCommandLine(command_line); | 50 ExtensionApiTest::SetUpCommandLine(command_line); |
51 command_line->AppendSwitch(switches::kDisablePopupBlocking); | 51 command_line->AppendSwitch(switches::kDisablePopupBlocking); |
(...skipping 245 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
297 // the app was loaded. | 297 // the app was loaded. |
298 ASSERT_TRUE(WaitForBackgroundMode(true)); | 298 ASSERT_TRUE(WaitForBackgroundMode(true)); |
299 | 299 |
300 const Extension* extension = GetSingleLoadedExtension(); | 300 const Extension* extension = GetSingleLoadedExtension(); |
301 ASSERT_TRUE( | 301 ASSERT_TRUE( |
302 BackgroundContentsServiceFactory::GetForProfile(browser()->profile())-> | 302 BackgroundContentsServiceFactory::GetForProfile(browser()->profile())-> |
303 GetAppBackgroundContents(ASCIIToUTF16(extension->id()))); | 303 GetAppBackgroundContents(ASCIIToUTF16(extension->id()))); |
304 UnloadExtension(extension->id()); | 304 UnloadExtension(extension->id()); |
305 } | 305 } |
306 | 306 |
| 307 // Old task manager browser tests should only run on Mac. |
| 308 #if defined(OS_MACOSX) |
307 IN_PROC_BROWSER_TEST_F(AppBackgroundPageApiTest, NoJsBackgroundPage) { | 309 IN_PROC_BROWSER_TEST_F(AppBackgroundPageApiTest, NoJsBackgroundPage) { |
308 // Keep the task manager up through this test to verify that a crash doesn't | 310 // Keep the task manager up through this test to verify that a crash doesn't |
309 // happen when window.open creates a background page that switches | 311 // happen when window.open creates a background page that switches |
310 // RenderViewHosts. See http://crbug.com/165138. | 312 // RenderViewHosts. See http://crbug.com/165138. |
311 // This test is for the old implementation of the task manager. We must | |
312 // explicitly disable the new one. | |
313 task_manager::browsertest_util::EnableOldTaskManager(); | |
314 chrome::ShowTaskManager(browser()); | 313 chrome::ShowTaskManager(browser()); |
315 | 314 |
316 // Make sure that no BackgroundContentses get deleted (a signal that repeated | 315 // Make sure that no BackgroundContentses get deleted (a signal that repeated |
317 // window.open calls recreate instances, instead of being no-ops). | 316 // window.open calls recreate instances, instead of being no-ops). |
318 content::TestNotificationTracker background_deleted_tracker; | 317 content::TestNotificationTracker background_deleted_tracker; |
319 background_deleted_tracker.ListenFor( | 318 background_deleted_tracker.ListenFor( |
320 chrome::NOTIFICATION_BACKGROUND_CONTENTS_DELETED, | 319 chrome::NOTIFICATION_BACKGROUND_CONTENTS_DELETED, |
321 content::Source<Profile>(browser()->profile())); | 320 content::Source<Profile>(browser()->profile())); |
322 | 321 |
323 host_resolver()->AddRule("a.com", "127.0.0.1"); | 322 host_resolver()->AddRule("a.com", "127.0.0.1"); |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
355 // The test makes sure that window.open returns null. | 354 // The test makes sure that window.open returns null. |
356 ASSERT_TRUE(RunExtensionTest("app_background_page/no_js")) << message_; | 355 ASSERT_TRUE(RunExtensionTest("app_background_page/no_js")) << message_; |
357 // And after it runs there should be a background page. | 356 // And after it runs there should be a background page. |
358 ASSERT_TRUE( | 357 ASSERT_TRUE( |
359 BackgroundContentsServiceFactory::GetForProfile(browser()->profile())-> | 358 BackgroundContentsServiceFactory::GetForProfile(browser()->profile())-> |
360 GetAppBackgroundContents(ASCIIToUTF16(extension->id()))); | 359 GetAppBackgroundContents(ASCIIToUTF16(extension->id()))); |
361 | 360 |
362 EXPECT_EQ(0u, background_deleted_tracker.size()); | 361 EXPECT_EQ(0u, background_deleted_tracker.size()); |
363 UnloadExtension(extension->id()); | 362 UnloadExtension(extension->id()); |
364 } | 363 } |
| 364 #endif // defined(OS_MACOSX) |
365 | 365 |
366 IN_PROC_BROWSER_TEST_F(AppBackgroundPageApiTest, NoJsManifestBackgroundPage) { | 366 IN_PROC_BROWSER_TEST_F(AppBackgroundPageApiTest, NoJsManifestBackgroundPage) { |
367 host_resolver()->AddRule("a.com", "127.0.0.1"); | 367 host_resolver()->AddRule("a.com", "127.0.0.1"); |
368 ASSERT_TRUE(StartEmbeddedTestServer()); | 368 ASSERT_TRUE(StartEmbeddedTestServer()); |
369 | 369 |
370 std::string app_manifest = base::StringPrintf( | 370 std::string app_manifest = base::StringPrintf( |
371 "{" | 371 "{" |
372 " \"name\": \"App\"," | 372 " \"name\": \"App\"," |
373 " \"version\": \"0.1\"," | 373 " \"version\": \"0.1\"," |
374 " \"manifest_version\": 2," | 374 " \"manifest_version\": 2," |
(...skipping 262 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
637 extensions::ProcessManager::Get(browser()->profile()); | 637 extensions::ProcessManager::Get(browser()->profile()); |
638 ImpulseCallbackCounter idle_impulse_counter(manager, extension()->id()); | 638 ImpulseCallbackCounter idle_impulse_counter(manager, extension()->id()); |
639 EXPECT_TRUE(nacl_modules_loaded.WaitUntilSatisfied()); | 639 EXPECT_TRUE(nacl_modules_loaded.WaitUntilSatisfied()); |
640 | 640 |
641 manager->SetKeepaliveImpulseDecrementCallbackForTesting( | 641 manager->SetKeepaliveImpulseDecrementCallbackForTesting( |
642 idle_impulse_counter.SetGoalAndGetCallback(1)); | 642 idle_impulse_counter.SetGoalAndGetCallback(1)); |
643 nacl_modules_loaded.Reply("be idle"); | 643 nacl_modules_loaded.Reply("be idle"); |
644 idle_impulse_counter.Wait(); | 644 idle_impulse_counter.Wait(); |
645 #endif | 645 #endif |
646 } | 646 } |
OLD | NEW |