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

Unified Diff: webkit/glue/multipart_response_delegate_unittest.cc

Issue 6771043: Enabled actual transfer size in chromium (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fixed nits Created 9 years, 9 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: webkit/glue/multipart_response_delegate_unittest.cc
diff --git a/webkit/glue/multipart_response_delegate_unittest.cc b/webkit/glue/multipart_response_delegate_unittest.cc
index c48c2debb182510f556d32f2cecaa70f1fbca0f6..dc5274752fcb90c5d402ce64e92a749746113115 100644
--- a/webkit/glue/multipart_response_delegate_unittest.cc
+++ b/webkit/glue/multipart_response_delegate_unittest.cc
@@ -74,6 +74,7 @@ class MockWebURLLoaderClient : public WebURLLoaderClient {
int length_received) {
++received_data_;
data_.append(data, data_length);
+ length_received_ += length_received;
}
// FIXME(vsevik): remove once removed in webkit
@@ -87,7 +88,7 @@ class MockWebURLLoaderClient : public WebURLLoaderClient {
virtual void didFail(WebURLLoader*, const WebURLError&) {}
void Reset() {
- received_response_ = received_data_ = 0;
+ received_response_ = received_data_ = length_received_ = 0;
data_.clear();
response_.reset();
}
@@ -96,7 +97,7 @@ class MockWebURLLoaderClient : public WebURLLoaderClient {
return string(response_.httpHeaderField(WebString::fromUTF8(name)).utf8());
}
- int received_response_, received_data_;
+ int received_response_, received_data_, length_received_;
string data_;
WebURLResponse response_;
};
@@ -225,11 +226,13 @@ TEST(MultipartResponseTest, MissingBoundaries) {
"--bound--"
"ignore junk after end token --bound\n\nTest2\n");
delegate.OnReceivedData(no_start_boundary.c_str(),
+ static_cast<int>(no_start_boundary.length()),
static_cast<int>(no_start_boundary.length()));
EXPECT_EQ(1, client.received_response_);
EXPECT_EQ(1, client.received_data_);
- EXPECT_EQ(string("This is a sample response"),
- client.data_);
+ EXPECT_EQ(string("This is a sample response"), client.data_);
+ EXPECT_EQ(static_cast<int>(no_start_boundary.length()),
+ client.length_received_);
delegate.OnCompletedRequest();
EXPECT_EQ(1, client.received_response_);
@@ -242,16 +245,20 @@ TEST(MultipartResponseTest, MissingBoundaries) {
"bound\nContent-type: text/plain\n\n"
"This is a sample response\n");
delegate2.OnReceivedData(no_end_boundary.c_str(),
+ static_cast<int>(no_end_boundary.length()),
static_cast<int>(no_end_boundary.length()));
EXPECT_EQ(1, client.received_response_);
EXPECT_EQ(1, client.received_data_);
EXPECT_EQ("This is a sample response\n", client.data_);
+ EXPECT_EQ(static_cast<int>(no_end_boundary.length()),
+ client.length_received_);
delegate2.OnCompletedRequest();
EXPECT_EQ(1, client.received_response_);
EXPECT_EQ(1, client.received_data_);
- EXPECT_EQ(string("This is a sample response\n"),
- client.data_);
+ EXPECT_EQ(string("This is a sample response\n"), client.data_);
+ EXPECT_EQ(static_cast<int>(no_end_boundary.length()),
+ client.length_received_);
// Neither boundary
client.Reset();
@@ -260,16 +267,18 @@ TEST(MultipartResponseTest, MissingBoundaries) {
"Content-type: text/plain\n\n"
"This is a sample response\n");
delegate3.OnReceivedData(no_boundaries.c_str(),
+ static_cast<int>(no_boundaries.length()),
static_cast<int>(no_boundaries.length()));
EXPECT_EQ(1, client.received_response_);
EXPECT_EQ(1, client.received_data_);
EXPECT_EQ("This is a sample response\n", client.data_);
+ EXPECT_EQ(static_cast<int>(no_boundaries.length()), client.length_received_);
delegate3.OnCompletedRequest();
EXPECT_EQ(1, client.received_response_);
EXPECT_EQ(1, client.received_data_);
- EXPECT_EQ(string("This is a sample response\n"),
- client.data_);
+ EXPECT_EQ(string("This is a sample response\n"), client.data_);
+ EXPECT_EQ(static_cast<int>(no_boundaries.length()), client.length_received_);
}
TEST(MultipartResponseTest, MalformedBoundary) {
@@ -289,10 +298,13 @@ TEST(MultipartResponseTest, MalformedBoundary) {
"This is a sample response\n"
"--bound--"
"ignore junk after end token --bound\n\nTest2\n");
- delegate.OnReceivedData(data.c_str(), static_cast<int>(data.length()));
+ delegate.OnReceivedData(data.c_str(),
+ static_cast<int>(data.length()),
+ static_cast<int>(data.length()));
EXPECT_EQ(1, client.received_response_);
EXPECT_EQ(1, client.received_data_);
EXPECT_EQ(string("This is a sample response"), client.data_);
+ EXPECT_EQ(static_cast<int>(data.length()), client.length_received_);
delegate.OnCompletedRequest();
EXPECT_EQ(1, client.received_response_);
@@ -307,11 +319,13 @@ struct TestChunk {
const int expected_responses;
const int expected_received_data;
const char* expected_data;
+ const int expected_length_received;
};
void VariousChunkSizesTest(const TestChunk chunks[], int chunks_size,
int responses, int received_data,
- const char* completed_data) {
+ const char* completed_data,
+ int completed_length_received) {
const string data(
"--bound\n" // 0-7
"Content-type: image/png\n\n" // 8-32
@@ -331,106 +345,106 @@ void VariousChunkSizesTest(const TestChunk chunks[], int chunks_size,
ASSERT_TRUE(chunks[i].start_pos < chunks[i].end_pos);
string chunk = data.substr(chunks[i].start_pos,
chunks[i].end_pos - chunks[i].start_pos);
- delegate.OnReceivedData(chunk.c_str(), static_cast<int>(chunk.length()));
- EXPECT_EQ(chunks[i].expected_responses,
- client.received_response_);
- EXPECT_EQ(chunks[i].expected_received_data,
- client.received_data_);
- EXPECT_EQ(string(chunks[i].expected_data),
- client.data_);
+ delegate.OnReceivedData(
+ chunk.c_str(),
+ static_cast<int>(chunk.length()),
+ static_cast<int>(chunk.length()));
+ EXPECT_EQ(chunks[i].expected_responses, client.received_response_);
+ EXPECT_EQ(chunks[i].expected_received_data, client.received_data_);
+ EXPECT_EQ(string(chunks[i].expected_data), client.data_);
+ EXPECT_EQ(chunks[i].expected_length_received, client.length_received_);
}
// Check final state
delegate.OnCompletedRequest();
- EXPECT_EQ(responses,
- client.received_response_);
- EXPECT_EQ(received_data,
- client.received_data_);
- EXPECT_EQ(string(completed_data),
- client.data_);
+ EXPECT_EQ(responses, client.received_response_);
+ EXPECT_EQ(received_data, client.received_data_);
+ string completed_data_string(completed_data);
+ EXPECT_EQ(completed_data_string, client.data_);
+ EXPECT_EQ(completed_length_received, client.length_received_);
}
TEST(MultipartResponseTest, BreakInBoundary) {
// Break in the first boundary
const TestChunk bound1[] = {
- { 0, 4, 0, 0, ""},
- { 4, 110, 2, 2, "foofoofoofoofoo" },
+ { 0, 4, 0, 0, "", 0 },
+ { 4, 110, 2, 2, "foofoofoofoofoo", 110 },
};
VariousChunkSizesTest(bound1, arraysize(bound1),
- 2, 2, "foofoofoofoofoo");
+ 2, 2, "foofoofoofoofoo", 110);
// Break in first and second
const TestChunk bound2[] = {
- { 0, 4, 0, 0, ""},
- { 4, 55, 1, 1, "datadatadatadat" },
- { 55, 65, 1, 2, "datadatadatadatadata" },
- { 65, 110, 2, 3, "foofoofoofoofoo" },
+ { 0, 4, 0, 0, "", 0 },
+ { 4, 55, 1, 1, "datadatadatadat", 55 },
+ { 55, 65, 1, 2, "datadatadatadatadata", 65 },
+ { 65, 110, 2, 3, "foofoofoofoofoo", 110 },
};
VariousChunkSizesTest(bound2, arraysize(bound2),
- 2, 3, "foofoofoofoofoo");
+ 2, 3, "foofoofoofoofoo", 110);
// Break in second only
const TestChunk bound3[] = {
- { 0, 55, 1, 1, "datadatadatadat" },
- { 55, 110, 2, 3, "foofoofoofoofoo" },
+ { 0, 55, 1, 1, "datadatadatadat", 55 },
+ { 55, 110, 2, 3, "foofoofoofoofoo", 110 },
};
VariousChunkSizesTest(bound3, arraysize(bound3),
- 2, 3, "foofoofoofoofoo");
+ 2, 3, "foofoofoofoofoo", 110);
}
TEST(MultipartResponseTest, BreakInHeaders) {
// Break in first header
const TestChunk header1[] = {
- { 0, 10, 0, 0, "" },
- { 10, 35, 1, 0, "" },
- { 35, 110, 2, 2, "foofoofoofoofoo" },
+ { 0, 10, 0, 0, "", 0 },
+ { 10, 35, 1, 0, "", 0 },
+ { 35, 110, 2, 2, "foofoofoofoofoo", 110 },
};
VariousChunkSizesTest(header1, arraysize(header1),
- 2, 2, "foofoofoofoofoo");
+ 2, 2, "foofoofoofoofoo", 110);
// Break in both headers
const TestChunk header2[] = {
- { 0, 10, 0, 0, "" },
- { 10, 65, 1, 1, "datadatadatadatadata" },
- { 65, 110, 2, 2, "foofoofoofoofoo" },
+ { 0, 10, 0, 0, "", 0 },
+ { 10, 65, 1, 1, "datadatadatadatadata", 65 },
+ { 65, 110, 2, 2, "foofoofoofoofoo", 110 },
};
VariousChunkSizesTest(header2, arraysize(header2),
- 2, 2, "foofoofoofoofoo");
+ 2, 2, "foofoofoofoofoo", 110);
// Break at end of a header
const TestChunk header3[] = {
- { 0, 33, 1, 0, "" },
- { 33, 65, 1, 1, "datadatadatadatadata" },
- { 65, 110, 2, 2, "foofoofoofoofoo" },
+ { 0, 33, 1, 0, "", 0 },
+ { 33, 65, 1, 1, "datadatadatadatadata", 65 },
+ { 65, 110, 2, 2, "foofoofoofoofoo", 110 },
};
VariousChunkSizesTest(header3, arraysize(header3),
- 2, 2, "foofoofoofoofoo");
+ 2, 2, "foofoofoofoofoo", 110);
}
TEST(MultipartResponseTest, BreakInData) {
// All data as one chunk
const TestChunk data1[] = {
- { 0, 110, 2, 2, "foofoofoofoofoo" },
+ { 0, 110, 2, 2, "foofoofoofoofoo", 110 },
};
VariousChunkSizesTest(data1, arraysize(data1),
- 2, 2, "foofoofoofoofoo");
+ 2, 2, "foofoofoofoofoo", 110);
// breaks in data segment
const TestChunk data2[] = {
- { 0, 35, 1, 0, "" },
- { 35, 65, 1, 1, "datadatadatadatadata" },
- { 65, 90, 2, 1, "" },
- { 90, 110, 2, 2, "foofoofoofoofoo" },
+ { 0, 35, 1, 0, "", 0 },
+ { 35, 65, 1, 1, "datadatadatadatadata", 65 },
+ { 65, 90, 2, 1, "", 65 },
+ { 90, 110, 2, 2, "foofoofoofoofoo", 110 },
};
VariousChunkSizesTest(data2, arraysize(data2),
- 2, 2, "foofoofoofoofoo");
+ 2, 2, "foofoofoofoofoo", 110);
// Incomplete send
const TestChunk data3[] = {
- { 0, 35, 1, 0, "" },
- { 35, 90, 2, 1, "" },
+ { 0, 35, 1, 0, "", 0 },
+ { 35, 90, 2, 1, "", 90 },
};
VariousChunkSizesTest(data3, arraysize(data3),
- 2, 2, "foof");
+ 2, 2, "foof", 90);
}
TEST(MultipartResponseTest, SmallChunk) {
@@ -449,10 +463,12 @@ TEST(MultipartResponseTest, SmallChunk) {
"--boundContent-type: text/plain\n\n"
"end--bound--");
delegate.OnReceivedData(data.c_str(),
+ static_cast<int>(data.length()),
static_cast<int>(data.length()));
EXPECT_EQ(4, client.received_response_);
EXPECT_EQ(2, client.received_data_);
EXPECT_EQ(string("end"), client.data_);
+ EXPECT_EQ(static_cast<int>(data.length()), client.length_received_);
delegate.OnCompletedRequest();
EXPECT_EQ(4, client.received_response_);
@@ -468,13 +484,13 @@ TEST(MultipartResponseTest, MultipleBoundaries) {
MultipartResponseDelegate delegate(&client, NULL, response, "bound");
string data("--bound\r\n\r\n--bound\r\n\r\nfoofoo--bound--");
- delegate.OnReceivedData(data.c_str(), static_cast<int>(data.length()));
- EXPECT_EQ(2,
- client.received_response_);
- EXPECT_EQ(1,
- client.received_data_);
- EXPECT_EQ(string("foofoo"),
- client.data_);
+ delegate.OnReceivedData(data.c_str(),
+ static_cast<int>(data.length()),
+ static_cast<int>(data.length()));
+ EXPECT_EQ(2, client.received_response_);
+ EXPECT_EQ(1, client.received_data_);
+ EXPECT_EQ(string("foofoo"), client.data_);
+ EXPECT_EQ(static_cast<int>(data.length()), client.length_received_);
}
TEST(MultipartResponseTest, MultipartByteRangeParsingTest) {
@@ -637,22 +653,25 @@ TEST(MultipartResponseTest, MultipartPayloadSet) {
"Content-type: text/plain\n\n"
"response data\n"
"--bound\n");
- delegate.OnReceivedData(data.c_str(), static_cast<int>(data.length()));
- EXPECT_EQ(1,
- client.received_response_);
- EXPECT_EQ(string("response data"),
- client.data_);
+ delegate.OnReceivedData(data.c_str(),
+ static_cast<int>(data.length()),
+ static_cast<int>(data.length()));
+ EXPECT_EQ(1, client.received_response_);
+ EXPECT_EQ(string("response data"), client.data_);
+ EXPECT_EQ(static_cast<int>(data.length()), client.length_received_);
EXPECT_FALSE(client.response_.isMultipartPayload());
string data2(
"Content-type: text/plain\n\n"
"response data2\n"
"--bound\n");
- delegate.OnReceivedData(data2.c_str(), static_cast<int>(data2.length()));
- EXPECT_EQ(2,
- client.received_response_);
- EXPECT_EQ(string("response data2"),
- client.data_);
+ delegate.OnReceivedData(data2.c_str(),
+ static_cast<int>(data2.length()),
+ static_cast<int>(data2.length()));
+ EXPECT_EQ(2, client.received_response_);
+ EXPECT_EQ(string("response data2"), client.data_);
+ EXPECT_EQ(static_cast<int>(data.length()) + static_cast<int>(data2.length()),
+ client.length_received_);
EXPECT_TRUE(client.response_.isMultipartPayload());
}

Powered by Google App Engine
This is Rietveld 408576698