| 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 "content/browser/appcache/appcache_update_job.h" | 5 #include "content/browser/appcache/appcache_update_job.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 #include <stdint.h> | 8 #include <stdint.h> |
| 9 | 9 |
| 10 #include <utility> | 10 #include <utility> |
| (...skipping 3029 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3040 | 3040 |
| 3041 void UpdateFinishedUnwound() { | 3041 void UpdateFinishedUnwound() { |
| 3042 EXPECT_EQ(AppCacheGroup::IDLE, group_->update_status()); | 3042 EXPECT_EQ(AppCacheGroup::IDLE, group_->update_status()); |
| 3043 EXPECT_TRUE(group_->update_job() == NULL); | 3043 EXPECT_TRUE(group_->update_job() == NULL); |
| 3044 if (do_checks_after_update_finished_) | 3044 if (do_checks_after_update_finished_) |
| 3045 VerifyExpectations(); | 3045 VerifyExpectations(); |
| 3046 | 3046 |
| 3047 // Clean up everything that was created on the IO thread. | 3047 // Clean up everything that was created on the IO thread. |
| 3048 protect_newest_cache_ = NULL; | 3048 protect_newest_cache_ = NULL; |
| 3049 group_ = NULL; | 3049 group_ = NULL; |
| 3050 base::STLDeleteContainerPointers(hosts_.begin(), hosts_.end()); | 3050 hosts_.clear(); |
| 3051 base::STLDeleteContainerPointers(frontends_.begin(), frontends_.end()); | 3051 frontends_.clear(); |
| 3052 response_infos_.clear(); | 3052 response_infos_.clear(); |
| 3053 service_.reset(NULL); | 3053 service_.reset(NULL); |
| 3054 | 3054 |
| 3055 event_->Signal(); | 3055 event_->Signal(); |
| 3056 } | 3056 } |
| 3057 | 3057 |
| 3058 void MakeService() { | 3058 void MakeService() { |
| 3059 service_.reset(new MockAppCacheService()); | 3059 service_.reset(new MockAppCacheService()); |
| 3060 service_->set_request_context(io_thread_->request_context()); | 3060 service_->set_request_context(io_thread_->request_context()); |
| 3061 } | 3061 } |
| (...skipping 18 matching lines...) Expand all Loading... |
| 3080 | 3080 |
| 3081 // Specific tests that expect a newer time should set | 3081 // Specific tests that expect a newer time should set |
| 3082 // expect_full_update_time_newer_than_ which causes this | 3082 // expect_full_update_time_newer_than_ which causes this |
| 3083 // equality expectation to be ignored. | 3083 // equality expectation to be ignored. |
| 3084 expect_full_update_time_equal_to_ = cache->update_time(); | 3084 expect_full_update_time_equal_to_ = cache->update_time(); |
| 3085 | 3085 |
| 3086 return cache; | 3086 return cache; |
| 3087 } | 3087 } |
| 3088 | 3088 |
| 3089 AppCacheHost* MakeHost(int host_id, AppCacheFrontend* frontend) { | 3089 AppCacheHost* MakeHost(int host_id, AppCacheFrontend* frontend) { |
| 3090 AppCacheHost* host = new AppCacheHost(host_id, frontend, service_.get()); | 3090 hosts_.push_back( |
| 3091 hosts_.push_back(host); | 3091 base::MakeUnique<AppCacheHost>(host_id, frontend, service_.get())); |
| 3092 return host; | 3092 return hosts_.back().get(); |
| 3093 } | 3093 } |
| 3094 | 3094 |
| 3095 AppCacheResponseInfo* MakeAppCacheResponseInfo( | 3095 AppCacheResponseInfo* MakeAppCacheResponseInfo( |
| 3096 const GURL& manifest_url, | 3096 const GURL& manifest_url, |
| 3097 int64_t response_id, | 3097 int64_t response_id, |
| 3098 const std::string& raw_headers) { | 3098 const std::string& raw_headers) { |
| 3099 net::HttpResponseInfo* http_info = new net::HttpResponseInfo(); | 3099 net::HttpResponseInfo* http_info = new net::HttpResponseInfo(); |
| 3100 http_info->headers = new net::HttpResponseHeaders(raw_headers); | 3100 http_info->headers = new net::HttpResponseHeaders(raw_headers); |
| 3101 scoped_refptr<AppCacheResponseInfo> info( | 3101 scoped_refptr<AppCacheResponseInfo> info( |
| 3102 new AppCacheResponseInfo(service_->storage(), manifest_url, | 3102 new AppCacheResponseInfo(service_->storage(), manifest_url, |
| 3103 response_id, http_info, 0)); | 3103 response_id, http_info, 0)); |
| 3104 response_infos_.push_back(info); | 3104 response_infos_.push_back(info); |
| 3105 return info.get(); | 3105 return info.get(); |
| 3106 } | 3106 } |
| 3107 | 3107 |
| 3108 MockFrontend* MakeMockFrontend() { | 3108 MockFrontend* MakeMockFrontend() { |
| 3109 MockFrontend* frontend = new MockFrontend(); | 3109 frontends_.push_back(base::MakeUnique<MockFrontend>()); |
| 3110 frontends_.push_back(frontend); | 3110 return frontends_.back().get(); |
| 3111 return frontend; | |
| 3112 } | 3111 } |
| 3113 | 3112 |
| 3114 // Verifies conditions about the group and notifications after an update | 3113 // Verifies conditions about the group and notifications after an update |
| 3115 // has finished. Cannot verify update job internals as update is deleted. | 3114 // has finished. Cannot verify update job internals as update is deleted. |
| 3116 void VerifyExpectations() { | 3115 void VerifyExpectations() { |
| 3117 RetryRequestTestJob::Verify(); | 3116 RetryRequestTestJob::Verify(); |
| 3118 HttpHeadersRequestTestJob::Verify(); | 3117 HttpHeadersRequestTestJob::Verify(); |
| 3119 | 3118 |
| 3120 EXPECT_EQ(expect_group_obsolete_, group_->is_obsolete()); | 3119 EXPECT_EQ(expect_group_obsolete_, group_->is_obsolete()); |
| 3121 EXPECT_EQ(expect_group_is_being_deleted_ || expect_eviction_, | 3120 EXPECT_EQ(expect_group_is_being_deleted_ || expect_eviction_, |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3186 EXPECT_NE(old_entry->response_id(), it->second.response_id()); | 3185 EXPECT_NE(old_entry->response_id(), it->second.response_id()); |
| 3187 } | 3186 } |
| 3188 } | 3187 } |
| 3189 } | 3188 } |
| 3190 } else { | 3189 } else { |
| 3191 EXPECT_TRUE(group_->newest_complete_cache() == NULL); | 3190 EXPECT_TRUE(group_->newest_complete_cache() == NULL); |
| 3192 } | 3191 } |
| 3193 | 3192 |
| 3194 // Check expected events. | 3193 // Check expected events. |
| 3195 for (size_t i = 0; i < frontends_.size(); ++i) { | 3194 for (size_t i = 0; i < frontends_.size(); ++i) { |
| 3196 MockFrontend* frontend = frontends_[i]; | 3195 MockFrontend* frontend = frontends_[i].get(); |
| 3197 | 3196 |
| 3198 MockFrontend::RaisedEvents& expected_events = frontend->expected_events_; | 3197 MockFrontend::RaisedEvents& expected_events = frontend->expected_events_; |
| 3199 MockFrontend::RaisedEvents& actual_events = frontend->raised_events_; | 3198 MockFrontend::RaisedEvents& actual_events = frontend->raised_events_; |
| 3200 EXPECT_EQ(expected_events.size(), actual_events.size()); | 3199 EXPECT_EQ(expected_events.size(), actual_events.size()); |
| 3201 | 3200 |
| 3202 // Check each expected event. | 3201 // Check each expected event. |
| 3203 for (size_t j = 0; | 3202 for (size_t j = 0; |
| 3204 j < expected_events.size() && j < actual_events.size(); ++j) { | 3203 j < expected_events.size() && j < actual_events.size(); ++j) { |
| 3205 EXPECT_EQ(expected_events[j].second, actual_events[j].second); | 3204 EXPECT_EQ(expected_events[j].second, actual_events[j].second); |
| 3206 | 3205 |
| (...skipping 216 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3423 | 3422 |
| 3424 std::unique_ptr<MockAppCacheService> service_; | 3423 std::unique_ptr<MockAppCacheService> service_; |
| 3425 scoped_refptr<AppCacheGroup> group_; | 3424 scoped_refptr<AppCacheGroup> group_; |
| 3426 scoped_refptr<AppCache> protect_newest_cache_; | 3425 scoped_refptr<AppCache> protect_newest_cache_; |
| 3427 std::unique_ptr<base::WaitableEvent> event_; | 3426 std::unique_ptr<base::WaitableEvent> event_; |
| 3428 | 3427 |
| 3429 std::unique_ptr<AppCacheResponseWriter> response_writer_; | 3428 std::unique_ptr<AppCacheResponseWriter> response_writer_; |
| 3430 | 3429 |
| 3431 // Hosts used by an async test that need to live until update job finishes. | 3430 // Hosts used by an async test that need to live until update job finishes. |
| 3432 // Otherwise, test can put host on the stack instead of here. | 3431 // Otherwise, test can put host on the stack instead of here. |
| 3433 std::vector<AppCacheHost*> hosts_; | 3432 std::vector<std::unique_ptr<AppCacheHost>> hosts_; |
| 3434 | 3433 |
| 3435 // Response infos used by an async test that need to live until update job | 3434 // Response infos used by an async test that need to live until update job |
| 3436 // finishes. | 3435 // finishes. |
| 3437 std::vector<scoped_refptr<AppCacheResponseInfo> > response_infos_; | 3436 std::vector<scoped_refptr<AppCacheResponseInfo> > response_infos_; |
| 3438 | 3437 |
| 3439 // Flag indicating if test cares to verify the update after update finishes. | 3438 // Flag indicating if test cares to verify the update after update finishes. |
| 3440 bool do_checks_after_update_finished_; | 3439 bool do_checks_after_update_finished_; |
| 3441 bool expect_group_obsolete_; | 3440 bool expect_group_obsolete_; |
| 3442 bool expect_group_has_cache_; | 3441 bool expect_group_has_cache_; |
| 3443 bool expect_group_is_being_deleted_; | 3442 bool expect_group_is_being_deleted_; |
| 3444 bool expect_evictable_error_; | 3443 bool expect_evictable_error_; |
| 3445 bool expect_eviction_; | 3444 bool expect_eviction_; |
| 3446 base::Time expect_full_update_time_newer_than_; | 3445 base::Time expect_full_update_time_newer_than_; |
| 3447 base::Time expect_full_update_time_equal_to_; | 3446 base::Time expect_full_update_time_equal_to_; |
| 3448 AppCache* expect_old_cache_; | 3447 AppCache* expect_old_cache_; |
| 3449 AppCache* expect_newest_cache_; | 3448 AppCache* expect_newest_cache_; |
| 3450 bool expect_non_null_update_time_; | 3449 bool expect_non_null_update_time_; |
| 3451 std::vector<MockFrontend*> frontends_; // to check expected events | 3450 std::vector<std::unique_ptr<MockFrontend>> |
| 3451 frontends_; // to check expected events |
| 3452 TestedManifest tested_manifest_; | 3452 TestedManifest tested_manifest_; |
| 3453 const char* tested_manifest_path_override_; | 3453 const char* tested_manifest_path_override_; |
| 3454 AppCache::EntryMap expect_extra_entries_; | 3454 AppCache::EntryMap expect_extra_entries_; |
| 3455 std::map<GURL, int64_t> expect_response_ids_; | 3455 std::map<GURL, int64_t> expect_response_ids_; |
| 3456 }; | 3456 }; |
| 3457 | 3457 |
| 3458 TEST_F(AppCacheUpdateJobTest, AlreadyChecking) { | 3458 TEST_F(AppCacheUpdateJobTest, AlreadyChecking) { |
| 3459 MockAppCacheService service; | 3459 MockAppCacheService service; |
| 3460 scoped_refptr<AppCacheGroup> group( | 3460 scoped_refptr<AppCacheGroup> group( |
| 3461 new AppCacheGroup(service.storage(), GURL("http://manifesturl.com"), | 3461 new AppCacheGroup(service.storage(), GURL("http://manifesturl.com"), |
| (...skipping 263 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3725 | 3725 |
| 3726 TEST_F(AppCacheUpdateJobTest, CrossOriginHttpsSuccess) { | 3726 TEST_F(AppCacheUpdateJobTest, CrossOriginHttpsSuccess) { |
| 3727 RunTestOnIOThread(&AppCacheUpdateJobTest::CrossOriginHttpsSuccessTest); | 3727 RunTestOnIOThread(&AppCacheUpdateJobTest::CrossOriginHttpsSuccessTest); |
| 3728 } | 3728 } |
| 3729 | 3729 |
| 3730 TEST_F(AppCacheUpdateJobTest, CrossOriginHttpsDenied) { | 3730 TEST_F(AppCacheUpdateJobTest, CrossOriginHttpsDenied) { |
| 3731 RunTestOnIOThread(&AppCacheUpdateJobTest::CrossOriginHttpsDeniedTest); | 3731 RunTestOnIOThread(&AppCacheUpdateJobTest::CrossOriginHttpsDeniedTest); |
| 3732 } | 3732 } |
| 3733 | 3733 |
| 3734 } // namespace content | 3734 } // namespace content |
| OLD | NEW |