summaryrefslogtreecommitdiffstats
path: root/webkit/glue/multipart_response_delegate_unittest.cc
diff options
context:
space:
mode:
authordarin@chromium.org <darin@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-06-09 18:45:04 +0000
committerdarin@chromium.org <darin@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-06-09 18:45:04 +0000
commitf92eb0034a4b0a8249f739df38b82add5e36044f (patch)
treed7749b8bf473f61d86a50ce04736950d1862c574 /webkit/glue/multipart_response_delegate_unittest.cc
parentb72eb73e72040cdaaa8957ca7a7417f9b89843fe (diff)
downloadchromium_src-f92eb0034a4b0a8249f739df38b82add5e36044f.zip
chromium_src-f92eb0034a4b0a8249f739df38b82add5e36044f.tar.gz
chromium_src-f92eb0034a4b0a8249f739df38b82add5e36044f.tar.bz2
Start using WebURLLoader, et. al. from the WebKit API.
Moves our ResourceHandle to webkit/api/src/ResourceHandle.cpp from webkit/glue/resource_handle_impl.cc. A portion of resource_handle_impl.cc was moved into weburlloader_impl.{h,cc}, which now contains our implementation of WebURLLoader. The annoying parts of this CL involve WebPluginImpl. I had to convert it over to using WebURLLoader instead of ResourceHandle so that MultipartResourceDelegate can be shared. There is some complexity in WebURLRequest / WebURLResponse to make it cheap to wrap a ResourceRequest / ResourceResponse. I think this is worth it since there is a lot of conversion between the two types. Originally reviewed here: http://codereview.chromium.org/113928 BUG=10038 TEST=covered by existing tests R=dglazkov Review URL: http://codereview.chromium.org/118438 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@17962 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'webkit/glue/multipart_response_delegate_unittest.cc')
-rw-r--r--webkit/glue/multipart_response_delegate_unittest.cc278
1 files changed, 167 insertions, 111 deletions
diff --git a/webkit/glue/multipart_response_delegate_unittest.cc b/webkit/glue/multipart_response_delegate_unittest.cc
index e05879d..df47529 100644
--- a/webkit/glue/multipart_response_delegate_unittest.cc
+++ b/webkit/glue/multipart_response_delegate_unittest.cc
@@ -4,71 +4,105 @@
#include <vector>
-#include "config.h"
-
-#include "base/compiler_specific.h"
-
-MSVC_PUSH_WARNING_LEVEL(0);
-#include "KURL.h"
-#include "ResourceResponse.h"
-#include "ResourceHandle.h"
-#include "ResourceHandleClient.h"
-MSVC_POP_WARNING();
-
#include "base/basictypes.h"
+#include "webkit/api/public/WebString.h"
+#include "webkit/api/public/WebURL.h"
+#include "webkit/api/public/WebURLLoaderClient.h"
+#include "webkit/api/public/WebURLResponse.h"
#include "webkit/glue/glue_util.h"
#include "webkit/glue/multipart_response_delegate.h"
#include "testing/gtest/include/gtest/gtest.h"
-using namespace WebCore;
-using namespace std;
+using std::string;
+using WebKit::WebString;
+using WebKit::WebURL;
+using WebKit::WebURLError;
+using WebKit::WebURLLoader;
+using WebKit::WebURLLoaderClient;
+using WebKit::WebURLRequest;
+using WebKit::WebURLResponse;
+using webkit_glue::MultipartResponseDelegate;
+using webkit_glue::MultipartResponseDelegateTester;
+
+namespace webkit_glue {
+
+class MultipartResponseDelegateTester {
+ public:
+ MultipartResponseDelegateTester(MultipartResponseDelegate* delegate)
+ : delegate_(delegate) {
+ }
+
+ int PushOverLine(const std::string& data, size_t pos) {
+ return delegate_->PushOverLine(data, pos);
+ }
+
+ bool ParseHeaders() { return delegate_->ParseHeaders(); }
+ size_t FindBoundary() { return delegate_->FindBoundary(); }
+ std::string& boundary() { return delegate_->boundary_; }
+ std::string& data() { return delegate_->data_; }
+
+ private:
+ MultipartResponseDelegate* delegate_;
+};
+
+} // namespace webkit_glue
namespace {
class MultipartResponseTest : public testing::Test {
};
-class MockResourceHandleClient : public ResourceHandleClient {
+class MockWebURLLoaderClient : public WebURLLoaderClient {
public:
- MockResourceHandleClient() { Reset(); }
+ MockWebURLLoaderClient() { Reset(); }
- virtual void didReceiveResponse(ResourceHandle* handle,
- const ResourceResponse& response) {
+ virtual void willSendRequest(
+ WebURLLoader*, WebURLRequest&, const WebURLResponse&) {}
+ virtual void didSendData(
+ WebURLLoader*, unsigned long long, unsigned long long) {}
+
+ virtual void didReceiveResponse(WebURLLoader* loader,
+ const WebURLResponse& response) {
++received_response_;
- resource_response_ = response;
+ response_ = response;
data_.clear();
}
- virtual void didReceiveData(ResourceHandle* handle,
+ virtual void didReceiveData(WebURLLoader* loader,
const char* data, int data_length,
- int length_received) {
+ long long length_received) {
++received_data_;
data_.append(data, data_length);
}
+ virtual void didFinishLoading(WebURLLoader*) {}
+ virtual void didFail(WebURLLoader*, const WebURLError&) {}
+
void Reset() {
received_response_ = received_data_ = 0;
data_.clear();
- resource_response_ = ResourceResponse();
+ response_.reset();
}
int received_response_, received_data_;
string data_;
- ResourceResponse resource_response_;
+ WebURLResponse response_;
};
-} // namespace
-
// We can't put this in an anonymous function because it's a friend class for
// access to private members.
TEST(MultipartResponseTest, Functions) {
// PushOverLine tests
- ResourceResponse response(KURL(), "multipart/x-mixed-replace", 0, "en-US",
- String());
- response.setHTTPHeaderField(String("Foo"), String("Bar"));
- response.setHTTPHeaderField(String("Content-type"), String("text/plain"));
- MockResourceHandleClient client;
+ WebURLResponse response;
+ response.initialize();
+ response.setMIMEType(WebString::fromUTF8("multipart/x-mixed-replace"));
+ response.setHTTPHeaderField(WebString::fromUTF8("Foo"),
+ WebString::fromUTF8("Bar"));
+ response.setHTTPHeaderField(WebString::fromUTF8("Content-type"),
+ WebString::fromUTF8("text/plain"));
+ MockWebURLLoaderClient client;
MultipartResponseDelegate delegate(&client, NULL, response, "bound");
+ MultipartResponseDelegateTester delegate_tester(&delegate);
struct {
const char* input;
@@ -90,8 +124,8 @@ TEST(MultipartResponseTest, Functions) {
};
for (size_t i = 0; i < ARRAYSIZE_UNSAFE(line_tests); ++i) {
EXPECT_EQ(line_tests[i].expected,
- delegate.PushOverLine(line_tests[i].input,
- line_tests[i].position));
+ delegate_tester.PushOverLine(line_tests[i].input,
+ line_tests[i].position));
}
// ParseHeaders tests
@@ -112,33 +146,33 @@ TEST(MultipartResponseTest, Functions) {
};
for (size_t i = 0; i < ARRAYSIZE_UNSAFE(header_tests); ++i) {
client.Reset();
- delegate.data_.assign(header_tests[i].data);
+ delegate_tester.data().assign(header_tests[i].data);
EXPECT_EQ(header_tests[i].rv,
- delegate.ParseHeaders());
+ delegate_tester.ParseHeaders());
EXPECT_EQ(header_tests[i].received_response_calls,
client.received_response_);
EXPECT_EQ(string(header_tests[i].newdata),
- delegate.data_);
+ delegate_tester.data());
}
// Test that the resource response is filled in correctly when parsing
// headers.
client.Reset();
string test_header("content-type: image/png\ncontent-length: 10\n\n");
- delegate.data_.assign(test_header);
- EXPECT_TRUE(delegate.ParseHeaders());
- EXPECT_TRUE(delegate.data_.length() == 0);
- EXPECT_EQ(webkit_glue::StringToStdWString(
- client.resource_response_.httpHeaderField(
- String("Content-Type"))),
- wstring(L"image/png"));
- EXPECT_EQ(webkit_glue::StringToStdWString(
- client.resource_response_.httpHeaderField(
- String("content-length"))),
- wstring(L"10"));
+ delegate_tester.data().assign(test_header);
+ EXPECT_TRUE(delegate_tester.ParseHeaders());
+ EXPECT_TRUE(delegate_tester.data().length() == 0);
+ EXPECT_EQ(webkit_glue::WebStringToStdString(
+ client.response_.httpHeaderField(
+ WebString::fromUTF8("Content-Type"))),
+ string("image/png"));
+ EXPECT_EQ(webkit_glue::WebStringToStdString(
+ client.response_.httpHeaderField(
+ WebString::fromUTF8("content-length"))),
+ string("10"));
// This header is passed from the original request.
- EXPECT_EQ(webkit_glue::StringToStdWString(
- client.resource_response_.httpHeaderField(String("foo"))),
- wstring(L"Bar"));
+ EXPECT_EQ(webkit_glue::WebStringToStdString(
+ client.response_.httpHeaderField(WebString::fromUTF8("foo"))),
+ string("Bar"));
// FindBoundary tests
struct {
@@ -154,21 +188,22 @@ TEST(MultipartResponseTest, Functions) {
{ "bound", "--boundbound", 0 },
};
for (size_t i = 0; i < ARRAYSIZE_UNSAFE(boundary_tests); ++i) {
- delegate.boundary_.assign(boundary_tests[i].boundary);
- delegate.data_.assign(boundary_tests[i].data);
+ delegate_tester.boundary().assign(boundary_tests[i].boundary);
+ delegate_tester.data().assign(boundary_tests[i].data);
EXPECT_EQ(boundary_tests[i].position,
- delegate.FindBoundary());
+ delegate_tester.FindBoundary());
}
}
-namespace {
-
TEST(MultipartResponseTest, MissingBoundaries) {
- ResourceResponse response(KURL(), "multipart/x-mixed-replace", 0, "en-US",
- String());
- response.setHTTPHeaderField(String("Foo"), String("Bar"));
- response.setHTTPHeaderField(String("Content-type"), String("text/plain"));
- MockResourceHandleClient client;
+ WebURLResponse response;
+ response.initialize();
+ response.setMIMEType(WebString::fromUTF8("multipart/x-mixed-replace"));
+ response.setHTTPHeaderField(WebString::fromUTF8("Foo"),
+ WebString::fromUTF8("Bar"));
+ response.setHTTPHeaderField(WebString::fromUTF8("Content-type"),
+ WebString::fromUTF8("text/plain"));
+ MockWebURLLoaderClient client;
MultipartResponseDelegate delegate(&client, NULL, response, "bound");
// No start boundary
@@ -228,11 +263,14 @@ TEST(MultipartResponseTest, MissingBoundaries) {
TEST(MultipartResponseTest, MalformedBoundary) {
// Some servers send a boundary that is prefixed by "--". See bug 5786.
- ResourceResponse response(KURL(), "multipart/x-mixed-replace", 0, "en-US",
- String());
- response.setHTTPHeaderField(String("Foo"), String("Bar"));
- response.setHTTPHeaderField(String("Content-type"), String("text/plain"));
- MockResourceHandleClient client;
+ WebURLResponse response;
+ response.initialize();
+ response.setMIMEType(WebString::fromUTF8("multipart/x-mixed-replace"));
+ response.setHTTPHeaderField(WebString::fromUTF8("Foo"),
+ WebString::fromUTF8("Bar"));
+ response.setHTTPHeaderField(WebString::fromUTF8("Content-type"),
+ WebString::fromUTF8("text/plain"));
+ MockWebURLLoaderClient client;
MultipartResponseDelegate delegate(&client, NULL, response, "--bound");
string data(
@@ -272,13 +310,14 @@ void VariousChunkSizesTest(const TestChunk chunks[], int chunks_size, int respon
"foofoofoofoofoo" // 86-100
"--bound--"); // 101-109
- ResourceResponse response(KURL(), "multipart/x-mixed-replace", 0, "en-US",
- String());
- MockResourceHandleClient client;
+ WebURLResponse response;
+ response.initialize();
+ response.setMIMEType(WebString::fromUTF8("multipart/x-mixed-replace"));
+ MockWebURLLoaderClient client;
MultipartResponseDelegate delegate(&client, NULL, response, "bound");
for (int i = 0; i < chunks_size; ++i) {
- ASSERT(chunks[i].start_pos < chunks[i].end_pos);
+ 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()));
@@ -385,9 +424,10 @@ TEST(MultipartResponseTest, BreakInData) {
TEST(MultipartResponseTest, MultipleBoundaries) {
// Test multiple boundaries back to back
- ResourceResponse response(KURL(), "multipart/x-mixed-replace", 0, "en-US",
- String());
- MockResourceHandleClient client;
+ WebURLResponse response;
+ response.initialize();
+ response.setMIMEType(WebString::fromUTF8("multipart/x-mixed-replace"));
+ MockWebURLLoaderClient client;
MultipartResponseDelegate delegate(&client, NULL, response, "bound");
string data("--bound\r\n\r\n--bound\r\n\r\nfoofoo--bound--");
@@ -402,12 +442,14 @@ TEST(MultipartResponseTest, MultipleBoundaries) {
TEST(MultipartResponseTest, MultipartByteRangeParsingTest) {
// Test multipart/byteranges based boundary parsing.
- ResourceResponse response1(KURL(), "multipart/byteranges", 0, "en-US",
- String());
- response1.setHTTPHeaderField(String("Content-Length"), String("200"));
+ WebURLResponse response1;
+ response1.initialize();
+ response1.setMIMEType(WebString::fromUTF8("multipart/x-mixed-replace"));
+ response1.setHTTPHeaderField(WebString::fromUTF8("Content-Length"),
+ WebString::fromUTF8("200"));
response1.setHTTPHeaderField(
- String("Content-type"),
- String("multipart/byteranges; boundary=--bound--"));
+ WebString::fromUTF8("Content-type"),
+ WebString::fromUTF8("multipart/byteranges; boundary=--bound--"));
std::string multipart_boundary;
bool result = MultipartResponseDelegate::ReadMultipartBoundary(
@@ -416,35 +458,39 @@ TEST(MultipartResponseTest, MultipartByteRangeParsingTest) {
EXPECT_EQ(string("--bound--"),
multipart_boundary);
- ResourceResponse response2(KURL(), "image/png", 0, "en-US",
- String());
+ WebURLResponse response2;
+ response2.initialize();
+ response2.setMIMEType(WebString::fromUTF8("image/png"));
- response2.setHTTPHeaderField(String("Content-Length"), String("300"));
+ response2.setHTTPHeaderField(WebString::fromUTF8("Content-Length"),
+ WebString::fromUTF8("300"));
response2.setHTTPHeaderField(
- String("Last-Modified"),
- String("Mon, 04 Apr 2005 20:36:01 GMT"));
+ WebString::fromUTF8("Last-Modified"),
+ WebString::fromUTF8("Mon, 04 Apr 2005 20:36:01 GMT"));
response2.setHTTPHeaderField(
- String("Date"),
- String("Thu, 11 Sep 2008 18:21:42 GMT"));
+ WebString::fromUTF8("Date"),
+ WebString::fromUTF8("Thu, 11 Sep 2008 18:21:42 GMT"));
multipart_boundary.clear();
result = MultipartResponseDelegate::ReadMultipartBoundary(
response2, &multipart_boundary);
EXPECT_EQ(result, false);
- ResourceResponse response3(KURL(), "multipart/byteranges", 0, "en-US",
- String());
+ WebURLResponse response3;
+ response3.initialize();
+ response3.setMIMEType(WebString::fromUTF8("multipart/byteranges"));
- response3.setHTTPHeaderField(String("Content-Length"), String("300"));
+ response3.setHTTPHeaderField(WebString::fromUTF8("Content-Length"),
+ WebString::fromUTF8("300"));
response3.setHTTPHeaderField(
- String("Last-Modified"),
- String("Mon, 04 Apr 2005 20:36:01 GMT"));
+ WebString::fromUTF8("Last-Modified"),
+ WebString::fromUTF8("Mon, 04 Apr 2005 20:36:01 GMT"));
response3.setHTTPHeaderField(
- String("Date"),
- String("Thu, 11 Sep 2008 18:21:42 GMT"));
+ WebString::fromUTF8("Date"),
+ WebString::fromUTF8("Thu, 11 Sep 2008 18:21:42 GMT"));
response3.setHTTPHeaderField(
- String("Content-type"),
- String("multipart/byteranges"));
+ WebString::fromUTF8("Content-type"),
+ WebString::fromUTF8("multipart/byteranges"));
multipart_boundary.clear();
result = MultipartResponseDelegate::ReadMultipartBoundary(
@@ -452,12 +498,15 @@ TEST(MultipartResponseTest, MultipartByteRangeParsingTest) {
EXPECT_EQ(result, false);
EXPECT_EQ(multipart_boundary.length(), 0U);
- ResourceResponse response4(KURL(), "multipart/byteranges", 0, "en-US",
- String());
- response4.setHTTPHeaderField(String("Content-Length"), String("200"));
+ WebURLResponse response4;
+ response4.initialize();
+ response4.setMIMEType(WebString::fromUTF8("multipart/byteranges"));
+ response4.setHTTPHeaderField(WebString::fromUTF8("Content-Length"),
+ WebString::fromUTF8("200"));
response4.setHTTPHeaderField(
- String("Content-type"),
- String("multipart/byteranges; boundary=--bound--; charSet=utf8"));
+ WebString::fromUTF8("Content-type"),
+ WebString::fromUTF8(
+ "multipart/byteranges; boundary=--bound--; charSet=utf8"));
multipart_boundary.clear();
@@ -466,12 +515,15 @@ TEST(MultipartResponseTest, MultipartByteRangeParsingTest) {
EXPECT_EQ(result, true);
EXPECT_EQ(string("--bound--"), multipart_boundary);
- ResourceResponse response5(KURL(), "multipart/byteranges", 0, "en-US",
- String());
- response5.setHTTPHeaderField(String("Content-Length"), String("200"));
+ WebURLResponse response5;
+ response5.initialize();
+ response5.setMIMEType(WebString::fromUTF8("multipart/byteranges"));
+ response5.setHTTPHeaderField(WebString::fromUTF8("Content-Length"),
+ WebString::fromUTF8("200"));
response5.setHTTPHeaderField(
- String("Content-type"),
- String("multipart/byteranges; boundary=\"--bound--\"; charSet=utf8"));
+ WebString::fromUTF8("Content-type"),
+ WebString::fromUTF8(
+ "multipart/byteranges; boundary=\"--bound--\"; charSet=utf8"));
multipart_boundary.clear();
@@ -482,12 +534,14 @@ TEST(MultipartResponseTest, MultipartByteRangeParsingTest) {
}
TEST(MultipartResponseTest, MultipartContentRangesTest) {
- ResourceResponse response1(KURL(), "application/pdf", 0, "en-US",
- String());
- response1.setHTTPHeaderField(String("Content-Length"), String("200"));
+ WebURLResponse response1;
+ response1.initialize();
+ response1.setMIMEType(WebString::fromUTF8("application/pdf"));
+ response1.setHTTPHeaderField(WebString::fromUTF8("Content-Length"),
+ WebString::fromUTF8("200"));
response1.setHTTPHeaderField(
- String("Content-Range"),
- String("bytes 1000-1050/5000"));
+ WebString::fromUTF8("Content-Range"),
+ WebString::fromUTF8("bytes 1000-1050/5000"));
int content_range_lower_bound = 0;
int content_range_upper_bound = 0;
@@ -500,12 +554,14 @@ TEST(MultipartResponseTest, MultipartContentRangesTest) {
EXPECT_EQ(content_range_lower_bound, 1000);
EXPECT_EQ(content_range_upper_bound, 1050);
- ResourceResponse response2(KURL(), "application/pdf", 0, "en-US",
- String());
- response2.setHTTPHeaderField(String("Content-Length"), String("200"));
+ WebURLResponse response2;
+ response2.initialize();
+ response2.setMIMEType(WebString::fromUTF8("application/pdf"));
+ response2.setHTTPHeaderField(WebString::fromUTF8("Content-Length"),
+ WebString::fromUTF8("200"));
response2.setHTTPHeaderField(
- String("Content-Range"),
- String("bytes 1000/1050"));
+ WebString::fromUTF8("Content-Range"),
+ WebString::fromUTF8("bytes 1000/1050"));
content_range_lower_bound = 0;
content_range_upper_bound = 0;