| OLD | NEW |
| 1 // Copyright 2012 The Chromium Authors. All rights reserved. | 1 // Copyright 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include <stddef.h> | 5 #include <stddef.h> |
| 6 #include <stdint.h> | 6 #include <stdint.h> |
| 7 | 7 |
| 8 #include "base/bit_cast.h" | 8 #include "base/bit_cast.h" |
| 9 #include "base/metrics/field_trial.h" | |
| 10 #include "base/strings/stringprintf.h" | 9 #include "base/strings/stringprintf.h" |
| 11 #include "base/synchronization/waitable_event.h" | 10 #include "base/synchronization/waitable_event.h" |
| 12 #include "base/test/mock_entropy_provider.h" | |
| 13 #include "base/threading/thread.h" | 11 #include "base/threading/thread.h" |
| 14 #include "build/build_config.h" | 12 #include "build/build_config.h" |
| 15 #include "net/http/http_response_headers.h" | 13 #include "net/http/http_response_headers.h" |
| 16 #include "net/test/embedded_test_server/embedded_test_server.h" | 14 #include "net/test/embedded_test_server/embedded_test_server.h" |
| 17 #include "net/url_request/test_url_fetcher_factory.h" | 15 #include "net/url_request/test_url_fetcher_factory.h" |
| 18 #include "net/url_request/url_fetcher_delegate.h" | 16 #include "net/url_request/url_fetcher_delegate.h" |
| 19 #include "net/url_request/url_request_test_util.h" | 17 #include "net/url_request/url_request_test_util.h" |
| 20 #include "sync/internal_api/public/base/cancelation_signal.h" | 18 #include "sync/internal_api/public/base/cancelation_signal.h" |
| 21 #include "sync/internal_api/public/http_bridge.h" | 19 #include "sync/internal_api/public/http_bridge.h" |
| 22 #include "sync/internal_api/public/http_post_provider_factory.h" | 20 #include "sync/internal_api/public/http_post_provider_factory.h" |
| 23 #include "testing/gtest/include/gtest/gtest.h" | 21 #include "testing/gtest/include/gtest/gtest.h" |
| 24 #include "third_party/zlib/zlib.h" | |
| 25 | 22 |
| 26 namespace syncer { | 23 namespace syncer { |
| 27 | 24 |
| 28 namespace { | 25 namespace { |
| 29 | 26 |
| 30 // TODO(timsteele): Should use PathService here. See Chromium Issue 3113. | 27 // TODO(timsteele): Should use PathService here. See Chromium Issue 3113. |
| 31 const base::FilePath::CharType kDocRoot[] = | 28 const base::FilePath::CharType kDocRoot[] = |
| 32 FILE_PATH_LITERAL("chrome/test/data"); | 29 FILE_PATH_LITERAL("chrome/test/data"); |
| 33 | 30 |
| 34 } // namespace | 31 } // namespace |
| (...skipping 228 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 263 | 260 |
| 264 GURL echo_header = test_server_.GetURL("/echoall"); | 261 GURL echo_header = test_server_.GetURL("/echoall"); |
| 265 http_bridge->SetURL(echo_header.spec().c_str(), echo_header.IntPort()); | 262 http_bridge->SetURL(echo_header.spec().c_str(), echo_header.IntPort()); |
| 266 | 263 |
| 267 std::string test_payload = "###TEST PAYLOAD###"; | 264 std::string test_payload = "###TEST PAYLOAD###"; |
| 268 http_bridge->SetPostPayload("text/html", test_payload.length() + 1, | 265 http_bridge->SetPostPayload("text/html", test_payload.length() + 1, |
| 269 test_payload.c_str()); | 266 test_payload.c_str()); |
| 270 | 267 |
| 271 int os_error = 0; | 268 int os_error = 0; |
| 272 int response_code = 0; | 269 int response_code = 0; |
| 273 base::FieldTrialList field_trial_list(new base::MockEntropyProvider()); | |
| 274 base::FieldTrialList::CreateFieldTrial("SyncHttpContentCompression", | |
| 275 "Enabled"); | |
| 276 bool success = http_bridge->MakeSynchronousPost(&os_error, &response_code); | 270 bool success = http_bridge->MakeSynchronousPost(&os_error, &response_code); |
| 277 EXPECT_TRUE(success); | 271 EXPECT_TRUE(success); |
| 278 EXPECT_EQ(200, response_code); | 272 EXPECT_EQ(200, response_code); |
| 279 EXPECT_EQ(0, os_error); | 273 EXPECT_EQ(0, os_error); |
| 280 | 274 |
| 281 std::string response(http_bridge->GetResponseContent(), | 275 std::string response(http_bridge->GetResponseContent(), |
| 282 http_bridge->GetResponseContentLength()); | 276 http_bridge->GetResponseContentLength()); |
| 283 EXPECT_NE(std::string::npos, | 277 EXPECT_NE(std::string::npos, |
| 284 response.find(base::StringPrintf( | 278 response.find(base::StringPrintf( |
| 285 "%s: %s", net::HttpRequestHeaders::kAcceptEncoding, | 279 "%s: %s", net::HttpRequestHeaders::kAcceptEncoding, |
| (...skipping 20 matching lines...) Expand all Loading... |
| 306 int response_code = 0; | 300 int response_code = 0; |
| 307 bool success = http_bridge->MakeSynchronousPost(&os_error, &response_code); | 301 bool success = http_bridge->MakeSynchronousPost(&os_error, &response_code); |
| 308 EXPECT_TRUE(success); | 302 EXPECT_TRUE(success); |
| 309 EXPECT_EQ(200, response_code); | 303 EXPECT_EQ(200, response_code); |
| 310 EXPECT_EQ(0, os_error); | 304 EXPECT_EQ(0, os_error); |
| 311 | 305 |
| 312 std::string response(http_bridge->GetResponseContent(), | 306 std::string response(http_bridge->GetResponseContent(), |
| 313 http_bridge->GetResponseContentLength()); | 307 http_bridge->GetResponseContentLength()); |
| 314 EXPECT_EQ(std::string::npos, response.find("Cookie:")); | 308 EXPECT_EQ(std::string::npos, response.find("Cookie:")); |
| 315 EXPECT_NE(std::string::npos, | 309 EXPECT_NE(std::string::npos, |
| 316 response.find(base::StringPrintf( | |
| 317 "%s: %s", net::HttpRequestHeaders::kAcceptEncoding, | |
| 318 "deflate"))); | |
| 319 EXPECT_NE(std::string::npos, | |
| 320 response.find(base::StringPrintf("%s: %s", | 310 response.find(base::StringPrintf("%s: %s", |
| 321 net::HttpRequestHeaders::kUserAgent, kUserAgent))); | 311 net::HttpRequestHeaders::kUserAgent, kUserAgent))); |
| 322 EXPECT_NE(std::string::npos, response.find(test_payload.c_str())); | 312 EXPECT_NE(std::string::npos, response.find(test_payload.c_str())); |
| 323 } | 313 } |
| 324 | 314 |
| 325 TEST_F(MAYBE_SyncHttpBridgeTest, TestExtraRequestHeaders) { | 315 TEST_F(MAYBE_SyncHttpBridgeTest, TestExtraRequestHeaders) { |
| 326 ASSERT_TRUE(test_server_.Start()); | 316 ASSERT_TRUE(test_server_.Start()); |
| 327 | 317 |
| 328 scoped_refptr<HttpBridge> http_bridge(BuildBridge()); | 318 scoped_refptr<HttpBridge> http_bridge(BuildBridge()); |
| 329 | 319 |
| (...skipping 256 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 586 | 576 |
| 587 // Sync thread: Finally run the posted task, only to find that our | 577 // Sync thread: Finally run the posted task, only to find that our |
| 588 // HttpBridgeFactory has been neutered. Should not crash. | 578 // HttpBridgeFactory has been neutered. Should not crash. |
| 589 factory->Init("TestUserAgent", BindToTrackerCallback()); | 579 factory->Init("TestUserAgent", BindToTrackerCallback()); |
| 590 | 580 |
| 591 // At this point, attempting to use the factory would trigger a crash. Both | 581 // At this point, attempting to use the factory would trigger a crash. Both |
| 592 // this test and the real world code should make sure this never happens. | 582 // this test and the real world code should make sure this never happens. |
| 593 } | 583 } |
| 594 | 584 |
| 595 } // namespace syncer | 585 } // namespace syncer |
| OLD | NEW |