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

Side by Side Diff: content/browser/fileapi/mock_url_request_delegate.cc

Issue 2368913003: Populate storage_unittests target. (Closed)
Patch Set: Removed unnecessary include from storage/browser/blob/blob_storage_context_unittest.cc. Created 4 years, 2 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
OLDNEW
(Empty)
1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "content/browser/fileapi/mock_url_request_delegate.h"
6
7 #include <stddef.h>
8
9 #include "base/run_loop.h"
10 #include "net/base/io_buffer.h"
11 #include "testing/gtest/include/gtest/gtest.h"
12
13 namespace {
14 const int kBufferSize = 1024;
15 }
16
17 namespace content {
18
19 MockURLRequestDelegate::MockURLRequestDelegate()
20 : io_buffer_(new net::IOBuffer(kBufferSize)) {
21 }
22
23 MockURLRequestDelegate::~MockURLRequestDelegate() {
24 }
25
26 void MockURLRequestDelegate::OnResponseStarted(net::URLRequest* request) {
27 if (request->status().is_success()) {
28 EXPECT_TRUE(request->response_headers());
29 metadata_ = request->response_info().metadata;
30 ReadSome(request);
31 } else {
32 RequestComplete();
33 }
34 }
35
36 void MockURLRequestDelegate::OnReadCompleted(net::URLRequest* request,
37 int bytes_read) {
38 if (bytes_read > 0)
39 ReceiveData(request, bytes_read);
40 else
41 RequestComplete();
42 }
43
44 void MockURLRequestDelegate::ReadSome(net::URLRequest* request) {
45 if (!request->is_pending()) {
46 RequestComplete();
47 return;
48 }
49
50 int bytes_read = 0;
51 if (!request->Read(io_buffer_.get(), kBufferSize, &bytes_read)) {
52 if (!request->status().is_io_pending())
53 RequestComplete();
54 return;
55 }
56
57 ReceiveData(request, bytes_read);
58 }
59
60 void MockURLRequestDelegate::ReceiveData(net::URLRequest* request,
61 int bytes_read) {
62 if (bytes_read) {
63 response_data_.append(io_buffer_->data(),
64 static_cast<size_t>(bytes_read));
65 ReadSome(request);
66 } else {
67 RequestComplete();
68 }
69 }
70
71 void MockURLRequestDelegate::RequestComplete() {
72 base::MessageLoop::current()->QuitWhenIdle();
73 }
74
75 } // namespace
OLDNEW
« no previous file with comments | « content/browser/fileapi/mock_url_request_delegate.h ('k') | content/browser/fileapi/native_file_util_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698