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

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: meacer nits Created 4 years, 1 month 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
« no previous file with comments | « components/network_time/network_time_test_utils.h ('k') | components/network_time/network_time_tracker.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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..38267b2e767b06164367e1b8c904d5e1ba95d2a6 100644
--- a/components/network_time/network_time_test_utils.cc
+++ b/components/network_time/network_time_test_utils.cc
@@ -17,37 +17,56 @@
namespace network_time {
-// Returns a valid time response. Update as follows:
+// Update as follows:
//
// curl http://clients2.google.com/time/1/current?cup2key=1:123123123
//
-// where 1 is the key version and 123123123 is the nonce. Copy the nonce, the
-// response, and the x-cup-server-proof header into the test.
+// where 1 is the key version and 123123123 is the nonce. Copy the
+// response and the x-cup-server-proof header into
+// |kGoodTimeResponseBody| and |kGoodTimeResponseServerProofHeader|
+// respectively, and the 'current_time_millis' value of the response
+// into |kGoodTimeResponseHandlerJsTime|.
+const char kGoodTimeResponseBody[] =
+ ")]}'\n"
+ "{\"current_time_millis\":1461621971825"
+ ",\"server_nonce\":-6."
+ "006853099049523E85}";
+const char kGoodTimeResponseServerProofHeader[] =
+ "304402202e0f24db1ea69f1bbe81da4108f381fcf7a2781c53cf7663cb47083cb5fe8e"
+ "fd"
+ "022009d2b67c0deceaaf849f7c529be96701ed5f15d5efcaf401a94e0801accc9832:"
+ "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855";
+const double kGoodTimeResponseHandlerJsTime = 1461621971825;
+
std::unique_ptr<net::test_server::HttpResponse> GoodTimeResponseHandler(
const net::test_server::HttpRequest& request) {
net::test_server::BasicHttpResponse* response =
new net::test_server::BasicHttpResponse();
response->set_code(net::HTTP_OK);
- response->set_content(
- ")]}'\n"
- "{\"current_time_millis\":1461621971825,\"server_nonce\":-6."
- "006853099049523E85}");
- response->AddCustomHeader(
- "x-cup-server-proof",
- "304402202e0f24db1ea69f1bbe81da4108f381fcf7a2781c53cf7663cb47083cb5fe8e"
- "fd"
- "022009d2b67c0deceaaf849f7c529be96701ed5f15d5efcaf401a94e0801accc9832:"
- "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855");
+ response->set_content(kGoodTimeResponseBody);
+ response->AddCustomHeader("x-cup-server-proof",
+ kGoodTimeResponseServerProofHeader);
return std::unique_ptr<net::test_server::HttpResponse>(response);
}
-FieldTrialTest::FieldTrialTest() {}
FieldTrialTest::~FieldTrialTest() {}
+FieldTrialTest* FieldTrialTest::CreateForUnitTest() {
+ FieldTrialTest* test = new FieldTrialTest();
+ test->create_field_trial_list_ = true;
+ return test;
+}
+
+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 +78,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 +101,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 */);
@@ -90,4 +122,6 @@ void FieldTrialTest::SetNetworkQueriesWithVariationsService(
scoped_feature_list_->InitWithFeatureList(std::move(feature_list));
}
+FieldTrialTest::FieldTrialTest() {}
+
} // namespace network_time
« no previous file with comments | « components/network_time/network_time_test_utils.h ('k') | components/network_time/network_time_tracker.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698