Commit 10befff7 authored by tmdiep@chromium.org's avatar tmdiep@chromium.org

Ephemeral apps should not trigger Chrome background mode

Ephemeral apps should not trigger Chrome background mode and the
"New background app added" notification bubble should not be
displayed when they are launched as they do not have background
activity after they are closed.

BUG=339001
TEST=unit_tests

Review URL: https://codereview.chromium.org/383113002

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@285539 0039d316-1c4b-4281-b951-d872f2087c98
parent 7281a3fb
...@@ -25,6 +25,7 @@ ...@@ -25,6 +25,7 @@
#include "extensions/browser/extension_prefs.h" #include "extensions/browser/extension_prefs.h"
#include "extensions/browser/extension_registry.h" #include "extensions/browser/extension_registry.h"
#include "extensions/browser/extension_system.h" #include "extensions/browser/extension_system.h"
#include "extensions/browser/extension_util.h"
#include "extensions/browser/image_loader.h" #include "extensions/browser/image_loader.h"
#include "extensions/common/extension.h" #include "extensions/common/extension.h"
#include "extensions/common/extension_icon_set.h" #include "extensions/common/extension_icon_set.h"
...@@ -310,6 +311,11 @@ bool BackgroundApplicationListModel::IsBackgroundApp( ...@@ -310,6 +311,11 @@ bool BackgroundApplicationListModel::IsBackgroundApp(
// 2) It is a hosted app, and has a background contents registered or in the // 2) It is a hosted app, and has a background contents registered or in the
// manifest. // manifest.
// Ephemeral apps are denied any background activity after their event page
// has been destroyed, thus they cannot be background apps.
if (extensions::util::IsEphemeralApp(extension.id(), profile))
return false;
// Not a background app if we don't have the background permission or // Not a background app if we don't have the background permission or
// the push messaging permission // the push messaging permission
if (!extension.permissions_data()->HasAPIPermission( if (!extension.permissions_data()->HasAPIPermission(
......
...@@ -20,6 +20,7 @@ ...@@ -20,6 +20,7 @@
#include "chrome/test/base/testing_profile.h" #include "chrome/test/base/testing_profile.h"
#include "content/public/browser/notification_registrar.h" #include "content/public/browser/notification_registrar.h"
#include "content/public/browser/notification_types.h" #include "content/public/browser/notification_types.h"
#include "extensions/browser/extension_prefs.h"
#include "extensions/browser/extension_system.h" #include "extensions/browser/extension_system.h"
#include "extensions/browser/uninstall_reason.h" #include "extensions/browser/uninstall_reason.h"
#include "extensions/common/extension.h" #include "extensions/common/extension.h"
...@@ -156,6 +157,20 @@ void RemoveBackgroundPermission(ExtensionService* service, ...@@ -156,6 +157,20 @@ void RemoveBackgroundPermission(ExtensionService* service,
extensions::PermissionsUpdater(service->profile()).RemovePermissions( extensions::PermissionsUpdater(service->profile()).RemovePermissions(
extension, extension->permissions_data()->active_permissions().get()); extension, extension->permissions_data()->active_permissions().get());
} }
void AddEphemeralApp(const Extension* extension, ExtensionService* service) {
extensions::ExtensionPrefs* prefs =
extensions::ExtensionPrefs::Get(service->profile());
ASSERT_TRUE(prefs);
prefs->OnExtensionInstalled(extension,
extensions::Extension::ENABLED,
syncer::StringOrdinal(),
extensions::kInstallFlagIsEphemeral,
std::string());
service->AddExtension(extension);
}
} // namespace } // namespace
// Crashes on Mac tryslaves. // Crashes on Mac tryslaves.
...@@ -316,7 +331,50 @@ TEST_F(BackgroundApplicationListModelTest, PushMessagingTest) { ...@@ -316,7 +331,50 @@ TEST_F(BackgroundApplicationListModelTest, PushMessagingTest) {
ASSERT_EQ(0U, model->size()); ASSERT_EQ(0U, model->size());
} }
// Verifies that an ephemeral app cannot trigger background mode.
TEST_F(BackgroundApplicationListModelTest, EphemeralAppTest) {
InitializeAndLoadEmptyExtensionService();
ExtensionService* service = extensions::ExtensionSystem::Get(profile_.get())->
extension_service();
ASSERT_TRUE(service);
ASSERT_TRUE(service->is_ready());
ASSERT_TRUE(service->extensions());
ASSERT_TRUE(service->extensions()->is_empty());
scoped_ptr<BackgroundApplicationListModel> model(
new BackgroundApplicationListModel(profile_.get()));
ASSERT_EQ(0U, model->size());
scoped_refptr<Extension> installed =
CreateExtensionBase("installed", false, PUSH_MESSAGING_PERMISSION);
scoped_refptr<Extension> ephemeral =
CreateExtensionBase("ephemeral", false, PUSH_MESSAGING_PERMISSION);
scoped_refptr<Extension> background = CreateExtension("background", true);
// Installed app with push messaging permissions can trigger background mode.
ASSERT_TRUE(IsBackgroundApp(*installed.get()));
service->AddExtension(installed.get());
ASSERT_EQ(1U, service->extensions()->size());
ASSERT_EQ(1U, model->size());
// An ephemeral app with push messaging permissions should not trigger
// background mode.
AddEphemeralApp(ephemeral.get(), service);
ASSERT_FALSE(IsBackgroundApp(*ephemeral.get()));
ASSERT_EQ(2U, service->extensions()->size());
ASSERT_EQ(1U, model->size());
// An ephemeral app with the background permission should not trigger
// background mode.
AddEphemeralApp(background.get(), service);
ASSERT_FALSE(IsBackgroundApp(*background.get()));
ASSERT_EQ(3U, service->extensions()->size());
ASSERT_EQ(1U, model->size());
// If the ephemeral app becomes promoted to an installed app, it can now
// trigger background mode.
service->PromoteEphemeralApp(ephemeral.get(), false /*from sync*/);
ASSERT_TRUE(IsBackgroundApp(*ephemeral.get()));
ASSERT_EQ(3U, service->extensions()->size());
ASSERT_EQ(2U, model->size());
}
// With minimal test logic, verifies behavior with dynamic permissions. // With minimal test logic, verifies behavior with dynamic permissions.
TEST_F(BackgroundApplicationListModelTest, AddRemovePermissionsTest) { TEST_F(BackgroundApplicationListModelTest, AddRemovePermissionsTest) {
......
...@@ -19,6 +19,7 @@ ...@@ -19,6 +19,7 @@
#include "chrome/test/base/testing_profile.h" #include "chrome/test/base/testing_profile.h"
#include "chrome/test/base/testing_profile_manager.h" #include "chrome/test/base/testing_profile_manager.h"
#include "content/public/test/test_browser_thread_bundle.h" #include "content/public/test/test_browser_thread_bundle.h"
#include "extensions/browser/extension_prefs.h"
#include "extensions/browser/extension_system.h" #include "extensions/browser/extension_system.h"
#include "testing/gtest/include/gtest/gtest.h" #include "testing/gtest/include/gtest/gtest.h"
#include "ui/gfx/image/image.h" #include "ui/gfx/image/image.h"
...@@ -268,6 +269,20 @@ class BackgroundModeManagerWithExtensionsTest ...@@ -268,6 +269,20 @@ class BackgroundModeManagerWithExtensionsTest
protected: protected:
scoped_ptr<SimpleTestBackgroundModeManager> manager_; scoped_ptr<SimpleTestBackgroundModeManager> manager_;
void AddEphemeralApp(const extensions::Extension* extension,
ExtensionService* service) {
extensions::ExtensionPrefs* prefs =
extensions::ExtensionPrefs::Get(service->profile());
ASSERT_TRUE(prefs);
prefs->OnExtensionInstalled(extension,
extensions::Extension::ENABLED,
syncer::StringOrdinal(),
extensions::kInstallFlagIsEphemeral,
std::string());
service->AddExtension(extension);
}
private: private:
// Required for extension service. // Required for extension service.
content::TestBrowserThreadBundle thread_bundle_; content::TestBrowserThreadBundle thread_bundle_;
...@@ -818,6 +833,15 @@ TEST_F(BackgroundModeManagerWithExtensionsTest, BalloonDisplay) { ...@@ -818,6 +833,15 @@ TEST_F(BackgroundModeManagerWithExtensionsTest, BalloonDisplay) {
"\"permissions\": [\"background\"]}", "\"permissions\": [\"background\"]}",
"ID-2")); "ID-2"));
scoped_refptr<extensions::Extension> ephemeral_app(
CreateExtension(
extensions::Manifest::COMMAND_LINE,
"{\"name\": \"Ephemeral App\", "
"\"version\": \"1.0\","
"\"manifest_version\": 2,"
"\"permissions\": [\"pushMessaging\"]}",
"ID-3"));
static_cast<extensions::TestExtensionSystem*>( static_cast<extensions::TestExtensionSystem*>(
extensions::ExtensionSystem::Get(profile_))->CreateExtensionService( extensions::ExtensionSystem::Get(profile_))->CreateExtensionService(
CommandLine::ForCurrentProcess(), CommandLine::ForCurrentProcess(),
...@@ -850,4 +874,14 @@ TEST_F(BackgroundModeManagerWithExtensionsTest, BalloonDisplay) { ...@@ -850,4 +874,14 @@ TEST_F(BackgroundModeManagerWithExtensionsTest, BalloonDisplay) {
// show the balloon. // show the balloon.
service->AddExtension(upgraded_no_bg_ext_has_bg); service->AddExtension(upgraded_no_bg_ext_has_bg);
EXPECT_TRUE(manager_->HasShownBalloon()); EXPECT_TRUE(manager_->HasShownBalloon());
// Installing an ephemeral app should not show the balloon.
manager_->SetHasShownBalloon(false);
AddEphemeralApp(ephemeral_app.get(), service);
EXPECT_FALSE(manager_->HasShownBalloon());
// Promoting the ephemeral app to a regular installed app should now show
// the balloon.
service->PromoteEphemeralApp(ephemeral_app.get(), false /*from sync*/);
EXPECT_TRUE(manager_->HasShownBalloon());
} }
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment