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

Unified Diff: content/browser/loader/test_resource_handler.cc

Issue 2441293003: Merge TestResourceHandlers used by two different test fixtures. (Closed)
Patch Set: Response to comments 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « content/browser/loader/test_resource_handler.h ('k') | content/test/BUILD.gn » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: content/browser/loader/test_resource_handler.cc
diff --git a/content/browser/loader/test_resource_handler.cc b/content/browser/loader/test_resource_handler.cc
new file mode 100644
index 0000000000000000000000000000000000000000..0ee72ae6744d140e22a9c3cf27a251259851c5b5
--- /dev/null
+++ b/content/browser/loader/test_resource_handler.cc
@@ -0,0 +1,111 @@
+// Copyright 2016 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 "content/browser/loader/test_resource_handler.h"
+
+#include "base/logging.h"
+#include "net/url_request/url_request_status.h"
+#include "testing/gtest/include/gtest/gtest.h"
+
+namespace content {
+
+TestResourceHandler::TestResourceHandler(net::URLRequestStatus* request_status,
+ std::string* body)
+ : ResourceHandler(nullptr), request_status_(request_status), body_(body) {
+ SetBufferSize(2048);
+}
+
+TestResourceHandler::TestResourceHandler()
+ : TestResourceHandler(nullptr, nullptr) {}
+
+TestResourceHandler::~TestResourceHandler() {}
+
+void TestResourceHandler::SetController(ResourceController* controller) {}
+
+bool TestResourceHandler::OnRequestRedirected(
+ const net::RedirectInfo& redirect_info,
+ ResourceResponse* response,
+ bool* defer) {
+ NOTREACHED() << "Redirects are not supported by the TestResourceHandler.";
+ return false;
+}
+
+bool TestResourceHandler::OnResponseStarted(ResourceResponse* response,
+ bool* defer) {
+ EXPECT_EQ(1, on_will_start_called_);
+ EXPECT_EQ(0, on_response_started_called_);
+ EXPECT_EQ(0, on_response_completed_called_);
+ ++on_response_started_called_;
+
+ if (!on_response_started_result_)
+ return false;
+ *defer = defer_on_response_started_;
+ defer_on_response_started_ = false;
+ return true;
+}
+
+bool TestResourceHandler::OnWillStart(const GURL& url, bool* defer) {
+ EXPECT_EQ(0, on_response_started_called_);
+ EXPECT_EQ(0, on_will_start_called_);
+ EXPECT_EQ(0, on_response_completed_called_);
+ ++on_will_start_called_;
+
+ if (!on_will_start_result_)
+ return false;
+
+ *defer = defer_on_will_start_;
+ return true;
+}
+
+bool TestResourceHandler::OnWillRead(scoped_refptr<net::IOBuffer>* buf,
+ int* buf_size,
+ int min_size) {
+ EXPECT_EQ(0, on_response_completed_called_);
+ ++on_will_read_called_;
+
+ *buf = buffer_;
+ *buf_size = buffer_size_;
+ memset(buffer_->data(), '\0', buffer_size_);
+ return on_will_read_result_;
+}
+
+bool TestResourceHandler::OnReadCompleted(int bytes_read, bool* defer) {
+ EXPECT_EQ(1, on_will_start_called_);
+ EXPECT_EQ(1, on_response_started_called_);
+ EXPECT_EQ(0, on_response_completed_called_);
+ ++on_read_completed_called_;
+
+ EXPECT_LE(static_cast<size_t>(bytes_read), buffer_size_);
+ if (body_)
+ body_->append(buffer_->data(), bytes_read);
+ if (!on_read_completed_result_)
+ return false;
+ *defer = defer_on_read_completed_;
+ defer_on_read_completed_ = false;
+ return true;
+}
+
+void TestResourceHandler::OnResponseCompleted(
+ const net::URLRequestStatus& status,
+ bool* defer) {
+ EXPECT_EQ(0, on_response_completed_called_);
+ ++on_response_completed_called_;
+
+ if (request_status_)
+ *request_status_ = status;
+ *defer = defer_on_response_completed_;
+ defer_on_response_completed_ = false;
+}
+
+void TestResourceHandler::OnDataDownloaded(int bytes_downloaded) {
+ NOTREACHED() << "Saving to file is not supported by the TestResourceHandler.";
+}
+
+void TestResourceHandler::SetBufferSize(int buffer_size) {
+ buffer_ = new net::IOBuffer(buffer_size);
+ buffer_size_ = buffer_size;
+ memset(buffer_->data(), '\0', buffer_size);
+}
+
+} // namespace content
« no previous file with comments | « content/browser/loader/test_resource_handler.h ('k') | content/test/BUILD.gn » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698