Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(283)

Side by Side Diff: webkit/appcache/appcache_update_job_unittest.cc

Issue 10207020: Workaround for a crashing appcache bug seen on the crash servers (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Created 8 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « webkit/appcache/appcache_update_job.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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
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 // See http://code.google.com/p/chromium/issues/detail?id=95101
994 void Bug95101Test() {
995 ASSERT_EQ(MessageLoop::TYPE_IO, MessageLoop::current()->type());
996
997 MakeService();
998 group_ = new AppCacheGroup(
999 service_.get(), MockHttpServer::GetMockUrl("files/empty-manifest"),
1000 service_->storage()->NewGroupId());
1001 AppCacheUpdateJob* update = new AppCacheUpdateJob(service_.get(), group_);
1002 group_->update_job_ = update;
1003
1004 // Create a malformed cache with a missing manifest entry.
1005 GURL wrong_manifest_url =
1006 MockHttpServer::GetMockUrl("files/missing-mime-manifest");
1007 AppCache* cache = MakeCacheForGroup(1, wrong_manifest_url, 111);
1008 MockFrontend* frontend = MakeMockFrontend();
1009 AppCacheHost* host = MakeHost(1, frontend);
1010 host->AssociateCompleteCache(cache);
1011
1012 update->StartUpdate(NULL, GURL());
1013 EXPECT_TRUE(update->manifest_fetcher_ != NULL);
1014
1015 // Set up checks for when update job finishes.
1016 do_checks_after_update_finished_ = true;
1017 expect_group_is_being_deleted_ = true;
1018 expect_group_has_cache_ = true;
1019 expect_newest_cache_ = cache; // newest cache unaffected by update
1020 MockFrontend::HostIds id(1, host->host_id());
1021 frontend->AddExpectedEvent(id, CHECKING_EVENT);
1022 frontend->AddExpectedEvent(id, ERROR_EVENT);
1023 frontend->expected_error_message_ =
1024 "Manifest entry not found in existing cache";
1025 WaitForUpdateToFinish();
1026 }
1027
992 void StartUpdateAfterSeedingStorageData(int result) { 1028 void StartUpdateAfterSeedingStorageData(int result) {
993 ASSERT_GT(result, 0); 1029 ASSERT_GT(result, 0);
994 response_writer_.reset(); 1030 response_writer_.reset();
995 1031
996 AppCacheUpdateJob* update = group_->update_job_; 1032 AppCacheUpdateJob* update = group_->update_job_;
997 update->StartUpdate(NULL, GURL()); 1033 update->StartUpdate(NULL, GURL());
998 EXPECT_TRUE(update->manifest_fetcher_ != NULL); 1034 EXPECT_TRUE(update->manifest_fetcher_ != NULL);
999 1035
1000 WaitForUpdateToFinish(); 1036 WaitForUpdateToFinish();
1001 } 1037 }
(...skipping 1893 matching lines...) Expand 10 before | Expand all | Expand 10 after
2895 2931
2896 event_->Signal(); 2932 event_->Signal();
2897 } 2933 }
2898 2934
2899 void MakeService() { 2935 void MakeService() {
2900 service_.reset(new MockAppCacheService()); 2936 service_.reset(new MockAppCacheService());
2901 service_->set_request_context(io_thread_->request_context()); 2937 service_->set_request_context(io_thread_->request_context());
2902 } 2938 }
2903 2939
2904 AppCache* MakeCacheForGroup(int64 cache_id, int64 manifest_response_id) { 2940 AppCache* MakeCacheForGroup(int64 cache_id, int64 manifest_response_id) {
2941 return MakeCacheForGroup(cache_id, group_->manifest_url(),
2942 manifest_response_id);
2943 }
2944
2945 AppCache* MakeCacheForGroup(int64 cache_id, const GURL& manifest_entry_url,
2946 int64 manifest_response_id) {
2905 AppCache* cache = new AppCache(service_.get(), cache_id); 2947 AppCache* cache = new AppCache(service_.get(), cache_id);
2906 cache->set_complete(true); 2948 cache->set_complete(true);
2907 cache->set_update_time(base::Time::Now()); 2949 cache->set_update_time(base::Time::Now());
2908 group_->AddCache(cache); 2950 group_->AddCache(cache);
2909 2951
2910 // Add manifest entry to cache. 2952 // Add manifest entry to cache.
2911 cache->AddEntry(group_->manifest_url(), 2953 cache->AddEntry(manifest_entry_url,
2912 AppCacheEntry(AppCacheEntry::MANIFEST, manifest_response_id)); 2954 AppCacheEntry(AppCacheEntry::MANIFEST, manifest_response_id));
2913 2955
2914 return cache; 2956 return cache;
2915 } 2957 }
2916 2958
2917 AppCacheHost* MakeHost(int host_id, AppCacheFrontend* frontend) { 2959 AppCacheHost* MakeHost(int host_id, AppCacheFrontend* frontend) {
2918 AppCacheHost* host = new AppCacheHost(host_id, frontend, service_.get()); 2960 AppCacheHost* host = new AppCacheHost(host_id, frontend, service_.get());
2919 hosts_.push_back(host); 2961 hosts_.push_back(host);
2920 return host; 2962 return host;
2921 } 2963 }
(...skipping 16 matching lines...) Expand all
2938 return frontend; 2980 return frontend;
2939 } 2981 }
2940 2982
2941 // Verifies conditions about the group and notifications after an update 2983 // Verifies conditions about the group and notifications after an update
2942 // has finished. Cannot verify update job internals as update is deleted. 2984 // has finished. Cannot verify update job internals as update is deleted.
2943 void VerifyExpectations() { 2985 void VerifyExpectations() {
2944 RetryRequestTestJob::Verify(); 2986 RetryRequestTestJob::Verify();
2945 HttpHeadersRequestTestJob::Verify(); 2987 HttpHeadersRequestTestJob::Verify();
2946 2988
2947 EXPECT_EQ(expect_group_obsolete_, group_->is_obsolete()); 2989 EXPECT_EQ(expect_group_obsolete_, group_->is_obsolete());
2990 EXPECT_EQ(expect_group_is_being_deleted_, group_->is_being_deleted());
2948 2991
2949 if (expect_group_has_cache_) { 2992 if (expect_group_has_cache_) {
2950 EXPECT_TRUE(group_->newest_complete_cache() != NULL); 2993 EXPECT_TRUE(group_->newest_complete_cache() != NULL);
2951 2994
2952 if (expect_non_null_update_time_) 2995 if (expect_non_null_update_time_)
2953 EXPECT_TRUE(!group_->newest_complete_cache()->update_time().is_null()); 2996 EXPECT_TRUE(!group_->newest_complete_cache()->update_time().is_null());
2954 2997
2955 if (expect_old_cache_) { 2998 if (expect_old_cache_) {
2956 EXPECT_NE(expect_old_cache_, group_->newest_complete_cache()); 2999 EXPECT_NE(expect_old_cache_, group_->newest_complete_cache());
2957 EXPECT_TRUE(group_->old_caches().end() != 3000 EXPECT_TRUE(group_->old_caches().end() !=
(...skipping 278 matching lines...) Expand 10 before | Expand all | Expand 10 after
3236 std::vector<AppCacheHost*> hosts_; 3279 std::vector<AppCacheHost*> hosts_;
3237 3280
3238 // Response infos used by an async test that need to live until update job 3281 // Response infos used by an async test that need to live until update job
3239 // finishes. 3282 // finishes.
3240 std::vector<scoped_refptr<AppCacheResponseInfo> > response_infos_; 3283 std::vector<scoped_refptr<AppCacheResponseInfo> > response_infos_;
3241 3284
3242 // Flag indicating if test cares to verify the update after update finishes. 3285 // Flag indicating if test cares to verify the update after update finishes.
3243 bool do_checks_after_update_finished_; 3286 bool do_checks_after_update_finished_;
3244 bool expect_group_obsolete_; 3287 bool expect_group_obsolete_;
3245 bool expect_group_has_cache_; 3288 bool expect_group_has_cache_;
3289 bool expect_group_is_being_deleted_;
3246 AppCache* expect_old_cache_; 3290 AppCache* expect_old_cache_;
3247 AppCache* expect_newest_cache_; 3291 AppCache* expect_newest_cache_;
3248 bool expect_non_null_update_time_; 3292 bool expect_non_null_update_time_;
3249 std::vector<MockFrontend*> frontends_; // to check expected events 3293 std::vector<MockFrontend*> frontends_; // to check expected events
3250 TestedManifest tested_manifest_; 3294 TestedManifest tested_manifest_;
3251 const char* tested_manifest_path_override_; 3295 const char* tested_manifest_path_override_;
3252 AppCache::EntryMap expect_extra_entries_; 3296 AppCache::EntryMap expect_extra_entries_;
3253 std::map<GURL, int64> expect_response_ids_; 3297 std::map<GURL, int64> expect_response_ids_;
3254 }; 3298 };
3255 3299
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after
3352 } 3396 }
3353 3397
3354 TEST_F(AppCacheUpdateJobTest, UpgradeNotModified) { 3398 TEST_F(AppCacheUpdateJobTest, UpgradeNotModified) {
3355 RunTestOnIOThread(&AppCacheUpdateJobTest::UpgradeNotModifiedTest); 3399 RunTestOnIOThread(&AppCacheUpdateJobTest::UpgradeNotModifiedTest);
3356 } 3400 }
3357 3401
3358 TEST_F(AppCacheUpdateJobTest, UpgradeManifestDataUnchanged) { 3402 TEST_F(AppCacheUpdateJobTest, UpgradeManifestDataUnchanged) {
3359 RunTestOnIOThread(&AppCacheUpdateJobTest::UpgradeManifestDataUnchangedTest); 3403 RunTestOnIOThread(&AppCacheUpdateJobTest::UpgradeManifestDataUnchangedTest);
3360 } 3404 }
3361 3405
3406 TEST_F(AppCacheUpdateJobTest, Bug95101Test) {
3407 RunTestOnIOThread(&AppCacheUpdateJobTest::Bug95101Test);
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
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
OLDNEW
« no previous file with comments | « webkit/appcache/appcache_update_job.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698