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