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/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 26 matching lines...) Expand all Loading... |
37 stored_group_ = group; | 37 stored_group_ = group; |
38 stored_group_success_ = success; | 38 stored_group_success_ = success; |
39 } | 39 } |
40 | 40 |
41 void OnGroupMadeObsolete(AppCacheGroup* group, bool success) { | 41 void OnGroupMadeObsolete(AppCacheGroup* group, bool success) { |
42 obsoleted_group_ = group; | 42 obsoleted_group_ = group; |
43 obsoleted_success_ = success; | 43 obsoleted_success_ = success; |
44 } | 44 } |
45 | 45 |
46 void OnMainResponseFound(const GURL& url, const AppCacheEntry& entry, | 46 void OnMainResponseFound(const GURL& url, const AppCacheEntry& entry, |
| 47 const GURL& fallback_url, |
47 const AppCacheEntry& fallback_entry, | 48 const AppCacheEntry& fallback_entry, |
48 int64 cache_id, const GURL& manifest_url, | 49 int64 cache_id, const GURL& manifest_url, |
49 bool was_blocked_by_policy) { | 50 bool was_blocked_by_policy) { |
50 found_url_ = url; | 51 found_url_ = url; |
51 found_entry_ = entry; | 52 found_entry_ = entry; |
| 53 found_fallback_url_ = fallback_url; |
52 found_fallback_entry_ = fallback_entry; | 54 found_fallback_entry_ = fallback_entry; |
53 found_cache_id_ = cache_id; | 55 found_cache_id_ = cache_id; |
54 found_manifest_url_ = manifest_url; | 56 found_manifest_url_ = manifest_url; |
55 } | 57 } |
56 | 58 |
57 scoped_refptr<AppCache> loaded_cache_; | 59 scoped_refptr<AppCache> loaded_cache_; |
58 int64 loaded_cache_id_; | 60 int64 loaded_cache_id_; |
59 scoped_refptr<AppCacheGroup> loaded_group_; | 61 scoped_refptr<AppCacheGroup> loaded_group_; |
60 GURL loaded_manifest_url_; | 62 GURL loaded_manifest_url_; |
61 scoped_refptr<AppCacheGroup> stored_group_; | 63 scoped_refptr<AppCacheGroup> stored_group_; |
62 bool stored_group_success_; | 64 bool stored_group_success_; |
63 scoped_refptr<AppCacheGroup> obsoleted_group_; | 65 scoped_refptr<AppCacheGroup> obsoleted_group_; |
64 bool obsoleted_success_; | 66 bool obsoleted_success_; |
65 GURL found_url_; | 67 GURL found_url_; |
66 AppCacheEntry found_entry_; | 68 AppCacheEntry found_entry_; |
| 69 GURL found_fallback_url_; |
67 AppCacheEntry found_fallback_entry_; | 70 AppCacheEntry found_fallback_entry_; |
68 int64 found_cache_id_; | 71 int64 found_cache_id_; |
69 GURL found_manifest_url_; | 72 GURL found_manifest_url_; |
70 }; | 73 }; |
71 }; | 74 }; |
72 | 75 |
73 | 76 |
74 TEST_F(MockAppCacheStorageTest, LoadCache_Miss) { | 77 TEST_F(MockAppCacheStorageTest, LoadCache_Miss) { |
75 // Attempt to load a cache that doesn't exist. Should | 78 // Attempt to load a cache that doesn't exist. Should |
76 // complete asyncly. | 79 // complete asyncly. |
(...skipping 315 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
392 GURL url("http://blah/some_url"); | 395 GURL url("http://blah/some_url"); |
393 EXPECT_NE(url, delegate.found_url_); | 396 EXPECT_NE(url, delegate.found_url_); |
394 storage->FindResponseForMainRequest(url, &delegate); | 397 storage->FindResponseForMainRequest(url, &delegate); |
395 EXPECT_NE(url, delegate.found_url_); | 398 EXPECT_NE(url, delegate.found_url_); |
396 MessageLoop::current()->RunAllPending(); // Do async task execution. | 399 MessageLoop::current()->RunAllPending(); // Do async task execution. |
397 EXPECT_EQ(url, delegate.found_url_); | 400 EXPECT_EQ(url, delegate.found_url_); |
398 EXPECT_TRUE(delegate.found_manifest_url_.is_empty()); | 401 EXPECT_TRUE(delegate.found_manifest_url_.is_empty()); |
399 EXPECT_EQ(kNoCacheId, delegate.found_cache_id_); | 402 EXPECT_EQ(kNoCacheId, delegate.found_cache_id_); |
400 EXPECT_EQ(kNoResponseId, delegate.found_entry_.response_id()); | 403 EXPECT_EQ(kNoResponseId, delegate.found_entry_.response_id()); |
401 EXPECT_EQ(kNoResponseId, delegate.found_fallback_entry_.response_id()); | 404 EXPECT_EQ(kNoResponseId, delegate.found_fallback_entry_.response_id()); |
| 405 EXPECT_TRUE(delegate.found_fallback_url_.is_empty()); |
402 EXPECT_EQ(0, delegate.found_entry_.types()); | 406 EXPECT_EQ(0, delegate.found_entry_.types()); |
403 EXPECT_EQ(0, delegate.found_fallback_entry_.types()); | 407 EXPECT_EQ(0, delegate.found_fallback_entry_.types()); |
404 } | 408 } |
405 | 409 |
406 TEST_F(MockAppCacheStorageTest, BasicFindMainResponse) { | 410 TEST_F(MockAppCacheStorageTest, BasicFindMainResponse) { |
407 // Should complete asyncly. | 411 // Should complete asyncly. |
408 MockAppCacheService service; | 412 MockAppCacheService service; |
409 MockAppCacheStorage* storage = | 413 MockAppCacheStorage* storage = |
410 reinterpret_cast<MockAppCacheStorage*>(service.storage()); | 414 reinterpret_cast<MockAppCacheStorage*>(service.storage()); |
411 | 415 |
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
483 MockStorageDelegate delegate; | 487 MockStorageDelegate delegate; |
484 EXPECT_NE(kTestUrl, delegate.found_url_); | 488 EXPECT_NE(kTestUrl, delegate.found_url_); |
485 storage->FindResponseForMainRequest(kTestUrl, &delegate); | 489 storage->FindResponseForMainRequest(kTestUrl, &delegate); |
486 EXPECT_NE(kTestUrl, delegate.found_url_); | 490 EXPECT_NE(kTestUrl, delegate.found_url_); |
487 MessageLoop::current()->RunAllPending(); // Do async task execution. | 491 MessageLoop::current()->RunAllPending(); // Do async task execution. |
488 EXPECT_EQ(kTestUrl, delegate.found_url_); | 492 EXPECT_EQ(kTestUrl, delegate.found_url_); |
489 EXPECT_EQ(kManifestUrl, delegate.found_manifest_url_); | 493 EXPECT_EQ(kManifestUrl, delegate.found_manifest_url_); |
490 EXPECT_EQ(kCacheId, delegate.found_cache_id_); | 494 EXPECT_EQ(kCacheId, delegate.found_cache_id_); |
491 EXPECT_FALSE(delegate.found_entry_.has_response_id()); | 495 EXPECT_FALSE(delegate.found_entry_.has_response_id()); |
492 EXPECT_EQ(kResponseId2, delegate.found_fallback_entry_.response_id()); | 496 EXPECT_EQ(kResponseId2, delegate.found_fallback_entry_.response_id()); |
| 497 EXPECT_EQ(kFallbackEntryUrl2, delegate.found_fallback_url_); |
493 EXPECT_TRUE(delegate.found_fallback_entry_.IsFallback()); | 498 EXPECT_TRUE(delegate.found_fallback_entry_.IsFallback()); |
494 } | 499 } |
495 | 500 |
496 TEST_F(MockAppCacheStorageTest, FindMainResponseWithMultipleCandidates) { | 501 TEST_F(MockAppCacheStorageTest, FindMainResponseWithMultipleCandidates) { |
497 // Should complete asyncly. | 502 // Should complete asyncly. |
498 MockAppCacheService service; | 503 MockAppCacheService service; |
499 MockAppCacheStorage* storage = | 504 MockAppCacheStorage* storage = |
500 reinterpret_cast<MockAppCacheStorage*>(service.storage()); | 505 reinterpret_cast<MockAppCacheStorage*>(service.storage()); |
501 | 506 |
502 // Setup some preconditions. Create 2 complete caches with an entry | 507 // Setup some preconditions. Create 2 complete caches with an entry |
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
585 // We should not find anything for the foreign entry. | 590 // We should not find anything for the foreign entry. |
586 EXPECT_NE(kEntryUrl, delegate.found_url_); | 591 EXPECT_NE(kEntryUrl, delegate.found_url_); |
587 storage->FindResponseForMainRequest(kEntryUrl, &delegate); | 592 storage->FindResponseForMainRequest(kEntryUrl, &delegate); |
588 EXPECT_NE(kEntryUrl, delegate.found_url_); | 593 EXPECT_NE(kEntryUrl, delegate.found_url_); |
589 MessageLoop::current()->RunAllPending(); // Do async task execution. | 594 MessageLoop::current()->RunAllPending(); // Do async task execution. |
590 EXPECT_EQ(kEntryUrl, delegate.found_url_); | 595 EXPECT_EQ(kEntryUrl, delegate.found_url_); |
591 EXPECT_TRUE(delegate.found_manifest_url_.is_empty()); | 596 EXPECT_TRUE(delegate.found_manifest_url_.is_empty()); |
592 EXPECT_EQ(kNoCacheId, delegate.found_cache_id_); | 597 EXPECT_EQ(kNoCacheId, delegate.found_cache_id_); |
593 EXPECT_EQ(kNoResponseId, delegate.found_entry_.response_id()); | 598 EXPECT_EQ(kNoResponseId, delegate.found_entry_.response_id()); |
594 EXPECT_EQ(kNoResponseId, delegate.found_fallback_entry_.response_id()); | 599 EXPECT_EQ(kNoResponseId, delegate.found_fallback_entry_.response_id()); |
| 600 EXPECT_TRUE(delegate.found_fallback_url_.is_empty()); |
595 EXPECT_EQ(0, delegate.found_entry_.types()); | 601 EXPECT_EQ(0, delegate.found_entry_.types()); |
596 EXPECT_EQ(0, delegate.found_fallback_entry_.types()); | 602 EXPECT_EQ(0, delegate.found_fallback_entry_.types()); |
597 | 603 |
598 // We should not find anything for the online namespace. | 604 // We should not find anything for the online namespace. |
599 EXPECT_NE(kOnlineNamespaceUrl, delegate.found_url_); | 605 EXPECT_NE(kOnlineNamespaceUrl, delegate.found_url_); |
600 storage->FindResponseForMainRequest(kOnlineNamespaceUrl, &delegate); | 606 storage->FindResponseForMainRequest(kOnlineNamespaceUrl, &delegate); |
601 EXPECT_NE(kOnlineNamespaceUrl, delegate.found_url_); | 607 EXPECT_NE(kOnlineNamespaceUrl, delegate.found_url_); |
602 MessageLoop::current()->RunAllPending(); // Do async task execution. | 608 MessageLoop::current()->RunAllPending(); // Do async task execution. |
603 EXPECT_EQ(kOnlineNamespaceUrl, delegate.found_url_); | 609 EXPECT_EQ(kOnlineNamespaceUrl, delegate.found_url_); |
604 EXPECT_TRUE(delegate.found_manifest_url_.is_empty()); | 610 EXPECT_TRUE(delegate.found_manifest_url_.is_empty()); |
605 EXPECT_EQ(kNoCacheId, delegate.found_cache_id_); | 611 EXPECT_EQ(kNoCacheId, delegate.found_cache_id_); |
606 EXPECT_EQ(kNoResponseId, delegate.found_entry_.response_id()); | 612 EXPECT_EQ(kNoResponseId, delegate.found_entry_.response_id()); |
607 EXPECT_EQ(kNoResponseId, delegate.found_fallback_entry_.response_id()); | 613 EXPECT_EQ(kNoResponseId, delegate.found_fallback_entry_.response_id()); |
| 614 EXPECT_TRUE(delegate.found_fallback_url_.is_empty()); |
608 EXPECT_EQ(0, delegate.found_entry_.types()); | 615 EXPECT_EQ(0, delegate.found_entry_.types()); |
609 EXPECT_EQ(0, delegate.found_fallback_entry_.types()); | 616 EXPECT_EQ(0, delegate.found_fallback_entry_.types()); |
610 } | 617 } |
611 | 618 |
612 } // namespace appcache | 619 } // namespace appcache |
613 | 620 |
OLD | NEW |