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 <stack> | 5 #include <stack> |
6 | 6 |
7 #include "base/message_loop.h" | 7 #include "base/message_loop.h" |
8 #include "base/thread.h" | 8 #include "base/thread.h" |
9 #include "base/waitable_event.h" | 9 #include "base/waitable_event.h" |
10 #include "net/base/net_errors.h" | 10 #include "net/base/net_errors.h" |
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
101 test_->ScheduleNextTask(); | 101 test_->ScheduleNextTask(); |
102 } | 102 } |
103 | 103 |
104 void OnGroupMadeObsolete(AppCacheGroup* group, bool success) { | 104 void OnGroupMadeObsolete(AppCacheGroup* group, bool success) { |
105 obsoleted_group_ = group; | 105 obsoleted_group_ = group; |
106 obsoleted_success_ = success; | 106 obsoleted_success_ = success; |
107 test_->ScheduleNextTask(); | 107 test_->ScheduleNextTask(); |
108 } | 108 } |
109 | 109 |
110 void OnMainResponseFound(const GURL& url, const AppCacheEntry& entry, | 110 void OnMainResponseFound(const GURL& url, const AppCacheEntry& entry, |
| 111 const GURL& fallback_url, |
111 const AppCacheEntry& fallback_entry, | 112 const AppCacheEntry& fallback_entry, |
112 int64 cache_id, const GURL& manifest_url, | 113 int64 cache_id, const GURL& manifest_url, |
113 bool was_blocked_by_policy) { | 114 bool was_blocked_by_policy) { |
114 found_url_ = url; | 115 found_url_ = url; |
115 found_entry_ = entry; | 116 found_entry_ = entry; |
| 117 found_fallback_url_ = fallback_url; |
116 found_fallback_entry_ = fallback_entry; | 118 found_fallback_entry_ = fallback_entry; |
117 found_cache_id_ = cache_id; | 119 found_cache_id_ = cache_id; |
118 found_manifest_url_ = manifest_url; | 120 found_manifest_url_ = manifest_url; |
119 found_blocked_by_policy_ = was_blocked_by_policy; | 121 found_blocked_by_policy_ = was_blocked_by_policy; |
120 test_->ScheduleNextTask(); | 122 test_->ScheduleNextTask(); |
121 } | 123 } |
122 | 124 |
123 scoped_refptr<AppCache> loaded_cache_; | 125 scoped_refptr<AppCache> loaded_cache_; |
124 int64 loaded_cache_id_; | 126 int64 loaded_cache_id_; |
125 scoped_refptr<AppCacheGroup> loaded_group_; | 127 scoped_refptr<AppCacheGroup> loaded_group_; |
126 GURL loaded_manifest_url_; | 128 GURL loaded_manifest_url_; |
127 scoped_refptr<AppCache> loaded_groups_newest_cache_; | 129 scoped_refptr<AppCache> loaded_groups_newest_cache_; |
128 scoped_refptr<AppCacheGroup> stored_group_; | 130 scoped_refptr<AppCacheGroup> stored_group_; |
129 bool stored_group_success_; | 131 bool stored_group_success_; |
130 bool would_exceed_quota_; | 132 bool would_exceed_quota_; |
131 scoped_refptr<AppCacheGroup> obsoleted_group_; | 133 scoped_refptr<AppCacheGroup> obsoleted_group_; |
132 bool obsoleted_success_; | 134 bool obsoleted_success_; |
133 GURL found_url_; | 135 GURL found_url_; |
134 AppCacheEntry found_entry_; | 136 AppCacheEntry found_entry_; |
| 137 GURL found_fallback_url_; |
135 AppCacheEntry found_fallback_entry_; | 138 AppCacheEntry found_fallback_entry_; |
136 int64 found_cache_id_; | 139 int64 found_cache_id_; |
137 GURL found_manifest_url_; | 140 GURL found_manifest_url_; |
138 bool found_blocked_by_policy_; | 141 bool found_blocked_by_policy_; |
139 AppCacheStorageImplTest* test_; | 142 AppCacheStorageImplTest* test_; |
140 }; | 143 }; |
141 | 144 |
142 class MockAppCachePolicy : public AppCachePolicy { | 145 class MockAppCachePolicy : public AppCachePolicy { |
143 public: | 146 public: |
144 explicit MockAppCachePolicy(AppCacheStorageImplTest* test) | 147 explicit MockAppCachePolicy(AppCacheStorageImplTest* test) |
(...skipping 587 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
732 } | 735 } |
733 | 736 |
734 void Verify_FindNoMainResponse() { | 737 void Verify_FindNoMainResponse() { |
735 EXPECT_EQ(kEntryUrl, delegate()->found_url_); | 738 EXPECT_EQ(kEntryUrl, delegate()->found_url_); |
736 // If the request was blocked by a policy, the manifest url is still valid. | 739 // If the request was blocked by a policy, the manifest url is still valid. |
737 EXPECT_TRUE(delegate()->found_manifest_url_.is_empty() || | 740 EXPECT_TRUE(delegate()->found_manifest_url_.is_empty() || |
738 delegate()->found_blocked_by_policy_); | 741 delegate()->found_blocked_by_policy_); |
739 EXPECT_EQ(kNoCacheId, delegate()->found_cache_id_); | 742 EXPECT_EQ(kNoCacheId, delegate()->found_cache_id_); |
740 EXPECT_EQ(kNoResponseId, delegate()->found_entry_.response_id()); | 743 EXPECT_EQ(kNoResponseId, delegate()->found_entry_.response_id()); |
741 EXPECT_EQ(kNoResponseId, delegate()->found_fallback_entry_.response_id()); | 744 EXPECT_EQ(kNoResponseId, delegate()->found_fallback_entry_.response_id()); |
| 745 EXPECT_TRUE(delegate()->found_fallback_url_.is_empty()); |
742 EXPECT_EQ(0, delegate()->found_entry_.types()); | 746 EXPECT_EQ(0, delegate()->found_entry_.types()); |
743 EXPECT_EQ(0, delegate()->found_fallback_entry_.types()); | 747 EXPECT_EQ(0, delegate()->found_fallback_entry_.types()); |
744 TestFinished(); | 748 TestFinished(); |
745 } | 749 } |
746 | 750 |
747 // BasicFindMainResponse ------------------------------- | 751 // BasicFindMainResponse ------------------------------- |
748 | 752 |
749 void BasicFindMainResponseInDatabase() { | 753 void BasicFindMainResponseInDatabase() { |
750 BasicFindMainResponse(true, false); | 754 BasicFindMainResponse(true, false); |
751 } | 755 } |
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
851 EXPECT_NE(kFallbackTestUrl, delegate()->found_url_); | 855 EXPECT_NE(kFallbackTestUrl, delegate()->found_url_); |
852 } | 856 } |
853 | 857 |
854 void Verify_BasicFindMainFallbackResponse() { | 858 void Verify_BasicFindMainFallbackResponse() { |
855 EXPECT_EQ(kFallbackTestUrl, delegate()->found_url_); | 859 EXPECT_EQ(kFallbackTestUrl, delegate()->found_url_); |
856 EXPECT_EQ(kManifestUrl, delegate()->found_manifest_url_); | 860 EXPECT_EQ(kManifestUrl, delegate()->found_manifest_url_); |
857 EXPECT_FALSE(delegate()->found_blocked_by_policy_); | 861 EXPECT_FALSE(delegate()->found_blocked_by_policy_); |
858 EXPECT_EQ(1, delegate()->found_cache_id_); | 862 EXPECT_EQ(1, delegate()->found_cache_id_); |
859 EXPECT_FALSE(delegate()->found_entry_.has_response_id()); | 863 EXPECT_FALSE(delegate()->found_entry_.has_response_id()); |
860 EXPECT_EQ(2, delegate()->found_fallback_entry_.response_id()); | 864 EXPECT_EQ(2, delegate()->found_fallback_entry_.response_id()); |
| 865 EXPECT_EQ(kEntryUrl2, delegate()->found_fallback_url_); |
861 EXPECT_TRUE(delegate()->found_fallback_entry_.IsFallback()); | 866 EXPECT_TRUE(delegate()->found_fallback_entry_.IsFallback()); |
862 TestFinished(); | 867 TestFinished(); |
863 } | 868 } |
864 | 869 |
865 // FindMainResponseWithMultipleHits ------------------------------- | 870 // FindMainResponseWithMultipleHits ------------------------------- |
866 | 871 |
867 void FindMainResponseWithMultipleHits() { | 872 void FindMainResponseWithMultipleHits() { |
868 PushNextTask(NewRunnableMethod(this, | 873 PushNextTask(NewRunnableMethod(this, |
869 &AppCacheStorageImplTest::Verify_FindMainResponseWithMultipleHits)); | 874 &AppCacheStorageImplTest::Verify_FindMainResponseWithMultipleHits)); |
870 | 875 |
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
947 storage()->FindResponseForMainRequest(kEntryUrl, delegate()); | 952 storage()->FindResponseForMainRequest(kEntryUrl, delegate()); |
948 } | 953 } |
949 | 954 |
950 void Verify_NotFound(GURL expected_url, bool test_finished) { | 955 void Verify_NotFound(GURL expected_url, bool test_finished) { |
951 EXPECT_EQ(expected_url, delegate()->found_url_); | 956 EXPECT_EQ(expected_url, delegate()->found_url_); |
952 EXPECT_TRUE(delegate()->found_manifest_url_.is_empty()); | 957 EXPECT_TRUE(delegate()->found_manifest_url_.is_empty()); |
953 EXPECT_FALSE(delegate()->found_blocked_by_policy_); | 958 EXPECT_FALSE(delegate()->found_blocked_by_policy_); |
954 EXPECT_EQ(kNoCacheId, delegate()->found_cache_id_); | 959 EXPECT_EQ(kNoCacheId, delegate()->found_cache_id_); |
955 EXPECT_EQ(kNoResponseId, delegate()->found_entry_.response_id()); | 960 EXPECT_EQ(kNoResponseId, delegate()->found_entry_.response_id()); |
956 EXPECT_EQ(kNoResponseId, delegate()->found_fallback_entry_.response_id()); | 961 EXPECT_EQ(kNoResponseId, delegate()->found_fallback_entry_.response_id()); |
| 962 EXPECT_TRUE(delegate()->found_fallback_url_.is_empty()); |
957 EXPECT_EQ(0, delegate()->found_entry_.types()); | 963 EXPECT_EQ(0, delegate()->found_entry_.types()); |
958 EXPECT_EQ(0, delegate()->found_fallback_entry_.types()); | 964 EXPECT_EQ(0, delegate()->found_fallback_entry_.types()); |
959 | 965 |
960 if (!test_finished) { | 966 if (!test_finished) { |
961 // We should not find anything for the online namespace. | 967 // We should not find anything for the online namespace. |
962 PushNextTask(NewRunnableMethod(this, | 968 PushNextTask(NewRunnableMethod(this, |
963 &AppCacheStorageImplTest::Verify_NotFound, kOnlineNamespace, true)); | 969 &AppCacheStorageImplTest::Verify_NotFound, kOnlineNamespace, true)); |
964 storage()->FindResponseForMainRequest(kOnlineNamespace, delegate()); | 970 storage()->FindResponseForMainRequest(kOnlineNamespace, delegate()); |
965 return; | 971 return; |
966 } | 972 } |
(...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1115 &AppCacheStorageImplTest::FindMainResponseExclusionsInWorkingSet); | 1121 &AppCacheStorageImplTest::FindMainResponseExclusionsInWorkingSet); |
1116 } | 1122 } |
1117 | 1123 |
1118 // That's all folks! | 1124 // That's all folks! |
1119 | 1125 |
1120 } // namespace appcache | 1126 } // namespace appcache |
1121 | 1127 |
1122 // AppCacheStorageImplTest is expected to always live longer than the | 1128 // AppCacheStorageImplTest is expected to always live longer than the |
1123 // runnable methods. This lets us call NewRunnableMethod on its instances. | 1129 // runnable methods. This lets us call NewRunnableMethod on its instances. |
1124 DISABLE_RUNNABLE_METHOD_REFCOUNT(appcache::AppCacheStorageImplTest); | 1130 DISABLE_RUNNABLE_METHOD_REFCOUNT(appcache::AppCacheStorageImplTest); |
OLD | NEW |