diff options
author | atwilson@chromium.org <atwilson@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-05-04 01:17:27 +0000 |
---|---|---|
committer | atwilson@chromium.org <atwilson@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-05-04 01:17:27 +0000 |
commit | 88ea00fc725ef255d550faeb30e268922afa6e24 (patch) | |
tree | f7bdb398876faadc985566f0f5df685332ba7be6 /chrome/browser/extensions/app_background_page_apitest.cc | |
parent | 8cffde0ee3ef1f115d8e37e2c34daba3d6b06f64 (diff) | |
download | chromium_src-88ea00fc725ef255d550faeb30e268922afa6e24.zip chromium_src-88ea00fc725ef255d550faeb30e268922afa6e24.tar.gz chromium_src-88ea00fc725ef255d550faeb30e268922afa6e24.tar.bz2 |
No longer start BG mode until a BackgroundContents is loaded
BUG=120448
TEST=Install hosted app, ensure it does not kick off background mode until it opens a background contents via JS.
Review URL: http://codereview.chromium.org/10298002
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@135264 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/extensions/app_background_page_apitest.cc')
-rw-r--r-- | chrome/browser/extensions/app_background_page_apitest.cc | 87 |
1 files changed, 87 insertions, 0 deletions
diff --git a/chrome/browser/extensions/app_background_page_apitest.cc b/chrome/browser/extensions/app_background_page_apitest.cc index 8b4a7b3..69cbc95 100644 --- a/chrome/browser/extensions/app_background_page_apitest.cc +++ b/chrome/browser/extensions/app_background_page_apitest.cc @@ -6,6 +6,8 @@ #include "base/utf_string_conversions.h" #include "chrome/browser/background/background_contents_service.h" #include "chrome/browser/background/background_contents_service_factory.h" +#include "chrome/browser/background/background_mode_manager.h" +#include "chrome/browser/browser_process.h" #include "chrome/browser/extensions/extension_apitest.h" #include "chrome/browser/extensions/extension_service.h" #include "chrome/browser/profiles/profile.h" @@ -14,6 +16,7 @@ #include "chrome/common/chrome_switches.h" #include "chrome/common/extensions/extension.h" #include "chrome/test/base/ui_test_utils.h" +#include "content/public/browser/notification_service.h" #include "content/test/test_notification_tracker.h" #include "net/base/mock_host_resolver.h" @@ -44,6 +47,33 @@ class AppBackgroundPageApiTest : public ExtensionApiTest { return true; } + bool WaitForBackgroundMode(bool expected_background_mode) { +#if defined(OS_CHROMEOS) + // BackgroundMode is not supported on chromeos, so we should test the + // behavior of BackgroundContents, but not the background mode state itself. + return true; +#else + BackgroundModeManager* manager = + g_browser_process->background_mode_manager(); + // If background mode is disabled on this platform (e.g. cros), then skip + // this check. + if (!manager || !manager->IsBackgroundModePrefEnabled()) { + DLOG(WARNING) << "Skipping check - background mode disabled"; + return true; + } + if (manager->IsBackgroundModeActiveForTest() == expected_background_mode) + return true; + + // We are not currently in the expected state - wait for the state to + // change. + ui_test_utils::WindowedNotificationObserver watcher( + chrome::NOTIFICATION_BACKGROUND_MODE_CHANGED, + content::NotificationService::AllSources()); + watcher.Wait(); + return manager->IsBackgroundModeActiveForTest() == expected_background_mode; +#endif + } + private: ScopedTempDir app_dir_; }; @@ -79,7 +109,12 @@ IN_PROC_BROWSER_TEST_F(AppBackgroundPageApiTest, MAYBE_Basic) { FilePath app_dir; ASSERT_TRUE(CreateApp(app_manifest, &app_dir)); ASSERT_TRUE(LoadExtension(app_dir)); + // Background mode should not be active until a background page is created. + ASSERT_TRUE(WaitForBackgroundMode(false)); ASSERT_TRUE(RunExtensionTest("app_background_page/basic")) << message_; + // The test closes the background contents, so we should fall back to no + // background mode at the end. + ASSERT_TRUE(WaitForBackgroundMode(false)); } // Crashy, http://crbug.com/69215. @@ -108,6 +143,7 @@ IN_PROC_BROWSER_TEST_F(AppBackgroundPageApiTest, DISABLED_LacksPermission) { ASSERT_TRUE(LoadExtension(app_dir)); ASSERT_TRUE(RunExtensionTest("app_background_page/lacks_permission")) << message_; + ASSERT_TRUE(WaitForBackgroundMode(false)); } IN_PROC_BROWSER_TEST_F(AppBackgroundPageApiTest, ManifestBackgroundPage) { @@ -137,7 +173,12 @@ IN_PROC_BROWSER_TEST_F(AppBackgroundPageApiTest, ManifestBackgroundPage) { FilePath app_dir; ASSERT_TRUE(CreateApp(app_manifest, &app_dir)); + // Background mode should not be active now because no background app was + // loaded. ASSERT_TRUE(LoadExtension(app_dir)); + // Background mode be active now because a background page was created when + // the app was loaded. + ASSERT_TRUE(WaitForBackgroundMode(true)); const Extension* extension = GetSingleLoadedExtension(); ASSERT_TRUE( @@ -323,3 +364,49 @@ IN_PROC_BROWSER_TEST_F(AppBackgroundPageApiTest, DISABLED_OpenPopupFromBGPage) { ASSERT_TRUE(LoadExtension(app_dir)); ASSERT_TRUE(RunExtensionTest("app_background_page/bg_open")) << message_; } + +IN_PROC_BROWSER_TEST_F(AppBackgroundPageApiTest, OpenThenClose) { + host_resolver()->AddRule("a.com", "127.0.0.1"); + ASSERT_TRUE(StartTestServer()); + + std::string app_manifest = base::StringPrintf( + "{" + " \"name\": \"App\"," + " \"version\": \"0.1\"," + " \"manifest_version\": 2," + " \"app\": {" + " \"urls\": [" + " \"http://a.com/\"" + " ]," + " \"launch\": {" + " \"web_url\": \"http://a.com:%d/\"" + " }" + " }," + " \"permissions\": [\"background\"]" + "}", + test_server()->host_port_pair().port()); + + FilePath app_dir; + ASSERT_TRUE(CreateApp(app_manifest, &app_dir)); + ASSERT_TRUE(LoadExtension(app_dir)); + // There isn't a background page loaded initially. + const Extension* extension = GetSingleLoadedExtension(); + ASSERT_FALSE( + BackgroundContentsServiceFactory::GetForProfile(browser()->profile())-> + GetAppBackgroundContents(ASCIIToUTF16(extension->id()))); + // Background mode should not be active until a background page is created. + ASSERT_TRUE(WaitForBackgroundMode(false)); + ASSERT_TRUE(RunExtensionTest("app_background_page/basic_open")) << message_; + // Background mode should be active now because a background page was created. + ASSERT_TRUE(WaitForBackgroundMode(true)); + ASSERT_TRUE( + BackgroundContentsServiceFactory::GetForProfile(browser()->profile())-> + GetAppBackgroundContents(ASCIIToUTF16(extension->id()))); + // Now close the BackgroundContents. + ASSERT_TRUE(RunExtensionTest("app_background_page/basic_close")) << message_; + // Background mode should no longer be active. + ASSERT_TRUE(WaitForBackgroundMode(false)); + ASSERT_FALSE( + BackgroundContentsServiceFactory::GetForProfile(browser()->profile())-> + GetAppBackgroundContents(ASCIIToUTF16(extension->id()))); +} |