| OLD | NEW |
| (Empty) | |
| 1 // Copyright 2017 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #ifndef COMPONENTS_CRONET_IOS_TEST_CRONET_TEST_BASE_H_ |
| 6 #define COMPONENTS_CRONET_IOS_TEST_CRONET_TEST_BASE_H_ |
| 7 |
| 8 #include <Cronet/Cronet.h> |
| 9 #include "net/cert/cert_verifier.h" |
| 10 #include "net/cert/x509_certificate.h" |
| 11 #include "testing/gtest/include/gtest/gtest.h" |
| 12 |
| 13 #pragma mark |
| 14 |
| 15 // Exposes private test-only methods of the Cronet class. |
| 16 @interface Cronet (ExposedForTesting) |
| 17 + (void)shutdownForTesting; |
| 18 + (void)setMockCertVerifierForTesting: |
| 19 (std::unique_ptr<net::CertVerifier>)certVerifier; |
| 20 @end |
| 21 |
| 22 // NSURLSessionDataDelegate delegate implementation used by the tests to |
| 23 // wait for a response and check its status. |
| 24 @interface TestDelegate : NSObject<NSURLSessionDataDelegate> |
| 25 |
| 26 // Error the request this delegate is attached to failed with, if any. |
| 27 @property(retain, atomic) NSError* error; |
| 28 |
| 29 // Contains total amount of received data. |
| 30 @property(readonly) long totalBytesReceived; |
| 31 |
| 32 // Resets the delegate, so it can be used again for another request. |
| 33 - (void)reset; |
| 34 |
| 35 // Contains the response body. |
| 36 - (NSString*)responseBody; |
| 37 |
| 38 /// Waits for request to complete. |
| 39 |
| 40 /// @return |NO| if the request didn't complete and the method timed-out. |
| 41 - (BOOL)waitForDone; |
| 42 |
| 43 @end |
| 44 |
| 45 // Forward declaration. |
| 46 namespace net { |
| 47 class MockCertVerifier; |
| 48 } |
| 49 |
| 50 namespace cronet { |
| 51 |
| 52 // A base class that should be extended by all other Cronet tests. |
| 53 // The class automatically starts and stops the test QUIC server. |
| 54 class CronetTestBase : public ::testing::Test { |
| 55 protected: |
| 56 static bool CalculatePublicKeySha256(const net::X509Certificate& cert, |
| 57 net::HashValue* out_hash_value); |
| 58 |
| 59 void SetUp() override; |
| 60 void TearDown() override; |
| 61 void StartDataTaskAndWaitForCompletion(NSURLSessionDataTask* task); |
| 62 std::unique_ptr<net::MockCertVerifier> CreateMockCertVerifier( |
| 63 const std::vector<std::string>& certs, |
| 64 bool known_root); |
| 65 |
| 66 ::testing::AssertionResult IsResponseSuccessful(); |
| 67 |
| 68 TestDelegate* delegate_; |
| 69 }; // class CronetTestBase |
| 70 |
| 71 } // namespace cronet |
| 72 |
| 73 #endif // COMPONENTS_CRONET_IOS_TEST_CRONET_TEST_BASE_H_ |
| OLD | NEW |