| 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 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 111 EXPECT_TRUE(handler_app.get()) << error; | 111 EXPECT_TRUE(handler_app.get()) << error; |
| 112 return handler_app; | 112 return handler_app; |
| 113 } | 113 } |
| 114 }; | 114 }; |
| 115 | 115 |
| 116 TEST_F(ExtensionSpecialStoragePolicyTest, EmptyPolicy) { | 116 TEST_F(ExtensionSpecialStoragePolicyTest, EmptyPolicy) { |
| 117 const GURL kHttpUrl("http://foo"); | 117 const GURL kHttpUrl("http://foo"); |
| 118 const GURL kExtensionUrl("chrome-extension://bar"); | 118 const GURL kExtensionUrl("chrome-extension://bar"); |
| 119 | 119 |
| 120 scoped_refptr<ExtensionSpecialStoragePolicy> policy( | 120 scoped_refptr<ExtensionSpecialStoragePolicy> policy( |
| 121 new ExtensionSpecialStoragePolicy); | 121 new ExtensionSpecialStoragePolicy(NULL)); |
| 122 | 122 |
| 123 ASSERT_FALSE(policy->IsStorageUnlimited(kHttpUrl)); | 123 ASSERT_FALSE(policy->IsStorageUnlimited(kHttpUrl)); |
| 124 ASSERT_FALSE(policy->IsStorageUnlimited(kHttpUrl)); // test cached result | 124 ASSERT_FALSE(policy->IsStorageUnlimited(kHttpUrl)); // test cached result |
| 125 ASSERT_FALSE(policy->IsStorageUnlimited(kExtensionUrl)); | 125 ASSERT_FALSE(policy->IsStorageUnlimited(kExtensionUrl)); |
| 126 ASSERT_FALSE(policy->IsStorageProtected(kHttpUrl)); | 126 ASSERT_FALSE(policy->IsStorageProtected(kHttpUrl)); |
| 127 | 127 |
| 128 // This one is just based on the scheme. | 128 // This one is just based on the scheme. |
| 129 ASSERT_TRUE(policy->IsStorageProtected(kExtensionUrl)); | 129 ASSERT_TRUE(policy->IsStorageProtected(kExtensionUrl)); |
| 130 } | 130 } |
| 131 | 131 |
| 132 | 132 |
| 133 TEST_F(ExtensionSpecialStoragePolicyTest, AppWithProtectedStorage) { | 133 TEST_F(ExtensionSpecialStoragePolicyTest, AppWithProtectedStorage) { |
| 134 scoped_refptr<Extension> extension(CreateProtectedApp()); | 134 scoped_refptr<Extension> extension(CreateProtectedApp()); |
| 135 scoped_refptr<ExtensionSpecialStoragePolicy> policy( | 135 scoped_refptr<ExtensionSpecialStoragePolicy> policy( |
| 136 new ExtensionSpecialStoragePolicy); | 136 new ExtensionSpecialStoragePolicy(NULL)); |
| 137 policy->GrantRightsForExtension(extension); | 137 policy->GrantRightsForExtension(extension); |
| 138 EXPECT_FALSE(policy->IsStorageUnlimited(extension->url())); | 138 EXPECT_FALSE(policy->IsStorageUnlimited(extension->url())); |
| 139 EXPECT_FALSE(policy->IsStorageUnlimited(GURL("http://explicit/"))); | 139 EXPECT_FALSE(policy->IsStorageUnlimited(GURL("http://explicit/"))); |
| 140 EXPECT_TRUE(policy->IsStorageProtected(GURL("http://explicit/"))); | 140 EXPECT_TRUE(policy->IsStorageProtected(GURL("http://explicit/"))); |
| 141 EXPECT_TRUE(policy->IsStorageProtected(GURL("http://explicit:6000/"))); | 141 EXPECT_TRUE(policy->IsStorageProtected(GURL("http://explicit:6000/"))); |
| 142 EXPECT_TRUE(policy->IsStorageProtected(GURL("http://foo.wildcards/"))); | 142 EXPECT_TRUE(policy->IsStorageProtected(GURL("http://foo.wildcards/"))); |
| 143 EXPECT_TRUE(policy->IsStorageProtected(GURL("https://bar.wildcards/"))); | 143 EXPECT_TRUE(policy->IsStorageProtected(GURL("https://bar.wildcards/"))); |
| 144 EXPECT_FALSE(policy->IsStorageProtected(GURL("http://not_listed/"))); | 144 EXPECT_FALSE(policy->IsStorageProtected(GURL("http://not_listed/"))); |
| 145 | 145 |
| 146 policy->RevokeRightsForExtension(extension); | 146 policy->RevokeRightsForExtension(extension); |
| 147 EXPECT_FALSE(policy->IsStorageProtected(GURL("http://explicit/"))); | 147 EXPECT_FALSE(policy->IsStorageProtected(GURL("http://explicit/"))); |
| 148 EXPECT_FALSE(policy->IsStorageProtected(GURL("http://foo.wildcards/"))); | 148 EXPECT_FALSE(policy->IsStorageProtected(GURL("http://foo.wildcards/"))); |
| 149 EXPECT_FALSE(policy->IsStorageProtected(GURL("https://bar.wildcards/"))); | 149 EXPECT_FALSE(policy->IsStorageProtected(GURL("https://bar.wildcards/"))); |
| 150 } | 150 } |
| 151 | 151 |
| 152 TEST_F(ExtensionSpecialStoragePolicyTest, AppWithUnlimitedStorage) { | 152 TEST_F(ExtensionSpecialStoragePolicyTest, AppWithUnlimitedStorage) { |
| 153 scoped_refptr<Extension> extension(CreateUnlimitedApp()); | 153 scoped_refptr<Extension> extension(CreateUnlimitedApp()); |
| 154 scoped_refptr<ExtensionSpecialStoragePolicy> policy( | 154 scoped_refptr<ExtensionSpecialStoragePolicy> policy( |
| 155 new ExtensionSpecialStoragePolicy); | 155 new ExtensionSpecialStoragePolicy(NULL)); |
| 156 policy->GrantRightsForExtension(extension); | 156 policy->GrantRightsForExtension(extension); |
| 157 EXPECT_TRUE(policy->IsStorageProtected(GURL("http://explicit/"))); | 157 EXPECT_TRUE(policy->IsStorageProtected(GURL("http://explicit/"))); |
| 158 EXPECT_TRUE(policy->IsStorageProtected(GURL("http://explicit:6000/"))); | 158 EXPECT_TRUE(policy->IsStorageProtected(GURL("http://explicit:6000/"))); |
| 159 EXPECT_TRUE(policy->IsStorageProtected(GURL("https://foo.wildcards/"))); | 159 EXPECT_TRUE(policy->IsStorageProtected(GURL("https://foo.wildcards/"))); |
| 160 EXPECT_TRUE(policy->IsStorageProtected(GURL("https://foo.wildcards/"))); | 160 EXPECT_TRUE(policy->IsStorageProtected(GURL("https://foo.wildcards/"))); |
| 161 EXPECT_TRUE(policy->IsStorageProtected(GURL("http://bar.wildcards/"))); | 161 EXPECT_TRUE(policy->IsStorageProtected(GURL("http://bar.wildcards/"))); |
| 162 EXPECT_FALSE(policy->IsStorageProtected(GURL("http://not_listed/"))); | 162 EXPECT_FALSE(policy->IsStorageProtected(GURL("http://not_listed/"))); |
| 163 EXPECT_TRUE(policy->IsStorageUnlimited(extension->url())); | 163 EXPECT_TRUE(policy->IsStorageUnlimited(extension->url())); |
| 164 EXPECT_TRUE(policy->IsStorageUnlimited(GURL("http://explicit/"))); | 164 EXPECT_TRUE(policy->IsStorageUnlimited(GURL("http://explicit/"))); |
| 165 EXPECT_TRUE(policy->IsStorageUnlimited(GURL("http://explicit:6000/"))); | 165 EXPECT_TRUE(policy->IsStorageUnlimited(GURL("http://explicit:6000/"))); |
| 166 EXPECT_TRUE(policy->IsStorageUnlimited(GURL("https://foo.wildcards/"))); | 166 EXPECT_TRUE(policy->IsStorageUnlimited(GURL("https://foo.wildcards/"))); |
| 167 EXPECT_TRUE(policy->IsStorageUnlimited(GURL("https://bar.wildcards/"))); | 167 EXPECT_TRUE(policy->IsStorageUnlimited(GURL("https://bar.wildcards/"))); |
| 168 EXPECT_FALSE(policy->IsStorageUnlimited(GURL("http://not_listed/"))); | 168 EXPECT_FALSE(policy->IsStorageUnlimited(GURL("http://not_listed/"))); |
| 169 | 169 |
| 170 policy->RevokeRightsForExtension(extension); | 170 policy->RevokeRightsForExtension(extension); |
| 171 EXPECT_FALSE(policy->IsStorageProtected(GURL("http://explicit/"))); | 171 EXPECT_FALSE(policy->IsStorageProtected(GURL("http://explicit/"))); |
| 172 EXPECT_FALSE(policy->IsStorageProtected(GURL("https://foo.wildcards/"))); | 172 EXPECT_FALSE(policy->IsStorageProtected(GURL("https://foo.wildcards/"))); |
| 173 EXPECT_FALSE(policy->IsStorageProtected(GURL("https://foo.wildcards/"))); | 173 EXPECT_FALSE(policy->IsStorageProtected(GURL("https://foo.wildcards/"))); |
| 174 EXPECT_FALSE(policy->IsStorageProtected(GURL("http://bar.wildcards/"))); | 174 EXPECT_FALSE(policy->IsStorageProtected(GURL("http://bar.wildcards/"))); |
| 175 EXPECT_FALSE(policy->IsStorageUnlimited(GURL("http://explicit/"))); | 175 EXPECT_FALSE(policy->IsStorageUnlimited(GURL("http://explicit/"))); |
| 176 EXPECT_FALSE(policy->IsStorageUnlimited(GURL("https://foo.wildcards/"))); | 176 EXPECT_FALSE(policy->IsStorageUnlimited(GURL("https://foo.wildcards/"))); |
| 177 EXPECT_FALSE(policy->IsStorageUnlimited(GURL("https://bar.wildcards/"))); | 177 EXPECT_FALSE(policy->IsStorageUnlimited(GURL("https://bar.wildcards/"))); |
| 178 } | 178 } |
| 179 | 179 |
| 180 TEST_F(ExtensionSpecialStoragePolicyTest, OverlappingApps) { | 180 TEST_F(ExtensionSpecialStoragePolicyTest, OverlappingApps) { |
| 181 scoped_refptr<Extension> protected_app(CreateProtectedApp()); | 181 scoped_refptr<Extension> protected_app(CreateProtectedApp()); |
| 182 scoped_refptr<Extension> unlimited_app(CreateUnlimitedApp()); | 182 scoped_refptr<Extension> unlimited_app(CreateUnlimitedApp()); |
| 183 scoped_refptr<ExtensionSpecialStoragePolicy> policy( | 183 scoped_refptr<ExtensionSpecialStoragePolicy> policy( |
| 184 new ExtensionSpecialStoragePolicy); | 184 new ExtensionSpecialStoragePolicy(NULL)); |
| 185 policy->GrantRightsForExtension(protected_app); | 185 policy->GrantRightsForExtension(protected_app); |
| 186 policy->GrantRightsForExtension(unlimited_app); | 186 policy->GrantRightsForExtension(unlimited_app); |
| 187 | 187 |
| 188 EXPECT_TRUE(policy->IsStorageProtected(GURL("http://explicit/"))); | 188 EXPECT_TRUE(policy->IsStorageProtected(GURL("http://explicit/"))); |
| 189 EXPECT_TRUE(policy->IsStorageProtected(GURL("http://explicit:6000/"))); | 189 EXPECT_TRUE(policy->IsStorageProtected(GURL("http://explicit:6000/"))); |
| 190 EXPECT_TRUE(policy->IsStorageProtected(GURL("https://foo.wildcards/"))); | 190 EXPECT_TRUE(policy->IsStorageProtected(GURL("https://foo.wildcards/"))); |
| 191 EXPECT_TRUE(policy->IsStorageProtected(GURL("https://foo.wildcards/"))); | 191 EXPECT_TRUE(policy->IsStorageProtected(GURL("https://foo.wildcards/"))); |
| 192 EXPECT_TRUE(policy->IsStorageProtected(GURL("http://bar.wildcards/"))); | 192 EXPECT_TRUE(policy->IsStorageProtected(GURL("http://bar.wildcards/"))); |
| 193 EXPECT_FALSE(policy->IsStorageProtected(GURL("http://not_listed/"))); | 193 EXPECT_FALSE(policy->IsStorageProtected(GURL("http://not_listed/"))); |
| 194 EXPECT_TRUE(policy->IsStorageUnlimited(GURL("http://explicit/"))); | 194 EXPECT_TRUE(policy->IsStorageUnlimited(GURL("http://explicit/"))); |
| 195 EXPECT_TRUE(policy->IsStorageUnlimited(GURL("http://explicit:6000/"))); | 195 EXPECT_TRUE(policy->IsStorageUnlimited(GURL("http://explicit:6000/"))); |
| 196 EXPECT_TRUE(policy->IsStorageUnlimited(GURL("https://foo.wildcards/"))); | 196 EXPECT_TRUE(policy->IsStorageUnlimited(GURL("https://foo.wildcards/"))); |
| 197 EXPECT_TRUE(policy->IsStorageUnlimited(GURL("https://bar.wildcards/"))); | 197 EXPECT_TRUE(policy->IsStorageUnlimited(GURL("https://bar.wildcards/"))); |
| 198 EXPECT_FALSE(policy->IsStorageUnlimited(GURL("http://not_listed/"))); | 198 EXPECT_FALSE(policy->IsStorageUnlimited(GURL("http://not_listed/"))); |
| 199 | 199 |
| 200 policy->RevokeRightsForExtension(unlimited_app); | 200 policy->RevokeRightsForExtension(unlimited_app); |
| 201 EXPECT_FALSE(policy->IsStorageUnlimited(GURL("http://explicit/"))); | 201 EXPECT_FALSE(policy->IsStorageUnlimited(GURL("http://explicit/"))); |
| 202 EXPECT_FALSE(policy->IsStorageUnlimited(GURL("https://foo.wildcards/"))); | 202 EXPECT_FALSE(policy->IsStorageUnlimited(GURL("https://foo.wildcards/"))); |
| 203 EXPECT_FALSE(policy->IsStorageUnlimited(GURL("https://bar.wildcards/"))); | 203 EXPECT_FALSE(policy->IsStorageUnlimited(GURL("https://bar.wildcards/"))); |
| 204 EXPECT_TRUE(policy->IsStorageProtected(GURL("http://explicit/"))); | 204 EXPECT_TRUE(policy->IsStorageProtected(GURL("http://explicit/"))); |
| 205 EXPECT_TRUE(policy->IsStorageProtected(GURL("http://foo.wildcards/"))); | 205 EXPECT_TRUE(policy->IsStorageProtected(GURL("http://foo.wildcards/"))); |
| 206 EXPECT_TRUE(policy->IsStorageProtected(GURL("https://bar.wildcards/"))); | 206 EXPECT_TRUE(policy->IsStorageProtected(GURL("https://bar.wildcards/"))); |
| 207 | 207 |
| 208 policy->RevokeRightsForExtension(protected_app); | 208 policy->RevokeRightsForExtension(protected_app); |
| 209 EXPECT_FALSE(policy->IsStorageProtected(GURL("http://explicit/"))); | 209 EXPECT_FALSE(policy->IsStorageProtected(GURL("http://explicit/"))); |
| 210 EXPECT_FALSE(policy->IsStorageProtected(GURL("http://foo.wildcards/"))); | 210 EXPECT_FALSE(policy->IsStorageProtected(GURL("http://foo.wildcards/"))); |
| 211 EXPECT_FALSE(policy->IsStorageProtected(GURL("https://bar.wildcards/"))); | 211 EXPECT_FALSE(policy->IsStorageProtected(GURL("https://bar.wildcards/"))); |
| 212 } | 212 } |
| OLD | NEW |