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[]; | |
meacer
2016/11/02 22:43:23
nit: Blank line? (here and below)
estark
2016/11/03 01:36:05
Done.
| |
37 // The x-cup-server-proof header value that should be served along with | |
38 // |kGoodTimeResponseBody| to make a test server response be accepted by | |
39 // NetworkTimeTracker as a valid response. | |
40 extern const char kGoodTimeResponseServerProofHeader[]; | |
41 // The time that |kGoodTimeResponseBody| uses. Can be converted to a | |
42 // base::Time with base::Time::FromJsTime. | |
43 extern const double kGoodTimeResponseHandlerTime; | |
44 | |
45 // Returns a valid network time response using the constants above. See | |
46 // comments in the .cc for how to update the time returned in the response. | |
30 std::unique_ptr<net::test_server::HttpResponse> GoodTimeResponseHandler( | 47 std::unique_ptr<net::test_server::HttpResponse> GoodTimeResponseHandler( |
31 const net::test_server::HttpRequest& request); | 48 const net::test_server::HttpRequest& request); |
32 | 49 |
33 // Allows tests to configure the network time queries field trial. | 50 // Allows tests to configure the network time queries field trial. |
34 class FieldTrialTest { | 51 class FieldTrialTest { |
35 public: | 52 public: |
36 enum FetchesOnDemandStatus { | 53 enum FetchBehavior { |
37 ENABLE_FETCHES_ON_DEMAND, | 54 FETCHES_IN_BACKGROUND_ONLY, |
38 DISABLE_FETCHES_ON_DEMAND, | 55 FETCHES_ON_DEMAND_ONLY, |
56 FETCHES_IN_BACKGROUND_AND_ON_DEMAND, | |
39 }; | 57 }; |
40 | 58 |
41 FieldTrialTest(); | |
42 virtual ~FieldTrialTest(); | 59 virtual ~FieldTrialTest(); |
43 void SetNetworkQueriesWithVariationsService( | 60 |
44 bool enable, | 61 // A FieldTrialList exists as a global singleton. Use |
45 float query_probability, | 62 // CreateForUnitTest() in unit tests to create a FieldTrialTest that |
46 FetchesOnDemandStatus fetches_on_demand); | 63 // creates its own FieldTrialList; use CreateForBrowserTest() to use |
64 // the singleton FieldTrialList that is created during browser setup. | |
65 static FieldTrialTest* CreateForUnitTest(); | |
66 static FieldTrialTest* CreateForBrowserTest(); | |
67 | |
68 void SetNetworkQueriesWithVariationsService(bool enable, | |
69 float query_probability, | |
70 FetchBehavior fetch_behavior); | |
47 | 71 |
48 private: | 72 private: |
73 FieldTrialTest(); | |
74 bool create_field_trial_list_ = true; | |
49 std::unique_ptr<base::FieldTrialList> field_trial_list_; | 75 std::unique_ptr<base::FieldTrialList> field_trial_list_; |
50 std::unique_ptr<base::test::ScopedFeatureList> scoped_feature_list_; | 76 std::unique_ptr<base::test::ScopedFeatureList> scoped_feature_list_; |
51 | 77 |
52 DISALLOW_COPY_AND_ASSIGN(FieldTrialTest); | 78 DISALLOW_COPY_AND_ASSIGN(FieldTrialTest); |
53 }; | 79 }; |
54 | 80 |
55 } // namespace network_time | 81 } // namespace network_time |
56 | 82 |
57 #endif // COMPONENTS_NETWORK_TIME_NETWORK_TIME_TEST_UTILS_H_ | 83 #endif // COMPONENTS_NETWORK_TIME_NETWORK_TIME_TEST_UTILS_H_ |
OLD | NEW |