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 5284b1de5376cd2c72e12a327afc707c1db7bba8..72b3aee0489ad5145775e37c8edc8bfcbbaa4be6 100644 |
--- a/content/child/web_url_loader_impl_unittest.cc |
+++ b/content/child/web_url_loader_impl_unittest.cc |
@@ -24,6 +24,7 @@ |
#include "content/child/request_extra_data.h" |
#include "content/child/request_info.h" |
#include "content/child/resource_dispatcher.h" |
+#include "content/child/sync_load_response.h" |
#include "content/public/child/fixed_received_data.h" |
#include "content/public/child/request_peer.h" |
#include "content/public/common/content_switches.h" |
@@ -67,6 +68,12 @@ class TestResourceDispatcher : public ResourceDispatcher { |
// TestDispatcher implementation: |
+ void StartSync(const RequestInfo& request_info, |
+ ResourceRequestBodyImpl* request_body, |
+ SyncLoadResponse* response) override { |
+ *response = sync_load_response_; |
+ } |
+ |
int StartAsync(const RequestInfo& request_info, |
ResourceRequestBodyImpl* request_body, |
std::unique_ptr<RequestPeer> peer) override { |
@@ -94,12 +101,17 @@ class TestResourceDispatcher : public ResourceDispatcher { |
} |
bool defers_loading() const { return defers_loading_; } |
+ void set_sync_load_response(const SyncLoadResponse& sync_load_response) { |
+ sync_load_response_ = sync_load_response; |
+ } |
+ |
private: |
std::unique_ptr<RequestPeer> peer_; |
bool canceled_; |
bool defers_loading_; |
GURL url_; |
GURL stream_url_; |
+ SyncLoadResponse sync_load_response_; |
DISALLOW_COPY_AND_ASSIGN(TestResourceDispatcher); |
}; |
@@ -124,10 +136,10 @@ class TestWebURLLoaderClient : public blink::WebURLLoaderClient { |
~TestWebURLLoaderClient() override {} |
// blink::WebURLLoaderClient implementation: |
- void willFollowRedirect( |
- blink::WebURLLoader* loader, |
- blink::WebURLRequest& newRequest, |
- const blink::WebURLResponse& redirectResponse) override { |
+ void willFollowRedirect(blink::WebURLLoader* loader, |
+ blink::WebURLRequest& newRequest, |
+ const blink::WebURLResponse& redirectResponse, |
+ int64_t encodedDataLength) override { |
EXPECT_TRUE(loader_); |
EXPECT_EQ(loader_.get(), loader); |
@@ -172,7 +184,8 @@ class TestWebURLLoaderClient : public blink::WebURLLoaderClient { |
void didReceiveData(blink::WebURLLoader* loader, |
const char* data, |
int dataLength, |
- int encodedDataLength) override { |
+ int encodedDataLength, |
+ int encodedBodyLength) override { |
EXPECT_TRUE(loader_); |
EXPECT_EQ(loader_.get(), loader); |
// The response should have started, but must not have finished, or failed. |
@@ -313,8 +326,9 @@ class WebURLLoaderImplTest : public testing::Test { |
// Assumes it is called only once for a request. |
void DoReceiveData() { |
EXPECT_EQ("", client()->received_data()); |
- peer()->OnReceivedData(base::WrapUnique(new FixedReceivedData( |
- kTestData, strlen(kTestData), strlen(kTestData)))); |
+ auto size = strlen(kTestData); |
+ peer()->OnReceivedData( |
+ base::WrapUnique(new FixedReceivedData(kTestData, size, size, size))); |
EXPECT_EQ(kTestData, client()->received_data()); |
} |
@@ -346,8 +360,9 @@ class WebURLLoaderImplTest : public testing::Test { |
} |
void DoReceiveDataFtp() { |
- peer()->OnReceivedData(base::WrapUnique(new FixedReceivedData( |
- kFtpDirListing, strlen(kFtpDirListing), strlen(kFtpDirListing)))); |
+ auto size = strlen(kFtpDirListing); |
+ peer()->OnReceivedData(base::WrapUnique( |
+ new FixedReceivedData(kFtpDirListing, size, size, size))); |
// The FTP delegate should modify the data the client sees. |
EXPECT_NE(kFtpDirListing, client()->received_data()); |
} |
@@ -675,5 +690,30 @@ TEST_F(WebURLLoaderImplTest, ResponseIPAddress) { |
}; |
} |
+// Verifies that the lengths used by the PerformanceResourceTiming API are |
+// correctly assigned for sync XHR. |
+TEST_F(WebURLLoaderImplTest, SyncLengths) { |
+ const GURL url(kTestURL); |
+ blink::WebURLRequest request(url); |
+ |
+ // Prepare a mock response |
+ SyncLoadResponse sync_load_response; |
+ sync_load_response.error_code = net::OK; |
+ sync_load_response.url = url; |
+ sync_load_response.data = "Today is Thursday"; |
+ ASSERT_EQ(17u, sync_load_response.data.size()); |
+ sync_load_response.encoded_body_length = 30; |
+ dispatcher()->set_sync_load_response(sync_load_response); |
+ |
+ blink::WebURLResponse response; |
+ response.initialize(); |
+ blink::WebURLError error; |
+ blink::WebData data; |
+ client()->loader()->loadSynchronously(request, response, error, data); |
+ |
+ EXPECT_EQ(30, response.encodedBodyLength()); |
+ EXPECT_EQ(17, response.decodedBodyLength()); |
kinuko
2016/07/07 05:11:40
nit: Prefer getting this number (17) explicitly fr
Adam Rice
2016/07/07 07:40:01
Done.
|
+} |
+ |
} // namespace |
} // namespace content |