OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/message_loop/message_loop.h" | 5 #include "base/message_loop/message_loop.h" |
6 #include "base/values.h" | 6 #include "base/values.h" |
7 #include "chrome/browser/content_settings/cookie_settings.h" | 7 #include "chrome/browser/content_settings/cookie_settings.h" |
8 #include "chrome/browser/extensions/extension_special_storage_policy.h" | 8 #include "chrome/browser/extensions/extension_special_storage_policy.h" |
9 #include "chrome/test/base/testing_profile.h" | 9 #include "chrome/test/base/testing_profile.h" |
10 #include "components/content_settings/core/common/content_settings.h" | 10 #include "components/content_settings/core/common/content_settings.h" |
(...skipping 180 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
191 ExtensionSet empty_set; | 191 ExtensionSet empty_set; |
192 ExpectProtectedBy(empty_set, kHttpUrl); | 192 ExpectProtectedBy(empty_set, kHttpUrl); |
193 | 193 |
194 // This one is just based on the scheme. | 194 // This one is just based on the scheme. |
195 EXPECT_TRUE(policy_->IsStorageProtected(kExtensionUrl)); | 195 EXPECT_TRUE(policy_->IsStorageProtected(kExtensionUrl)); |
196 EXPECT_TRUE(policy_->IsStorageProtected(app->url())); | 196 EXPECT_TRUE(policy_->IsStorageProtected(app->url())); |
197 } | 197 } |
198 | 198 |
199 TEST_F(ExtensionSpecialStoragePolicyTest, AppWithProtectedStorage) { | 199 TEST_F(ExtensionSpecialStoragePolicyTest, AppWithProtectedStorage) { |
200 scoped_refptr<Extension> extension(CreateProtectedApp()); | 200 scoped_refptr<Extension> extension(CreateProtectedApp()); |
201 policy_->GrantRightsForExtension(extension.get()); | 201 policy_->GrantRightsForExtension(extension.get(), NULL); |
202 ExtensionSet protecting_extensions; | 202 ExtensionSet protecting_extensions; |
203 protecting_extensions.Insert(extension); | 203 protecting_extensions.Insert(extension); |
204 ExtensionSet empty_set; | 204 ExtensionSet empty_set; |
205 | 205 |
206 EXPECT_FALSE(policy_->IsStorageUnlimited(extension->url())); | 206 EXPECT_FALSE(policy_->IsStorageUnlimited(extension->url())); |
207 EXPECT_FALSE(policy_->IsStorageUnlimited(GURL("http://explicit/"))); | 207 EXPECT_FALSE(policy_->IsStorageUnlimited(GURL("http://explicit/"))); |
208 ExpectProtectedBy(protecting_extensions, GURL("http://explicit/")); | 208 ExpectProtectedBy(protecting_extensions, GURL("http://explicit/")); |
209 ExpectProtectedBy(protecting_extensions, GURL("http://explicit:6000/")); | 209 ExpectProtectedBy(protecting_extensions, GURL("http://explicit:6000/")); |
210 ExpectProtectedBy(protecting_extensions, GURL("http://foo.wildcards/")); | 210 ExpectProtectedBy(protecting_extensions, GURL("http://foo.wildcards/")); |
211 ExpectProtectedBy(protecting_extensions, GURL("https://bar.wildcards/")); | 211 ExpectProtectedBy(protecting_extensions, GURL("https://bar.wildcards/")); |
212 ExpectProtectedBy(empty_set, GURL("http://not_listed/")); | 212 ExpectProtectedBy(empty_set, GURL("http://not_listed/")); |
213 | 213 |
214 policy_->RevokeRightsForExtension(extension.get()); | 214 policy_->RevokeRightsForExtension(extension.get()); |
215 ExpectProtectedBy(empty_set, GURL("http://explicit/")); | 215 ExpectProtectedBy(empty_set, GURL("http://explicit/")); |
216 ExpectProtectedBy(empty_set, GURL("http://foo.wildcards/")); | 216 ExpectProtectedBy(empty_set, GURL("http://foo.wildcards/")); |
217 ExpectProtectedBy(empty_set, GURL("https://bar.wildcards/")); | 217 ExpectProtectedBy(empty_set, GURL("https://bar.wildcards/")); |
218 } | 218 } |
219 | 219 |
220 TEST_F(ExtensionSpecialStoragePolicyTest, AppWithUnlimitedStorage) { | 220 TEST_F(ExtensionSpecialStoragePolicyTest, AppWithUnlimitedStorage) { |
221 scoped_refptr<Extension> extension(CreateUnlimitedApp()); | 221 scoped_refptr<Extension> extension(CreateUnlimitedApp()); |
222 policy_->GrantRightsForExtension(extension.get()); | 222 policy_->GrantRightsForExtension(extension.get(), NULL); |
223 ExtensionSet protecting_extensions; | 223 ExtensionSet protecting_extensions; |
224 protecting_extensions.Insert(extension); | 224 protecting_extensions.Insert(extension); |
225 ExtensionSet empty_set; | 225 ExtensionSet empty_set; |
226 | 226 |
227 ExpectProtectedBy(protecting_extensions, GURL("http://explicit/")); | 227 ExpectProtectedBy(protecting_extensions, GURL("http://explicit/")); |
228 ExpectProtectedBy(protecting_extensions, GURL("http://explicit:6000/")); | 228 ExpectProtectedBy(protecting_extensions, GURL("http://explicit:6000/")); |
229 ExpectProtectedBy(protecting_extensions, GURL("https://foo.wildcards/")); | 229 ExpectProtectedBy(protecting_extensions, GURL("https://foo.wildcards/")); |
230 ExpectProtectedBy(protecting_extensions, GURL("https://foo.wildcards/")); | 230 ExpectProtectedBy(protecting_extensions, GURL("https://foo.wildcards/")); |
231 ExpectProtectedBy(protecting_extensions, GURL("http://bar.wildcards/")); | 231 ExpectProtectedBy(protecting_extensions, GURL("http://bar.wildcards/")); |
232 ExpectProtectedBy(empty_set, GURL("http://not_listed/")); | 232 ExpectProtectedBy(empty_set, GURL("http://not_listed/")); |
(...skipping 13 matching lines...) Expand all Loading... |
246 EXPECT_FALSE(policy_->IsStorageUnlimited(GURL("https://foo.wildcards/"))); | 246 EXPECT_FALSE(policy_->IsStorageUnlimited(GURL("https://foo.wildcards/"))); |
247 EXPECT_FALSE(policy_->IsStorageUnlimited(GURL("https://bar.wildcards/"))); | 247 EXPECT_FALSE(policy_->IsStorageUnlimited(GURL("https://bar.wildcards/"))); |
248 } | 248 } |
249 | 249 |
250 TEST_F(ExtensionSpecialStoragePolicyTest, CanQueryDiskSize) { | 250 TEST_F(ExtensionSpecialStoragePolicyTest, CanQueryDiskSize) { |
251 const GURL kHttpUrl("http://foo"); | 251 const GURL kHttpUrl("http://foo"); |
252 const GURL kExtensionUrl("chrome-extension://bar"); | 252 const GURL kExtensionUrl("chrome-extension://bar"); |
253 scoped_refptr<Extension> regular_app(CreateRegularApp()); | 253 scoped_refptr<Extension> regular_app(CreateRegularApp()); |
254 scoped_refptr<Extension> protected_app(CreateProtectedApp()); | 254 scoped_refptr<Extension> protected_app(CreateProtectedApp()); |
255 scoped_refptr<Extension> unlimited_app(CreateUnlimitedApp()); | 255 scoped_refptr<Extension> unlimited_app(CreateUnlimitedApp()); |
256 policy_->GrantRightsForExtension(regular_app.get()); | 256 policy_->GrantRightsForExtension(regular_app.get(), NULL); |
257 policy_->GrantRightsForExtension(protected_app.get()); | 257 policy_->GrantRightsForExtension(protected_app.get(), NULL); |
258 policy_->GrantRightsForExtension(unlimited_app.get()); | 258 policy_->GrantRightsForExtension(unlimited_app.get(), NULL); |
259 | 259 |
260 EXPECT_FALSE(policy_->CanQueryDiskSize(kHttpUrl)); | 260 EXPECT_FALSE(policy_->CanQueryDiskSize(kHttpUrl)); |
261 EXPECT_FALSE(policy_->CanQueryDiskSize(kExtensionUrl)); | 261 EXPECT_FALSE(policy_->CanQueryDiskSize(kExtensionUrl)); |
262 EXPECT_TRUE(policy_->CanQueryDiskSize(regular_app->url())); | 262 EXPECT_TRUE(policy_->CanQueryDiskSize(regular_app->url())); |
263 EXPECT_TRUE(policy_->CanQueryDiskSize(protected_app->url())); | 263 EXPECT_TRUE(policy_->CanQueryDiskSize(protected_app->url())); |
264 EXPECT_TRUE(policy_->CanQueryDiskSize(unlimited_app->url())); | 264 EXPECT_TRUE(policy_->CanQueryDiskSize(unlimited_app->url())); |
265 } | 265 } |
266 | 266 |
267 TEST_F(ExtensionSpecialStoragePolicyTest, HasIsolatedStorage) { | 267 TEST_F(ExtensionSpecialStoragePolicyTest, HasIsolatedStorage) { |
268 const GURL kHttpUrl("http://foo"); | 268 const GURL kHttpUrl("http://foo"); |
269 const GURL kExtensionUrl("chrome-extension://bar"); | 269 const GURL kExtensionUrl("chrome-extension://bar"); |
270 scoped_refptr<Extension> app(CreateRegularApp()); | 270 scoped_refptr<Extension> app(CreateRegularApp()); |
271 policy_->GrantRightsForExtension(app.get()); | 271 policy_->GrantRightsForExtension(app.get(), NULL); |
272 | 272 |
273 EXPECT_FALSE(policy_->HasIsolatedStorage(kHttpUrl)); | 273 EXPECT_FALSE(policy_->HasIsolatedStorage(kHttpUrl)); |
274 EXPECT_FALSE(policy_->HasIsolatedStorage(kExtensionUrl)); | 274 EXPECT_FALSE(policy_->HasIsolatedStorage(kExtensionUrl)); |
275 EXPECT_TRUE(policy_->HasIsolatedStorage(app->url())); | 275 EXPECT_TRUE(policy_->HasIsolatedStorage(app->url())); |
276 } | 276 } |
277 | 277 |
278 TEST_F(ExtensionSpecialStoragePolicyTest, OverlappingApps) { | 278 TEST_F(ExtensionSpecialStoragePolicyTest, OverlappingApps) { |
279 scoped_refptr<Extension> protected_app(CreateProtectedApp()); | 279 scoped_refptr<Extension> protected_app(CreateProtectedApp()); |
280 scoped_refptr<Extension> unlimited_app(CreateUnlimitedApp()); | 280 scoped_refptr<Extension> unlimited_app(CreateUnlimitedApp()); |
281 policy_->GrantRightsForExtension(protected_app.get()); | 281 policy_->GrantRightsForExtension(protected_app.get(), NULL); |
282 policy_->GrantRightsForExtension(unlimited_app.get()); | 282 policy_->GrantRightsForExtension(unlimited_app.get(), NULL); |
283 ExtensionSet protecting_extensions; | 283 ExtensionSet protecting_extensions; |
284 ExtensionSet empty_set; | 284 ExtensionSet empty_set; |
285 protecting_extensions.Insert(protected_app); | 285 protecting_extensions.Insert(protected_app); |
286 protecting_extensions.Insert(unlimited_app); | 286 protecting_extensions.Insert(unlimited_app); |
287 | 287 |
288 ExpectProtectedBy(protecting_extensions, GURL("http://explicit/")); | 288 ExpectProtectedBy(protecting_extensions, GURL("http://explicit/")); |
289 ExpectProtectedBy(protecting_extensions, GURL("http://explicit:6000/")); | 289 ExpectProtectedBy(protecting_extensions, GURL("http://explicit:6000/")); |
290 ExpectProtectedBy(protecting_extensions, GURL("https://foo.wildcards/")); | 290 ExpectProtectedBy(protecting_extensions, GURL("https://foo.wildcards/")); |
291 ExpectProtectedBy(protecting_extensions, GURL("https://foo.wildcards/")); | 291 ExpectProtectedBy(protecting_extensions, GURL("https://foo.wildcards/")); |
292 ExpectProtectedBy(protecting_extensions, GURL("http://bar.wildcards/")); | 292 ExpectProtectedBy(protecting_extensions, GURL("http://bar.wildcards/")); |
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
364 SpecialStoragePolicy::STORAGE_PROTECTED, | 364 SpecialStoragePolicy::STORAGE_PROTECTED, |
365 | 365 |
366 SpecialStoragePolicy::STORAGE_PROTECTED | | 366 SpecialStoragePolicy::STORAGE_PROTECTED | |
367 SpecialStoragePolicy::STORAGE_UNLIMITED, | 367 SpecialStoragePolicy::STORAGE_UNLIMITED, |
368 }; | 368 }; |
369 | 369 |
370 ASSERT_EQ(arraysize(apps), arraysize(change_flags)); | 370 ASSERT_EQ(arraysize(apps), arraysize(change_flags)); |
371 for (size_t i = 0; i < arraysize(apps); ++i) { | 371 for (size_t i = 0; i < arraysize(apps); ++i) { |
372 SCOPED_TRACE(testing::Message() << "i: " << i); | 372 SCOPED_TRACE(testing::Message() << "i: " << i); |
373 observer.ExpectGrant(apps[i]->id(), change_flags[i]); | 373 observer.ExpectGrant(apps[i]->id(), change_flags[i]); |
374 policy_->GrantRightsForExtension(apps[i].get()); | 374 policy_->GrantRightsForExtension(apps[i].get(), NULL); |
375 message_loop.RunUntilIdle(); | 375 message_loop.RunUntilIdle(); |
376 EXPECT_TRUE(observer.IsCompleted()); | 376 EXPECT_TRUE(observer.IsCompleted()); |
377 } | 377 } |
378 | 378 |
379 for (size_t i = 0; i < arraysize(apps); ++i) { | 379 for (size_t i = 0; i < arraysize(apps); ++i) { |
380 SCOPED_TRACE(testing::Message() << "i: " << i); | 380 SCOPED_TRACE(testing::Message() << "i: " << i); |
381 policy_->GrantRightsForExtension(apps[i].get()); | 381 policy_->GrantRightsForExtension(apps[i].get(), NULL); |
382 message_loop.RunUntilIdle(); | 382 message_loop.RunUntilIdle(); |
383 EXPECT_TRUE(observer.IsCompleted()); | 383 EXPECT_TRUE(observer.IsCompleted()); |
384 } | 384 } |
385 | 385 |
386 for (size_t i = 0; i < arraysize(apps); ++i) { | 386 for (size_t i = 0; i < arraysize(apps); ++i) { |
387 SCOPED_TRACE(testing::Message() << "i: " << i); | 387 SCOPED_TRACE(testing::Message() << "i: " << i); |
388 observer.ExpectRevoke(apps[i]->id(), change_flags[i]); | 388 observer.ExpectRevoke(apps[i]->id(), change_flags[i]); |
389 policy_->RevokeRightsForExtension(apps[i].get()); | 389 policy_->RevokeRightsForExtension(apps[i].get()); |
390 message_loop.RunUntilIdle(); | 390 message_loop.RunUntilIdle(); |
391 EXPECT_TRUE(observer.IsCompleted()); | 391 EXPECT_TRUE(observer.IsCompleted()); |
392 } | 392 } |
393 | 393 |
394 for (size_t i = 0; i < arraysize(apps); ++i) { | 394 for (size_t i = 0; i < arraysize(apps); ++i) { |
395 SCOPED_TRACE(testing::Message() << "i: " << i); | 395 SCOPED_TRACE(testing::Message() << "i: " << i); |
396 policy_->RevokeRightsForExtension(apps[i].get()); | 396 policy_->RevokeRightsForExtension(apps[i].get()); |
397 message_loop.RunUntilIdle(); | 397 message_loop.RunUntilIdle(); |
398 EXPECT_TRUE(observer.IsCompleted()); | 398 EXPECT_TRUE(observer.IsCompleted()); |
399 } | 399 } |
400 | 400 |
401 observer.ExpectClear(); | 401 observer.ExpectClear(); |
402 policy_->RevokeRightsForAllExtensions(); | 402 policy_->RevokeRightsForAllExtensions(); |
403 message_loop.RunUntilIdle(); | 403 message_loop.RunUntilIdle(); |
404 EXPECT_TRUE(observer.IsCompleted()); | 404 EXPECT_TRUE(observer.IsCompleted()); |
405 | 405 |
406 policy_->RemoveObserver(&observer); | 406 policy_->RemoveObserver(&observer); |
407 } | 407 } |
OLD | NEW |