OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 <stack> | 5 #include <stack> |
6 #include <utility> | 6 #include <utility> |
7 | 7 |
8 #include "base/compiler_specific.h" | 8 #include "base/compiler_specific.h" |
9 #include "base/pickle.h" | 9 #include "base/pickle.h" |
10 #include "base/thread.h" | 10 #include "base/thread.h" |
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
97 return; | 97 return; |
98 } | 98 } |
99 } | 99 } |
100 } else { | 100 } else { |
101 RequestComplete(); | 101 RequestComplete(); |
102 } | 102 } |
103 } | 103 } |
104 | 104 |
105 void ReadSome(URLRequest* request) { | 105 void ReadSome(URLRequest* request) { |
106 DCHECK(amount_received_ + kBlockSize <= kNumBlocks * kBlockSize); | 106 DCHECK(amount_received_ + kBlockSize <= kNumBlocks * kBlockSize); |
107 scoped_refptr<IOBuffer> wrapped_buffer = | 107 scoped_refptr<IOBuffer> wrapped_buffer( |
108 new net::WrappedIOBuffer(received_data_->data() + amount_received_); | 108 new net::WrappedIOBuffer(received_data_->data() + amount_received_)); |
109 int bytes_read = 0; | 109 int bytes_read = 0; |
110 EXPECT_FALSE(request->Read(wrapped_buffer, kBlockSize, &bytes_read)); | 110 EXPECT_FALSE(request->Read(wrapped_buffer, kBlockSize, &bytes_read)); |
111 EXPECT_EQ(0, bytes_read); | 111 EXPECT_EQ(0, bytes_read); |
112 } | 112 } |
113 | 113 |
114 void RequestComplete() { | 114 void RequestComplete() { |
115 test_->ScheduleNextTask(); | 115 test_->ScheduleNextTask(); |
116 } | 116 } |
117 | 117 |
118 AppCacheURLRequestJobTest* test_; | 118 AppCacheURLRequestJobTest* test_; |
(...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
257 task_stack_.pop(); | 257 task_stack_.pop(); |
258 if (immediate) | 258 if (immediate) |
259 task->Run(); | 259 task->Run(); |
260 else | 260 else |
261 MessageLoop::current()->PostTask(FROM_HERE, task.release()); | 261 MessageLoop::current()->PostTask(FROM_HERE, task.release()); |
262 } | 262 } |
263 | 263 |
264 // Wrappers to call AppCacheResponseReader/Writer Read and Write methods | 264 // Wrappers to call AppCacheResponseReader/Writer Read and Write methods |
265 | 265 |
266 void WriteBasicResponse() { | 266 void WriteBasicResponse() { |
267 scoped_refptr<IOBuffer> body = new WrappedIOBuffer(kHttpBasicBody); | 267 scoped_refptr<IOBuffer> body(new WrappedIOBuffer(kHttpBasicBody)); |
268 std::string raw_headers(kHttpBasicHeaders, arraysize(kHttpBasicHeaders)); | 268 std::string raw_headers(kHttpBasicHeaders, arraysize(kHttpBasicHeaders)); |
269 WriteResponse(MakeHttpResponseInfo(raw_headers), body, | 269 WriteResponse(MakeHttpResponseInfo(raw_headers), body, |
270 strlen(kHttpBasicBody)); | 270 strlen(kHttpBasicBody)); |
271 } | 271 } |
272 | 272 |
273 void WriteResponse(net::HttpResponseInfo* head, | 273 void WriteResponse(net::HttpResponseInfo* head, |
274 IOBuffer* body, int body_len) { | 274 IOBuffer* body, int body_len) { |
275 DCHECK(body); | 275 DCHECK(body); |
276 scoped_refptr<IOBuffer> body_ref(body); | 276 scoped_refptr<IOBuffer> body_ref(body); |
277 PushNextTask(NewRunnableMethod( | 277 PushNextTask(NewRunnableMethod( |
(...skipping 318 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
596 writer_.reset(service_->storage()->CreateResponseWriter(GURL())); | 596 writer_.reset(service_->storage()->CreateResponseWriter(GURL())); |
597 written_response_id_ = writer_->response_id(); | 597 written_response_id_ = writer_->response_id(); |
598 WriteLargeResponse(); | 598 WriteLargeResponse(); |
599 // Continues async | 599 // Continues async |
600 } | 600 } |
601 | 601 |
602 void WriteLargeResponse() { | 602 void WriteLargeResponse() { |
603 // 3, 1k blocks | 603 // 3, 1k blocks |
604 static const char kHttpHeaders[] = | 604 static const char kHttpHeaders[] = |
605 "HTTP/1.0 200 OK\0Content-Length: 3072\0\0"; | 605 "HTTP/1.0 200 OK\0Content-Length: 3072\0\0"; |
606 scoped_refptr<IOBuffer> body = new IOBuffer(kBlockSize * 3); | 606 scoped_refptr<IOBuffer> body(new IOBuffer(kBlockSize * 3)); |
607 char* p = body->data(); | 607 char* p = body->data(); |
608 for (int i = 0; i < 3; ++i, p += kBlockSize) | 608 for (int i = 0; i < 3; ++i, p += kBlockSize) |
609 FillData(i + 1, p, kBlockSize); | 609 FillData(i + 1, p, kBlockSize); |
610 std::string raw_headers(kHttpHeaders, arraysize(kHttpHeaders)); | 610 std::string raw_headers(kHttpHeaders, arraysize(kHttpHeaders)); |
611 WriteResponse(MakeHttpResponseInfo(raw_headers), body, kBlockSize * 3); | 611 WriteResponse(MakeHttpResponseInfo(raw_headers), body, kBlockSize * 3); |
612 } | 612 } |
613 | 613 |
614 void VerifyDeliverLargeAppCachedResponse() { | 614 void VerifyDeliverLargeAppCachedResponse() { |
615 EXPECT_TRUE(request_->status().is_success()); | 615 EXPECT_TRUE(request_->status().is_success()); |
616 EXPECT_TRUE(CompareHttpResponseInfos( | 616 EXPECT_TRUE(CompareHttpResponseInfos( |
(...skipping 195 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
812 | 812 |
813 TEST_F(AppCacheURLRequestJobTest, CancelRequestWithIOPending) { | 813 TEST_F(AppCacheURLRequestJobTest, CancelRequestWithIOPending) { |
814 RunTestOnIOThread(&AppCacheURLRequestJobTest::CancelRequestWithIOPending); | 814 RunTestOnIOThread(&AppCacheURLRequestJobTest::CancelRequestWithIOPending); |
815 } | 815 } |
816 | 816 |
817 } // namespace appcache | 817 } // namespace appcache |
818 | 818 |
819 // AppCacheURLRequestJobTest is expected to always live longer than the | 819 // AppCacheURLRequestJobTest is expected to always live longer than the |
820 // runnable methods. This lets us call NewRunnableMethod on its instances. | 820 // runnable methods. This lets us call NewRunnableMethod on its instances. |
821 DISABLE_RUNNABLE_METHOD_REFCOUNT(appcache::AppCacheURLRequestJobTest); | 821 DISABLE_RUNNABLE_METHOD_REFCOUNT(appcache::AppCacheURLRequestJobTest); |
OLD | NEW |