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 #ifndef COMPONENTS_NETWORK_TIME_NETWORK_TIME_TEST_UTILS_H_ | 5 #ifndef COMPONENTS_NETWORK_TIME_NETWORK_TIME_TEST_UTILS_H_ |
6 #define COMPONENTS_NETWORK_TIME_NETWORK_TIME_TEST_UTILS_H_ | 6 #define COMPONENTS_NETWORK_TIME_NETWORK_TIME_TEST_UTILS_H_ |
7 | 7 |
8 #include <map> | 8 #include <map> |
9 #include <memory> | 9 #include <memory> |
10 | 10 |
11 #include "base/macros.h" | 11 #include "base/macros.h" |
12 | 12 |
13 namespace base { | 13 namespace base { |
14 namespace test { | 14 namespace test { |
15 class ScopedFeatureList; | 15 class ScopedFeatureList; |
16 }; // namespace test | 16 }; // namespace test |
17 | 17 |
18 class FieldTrialList; | 18 class FieldTrialList; |
19 } // namespace base | 19 } // namespace base |
20 | 20 |
21 namespace net { | 21 namespace net { |
22 namespace test_server { | 22 namespace test_server { |
23 struct HttpRequest; | 23 struct HttpRequest; |
24 class HttpResponse; | 24 class HttpResponse; |
25 } // namespace test_server | 25 } // namespace test_server |
26 } // namespace net | 26 } // namespace net |
27 | 27 |
28 namespace network_time { | 28 namespace network_time { |
29 | 29 |
| 30 // The body of a valid time response. Can be returned, with |
| 31 // |kGoodTimeResponseServerProofHeader|, in responses from test servers |
| 32 // to simulate a network time server. This response uses 1 as the key |
| 33 // version and 123123123 as the nonce. Use |
| 34 // NetworkTimeTracker::OverrideNonceForTesting() to set the nonce so |
| 35 // that this response validates. |
| 36 extern const char kGoodTimeResponseBody[]; |
| 37 |
| 38 // The x-cup-server-proof header value that should be served along with |
| 39 // |kGoodTimeResponseBody| to make a test server response be accepted by |
| 40 // NetworkTimeTracker as a valid response. |
| 41 extern const char kGoodTimeResponseServerProofHeader[]; |
| 42 |
| 43 // The time that |kGoodTimeResponseBody| uses. Can be converted to a |
| 44 // base::Time with base::Time::FromJsTime. |
| 45 extern const double kGoodTimeResponseHandlerJsTime; |
| 46 |
| 47 // Returns a valid network time response using the constants above. See |
| 48 // comments in the .cc for how to update the time returned in the response. |
30 std::unique_ptr<net::test_server::HttpResponse> GoodTimeResponseHandler( | 49 std::unique_ptr<net::test_server::HttpResponse> GoodTimeResponseHandler( |
31 const net::test_server::HttpRequest& request); | 50 const net::test_server::HttpRequest& request); |
32 | 51 |
33 // Allows tests to configure the network time queries field trial. | 52 // Allows tests to configure the network time queries field trial. |
34 class FieldTrialTest { | 53 class FieldTrialTest { |
35 public: | 54 public: |
36 enum FetchesOnDemandStatus { | 55 enum FetchBehavior { |
37 ENABLE_FETCHES_ON_DEMAND, | 56 FETCHES_IN_BACKGROUND_ONLY, |
38 DISABLE_FETCHES_ON_DEMAND, | 57 FETCHES_ON_DEMAND_ONLY, |
| 58 FETCHES_IN_BACKGROUND_AND_ON_DEMAND, |
39 }; | 59 }; |
40 | 60 |
41 FieldTrialTest(); | |
42 virtual ~FieldTrialTest(); | 61 virtual ~FieldTrialTest(); |
43 void SetNetworkQueriesWithVariationsService( | 62 |
44 bool enable, | 63 // A FieldTrialList exists as a global singleton. Use |
45 float query_probability, | 64 // CreateForUnitTest() in unit tests to create a FieldTrialTest that |
46 FetchesOnDemandStatus fetches_on_demand); | 65 // creates its own FieldTrialList; use CreateForBrowserTest() to use |
| 66 // the singleton FieldTrialList that is created during browser setup. |
| 67 static FieldTrialTest* CreateForUnitTest(); |
| 68 static FieldTrialTest* CreateForBrowserTest(); |
| 69 |
| 70 void SetNetworkQueriesWithVariationsService(bool enable, |
| 71 float query_probability, |
| 72 FetchBehavior fetch_behavior); |
47 | 73 |
48 private: | 74 private: |
| 75 FieldTrialTest(); |
| 76 bool create_field_trial_list_ = true; |
49 std::unique_ptr<base::FieldTrialList> field_trial_list_; | 77 std::unique_ptr<base::FieldTrialList> field_trial_list_; |
50 std::unique_ptr<base::test::ScopedFeatureList> scoped_feature_list_; | 78 std::unique_ptr<base::test::ScopedFeatureList> scoped_feature_list_; |
51 | 79 |
52 DISALLOW_COPY_AND_ASSIGN(FieldTrialTest); | 80 DISALLOW_COPY_AND_ASSIGN(FieldTrialTest); |
53 }; | 81 }; |
54 | 82 |
55 } // namespace network_time | 83 } // namespace network_time |
56 | 84 |
57 #endif // COMPONENTS_NETWORK_TIME_NETWORK_TIME_TEST_UTILS_H_ | 85 #endif // COMPONENTS_NETWORK_TIME_NETWORK_TIME_TEST_UTILS_H_ |
OLD | NEW |