Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(718)

Unified Diff: components/network_time/network_time_test_utils.cc

Issue 2449193002: Attempt an on-demand time fetch when encountering a date invalid error (Closed)
Patch Set: cleanup Created 4 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: components/network_time/network_time_test_utils.cc
diff --git a/components/network_time/network_time_test_utils.cc b/components/network_time/network_time_test_utils.cc
index 82dc3a5035557c57dca0709b438eeb88d060dd7a..a004a3b662d182c9e2f9c47ea1cb2da7e809868f 100644
--- a/components/network_time/network_time_test_utils.cc
+++ b/components/network_time/network_time_test_utils.cc
@@ -17,6 +17,8 @@
namespace network_time {
+const double kGoodTimeResponseHandlerTime = 1461621971825;
+
// Returns a valid time response. Update as follows:
//
// curl http://clients2.google.com/time/1/current?cup2key=1:123123123
@@ -30,7 +32,9 @@ std::unique_ptr<net::test_server::HttpResponse> GoodTimeResponseHandler(
response->set_code(net::HTTP_OK);
response->set_content(
")]}'\n"
- "{\"current_time_millis\":1461621971825,\"server_nonce\":-6."
+ "{\"current_time_millis\":" +
+ base::DoubleToString(kGoodTimeResponseHandlerTime) +
+ ",\"server_nonce\":-6."
"006853099049523E85}");
response->AddCustomHeader(
"x-cup-server-proof",
@@ -44,10 +48,16 @@ std::unique_ptr<net::test_server::HttpResponse> GoodTimeResponseHandler(
FieldTrialTest::FieldTrialTest() {}
FieldTrialTest::~FieldTrialTest() {}
+FieldTrialTest* FieldTrialTest::CreateForBrowserTest() {
+ FieldTrialTest* test = new FieldTrialTest();
+ test->create_field_trial_list_ = false;
+ return test;
+}
+
void FieldTrialTest::SetNetworkQueriesWithVariationsService(
bool enable,
float query_probability,
- FetchesOnDemandStatus fetches_on_demand) {
+ FetchBehavior fetch_behavior) {
const std::string kTrialName = "Trial";
const std::string kGroupName = "group";
const base::Feature kFeature{"NetworkTimeServiceQuerying",
@@ -59,8 +69,19 @@ void FieldTrialTest::SetNetworkQueriesWithVariationsService(
std::map<std::string, std::string> params;
params["RandomQueryProbability"] = base::DoubleToString(query_probability);
params["CheckTimeIntervalSeconds"] = base::Int64ToString(360);
- params["EnableFetchesOnDemand"] =
- fetches_on_demand == ENABLE_FETCHES_ON_DEMAND ? "true" : "";
+ std::string fetch_behavior_param;
+ switch (fetch_behavior) {
+ case FETCHES_IN_BACKGROUND_ONLY:
+ fetch_behavior_param = "background-only";
+ break;
+ case FETCHES_ON_DEMAND_ONLY:
+ fetch_behavior_param = "on-demand-only";
+ break;
+ case FETCHES_IN_BACKGROUND_AND_ON_DEMAND:
+ fetch_behavior_param = "background-and-on-demand";
+ break;
+ }
+ params["FetchBehavior"] = fetch_behavior_param;
// There are 3 things here: a FieldTrial, a FieldTrialList, and a
// FeatureList. Don't get confused! The FieldTrial is reference-counted,
@@ -71,10 +92,12 @@ void FieldTrialTest::SetNetworkQueriesWithVariationsService(
// ScopedFeatureList helper class. If this comment was useful to you
// please send me a postcard.
- field_trial_list_.reset(); // Averts a CHECK fail in constructor below.
- field_trial_list_.reset(
- new base::FieldTrialList(base::MakeUnique<base::MockEntropyProvider>()));
- // refcounted, and reference held by field_trial_list_.
+ if (create_field_trial_list_) {
+ field_trial_list_.reset(); // Averts a CHECK fail in constructor below.
+ field_trial_list_.reset(new base::FieldTrialList(
+ base::MakeUnique<base::MockEntropyProvider>()));
+ }
+ // refcounted, and reference held by the singleton FieldTrialList.
base::FieldTrial* trial = base::FieldTrialList::FactoryGetFieldTrial(
kTrialName, 100, kGroupName, 1971, 1, 1,
base::FieldTrial::SESSION_RANDOMIZED, nullptr /* default_group_number */);

Powered by Google App Engine
This is Rietveld 408576698