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.
5 #include "content/browser/fileapi/mock_url_request_delegate.h"
7 #include "base/run_loop.h"
8 #include "net/base/io_buffer.h"
9 #include "testing/gtest/include/gtest/gtest.h"
12 const int kBufferSize
= 1024;
17 MockURLRequestDelegate::MockURLRequestDelegate()
18 : io_buffer_(new net::IOBuffer(kBufferSize
)) {
21 MockURLRequestDelegate::~MockURLRequestDelegate() {
24 void MockURLRequestDelegate::OnResponseStarted(net::URLRequest
* request
) {
25 if (request
->status().is_success()) {
26 EXPECT_TRUE(request
->response_headers());
33 void MockURLRequestDelegate::OnReadCompleted(net::URLRequest
* request
,
36 ReceiveData(request
, bytes_read
);
41 void MockURLRequestDelegate::ReadSome(net::URLRequest
* request
) {
42 if (!request
->is_pending()) {
48 if (!request
->Read(io_buffer_
.get(), kBufferSize
, &bytes_read
)) {
49 if (!request
->status().is_io_pending())
54 ReceiveData(request
, bytes_read
);
57 void MockURLRequestDelegate::ReceiveData(net::URLRequest
* request
,
60 response_data_
.append(io_buffer_
->data(),
61 static_cast<size_t>(bytes_read
));
68 void MockURLRequestDelegate::RequestComplete() {
69 base::MessageLoop::current()->Quit();