Chromium Code Reviews| Index: components/cronet/ios/test/cronet_test_base.h |
| diff --git a/components/cronet/ios/test/cronet_test_base.h b/components/cronet/ios/test/cronet_test_base.h |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..f6d314545fc12559437fbe666e5a54891a1c573a |
| --- /dev/null |
| +++ b/components/cronet/ios/test/cronet_test_base.h |
| @@ -0,0 +1,72 @@ |
| +// Copyright 2017 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#ifndef PRODUCTS_CRONET_TEST_BASE_H |
|
mef
2017/06/12 22:25:24
nit: COMPONENTS_CRONET_IOS_TEST_CRONET_TEST_BASE_H
kapishnikov
2017/06/16 20:11:05
Done.
|
| +#define PRODUCTS_CRONET_TEST_BASE_H |
| + |
| +#include "Cronet/Cronet.h" |
|
mef
2017/06/12 22:25:24
Should this be #import <Cronet/Cronet.h>?
kapishnikov
2017/06/16 20:11:05
Done.
|
| +#include "net/cert/cert_verifier.h" |
| +#include "net/cert/x509_certificate.h" |
| +#include "testing/gtest/include/gtest/gtest.h" |
| + |
| +#pragma mark |
| + |
| +// Exposes private test-only methods of the Cronet class. |
| +@interface Cronet (ExposedForTesting) |
| ++ (void)shutdownForTesting; |
| ++ (void)setMockCertVerifier:(std::unique_ptr<net::CertVerifier>)certVerifier; |
| +@end |
| + |
| +// NSURLSessionDataDelegate delegate implementation used by the tests to |
| +// wait for a response and check its status. |
| +@interface TestDelegate : NSObject<NSURLSessionDataDelegate> |
| + |
| +// Completion semaphore for this TestDelegate. When the request this delegate is |
| +// attached to finishes (either successfully or with an error), this delegate |
| +// signals this semaphore. |
| +@property(strong, atomic) dispatch_semaphore_t semaphore; |
|
mef
2017/06/12 22:25:24
Maybe hide this in implementation and add a 'waitF
kapishnikov
2017/06/16 20:11:05
Done. Added waitForDone() to the delegate.
|
| + |
| +// Error the request this delegate is attached to failed with, if any. |
| +@property(retain, atomic) NSError* error; |
| + |
| +// Contains total amount of received data. |
| +@property(readonly) long totalBytesReceived; |
| + |
| +// Resets the delegate, so it can be used again for another request. |
| +- (void)reset; |
| + |
| +// Contains the response body. |
| +- (NSString*)responseBody; |
| + |
| +@end |
| + |
| +// Forward declaration. |
| +namespace net { |
| +class MockCertVerifier; |
| +} |
| + |
| +namespace cronet { |
| + |
| +// A base class that should be extended by all other Cronet tests. |
| +// The class automatically starts and stoppes the test QUIC server. |
|
mef
2017/06/12 22:25:24
nit: stops.
kapishnikov
2017/06/16 20:11:05
Done.
|
| +class CronetTestBase : public ::testing::Test { |
| + protected: |
| + static bool CalculatePublicKeySha256(const net::X509Certificate& cert, |
|
mef
2017/06/12 22:25:24
Do we need this in base or in PKP only?
kapishnikov
2017/06/16 20:11:05
I would consider this method non-PKP specific but
|
| + net::HashValue* out_hash_value); |
| + |
| + void SetUp() override; |
| + void TearDown() override; |
| + void StartDataTaskAndWaitForCompletion(NSURLSessionDataTask* task); |
| + std::unique_ptr<net::MockCertVerifier> CreateMockCertVerifier( |
| + const std::vector<std::string>& certs, |
| + bool known_root); |
| + |
| + ::testing::AssertionResult IsResponseSuccessful(); |
| + |
| + TestDelegate* delegate_; |
| +}; // class CronetTestBase |
| + |
| +} // namespace cronet |
| + |
| +#endif // PRODUCTS_CRONET_TEST_BASE_H |