| Index: chrome/browser/extensions/app_background_page_apitest.cc
|
| diff --git a/chrome/browser/extensions/app_background_page_apitest.cc b/chrome/browser/extensions/app_background_page_apitest.cc
|
| index 8b4a7b347c1ce5ec15b077c04301f3deca5f4695..0c33c01001f523b7b7bd2eb3b9643f9cf8ffbc89 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"
|
| @@ -44,6 +46,18 @@ class AppBackgroundPageApiTest : public ExtensionApiTest {
|
| return true;
|
| }
|
|
|
| + bool CheckBackgroundMode(bool expected_background_mode) {
|
| + 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;
|
| + }
|
| + return manager->IsBackgroundModeActiveForTest() == expected_background_mode;
|
| + }
|
| +
|
| private:
|
| ScopedTempDir app_dir_;
|
| };
|
| @@ -79,7 +93,11 @@ 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(CheckBackgroundMode(false));
|
| ASSERT_TRUE(RunExtensionTest("app_background_page/basic")) << message_;
|
| + // Background mode should be active now because a background page was created.
|
| + ASSERT_TRUE(CheckBackgroundMode(true));
|
| }
|
|
|
| // Crashy, http://crbug.com/69215.
|
| @@ -108,6 +126,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(CheckBackgroundMode(false));
|
| }
|
|
|
| IN_PROC_BROWSER_TEST_F(AppBackgroundPageApiTest, ManifestBackgroundPage) {
|
| @@ -137,7 +156,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(CheckBackgroundMode(true));
|
|
|
| const Extension* extension = GetSingleLoadedExtension();
|
| ASSERT_TRUE(
|
| @@ -323,3 +347,46 @@ 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(CheckBackgroundMode(false));
|
| + ASSERT_TRUE(RunExtensionTest("app_background_page/basic")) << message_;
|
| + // Background mode should be active now because a background page was created.
|
| + ASSERT_TRUE(CheckBackgroundMode(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(CheckBackgroundMode(false));
|
| +}
|
|
|