Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(222)

Side by Side Diff: chrome/browser/extensions/extension_special_storage_policy_unittest.cc

Issue 16295003: Update chrome/ to use scoped_refptr<T>::get() rather than implicit "operator T*" (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebased Created 7 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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.h" 5 #include "base/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/common/content_settings.h" 9 #include "chrome/common/content_settings.h"
10 #include "chrome/common/content_settings_types.h" 10 #include "chrome/common/content_settings_types.h"
(...skipping 178 matching lines...) Expand 10 before | Expand all | Expand 10 after
189 ExtensionSet empty_set; 189 ExtensionSet empty_set;
190 ExpectProtectedBy(empty_set, kHttpUrl); 190 ExpectProtectedBy(empty_set, kHttpUrl);
191 191
192 // This one is just based on the scheme. 192 // This one is just based on the scheme.
193 EXPECT_TRUE(policy_->IsStorageProtected(kExtensionUrl)); 193 EXPECT_TRUE(policy_->IsStorageProtected(kExtensionUrl));
194 EXPECT_TRUE(policy_->IsStorageProtected(app->url())); 194 EXPECT_TRUE(policy_->IsStorageProtected(app->url()));
195 } 195 }
196 196
197 TEST_F(ExtensionSpecialStoragePolicyTest, AppWithProtectedStorage) { 197 TEST_F(ExtensionSpecialStoragePolicyTest, AppWithProtectedStorage) {
198 scoped_refptr<Extension> extension(CreateProtectedApp()); 198 scoped_refptr<Extension> extension(CreateProtectedApp());
199 policy_->GrantRightsForExtension(extension); 199 policy_->GrantRightsForExtension(extension.get());
200 ExtensionSet protecting_extensions; 200 ExtensionSet protecting_extensions;
201 protecting_extensions.Insert(extension); 201 protecting_extensions.Insert(extension);
202 ExtensionSet empty_set; 202 ExtensionSet empty_set;
203 203
204 EXPECT_FALSE(policy_->IsStorageUnlimited(extension->url())); 204 EXPECT_FALSE(policy_->IsStorageUnlimited(extension->url()));
205 EXPECT_FALSE(policy_->IsStorageUnlimited(GURL("http://explicit/"))); 205 EXPECT_FALSE(policy_->IsStorageUnlimited(GURL("http://explicit/")));
206 ExpectProtectedBy(protecting_extensions, GURL("http://explicit/")); 206 ExpectProtectedBy(protecting_extensions, GURL("http://explicit/"));
207 ExpectProtectedBy(protecting_extensions, GURL("http://explicit:6000/")); 207 ExpectProtectedBy(protecting_extensions, GURL("http://explicit:6000/"));
208 ExpectProtectedBy(protecting_extensions, GURL("http://foo.wildcards/")); 208 ExpectProtectedBy(protecting_extensions, GURL("http://foo.wildcards/"));
209 ExpectProtectedBy(protecting_extensions, GURL("https://bar.wildcards/")); 209 ExpectProtectedBy(protecting_extensions, GURL("https://bar.wildcards/"));
210 ExpectProtectedBy(empty_set, GURL("http://not_listed/")); 210 ExpectProtectedBy(empty_set, GURL("http://not_listed/"));
211 211
212 policy_->RevokeRightsForExtension(extension); 212 policy_->RevokeRightsForExtension(extension.get());
213 ExpectProtectedBy(empty_set, GURL("http://explicit/")); 213 ExpectProtectedBy(empty_set, GURL("http://explicit/"));
214 ExpectProtectedBy(empty_set, GURL("http://foo.wildcards/")); 214 ExpectProtectedBy(empty_set, GURL("http://foo.wildcards/"));
215 ExpectProtectedBy(empty_set, GURL("https://bar.wildcards/")); 215 ExpectProtectedBy(empty_set, GURL("https://bar.wildcards/"));
216 } 216 }
217 217
218 TEST_F(ExtensionSpecialStoragePolicyTest, AppWithUnlimitedStorage) { 218 TEST_F(ExtensionSpecialStoragePolicyTest, AppWithUnlimitedStorage) {
219 scoped_refptr<Extension> extension(CreateUnlimitedApp()); 219 scoped_refptr<Extension> extension(CreateUnlimitedApp());
220 policy_->GrantRightsForExtension(extension); 220 policy_->GrantRightsForExtension(extension.get());
221 ExtensionSet protecting_extensions; 221 ExtensionSet protecting_extensions;
222 protecting_extensions.Insert(extension); 222 protecting_extensions.Insert(extension);
223 ExtensionSet empty_set; 223 ExtensionSet empty_set;
224 224
225 ExpectProtectedBy(protecting_extensions, GURL("http://explicit/")); 225 ExpectProtectedBy(protecting_extensions, GURL("http://explicit/"));
226 ExpectProtectedBy(protecting_extensions, GURL("http://explicit:6000/")); 226 ExpectProtectedBy(protecting_extensions, GURL("http://explicit:6000/"));
227 ExpectProtectedBy(protecting_extensions, GURL("https://foo.wildcards/")); 227 ExpectProtectedBy(protecting_extensions, GURL("https://foo.wildcards/"));
228 ExpectProtectedBy(protecting_extensions, GURL("https://foo.wildcards/")); 228 ExpectProtectedBy(protecting_extensions, GURL("https://foo.wildcards/"));
229 ExpectProtectedBy(protecting_extensions, GURL("http://bar.wildcards/")); 229 ExpectProtectedBy(protecting_extensions, GURL("http://bar.wildcards/"));
230 ExpectProtectedBy(empty_set, GURL("http://not_listed/")); 230 ExpectProtectedBy(empty_set, GURL("http://not_listed/"));
231 EXPECT_TRUE(policy_->IsStorageUnlimited(extension->url())); 231 EXPECT_TRUE(policy_->IsStorageUnlimited(extension->url()));
232 EXPECT_TRUE(policy_->IsStorageUnlimited(GURL("http://explicit/"))); 232 EXPECT_TRUE(policy_->IsStorageUnlimited(GURL("http://explicit/")));
233 EXPECT_TRUE(policy_->IsStorageUnlimited(GURL("http://explicit:6000/"))); 233 EXPECT_TRUE(policy_->IsStorageUnlimited(GURL("http://explicit:6000/")));
234 EXPECT_TRUE(policy_->IsStorageUnlimited(GURL("https://foo.wildcards/"))); 234 EXPECT_TRUE(policy_->IsStorageUnlimited(GURL("https://foo.wildcards/")));
235 EXPECT_TRUE(policy_->IsStorageUnlimited(GURL("https://bar.wildcards/"))); 235 EXPECT_TRUE(policy_->IsStorageUnlimited(GURL("https://bar.wildcards/")));
236 EXPECT_FALSE(policy_->IsStorageUnlimited(GURL("http://not_listed/"))); 236 EXPECT_FALSE(policy_->IsStorageUnlimited(GURL("http://not_listed/")));
237 237
238 policy_->RevokeRightsForExtension(extension); 238 policy_->RevokeRightsForExtension(extension.get());
239 ExpectProtectedBy(empty_set, GURL("http://explicit/")); 239 ExpectProtectedBy(empty_set, GURL("http://explicit/"));
240 ExpectProtectedBy(empty_set, GURL("https://foo.wildcards/")); 240 ExpectProtectedBy(empty_set, GURL("https://foo.wildcards/"));
241 ExpectProtectedBy(empty_set, GURL("https://foo.wildcards/")); 241 ExpectProtectedBy(empty_set, GURL("https://foo.wildcards/"));
242 ExpectProtectedBy(empty_set, GURL("http://bar.wildcards/")); 242 ExpectProtectedBy(empty_set, GURL("http://bar.wildcards/"));
243 EXPECT_FALSE(policy_->IsStorageUnlimited(GURL("http://explicit/"))); 243 EXPECT_FALSE(policy_->IsStorageUnlimited(GURL("http://explicit/")));
244 EXPECT_FALSE(policy_->IsStorageUnlimited(GURL("https://foo.wildcards/"))); 244 EXPECT_FALSE(policy_->IsStorageUnlimited(GURL("https://foo.wildcards/")));
245 EXPECT_FALSE(policy_->IsStorageUnlimited(GURL("https://bar.wildcards/"))); 245 EXPECT_FALSE(policy_->IsStorageUnlimited(GURL("https://bar.wildcards/")));
246 } 246 }
247 247
248 TEST_F(ExtensionSpecialStoragePolicyTest, CanQueryDiskSize) { 248 TEST_F(ExtensionSpecialStoragePolicyTest, CanQueryDiskSize) {
249 const GURL kHttpUrl("http://foo"); 249 const GURL kHttpUrl("http://foo");
250 const GURL kExtensionUrl("chrome-extension://bar"); 250 const GURL kExtensionUrl("chrome-extension://bar");
251 scoped_refptr<Extension> regular_app(CreateRegularApp()); 251 scoped_refptr<Extension> regular_app(CreateRegularApp());
252 scoped_refptr<Extension> protected_app(CreateProtectedApp()); 252 scoped_refptr<Extension> protected_app(CreateProtectedApp());
253 scoped_refptr<Extension> unlimited_app(CreateUnlimitedApp()); 253 scoped_refptr<Extension> unlimited_app(CreateUnlimitedApp());
254 policy_->GrantRightsForExtension(regular_app); 254 policy_->GrantRightsForExtension(regular_app.get());
255 policy_->GrantRightsForExtension(protected_app); 255 policy_->GrantRightsForExtension(protected_app.get());
256 policy_->GrantRightsForExtension(unlimited_app); 256 policy_->GrantRightsForExtension(unlimited_app.get());
257 257
258 EXPECT_FALSE(policy_->CanQueryDiskSize(kHttpUrl)); 258 EXPECT_FALSE(policy_->CanQueryDiskSize(kHttpUrl));
259 EXPECT_FALSE(policy_->CanQueryDiskSize(kExtensionUrl)); 259 EXPECT_FALSE(policy_->CanQueryDiskSize(kExtensionUrl));
260 EXPECT_TRUE(policy_->CanQueryDiskSize(regular_app->url())); 260 EXPECT_TRUE(policy_->CanQueryDiskSize(regular_app->url()));
261 EXPECT_TRUE(policy_->CanQueryDiskSize(protected_app->url())); 261 EXPECT_TRUE(policy_->CanQueryDiskSize(protected_app->url()));
262 EXPECT_TRUE(policy_->CanQueryDiskSize(unlimited_app->url())); 262 EXPECT_TRUE(policy_->CanQueryDiskSize(unlimited_app->url()));
263 } 263 }
264 264
265 TEST_F(ExtensionSpecialStoragePolicyTest, HasIsolatedStorage) { 265 TEST_F(ExtensionSpecialStoragePolicyTest, HasIsolatedStorage) {
266 const GURL kHttpUrl("http://foo"); 266 const GURL kHttpUrl("http://foo");
267 const GURL kExtensionUrl("chrome-extension://bar"); 267 const GURL kExtensionUrl("chrome-extension://bar");
268 scoped_refptr<Extension> app(CreateRegularApp()); 268 scoped_refptr<Extension> app(CreateRegularApp());
269 policy_->GrantRightsForExtension(app); 269 policy_->GrantRightsForExtension(app.get());
270 270
271 EXPECT_FALSE(policy_->HasIsolatedStorage(kHttpUrl)); 271 EXPECT_FALSE(policy_->HasIsolatedStorage(kHttpUrl));
272 EXPECT_FALSE(policy_->HasIsolatedStorage(kExtensionUrl)); 272 EXPECT_FALSE(policy_->HasIsolatedStorage(kExtensionUrl));
273 EXPECT_TRUE(policy_->HasIsolatedStorage(app->url())); 273 EXPECT_TRUE(policy_->HasIsolatedStorage(app->url()));
274 } 274 }
275 275
276 TEST_F(ExtensionSpecialStoragePolicyTest, OverlappingApps) { 276 TEST_F(ExtensionSpecialStoragePolicyTest, OverlappingApps) {
277 scoped_refptr<Extension> protected_app(CreateProtectedApp()); 277 scoped_refptr<Extension> protected_app(CreateProtectedApp());
278 scoped_refptr<Extension> unlimited_app(CreateUnlimitedApp()); 278 scoped_refptr<Extension> unlimited_app(CreateUnlimitedApp());
279 policy_->GrantRightsForExtension(protected_app); 279 policy_->GrantRightsForExtension(protected_app.get());
280 policy_->GrantRightsForExtension(unlimited_app); 280 policy_->GrantRightsForExtension(unlimited_app.get());
281 ExtensionSet protecting_extensions; 281 ExtensionSet protecting_extensions;
282 ExtensionSet empty_set; 282 ExtensionSet empty_set;
283 protecting_extensions.Insert(protected_app); 283 protecting_extensions.Insert(protected_app);
284 protecting_extensions.Insert(unlimited_app); 284 protecting_extensions.Insert(unlimited_app);
285 285
286 ExpectProtectedBy(protecting_extensions, GURL("http://explicit/")); 286 ExpectProtectedBy(protecting_extensions, GURL("http://explicit/"));
287 ExpectProtectedBy(protecting_extensions, GURL("http://explicit:6000/")); 287 ExpectProtectedBy(protecting_extensions, GURL("http://explicit:6000/"));
288 ExpectProtectedBy(protecting_extensions, GURL("https://foo.wildcards/")); 288 ExpectProtectedBy(protecting_extensions, GURL("https://foo.wildcards/"));
289 ExpectProtectedBy(protecting_extensions, GURL("https://foo.wildcards/")); 289 ExpectProtectedBy(protecting_extensions, GURL("https://foo.wildcards/"));
290 ExpectProtectedBy(protecting_extensions, GURL("http://bar.wildcards/")); 290 ExpectProtectedBy(protecting_extensions, GURL("http://bar.wildcards/"));
291 ExpectProtectedBy(empty_set, GURL("http://not_listed/")); 291 ExpectProtectedBy(empty_set, GURL("http://not_listed/"));
292 EXPECT_TRUE(policy_->IsStorageUnlimited(GURL("http://explicit/"))); 292 EXPECT_TRUE(policy_->IsStorageUnlimited(GURL("http://explicit/")));
293 EXPECT_TRUE(policy_->IsStorageUnlimited(GURL("http://explicit:6000/"))); 293 EXPECT_TRUE(policy_->IsStorageUnlimited(GURL("http://explicit:6000/")));
294 EXPECT_TRUE(policy_->IsStorageUnlimited(GURL("https://foo.wildcards/"))); 294 EXPECT_TRUE(policy_->IsStorageUnlimited(GURL("https://foo.wildcards/")));
295 EXPECT_TRUE(policy_->IsStorageUnlimited(GURL("https://bar.wildcards/"))); 295 EXPECT_TRUE(policy_->IsStorageUnlimited(GURL("https://bar.wildcards/")));
296 EXPECT_FALSE(policy_->IsStorageUnlimited(GURL("http://not_listed/"))); 296 EXPECT_FALSE(policy_->IsStorageUnlimited(GURL("http://not_listed/")));
297 297
298 policy_->RevokeRightsForExtension(unlimited_app); 298 policy_->RevokeRightsForExtension(unlimited_app.get());
299 protecting_extensions.Remove(unlimited_app->id()); 299 protecting_extensions.Remove(unlimited_app->id());
300 EXPECT_FALSE(policy_->IsStorageUnlimited(GURL("http://explicit/"))); 300 EXPECT_FALSE(policy_->IsStorageUnlimited(GURL("http://explicit/")));
301 EXPECT_FALSE(policy_->IsStorageUnlimited(GURL("https://foo.wildcards/"))); 301 EXPECT_FALSE(policy_->IsStorageUnlimited(GURL("https://foo.wildcards/")));
302 EXPECT_FALSE(policy_->IsStorageUnlimited(GURL("https://bar.wildcards/"))); 302 EXPECT_FALSE(policy_->IsStorageUnlimited(GURL("https://bar.wildcards/")));
303 ExpectProtectedBy(protecting_extensions, GURL("http://explicit/")); 303 ExpectProtectedBy(protecting_extensions, GURL("http://explicit/"));
304 ExpectProtectedBy(protecting_extensions, GURL("http://foo.wildcards/")); 304 ExpectProtectedBy(protecting_extensions, GURL("http://foo.wildcards/"));
305 ExpectProtectedBy(protecting_extensions, GURL("https://bar.wildcards/")); 305 ExpectProtectedBy(protecting_extensions, GURL("https://bar.wildcards/"));
306 306
307 policy_->RevokeRightsForExtension(protected_app); 307 policy_->RevokeRightsForExtension(protected_app.get());
308 ExpectProtectedBy(empty_set, GURL("http://explicit/")); 308 ExpectProtectedBy(empty_set, GURL("http://explicit/"));
309 ExpectProtectedBy(empty_set, GURL("http://foo.wildcards/")); 309 ExpectProtectedBy(empty_set, GURL("http://foo.wildcards/"));
310 ExpectProtectedBy(empty_set, GURL("https://bar.wildcards/")); 310 ExpectProtectedBy(empty_set, GURL("https://bar.wildcards/"));
311 } 311 }
312 312
313 TEST_F(ExtensionSpecialStoragePolicyTest, HasSessionOnlyOrigins) { 313 TEST_F(ExtensionSpecialStoragePolicyTest, HasSessionOnlyOrigins) {
314 base::MessageLoop message_loop; 314 base::MessageLoop message_loop;
315 content::TestBrowserThread ui_thread(BrowserThread::UI, &message_loop); 315 content::TestBrowserThread ui_thread(BrowserThread::UI, &message_loop);
316 316
317 TestingProfile profile; 317 TestingProfile profile;
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
362 SpecialStoragePolicy::STORAGE_PROTECTED, 362 SpecialStoragePolicy::STORAGE_PROTECTED,
363 363
364 SpecialStoragePolicy::STORAGE_PROTECTED | 364 SpecialStoragePolicy::STORAGE_PROTECTED |
365 SpecialStoragePolicy::STORAGE_UNLIMITED, 365 SpecialStoragePolicy::STORAGE_UNLIMITED,
366 }; 366 };
367 367
368 ASSERT_EQ(arraysize(apps), arraysize(change_flags)); 368 ASSERT_EQ(arraysize(apps), arraysize(change_flags));
369 for (size_t i = 0; i < arraysize(apps); ++i) { 369 for (size_t i = 0; i < arraysize(apps); ++i) {
370 SCOPED_TRACE(testing::Message() << "i: " << i); 370 SCOPED_TRACE(testing::Message() << "i: " << i);
371 observer.ExpectGrant(apps[i]->id(), change_flags[i]); 371 observer.ExpectGrant(apps[i]->id(), change_flags[i]);
372 policy_->GrantRightsForExtension(apps[i]); 372 policy_->GrantRightsForExtension(apps[i].get());
373 message_loop.RunUntilIdle(); 373 message_loop.RunUntilIdle();
374 EXPECT_TRUE(observer.IsCompleted()); 374 EXPECT_TRUE(observer.IsCompleted());
375 } 375 }
376 376
377 for (size_t i = 0; i < arraysize(apps); ++i) { 377 for (size_t i = 0; i < arraysize(apps); ++i) {
378 SCOPED_TRACE(testing::Message() << "i: " << i); 378 SCOPED_TRACE(testing::Message() << "i: " << i);
379 policy_->GrantRightsForExtension(apps[i]); 379 policy_->GrantRightsForExtension(apps[i].get());
380 message_loop.RunUntilIdle(); 380 message_loop.RunUntilIdle();
381 EXPECT_TRUE(observer.IsCompleted()); 381 EXPECT_TRUE(observer.IsCompleted());
382 } 382 }
383 383
384 for (size_t i = 0; i < arraysize(apps); ++i) { 384 for (size_t i = 0; i < arraysize(apps); ++i) {
385 SCOPED_TRACE(testing::Message() << "i: " << i); 385 SCOPED_TRACE(testing::Message() << "i: " << i);
386 observer.ExpectRevoke(apps[i]->id(), change_flags[i]); 386 observer.ExpectRevoke(apps[i]->id(), change_flags[i]);
387 policy_->RevokeRightsForExtension(apps[i]); 387 policy_->RevokeRightsForExtension(apps[i].get());
388 message_loop.RunUntilIdle(); 388 message_loop.RunUntilIdle();
389 EXPECT_TRUE(observer.IsCompleted()); 389 EXPECT_TRUE(observer.IsCompleted());
390 } 390 }
391 391
392 for (size_t i = 0; i < arraysize(apps); ++i) { 392 for (size_t i = 0; i < arraysize(apps); ++i) {
393 SCOPED_TRACE(testing::Message() << "i: " << i); 393 SCOPED_TRACE(testing::Message() << "i: " << i);
394 policy_->RevokeRightsForExtension(apps[i]); 394 policy_->RevokeRightsForExtension(apps[i].get());
395 message_loop.RunUntilIdle(); 395 message_loop.RunUntilIdle();
396 EXPECT_TRUE(observer.IsCompleted()); 396 EXPECT_TRUE(observer.IsCompleted());
397 } 397 }
398 398
399 observer.ExpectClear(); 399 observer.ExpectClear();
400 policy_->RevokeRightsForAllExtensions(); 400 policy_->RevokeRightsForAllExtensions();
401 message_loop.RunUntilIdle(); 401 message_loop.RunUntilIdle();
402 EXPECT_TRUE(observer.IsCompleted()); 402 EXPECT_TRUE(observer.IsCompleted());
403 403
404 policy_->RemoveObserver(&observer); 404 policy_->RemoveObserver(&observer);
405 } 405 }
OLDNEW
« no previous file with comments | « chrome/browser/extensions/extension_special_storage_policy.cc ('k') | chrome/browser/extensions/extension_system.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698