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

Unified Diff: content/child/web_url_loader_impl_unittest.cc

Issue 1103813002: Make WebURLLoader capable of retaining received buffers. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 8 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/child/web_url_loader_impl_unittest.cc
diff --git a/content/child/web_url_loader_impl_unittest.cc b/content/child/web_url_loader_impl_unittest.cc
index f1321696708ff30f233f4ddf64bac09fc0cd8521..d479fd253ac03bc1eb3d073e59e28b8cd6b5b724 100644
--- a/content/child/web_url_loader_impl_unittest.cc
+++ b/content/child/web_url_loader_impl_unittest.cc
@@ -5,6 +5,7 @@
#include "content/child/web_url_loader_impl.h"
#include <string.h>
+#include <vector>
#include "base/command_line.h"
#include "base/macros.h"
@@ -33,6 +34,26 @@
namespace content {
namespace {
+class FixedReceivedData final : public RequestPeer::ReceivedData {
+ public:
+ FixedReceivedData(const char* payload, int length, int encoded_length)
+ : data_(&payload[0], &payload[length]), encoded_length_(encoded_length) {}
+ ~FixedReceivedData() override {}
+
+ const char* payload() const override {
+ // TODO(yhirano): Use |data_.data()| when we can use c++11.
+ return data_.empty() ? nullptr : &data_[0];
+ }
+ int length() const override { return data_.size(); }
+ int encoded_length() const override { return encoded_length_; }
+
+ private:
+ const std::vector<char> data_;
+ const int encoded_length_;
+
+ DISALLOW_COPY_AND_ASSIGN(FixedReceivedData);
+};
+
const char kTestURL[] = "http://foo";
const char kTestData[] = "blah!";
@@ -285,7 +306,8 @@ class WebURLLoaderImplTest : public testing::Test {
// Assumes it is called only once for a request.
void DoReceiveData() {
EXPECT_EQ("", client()->received_data());
- peer()->OnReceivedData(kTestData, strlen(kTestData), strlen(kTestData));
+ peer()->OnReceivedData(make_scoped_ptr(new FixedReceivedData(
+ kTestData, strlen(kTestData), strlen(kTestData))));
EXPECT_EQ(kTestData, client()->received_data());
}
@@ -317,8 +339,8 @@ class WebURLLoaderImplTest : public testing::Test {
}
void DoReceiveDataFtp() {
- peer()->OnReceivedData(kFtpDirListing, strlen(kFtpDirListing),
- strlen(kFtpDirListing));
+ peer()->OnReceivedData(make_scoped_ptr(new FixedReceivedData(
+ kFtpDirListing, strlen(kFtpDirListing), strlen(kFtpDirListing))));
// The FTP delegate should modify the data the client sees.
EXPECT_NE(kFtpDirListing, client()->received_data());
}
@@ -335,8 +357,9 @@ class WebURLLoaderImplTest : public testing::Test {
}
void DoReceiveDataMultipart() {
- peer()->OnReceivedData(kMultipartResponse, strlen(kMultipartResponse),
- strlen(kMultipartResponse));
+ peer()->OnReceivedData(make_scoped_ptr(
+ new FixedReceivedData(kMultipartResponse, strlen(kMultipartResponse),
+ strlen(kMultipartResponse))));
// Multipart delegate should modify the data the client sees.
EXPECT_NE(kMultipartResponse, client()->received_data());
}

Powered by Google App Engine
This is Rietveld 408576698