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 150 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
161 reinterpret_cast<MockAppCacheStorage*>(service.storage()); | 161 reinterpret_cast<MockAppCacheStorage*>(service.storage()); |
162 | 162 |
163 // Setup some preconditions. Create a group and newest cache that | 163 // Setup some preconditions. Create a group and newest cache that |
164 // appears to be "stored" and "not currently in use". | 164 // appears to be "stored" and "not currently in use". |
165 GURL manifest_url("http://blah/"); | 165 GURL manifest_url("http://blah/"); |
166 scoped_refptr<AppCacheGroup> group( | 166 scoped_refptr<AppCacheGroup> group( |
167 new AppCacheGroup(&service, manifest_url, 111)); | 167 new AppCacheGroup(&service, manifest_url, 111)); |
168 int64 cache_id = storage->NewCacheId(); | 168 int64 cache_id = storage->NewCacheId(); |
169 scoped_refptr<AppCache> cache(new AppCache(&service, cache_id)); | 169 scoped_refptr<AppCache> cache(new AppCache(&service, cache_id)); |
170 cache->set_complete(true); | 170 cache->set_complete(true); |
171 group->AddCache(cache); | 171 group->AddCache(cache.get()); |
172 storage->AddStoredGroup(group); | 172 storage->AddStoredGroup(group.get()); |
173 storage->AddStoredCache(cache); | 173 storage->AddStoredCache(cache.get()); |
174 | 174 |
175 // Drop the references from above so the only refs to these | 175 // Drop the references from above so the only refs to these |
176 // objects are from within the storage class. This is to make | 176 // objects are from within the storage class. This is to make |
177 // these objects appear as "not currently in use". | 177 // these objects appear as "not currently in use". |
178 AppCache* cache_ptr = cache.get(); | 178 AppCache* cache_ptr = cache.get(); |
179 AppCacheGroup* group_ptr = group.get(); | 179 AppCacheGroup* group_ptr = group.get(); |
180 cache = NULL; | 180 cache = NULL; |
181 group = NULL; | 181 group = NULL; |
182 | 182 |
183 // Setup a delegate to receive completion callbacks. | 183 // Setup a delegate to receive completion callbacks. |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
218 new AppCacheGroup(&service, manifest_url, 111)); | 218 new AppCacheGroup(&service, manifest_url, 111)); |
219 int64 cache_id = storage->NewCacheId(); | 219 int64 cache_id = storage->NewCacheId(); |
220 scoped_refptr<AppCache> cache(new AppCache(&service, cache_id)); | 220 scoped_refptr<AppCache> cache(new AppCache(&service, cache_id)); |
221 // Hold a ref to the cache simulate the UpdateJob holding that ref, | 221 // Hold a ref to the cache simulate the UpdateJob holding that ref, |
222 // and hold a ref to the group to simulate the CacheHost holding that ref. | 222 // and hold a ref to the group to simulate the CacheHost holding that ref. |
223 | 223 |
224 // Conduct the store test. | 224 // Conduct the store test. |
225 MockStorageDelegate delegate; | 225 MockStorageDelegate delegate; |
226 EXPECT_TRUE(storage->stored_caches_.empty()); | 226 EXPECT_TRUE(storage->stored_caches_.empty()); |
227 EXPECT_TRUE(storage->stored_groups_.empty()); | 227 EXPECT_TRUE(storage->stored_groups_.empty()); |
228 storage->StoreGroupAndNewestCache(group, cache, &delegate); | 228 storage->StoreGroupAndNewestCache(group.get(), cache.get(), &delegate); |
229 EXPECT_FALSE(delegate.stored_group_success_); | 229 EXPECT_FALSE(delegate.stored_group_success_); |
230 EXPECT_TRUE(storage->stored_caches_.empty()); | 230 EXPECT_TRUE(storage->stored_caches_.empty()); |
231 EXPECT_TRUE(storage->stored_groups_.empty()); | 231 EXPECT_TRUE(storage->stored_groups_.empty()); |
232 MessageLoop::current()->RunAllPending(); // Do async task execution. | 232 MessageLoop::current()->RunAllPending(); // Do async task execution. |
233 EXPECT_TRUE(delegate.stored_group_success_); | 233 EXPECT_TRUE(delegate.stored_group_success_); |
234 EXPECT_FALSE(storage->stored_caches_.empty()); | 234 EXPECT_FALSE(storage->stored_caches_.empty()); |
235 EXPECT_FALSE(storage->stored_groups_.empty()); | 235 EXPECT_FALSE(storage->stored_groups_.empty()); |
236 EXPECT_EQ(cache, group->newest_complete_cache()); | 236 EXPECT_EQ(cache, group->newest_complete_cache()); |
237 EXPECT_TRUE(cache->is_complete()); | 237 EXPECT_TRUE(cache->is_complete()); |
238 } | 238 } |
239 | 239 |
240 TEST_F(MockAppCacheStorageTest, StoreExistingGroup) { | 240 TEST_F(MockAppCacheStorageTest, StoreExistingGroup) { |
241 // Store a group and its newest cache. Should complete asyncly. | 241 // Store a group and its newest cache. Should complete asyncly. |
242 MockAppCacheService service; | 242 MockAppCacheService service; |
243 MockAppCacheStorage* storage = | 243 MockAppCacheStorage* storage = |
244 reinterpret_cast<MockAppCacheStorage*>(service.storage()); | 244 reinterpret_cast<MockAppCacheStorage*>(service.storage()); |
245 | 245 |
246 // Setup some preconditions. Create a group and old complete cache | 246 // Setup some preconditions. Create a group and old complete cache |
247 // that appear to be "stored", and a newest unstored complete cache. | 247 // that appear to be "stored", and a newest unstored complete cache. |
248 GURL manifest_url("http://blah/"); | 248 GURL manifest_url("http://blah/"); |
249 scoped_refptr<AppCacheGroup> group( | 249 scoped_refptr<AppCacheGroup> group( |
250 new AppCacheGroup(&service, manifest_url, 111)); | 250 new AppCacheGroup(&service, manifest_url, 111)); |
251 int64 old_cache_id = storage->NewCacheId(); | 251 int64 old_cache_id = storage->NewCacheId(); |
252 scoped_refptr<AppCache> old_cache(new AppCache(&service, old_cache_id)); | 252 scoped_refptr<AppCache> old_cache(new AppCache(&service, old_cache_id)); |
253 old_cache->set_complete(true); | 253 old_cache->set_complete(true); |
254 group->AddCache(old_cache); | 254 group->AddCache(old_cache.get()); |
255 storage->AddStoredGroup(group); | 255 storage->AddStoredGroup(group.get()); |
256 storage->AddStoredCache(old_cache); | 256 storage->AddStoredCache(old_cache.get()); |
257 int64 new_cache_id = storage->NewCacheId(); | 257 int64 new_cache_id = storage->NewCacheId(); |
258 scoped_refptr<AppCache> new_cache(new AppCache(&service, new_cache_id)); | 258 scoped_refptr<AppCache> new_cache(new AppCache(&service, new_cache_id)); |
259 // Hold our refs to simulate the UpdateJob holding these refs. | 259 // Hold our refs to simulate the UpdateJob holding these refs. |
260 | 260 |
261 // Conduct the test. | 261 // Conduct the test. |
262 MockStorageDelegate delegate; | 262 MockStorageDelegate delegate; |
263 EXPECT_EQ(size_t(1), storage->stored_caches_.size()); | 263 EXPECT_EQ(size_t(1), storage->stored_caches_.size()); |
264 EXPECT_EQ(size_t(1), storage->stored_groups_.size()); | 264 EXPECT_EQ(size_t(1), storage->stored_groups_.size()); |
265 EXPECT_TRUE(storage->IsCacheStored(old_cache)); | 265 EXPECT_TRUE(storage->IsCacheStored(old_cache.get())); |
266 EXPECT_FALSE(storage->IsCacheStored(new_cache)); | 266 EXPECT_FALSE(storage->IsCacheStored(new_cache.get())); |
267 storage->StoreGroupAndNewestCache(group, new_cache, &delegate); | 267 storage->StoreGroupAndNewestCache(group.get(), new_cache.get(), &delegate); |
268 EXPECT_FALSE(delegate.stored_group_success_); | 268 EXPECT_FALSE(delegate.stored_group_success_); |
269 EXPECT_EQ(size_t(1), storage->stored_caches_.size()); | 269 EXPECT_EQ(size_t(1), storage->stored_caches_.size()); |
270 EXPECT_EQ(size_t(1), storage->stored_groups_.size()); | 270 EXPECT_EQ(size_t(1), storage->stored_groups_.size()); |
271 EXPECT_TRUE(storage->IsCacheStored(old_cache)); | 271 EXPECT_TRUE(storage->IsCacheStored(old_cache.get())); |
272 EXPECT_FALSE(storage->IsCacheStored(new_cache)); | 272 EXPECT_FALSE(storage->IsCacheStored(new_cache.get())); |
273 MessageLoop::current()->RunAllPending(); // Do async task execution. | 273 MessageLoop::current()->RunAllPending(); // Do async task execution. |
274 EXPECT_TRUE(delegate.stored_group_success_); | 274 EXPECT_TRUE(delegate.stored_group_success_); |
275 EXPECT_EQ(size_t(1), storage->stored_caches_.size()); | 275 EXPECT_EQ(size_t(1), storage->stored_caches_.size()); |
276 EXPECT_EQ(size_t(1), storage->stored_groups_.size()); | 276 EXPECT_EQ(size_t(1), storage->stored_groups_.size()); |
277 EXPECT_FALSE(storage->IsCacheStored(old_cache)); | 277 EXPECT_FALSE(storage->IsCacheStored(old_cache.get())); |
278 EXPECT_TRUE(storage->IsCacheStored(new_cache)); | 278 EXPECT_TRUE(storage->IsCacheStored(new_cache.get())); |
279 EXPECT_EQ(new_cache.get(), group->newest_complete_cache()); | 279 EXPECT_EQ(new_cache.get(), group->newest_complete_cache()); |
280 EXPECT_TRUE(new_cache->is_complete()); | 280 EXPECT_TRUE(new_cache->is_complete()); |
281 } | 281 } |
282 | 282 |
283 TEST_F(MockAppCacheStorageTest, StoreExistingGroupExistingCache) { | 283 TEST_F(MockAppCacheStorageTest, StoreExistingGroupExistingCache) { |
284 // Store a group with updates to its existing newest complete cache. | 284 // Store a group with updates to its existing newest complete cache. |
285 MockAppCacheService service; | 285 MockAppCacheService service; |
286 MockAppCacheStorage* storage = | 286 MockAppCacheStorage* storage = |
287 reinterpret_cast<MockAppCacheStorage*>(service.storage()); | 287 reinterpret_cast<MockAppCacheStorage*>(service.storage()); |
288 | 288 |
289 // Setup some preconditions. Create a group and a complete cache that | 289 // Setup some preconditions. Create a group and a complete cache that |
290 // appear to be "stored". | 290 // appear to be "stored". |
291 GURL manifest_url("http://blah"); | 291 GURL manifest_url("http://blah"); |
292 scoped_refptr<AppCacheGroup> group( | 292 scoped_refptr<AppCacheGroup> group( |
293 new AppCacheGroup(&service, manifest_url, 111)); | 293 new AppCacheGroup(&service, manifest_url, 111)); |
294 int64 cache_id = storage->NewCacheId(); | 294 int64 cache_id = storage->NewCacheId(); |
295 scoped_refptr<AppCache> cache(new AppCache(&service, cache_id)); | 295 scoped_refptr<AppCache> cache(new AppCache(&service, cache_id)); |
296 cache->set_complete(true); | 296 cache->set_complete(true); |
297 group->AddCache(cache); | 297 group->AddCache(cache.get()); |
298 storage->AddStoredGroup(group); | 298 storage->AddStoredGroup(group.get()); |
299 storage->AddStoredCache(cache); | 299 storage->AddStoredCache(cache.get()); |
300 // Hold our refs to simulate the UpdateJob holding these refs. | 300 // Hold our refs to simulate the UpdateJob holding these refs. |
301 | 301 |
302 // Change the group's newest cache. | 302 // Change the group's newest cache. |
303 EXPECT_EQ(cache, group->newest_complete_cache()); | 303 EXPECT_EQ(cache, group->newest_complete_cache()); |
304 GURL entry_url("http://blah/blah"); | 304 GURL entry_url("http://blah/blah"); |
305 cache->AddEntry(entry_url, AppCacheEntry(AppCacheEntry::MASTER)); | 305 cache->AddEntry(entry_url, AppCacheEntry(AppCacheEntry::MASTER)); |
306 | 306 |
307 // Conduct the test. | 307 // Conduct the test. |
308 MockStorageDelegate delegate; | 308 MockStorageDelegate delegate; |
309 EXPECT_EQ(size_t(1), storage->stored_caches_.size()); | 309 EXPECT_EQ(size_t(1), storage->stored_caches_.size()); |
310 EXPECT_EQ(size_t(1), storage->stored_groups_.size()); | 310 EXPECT_EQ(size_t(1), storage->stored_groups_.size()); |
311 EXPECT_TRUE(storage->IsCacheStored(cache)); | 311 EXPECT_TRUE(storage->IsCacheStored(cache.get())); |
312 storage->StoreGroupAndNewestCache(group, cache, &delegate); | 312 storage->StoreGroupAndNewestCache(group.get(), cache.get(), &delegate); |
313 EXPECT_FALSE(delegate.stored_group_success_); | 313 EXPECT_FALSE(delegate.stored_group_success_); |
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 MessageLoop::current()->RunAllPending(); // Do async task execution. | 316 MessageLoop::current()->RunAllPending(); // Do async task execution. |
317 EXPECT_TRUE(delegate.stored_group_success_); | 317 EXPECT_TRUE(delegate.stored_group_success_); |
318 EXPECT_EQ(size_t(1), storage->stored_caches_.size()); | 318 EXPECT_EQ(size_t(1), storage->stored_caches_.size()); |
319 EXPECT_EQ(size_t(1), storage->stored_groups_.size()); | 319 EXPECT_EQ(size_t(1), storage->stored_groups_.size()); |
320 EXPECT_TRUE(storage->IsCacheStored(cache)); | 320 EXPECT_TRUE(storage->IsCacheStored(cache.get())); |
321 EXPECT_EQ(cache, group->newest_complete_cache()); | 321 EXPECT_EQ(cache, group->newest_complete_cache()); |
322 EXPECT_TRUE(cache->GetEntry(entry_url)); | 322 EXPECT_TRUE(cache->GetEntry(entry_url)); |
323 } | 323 } |
324 | 324 |
325 TEST_F(MockAppCacheStorageTest, MakeGroupObsolete) { | 325 TEST_F(MockAppCacheStorageTest, MakeGroupObsolete) { |
326 // Make a group obsolete, should complete asyncly. | 326 // Make a group obsolete, should complete asyncly. |
327 MockAppCacheService service; | 327 MockAppCacheService service; |
328 MockAppCacheStorage* storage = | 328 MockAppCacheStorage* storage = |
329 reinterpret_cast<MockAppCacheStorage*>(service.storage()); | 329 reinterpret_cast<MockAppCacheStorage*>(service.storage()); |
330 | 330 |
331 // Setup some preconditions. Create a group and newest cache that | 331 // Setup some preconditions. Create a group and newest cache that |
332 // appears to be "stored" and "currently in use". | 332 // appears to be "stored" and "currently in use". |
333 GURL manifest_url("http://blah/"); | 333 GURL manifest_url("http://blah/"); |
334 scoped_refptr<AppCacheGroup> group( | 334 scoped_refptr<AppCacheGroup> group( |
335 new AppCacheGroup(&service, manifest_url, 111)); | 335 new AppCacheGroup(&service, manifest_url, 111)); |
336 int64 cache_id = storage->NewCacheId(); | 336 int64 cache_id = storage->NewCacheId(); |
337 scoped_refptr<AppCache> cache(new AppCache(&service, cache_id)); | 337 scoped_refptr<AppCache> cache(new AppCache(&service, cache_id)); |
338 cache->set_complete(true); | 338 cache->set_complete(true); |
339 group->AddCache(cache); | 339 group->AddCache(cache.get()); |
340 storage->AddStoredGroup(group); | 340 storage->AddStoredGroup(group.get()); |
341 storage->AddStoredCache(cache); | 341 storage->AddStoredCache(cache.get()); |
342 // Hold our refs to simulate the UpdateJob holding these refs. | 342 // Hold our refs to simulate the UpdateJob holding these refs. |
343 | 343 |
344 // Conduct the test. | 344 // Conduct the test. |
345 MockStorageDelegate delegate; | 345 MockStorageDelegate delegate; |
346 EXPECT_FALSE(group->is_obsolete()); | 346 EXPECT_FALSE(group->is_obsolete()); |
347 EXPECT_EQ(size_t(1), storage->stored_caches_.size()); | 347 EXPECT_EQ(size_t(1), storage->stored_caches_.size()); |
348 EXPECT_EQ(size_t(1), storage->stored_groups_.size()); | 348 EXPECT_EQ(size_t(1), storage->stored_groups_.size()); |
349 EXPECT_FALSE(cache->HasOneRef()); | 349 EXPECT_FALSE(cache->HasOneRef()); |
350 EXPECT_FALSE(group->HasOneRef()); | 350 EXPECT_FALSE(group->HasOneRef()); |
351 storage->MakeGroupObsolete(group, &delegate); | 351 storage->MakeGroupObsolete(group.get(), &delegate); |
352 EXPECT_FALSE(group->is_obsolete()); | 352 EXPECT_FALSE(group->is_obsolete()); |
353 EXPECT_EQ(size_t(1), storage->stored_caches_.size()); | 353 EXPECT_EQ(size_t(1), storage->stored_caches_.size()); |
354 EXPECT_EQ(size_t(1), storage->stored_groups_.size()); | 354 EXPECT_EQ(size_t(1), storage->stored_groups_.size()); |
355 EXPECT_FALSE(cache->HasOneRef()); | 355 EXPECT_FALSE(cache->HasOneRef()); |
356 EXPECT_FALSE(group->HasOneRef()); | 356 EXPECT_FALSE(group->HasOneRef()); |
357 MessageLoop::current()->RunAllPending(); // Do async task execution. | 357 MessageLoop::current()->RunAllPending(); // Do async task execution. |
358 EXPECT_TRUE(delegate.obsoleted_success_); | 358 EXPECT_TRUE(delegate.obsoleted_success_); |
359 EXPECT_EQ(group.get(), delegate.obsoleted_group_.get()); | 359 EXPECT_EQ(group.get(), delegate.obsoleted_group_.get()); |
360 EXPECT_TRUE(group->is_obsolete()); | 360 EXPECT_TRUE(group->is_obsolete()); |
361 EXPECT_TRUE(storage->stored_caches_.empty()); | 361 EXPECT_TRUE(storage->stored_caches_.empty()); |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
420 const int64 kCacheId = storage->NewCacheId(); | 420 const int64 kCacheId = storage->NewCacheId(); |
421 const GURL kEntryUrl("http://blah/entry"); | 421 const GURL kEntryUrl("http://blah/entry"); |
422 const GURL kManifestUrl("http://blah/manifest"); | 422 const GURL kManifestUrl("http://blah/manifest"); |
423 const int64 kResponseId = 1; | 423 const int64 kResponseId = 1; |
424 scoped_refptr<AppCache> cache(new AppCache(&service, kCacheId)); | 424 scoped_refptr<AppCache> cache(new AppCache(&service, kCacheId)); |
425 cache->AddEntry( | 425 cache->AddEntry( |
426 kEntryUrl, AppCacheEntry(AppCacheEntry::EXPLICIT, kResponseId)); | 426 kEntryUrl, AppCacheEntry(AppCacheEntry::EXPLICIT, kResponseId)); |
427 cache->set_complete(true); | 427 cache->set_complete(true); |
428 scoped_refptr<AppCacheGroup> group( | 428 scoped_refptr<AppCacheGroup> group( |
429 new AppCacheGroup(&service, kManifestUrl, 111)); | 429 new AppCacheGroup(&service, kManifestUrl, 111)); |
430 group->AddCache(cache); | 430 group->AddCache(cache.get()); |
431 storage->AddStoredGroup(group); | 431 storage->AddStoredGroup(group.get()); |
432 storage->AddStoredCache(cache); | 432 storage->AddStoredCache(cache.get()); |
433 | 433 |
434 // Conduct the test. | 434 // Conduct the test. |
435 MockStorageDelegate delegate; | 435 MockStorageDelegate delegate; |
436 EXPECT_NE(kEntryUrl, delegate.found_url_); | 436 EXPECT_NE(kEntryUrl, delegate.found_url_); |
437 storage->FindResponseForMainRequest(kEntryUrl, GURL(), &delegate); | 437 storage->FindResponseForMainRequest(kEntryUrl, GURL(), &delegate); |
438 EXPECT_NE(kEntryUrl, delegate.found_url_); | 438 EXPECT_NE(kEntryUrl, delegate.found_url_); |
439 MessageLoop::current()->RunAllPending(); // Do async task execution. | 439 MessageLoop::current()->RunAllPending(); // Do async task execution. |
440 EXPECT_EQ(kEntryUrl, delegate.found_url_); | 440 EXPECT_EQ(kEntryUrl, delegate.found_url_); |
441 EXPECT_EQ(kManifestUrl, delegate.found_manifest_url_); | 441 EXPECT_EQ(kManifestUrl, delegate.found_manifest_url_); |
442 EXPECT_EQ(kCacheId, delegate.found_cache_id_); | 442 EXPECT_EQ(kCacheId, delegate.found_cache_id_); |
(...skipping 30 matching lines...) Expand all Loading... |
473 scoped_refptr<AppCache> cache(new AppCache(&service, kCacheId)); | 473 scoped_refptr<AppCache> cache(new AppCache(&service, kCacheId)); |
474 cache->InitializeWithManifest(&manifest); | 474 cache->InitializeWithManifest(&manifest); |
475 cache->AddEntry(kFallbackEntryUrl1, | 475 cache->AddEntry(kFallbackEntryUrl1, |
476 AppCacheEntry(AppCacheEntry::FALLBACK, kResponseId1)); | 476 AppCacheEntry(AppCacheEntry::FALLBACK, kResponseId1)); |
477 cache->AddEntry(kFallbackEntryUrl2, | 477 cache->AddEntry(kFallbackEntryUrl2, |
478 AppCacheEntry(AppCacheEntry::FALLBACK, kResponseId2)); | 478 AppCacheEntry(AppCacheEntry::FALLBACK, kResponseId2)); |
479 cache->set_complete(true); | 479 cache->set_complete(true); |
480 | 480 |
481 scoped_refptr<AppCacheGroup> group( | 481 scoped_refptr<AppCacheGroup> group( |
482 new AppCacheGroup(&service, kManifestUrl, 111)); | 482 new AppCacheGroup(&service, kManifestUrl, 111)); |
483 group->AddCache(cache); | 483 group->AddCache(cache.get()); |
484 storage->AddStoredGroup(group); | 484 storage->AddStoredGroup(group.get()); |
485 storage->AddStoredCache(cache); | 485 storage->AddStoredCache(cache.get()); |
486 | 486 |
487 // The test url is in both fallback namespace urls, but should match | 487 // The test url is in both fallback namespace urls, but should match |
488 // the longer of the two. | 488 // the longer of the two. |
489 const GURL kTestUrl("http://blah/fallback_namespace/longer/test"); | 489 const GURL kTestUrl("http://blah/fallback_namespace/longer/test"); |
490 | 490 |
491 // Conduct the test. | 491 // Conduct the test. |
492 MockStorageDelegate delegate; | 492 MockStorageDelegate delegate; |
493 EXPECT_NE(kTestUrl, delegate.found_url_); | 493 EXPECT_NE(kTestUrl, delegate.found_url_); |
494 storage->FindResponseForMainRequest(kTestUrl, GURL(), &delegate); | 494 storage->FindResponseForMainRequest(kTestUrl, GURL(), &delegate); |
495 EXPECT_NE(kTestUrl, delegate.found_url_); | 495 EXPECT_NE(kTestUrl, delegate.found_url_); |
(...skipping 24 matching lines...) Expand all Loading... |
520 const int64 kResponseId1 = 1; | 520 const int64 kResponseId1 = 1; |
521 const int64 kResponseId2 = 2; | 521 const int64 kResponseId2 = 2; |
522 | 522 |
523 // The first cache. | 523 // The first cache. |
524 scoped_refptr<AppCache> cache(new AppCache(&service, kCacheId1)); | 524 scoped_refptr<AppCache> cache(new AppCache(&service, kCacheId1)); |
525 cache->AddEntry( | 525 cache->AddEntry( |
526 kEntryUrl, AppCacheEntry(AppCacheEntry::EXPLICIT, kResponseId1)); | 526 kEntryUrl, AppCacheEntry(AppCacheEntry::EXPLICIT, kResponseId1)); |
527 cache->set_complete(true); | 527 cache->set_complete(true); |
528 scoped_refptr<AppCacheGroup> group( | 528 scoped_refptr<AppCacheGroup> group( |
529 new AppCacheGroup(&service, kManifestUrl1, 111)); | 529 new AppCacheGroup(&service, kManifestUrl1, 111)); |
530 group->AddCache(cache); | 530 group->AddCache(cache.get()); |
531 storage->AddStoredGroup(group); | 531 storage->AddStoredGroup(group.get()); |
532 storage->AddStoredCache(cache); | 532 storage->AddStoredCache(cache.get()); |
533 // Drop our references to cache1 so it appears as "not in use". | 533 // Drop our references to cache1 so it appears as "not in use". |
534 cache = NULL; | 534 cache = NULL; |
535 group = NULL; | 535 group = NULL; |
536 | 536 |
537 // The second cache. | 537 // The second cache. |
538 cache = new AppCache(&service, kCacheId2); | 538 cache = new AppCache(&service, kCacheId2); |
539 cache->AddEntry( | 539 cache->AddEntry( |
540 kEntryUrl, AppCacheEntry(AppCacheEntry::EXPLICIT, kResponseId2)); | 540 kEntryUrl, AppCacheEntry(AppCacheEntry::EXPLICIT, kResponseId2)); |
541 cache->set_complete(true); | 541 cache->set_complete(true); |
542 group = new AppCacheGroup(&service, kManifestUrl2, 222); | 542 group = new AppCacheGroup(&service, kManifestUrl2, 222); |
543 group->AddCache(cache); | 543 group->AddCache(cache.get()); |
544 storage->AddStoredGroup(group); | 544 storage->AddStoredGroup(group.get()); |
545 storage->AddStoredCache(cache); | 545 storage->AddStoredCache(cache.get()); |
546 | 546 |
547 // Conduct the test, we should find the response from the second cache | 547 // Conduct the test, we should find the response from the second cache |
548 // since it's "in use". | 548 // since it's "in use". |
549 MockStorageDelegate delegate; | 549 MockStorageDelegate delegate; |
550 EXPECT_NE(kEntryUrl, delegate.found_url_); | 550 EXPECT_NE(kEntryUrl, delegate.found_url_); |
551 storage->FindResponseForMainRequest(kEntryUrl, GURL(), &delegate); | 551 storage->FindResponseForMainRequest(kEntryUrl, GURL(), &delegate); |
552 EXPECT_NE(kEntryUrl, delegate.found_url_); | 552 EXPECT_NE(kEntryUrl, delegate.found_url_); |
553 MessageLoop::current()->RunAllPending(); // Do async task execution. | 553 MessageLoop::current()->RunAllPending(); // Do async task execution. |
554 EXPECT_EQ(kEntryUrl, delegate.found_url_); | 554 EXPECT_EQ(kEntryUrl, delegate.found_url_); |
555 EXPECT_EQ(kManifestUrl2, delegate.found_manifest_url_); | 555 EXPECT_EQ(kManifestUrl2, delegate.found_manifest_url_); |
(...skipping 23 matching lines...) Expand all Loading... |
579 | 579 |
580 scoped_refptr<AppCache> cache(new AppCache(&service, kCacheId)); | 580 scoped_refptr<AppCache> cache(new AppCache(&service, kCacheId)); |
581 cache->InitializeWithManifest(&manifest); | 581 cache->InitializeWithManifest(&manifest); |
582 cache->AddEntry( | 582 cache->AddEntry( |
583 kEntryUrl, | 583 kEntryUrl, |
584 AppCacheEntry(AppCacheEntry::EXPLICIT | AppCacheEntry::FOREIGN, | 584 AppCacheEntry(AppCacheEntry::EXPLICIT | AppCacheEntry::FOREIGN, |
585 kResponseId)); | 585 kResponseId)); |
586 cache->set_complete(true); | 586 cache->set_complete(true); |
587 scoped_refptr<AppCacheGroup> group( | 587 scoped_refptr<AppCacheGroup> group( |
588 new AppCacheGroup(&service, kManifestUrl, 111)); | 588 new AppCacheGroup(&service, kManifestUrl, 111)); |
589 group->AddCache(cache); | 589 group->AddCache(cache.get()); |
590 storage->AddStoredGroup(group); | 590 storage->AddStoredGroup(group.get()); |
591 storage->AddStoredCache(cache); | 591 storage->AddStoredCache(cache.get()); |
592 | 592 |
593 MockStorageDelegate delegate; | 593 MockStorageDelegate delegate; |
594 | 594 |
595 // We should not find anything for the foreign entry. | 595 // We should not find anything for the foreign entry. |
596 EXPECT_NE(kEntryUrl, delegate.found_url_); | 596 EXPECT_NE(kEntryUrl, delegate.found_url_); |
597 storage->FindResponseForMainRequest(kEntryUrl, GURL(), &delegate); | 597 storage->FindResponseForMainRequest(kEntryUrl, GURL(), &delegate); |
598 EXPECT_NE(kEntryUrl, delegate.found_url_); | 598 EXPECT_NE(kEntryUrl, delegate.found_url_); |
599 MessageLoop::current()->RunAllPending(); // Do async task execution. | 599 MessageLoop::current()->RunAllPending(); // Do async task execution. |
600 EXPECT_EQ(kEntryUrl, delegate.found_url_); | 600 EXPECT_EQ(kEntryUrl, delegate.found_url_); |
601 EXPECT_TRUE(delegate.found_manifest_url_.is_empty()); | 601 EXPECT_TRUE(delegate.found_manifest_url_.is_empty()); |
(...skipping 13 matching lines...) Expand all Loading... |
615 EXPECT_TRUE(delegate.found_manifest_url_.is_empty()); | 615 EXPECT_TRUE(delegate.found_manifest_url_.is_empty()); |
616 EXPECT_EQ(kNoCacheId, delegate.found_cache_id_); | 616 EXPECT_EQ(kNoCacheId, delegate.found_cache_id_); |
617 EXPECT_EQ(kNoResponseId, delegate.found_entry_.response_id()); | 617 EXPECT_EQ(kNoResponseId, delegate.found_entry_.response_id()); |
618 EXPECT_EQ(kNoResponseId, delegate.found_fallback_entry_.response_id()); | 618 EXPECT_EQ(kNoResponseId, delegate.found_fallback_entry_.response_id()); |
619 EXPECT_TRUE(delegate.found_fallback_url_.is_empty()); | 619 EXPECT_TRUE(delegate.found_fallback_url_.is_empty()); |
620 EXPECT_EQ(0, delegate.found_entry_.types()); | 620 EXPECT_EQ(0, delegate.found_entry_.types()); |
621 EXPECT_EQ(0, delegate.found_fallback_entry_.types()); | 621 EXPECT_EQ(0, delegate.found_fallback_entry_.types()); |
622 } | 622 } |
623 | 623 |
624 } // namespace appcache | 624 } // namespace appcache |
OLD | NEW |