Commit c13be907 authored by kinuko@chromium.org's avatar kinuko@chromium.org

Fix ExtensionSpecialStoragePolicy.IsInstalledApp

We weren't adding apps to the installed_app set when it doesn't have
any storage permissions.

BUG=231167
TEST=ExtensionSpecialStoragePolicyTest.IsInstalled

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

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@194511 0039d316-1c4b-4281-b951-d872f2087c98
parent 0bc1f571
......@@ -87,11 +87,10 @@ const ExtensionSet* ExtensionSpecialStoragePolicy::ExtensionsProtectingOrigin(
void ExtensionSpecialStoragePolicy::GrantRightsForExtension(
const extensions::Extension* extension) {
DCHECK(extension);
if (!NeedsProtection(extension) &&
!extension->HasAPIPermission(
APIPermission::kUnlimitedStorage) &&
!extension->HasAPIPermission(
APIPermission::kFileBrowserHandler)) {
if (!(NeedsProtection(extension) ||
extension->HasAPIPermission(APIPermission::kUnlimitedStorage) ||
extension->HasAPIPermission(APIPermission::kFileBrowserHandler) ||
extension->is_app())) {
return;
}
{
......@@ -103,8 +102,7 @@ void ExtensionSpecialStoragePolicy::GrantRightsForExtension(
installed_apps_.Add(extension);
if (extension->HasAPIPermission(APIPermission::kUnlimitedStorage))
unlimited_extensions_.Add(extension);
if (extension->HasAPIPermission(
APIPermission::kFileBrowserHandler))
if (extension->HasAPIPermission(APIPermission::kFileBrowserHandler))
file_handler_extensions_.Add(extension);
}
NotifyChanged();
......@@ -113,11 +111,10 @@ void ExtensionSpecialStoragePolicy::GrantRightsForExtension(
void ExtensionSpecialStoragePolicy::RevokeRightsForExtension(
const extensions::Extension* extension) {
DCHECK(extension);
if (!NeedsProtection(extension) &&
!extension->HasAPIPermission(
APIPermission::kUnlimitedStorage) &&
!extension->HasAPIPermission(
APIPermission::kFileBrowserHandler)) {
if (!(NeedsProtection(extension) ||
extension->HasAPIPermission(APIPermission::kUnlimitedStorage) ||
extension->HasAPIPermission(APIPermission::kFileBrowserHandler) ||
extension->is_app())) {
return;
}
{
......
......@@ -129,6 +129,24 @@ class ExtensionSpecialStoragePolicyTest : public extensions::ExtensionTest {
return handler_app;
}
scoped_refptr<Extension> CreateRegularApp() {
#if defined(OS_WIN)
base::FilePath path(FILE_PATH_LITERAL("c:\\app"));
#elif defined(OS_POSIX)
base::FilePath path(FILE_PATH_LITERAL("/app"));
#endif
DictionaryValue manifest;
manifest.SetString(keys::kName, "App");
manifest.SetString(keys::kVersion, "1");
manifest.SetString(keys::kPlatformAppBackgroundPage, "background.html");
std::string error;
scoped_refptr<Extension> app = Extension::Create(
path, Manifest::INVALID_LOCATION, manifest,
Extension::NO_FLAGS, &error);
EXPECT_TRUE(app.get()) << error;
return app;
}
// Verifies that the set of extensions protecting |url| is *exactly* equal to
// |expected_extensions|. Pass in an empty set to verify that an origin is not
// protected.
......@@ -150,18 +168,20 @@ class ExtensionSpecialStoragePolicyTest : public extensions::ExtensionTest {
TEST_F(ExtensionSpecialStoragePolicyTest, EmptyPolicy) {
const GURL kHttpUrl("http://foo");
const GURL kExtensionUrl("chrome-extension://bar");
scoped_refptr<Extension> app(CreateRegularApp());
EXPECT_FALSE(policy_->IsStorageUnlimited(kHttpUrl));
EXPECT_FALSE(policy_->IsStorageUnlimited(kHttpUrl)); // test cached result
EXPECT_FALSE(policy_->IsStorageUnlimited(kExtensionUrl));
EXPECT_FALSE(policy_->IsStorageUnlimited(app->url()));
ExtensionSet empty_set;
ExpectProtectedBy(empty_set, kHttpUrl);
// This one is just based on the scheme.
EXPECT_TRUE(policy_->IsStorageProtected(kExtensionUrl));
EXPECT_TRUE(policy_->IsStorageProtected(app->url()));
}
TEST_F(ExtensionSpecialStoragePolicyTest, AppWithProtectedStorage) {
scoped_refptr<Extension> extension(CreateProtectedApp());
policy_->GrantRightsForExtension(extension);
......@@ -213,6 +233,23 @@ TEST_F(ExtensionSpecialStoragePolicyTest, AppWithUnlimitedStorage) {
EXPECT_FALSE(policy_->IsStorageUnlimited(GURL("https://bar.wildcards/")));
}
TEST_F(ExtensionSpecialStoragePolicyTest, IsInstalled) {
const GURL kHttpUrl("http://foo");
const GURL kExtensionUrl("chrome-extension://bar");
scoped_refptr<Extension> regular_app(CreateRegularApp());
scoped_refptr<Extension> protected_app(CreateProtectedApp());
scoped_refptr<Extension> unlimited_app(CreateUnlimitedApp());
policy_->GrantRightsForExtension(regular_app);
policy_->GrantRightsForExtension(protected_app);
policy_->GrantRightsForExtension(unlimited_app);
EXPECT_FALSE(policy_->IsInstalledApp(kHttpUrl));
EXPECT_FALSE(policy_->IsInstalledApp(kExtensionUrl));
EXPECT_TRUE(policy_->IsInstalledApp(regular_app->url()));
EXPECT_TRUE(policy_->IsInstalledApp(protected_app->url()));
EXPECT_TRUE(policy_->IsInstalledApp(unlimited_app->url()));
}
TEST_F(ExtensionSpecialStoragePolicyTest, OverlappingApps) {
scoped_refptr<Extension> protected_app(CreateProtectedApp());
scoped_refptr<Extension> unlimited_app(CreateUnlimitedApp());
......
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