Index: sync/internal_api/http_bridge_unittest.cc |
diff --git a/sync/internal_api/http_bridge_unittest.cc b/sync/internal_api/http_bridge_unittest.cc |
index 3c6db88be2ded0327d32ff9de36dbdc05dd17f0d..e18c8fa639ac7108d0b7bff67fda61a0d4aa3fd7 100644 |
--- a/sync/internal_api/http_bridge_unittest.cc |
+++ b/sync/internal_api/http_bridge_unittest.cc |
@@ -2,8 +2,10 @@ |
// Use of this source code is governed by a BSD-style license that can be |
// found in the LICENSE file. |
+#include "base/metrics/field_trial.h" |
#include "base/strings/stringprintf.h" |
#include "base/synchronization/waitable_event.h" |
+#include "base/test/mock_entropy_provider.h" |
#include "base/threading/thread.h" |
#include "net/http/http_response_headers.h" |
#include "net/test/spawned_test_server/spawned_test_server.h" |
@@ -146,9 +148,12 @@ class ShuntedHttpBridge : public HttpBridge { |
std::string response_content = "success!"; |
net::TestURLFetcher fetcher(0, GURL("http://www.google.com"), NULL); |
+ scoped_refptr<net::HttpResponseHeaders> response_headers( |
+ new net::HttpResponseHeaders("")); |
fetcher.set_response_code(200); |
fetcher.set_cookies(cookies); |
fetcher.SetResponseString(response_content); |
+ fetcher.set_response_headers(response_headers); |
OnURLFetchComplete(&fetcher); |
} |
SyncHttpBridgeTest* test_; |
@@ -232,6 +237,69 @@ TEST_F(SyncHttpBridgeTest, TestMakeSynchronousPostLiveWithPayload) { |
EXPECT_EQ(payload, std::string(http_bridge->GetResponseContent())); |
} |
+// Full round-trip test of the HttpBridge with compressed data, using default |
+// UA string and no request cookies. |
Nicolas Zea
2015/07/30 19:59:44
Do the UA string or request cookies actually matte
Gang Wu
2015/07/31 00:39:45
comment updated.
|
+TEST_F(SyncHttpBridgeTest, CompressedRequestPayloadCheck) { |
+ ASSERT_TRUE(test_server_.Start()); |
+ |
+ scoped_refptr<HttpBridge> http_bridge(BuildBridge()); |
+ |
+ std::string payload = "this should be echoed back"; |
+ GURL echo = test_server_.GetURL("echo"); |
+ http_bridge->SetURL(echo.spec().c_str(), echo.IntPort()); |
+ http_bridge->SetPostPayload("application/x-www-form-urlencoded", |
+ payload.length(), payload.c_str()); |
+ int os_error = 0; |
+ int response_code = 0; |
+ base::FieldTrialList field_trial_list(new base::MockEntropyProvider()); |
+ base::FieldTrialList::CreateFieldTrial("SyncHttpContentCompression", |
+ "Enabled"); |
+ bool success = http_bridge->MakeSynchronousPost(&os_error, &response_code); |
+ EXPECT_TRUE(success); |
+ EXPECT_EQ(200, response_code); |
+ EXPECT_EQ(0, os_error); |
+ |
+ EXPECT_NE(payload.length() + 1, |
+ static_cast<size_t>(http_bridge->GetResponseContentLength())); |
+ std::string compressed_payload(http_bridge->GetResponseContent(), |
+ http_bridge->GetResponseContentLength()); |
+ std::string uncompressed_payload; |
+ GzipUncompress(compressed_payload, &uncompressed_payload); |
+ EXPECT_EQ(payload, uncompressed_payload); |
+} |
+ |
+// Full round-trip test of the HttpBridge with compression. |
Nicolas Zea
2015/07/30 19:59:44
Update comment to explain what is being tested w.r
Gang Wu
2015/07/31 00:39:45
Done.
|
+TEST_F(SyncHttpBridgeTest, CompressedRequestHeaderCheck) { |
+ ASSERT_TRUE(test_server_.Start()); |
+ |
+ scoped_refptr<HttpBridge> http_bridge(BuildBridge()); |
+ |
+ GURL echo_header = test_server_.GetURL("echoall"); |
+ http_bridge->SetURL(echo_header.spec().c_str(), echo_header.IntPort()); |
+ |
+ std::string test_payload = "###TEST PAYLOAD###"; |
+ http_bridge->SetPostPayload("text/html", test_payload.length() + 1, |
+ test_payload.c_str()); |
+ |
+ int os_error = 0; |
+ int response_code = 0; |
+ base::FieldTrialList field_trial_list(new base::MockEntropyProvider()); |
+ base::FieldTrialList::CreateFieldTrial("SyncHttpContentCompression", |
+ "Enabled"); |
+ bool success = http_bridge->MakeSynchronousPost(&os_error, &response_code); |
+ EXPECT_TRUE(success); |
+ EXPECT_EQ(200, response_code); |
+ EXPECT_EQ(0, os_error); |
+ |
+ std::string response(http_bridge->GetResponseContent(), |
+ http_bridge->GetResponseContentLength()); |
+ EXPECT_NE(std::string::npos, response.find("Content-Encoding: gzip")); |
+ EXPECT_NE(std::string::npos, response.find("Accept-Encoding: gzip, deflate")); |
+ EXPECT_NE(std::string::npos, |
+ response.find(base::StringPrintf( |
+ "%s: %s", net::HttpRequestHeaders::kUserAgent, kUserAgent))); |
+} |
+ |
// Full round-trip test of the HttpBridge. |
TEST_F(SyncHttpBridgeTest, TestMakeSynchronousPostLiveComprehensive) { |
ASSERT_TRUE(test_server_.Start()); |
@@ -255,6 +323,7 @@ TEST_F(SyncHttpBridgeTest, TestMakeSynchronousPostLiveComprehensive) { |
std::string response(http_bridge->GetResponseContent(), |
http_bridge->GetResponseContentLength()); |
EXPECT_EQ(std::string::npos, response.find("Cookie:")); |
+ EXPECT_NE(std::string::npos, response.find("Accept-Encoding: deflate")); |
EXPECT_NE(std::string::npos, |
response.find(base::StringPrintf("%s: %s", |
net::HttpRequestHeaders::kUserAgent, kUserAgent))); |