| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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 #import <Foundation/Foundation.h> | |
| 6 #include <stdint.h> | 5 #include <stdint.h> |
| 7 #include <list> | 6 #include <list> |
| 8 #include <map> | 7 #include <map> |
| 9 #include <string> | 8 #include <string> |
| 10 | 9 |
| 10 #include "base/at_exit.h" |
| 11 #include "base/logging.h" | 11 #include "base/logging.h" |
| 12 #include "base/mac/scoped_nsobject.h" | 12 #include "base/mac/scoped_nsobject.h" |
| 13 #include "base/macros.h" | 13 #include "base/macros.h" |
| 14 #include "base/memory/ptr_util.h" | 14 #include "base/memory/ptr_util.h" |
| 15 #include "base/strings/string_util.h" | 15 #include "base/strings/string_util.h" |
| 16 #include "base/strings/sys_string_conversions.h" | 16 #include "base/strings/sys_string_conversions.h" |
| 17 #include "base/synchronization/waitable_event.h" | 17 #include "base/synchronization/waitable_event.h" |
| 18 #import "components/cronet/ios/Cronet.h" |
| 18 #include "components/cronet/ios/cronet_c_for_grpc.h" | 19 #include "components/cronet/ios/cronet_c_for_grpc.h" |
| 19 #include "components/cronet/ios/cronet_environment.h" | |
| 20 #include "components/cronet/ios/test/quic_test_server.h" | 20 #include "components/cronet/ios/test/quic_test_server.h" |
| 21 #include "net/base/mac/url_conversions.h" | 21 #include "net/base/mac/url_conversions.h" |
| 22 #include "net/base/net_errors.h" | 22 #include "net/base/net_errors.h" |
| 23 #include "net/cert/mock_cert_verifier.h" | |
| 24 #include "net/test/test_data_directory.h" | 23 #include "net/test/test_data_directory.h" |
| 25 #include "testing/gtest/include/gtest/gtest.h" | 24 #include "testing/gtest/include/gtest/gtest.h" |
| 26 #include "testing/gtest_mac.h" | 25 #include "testing/gtest_mac.h" |
| 27 #include "url/gurl.h" | 26 #include "url/gurl.h" |
| 28 | 27 |
| 29 namespace { | 28 namespace { |
| 30 | 29 |
| 31 cronet_bidirectional_stream_header kTestHeaders[] = { | 30 cronet_bidirectional_stream_header kTestHeaders[] = { |
| 32 {"header1", "foo"}, | 31 {"header1", "foo"}, |
| 33 {"header2", "bar"}, | 32 {"header2", "bar"}, |
| 34 }; | 33 }; |
| 35 const cronet_bidirectional_stream_header_array kTestHeadersArray = { | 34 const cronet_bidirectional_stream_header_array kTestHeadersArray = { |
| 36 2, 2, kTestHeaders}; | 35 2, 2, kTestHeaders}; |
| 37 } // namespace | 36 } // namespace |
| 38 | 37 |
| 39 namespace cronet { | 38 namespace cronet { |
| 40 | 39 |
| 40 base::AtExitManager* g_at_exit_ = nullptr; |
| 41 |
| 42 void StartCronetIfNecessary() { |
| 43 static bool initialized = false; |
| 44 if (!initialized) { |
| 45 initialized = true; |
| 46 [Cronet setUserAgent:@"CronetTest/1.0.0.0" partial:NO]; |
| 47 [Cronet setHttp2Enabled:true]; |
| 48 [Cronet setQuicEnabled:true]; |
| 49 [Cronet setSslKeyLogFileName:@"SSLKEYLOGFILE"]; |
| 50 |
| 51 [Cronet addQuicHint:@"test.example.com" |
| 52 port:cronet::kTestServerPort |
| 53 altPort:cronet::kTestServerPort]; |
| 54 [Cronet enableTestCertVerifierForTesting]; |
| 55 [Cronet |
| 56 setHostResolverRulesForTesting:@"MAP test.example.com 127.0.0.1," |
| 57 "MAP notfound.example.com ~NOTFOUND"]; |
| 58 [Cronet start]; |
| 59 |
| 60 // This method must be called once from the main thread. |
| 61 if (!g_at_exit_) |
| 62 g_at_exit_ = new base::AtExitManager; |
| 63 } |
| 64 } |
| 65 |
| 41 class CronetBidirectionalStreamTest : public ::testing::TestWithParam<bool> { | 66 class CronetBidirectionalStreamTest : public ::testing::TestWithParam<bool> { |
| 42 protected: | 67 protected: |
| 43 CronetBidirectionalStreamTest() {} | 68 CronetBidirectionalStreamTest() {} |
| 44 ~CronetBidirectionalStreamTest() override {} | 69 ~CronetBidirectionalStreamTest() override {} |
| 45 | 70 |
| 46 void SetUp() override { | 71 void SetUp() override { |
| 47 static bool initialized = false; | 72 StartCronetIfNecessary(); |
| 48 if (!initialized) { | |
| 49 initialized = true; | |
| 50 // Hack to work around issues with SetUp being called multiple times | |
| 51 // during the test, and QuicTestServer not shutting down / restarting | |
| 52 // gracefully. | |
| 53 CronetEnvironment::Initialize(); | |
| 54 cronet_environment_ = new CronetEnvironment("CronetTest/1.0.0.0"); | |
| 55 cronet_environment_->set_http2_enabled(true); | |
| 56 cronet_environment_->set_quic_enabled(true); | |
| 57 cronet_environment_->set_ssl_key_log_file_name("SSLKEYLOGFILE"); | |
| 58 | |
| 59 std::unique_ptr<net::MockCertVerifier> mock_cert_verifier( | |
| 60 new net::MockCertVerifier()); | |
| 61 mock_cert_verifier->set_default_result(net::OK); | |
| 62 | |
| 63 cronet_environment_->set_cert_verifier(std::move(mock_cert_verifier)); | |
| 64 cronet_environment_->set_host_resolver_rules( | |
| 65 "MAP test.example.com 127.0.0.1," | |
| 66 "MAP notfound.example.com ~NOTFOUND"); | |
| 67 cronet_environment_->AddQuicHint(kTestServerDomain, kTestServerPort, | |
| 68 kTestServerPort); | |
| 69 | |
| 70 cronet_environment_->Start(); | |
| 71 | |
| 72 cronet_engine_.obj = cronet_environment_; | |
| 73 } | |
| 74 | |
| 75 StartQuicTestServer(); | 73 StartQuicTestServer(); |
| 76 cronet_environment_->StartNetLog("cronet_netlog.json", true); | 74 [Cronet startNetLogToFile:@"cronet_netlog.json" logBytes:YES]; |
| 77 } | 75 } |
| 78 | 76 |
| 79 void TearDown() override { | 77 void TearDown() override { |
| 80 ShutdownQuicTestServer(); | 78 ShutdownQuicTestServer(); |
| 81 cronet_environment_->StopNetLog(); | 79 [Cronet stopNetLog]; |
| 82 } | 80 } |
| 83 | 81 |
| 84 cronet_engine* engine() { return &cronet_engine_; } | 82 cronet_engine* engine() { return [Cronet getGlobalEngine]; } |
| 85 | |
| 86 private: | |
| 87 static CronetEnvironment* cronet_environment_; | |
| 88 static cronet_engine cronet_engine_; | |
| 89 }; | 83 }; |
| 90 | 84 |
| 91 CronetEnvironment* CronetBidirectionalStreamTest::cronet_environment_ = nullptr; | |
| 92 cronet_engine CronetBidirectionalStreamTest::cronet_engine_ = {0}; | |
| 93 | |
| 94 class TestBidirectionalStreamCallback { | 85 class TestBidirectionalStreamCallback { |
| 95 public: | 86 public: |
| 96 enum ResponseStep { | 87 enum ResponseStep { |
| 97 NOTHING, | 88 NOTHING, |
| 98 ON_STREAM_READY, | 89 ON_STREAM_READY, |
| 99 ON_RESPONSE_STARTED, | 90 ON_RESPONSE_STARTED, |
| 100 ON_READ_COMPLETED, | 91 ON_READ_COMPLETED, |
| 101 ON_WRITE_COMPLETED, | 92 ON_WRITE_COMPLETED, |
| 102 ON_TRAILERS, | 93 ON_TRAILERS, |
| 103 ON_CANCELED, | 94 ON_CANCELED, |
| (...skipping 604 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 708 ASSERT_EQ(TestBidirectionalStreamCallback::ON_FAILED, test.response_step); | 699 ASSERT_EQ(TestBidirectionalStreamCallback::ON_FAILED, test.response_step); |
| 709 ASSERT_EQ(net::ERR_NAME_NOT_RESOLVED, test.net_error); | 700 ASSERT_EQ(net::ERR_NAME_NOT_RESOLVED, test.net_error); |
| 710 cronet_bidirectional_stream_destroy(test.stream); | 701 cronet_bidirectional_stream_destroy(test.stream); |
| 711 } | 702 } |
| 712 | 703 |
| 713 INSTANTIATE_TEST_CASE_P(CronetBidirectionalStreamDelayRequestHeadersUntilFlush, | 704 INSTANTIATE_TEST_CASE_P(CronetBidirectionalStreamDelayRequestHeadersUntilFlush, |
| 714 CronetBidirectionalStreamTest, | 705 CronetBidirectionalStreamTest, |
| 715 ::testing::Values(true, false)); | 706 ::testing::Values(true, false)); |
| 716 | 707 |
| 717 } // namespace cronet | 708 } // namespace cronet |
| OLD | NEW |