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

Side by Side Diff: webkit/appcache/appcache_host_unittest.cc

Issue 16155009: Update webkit/ to use scoped_refptr<T>::get() rather than implicit "operator T*" (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: 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
« no previous file with comments | « webkit/appcache/appcache_host.cc ('k') | webkit/appcache/appcache_request_handler.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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/bind.h" 5 #include "base/bind.h"
6 #include "base/bind_helpers.h" 6 #include "base/bind_helpers.h"
7 #include "base/memory/scoped_ptr.h" 7 #include "base/memory/scoped_ptr.h"
8 #include "base/message_loop.h" 8 #include "base/message_loop.h"
9 #include "net/url_request/url_request.h" 9 #include "net/url_request/url_request.h"
10 #include "testing/gtest/include/gtest/gtest.h" 10 #include "testing/gtest/include/gtest/gtest.h"
(...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after
182 182
183 last_swap_result_ = true; 183 last_swap_result_ = true;
184 host.SwapCacheWithCallback(swap_cache_callback_, reinterpret_cast<void*>(3)); 184 host.SwapCacheWithCallback(swap_cache_callback_, reinterpret_cast<void*>(3));
185 EXPECT_FALSE(last_swap_result_); 185 EXPECT_FALSE(last_swap_result_);
186 EXPECT_EQ(reinterpret_cast<void*>(3), last_callback_param_); 186 EXPECT_EQ(reinterpret_cast<void*>(3), last_callback_param_);
187 } 187 }
188 188
189 TEST_F(AppCacheHostTest, SelectNoCache) { 189 TEST_F(AppCacheHostTest, SelectNoCache) {
190 scoped_refptr<MockQuotaManagerProxy> mock_quota_proxy( 190 scoped_refptr<MockQuotaManagerProxy> mock_quota_proxy(
191 new MockQuotaManagerProxy); 191 new MockQuotaManagerProxy);
192 service_.set_quota_manager_proxy(mock_quota_proxy); 192 service_.set_quota_manager_proxy(mock_quota_proxy.get());
193 193
194 // Reset our mock frontend 194 // Reset our mock frontend
195 mock_frontend_.last_cache_id_ = -333; 195 mock_frontend_.last_cache_id_ = -333;
196 mock_frontend_.last_host_id_ = -333; 196 mock_frontend_.last_host_id_ = -333;
197 mock_frontend_.last_status_ = OBSOLETE; 197 mock_frontend_.last_status_ = OBSOLETE;
198 198
199 const GURL kDocAndOriginUrl(GURL("http://whatever/").GetOrigin()); 199 const GURL kDocAndOriginUrl(GURL("http://whatever/").GetOrigin());
200 { 200 {
201 AppCacheHost host(1, &mock_frontend_, &service_); 201 AppCacheHost host(1, &mock_frontend_, &service_);
202 host.SelectCache(kDocAndOriginUrl, kNoCacheId, GURL()); 202 host.SelectCache(kDocAndOriginUrl, kNoCacheId, GURL());
(...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after
343 EXPECT_EQ(reinterpret_cast<void*>(1), last_callback_param_); 343 EXPECT_EQ(reinterpret_cast<void*>(1), last_callback_param_);
344 } 344 }
345 345
346 TEST_F(AppCacheHostTest, SetSwappableCache) { 346 TEST_F(AppCacheHostTest, SetSwappableCache) {
347 AppCacheHost host(1, &mock_frontend_, &service_); 347 AppCacheHost host(1, &mock_frontend_, &service_);
348 host.SetSwappableCache(NULL); 348 host.SetSwappableCache(NULL);
349 EXPECT_FALSE(host.swappable_cache_.get()); 349 EXPECT_FALSE(host.swappable_cache_.get());
350 350
351 scoped_refptr<AppCacheGroup> group1(new AppCacheGroup( 351 scoped_refptr<AppCacheGroup> group1(new AppCacheGroup(
352 service_.storage(), GURL(), service_.storage()->NewGroupId())); 352 service_.storage(), GURL(), service_.storage()->NewGroupId()));
353 host.SetSwappableCache(group1); 353 host.SetSwappableCache(group1.get());
354 EXPECT_FALSE(host.swappable_cache_.get()); 354 EXPECT_FALSE(host.swappable_cache_.get());
355 355
356 AppCache* cache1 = new AppCache(service_.storage(), 111); 356 AppCache* cache1 = new AppCache(service_.storage(), 111);
357 cache1->set_complete(true); 357 cache1->set_complete(true);
358 group1->AddCache(cache1); 358 group1->AddCache(cache1);
359 host.SetSwappableCache(group1); 359 host.SetSwappableCache(group1.get());
360 EXPECT_EQ(cache1, host.swappable_cache_.get()); 360 EXPECT_EQ(cache1, host.swappable_cache_.get());
361 361
362 mock_frontend_.last_host_id_ = -222; // to verify we received OnCacheSelected 362 mock_frontend_.last_host_id_ = -222; // to verify we received OnCacheSelected
363 363
364 host.AssociateCompleteCache(cache1); 364 host.AssociateCompleteCache(cache1);
365 EXPECT_FALSE(host.swappable_cache_.get()); // was same as associated cache 365 EXPECT_FALSE(host.swappable_cache_.get()); // was same as associated cache
366 EXPECT_EQ(appcache::IDLE, host.GetStatus()); 366 EXPECT_EQ(appcache::IDLE, host.GetStatus());
367 // verify OnCacheSelected was called 367 // verify OnCacheSelected was called
368 EXPECT_EQ(host.host_id(), mock_frontend_.last_host_id_); 368 EXPECT_EQ(host.host_id(), mock_frontend_.last_host_id_);
369 EXPECT_EQ(cache1->cache_id(), mock_frontend_.last_cache_id_); 369 EXPECT_EQ(cache1->cache_id(), mock_frontend_.last_cache_id_);
(...skipping 22 matching lines...) Expand all
392 392
393 host.AssociateNoCache(GURL()); 393 host.AssociateNoCache(GURL());
394 EXPECT_FALSE(host.swappable_cache_.get()); 394 EXPECT_FALSE(host.swappable_cache_.get());
395 EXPECT_FALSE(group2->HasCache()); // both caches in group2 have refcount 0 395 EXPECT_FALSE(group2->HasCache()); // both caches in group2 have refcount 0
396 396
397 // Host adds reference to newest cache when an update is complete. 397 // Host adds reference to newest cache when an update is complete.
398 AppCache* cache5 = new AppCache(service_.storage(), 555); 398 AppCache* cache5 = new AppCache(service_.storage(), 555);
399 cache5->set_complete(true); 399 cache5->set_complete(true);
400 group2->AddCache(cache5); 400 group2->AddCache(cache5);
401 host.group_being_updated_ = group2; 401 host.group_being_updated_ = group2;
402 host.OnUpdateComplete(group2); 402 host.OnUpdateComplete(group2.get());
403 EXPECT_FALSE(host.group_being_updated_); 403 EXPECT_FALSE(host.group_being_updated_.get());
404 EXPECT_EQ(cache5, host.swappable_cache_.get()); 404 EXPECT_EQ(cache5, host.swappable_cache_.get());
405 405
406 group2->RemoveCache(cache5); 406 group2->RemoveCache(cache5);
407 EXPECT_FALSE(group2->HasCache()); 407 EXPECT_FALSE(group2->HasCache());
408 host.group_being_updated_ = group2; 408 host.group_being_updated_ = group2;
409 host.OnUpdateComplete(group2); 409 host.OnUpdateComplete(group2.get());
410 EXPECT_FALSE(host.group_being_updated_); 410 EXPECT_FALSE(host.group_being_updated_.get());
411 EXPECT_FALSE(host.swappable_cache_.get()); // group2 had no newest cache 411 EXPECT_FALSE(host.swappable_cache_.get()); // group2 had no newest cache
412 } 412 }
413 413
414 TEST_F(AppCacheHostTest, ForDedicatedWorker) { 414 TEST_F(AppCacheHostTest, ForDedicatedWorker) {
415 const int kMockProcessId = 1; 415 const int kMockProcessId = 1;
416 const int kParentHostId = 1; 416 const int kParentHostId = 1;
417 const int kWorkerHostId = 2; 417 const int kWorkerHostId = 2;
418 418
419 AppCacheBackendImpl backend_impl; 419 AppCacheBackendImpl backend_impl;
420 backend_impl.Initialize(&service_, &mock_frontend_, kMockProcessId); 420 backend_impl.Initialize(&service_, &mock_frontend_, kMockProcessId);
(...skipping 22 matching lines...) Expand all
443 parent_host = NULL; 443 parent_host = NULL;
444 EXPECT_EQ(NULL, backend_impl.GetHost(kParentHostId)); 444 EXPECT_EQ(NULL, backend_impl.GetHost(kParentHostId));
445 EXPECT_EQ(NULL, worker_host->GetParentAppCacheHost()); 445 EXPECT_EQ(NULL, worker_host->GetParentAppCacheHost());
446 } 446 }
447 447
448 TEST_F(AppCacheHostTest, SelectCacheAllowed) { 448 TEST_F(AppCacheHostTest, SelectCacheAllowed) {
449 scoped_refptr<MockQuotaManagerProxy> mock_quota_proxy( 449 scoped_refptr<MockQuotaManagerProxy> mock_quota_proxy(
450 new MockQuotaManagerProxy); 450 new MockQuotaManagerProxy);
451 MockAppCachePolicy mock_appcache_policy; 451 MockAppCachePolicy mock_appcache_policy;
452 mock_appcache_policy.can_create_return_value_ = true; 452 mock_appcache_policy.can_create_return_value_ = true;
453 service_.set_quota_manager_proxy(mock_quota_proxy); 453 service_.set_quota_manager_proxy(mock_quota_proxy.get());
454 service_.set_appcache_policy(&mock_appcache_policy); 454 service_.set_appcache_policy(&mock_appcache_policy);
455 455
456 // Reset our mock frontend 456 // Reset our mock frontend
457 mock_frontend_.last_cache_id_ = -333; 457 mock_frontend_.last_cache_id_ = -333;
458 mock_frontend_.last_host_id_ = -333; 458 mock_frontend_.last_host_id_ = -333;
459 mock_frontend_.last_status_ = OBSOLETE; 459 mock_frontend_.last_status_ = OBSOLETE;
460 mock_frontend_.last_event_id_ = OBSOLETE_EVENT; 460 mock_frontend_.last_event_id_ = OBSOLETE_EVENT;
461 mock_frontend_.content_blocked_ = false; 461 mock_frontend_.content_blocked_ = false;
462 462
463 const GURL kDocAndOriginUrl(GURL("http://whatever/").GetOrigin()); 463 const GURL kDocAndOriginUrl(GURL("http://whatever/").GetOrigin());
(...skipping 17 matching lines...) Expand all
481 } 481 }
482 EXPECT_EQ(0, mock_quota_proxy->GetInUseCount(kDocAndOriginUrl)); 482 EXPECT_EQ(0, mock_quota_proxy->GetInUseCount(kDocAndOriginUrl));
483 service_.set_quota_manager_proxy(NULL); 483 service_.set_quota_manager_proxy(NULL);
484 } 484 }
485 485
486 TEST_F(AppCacheHostTest, SelectCacheBlocked) { 486 TEST_F(AppCacheHostTest, SelectCacheBlocked) {
487 scoped_refptr<MockQuotaManagerProxy> mock_quota_proxy( 487 scoped_refptr<MockQuotaManagerProxy> mock_quota_proxy(
488 new MockQuotaManagerProxy); 488 new MockQuotaManagerProxy);
489 MockAppCachePolicy mock_appcache_policy; 489 MockAppCachePolicy mock_appcache_policy;
490 mock_appcache_policy.can_create_return_value_ = false; 490 mock_appcache_policy.can_create_return_value_ = false;
491 service_.set_quota_manager_proxy(mock_quota_proxy); 491 service_.set_quota_manager_proxy(mock_quota_proxy.get());
492 service_.set_appcache_policy(&mock_appcache_policy); 492 service_.set_appcache_policy(&mock_appcache_policy);
493 493
494 // Reset our mock frontend 494 // Reset our mock frontend
495 mock_frontend_.last_cache_id_ = -333; 495 mock_frontend_.last_cache_id_ = -333;
496 mock_frontend_.last_host_id_ = -333; 496 mock_frontend_.last_host_id_ = -333;
497 mock_frontend_.last_status_ = OBSOLETE; 497 mock_frontend_.last_status_ = OBSOLETE;
498 mock_frontend_.last_event_id_ = OBSOLETE_EVENT; 498 mock_frontend_.last_event_id_ = OBSOLETE_EVENT;
499 mock_frontend_.content_blocked_ = false; 499 mock_frontend_.content_blocked_ = false;
500 500
501 const GURL kDocAndOriginUrl(GURL("http://whatever/").GetOrigin()); 501 const GURL kDocAndOriginUrl(GURL("http://whatever/").GetOrigin());
(...skipping 19 matching lines...) Expand all
521 EXPECT_EQ(&mock_frontend_, host.frontend()); 521 EXPECT_EQ(&mock_frontend_, host.frontend());
522 EXPECT_EQ(NULL, host.associated_cache()); 522 EXPECT_EQ(NULL, host.associated_cache());
523 EXPECT_FALSE(host.is_selection_pending()); 523 EXPECT_FALSE(host.is_selection_pending());
524 EXPECT_TRUE(host.preferred_manifest_url().is_empty()); 524 EXPECT_TRUE(host.preferred_manifest_url().is_empty());
525 } 525 }
526 EXPECT_EQ(0, mock_quota_proxy->GetInUseCount(kDocAndOriginUrl)); 526 EXPECT_EQ(0, mock_quota_proxy->GetInUseCount(kDocAndOriginUrl));
527 service_.set_quota_manager_proxy(NULL); 527 service_.set_quota_manager_proxy(NULL);
528 } 528 }
529 529
530 } // namespace appcache 530 } // namespace appcache
OLDNEW
« no previous file with comments | « webkit/appcache/appcache_host.cc ('k') | webkit/appcache/appcache_request_handler.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698