Chromium Code Reviews| 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 "testing/gtest/include/gtest/gtest.h" | 5 #include "testing/gtest/include/gtest/gtest.h" |
| 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/stl_util.h" | 9 #include "base/stl_util.h" |
| 10 #include "base/threading/thread.h" | 10 #include "base/threading/thread.h" |
| (...skipping 553 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 564 scoped_refptr<net::URLRequestContext> request_context_; | 564 scoped_refptr<net::URLRequestContext> request_context_; |
| 565 }; | 565 }; |
| 566 | 566 |
| 567 class AppCacheUpdateJobTest : public testing::Test, | 567 class AppCacheUpdateJobTest : public testing::Test, |
| 568 public AppCacheGroup::UpdateObserver { | 568 public AppCacheGroup::UpdateObserver { |
| 569 public: | 569 public: |
| 570 AppCacheUpdateJobTest() | 570 AppCacheUpdateJobTest() |
| 571 : do_checks_after_update_finished_(false), | 571 : do_checks_after_update_finished_(false), |
| 572 expect_group_obsolete_(false), | 572 expect_group_obsolete_(false), |
| 573 expect_group_has_cache_(false), | 573 expect_group_has_cache_(false), |
| 574 expect_group_is_being_deleted_(false), | |
| 574 expect_old_cache_(NULL), | 575 expect_old_cache_(NULL), |
| 575 expect_newest_cache_(NULL), | 576 expect_newest_cache_(NULL), |
| 576 expect_non_null_update_time_(false), | 577 expect_non_null_update_time_(false), |
| 577 tested_manifest_(NONE), | 578 tested_manifest_(NONE), |
| 578 tested_manifest_path_override_(NULL) { | 579 tested_manifest_path_override_(NULL) { |
| 579 io_thread_.reset(new IOThread("AppCacheUpdateJob IO test thread")); | 580 io_thread_.reset(new IOThread("AppCacheUpdateJob IO test thread")); |
| 580 base::Thread::Options options(MessageLoop::TYPE_IO, 0); | 581 base::Thread::Options options(MessageLoop::TYPE_IO, 0); |
| 581 io_thread_->StartWithOptions(options); | 582 io_thread_->StartWithOptions(options); |
| 582 } | 583 } |
| 583 | 584 |
| (...skipping 398 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 982 scoped_refptr<net::StringIOBuffer> io_buffer( | 983 scoped_refptr<net::StringIOBuffer> io_buffer( |
| 983 new net::StringIOBuffer(seed_data)); | 984 new net::StringIOBuffer(seed_data)); |
| 984 response_writer_->WriteData( | 985 response_writer_->WriteData( |
| 985 io_buffer, seed_data.length(), | 986 io_buffer, seed_data.length(), |
| 986 base::Bind(&AppCacheUpdateJobTest::StartUpdateAfterSeedingStorageData, | 987 base::Bind(&AppCacheUpdateJobTest::StartUpdateAfterSeedingStorageData, |
| 987 base::Unretained(this))); | 988 base::Unretained(this))); |
| 988 | 989 |
| 989 // Start update after data write completes asynchronously. | 990 // Start update after data write completes asynchronously. |
| 990 } | 991 } |
| 991 | 992 |
| 993 void UpgradeMissingManifestEntryDoesntCrash() { | |
|
jennb
2012/05/03 18:43:31
nit: s/Doesnt/DoesNot
michaeln
2012/05/03 19:03:25
Done, renamed to Bug95101Test()
| |
| 994 ASSERT_EQ(MessageLoop::TYPE_IO, MessageLoop::current()->type()); | |
| 995 | |
| 996 MakeService(); | |
| 997 group_ = new AppCacheGroup( | |
| 998 service_.get(), MockHttpServer::GetMockUrl("files/empty-manifest"), | |
| 999 service_->storage()->NewGroupId()); | |
| 1000 AppCacheUpdateJob* update = new AppCacheUpdateJob(service_.get(), group_); | |
| 1001 group_->update_job_ = update; | |
| 1002 | |
| 1003 // Create a malformed cache with a missing manifest entry. | |
| 1004 GURL wrong_manifest_url = | |
| 1005 MockHttpServer::GetMockUrl("files/missing-mime-manifest"); | |
| 1006 AppCache* cache = MakeCacheForGroup(1, wrong_manifest_url, 111); | |
| 1007 MockFrontend* frontend = MakeMockFrontend(); | |
| 1008 AppCacheHost* host = MakeHost(1, frontend); | |
| 1009 host->AssociateCompleteCache(cache); | |
| 1010 | |
| 1011 update->StartUpdate(NULL, GURL()); | |
| 1012 EXPECT_TRUE(update->manifest_fetcher_ != NULL); | |
| 1013 | |
| 1014 // Set up checks for when update job finishes. | |
| 1015 do_checks_after_update_finished_ = true; | |
| 1016 expect_group_is_being_deleted_ = true; | |
| 1017 expect_group_has_cache_ = true; | |
| 1018 expect_newest_cache_ = cache; // newest cache unaffected by update | |
| 1019 MockFrontend::HostIds id(1, host->host_id()); | |
| 1020 frontend->AddExpectedEvent(id, CHECKING_EVENT); | |
| 1021 frontend->AddExpectedEvent(id, ERROR_EVENT); | |
| 1022 frontend->expected_error_message_ = | |
| 1023 "Manifest entry not found in existing cache"; | |
| 1024 WaitForUpdateToFinish(); | |
| 1025 } | |
| 1026 | |
| 992 void StartUpdateAfterSeedingStorageData(int result) { | 1027 void StartUpdateAfterSeedingStorageData(int result) { |
| 993 ASSERT_GT(result, 0); | 1028 ASSERT_GT(result, 0); |
| 994 response_writer_.reset(); | 1029 response_writer_.reset(); |
| 995 | 1030 |
| 996 AppCacheUpdateJob* update = group_->update_job_; | 1031 AppCacheUpdateJob* update = group_->update_job_; |
| 997 update->StartUpdate(NULL, GURL()); | 1032 update->StartUpdate(NULL, GURL()); |
| 998 EXPECT_TRUE(update->manifest_fetcher_ != NULL); | 1033 EXPECT_TRUE(update->manifest_fetcher_ != NULL); |
| 999 | 1034 |
| 1000 WaitForUpdateToFinish(); | 1035 WaitForUpdateToFinish(); |
| 1001 } | 1036 } |
| (...skipping 1893 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2895 | 2930 |
| 2896 event_->Signal(); | 2931 event_->Signal(); |
| 2897 } | 2932 } |
| 2898 | 2933 |
| 2899 void MakeService() { | 2934 void MakeService() { |
| 2900 service_.reset(new MockAppCacheService()); | 2935 service_.reset(new MockAppCacheService()); |
| 2901 service_->set_request_context(io_thread_->request_context()); | 2936 service_->set_request_context(io_thread_->request_context()); |
| 2902 } | 2937 } |
| 2903 | 2938 |
| 2904 AppCache* MakeCacheForGroup(int64 cache_id, int64 manifest_response_id) { | 2939 AppCache* MakeCacheForGroup(int64 cache_id, int64 manifest_response_id) { |
| 2940 return MakeCacheForGroup(cache_id, group_->manifest_url(), | |
| 2941 manifest_response_id); | |
| 2942 } | |
| 2943 | |
| 2944 AppCache* MakeCacheForGroup(int64 cache_id, const GURL& manifest_entry_url, | |
| 2945 int64 manifest_response_id) { | |
| 2905 AppCache* cache = new AppCache(service_.get(), cache_id); | 2946 AppCache* cache = new AppCache(service_.get(), cache_id); |
| 2906 cache->set_complete(true); | 2947 cache->set_complete(true); |
| 2907 cache->set_update_time(base::Time::Now()); | 2948 cache->set_update_time(base::Time::Now()); |
| 2908 group_->AddCache(cache); | 2949 group_->AddCache(cache); |
| 2909 | 2950 |
| 2910 // Add manifest entry to cache. | 2951 // Add manifest entry to cache. |
| 2911 cache->AddEntry(group_->manifest_url(), | 2952 cache->AddEntry(manifest_entry_url, |
| 2912 AppCacheEntry(AppCacheEntry::MANIFEST, manifest_response_id)); | 2953 AppCacheEntry(AppCacheEntry::MANIFEST, manifest_response_id)); |
| 2913 | 2954 |
| 2914 return cache; | 2955 return cache; |
| 2915 } | 2956 } |
| 2916 | 2957 |
| 2917 AppCacheHost* MakeHost(int host_id, AppCacheFrontend* frontend) { | 2958 AppCacheHost* MakeHost(int host_id, AppCacheFrontend* frontend) { |
| 2918 AppCacheHost* host = new AppCacheHost(host_id, frontend, service_.get()); | 2959 AppCacheHost* host = new AppCacheHost(host_id, frontend, service_.get()); |
| 2919 hosts_.push_back(host); | 2960 hosts_.push_back(host); |
| 2920 return host; | 2961 return host; |
| 2921 } | 2962 } |
| (...skipping 16 matching lines...) Expand all Loading... | |
| 2938 return frontend; | 2979 return frontend; |
| 2939 } | 2980 } |
| 2940 | 2981 |
| 2941 // Verifies conditions about the group and notifications after an update | 2982 // Verifies conditions about the group and notifications after an update |
| 2942 // has finished. Cannot verify update job internals as update is deleted. | 2983 // has finished. Cannot verify update job internals as update is deleted. |
| 2943 void VerifyExpectations() { | 2984 void VerifyExpectations() { |
| 2944 RetryRequestTestJob::Verify(); | 2985 RetryRequestTestJob::Verify(); |
| 2945 HttpHeadersRequestTestJob::Verify(); | 2986 HttpHeadersRequestTestJob::Verify(); |
| 2946 | 2987 |
| 2947 EXPECT_EQ(expect_group_obsolete_, group_->is_obsolete()); | 2988 EXPECT_EQ(expect_group_obsolete_, group_->is_obsolete()); |
| 2989 EXPECT_EQ(expect_group_is_being_deleted_, group_->is_being_deleted()); | |
| 2948 | 2990 |
| 2949 if (expect_group_has_cache_) { | 2991 if (expect_group_has_cache_) { |
| 2950 EXPECT_TRUE(group_->newest_complete_cache() != NULL); | 2992 EXPECT_TRUE(group_->newest_complete_cache() != NULL); |
| 2951 | 2993 |
| 2952 if (expect_non_null_update_time_) | 2994 if (expect_non_null_update_time_) |
| 2953 EXPECT_TRUE(!group_->newest_complete_cache()->update_time().is_null()); | 2995 EXPECT_TRUE(!group_->newest_complete_cache()->update_time().is_null()); |
| 2954 | 2996 |
| 2955 if (expect_old_cache_) { | 2997 if (expect_old_cache_) { |
| 2956 EXPECT_NE(expect_old_cache_, group_->newest_complete_cache()); | 2998 EXPECT_NE(expect_old_cache_, group_->newest_complete_cache()); |
| 2957 EXPECT_TRUE(group_->old_caches().end() != | 2999 EXPECT_TRUE(group_->old_caches().end() != |
| (...skipping 278 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 3236 std::vector<AppCacheHost*> hosts_; | 3278 std::vector<AppCacheHost*> hosts_; |
| 3237 | 3279 |
| 3238 // Response infos used by an async test that need to live until update job | 3280 // Response infos used by an async test that need to live until update job |
| 3239 // finishes. | 3281 // finishes. |
| 3240 std::vector<scoped_refptr<AppCacheResponseInfo> > response_infos_; | 3282 std::vector<scoped_refptr<AppCacheResponseInfo> > response_infos_; |
| 3241 | 3283 |
| 3242 // Flag indicating if test cares to verify the update after update finishes. | 3284 // Flag indicating if test cares to verify the update after update finishes. |
| 3243 bool do_checks_after_update_finished_; | 3285 bool do_checks_after_update_finished_; |
| 3244 bool expect_group_obsolete_; | 3286 bool expect_group_obsolete_; |
| 3245 bool expect_group_has_cache_; | 3287 bool expect_group_has_cache_; |
| 3288 bool expect_group_is_being_deleted_; | |
| 3246 AppCache* expect_old_cache_; | 3289 AppCache* expect_old_cache_; |
| 3247 AppCache* expect_newest_cache_; | 3290 AppCache* expect_newest_cache_; |
| 3248 bool expect_non_null_update_time_; | 3291 bool expect_non_null_update_time_; |
| 3249 std::vector<MockFrontend*> frontends_; // to check expected events | 3292 std::vector<MockFrontend*> frontends_; // to check expected events |
| 3250 TestedManifest tested_manifest_; | 3293 TestedManifest tested_manifest_; |
| 3251 const char* tested_manifest_path_override_; | 3294 const char* tested_manifest_path_override_; |
| 3252 AppCache::EntryMap expect_extra_entries_; | 3295 AppCache::EntryMap expect_extra_entries_; |
| 3253 std::map<GURL, int64> expect_response_ids_; | 3296 std::map<GURL, int64> expect_response_ids_; |
| 3254 }; | 3297 }; |
| 3255 | 3298 |
| (...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 3352 } | 3395 } |
| 3353 | 3396 |
| 3354 TEST_F(AppCacheUpdateJobTest, UpgradeNotModified) { | 3397 TEST_F(AppCacheUpdateJobTest, UpgradeNotModified) { |
| 3355 RunTestOnIOThread(&AppCacheUpdateJobTest::UpgradeNotModifiedTest); | 3398 RunTestOnIOThread(&AppCacheUpdateJobTest::UpgradeNotModifiedTest); |
| 3356 } | 3399 } |
| 3357 | 3400 |
| 3358 TEST_F(AppCacheUpdateJobTest, UpgradeManifestDataUnchanged) { | 3401 TEST_F(AppCacheUpdateJobTest, UpgradeManifestDataUnchanged) { |
| 3359 RunTestOnIOThread(&AppCacheUpdateJobTest::UpgradeManifestDataUnchangedTest); | 3402 RunTestOnIOThread(&AppCacheUpdateJobTest::UpgradeManifestDataUnchangedTest); |
| 3360 } | 3403 } |
| 3361 | 3404 |
| 3405 TEST_F(AppCacheUpdateJobTest, UpgradeMissingManifestEntryDoesntCrash) { | |
| 3406 RunTestOnIOThread( | |
| 3407 &AppCacheUpdateJobTest::UpgradeMissingManifestEntryDoesntCrash); | |
| 3408 } | |
| 3409 | |
| 3362 TEST_F(AppCacheUpdateJobTest, BasicCacheAttemptSuccess) { | 3410 TEST_F(AppCacheUpdateJobTest, BasicCacheAttemptSuccess) { |
| 3363 RunTestOnIOThread(&AppCacheUpdateJobTest::BasicCacheAttemptSuccessTest); | 3411 RunTestOnIOThread(&AppCacheUpdateJobTest::BasicCacheAttemptSuccessTest); |
| 3364 } | 3412 } |
| 3365 | 3413 |
| 3366 TEST_F(AppCacheUpdateJobTest, DownloadInterceptEntriesTest) { | 3414 TEST_F(AppCacheUpdateJobTest, DownloadInterceptEntriesTest) { |
| 3367 RunTestOnIOThread(&AppCacheUpdateJobTest::DownloadInterceptEntriesTest); | 3415 RunTestOnIOThread(&AppCacheUpdateJobTest::DownloadInterceptEntriesTest); |
| 3368 } | 3416 } |
| 3369 | 3417 |
| 3370 TEST_F(AppCacheUpdateJobTest, BasicUpgradeSuccess) { | 3418 TEST_F(AppCacheUpdateJobTest, BasicUpgradeSuccess) { |
| 3371 RunTestOnIOThread(&AppCacheUpdateJobTest::BasicUpgradeSuccessTest); | 3419 RunTestOnIOThread(&AppCacheUpdateJobTest::BasicUpgradeSuccessTest); |
| (...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 3519 | 3567 |
| 3520 TEST_F(AppCacheUpdateJobTest, CrossOriginHttpsSuccess) { | 3568 TEST_F(AppCacheUpdateJobTest, CrossOriginHttpsSuccess) { |
| 3521 RunTestOnIOThread(&AppCacheUpdateJobTest::CrossOriginHttpsSuccessTest); | 3569 RunTestOnIOThread(&AppCacheUpdateJobTest::CrossOriginHttpsSuccessTest); |
| 3522 } | 3570 } |
| 3523 | 3571 |
| 3524 TEST_F(AppCacheUpdateJobTest, CrossOriginHttpsDenied) { | 3572 TEST_F(AppCacheUpdateJobTest, CrossOriginHttpsDenied) { |
| 3525 RunTestOnIOThread(&AppCacheUpdateJobTest::CrossOriginHttpsDeniedTest); | 3573 RunTestOnIOThread(&AppCacheUpdateJobTest::CrossOriginHttpsDeniedTest); |
| 3526 } | 3574 } |
| 3527 | 3575 |
| 3528 } // namespace appcache | 3576 } // namespace appcache |
| OLD | NEW |