OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "chrome/browser/metrics/variations/variations_service.h" | 5 #include "chrome/browser/metrics/variations/variations_service.h" |
6 | 6 |
7 #include <vector> | 7 #include <vector> |
8 | 8 |
9 #include "base/base64.h" | 9 #include "base/base64.h" |
10 #include "base/prefs/testing_pref_service.h" | 10 #include "base/prefs/testing_pref_service.h" |
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
84 } | 84 } |
85 | 85 |
86 // Serializes |seed| to base64-encoded protobuf binary format. | 86 // Serializes |seed| to base64-encoded protobuf binary format. |
87 std::string SerializeSeedBase64(const VariationsSeed& seed, std::string* hash) { | 87 std::string SerializeSeedBase64(const VariationsSeed& seed, std::string* hash) { |
88 std::string serialized_seed = SerializeSeed(seed); | 88 std::string serialized_seed = SerializeSeed(seed); |
89 if (hash != NULL) { | 89 if (hash != NULL) { |
90 std::string sha1 = base::SHA1HashString(serialized_seed); | 90 std::string sha1 = base::SHA1HashString(serialized_seed); |
91 *hash = base::HexEncode(sha1.data(), sha1.size()); | 91 *hash = base::HexEncode(sha1.data(), sha1.size()); |
92 } | 92 } |
93 std::string base64_serialized_seed; | 93 std::string base64_serialized_seed; |
94 EXPECT_TRUE(base::Base64Encode(serialized_seed, &base64_serialized_seed)); | 94 base::Base64Encode(serialized_seed, &base64_serialized_seed); |
95 return base64_serialized_seed; | 95 return base64_serialized_seed; |
96 } | 96 } |
97 | 97 |
98 // Simulates a variations service response by setting a date header and the | 98 // Simulates a variations service response by setting a date header and the |
99 // specified HTTP |response_code| on |fetcher|. | 99 // specified HTTP |response_code| on |fetcher|. |
100 void SimulateServerResponse(int response_code, net::TestURLFetcher* fetcher) { | 100 void SimulateServerResponse(int response_code, net::TestURLFetcher* fetcher) { |
101 ASSERT_TRUE(fetcher); | 101 ASSERT_TRUE(fetcher); |
102 scoped_refptr<net::HttpResponseHeaders> headers( | 102 scoped_refptr<net::HttpResponseHeaders> headers( |
103 new net::HttpResponseHeaders("date:Wed, 13 Feb 2013 00:25:24 GMT\0\0")); | 103 new net::HttpResponseHeaders("date:Wed, 13 Feb 2013 00:25:24 GMT\0\0")); |
104 fetcher->set_response_headers(headers); | 104 fetcher->set_response_headers(headers); |
(...skipping 292 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
397 prefs.FindPreference(prefs::kVariationsSeedDate)->IsDefaultValue()); | 397 prefs.FindPreference(prefs::kVariationsSeedDate)->IsDefaultValue()); |
398 | 398 |
399 net::TestURLFetcher* fetcher = factory.GetFetcherByID(0); | 399 net::TestURLFetcher* fetcher = factory.GetFetcherByID(0); |
400 SimulateServerResponse(net::HTTP_NOT_MODIFIED, fetcher); | 400 SimulateServerResponse(net::HTTP_NOT_MODIFIED, fetcher); |
401 variations_service.OnURLFetchComplete(fetcher); | 401 variations_service.OnURLFetchComplete(fetcher); |
402 EXPECT_FALSE( | 402 EXPECT_FALSE( |
403 prefs.FindPreference(prefs::kVariationsSeedDate)->IsDefaultValue()); | 403 prefs.FindPreference(prefs::kVariationsSeedDate)->IsDefaultValue()); |
404 } | 404 } |
405 | 405 |
406 } // namespace chrome_variations | 406 } // namespace chrome_variations |
OLD | NEW |