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

Unified Diff: content/browser/fileapi/mock_url_request_delegate.cc

Issue 293083002: Add a blob field to ServiceWorkerFetchResponse and read the blob (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fix merge conflict Created 6 years, 7 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 side-by-side diff with in-line comments
Download patch
Index: content/browser/fileapi/mock_url_request_delegate.cc
diff --git a/content/browser/fileapi/mock_url_request_delegate.cc b/content/browser/fileapi/mock_url_request_delegate.cc
new file mode 100644
index 0000000000000000000000000000000000000000..97e09f0df6f6285601f55bf3f98337f6399302d4
--- /dev/null
+++ b/content/browser/fileapi/mock_url_request_delegate.cc
@@ -0,0 +1,72 @@
+// Copyright 2014 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "mock_url_request_delegate.h"
+
+#include "base/run_loop.h"
+#include "net/base/io_buffer.h"
+#include "testing/gtest/include/gtest/gtest.h"
+
+namespace {
+const int kBufferSize = 1024;
+}
+
+namespace content {
+
+MockURLRequestDelegate::MockURLRequestDelegate()
+ : io_buffer_(new net::IOBuffer(kBufferSize)) {
+}
+
+MockURLRequestDelegate::~MockURLRequestDelegate() {
+}
+
+void MockURLRequestDelegate::OnResponseStarted(net::URLRequest* request) {
+ if (request->status().is_success()) {
+ EXPECT_TRUE(request->response_headers());
+ ReadSome(request);
+ } else {
+ RequestComplete();
+ }
+}
+
+void MockURLRequestDelegate::OnReadCompleted(net::URLRequest* request,
+ int bytes_read) {
+ if (bytes_read > 0)
+ ReceiveData(request, bytes_read);
+ else
+ RequestComplete();
+}
+
+void MockURLRequestDelegate::ReadSome(net::URLRequest* request) {
+ if (!request->is_pending()) {
+ RequestComplete();
+ return;
+ }
+
+ int bytes_read = 0;
+ if (!request->Read(io_buffer_.get(), kBufferSize, &bytes_read)) {
+ if (!request->status().is_io_pending())
+ RequestComplete();
+ return;
+ }
+
+ ReceiveData(request, bytes_read);
+}
+
+void MockURLRequestDelegate::ReceiveData(net::URLRequest* request,
+ int bytes_read) {
+ if (bytes_read) {
+ response_data_.append(io_buffer_->data(),
+ static_cast<size_t>(bytes_read));
+ ReadSome(request);
+ } else {
+ RequestComplete();
+ }
+}
+
+void MockURLRequestDelegate::RequestComplete() {
+ base::MessageLoop::current()->Quit();
+}
+
+} // namespace
« no previous file with comments | « content/browser/fileapi/mock_url_request_delegate.h ('k') | content/browser/loader/resource_dispatcher_host_impl.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698