| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/values.h" | 5 #include "base/values.h" |
| 6 #include "chrome/browser/extensions/extension_special_storage_policy.h" | 6 #include "chrome/browser/extensions/extension_special_storage_policy.h" |
| 7 #include "chrome/common/extensions/extension.h" | 7 #include "chrome/common/extensions/extension.h" |
| 8 #include "chrome/common/extensions/extension_constants.h" | 8 #include "chrome/common/extensions/extension_constants.h" |
| 9 #include "testing/gtest/include/gtest/gtest.h" | 9 #include "testing/gtest/include/gtest/gtest.h" |
| 10 | 10 |
| (...skipping 10 matching lines...) Expand all Loading... |
| 21 DictionaryValue manifest; | 21 DictionaryValue manifest; |
| 22 manifest.SetString(keys::kName, "Protected"); | 22 manifest.SetString(keys::kName, "Protected"); |
| 23 manifest.SetString(keys::kVersion, "1"); | 23 manifest.SetString(keys::kVersion, "1"); |
| 24 manifest.SetString(keys::kLaunchWebURL, "http://explicit/protected/start"); | 24 manifest.SetString(keys::kLaunchWebURL, "http://explicit/protected/start"); |
| 25 ListValue* list = new ListValue(); | 25 ListValue* list = new ListValue(); |
| 26 list->Append(Value::CreateStringValue("http://explicit/protected")); | 26 list->Append(Value::CreateStringValue("http://explicit/protected")); |
| 27 list->Append(Value::CreateStringValue("*://*.wildcards/protected")); | 27 list->Append(Value::CreateStringValue("*://*.wildcards/protected")); |
| 28 manifest.Set(keys::kWebURLs, list); | 28 manifest.Set(keys::kWebURLs, list); |
| 29 std::string error; | 29 std::string error; |
| 30 scoped_refptr<Extension> protected_app = Extension::Create( | 30 scoped_refptr<Extension> protected_app = Extension::Create( |
| 31 path, Extension::INVALID, manifest, false, true, &error); | 31 path, Extension::INVALID, manifest, Extension::STRICT_ERROR_CHECKS, |
| 32 &error); |
| 32 EXPECT_TRUE(protected_app.get()) << error; | 33 EXPECT_TRUE(protected_app.get()) << error; |
| 33 return protected_app; | 34 return protected_app; |
| 34 } | 35 } |
| 35 | 36 |
| 36 scoped_refptr<Extension> CreateUnlimitedApp() { | 37 scoped_refptr<Extension> CreateUnlimitedApp() { |
| 37 #if defined(OS_WIN) | 38 #if defined(OS_WIN) |
| 38 FilePath path(FILE_PATH_LITERAL("c:\\bar")); | 39 FilePath path(FILE_PATH_LITERAL("c:\\bar")); |
| 39 #elif defined(OS_POSIX) | 40 #elif defined(OS_POSIX) |
| 40 FilePath path(FILE_PATH_LITERAL("/bar")); | 41 FilePath path(FILE_PATH_LITERAL("/bar")); |
| 41 #endif | 42 #endif |
| 42 DictionaryValue manifest; | 43 DictionaryValue manifest; |
| 43 manifest.SetString(keys::kName, "Unlimited"); | 44 manifest.SetString(keys::kName, "Unlimited"); |
| 44 manifest.SetString(keys::kVersion, "1"); | 45 manifest.SetString(keys::kVersion, "1"); |
| 45 manifest.SetString(keys::kLaunchWebURL, "http://explicit/unlimited/start"); | 46 manifest.SetString(keys::kLaunchWebURL, "http://explicit/unlimited/start"); |
| 46 ListValue* list = new ListValue(); | 47 ListValue* list = new ListValue(); |
| 47 list->Append(Value::CreateStringValue("unlimitedStorage")); | 48 list->Append(Value::CreateStringValue("unlimitedStorage")); |
| 48 manifest.Set(keys::kPermissions, list); | 49 manifest.Set(keys::kPermissions, list); |
| 49 list = new ListValue(); | 50 list = new ListValue(); |
| 50 list->Append(Value::CreateStringValue("http://explicit/unlimited")); | 51 list->Append(Value::CreateStringValue("http://explicit/unlimited")); |
| 51 list->Append(Value::CreateStringValue("*://*.wildcards/unlimited")); | 52 list->Append(Value::CreateStringValue("*://*.wildcards/unlimited")); |
| 52 manifest.Set(keys::kWebURLs, list); | 53 manifest.Set(keys::kWebURLs, list); |
| 53 std::string error; | 54 std::string error; |
| 54 scoped_refptr<Extension> unlimited_app = Extension::Create( | 55 scoped_refptr<Extension> unlimited_app = Extension::Create( |
| 55 path, Extension::INVALID, manifest, false, true, &error); | 56 path, Extension::INVALID, manifest, Extension::STRICT_ERROR_CHECKS, |
| 57 &error); |
| 56 EXPECT_TRUE(unlimited_app.get()) << error; | 58 EXPECT_TRUE(unlimited_app.get()) << error; |
| 57 return unlimited_app; | 59 return unlimited_app; |
| 58 } | 60 } |
| 59 }; | 61 }; |
| 60 | 62 |
| 61 TEST_F(ExtensionSpecialStoragePolicyTest, EmptyPolicy) { | 63 TEST_F(ExtensionSpecialStoragePolicyTest, EmptyPolicy) { |
| 62 const GURL kHttpUrl("http://foo"); | 64 const GURL kHttpUrl("http://foo"); |
| 63 const GURL kExtensionUrl("chrome-extension://bar"); | 65 const GURL kExtensionUrl("chrome-extension://bar"); |
| 64 | 66 |
| 65 scoped_refptr<ExtensionSpecialStoragePolicy> policy( | 67 scoped_refptr<ExtensionSpecialStoragePolicy> policy( |
| (...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 148 EXPECT_FALSE(policy->IsStorageUnlimited(GURL("https://bar.wildcards/"))); | 150 EXPECT_FALSE(policy->IsStorageUnlimited(GURL("https://bar.wildcards/"))); |
| 149 EXPECT_TRUE(policy->IsStorageProtected(GURL("http://explicit/"))); | 151 EXPECT_TRUE(policy->IsStorageProtected(GURL("http://explicit/"))); |
| 150 EXPECT_TRUE(policy->IsStorageProtected(GURL("http://foo.wildcards/"))); | 152 EXPECT_TRUE(policy->IsStorageProtected(GURL("http://foo.wildcards/"))); |
| 151 EXPECT_TRUE(policy->IsStorageProtected(GURL("https://bar.wildcards/"))); | 153 EXPECT_TRUE(policy->IsStorageProtected(GURL("https://bar.wildcards/"))); |
| 152 | 154 |
| 153 policy->RevokeRightsForExtension(protected_app); | 155 policy->RevokeRightsForExtension(protected_app); |
| 154 EXPECT_FALSE(policy->IsStorageProtected(GURL("http://explicit/"))); | 156 EXPECT_FALSE(policy->IsStorageProtected(GURL("http://explicit/"))); |
| 155 EXPECT_FALSE(policy->IsStorageProtected(GURL("http://foo.wildcards/"))); | 157 EXPECT_FALSE(policy->IsStorageProtected(GURL("http://foo.wildcards/"))); |
| 156 EXPECT_FALSE(policy->IsStorageProtected(GURL("https://bar.wildcards/"))); | 158 EXPECT_FALSE(policy->IsStorageProtected(GURL("https://bar.wildcards/"))); |
| 157 } | 159 } |
| OLD | NEW |