| 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 "chrome/browser/background/background_contents_service.h" | 11 #include "chrome/browser/background/background_contents_service.h" |
| 12 #include "chrome/browser/background/background_contents_service_factory.h" | 12 #include "chrome/browser/background/background_contents_service_factory.h" |
| 13 #include "chrome/browser/background/background_mode_manager.h" | 13 #include "chrome/browser/background/background_mode_manager.h" |
| 14 #include "chrome/browser/browser_process.h" | 14 #include "chrome/browser/browser_process.h" |
| 15 #include "chrome/browser/chrome_notification_types.h" | |
| 16 #include "chrome/browser/extensions/extension_apitest.h" | 15 #include "chrome/browser/extensions/extension_apitest.h" |
| 17 #include "chrome/browser/extensions/extension_service.h" | 16 #include "chrome/browser/extensions/extension_service.h" |
| 18 #include "chrome/browser/profiles/profile.h" | 17 #include "chrome/browser/profiles/profile.h" |
| 19 #include "chrome/browser/ui/browser.h" | 18 #include "chrome/browser/ui/browser.h" |
| 20 #include "chrome/browser/ui/browser_dialogs.h" | 19 #include "chrome/browser/ui/browser_dialogs.h" |
| 21 #include "chrome/browser/ui/browser_window.h" | 20 #include "chrome/browser/ui/browser_window.h" |
| 22 #include "chrome/browser/ui/extensions/application_launch.h" | 21 #include "chrome/browser/ui/extensions/application_launch.h" |
| 23 #include "chrome/common/chrome_paths.h" | 22 #include "chrome/common/chrome_paths.h" |
| 24 #include "chrome/common/chrome_switches.h" | 23 #include "chrome/common/chrome_switches.h" |
| 25 #include "content/public/browser/notification_service.h" | 24 #include "content/public/browser/notification_service.h" |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 90 // We are not currently in the expected state - wait for the state to | 89 // We are not currently in the expected state - wait for the state to |
| 91 // change. | 90 // change. |
| 92 content::WindowedNotificationObserver watcher( | 91 content::WindowedNotificationObserver watcher( |
| 93 chrome::NOTIFICATION_BACKGROUND_MODE_CHANGED, | 92 chrome::NOTIFICATION_BACKGROUND_MODE_CHANGED, |
| 94 content::NotificationService::AllSources()); | 93 content::NotificationService::AllSources()); |
| 95 watcher.Wait(); | 94 watcher.Wait(); |
| 96 return manager->IsBackgroundModeActive() == expected_background_mode; | 95 return manager->IsBackgroundModeActive() == expected_background_mode; |
| 97 #endif | 96 #endif |
| 98 } | 97 } |
| 99 | 98 |
| 100 void CloseBrowser(Browser* browser) { | |
| 101 content::WindowedNotificationObserver observer( | |
| 102 chrome::NOTIFICATION_BROWSER_CLOSED, | |
| 103 content::NotificationService::AllSources()); | |
| 104 browser->window()->Close(); | |
| 105 #if defined(OS_MACOSX) | |
| 106 // BrowserWindowController depends on the auto release pool being recycled | |
| 107 // in the message loop to delete itself, which frees the Browser object | |
| 108 // which fires this event. | |
| 109 AutoreleasePool()->Recycle(); | |
| 110 #endif | |
| 111 observer.Wait(); | |
| 112 } | |
| 113 | |
| 114 void UnloadExtensionViaTask(const std::string& id) { | 99 void UnloadExtensionViaTask(const std::string& id) { |
| 115 base::ThreadTaskRunnerHandle::Get()->PostTask( | 100 base::ThreadTaskRunnerHandle::Get()->PostTask( |
| 116 FROM_HERE, | 101 FROM_HERE, |
| 117 base::Bind(&AppBackgroundPageApiTest::UnloadExtension, this, id)); | 102 base::Bind(&AppBackgroundPageApiTest::UnloadExtension, this, id)); |
| 118 } | 103 } |
| 119 | 104 |
| 120 private: | 105 private: |
| 121 base::ScopedTempDir app_dir_; | 106 base::ScopedTempDir app_dir_; |
| 122 }; | 107 }; |
| 123 | 108 |
| (...skipping 463 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 587 // the app was loaded. | 572 // the app was loaded. |
| 588 ASSERT_TRUE(WaitForBackgroundMode(true)); | 573 ASSERT_TRUE(WaitForBackgroundMode(true)); |
| 589 | 574 |
| 590 const Extension* extension = GetSingleLoadedExtension(); | 575 const Extension* extension = GetSingleLoadedExtension(); |
| 591 ASSERT_TRUE( | 576 ASSERT_TRUE( |
| 592 BackgroundContentsServiceFactory::GetForProfile(browser()->profile())-> | 577 BackgroundContentsServiceFactory::GetForProfile(browser()->profile())-> |
| 593 GetAppBackgroundContents(ASCIIToUTF16(extension->id()))); | 578 GetAppBackgroundContents(ASCIIToUTF16(extension->id()))); |
| 594 | 579 |
| 595 // Close all browsers - app should continue running. | 580 // Close all browsers - app should continue running. |
| 596 set_exit_when_last_browser_closes(false); | 581 set_exit_when_last_browser_closes(false); |
| 597 CloseBrowser(browser()); | 582 CloseBrowserSynchronously(browser()); |
| 598 | 583 |
| 599 // Post a task to unload the extension - this should cause Chrome to exit | 584 // Post a task to unload the extension - this should cause Chrome to exit |
| 600 // cleanly (not crash). | 585 // cleanly (not crash). |
| 601 UnloadExtensionViaTask(extension->id()); | 586 UnloadExtensionViaTask(extension->id()); |
| 602 content::RunAllPendingInMessageLoop(); | 587 content::RunAllPendingInMessageLoop(); |
| 603 ASSERT_TRUE(WaitForBackgroundMode(false)); | 588 ASSERT_TRUE(WaitForBackgroundMode(false)); |
| 604 } | 589 } |
| 605 | 590 |
| 606 // Verify active NaCl embeds cause many keepalive impulses to be sent. | 591 // Verify active NaCl embeds cause many keepalive impulses to be sent. |
| 607 // Disabled on Windows due to flakiness: http://crbug.com/346278 | 592 // Disabled on Windows due to flakiness: http://crbug.com/346278 |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 647 extensions::ProcessManager::Get(browser()->profile()); | 632 extensions::ProcessManager::Get(browser()->profile()); |
| 648 ImpulseCallbackCounter idle_impulse_counter(manager, extension()->id()); | 633 ImpulseCallbackCounter idle_impulse_counter(manager, extension()->id()); |
| 649 EXPECT_TRUE(nacl_modules_loaded.WaitUntilSatisfied()); | 634 EXPECT_TRUE(nacl_modules_loaded.WaitUntilSatisfied()); |
| 650 | 635 |
| 651 manager->SetKeepaliveImpulseDecrementCallbackForTesting( | 636 manager->SetKeepaliveImpulseDecrementCallbackForTesting( |
| 652 idle_impulse_counter.SetGoalAndGetCallback(1)); | 637 idle_impulse_counter.SetGoalAndGetCallback(1)); |
| 653 nacl_modules_loaded.Reply("be idle"); | 638 nacl_modules_loaded.Reply("be idle"); |
| 654 idle_impulse_counter.Wait(); | 639 idle_impulse_counter.Wait(); |
| 655 #endif | 640 #endif |
| 656 } | 641 } |
| OLD | NEW |