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

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

Issue 8991001: base::Bind: Convert most of webkit/appcache. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Review fix 2. Created 9 years 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') | webkit/appcache/appcache_url_request_job.h » ('j') | 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) 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 960 matching lines...) Expand 10 before | Expand all | Expand 10 after
971 frontend1->AddExpectedEvent(ids1, CHECKING_EVENT); 971 frontend1->AddExpectedEvent(ids1, CHECKING_EVENT);
972 frontend1->AddExpectedEvent(ids1, NO_UPDATE_EVENT); 972 frontend1->AddExpectedEvent(ids1, NO_UPDATE_EVENT);
973 MockFrontend::HostIds ids2(1, host2->host_id()); 973 MockFrontend::HostIds ids2(1, host2->host_id());
974 frontend2->AddExpectedEvent(ids2, CHECKING_EVENT); 974 frontend2->AddExpectedEvent(ids2, CHECKING_EVENT);
975 frontend2->AddExpectedEvent(ids2, NO_UPDATE_EVENT); 975 frontend2->AddExpectedEvent(ids2, NO_UPDATE_EVENT);
976 976
977 // Seed storage with expected manifest data. 977 // Seed storage with expected manifest data.
978 const std::string seed_data(kManifest1Contents); 978 const std::string seed_data(kManifest1Contents);
979 scoped_refptr<net::StringIOBuffer> io_buffer( 979 scoped_refptr<net::StringIOBuffer> io_buffer(
980 new net::StringIOBuffer(seed_data)); 980 new net::StringIOBuffer(seed_data));
981 write_callback_.reset( 981 response_writer_->WriteData(
982 new net::OldCompletionCallbackImpl<AppCacheUpdateJobTest>(this, 982 io_buffer, seed_data.length(),
983 &AppCacheUpdateJobTest::StartUpdateAfterSeedingStorageData)); 983 base::Bind(&AppCacheUpdateJobTest::StartUpdateAfterSeedingStorageData,
984 response_writer_->WriteData(io_buffer, seed_data.length(), 984 base::Unretained(this)));
985 write_callback_.get());
986 985
987 // Start update after data write completes asynchronously. 986 // Start update after data write completes asynchronously.
988 } 987 }
989 988
990 void StartUpdateAfterSeedingStorageData(int result) { 989 void StartUpdateAfterSeedingStorageData(int result) {
991 ASSERT_GT(result, 0); 990 ASSERT_GT(result, 0);
992 write_callback_.reset();
993 response_writer_.reset(); 991 response_writer_.reset();
994 992
995 AppCacheUpdateJob* update = group_->update_job_; 993 AppCacheUpdateJob* update = group_->update_job_;
996 update->StartUpdate(NULL, GURL()); 994 update->StartUpdate(NULL, GURL());
997 EXPECT_TRUE(update->manifest_fetcher_ != NULL); 995 EXPECT_TRUE(update->manifest_fetcher_ != NULL);
998 996
999 WaitForUpdateToFinish(); 997 WaitForUpdateToFinish();
1000 } 998 }
1001 999
1002 void BasicCacheAttemptSuccessTest() { 1000 void BasicCacheAttemptSuccessTest() {
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after
1097 frontend2->AddExpectedEvent(ids2, DOWNLOADING_EVENT); 1095 frontend2->AddExpectedEvent(ids2, DOWNLOADING_EVENT);
1098 frontend2->AddExpectedEvent(ids2, PROGRESS_EVENT); 1096 frontend2->AddExpectedEvent(ids2, PROGRESS_EVENT);
1099 frontend2->AddExpectedEvent(ids2, PROGRESS_EVENT); 1097 frontend2->AddExpectedEvent(ids2, PROGRESS_EVENT);
1100 frontend2->AddExpectedEvent(ids2, PROGRESS_EVENT); // final 1098 frontend2->AddExpectedEvent(ids2, PROGRESS_EVENT); // final
1101 frontend2->AddExpectedEvent(ids2, UPDATE_READY_EVENT); 1099 frontend2->AddExpectedEvent(ids2, UPDATE_READY_EVENT);
1102 1100
1103 // Seed storage with expected manifest data different from manifest1. 1101 // Seed storage with expected manifest data different from manifest1.
1104 const std::string seed_data("different"); 1102 const std::string seed_data("different");
1105 scoped_refptr<net::StringIOBuffer> io_buffer( 1103 scoped_refptr<net::StringIOBuffer> io_buffer(
1106 new net::StringIOBuffer(seed_data)); 1104 new net::StringIOBuffer(seed_data));
1107 write_callback_.reset( 1105 response_writer_->WriteData(
1108 new net::OldCompletionCallbackImpl<AppCacheUpdateJobTest>(this, 1106 io_buffer, seed_data.length(),
1109 &AppCacheUpdateJobTest::StartUpdateAfterSeedingStorageData)); 1107 base::Bind(&AppCacheUpdateJobTest::StartUpdateAfterSeedingStorageData,
1110 response_writer_->WriteData(io_buffer, seed_data.length(), 1108 base::Unretained(this)));
1111 write_callback_.get());
1112 1109
1113 // Start update after data write completes asynchronously. 1110 // Start update after data write completes asynchronously.
1114 } 1111 }
1115 1112
1116 void UpgradeLoadFromNewestCacheTest() { 1113 void UpgradeLoadFromNewestCacheTest() {
1117 ASSERT_EQ(MessageLoop::TYPE_IO, MessageLoop::current()->type()); 1114 ASSERT_EQ(MessageLoop::TYPE_IO, MessageLoop::current()->type());
1118 1115
1119 MakeService(); 1116 MakeService();
1120 group_ = new AppCacheGroup( 1117 group_ = new AppCacheGroup(
1121 service_.get(), MockHttpServer::GetMockUrl("files/manifest1"), 1118 service_.get(), MockHttpServer::GetMockUrl("files/manifest1"),
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
1160 "Cache-Control: max-age=8675309\0" 1157 "Cache-Control: max-age=8675309\0"
1161 "\0"; 1158 "\0";
1162 net::HttpResponseHeaders* headers = 1159 net::HttpResponseHeaders* headers =
1163 new net::HttpResponseHeaders(std::string(data, arraysize(data))); 1160 new net::HttpResponseHeaders(std::string(data, arraysize(data)));
1164 net::HttpResponseInfo* response_info = new net::HttpResponseInfo(); 1161 net::HttpResponseInfo* response_info = new net::HttpResponseInfo();
1165 response_info->request_time = base::Time::Now(); 1162 response_info->request_time = base::Time::Now();
1166 response_info->response_time = base::Time::Now(); 1163 response_info->response_time = base::Time::Now();
1167 response_info->headers = headers; // adds ref to headers 1164 response_info->headers = headers; // adds ref to headers
1168 scoped_refptr<HttpResponseInfoIOBuffer> io_buffer( 1165 scoped_refptr<HttpResponseInfoIOBuffer> io_buffer(
1169 new HttpResponseInfoIOBuffer(response_info)); // adds ref to info 1166 new HttpResponseInfoIOBuffer(response_info)); // adds ref to info
1170 write_callback_.reset( 1167 response_writer_->WriteInfo(
1171 new net::OldCompletionCallbackImpl<AppCacheUpdateJobTest>(this, 1168 io_buffer,
1172 &AppCacheUpdateJobTest::StartUpdateAfterSeedingStorageData)); 1169 base::Bind(&AppCacheUpdateJobTest::StartUpdateAfterSeedingStorageData,
1173 response_writer_->WriteInfo(io_buffer, write_callback_.get()); 1170 base::Unretained(this)));
1174 1171
1175 // Start update after data write completes asynchronously. 1172 // Start update after data write completes asynchronously.
1176 } 1173 }
1177 1174
1178 void UpgradeNoLoadFromNewestCacheTest() { 1175 void UpgradeNoLoadFromNewestCacheTest() {
1179 ASSERT_EQ(MessageLoop::TYPE_IO, MessageLoop::current()->type()); 1176 ASSERT_EQ(MessageLoop::TYPE_IO, MessageLoop::current()->type());
1180 1177
1181 MakeService(); 1178 MakeService();
1182 group_ = new AppCacheGroup( 1179 group_ = new AppCacheGroup(
1183 service_.get(), MockHttpServer::GetMockUrl("files/manifest1"), 1180 service_.get(), MockHttpServer::GetMockUrl("files/manifest1"),
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
1219 "Expires: Thu, 01 Dec 1994 16:00:00 GMT\0" 1216 "Expires: Thu, 01 Dec 1994 16:00:00 GMT\0"
1220 "\0"; 1217 "\0";
1221 net::HttpResponseHeaders* headers = 1218 net::HttpResponseHeaders* headers =
1222 new net::HttpResponseHeaders(std::string(data, arraysize(data))); 1219 new net::HttpResponseHeaders(std::string(data, arraysize(data)));
1223 net::HttpResponseInfo* response_info = new net::HttpResponseInfo(); 1220 net::HttpResponseInfo* response_info = new net::HttpResponseInfo();
1224 response_info->request_time = base::Time::Now(); 1221 response_info->request_time = base::Time::Now();
1225 response_info->response_time = base::Time::Now(); 1222 response_info->response_time = base::Time::Now();
1226 response_info->headers = headers; // adds ref to headers 1223 response_info->headers = headers; // adds ref to headers
1227 scoped_refptr<HttpResponseInfoIOBuffer> io_buffer( 1224 scoped_refptr<HttpResponseInfoIOBuffer> io_buffer(
1228 new HttpResponseInfoIOBuffer(response_info)); // adds ref to info 1225 new HttpResponseInfoIOBuffer(response_info)); // adds ref to info
1229 write_callback_.reset( 1226 response_writer_->WriteInfo(
1230 new net::OldCompletionCallbackImpl<AppCacheUpdateJobTest>(this, 1227 io_buffer,
1231 &AppCacheUpdateJobTest::StartUpdateAfterSeedingStorageData)); 1228 base::Bind(&AppCacheUpdateJobTest::StartUpdateAfterSeedingStorageData,
1232 response_writer_->WriteInfo(io_buffer, write_callback_.get()); 1229 base::Unretained(this)));
1233 1230
1234 // Start update after data write completes asynchronously. 1231 // Start update after data write completes asynchronously.
1235 } 1232 }
1236 1233
1237 void UpgradeLoadFromNewestCacheVaryHeaderTest() { 1234 void UpgradeLoadFromNewestCacheVaryHeaderTest() {
1238 ASSERT_EQ(MessageLoop::TYPE_IO, MessageLoop::current()->type()); 1235 ASSERT_EQ(MessageLoop::TYPE_IO, MessageLoop::current()->type());
1239 1236
1240 MakeService(); 1237 MakeService();
1241 group_ = new AppCacheGroup( 1238 group_ = new AppCacheGroup(
1242 service_.get(), MockHttpServer::GetMockUrl("files/manifest1"), 1239 service_.get(), MockHttpServer::GetMockUrl("files/manifest1"),
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
1278 "Vary: blah\0" 1275 "Vary: blah\0"
1279 "\0"; 1276 "\0";
1280 net::HttpResponseHeaders* headers = 1277 net::HttpResponseHeaders* headers =
1281 new net::HttpResponseHeaders(std::string(data, arraysize(data))); 1278 new net::HttpResponseHeaders(std::string(data, arraysize(data)));
1282 net::HttpResponseInfo* response_info = new net::HttpResponseInfo(); 1279 net::HttpResponseInfo* response_info = new net::HttpResponseInfo();
1283 response_info->request_time = base::Time::Now(); 1280 response_info->request_time = base::Time::Now();
1284 response_info->response_time = base::Time::Now(); 1281 response_info->response_time = base::Time::Now();
1285 response_info->headers = headers; // adds ref to headers 1282 response_info->headers = headers; // adds ref to headers
1286 scoped_refptr<HttpResponseInfoIOBuffer> io_buffer( 1283 scoped_refptr<HttpResponseInfoIOBuffer> io_buffer(
1287 new HttpResponseInfoIOBuffer(response_info)); // adds ref to info 1284 new HttpResponseInfoIOBuffer(response_info)); // adds ref to info
1288 write_callback_.reset( 1285 response_writer_->WriteInfo(
1289 new net::OldCompletionCallbackImpl<AppCacheUpdateJobTest>(this, 1286 io_buffer,
1290 &AppCacheUpdateJobTest::StartUpdateAfterSeedingStorageData)); 1287 base::Bind(&AppCacheUpdateJobTest::StartUpdateAfterSeedingStorageData,
1291 response_writer_->WriteInfo(io_buffer, write_callback_.get()); 1288 base::Unretained(this)));
1292 1289
1293 // Start update after data write completes asynchronously. 1290 // Start update after data write completes asynchronously.
1294 } 1291 }
1295 1292
1296 void UpgradeSuccessMergedTypesTest() { 1293 void UpgradeSuccessMergedTypesTest() {
1297 ASSERT_EQ(MessageLoop::TYPE_IO, MessageLoop::current()->type()); 1294 ASSERT_EQ(MessageLoop::TYPE_IO, MessageLoop::current()->type());
1298 1295
1299 MakeService(); 1296 MakeService();
1300 group_ = new AppCacheGroup(service_.get(), 1297 group_ = new AppCacheGroup(service_.get(),
1301 MockHttpServer::GetMockUrl("files/manifest-merged-types"), 1298 MockHttpServer::GetMockUrl("files/manifest-merged-types"),
(...skipping 1357 matching lines...) Expand 10 before | Expand all | Expand 10 after
2659 const char data[] = 2656 const char data[] =
2660 "HTTP/1.1 200 OK\0" 2657 "HTTP/1.1 200 OK\0"
2661 "Last-Modified: Sat, 29 Oct 1994 19:43:31 GMT\0" 2658 "Last-Modified: Sat, 29 Oct 1994 19:43:31 GMT\0"
2662 "\0"; 2659 "\0";
2663 net::HttpResponseHeaders* headers = 2660 net::HttpResponseHeaders* headers =
2664 new net::HttpResponseHeaders(std::string(data, arraysize(data))); 2661 new net::HttpResponseHeaders(std::string(data, arraysize(data)));
2665 net::HttpResponseInfo* response_info = new net::HttpResponseInfo(); 2662 net::HttpResponseInfo* response_info = new net::HttpResponseInfo();
2666 response_info->headers = headers; // adds ref to headers 2663 response_info->headers = headers; // adds ref to headers
2667 scoped_refptr<HttpResponseInfoIOBuffer> io_buffer( 2664 scoped_refptr<HttpResponseInfoIOBuffer> io_buffer(
2668 new HttpResponseInfoIOBuffer(response_info)); // adds ref to info 2665 new HttpResponseInfoIOBuffer(response_info)); // adds ref to info
2669 write_callback_.reset( 2666 response_writer_->WriteInfo(
2670 new net::OldCompletionCallbackImpl<AppCacheUpdateJobTest>(this, 2667 io_buffer,
2671 &AppCacheUpdateJobTest::StartUpdateAfterSeedingStorageData)); 2668 base::Bind(&AppCacheUpdateJobTest::StartUpdateAfterSeedingStorageData,
2672 response_writer_->WriteInfo(io_buffer, write_callback_.get()); 2669 base::Unretained(this)));
2673 2670
2674 // Start update after data write completes asynchronously. 2671 // Start update after data write completes asynchronously.
2675 } 2672 }
2676 2673
2677 void IfNoneMatchUpgradeTest() { 2674 void IfNoneMatchUpgradeTest() {
2678 ASSERT_EQ(MessageLoop::TYPE_IO, MessageLoop::current()->type()); 2675 ASSERT_EQ(MessageLoop::TYPE_IO, MessageLoop::current()->type());
2679 2676
2680 HttpHeadersRequestTestJob::Initialize("", "\"LadeDade\""); 2677 HttpHeadersRequestTestJob::Initialize("", "\"LadeDade\"");
2681 net::URLRequestJobFactory* new_factory(new net::URLRequestJobFactory); 2678 net::URLRequestJobFactory* new_factory(new net::URLRequestJobFactory);
2682 new_factory->SetProtocolHandler("http", new IfModifiedSinceJobFactory); 2679 new_factory->SetProtocolHandler("http", new IfModifiedSinceJobFactory);
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
2718 const char data[] = 2715 const char data[] =
2719 "HTTP/1.1 200 OK\0" 2716 "HTTP/1.1 200 OK\0"
2720 "ETag: \"LadeDade\"\0" 2717 "ETag: \"LadeDade\"\0"
2721 "\0"; 2718 "\0";
2722 net::HttpResponseHeaders* headers = 2719 net::HttpResponseHeaders* headers =
2723 new net::HttpResponseHeaders(std::string(data, arraysize(data))); 2720 new net::HttpResponseHeaders(std::string(data, arraysize(data)));
2724 net::HttpResponseInfo* response_info = new net::HttpResponseInfo(); 2721 net::HttpResponseInfo* response_info = new net::HttpResponseInfo();
2725 response_info->headers = headers; // adds ref to headers 2722 response_info->headers = headers; // adds ref to headers
2726 scoped_refptr<HttpResponseInfoIOBuffer> io_buffer( 2723 scoped_refptr<HttpResponseInfoIOBuffer> io_buffer(
2727 new HttpResponseInfoIOBuffer(response_info)); // adds ref to info 2724 new HttpResponseInfoIOBuffer(response_info)); // adds ref to info
2728 write_callback_.reset( 2725 response_writer_->WriteInfo(
2729 new net::OldCompletionCallbackImpl<AppCacheUpdateJobTest>(this, 2726 io_buffer,
2730 &AppCacheUpdateJobTest::StartUpdateAfterSeedingStorageData)); 2727 base::Bind(&AppCacheUpdateJobTest::StartUpdateAfterSeedingStorageData,
2731 response_writer_->WriteInfo(io_buffer, write_callback_.get()); 2728 base::Unretained(this)));
2732 2729
2733 // Start update after data write completes asynchronously. 2730 // Start update after data write completes asynchronously.
2734 } 2731 }
2735 2732
2736 void IfNoneMatchRefetchTest() { 2733 void IfNoneMatchRefetchTest() {
2737 ASSERT_EQ(MessageLoop::TYPE_IO, MessageLoop::current()->type()); 2734 ASSERT_EQ(MessageLoop::TYPE_IO, MessageLoop::current()->type());
2738 2735
2739 HttpHeadersRequestTestJob::Initialize("", "\"LadeDade\""); 2736 HttpHeadersRequestTestJob::Initialize("", "\"LadeDade\"");
2740 net::URLRequestJobFactory* new_factory(new net::URLRequestJobFactory); 2737 net::URLRequestJobFactory* new_factory(new net::URLRequestJobFactory);
2741 new_factory->SetProtocolHandler("http", new IfModifiedSinceJobFactory); 2738 new_factory->SetProtocolHandler("http", new IfModifiedSinceJobFactory);
(...skipping 481 matching lines...) Expand 10 before | Expand all | Expand 10 after
3223 }; 3220 };
3224 3221
3225 scoped_ptr<IOThread> io_thread_; 3222 scoped_ptr<IOThread> io_thread_;
3226 3223
3227 scoped_ptr<MockAppCacheService> service_; 3224 scoped_ptr<MockAppCacheService> service_;
3228 scoped_refptr<AppCacheGroup> group_; 3225 scoped_refptr<AppCacheGroup> group_;
3229 scoped_refptr<AppCache> protect_newest_cache_; 3226 scoped_refptr<AppCache> protect_newest_cache_;
3230 scoped_ptr<base::WaitableEvent> event_; 3227 scoped_ptr<base::WaitableEvent> event_;
3231 3228
3232 scoped_ptr<AppCacheResponseWriter> response_writer_; 3229 scoped_ptr<AppCacheResponseWriter> response_writer_;
3233 scoped_ptr<net::OldCompletionCallbackImpl<AppCacheUpdateJobTest> >
3234 write_callback_;
3235 3230
3236 // Hosts used by an async test that need to live until update job finishes. 3231 // Hosts used by an async test that need to live until update job finishes.
3237 // Otherwise, test can put host on the stack instead of here. 3232 // Otherwise, test can put host on the stack instead of here.
3238 std::vector<AppCacheHost*> hosts_; 3233 std::vector<AppCacheHost*> hosts_;
3239 3234
3240 // Response infos used by an async test that need to live until update job 3235 // Response infos used by an async test that need to live until update job
3241 // finishes. 3236 // finishes.
3242 std::vector<scoped_refptr<AppCacheResponseInfo> > response_infos_; 3237 std::vector<scoped_refptr<AppCacheResponseInfo> > response_infos_;
3243 3238
3244 // Flag indicating if test cares to verify the update after update finishes. 3239 // Flag indicating if test cares to verify the update after update finishes.
(...skipping 276 matching lines...) Expand 10 before | Expand all | Expand 10 after
3521 3516
3522 TEST_F(AppCacheUpdateJobTest, CrossOriginHttpsSuccess) { 3517 TEST_F(AppCacheUpdateJobTest, CrossOriginHttpsSuccess) {
3523 RunTestOnIOThread(&AppCacheUpdateJobTest::CrossOriginHttpsSuccessTest); 3518 RunTestOnIOThread(&AppCacheUpdateJobTest::CrossOriginHttpsSuccessTest);
3524 } 3519 }
3525 3520
3526 TEST_F(AppCacheUpdateJobTest, CrossOriginHttpsDenied) { 3521 TEST_F(AppCacheUpdateJobTest, CrossOriginHttpsDenied) {
3527 RunTestOnIOThread(&AppCacheUpdateJobTest::CrossOriginHttpsDeniedTest); 3522 RunTestOnIOThread(&AppCacheUpdateJobTest::CrossOriginHttpsDeniedTest);
3528 } 3523 }
3529 3524
3530 } // namespace appcache 3525 } // namespace appcache
OLDNEW
« no previous file with comments | « webkit/appcache/appcache_update_job.cc ('k') | webkit/appcache/appcache_url_request_job.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698