| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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/callback.h" | 5 #include "base/callback.h" |
| 6 #include "base/scoped_ptr.h" | 6 #include "base/scoped_ptr.h" |
| 7 #include "net/url_request/url_request.h" | 7 #include "net/url_request/url_request.h" |
| 8 #include "testing/gtest/include/gtest/gtest.h" | 8 #include "testing/gtest/include/gtest/gtest.h" |
| 9 #include "webkit/appcache/appcache.h" | 9 #include "webkit/appcache/appcache.h" |
| 10 #include "webkit/appcache/appcache_backend_impl.h" | 10 #include "webkit/appcache/appcache_backend_impl.h" |
| (...skipping 237 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 248 // Callback should have fired upon completing the group load. | 248 // Callback should have fired upon completing the group load. |
| 249 EXPECT_EQ(UNCACHED, last_status_result_); | 249 EXPECT_EQ(UNCACHED, last_status_result_); |
| 250 EXPECT_EQ(reinterpret_cast<void*>(1), last_callback_param_); | 250 EXPECT_EQ(reinterpret_cast<void*>(1), last_callback_param_); |
| 251 } | 251 } |
| 252 | 252 |
| 253 TEST_F(AppCacheHostTest, SetSwappableCache) { | 253 TEST_F(AppCacheHostTest, SetSwappableCache) { |
| 254 AppCacheHost host(1, &mock_frontend_, &service_); | 254 AppCacheHost host(1, &mock_frontend_, &service_); |
| 255 host.SetSwappableCache(NULL); | 255 host.SetSwappableCache(NULL); |
| 256 EXPECT_FALSE(host.swappable_cache_.get()); | 256 EXPECT_FALSE(host.swappable_cache_.get()); |
| 257 | 257 |
| 258 scoped_refptr<AppCacheGroup> group1 = | 258 scoped_refptr<AppCacheGroup> group1( |
| 259 new AppCacheGroup(&service_, GURL(), service_.storage()->NewGroupId()); | 259 new AppCacheGroup(&service_, GURL(), service_.storage()->NewGroupId())); |
| 260 host.SetSwappableCache(group1); | 260 host.SetSwappableCache(group1); |
| 261 EXPECT_FALSE(host.swappable_cache_.get()); | 261 EXPECT_FALSE(host.swappable_cache_.get()); |
| 262 | 262 |
| 263 AppCache* cache1 = new AppCache(&service_, 111); | 263 AppCache* cache1 = new AppCache(&service_, 111); |
| 264 cache1->set_complete(true); | 264 cache1->set_complete(true); |
| 265 group1->AddCache(cache1); | 265 group1->AddCache(cache1); |
| 266 host.SetSwappableCache(group1); | 266 host.SetSwappableCache(group1); |
| 267 EXPECT_EQ(cache1, host.swappable_cache_.get()); | 267 EXPECT_EQ(cache1, host.swappable_cache_.get()); |
| 268 | 268 |
| 269 mock_frontend_.last_host_id_ = -222; // to verify we received OnCacheSelected | 269 mock_frontend_.last_host_id_ = -222; // to verify we received OnCacheSelected |
| 270 | 270 |
| 271 host.AssociateCache(cache1); | 271 host.AssociateCache(cache1); |
| 272 EXPECT_FALSE(host.swappable_cache_.get()); // was same as associated cache | 272 EXPECT_FALSE(host.swappable_cache_.get()); // was same as associated cache |
| 273 EXPECT_EQ(appcache::IDLE, host.GetStatus()); | 273 EXPECT_EQ(appcache::IDLE, host.GetStatus()); |
| 274 // verify OnCacheSelected was called | 274 // verify OnCacheSelected was called |
| 275 EXPECT_EQ(host.host_id(), mock_frontend_.last_host_id_); | 275 EXPECT_EQ(host.host_id(), mock_frontend_.last_host_id_); |
| 276 EXPECT_EQ(cache1->cache_id(), mock_frontend_.last_cache_id_); | 276 EXPECT_EQ(cache1->cache_id(), mock_frontend_.last_cache_id_); |
| 277 EXPECT_EQ(appcache::IDLE, mock_frontend_.last_status_); | 277 EXPECT_EQ(appcache::IDLE, mock_frontend_.last_status_); |
| 278 | 278 |
| 279 AppCache* cache2 = new AppCache(&service_, 222); | 279 AppCache* cache2 = new AppCache(&service_, 222); |
| 280 cache2->set_complete(true); | 280 cache2->set_complete(true); |
| 281 group1->AddCache(cache2); | 281 group1->AddCache(cache2); |
| 282 EXPECT_EQ(cache2, host.swappable_cache_.get()); // updated to newest | 282 EXPECT_EQ(cache2, host.swappable_cache_.get()); // updated to newest |
| 283 | 283 |
| 284 scoped_refptr<AppCacheGroup> group2 = | 284 scoped_refptr<AppCacheGroup> group2( |
| 285 new AppCacheGroup(&service_, GURL("http://foo.com"), | 285 new AppCacheGroup(&service_, GURL("http://foo.com"), |
| 286 service_.storage()->NewGroupId()); | 286 service_.storage()->NewGroupId())); |
| 287 AppCache* cache3 = new AppCache(&service_, 333); | 287 AppCache* cache3 = new AppCache(&service_, 333); |
| 288 cache3->set_complete(true); | 288 cache3->set_complete(true); |
| 289 group2->AddCache(cache3); | 289 group2->AddCache(cache3); |
| 290 | 290 |
| 291 AppCache* cache4 = new AppCache(&service_, 444); | 291 AppCache* cache4 = new AppCache(&service_, 444); |
| 292 cache4->set_complete(true); | 292 cache4->set_complete(true); |
| 293 group2->AddCache(cache4); | 293 group2->AddCache(cache4); |
| 294 EXPECT_EQ(cache2, host.swappable_cache_.get()); // unchanged | 294 EXPECT_EQ(cache2, host.swappable_cache_.get()); // unchanged |
| 295 | 295 |
| 296 host.AssociateCache(cache3); | 296 host.AssociateCache(cache3); |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 347 | 347 |
| 348 // Simulate the parent being torn down. | 348 // Simulate the parent being torn down. |
| 349 backend_impl.UnregisterHost(kParentHostId); | 349 backend_impl.UnregisterHost(kParentHostId); |
| 350 parent_host = NULL; | 350 parent_host = NULL; |
| 351 EXPECT_EQ(NULL, backend_impl.GetHost(kParentHostId)); | 351 EXPECT_EQ(NULL, backend_impl.GetHost(kParentHostId)); |
| 352 EXPECT_EQ(NULL, worker_host->GetParentAppCacheHost()); | 352 EXPECT_EQ(NULL, worker_host->GetParentAppCacheHost()); |
| 353 } | 353 } |
| 354 | 354 |
| 355 } // namespace appcache | 355 } // namespace appcache |
| 356 | 356 |
| OLD | NEW |