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.h" | 5 #include "base/message_loop.h" |
6 #include "testing/gtest/include/gtest/gtest.h" | 6 #include "testing/gtest/include/gtest/gtest.h" |
7 #include "webkit/appcache/appcache.h" | 7 #include "webkit/appcache/appcache.h" |
8 #include "webkit/appcache/appcache_group.h" | 8 #include "webkit/appcache/appcache_group.h" |
9 #include "webkit/appcache/appcache_response.h" | 9 #include "webkit/appcache/appcache_response.h" |
10 #include "webkit/appcache/appcache_storage.h" | 10 #include "webkit/appcache/appcache_storage.h" |
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
82 | 82 |
83 TEST_F(MockAppCacheStorageTest, LoadCache_Miss) { | 83 TEST_F(MockAppCacheStorageTest, LoadCache_Miss) { |
84 // Attempt to load a cache that doesn't exist. Should | 84 // Attempt to load a cache that doesn't exist. Should |
85 // complete asyncly. | 85 // complete asyncly. |
86 MockAppCacheService service; | 86 MockAppCacheService service; |
87 MockStorageDelegate delegate; | 87 MockStorageDelegate delegate; |
88 service.storage()->LoadCache(111, &delegate); | 88 service.storage()->LoadCache(111, &delegate); |
89 EXPECT_NE(111, delegate.loaded_cache_id_); | 89 EXPECT_NE(111, delegate.loaded_cache_id_); |
90 base::MessageLoop::current()->RunUntilIdle(); // Do async task execution. | 90 base::MessageLoop::current()->RunUntilIdle(); // Do async task execution. |
91 EXPECT_EQ(111, delegate.loaded_cache_id_); | 91 EXPECT_EQ(111, delegate.loaded_cache_id_); |
92 EXPECT_FALSE(delegate.loaded_cache_); | 92 EXPECT_FALSE(delegate.loaded_cache_.get()); |
93 } | 93 } |
94 | 94 |
95 TEST_F(MockAppCacheStorageTest, LoadCache_NearHit) { | 95 TEST_F(MockAppCacheStorageTest, LoadCache_NearHit) { |
96 // Attempt to load a cache that is currently in use | 96 // Attempt to load a cache that is currently in use |
97 // and does not require loading from disk. This | 97 // and does not require loading from disk. This |
98 // load should complete syncly. | 98 // load should complete syncly. |
99 MockAppCacheService service; | 99 MockAppCacheService service; |
100 | 100 |
101 // Setup some preconditions. Make an 'unstored' cache for | 101 // Setup some preconditions. Make an 'unstored' cache for |
102 // us to load. The ctor should put it in the working set. | 102 // us to load. The ctor should put it in the working set. |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
164 reinterpret_cast<MockAppCacheStorage*>(service.storage()); | 164 reinterpret_cast<MockAppCacheStorage*>(service.storage()); |
165 | 165 |
166 // Setup some preconditions. Create a group and newest cache that | 166 // Setup some preconditions. Create a group and newest cache that |
167 // appears to be "stored" and "not currently in use". | 167 // appears to be "stored" and "not currently in use". |
168 GURL manifest_url("http://blah/"); | 168 GURL manifest_url("http://blah/"); |
169 scoped_refptr<AppCacheGroup> group( | 169 scoped_refptr<AppCacheGroup> group( |
170 new AppCacheGroup(service.storage(), manifest_url, 111)); | 170 new AppCacheGroup(service.storage(), manifest_url, 111)); |
171 int64 cache_id = storage->NewCacheId(); | 171 int64 cache_id = storage->NewCacheId(); |
172 scoped_refptr<AppCache> cache(new AppCache(service.storage(), cache_id)); | 172 scoped_refptr<AppCache> cache(new AppCache(service.storage(), cache_id)); |
173 cache->set_complete(true); | 173 cache->set_complete(true); |
174 group->AddCache(cache); | 174 group->AddCache(cache.get()); |
175 storage->AddStoredGroup(group); | 175 storage->AddStoredGroup(group.get()); |
176 storage->AddStoredCache(cache); | 176 storage->AddStoredCache(cache.get()); |
177 | 177 |
178 // Drop the references from above so the only refs to these | 178 // Drop the references from above so the only refs to these |
179 // objects are from within the storage class. This is to make | 179 // objects are from within the storage class. This is to make |
180 // these objects appear as "not currently in use". | 180 // these objects appear as "not currently in use". |
181 AppCache* cache_ptr = cache.get(); | 181 AppCache* cache_ptr = cache.get(); |
182 AppCacheGroup* group_ptr = group.get(); | 182 AppCacheGroup* group_ptr = group.get(); |
183 cache = NULL; | 183 cache = NULL; |
184 group = NULL; | 184 group = NULL; |
185 | 185 |
186 // Setup a delegate to receive completion callbacks. | 186 // Setup a delegate to receive completion callbacks. |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
221 new AppCacheGroup(service.storage(), manifest_url, 111)); | 221 new AppCacheGroup(service.storage(), manifest_url, 111)); |
222 int64 cache_id = storage->NewCacheId(); | 222 int64 cache_id = storage->NewCacheId(); |
223 scoped_refptr<AppCache> cache(new AppCache(service.storage(), cache_id)); | 223 scoped_refptr<AppCache> cache(new AppCache(service.storage(), cache_id)); |
224 // Hold a ref to the cache simulate the UpdateJob holding that ref, | 224 // Hold a ref to the cache simulate the UpdateJob holding that ref, |
225 // and hold a ref to the group to simulate the CacheHost holding that ref. | 225 // and hold a ref to the group to simulate the CacheHost holding that ref. |
226 | 226 |
227 // Conduct the store test. | 227 // Conduct the store test. |
228 MockStorageDelegate delegate; | 228 MockStorageDelegate delegate; |
229 EXPECT_TRUE(storage->stored_caches_.empty()); | 229 EXPECT_TRUE(storage->stored_caches_.empty()); |
230 EXPECT_TRUE(storage->stored_groups_.empty()); | 230 EXPECT_TRUE(storage->stored_groups_.empty()); |
231 storage->StoreGroupAndNewestCache(group, cache, &delegate); | 231 storage->StoreGroupAndNewestCache(group.get(), cache.get(), &delegate); |
232 EXPECT_FALSE(delegate.stored_group_success_); | 232 EXPECT_FALSE(delegate.stored_group_success_); |
233 EXPECT_TRUE(storage->stored_caches_.empty()); | 233 EXPECT_TRUE(storage->stored_caches_.empty()); |
234 EXPECT_TRUE(storage->stored_groups_.empty()); | 234 EXPECT_TRUE(storage->stored_groups_.empty()); |
235 base::MessageLoop::current()->RunUntilIdle(); // Do async task execution. | 235 base::MessageLoop::current()->RunUntilIdle(); // Do async task execution. |
236 EXPECT_TRUE(delegate.stored_group_success_); | 236 EXPECT_TRUE(delegate.stored_group_success_); |
237 EXPECT_FALSE(storage->stored_caches_.empty()); | 237 EXPECT_FALSE(storage->stored_caches_.empty()); |
238 EXPECT_FALSE(storage->stored_groups_.empty()); | 238 EXPECT_FALSE(storage->stored_groups_.empty()); |
239 EXPECT_EQ(cache, group->newest_complete_cache()); | 239 EXPECT_EQ(cache, group->newest_complete_cache()); |
240 EXPECT_TRUE(cache->is_complete()); | 240 EXPECT_TRUE(cache->is_complete()); |
241 } | 241 } |
242 | 242 |
243 TEST_F(MockAppCacheStorageTest, StoreExistingGroup) { | 243 TEST_F(MockAppCacheStorageTest, StoreExistingGroup) { |
244 // Store a group and its newest cache. Should complete asyncly. | 244 // Store a group and its newest cache. Should complete asyncly. |
245 MockAppCacheService service; | 245 MockAppCacheService service; |
246 MockAppCacheStorage* storage = | 246 MockAppCacheStorage* storage = |
247 reinterpret_cast<MockAppCacheStorage*>(service.storage()); | 247 reinterpret_cast<MockAppCacheStorage*>(service.storage()); |
248 | 248 |
249 // Setup some preconditions. Create a group and old complete cache | 249 // Setup some preconditions. Create a group and old complete cache |
250 // that appear to be "stored", and a newest unstored complete cache. | 250 // that appear to be "stored", and a newest unstored complete cache. |
251 GURL manifest_url("http://blah/"); | 251 GURL manifest_url("http://blah/"); |
252 scoped_refptr<AppCacheGroup> group( | 252 scoped_refptr<AppCacheGroup> group( |
253 new AppCacheGroup(service.storage(), manifest_url, 111)); | 253 new AppCacheGroup(service.storage(), manifest_url, 111)); |
254 int64 old_cache_id = storage->NewCacheId(); | 254 int64 old_cache_id = storage->NewCacheId(); |
255 scoped_refptr<AppCache> old_cache( | 255 scoped_refptr<AppCache> old_cache( |
256 new AppCache(service.storage(), old_cache_id)); | 256 new AppCache(service.storage(), old_cache_id)); |
257 old_cache->set_complete(true); | 257 old_cache->set_complete(true); |
258 group->AddCache(old_cache); | 258 group->AddCache(old_cache.get()); |
259 storage->AddStoredGroup(group); | 259 storage->AddStoredGroup(group.get()); |
260 storage->AddStoredCache(old_cache); | 260 storage->AddStoredCache(old_cache.get()); |
261 int64 new_cache_id = storage->NewCacheId(); | 261 int64 new_cache_id = storage->NewCacheId(); |
262 scoped_refptr<AppCache> new_cache( | 262 scoped_refptr<AppCache> new_cache( |
263 new AppCache(service.storage(), new_cache_id)); | 263 new AppCache(service.storage(), new_cache_id)); |
264 // Hold our refs to simulate the UpdateJob holding these refs. | 264 // Hold our refs to simulate the UpdateJob holding these refs. |
265 | 265 |
266 // Conduct the test. | 266 // Conduct the test. |
267 MockStorageDelegate delegate; | 267 MockStorageDelegate delegate; |
268 EXPECT_EQ(size_t(1), storage->stored_caches_.size()); | 268 EXPECT_EQ(size_t(1), storage->stored_caches_.size()); |
269 EXPECT_EQ(size_t(1), storage->stored_groups_.size()); | 269 EXPECT_EQ(size_t(1), storage->stored_groups_.size()); |
270 EXPECT_TRUE(storage->IsCacheStored(old_cache)); | 270 EXPECT_TRUE(storage->IsCacheStored(old_cache.get())); |
271 EXPECT_FALSE(storage->IsCacheStored(new_cache)); | 271 EXPECT_FALSE(storage->IsCacheStored(new_cache.get())); |
272 storage->StoreGroupAndNewestCache(group, new_cache, &delegate); | 272 storage->StoreGroupAndNewestCache(group.get(), new_cache.get(), &delegate); |
273 EXPECT_FALSE(delegate.stored_group_success_); | 273 EXPECT_FALSE(delegate.stored_group_success_); |
274 EXPECT_EQ(size_t(1), storage->stored_caches_.size()); | 274 EXPECT_EQ(size_t(1), storage->stored_caches_.size()); |
275 EXPECT_EQ(size_t(1), storage->stored_groups_.size()); | 275 EXPECT_EQ(size_t(1), storage->stored_groups_.size()); |
276 EXPECT_TRUE(storage->IsCacheStored(old_cache)); | 276 EXPECT_TRUE(storage->IsCacheStored(old_cache.get())); |
277 EXPECT_FALSE(storage->IsCacheStored(new_cache)); | 277 EXPECT_FALSE(storage->IsCacheStored(new_cache.get())); |
278 base::MessageLoop::current()->RunUntilIdle(); // Do async task execution. | 278 base::MessageLoop::current()->RunUntilIdle(); // Do async task execution. |
279 EXPECT_TRUE(delegate.stored_group_success_); | 279 EXPECT_TRUE(delegate.stored_group_success_); |
280 EXPECT_EQ(size_t(1), storage->stored_caches_.size()); | 280 EXPECT_EQ(size_t(1), storage->stored_caches_.size()); |
281 EXPECT_EQ(size_t(1), storage->stored_groups_.size()); | 281 EXPECT_EQ(size_t(1), storage->stored_groups_.size()); |
282 EXPECT_FALSE(storage->IsCacheStored(old_cache)); | 282 EXPECT_FALSE(storage->IsCacheStored(old_cache.get())); |
283 EXPECT_TRUE(storage->IsCacheStored(new_cache)); | 283 EXPECT_TRUE(storage->IsCacheStored(new_cache.get())); |
284 EXPECT_EQ(new_cache.get(), group->newest_complete_cache()); | 284 EXPECT_EQ(new_cache.get(), group->newest_complete_cache()); |
285 EXPECT_TRUE(new_cache->is_complete()); | 285 EXPECT_TRUE(new_cache->is_complete()); |
286 } | 286 } |
287 | 287 |
288 TEST_F(MockAppCacheStorageTest, StoreExistingGroupExistingCache) { | 288 TEST_F(MockAppCacheStorageTest, StoreExistingGroupExistingCache) { |
289 // Store a group with updates to its existing newest complete cache. | 289 // Store a group with updates to its existing newest complete cache. |
290 MockAppCacheService service; | 290 MockAppCacheService service; |
291 MockAppCacheStorage* storage = | 291 MockAppCacheStorage* storage = |
292 reinterpret_cast<MockAppCacheStorage*>(service.storage()); | 292 reinterpret_cast<MockAppCacheStorage*>(service.storage()); |
293 | 293 |
294 // Setup some preconditions. Create a group and a complete cache that | 294 // Setup some preconditions. Create a group and a complete cache that |
295 // appear to be "stored". | 295 // appear to be "stored". |
296 GURL manifest_url("http://blah"); | 296 GURL manifest_url("http://blah"); |
297 scoped_refptr<AppCacheGroup> group( | 297 scoped_refptr<AppCacheGroup> group( |
298 new AppCacheGroup(service.storage(), manifest_url, 111)); | 298 new AppCacheGroup(service.storage(), manifest_url, 111)); |
299 int64 cache_id = storage->NewCacheId(); | 299 int64 cache_id = storage->NewCacheId(); |
300 scoped_refptr<AppCache> cache(new AppCache(service.storage(), cache_id)); | 300 scoped_refptr<AppCache> cache(new AppCache(service.storage(), cache_id)); |
301 cache->set_complete(true); | 301 cache->set_complete(true); |
302 group->AddCache(cache); | 302 group->AddCache(cache.get()); |
303 storage->AddStoredGroup(group); | 303 storage->AddStoredGroup(group.get()); |
304 storage->AddStoredCache(cache); | 304 storage->AddStoredCache(cache.get()); |
305 // Hold our refs to simulate the UpdateJob holding these refs. | 305 // Hold our refs to simulate the UpdateJob holding these refs. |
306 | 306 |
307 // Change the group's newest cache. | 307 // Change the group's newest cache. |
308 EXPECT_EQ(cache, group->newest_complete_cache()); | 308 EXPECT_EQ(cache, group->newest_complete_cache()); |
309 GURL entry_url("http://blah/blah"); | 309 GURL entry_url("http://blah/blah"); |
310 cache->AddEntry(entry_url, AppCacheEntry(AppCacheEntry::MASTER)); | 310 cache->AddEntry(entry_url, AppCacheEntry(AppCacheEntry::MASTER)); |
311 | 311 |
312 // Conduct the test. | 312 // Conduct the test. |
313 MockStorageDelegate delegate; | 313 MockStorageDelegate delegate; |
314 EXPECT_EQ(size_t(1), storage->stored_caches_.size()); | 314 EXPECT_EQ(size_t(1), storage->stored_caches_.size()); |
315 EXPECT_EQ(size_t(1), storage->stored_groups_.size()); | 315 EXPECT_EQ(size_t(1), storage->stored_groups_.size()); |
316 EXPECT_TRUE(storage->IsCacheStored(cache)); | 316 EXPECT_TRUE(storage->IsCacheStored(cache.get())); |
317 storage->StoreGroupAndNewestCache(group, cache, &delegate); | 317 storage->StoreGroupAndNewestCache(group.get(), cache.get(), &delegate); |
318 EXPECT_FALSE(delegate.stored_group_success_); | 318 EXPECT_FALSE(delegate.stored_group_success_); |
319 EXPECT_EQ(size_t(1), storage->stored_caches_.size()); | 319 EXPECT_EQ(size_t(1), storage->stored_caches_.size()); |
320 EXPECT_EQ(size_t(1), storage->stored_groups_.size()); | 320 EXPECT_EQ(size_t(1), storage->stored_groups_.size()); |
321 base::MessageLoop::current()->RunUntilIdle(); // Do async task execution. | 321 base::MessageLoop::current()->RunUntilIdle(); // Do async task execution. |
322 EXPECT_TRUE(delegate.stored_group_success_); | 322 EXPECT_TRUE(delegate.stored_group_success_); |
323 EXPECT_EQ(size_t(1), storage->stored_caches_.size()); | 323 EXPECT_EQ(size_t(1), storage->stored_caches_.size()); |
324 EXPECT_EQ(size_t(1), storage->stored_groups_.size()); | 324 EXPECT_EQ(size_t(1), storage->stored_groups_.size()); |
325 EXPECT_TRUE(storage->IsCacheStored(cache)); | 325 EXPECT_TRUE(storage->IsCacheStored(cache.get())); |
326 EXPECT_EQ(cache, group->newest_complete_cache()); | 326 EXPECT_EQ(cache, group->newest_complete_cache()); |
327 EXPECT_TRUE(cache->GetEntry(entry_url)); | 327 EXPECT_TRUE(cache->GetEntry(entry_url)); |
328 } | 328 } |
329 | 329 |
330 TEST_F(MockAppCacheStorageTest, MakeGroupObsolete) { | 330 TEST_F(MockAppCacheStorageTest, MakeGroupObsolete) { |
331 // Make a group obsolete, should complete asyncly. | 331 // Make a group obsolete, should complete asyncly. |
332 MockAppCacheService service; | 332 MockAppCacheService service; |
333 MockAppCacheStorage* storage = | 333 MockAppCacheStorage* storage = |
334 reinterpret_cast<MockAppCacheStorage*>(service.storage()); | 334 reinterpret_cast<MockAppCacheStorage*>(service.storage()); |
335 | 335 |
336 // Setup some preconditions. Create a group and newest cache that | 336 // Setup some preconditions. Create a group and newest cache that |
337 // appears to be "stored" and "currently in use". | 337 // appears to be "stored" and "currently in use". |
338 GURL manifest_url("http://blah/"); | 338 GURL manifest_url("http://blah/"); |
339 scoped_refptr<AppCacheGroup> group( | 339 scoped_refptr<AppCacheGroup> group( |
340 new AppCacheGroup(service.storage(), manifest_url, 111)); | 340 new AppCacheGroup(service.storage(), manifest_url, 111)); |
341 int64 cache_id = storage->NewCacheId(); | 341 int64 cache_id = storage->NewCacheId(); |
342 scoped_refptr<AppCache> cache(new AppCache(service.storage(), cache_id)); | 342 scoped_refptr<AppCache> cache(new AppCache(service.storage(), cache_id)); |
343 cache->set_complete(true); | 343 cache->set_complete(true); |
344 group->AddCache(cache); | 344 group->AddCache(cache.get()); |
345 storage->AddStoredGroup(group); | 345 storage->AddStoredGroup(group.get()); |
346 storage->AddStoredCache(cache); | 346 storage->AddStoredCache(cache.get()); |
347 // Hold our refs to simulate the UpdateJob holding these refs. | 347 // Hold our refs to simulate the UpdateJob holding these refs. |
348 | 348 |
349 // Conduct the test. | 349 // Conduct the test. |
350 MockStorageDelegate delegate; | 350 MockStorageDelegate delegate; |
351 EXPECT_FALSE(group->is_obsolete()); | 351 EXPECT_FALSE(group->is_obsolete()); |
352 EXPECT_EQ(size_t(1), storage->stored_caches_.size()); | 352 EXPECT_EQ(size_t(1), storage->stored_caches_.size()); |
353 EXPECT_EQ(size_t(1), storage->stored_groups_.size()); | 353 EXPECT_EQ(size_t(1), storage->stored_groups_.size()); |
354 EXPECT_FALSE(cache->HasOneRef()); | 354 EXPECT_FALSE(cache->HasOneRef()); |
355 EXPECT_FALSE(group->HasOneRef()); | 355 EXPECT_FALSE(group->HasOneRef()); |
356 storage->MakeGroupObsolete(group, &delegate); | 356 storage->MakeGroupObsolete(group.get(), &delegate); |
357 EXPECT_FALSE(group->is_obsolete()); | 357 EXPECT_FALSE(group->is_obsolete()); |
358 EXPECT_EQ(size_t(1), storage->stored_caches_.size()); | 358 EXPECT_EQ(size_t(1), storage->stored_caches_.size()); |
359 EXPECT_EQ(size_t(1), storage->stored_groups_.size()); | 359 EXPECT_EQ(size_t(1), storage->stored_groups_.size()); |
360 EXPECT_FALSE(cache->HasOneRef()); | 360 EXPECT_FALSE(cache->HasOneRef()); |
361 EXPECT_FALSE(group->HasOneRef()); | 361 EXPECT_FALSE(group->HasOneRef()); |
362 base::MessageLoop::current()->RunUntilIdle(); // Do async task execution. | 362 base::MessageLoop::current()->RunUntilIdle(); // Do async task execution. |
363 EXPECT_TRUE(delegate.obsoleted_success_); | 363 EXPECT_TRUE(delegate.obsoleted_success_); |
364 EXPECT_EQ(group.get(), delegate.obsoleted_group_.get()); | 364 EXPECT_EQ(group.get(), delegate.obsoleted_group_.get()); |
365 EXPECT_TRUE(group->is_obsolete()); | 365 EXPECT_TRUE(group->is_obsolete()); |
366 EXPECT_TRUE(storage->stored_caches_.empty()); | 366 EXPECT_TRUE(storage->stored_caches_.empty()); |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
425 const int64 kCacheId = storage->NewCacheId(); | 425 const int64 kCacheId = storage->NewCacheId(); |
426 const GURL kEntryUrl("http://blah/entry"); | 426 const GURL kEntryUrl("http://blah/entry"); |
427 const GURL kManifestUrl("http://blah/manifest"); | 427 const GURL kManifestUrl("http://blah/manifest"); |
428 const int64 kResponseId = 1; | 428 const int64 kResponseId = 1; |
429 scoped_refptr<AppCache> cache(new AppCache(service.storage(), kCacheId)); | 429 scoped_refptr<AppCache> cache(new AppCache(service.storage(), kCacheId)); |
430 cache->AddEntry( | 430 cache->AddEntry( |
431 kEntryUrl, AppCacheEntry(AppCacheEntry::EXPLICIT, kResponseId)); | 431 kEntryUrl, AppCacheEntry(AppCacheEntry::EXPLICIT, kResponseId)); |
432 cache->set_complete(true); | 432 cache->set_complete(true); |
433 scoped_refptr<AppCacheGroup> group( | 433 scoped_refptr<AppCacheGroup> group( |
434 new AppCacheGroup(service.storage(), kManifestUrl, 111)); | 434 new AppCacheGroup(service.storage(), kManifestUrl, 111)); |
435 group->AddCache(cache); | 435 group->AddCache(cache.get()); |
436 storage->AddStoredGroup(group); | 436 storage->AddStoredGroup(group.get()); |
437 storage->AddStoredCache(cache); | 437 storage->AddStoredCache(cache.get()); |
438 | 438 |
439 // Conduct the test. | 439 // Conduct the test. |
440 MockStorageDelegate delegate; | 440 MockStorageDelegate delegate; |
441 EXPECT_NE(kEntryUrl, delegate.found_url_); | 441 EXPECT_NE(kEntryUrl, delegate.found_url_); |
442 storage->FindResponseForMainRequest(kEntryUrl, GURL(), &delegate); | 442 storage->FindResponseForMainRequest(kEntryUrl, GURL(), &delegate); |
443 EXPECT_NE(kEntryUrl, delegate.found_url_); | 443 EXPECT_NE(kEntryUrl, delegate.found_url_); |
444 base::MessageLoop::current()->RunUntilIdle(); // Do async task execution. | 444 base::MessageLoop::current()->RunUntilIdle(); // Do async task execution. |
445 EXPECT_EQ(kEntryUrl, delegate.found_url_); | 445 EXPECT_EQ(kEntryUrl, delegate.found_url_); |
446 EXPECT_EQ(kManifestUrl, delegate.found_manifest_url_); | 446 EXPECT_EQ(kManifestUrl, delegate.found_manifest_url_); |
447 EXPECT_EQ(kCacheId, delegate.found_cache_id_); | 447 EXPECT_EQ(kCacheId, delegate.found_cache_id_); |
(...skipping 30 matching lines...) Expand all Loading... |
478 scoped_refptr<AppCache> cache(new AppCache(service.storage(), kCacheId)); | 478 scoped_refptr<AppCache> cache(new AppCache(service.storage(), kCacheId)); |
479 cache->InitializeWithManifest(&manifest); | 479 cache->InitializeWithManifest(&manifest); |
480 cache->AddEntry(kFallbackEntryUrl1, | 480 cache->AddEntry(kFallbackEntryUrl1, |
481 AppCacheEntry(AppCacheEntry::FALLBACK, kResponseId1)); | 481 AppCacheEntry(AppCacheEntry::FALLBACK, kResponseId1)); |
482 cache->AddEntry(kFallbackEntryUrl2, | 482 cache->AddEntry(kFallbackEntryUrl2, |
483 AppCacheEntry(AppCacheEntry::FALLBACK, kResponseId2)); | 483 AppCacheEntry(AppCacheEntry::FALLBACK, kResponseId2)); |
484 cache->set_complete(true); | 484 cache->set_complete(true); |
485 | 485 |
486 scoped_refptr<AppCacheGroup> group( | 486 scoped_refptr<AppCacheGroup> group( |
487 new AppCacheGroup(service.storage(), kManifestUrl, 111)); | 487 new AppCacheGroup(service.storage(), kManifestUrl, 111)); |
488 group->AddCache(cache); | 488 group->AddCache(cache.get()); |
489 storage->AddStoredGroup(group); | 489 storage->AddStoredGroup(group.get()); |
490 storage->AddStoredCache(cache); | 490 storage->AddStoredCache(cache.get()); |
491 | 491 |
492 // The test url is in both fallback namespace urls, but should match | 492 // The test url is in both fallback namespace urls, but should match |
493 // the longer of the two. | 493 // the longer of the two. |
494 const GURL kTestUrl("http://blah/fallback_namespace/longer/test"); | 494 const GURL kTestUrl("http://blah/fallback_namespace/longer/test"); |
495 | 495 |
496 // Conduct the test. | 496 // Conduct the test. |
497 MockStorageDelegate delegate; | 497 MockStorageDelegate delegate; |
498 EXPECT_NE(kTestUrl, delegate.found_url_); | 498 EXPECT_NE(kTestUrl, delegate.found_url_); |
499 storage->FindResponseForMainRequest(kTestUrl, GURL(), &delegate); | 499 storage->FindResponseForMainRequest(kTestUrl, GURL(), &delegate); |
500 EXPECT_NE(kTestUrl, delegate.found_url_); | 500 EXPECT_NE(kTestUrl, delegate.found_url_); |
(...skipping 24 matching lines...) Expand all Loading... |
525 const int64 kResponseId1 = 1; | 525 const int64 kResponseId1 = 1; |
526 const int64 kResponseId2 = 2; | 526 const int64 kResponseId2 = 2; |
527 | 527 |
528 // The first cache. | 528 // The first cache. |
529 scoped_refptr<AppCache> cache(new AppCache(service.storage(), kCacheId1)); | 529 scoped_refptr<AppCache> cache(new AppCache(service.storage(), kCacheId1)); |
530 cache->AddEntry( | 530 cache->AddEntry( |
531 kEntryUrl, AppCacheEntry(AppCacheEntry::EXPLICIT, kResponseId1)); | 531 kEntryUrl, AppCacheEntry(AppCacheEntry::EXPLICIT, kResponseId1)); |
532 cache->set_complete(true); | 532 cache->set_complete(true); |
533 scoped_refptr<AppCacheGroup> group( | 533 scoped_refptr<AppCacheGroup> group( |
534 new AppCacheGroup(service.storage(), kManifestUrl1, 111)); | 534 new AppCacheGroup(service.storage(), kManifestUrl1, 111)); |
535 group->AddCache(cache); | 535 group->AddCache(cache.get()); |
536 storage->AddStoredGroup(group); | 536 storage->AddStoredGroup(group.get()); |
537 storage->AddStoredCache(cache); | 537 storage->AddStoredCache(cache.get()); |
538 // Drop our references to cache1 so it appears as "not in use". | 538 // Drop our references to cache1 so it appears as "not in use". |
539 cache = NULL; | 539 cache = NULL; |
540 group = NULL; | 540 group = NULL; |
541 | 541 |
542 // The second cache. | 542 // The second cache. |
543 cache = new AppCache(service.storage(), kCacheId2); | 543 cache = new AppCache(service.storage(), kCacheId2); |
544 cache->AddEntry( | 544 cache->AddEntry( |
545 kEntryUrl, AppCacheEntry(AppCacheEntry::EXPLICIT, kResponseId2)); | 545 kEntryUrl, AppCacheEntry(AppCacheEntry::EXPLICIT, kResponseId2)); |
546 cache->set_complete(true); | 546 cache->set_complete(true); |
547 group = new AppCacheGroup(service.storage(), kManifestUrl2, 222); | 547 group = new AppCacheGroup(service.storage(), kManifestUrl2, 222); |
548 group->AddCache(cache); | 548 group->AddCache(cache.get()); |
549 storage->AddStoredGroup(group); | 549 storage->AddStoredGroup(group.get()); |
550 storage->AddStoredCache(cache); | 550 storage->AddStoredCache(cache.get()); |
551 | 551 |
552 // Conduct the test, we should find the response from the second cache | 552 // Conduct the test, we should find the response from the second cache |
553 // since it's "in use". | 553 // since it's "in use". |
554 MockStorageDelegate delegate; | 554 MockStorageDelegate delegate; |
555 EXPECT_NE(kEntryUrl, delegate.found_url_); | 555 EXPECT_NE(kEntryUrl, delegate.found_url_); |
556 storage->FindResponseForMainRequest(kEntryUrl, GURL(), &delegate); | 556 storage->FindResponseForMainRequest(kEntryUrl, GURL(), &delegate); |
557 EXPECT_NE(kEntryUrl, delegate.found_url_); | 557 EXPECT_NE(kEntryUrl, delegate.found_url_); |
558 base::MessageLoop::current()->RunUntilIdle(); // Do async task execution. | 558 base::MessageLoop::current()->RunUntilIdle(); // Do async task execution. |
559 EXPECT_EQ(kEntryUrl, delegate.found_url_); | 559 EXPECT_EQ(kEntryUrl, delegate.found_url_); |
560 EXPECT_EQ(kManifestUrl2, delegate.found_manifest_url_); | 560 EXPECT_EQ(kManifestUrl2, delegate.found_manifest_url_); |
(...skipping 24 matching lines...) Expand all Loading... |
585 GURL(), false)); | 585 GURL(), false)); |
586 scoped_refptr<AppCache> cache(new AppCache(service.storage(), kCacheId)); | 586 scoped_refptr<AppCache> cache(new AppCache(service.storage(), kCacheId)); |
587 cache->InitializeWithManifest(&manifest); | 587 cache->InitializeWithManifest(&manifest); |
588 cache->AddEntry( | 588 cache->AddEntry( |
589 kEntryUrl, | 589 kEntryUrl, |
590 AppCacheEntry(AppCacheEntry::EXPLICIT | AppCacheEntry::FOREIGN, | 590 AppCacheEntry(AppCacheEntry::EXPLICIT | AppCacheEntry::FOREIGN, |
591 kResponseId)); | 591 kResponseId)); |
592 cache->set_complete(true); | 592 cache->set_complete(true); |
593 scoped_refptr<AppCacheGroup> group( | 593 scoped_refptr<AppCacheGroup> group( |
594 new AppCacheGroup(service.storage(), kManifestUrl, 111)); | 594 new AppCacheGroup(service.storage(), kManifestUrl, 111)); |
595 group->AddCache(cache); | 595 group->AddCache(cache.get()); |
596 storage->AddStoredGroup(group); | 596 storage->AddStoredGroup(group.get()); |
597 storage->AddStoredCache(cache); | 597 storage->AddStoredCache(cache.get()); |
598 | 598 |
599 MockStorageDelegate delegate; | 599 MockStorageDelegate delegate; |
600 | 600 |
601 // We should not find anything for the foreign entry. | 601 // We should not find anything for the foreign entry. |
602 EXPECT_NE(kEntryUrl, delegate.found_url_); | 602 EXPECT_NE(kEntryUrl, delegate.found_url_); |
603 storage->FindResponseForMainRequest(kEntryUrl, GURL(), &delegate); | 603 storage->FindResponseForMainRequest(kEntryUrl, GURL(), &delegate); |
604 EXPECT_NE(kEntryUrl, delegate.found_url_); | 604 EXPECT_NE(kEntryUrl, delegate.found_url_); |
605 base::MessageLoop::current()->RunUntilIdle(); // Do async task execution. | 605 base::MessageLoop::current()->RunUntilIdle(); // Do async task execution. |
606 EXPECT_EQ(kEntryUrl, delegate.found_url_); | 606 EXPECT_EQ(kEntryUrl, delegate.found_url_); |
607 EXPECT_TRUE(delegate.found_manifest_url_.is_empty()); | 607 EXPECT_TRUE(delegate.found_manifest_url_.is_empty()); |
(...skipping 13 matching lines...) Expand all Loading... |
621 EXPECT_TRUE(delegate.found_manifest_url_.is_empty()); | 621 EXPECT_TRUE(delegate.found_manifest_url_.is_empty()); |
622 EXPECT_EQ(kNoCacheId, delegate.found_cache_id_); | 622 EXPECT_EQ(kNoCacheId, delegate.found_cache_id_); |
623 EXPECT_EQ(kNoResponseId, delegate.found_entry_.response_id()); | 623 EXPECT_EQ(kNoResponseId, delegate.found_entry_.response_id()); |
624 EXPECT_EQ(kNoResponseId, delegate.found_fallback_entry_.response_id()); | 624 EXPECT_EQ(kNoResponseId, delegate.found_fallback_entry_.response_id()); |
625 EXPECT_TRUE(delegate.found_fallback_url_.is_empty()); | 625 EXPECT_TRUE(delegate.found_fallback_url_.is_empty()); |
626 EXPECT_EQ(0, delegate.found_entry_.types()); | 626 EXPECT_EQ(0, delegate.found_entry_.types()); |
627 EXPECT_EQ(0, delegate.found_fallback_entry_.types()); | 627 EXPECT_EQ(0, delegate.found_fallback_entry_.types()); |
628 } | 628 } |
629 | 629 |
630 } // namespace appcache | 630 } // namespace appcache |
OLD | NEW |