OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
82 "HTTP/1.1 410 GONE\0" | 82 "HTTP/1.1 410 GONE\0" |
83 "\0"; | 83 "\0"; |
84 const char not_found_headers[] = | 84 const char not_found_headers[] = |
85 "HTTP/1.1 404 NOT FOUND\0" | 85 "HTTP/1.1 404 NOT FOUND\0" |
86 "\0"; | 86 "\0"; |
87 const char no_store_headers[] = | 87 const char no_store_headers[] = |
88 "HTTP/1.1 200 OK\0" | 88 "HTTP/1.1 200 OK\0" |
89 "Cache-Control: no-store\0" | 89 "Cache-Control: no-store\0" |
90 "\0"; | 90 "\0"; |
91 | 91 |
92 if (path == "/files/wrong-mime-manifest") { | 92 if (path == "/files/missing-mime-manifest") { |
93 (*headers) = std::string(ok_headers, arraysize(ok_headers)); | 93 (*headers) = std::string(ok_headers, arraysize(ok_headers)); |
94 (*body) = "CACHE MANIFEST\n"; | 94 (*body) = "CACHE MANIFEST\n"; |
95 } else if (path == "/files/bad-manifest") { | 95 } else if (path == "/files/bad-manifest") { |
96 (*headers) = std::string(manifest_headers, arraysize(manifest_headers)); | 96 (*headers) = std::string(manifest_headers, arraysize(manifest_headers)); |
97 (*body) = "BAD CACHE MANIFEST"; | 97 (*body) = "BAD CACHE MANIFEST"; |
98 } else if (path == "/files/empty1") { | 98 } else if (path == "/files/empty1") { |
99 (*headers) = std::string(ok_headers, arraysize(ok_headers)); | 99 (*headers) = std::string(ok_headers, arraysize(ok_headers)); |
100 (*body) = ""; | 100 (*body) = ""; |
101 } else if (path == "/files/empty-file-manifest") { | 101 } else if (path == "/files/empty-file-manifest") { |
102 (*headers) = std::string(manifest_headers, arraysize(manifest_headers)); | 102 (*headers) = std::string(manifest_headers, arraysize(manifest_headers)); |
(...skipping 656 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
759 // Set up checks for when update job finishes. | 759 // Set up checks for when update job finishes. |
760 do_checks_after_update_finished_ = true; | 760 do_checks_after_update_finished_ = true; |
761 expect_group_obsolete_ = false; | 761 expect_group_obsolete_ = false; |
762 expect_group_has_cache_ = false; // redirect is like a failed request | 762 expect_group_has_cache_ = false; // redirect is like a failed request |
763 frontend->AddExpectedEvent(MockFrontend::HostIds(1, host->host_id()), | 763 frontend->AddExpectedEvent(MockFrontend::HostIds(1, host->host_id()), |
764 CHECKING_EVENT); | 764 CHECKING_EVENT); |
765 | 765 |
766 WaitForUpdateToFinish(); | 766 WaitForUpdateToFinish(); |
767 } | 767 } |
768 | 768 |
769 void ManifestWrongMimeTypeTest() { | 769 void ManifestMissingMimeTypeTest() { |
770 ASSERT_EQ(MessageLoop::TYPE_IO, MessageLoop::current()->type()); | 770 ASSERT_EQ(MessageLoop::TYPE_IO, MessageLoop::current()->type()); |
771 | 771 |
772 MakeService(); | 772 MakeService(); |
773 group_ = new AppCacheGroup( | 773 group_ = new AppCacheGroup( |
774 service_.get(), MockHttpServer::GetMockUrl("files/wrong-mime-manifest"), | 774 service_.get(), |
| 775 MockHttpServer::GetMockUrl("files/missing-mime-manifest"), |
775 service_->storage()->NewGroupId()); | 776 service_->storage()->NewGroupId()); |
776 AppCacheUpdateJob* update = new AppCacheUpdateJob(service_.get(), group_); | 777 AppCacheUpdateJob* update = new AppCacheUpdateJob(service_.get(), group_); |
777 group_->update_job_ = update; | 778 group_->update_job_ = update; |
778 | 779 |
| 780 AppCache* cache = MakeCacheForGroup(service_->storage()->NewCacheId(), 33); |
779 MockFrontend* frontend = MakeMockFrontend(); | 781 MockFrontend* frontend = MakeMockFrontend(); |
780 AppCacheHost* host = MakeHost(1, frontend); | 782 AppCacheHost* host = MakeHost(1, frontend); |
781 update->StartUpdate(host, GURL()); | 783 host->AssociateCompleteCache(cache); |
| 784 |
| 785 frontend->SetVerifyProgressEvents(true); |
| 786 |
| 787 update->StartUpdate(NULL, GURL()); |
782 EXPECT_TRUE(update->manifest_fetcher_ != NULL); | 788 EXPECT_TRUE(update->manifest_fetcher_ != NULL); |
783 | 789 |
784 // Set up checks for when update job finishes. | 790 // Set up checks for when update job finishes. |
785 do_checks_after_update_finished_ = true; | 791 do_checks_after_update_finished_ = true; |
786 expect_group_obsolete_ = false; | 792 expect_group_obsolete_ = false; |
787 expect_group_has_cache_ = false; // bad mime type is like a failed request | 793 expect_group_has_cache_ = true; |
788 frontend->AddExpectedEvent(MockFrontend::HostIds(1, host->host_id()), | 794 expect_old_cache_ = cache; |
789 CHECKING_EVENT); | 795 tested_manifest_ = EMPTY_MANIFEST; |
| 796 tested_manifest_path_override_ = "files/missing-mime-manifest"; |
| 797 MockFrontend::HostIds ids(1, host->host_id()); |
| 798 frontend->AddExpectedEvent(ids, CHECKING_EVENT); |
| 799 frontend->AddExpectedEvent(ids, DOWNLOADING_EVENT); |
| 800 frontend->AddExpectedEvent(ids, PROGRESS_EVENT); // final |
| 801 frontend->AddExpectedEvent(ids, UPDATE_READY_EVENT); |
790 | 802 |
791 WaitForUpdateToFinish(); | 803 WaitForUpdateToFinish(); |
792 } | 804 } |
793 | 805 |
794 void ManifestNotFoundTest() { | 806 void ManifestNotFoundTest() { |
795 ASSERT_EQ(MessageLoop::TYPE_IO, MessageLoop::current()->type()); | 807 ASSERT_EQ(MessageLoop::TYPE_IO, MessageLoop::current()->type()); |
796 | 808 |
797 MakeService(); | 809 MakeService(); |
798 group_ = new AppCacheGroup( | 810 group_ = new AppCacheGroup( |
799 service_.get(), MockHttpServer::GetMockUrl("files/nosuchfile"), | 811 service_.get(), MockHttpServer::GetMockUrl("files/nosuchfile"), |
(...skipping 2460 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3260 } | 3272 } |
3261 | 3273 |
3262 TEST_F(AppCacheUpdateJobTest, UpgradeFetchManifestFail) { | 3274 TEST_F(AppCacheUpdateJobTest, UpgradeFetchManifestFail) { |
3263 RunTestOnIOThread(&AppCacheUpdateJobTest::UpgradeFetchManifestFailTest); | 3275 RunTestOnIOThread(&AppCacheUpdateJobTest::UpgradeFetchManifestFailTest); |
3264 } | 3276 } |
3265 | 3277 |
3266 TEST_F(AppCacheUpdateJobTest, ManifestRedirect) { | 3278 TEST_F(AppCacheUpdateJobTest, ManifestRedirect) { |
3267 RunTestOnIOThread(&AppCacheUpdateJobTest::ManifestRedirectTest); | 3279 RunTestOnIOThread(&AppCacheUpdateJobTest::ManifestRedirectTest); |
3268 } | 3280 } |
3269 | 3281 |
3270 TEST_F(AppCacheUpdateJobTest, ManifestWrongMimeType) { | 3282 TEST_F(AppCacheUpdateJobTest, ManifestMissingMimeTypeTest) { |
3271 RunTestOnIOThread(&AppCacheUpdateJobTest::ManifestWrongMimeTypeTest); | 3283 RunTestOnIOThread(&AppCacheUpdateJobTest::ManifestMissingMimeTypeTest); |
3272 } | 3284 } |
3273 | 3285 |
3274 TEST_F(AppCacheUpdateJobTest, ManifestNotFound) { | 3286 TEST_F(AppCacheUpdateJobTest, ManifestNotFound) { |
3275 RunTestOnIOThread(&AppCacheUpdateJobTest::ManifestNotFoundTest); | 3287 RunTestOnIOThread(&AppCacheUpdateJobTest::ManifestNotFoundTest); |
3276 } | 3288 } |
3277 | 3289 |
3278 TEST_F(AppCacheUpdateJobTest, ManifestGone) { | 3290 TEST_F(AppCacheUpdateJobTest, ManifestGone) { |
3279 RunTestOnIOThread(&AppCacheUpdateJobTest::ManifestGoneTest); | 3291 RunTestOnIOThread(&AppCacheUpdateJobTest::ManifestGoneTest); |
3280 } | 3292 } |
3281 | 3293 |
(...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3447 | 3459 |
3448 TEST_F(AppCacheUpdateJobTest, CrossOriginHttpsSuccess) { | 3460 TEST_F(AppCacheUpdateJobTest, CrossOriginHttpsSuccess) { |
3449 RunTestOnIOThread(&AppCacheUpdateJobTest::CrossOriginHttpsSuccessTest); | 3461 RunTestOnIOThread(&AppCacheUpdateJobTest::CrossOriginHttpsSuccessTest); |
3450 } | 3462 } |
3451 | 3463 |
3452 TEST_F(AppCacheUpdateJobTest, CrossOriginHttpsDenied) { | 3464 TEST_F(AppCacheUpdateJobTest, CrossOriginHttpsDenied) { |
3453 RunTestOnIOThread(&AppCacheUpdateJobTest::CrossOriginHttpsDeniedTest); | 3465 RunTestOnIOThread(&AppCacheUpdateJobTest::CrossOriginHttpsDeniedTest); |
3454 } | 3466 } |
3455 | 3467 |
3456 } // namespace appcache | 3468 } // namespace appcache |
OLD | NEW |