| 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 <string> | 5 #include <string> |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/bind_helpers.h" | 8 #include "base/bind_helpers.h" |
| 9 #include "base/message_loop.h" | 9 #include "base/message_loop.h" |
| 10 #include "base/pickle.h" | 10 #include "base/pickle.h" |
| (...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 123 // Create a mock group, cache, and entry and stuff them into mock storage. | 123 // Create a mock group, cache, and entry and stuff them into mock storage. |
| 124 scoped_refptr<AppCacheGroup> group( | 124 scoped_refptr<AppCacheGroup> group( |
| 125 new AppCacheGroup(service_->storage(), kManifestUrl, kMockGroupId)); | 125 new AppCacheGroup(service_->storage(), kManifestUrl, kMockGroupId)); |
| 126 scoped_refptr<AppCache> cache( | 126 scoped_refptr<AppCache> cache( |
| 127 new AppCache(service_->storage(), kMockCacheId)); | 127 new AppCache(service_->storage(), kMockCacheId)); |
| 128 cache->AddEntry( | 128 cache->AddEntry( |
| 129 kManifestUrl, | 129 kManifestUrl, |
| 130 AppCacheEntry(AppCacheEntry::MANIFEST, kMockResponseId, | 130 AppCacheEntry(AppCacheEntry::MANIFEST, kMockResponseId, |
| 131 kMockInfoSize + kMockBodySize)); | 131 kMockInfoSize + kMockBodySize)); |
| 132 cache->set_complete(true); | 132 cache->set_complete(true); |
| 133 group->AddCache(cache); | 133 group->AddCache(cache.get()); |
| 134 mock_storage()->AddStoredGroup(group); | 134 mock_storage()->AddStoredGroup(group.get()); |
| 135 mock_storage()->AddStoredCache(cache); | 135 mock_storage()->AddStoredCache(cache.get()); |
| 136 } | 136 } |
| 137 | 137 |
| 138 void SetupMockReader( | 138 void SetupMockReader( |
| 139 bool valid_info, bool valid_data, bool valid_size) { | 139 bool valid_info, bool valid_data, bool valid_size) { |
| 140 net::HttpResponseInfo* info = valid_info ? MakeMockResponseInfo() : NULL; | 140 net::HttpResponseInfo* info = valid_info ? MakeMockResponseInfo() : NULL; |
| 141 int info_size = info ? GetResponseInfoSize(info) : 0; | 141 int info_size = info ? GetResponseInfoSize(info) : 0; |
| 142 const char* data = valid_data ? kMockBody : NULL; | 142 const char* data = valid_data ? kMockBody : NULL; |
| 143 int data_size = valid_size ? kMockBodySize : 3; | 143 int data_size = valid_size ? kMockBodySize : 3; |
| 144 mock_storage()->SimulateResponseReader( | 144 mock_storage()->SimulateResponseReader( |
| 145 new MockResponseReader(kMockResponseId, info, info_size, | 145 new MockResponseReader(kMockResponseId, info, info_size, |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 205 AppCacheInfo mock_manifest_2; | 205 AppCacheInfo mock_manifest_2; |
| 206 AppCacheInfo mock_manifest_3; | 206 AppCacheInfo mock_manifest_3; |
| 207 mock_manifest_1.manifest_url = kOrigin.Resolve("manifest1"); | 207 mock_manifest_1.manifest_url = kOrigin.Resolve("manifest1"); |
| 208 mock_manifest_2.manifest_url = kOrigin.Resolve("manifest2"); | 208 mock_manifest_2.manifest_url = kOrigin.Resolve("manifest2"); |
| 209 mock_manifest_3.manifest_url = kOrigin.Resolve("manifest3"); | 209 mock_manifest_3.manifest_url = kOrigin.Resolve("manifest3"); |
| 210 AppCacheInfoVector info_vector; | 210 AppCacheInfoVector info_vector; |
| 211 info_vector.push_back(mock_manifest_1); | 211 info_vector.push_back(mock_manifest_1); |
| 212 info_vector.push_back(mock_manifest_2); | 212 info_vector.push_back(mock_manifest_2); |
| 213 info_vector.push_back(mock_manifest_3); | 213 info_vector.push_back(mock_manifest_3); |
| 214 info->infos_by_origin[kOrigin] = info_vector; | 214 info->infos_by_origin[kOrigin] = info_vector; |
| 215 mock_storage()->SimulateGetAllInfo(info); | 215 mock_storage()->SimulateGetAllInfo(info.get()); |
| 216 service_->DeleteAppCachesForOrigin(kOrigin, deletion_callback_); | 216 service_->DeleteAppCachesForOrigin(kOrigin, deletion_callback_); |
| 217 EXPECT_EQ(0, delete_completion_count_); | 217 EXPECT_EQ(0, delete_completion_count_); |
| 218 base::MessageLoop::current()->RunUntilIdle(); | 218 base::MessageLoop::current()->RunUntilIdle(); |
| 219 EXPECT_EQ(1, delete_completion_count_); | 219 EXPECT_EQ(1, delete_completion_count_); |
| 220 EXPECT_EQ(net::OK, delete_result_); | 220 EXPECT_EQ(net::OK, delete_result_); |
| 221 delete_completion_count_ = 0; | 221 delete_completion_count_ = 0; |
| 222 | 222 |
| 223 // Should fail if storage fails to delete. | 223 // Should fail if storage fails to delete. |
| 224 info->infos_by_origin[kOrigin] = info_vector; | 224 info->infos_by_origin[kOrigin] = info_vector; |
| 225 mock_storage()->SimulateGetAllInfo(info); | 225 mock_storage()->SimulateGetAllInfo(info.get()); |
| 226 mock_storage()->SimulateMakeGroupObsoleteFailure(); | 226 mock_storage()->SimulateMakeGroupObsoleteFailure(); |
| 227 service_->DeleteAppCachesForOrigin(kOrigin, deletion_callback_); | 227 service_->DeleteAppCachesForOrigin(kOrigin, deletion_callback_); |
| 228 EXPECT_EQ(0, delete_completion_count_); | 228 EXPECT_EQ(0, delete_completion_count_); |
| 229 base::MessageLoop::current()->RunUntilIdle(); | 229 base::MessageLoop::current()->RunUntilIdle(); |
| 230 EXPECT_EQ(1, delete_completion_count_); | 230 EXPECT_EQ(1, delete_completion_count_); |
| 231 EXPECT_EQ(net::ERR_FAILED, delete_result_); | 231 EXPECT_EQ(net::ERR_FAILED, delete_result_); |
| 232 delete_completion_count_ = 0; | 232 delete_completion_count_ = 0; |
| 233 | 233 |
| 234 // Should complete with abort error if the service is deleted | 234 // Should complete with abort error if the service is deleted |
| 235 // prior to a delete completion. | 235 // prior to a delete completion. |
| (...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 311 base::MessageLoop::current()->RunUntilIdle(); | 311 base::MessageLoop::current()->RunUntilIdle(); |
| 312 EXPECT_EQ(0, CountPendingHelpers()); | 312 EXPECT_EQ(0, CountPendingHelpers()); |
| 313 EXPECT_FALSE(IsGroupStored(kManifestUrl)); | 313 EXPECT_FALSE(IsGroupStored(kManifestUrl)); |
| 314 ResetStorage(); | 314 ResetStorage(); |
| 315 | 315 |
| 316 service_.reset(); // Clean up. | 316 service_.reset(); // Clean up. |
| 317 base::MessageLoop::current()->RunUntilIdle(); | 317 base::MessageLoop::current()->RunUntilIdle(); |
| 318 } | 318 } |
| 319 | 319 |
| 320 } // namespace appcache | 320 } // namespace appcache |
| OLD | NEW |