OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 <stddef.h> |
| 6 #include <stdint.h> |
| 7 |
5 #include "base/bind.h" | 8 #include "base/bind.h" |
6 #include "base/bind_helpers.h" | 9 #include "base/bind_helpers.h" |
7 #include "base/location.h" | 10 #include "base/location.h" |
| 11 #include "base/macros.h" |
8 #include "base/single_thread_task_runner.h" | 12 #include "base/single_thread_task_runner.h" |
9 #include "base/stl_util.h" | 13 #include "base/stl_util.h" |
10 #include "base/synchronization/waitable_event.h" | 14 #include "base/synchronization/waitable_event.h" |
11 #include "base/thread_task_runner_handle.h" | 15 #include "base/thread_task_runner_handle.h" |
12 #include "base/threading/thread.h" | 16 #include "base/threading/thread.h" |
13 #include "content/browser/appcache/appcache_group.h" | 17 #include "content/browser/appcache/appcache_group.h" |
14 #include "content/browser/appcache/appcache_host.h" | 18 #include "content/browser/appcache/appcache_host.h" |
15 #include "content/browser/appcache/appcache_response.h" | 19 #include "content/browser/appcache/appcache_response.h" |
16 #include "content/browser/appcache/appcache_update_job.h" | 20 #include "content/browser/appcache/appcache_update_job.h" |
17 #include "content/browser/appcache/mock_appcache_service.h" | 21 #include "content/browser/appcache/mock_appcache_service.h" |
(...skipping 1208 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1226 group_->group_id())); | 1230 group_->group_id())); |
1227 cache->AddEntry(MockHttpServer::GetMockUrl("files/explicit1"), | 1231 cache->AddEntry(MockHttpServer::GetMockUrl("files/explicit1"), |
1228 AppCacheEntry(AppCacheEntry::EXPLICIT, | 1232 AppCacheEntry(AppCacheEntry::EXPLICIT, |
1229 response_writer_->response_id())); | 1233 response_writer_->response_id())); |
1230 | 1234 |
1231 // Set up checks for when update job finishes. | 1235 // Set up checks for when update job finishes. |
1232 do_checks_after_update_finished_ = true; | 1236 do_checks_after_update_finished_ = true; |
1233 expect_group_obsolete_ = false; | 1237 expect_group_obsolete_ = false; |
1234 expect_group_has_cache_ = true; | 1238 expect_group_has_cache_ = true; |
1235 expect_old_cache_ = cache; | 1239 expect_old_cache_ = cache; |
1236 expect_response_ids_.insert( | 1240 expect_response_ids_.insert(std::map<GURL, int64_t>::value_type( |
1237 std::map<GURL, int64>::value_type( | 1241 MockHttpServer::GetMockUrl("files/explicit1"), |
1238 MockHttpServer::GetMockUrl("files/explicit1"), | 1242 response_writer_->response_id())); |
1239 response_writer_->response_id())); | |
1240 tested_manifest_ = MANIFEST1; | 1243 tested_manifest_ = MANIFEST1; |
1241 MockFrontend::HostIds ids(1, host->host_id()); | 1244 MockFrontend::HostIds ids(1, host->host_id()); |
1242 frontend->AddExpectedEvent(ids, APPCACHE_CHECKING_EVENT); | 1245 frontend->AddExpectedEvent(ids, APPCACHE_CHECKING_EVENT); |
1243 frontend->AddExpectedEvent(ids, APPCACHE_DOWNLOADING_EVENT); | 1246 frontend->AddExpectedEvent(ids, APPCACHE_DOWNLOADING_EVENT); |
1244 frontend->AddExpectedEvent(ids, APPCACHE_PROGRESS_EVENT); | 1247 frontend->AddExpectedEvent(ids, APPCACHE_PROGRESS_EVENT); |
1245 frontend->AddExpectedEvent(ids, APPCACHE_PROGRESS_EVENT); | 1248 frontend->AddExpectedEvent(ids, APPCACHE_PROGRESS_EVENT); |
1246 frontend->AddExpectedEvent(ids, APPCACHE_PROGRESS_EVENT); // final | 1249 frontend->AddExpectedEvent(ids, APPCACHE_PROGRESS_EVENT); // final |
1247 frontend->AddExpectedEvent(ids, APPCACHE_UPDATE_READY_EVENT); | 1250 frontend->AddExpectedEvent(ids, APPCACHE_UPDATE_READY_EVENT); |
1248 | 1251 |
1249 // Seed storage with expected http response info for entry. Allow reuse. | 1252 // Seed storage with expected http response info for entry. Allow reuse. |
(...skipping 313 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1563 tested_manifest_ = MANIFEST1; | 1566 tested_manifest_ = MANIFEST1; |
1564 expect_extra_entries_.insert(AppCache::EntryMap::value_type( | 1567 expect_extra_entries_.insert(AppCache::EntryMap::value_type( |
1565 MockHttpServer::GetMockUrl("files/explicit2"), | 1568 MockHttpServer::GetMockUrl("files/explicit2"), |
1566 AppCacheEntry(AppCacheEntry::MASTER))); // foreign flag is dropped | 1569 AppCacheEntry(AppCacheEntry::MASTER))); // foreign flag is dropped |
1567 expect_extra_entries_.insert(AppCache::EntryMap::value_type( | 1570 expect_extra_entries_.insert(AppCache::EntryMap::value_type( |
1568 MockHttpServer::GetMockUrl("files/servererror"), | 1571 MockHttpServer::GetMockUrl("files/servererror"), |
1569 AppCacheEntry(AppCacheEntry::MASTER))); | 1572 AppCacheEntry(AppCacheEntry::MASTER))); |
1570 expect_extra_entries_.insert(AppCache::EntryMap::value_type( | 1573 expect_extra_entries_.insert(AppCache::EntryMap::value_type( |
1571 MockHttpServer::GetMockUrl("files/notmodified"), | 1574 MockHttpServer::GetMockUrl("files/notmodified"), |
1572 AppCacheEntry(AppCacheEntry::EXPLICIT))); | 1575 AppCacheEntry(AppCacheEntry::EXPLICIT))); |
1573 expect_response_ids_.insert(std::map<GURL, int64>::value_type( | 1576 expect_response_ids_.insert(std::map<GURL, int64_t>::value_type( |
1574 MockHttpServer::GetMockUrl("files/servererror"), 444)); // copied | 1577 MockHttpServer::GetMockUrl("files/servererror"), 444)); // copied |
1575 expect_response_ids_.insert(std::map<GURL, int64>::value_type( | 1578 expect_response_ids_.insert(std::map<GURL, int64_t>::value_type( |
1576 MockHttpServer::GetMockUrl("files/notmodified"), 555)); // copied | 1579 MockHttpServer::GetMockUrl("files/notmodified"), 555)); // copied |
1577 MockFrontend::HostIds ids1(1, host1->host_id()); | 1580 MockFrontend::HostIds ids1(1, host1->host_id()); |
1578 frontend1->AddExpectedEvent(ids1, APPCACHE_CHECKING_EVENT); | 1581 frontend1->AddExpectedEvent(ids1, APPCACHE_CHECKING_EVENT); |
1579 frontend1->AddExpectedEvent(ids1, APPCACHE_DOWNLOADING_EVENT); | 1582 frontend1->AddExpectedEvent(ids1, APPCACHE_DOWNLOADING_EVENT); |
1580 frontend1->AddExpectedEvent(ids1, APPCACHE_PROGRESS_EVENT); // explicit1 | 1583 frontend1->AddExpectedEvent(ids1, APPCACHE_PROGRESS_EVENT); // explicit1 |
1581 frontend1->AddExpectedEvent(ids1, APPCACHE_PROGRESS_EVENT); // fallback1a | 1584 frontend1->AddExpectedEvent(ids1, APPCACHE_PROGRESS_EVENT); // fallback1a |
1582 frontend1->AddExpectedEvent(ids1, APPCACHE_PROGRESS_EVENT); // notfound | 1585 frontend1->AddExpectedEvent(ids1, APPCACHE_PROGRESS_EVENT); // notfound |
1583 frontend1->AddExpectedEvent(ids1, APPCACHE_PROGRESS_EVENT); // explicit2 | 1586 frontend1->AddExpectedEvent(ids1, APPCACHE_PROGRESS_EVENT); // explicit2 |
1584 frontend1->AddExpectedEvent(ids1, APPCACHE_PROGRESS_EVENT); // servererror | 1587 frontend1->AddExpectedEvent(ids1, APPCACHE_PROGRESS_EVENT); // servererror |
1585 frontend1->AddExpectedEvent(ids1, APPCACHE_PROGRESS_EVENT); // notmodified | 1588 frontend1->AddExpectedEvent(ids1, APPCACHE_PROGRESS_EVENT); // notmodified |
(...skipping 338 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1924 | 1927 |
1925 void MasterEntryFailStoreNewestCacheTest() { | 1928 void MasterEntryFailStoreNewestCacheTest() { |
1926 ASSERT_TRUE(base::MessageLoopForIO::IsCurrent()); | 1929 ASSERT_TRUE(base::MessageLoopForIO::IsCurrent()); |
1927 | 1930 |
1928 MakeService(); | 1931 MakeService(); |
1929 MockAppCacheStorage* storage = | 1932 MockAppCacheStorage* storage = |
1930 reinterpret_cast<MockAppCacheStorage*>(service_->storage()); | 1933 reinterpret_cast<MockAppCacheStorage*>(service_->storage()); |
1931 storage->SimulateStoreGroupAndNewestCacheFailure(); | 1934 storage->SimulateStoreGroupAndNewestCacheFailure(); |
1932 | 1935 |
1933 const GURL kManifestUrl = MockHttpServer::GetMockUrl("files/notmodified"); | 1936 const GURL kManifestUrl = MockHttpServer::GetMockUrl("files/notmodified"); |
1934 const int64 kManifestResponseId = 11; | 1937 const int64_t kManifestResponseId = 11; |
1935 | 1938 |
1936 // Seed the response_info working set with canned data for | 1939 // Seed the response_info working set with canned data for |
1937 // files/servererror and for files/notmodified to test that the | 1940 // files/servererror and for files/notmodified to test that the |
1938 // existing entries for those resource are reused by the update job. | 1941 // existing entries for those resource are reused by the update job. |
1939 const char kData[] = | 1942 const char kData[] = |
1940 "HTTP/1.1 200 OK\0" | 1943 "HTTP/1.1 200 OK\0" |
1941 "Content-type: text/cache-manifest\0" | 1944 "Content-type: text/cache-manifest\0" |
1942 "Last-Modified: Sat, 29 Oct 1994 19:43:31 GMT\0" | 1945 "Last-Modified: Sat, 29 Oct 1994 19:43:31 GMT\0" |
1943 "\0"; | 1946 "\0"; |
1944 const std::string kRawHeaders(kData, arraysize(kData)); | 1947 const std::string kRawHeaders(kData, arraysize(kData)); |
(...skipping 1106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3051 service_.reset(NULL); | 3054 service_.reset(NULL); |
3052 | 3055 |
3053 event_->Signal(); | 3056 event_->Signal(); |
3054 } | 3057 } |
3055 | 3058 |
3056 void MakeService() { | 3059 void MakeService() { |
3057 service_.reset(new MockAppCacheService()); | 3060 service_.reset(new MockAppCacheService()); |
3058 service_->set_request_context(io_thread_->request_context()); | 3061 service_->set_request_context(io_thread_->request_context()); |
3059 } | 3062 } |
3060 | 3063 |
3061 AppCache* MakeCacheForGroup(int64 cache_id, int64 manifest_response_id) { | 3064 AppCache* MakeCacheForGroup(int64_t cache_id, int64_t manifest_response_id) { |
3062 return MakeCacheForGroup(cache_id, group_->manifest_url(), | 3065 return MakeCacheForGroup(cache_id, group_->manifest_url(), |
3063 manifest_response_id); | 3066 manifest_response_id); |
3064 } | 3067 } |
3065 | 3068 |
3066 AppCache* MakeCacheForGroup(int64 cache_id, const GURL& manifest_entry_url, | 3069 AppCache* MakeCacheForGroup(int64_t cache_id, |
3067 int64 manifest_response_id) { | 3070 const GURL& manifest_entry_url, |
| 3071 int64_t manifest_response_id) { |
3068 AppCache* cache = new AppCache(service_->storage(), cache_id); | 3072 AppCache* cache = new AppCache(service_->storage(), cache_id); |
3069 cache->set_complete(true); | 3073 cache->set_complete(true); |
3070 cache->set_update_time(base::Time::Now() - kOneHour); | 3074 cache->set_update_time(base::Time::Now() - kOneHour); |
3071 group_->AddCache(cache); | 3075 group_->AddCache(cache); |
3072 group_->set_last_full_update_check_time(cache->update_time()); | 3076 group_->set_last_full_update_check_time(cache->update_time()); |
3073 | 3077 |
3074 // Add manifest entry to cache. | 3078 // Add manifest entry to cache. |
3075 cache->AddEntry(manifest_entry_url, | 3079 cache->AddEntry(manifest_entry_url, |
3076 AppCacheEntry(AppCacheEntry::MANIFEST, manifest_response_id)); | 3080 AppCacheEntry(AppCacheEntry::MANIFEST, manifest_response_id)); |
3077 | 3081 |
3078 // Specific tests that expect a newer time should set | 3082 // Specific tests that expect a newer time should set |
3079 // expect_full_update_time_newer_than_ which causes this | 3083 // expect_full_update_time_newer_than_ which causes this |
3080 // equality expectation to be ignored. | 3084 // equality expectation to be ignored. |
3081 expect_full_update_time_equal_to_ = cache->update_time(); | 3085 expect_full_update_time_equal_to_ = cache->update_time(); |
3082 | 3086 |
3083 return cache; | 3087 return cache; |
3084 } | 3088 } |
3085 | 3089 |
3086 AppCacheHost* MakeHost(int host_id, AppCacheFrontend* frontend) { | 3090 AppCacheHost* MakeHost(int host_id, AppCacheFrontend* frontend) { |
3087 AppCacheHost* host = new AppCacheHost(host_id, frontend, service_.get()); | 3091 AppCacheHost* host = new AppCacheHost(host_id, frontend, service_.get()); |
3088 hosts_.push_back(host); | 3092 hosts_.push_back(host); |
3089 return host; | 3093 return host; |
3090 } | 3094 } |
3091 | 3095 |
3092 AppCacheResponseInfo* MakeAppCacheResponseInfo( | 3096 AppCacheResponseInfo* MakeAppCacheResponseInfo( |
3093 const GURL& manifest_url, int64 response_id, | 3097 const GURL& manifest_url, |
| 3098 int64_t response_id, |
3094 const std::string& raw_headers) { | 3099 const std::string& raw_headers) { |
3095 net::HttpResponseInfo* http_info = new net::HttpResponseInfo(); | 3100 net::HttpResponseInfo* http_info = new net::HttpResponseInfo(); |
3096 http_info->headers = new net::HttpResponseHeaders(raw_headers); | 3101 http_info->headers = new net::HttpResponseHeaders(raw_headers); |
3097 scoped_refptr<AppCacheResponseInfo> info( | 3102 scoped_refptr<AppCacheResponseInfo> info( |
3098 new AppCacheResponseInfo(service_->storage(), manifest_url, | 3103 new AppCacheResponseInfo(service_->storage(), manifest_url, |
3099 response_id, http_info, 0)); | 3104 response_id, http_info, 0)); |
3100 response_infos_.push_back(info); | 3105 response_infos_.push_back(info); |
3101 return info.get(); | 3106 return info.get(); |
3102 } | 3107 } |
3103 | 3108 |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3165 | 3170 |
3166 // Check that all entries in the newest cache were stored. | 3171 // Check that all entries in the newest cache were stored. |
3167 const AppCache::EntryMap& entries = | 3172 const AppCache::EntryMap& entries = |
3168 group_->newest_complete_cache()->entries(); | 3173 group_->newest_complete_cache()->entries(); |
3169 for (AppCache::EntryMap::const_iterator it = entries.begin(); | 3174 for (AppCache::EntryMap::const_iterator it = entries.begin(); |
3170 it != entries.end(); ++it) { | 3175 it != entries.end(); ++it) { |
3171 EXPECT_NE(kAppCacheNoResponseId, it->second.response_id()); | 3176 EXPECT_NE(kAppCacheNoResponseId, it->second.response_id()); |
3172 | 3177 |
3173 // Check that any copied entries have the expected response id | 3178 // Check that any copied entries have the expected response id |
3174 // and that entries that are not copied have a different response id. | 3179 // and that entries that are not copied have a different response id. |
3175 std::map<GURL, int64>::iterator found = | 3180 std::map<GURL, int64_t>::iterator found = |
3176 expect_response_ids_.find(it->first); | 3181 expect_response_ids_.find(it->first); |
3177 if (found != expect_response_ids_.end()) { | 3182 if (found != expect_response_ids_.end()) { |
3178 EXPECT_EQ(found->second, it->second.response_id()); | 3183 EXPECT_EQ(found->second, it->second.response_id()); |
3179 } else if (expect_old_cache_) { | 3184 } else if (expect_old_cache_) { |
3180 AppCacheEntry* old_entry = expect_old_cache_->GetEntry(it->first); | 3185 AppCacheEntry* old_entry = expect_old_cache_->GetEntry(it->first); |
3181 if (old_entry) | 3186 if (old_entry) |
3182 EXPECT_NE(old_entry->response_id(), it->second.response_id()); | 3187 EXPECT_NE(old_entry->response_id(), it->second.response_id()); |
3183 } | 3188 } |
3184 } | 3189 } |
3185 } | 3190 } |
(...skipping 255 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3441 bool expect_eviction_; | 3446 bool expect_eviction_; |
3442 base::Time expect_full_update_time_newer_than_; | 3447 base::Time expect_full_update_time_newer_than_; |
3443 base::Time expect_full_update_time_equal_to_; | 3448 base::Time expect_full_update_time_equal_to_; |
3444 AppCache* expect_old_cache_; | 3449 AppCache* expect_old_cache_; |
3445 AppCache* expect_newest_cache_; | 3450 AppCache* expect_newest_cache_; |
3446 bool expect_non_null_update_time_; | 3451 bool expect_non_null_update_time_; |
3447 std::vector<MockFrontend*> frontends_; // to check expected events | 3452 std::vector<MockFrontend*> frontends_; // to check expected events |
3448 TestedManifest tested_manifest_; | 3453 TestedManifest tested_manifest_; |
3449 const char* tested_manifest_path_override_; | 3454 const char* tested_manifest_path_override_; |
3450 AppCache::EntryMap expect_extra_entries_; | 3455 AppCache::EntryMap expect_extra_entries_; |
3451 std::map<GURL, int64> expect_response_ids_; | 3456 std::map<GURL, int64_t> expect_response_ids_; |
3452 }; | 3457 }; |
3453 | 3458 |
3454 TEST_F(AppCacheUpdateJobTest, AlreadyChecking) { | 3459 TEST_F(AppCacheUpdateJobTest, AlreadyChecking) { |
3455 MockAppCacheService service; | 3460 MockAppCacheService service; |
3456 scoped_refptr<AppCacheGroup> group( | 3461 scoped_refptr<AppCacheGroup> group( |
3457 new AppCacheGroup(service.storage(), GURL("http://manifesturl.com"), | 3462 new AppCacheGroup(service.storage(), GURL("http://manifesturl.com"), |
3458 service.storage()->NewGroupId())); | 3463 service.storage()->NewGroupId())); |
3459 | 3464 |
3460 AppCacheUpdateJob update(&service, group.get()); | 3465 AppCacheUpdateJob update(&service, group.get()); |
3461 | 3466 |
(...skipping 259 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3721 | 3726 |
3722 TEST_F(AppCacheUpdateJobTest, CrossOriginHttpsSuccess) { | 3727 TEST_F(AppCacheUpdateJobTest, CrossOriginHttpsSuccess) { |
3723 RunTestOnIOThread(&AppCacheUpdateJobTest::CrossOriginHttpsSuccessTest); | 3728 RunTestOnIOThread(&AppCacheUpdateJobTest::CrossOriginHttpsSuccessTest); |
3724 } | 3729 } |
3725 | 3730 |
3726 TEST_F(AppCacheUpdateJobTest, CrossOriginHttpsDenied) { | 3731 TEST_F(AppCacheUpdateJobTest, CrossOriginHttpsDenied) { |
3727 RunTestOnIOThread(&AppCacheUpdateJobTest::CrossOriginHttpsDeniedTest); | 3732 RunTestOnIOThread(&AppCacheUpdateJobTest::CrossOriginHttpsDeniedTest); |
3728 } | 3733 } |
3729 | 3734 |
3730 } // namespace content | 3735 } // namespace content |
OLD | NEW |