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 #include "components/network_time/network_time_test_utils.h" | 5 #include "components/network_time/network_time_test_utils.h" |
6 | 6 |
7 #include "base/feature_list.h" | 7 #include "base/feature_list.h" |
8 #include "base/memory/ptr_util.h" | 8 #include "base/memory/ptr_util.h" |
9 #include "base/metrics/field_trial.h" | 9 #include "base/metrics/field_trial.h" |
10 #include "base/strings/string_number_conversions.h" | 10 #include "base/strings/string_number_conversions.h" |
11 #include "base/test/mock_entropy_provider.h" | 11 #include "base/test/mock_entropy_provider.h" |
12 #include "base/test/scoped_feature_list.h" | 12 #include "base/test/scoped_feature_list.h" |
13 #include "components/variations/variations_associated_data.h" | 13 #include "components/variations/variations_associated_data.h" |
| 14 #include "net/http/http_response_headers.h" |
| 15 #include "net/test/embedded_test_server/http_response.h" |
| 16 #include "testing/gtest/include/gtest/gtest.h" |
14 | 17 |
15 namespace network_time { | 18 namespace network_time { |
16 | 19 |
17 FieldTrialTest::FieldTrialTest() : ::testing::Test() {} | 20 // Returns a valid time response. Update as follows: |
| 21 // |
| 22 // curl http://clients2.google.com/time/1/current?cup2key=1:123123123 |
| 23 // |
| 24 // where 1 is the key version and 123123123 is the nonce. Copy the nonce, the |
| 25 // response, and the x-cup-server-proof header into the test. |
| 26 std::unique_ptr<net::test_server::HttpResponse> GoodTimeResponseHandler( |
| 27 const net::test_server::HttpRequest& request) { |
| 28 net::test_server::BasicHttpResponse* response = |
| 29 new net::test_server::BasicHttpResponse(); |
| 30 response->set_code(net::HTTP_OK); |
| 31 response->set_content( |
| 32 ")]}'\n" |
| 33 "{\"current_time_millis\":1461621971825,\"server_nonce\":-6." |
| 34 "006853099049523E85}"); |
| 35 response->AddCustomHeader( |
| 36 "x-cup-server-proof", |
| 37 "304402202e0f24db1ea69f1bbe81da4108f381fcf7a2781c53cf7663cb47083cb5fe8e" |
| 38 "fd" |
| 39 "022009d2b67c0deceaaf849f7c529be96701ed5f15d5efcaf401a94e0801accc9832:" |
| 40 "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855"); |
| 41 return std::unique_ptr<net::test_server::HttpResponse>(response); |
| 42 } |
| 43 |
| 44 FieldTrialTest::FieldTrialTest() {} |
18 FieldTrialTest::~FieldTrialTest() {} | 45 FieldTrialTest::~FieldTrialTest() {} |
19 | 46 |
20 void FieldTrialTest::SetNetworkQueriesWithVariationsService( | 47 void FieldTrialTest::SetNetworkQueriesWithVariationsService( |
21 bool enable, | 48 bool enable, |
22 float query_probability) { | 49 float query_probability, |
| 50 FetchesOnDemandStatus fetches_on_demand) { |
23 const std::string kTrialName = "Trial"; | 51 const std::string kTrialName = "Trial"; |
24 const std::string kGroupName = "group"; | 52 const std::string kGroupName = "group"; |
25 const base::Feature kFeature{"NetworkTimeServiceQuerying", | 53 const base::Feature kFeature{"NetworkTimeServiceQuerying", |
26 base::FEATURE_DISABLED_BY_DEFAULT}; | 54 base::FEATURE_DISABLED_BY_DEFAULT}; |
27 | 55 |
28 // Clear all the things. | 56 // Clear all the things. |
29 variations::testing::ClearAllVariationParams(); | 57 variations::testing::ClearAllVariationParams(); |
30 | 58 |
31 std::map<std::string, std::string> params; | 59 std::map<std::string, std::string> params; |
32 params["RandomQueryProbability"] = base::DoubleToString(query_probability); | 60 params["RandomQueryProbability"] = base::DoubleToString(query_probability); |
33 params["CheckTimeIntervalSeconds"] = base::Int64ToString(360); | 61 params["CheckTimeIntervalSeconds"] = base::Int64ToString(360); |
| 62 params["EnableFetchesOnDemand"] = |
| 63 fetches_on_demand == ENABLE_FETCHES_ON_DEMAND ? "true" : ""; |
34 | 64 |
35 // There are 3 things here: a FieldTrial, a FieldTrialList, and a | 65 // There are 3 things here: a FieldTrial, a FieldTrialList, and a |
36 // FeatureList. Don't get confused! The FieldTrial is reference-counted, | 66 // FeatureList. Don't get confused! The FieldTrial is reference-counted, |
37 // and a reference is held by the FieldTrialList. The FieldTrialList and | 67 // and a reference is held by the FieldTrialList. The FieldTrialList and |
38 // FeatureList are both singletons. The authorized way to reset the former | 68 // FeatureList are both singletons. The authorized way to reset the former |
39 // for testing is to destruct it (above). The latter, by contrast, should | 69 // for testing is to destruct it (above). The latter, by contrast, should |
40 // should already start in a clean state and can be manipulated via the | 70 // should already start in a clean state and can be manipulated via the |
41 // ScopedFeatureList helper class. If this comment was useful to you | 71 // ScopedFeatureList helper class. If this comment was useful to you |
42 // please send me a postcard. | 72 // please send me a postcard. |
43 | 73 |
(...skipping 10 matching lines...) Expand all Loading... |
54 std::unique_ptr<base::FeatureList> feature_list(new base::FeatureList); | 84 std::unique_ptr<base::FeatureList> feature_list(new base::FeatureList); |
55 feature_list->RegisterFieldTrialOverride( | 85 feature_list->RegisterFieldTrialOverride( |
56 kFeature.name, enable ? base::FeatureList::OVERRIDE_ENABLE_FEATURE | 86 kFeature.name, enable ? base::FeatureList::OVERRIDE_ENABLE_FEATURE |
57 : base::FeatureList::OVERRIDE_DISABLE_FEATURE, | 87 : base::FeatureList::OVERRIDE_DISABLE_FEATURE, |
58 trial); | 88 trial); |
59 scoped_feature_list_.reset(new base::test::ScopedFeatureList); | 89 scoped_feature_list_.reset(new base::test::ScopedFeatureList); |
60 scoped_feature_list_->InitWithFeatureList(std::move(feature_list)); | 90 scoped_feature_list_->InitWithFeatureList(std::move(feature_list)); |
61 } | 91 } |
62 | 92 |
63 } // namespace network_time | 93 } // namespace network_time |
OLD | NEW |