OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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_seed_store.h" | 5 #include "chrome/browser/metrics/variations/variations_seed_store.h" |
6 | 6 |
7 #include "base/base64.h" | 7 #include "base/base64.h" |
8 #include "base/prefs/testing_pref_service.h" | 8 #include "base/prefs/testing_pref_service.h" |
9 #include "components/metrics/compression_utils.h" | 9 #include "components/compression/compression_utils.h" |
10 #include "components/variations/pref_names.h" | 10 #include "components/variations/pref_names.h" |
11 #include "components/variations/proto/study.pb.h" | 11 #include "components/variations/proto/study.pb.h" |
12 #include "components/variations/proto/variations_seed.pb.h" | 12 #include "components/variations/proto/variations_seed.pb.h" |
13 #include "testing/gtest/include/gtest/gtest.h" | 13 #include "testing/gtest/include/gtest/gtest.h" |
14 | 14 |
15 namespace chrome_variations { | 15 namespace chrome_variations { |
16 | 16 |
17 namespace { | 17 namespace { |
18 | 18 |
19 class TestVariationsSeedStore : public VariationsSeedStore { | 19 class TestVariationsSeedStore : public VariationsSeedStore { |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
57 // Serializes |seed| to protobuf binary format. | 57 // Serializes |seed| to protobuf binary format. |
58 std::string SerializeSeed(const variations::VariationsSeed& seed) { | 58 std::string SerializeSeed(const variations::VariationsSeed& seed) { |
59 std::string serialized_seed; | 59 std::string serialized_seed; |
60 seed.SerializeToString(&serialized_seed); | 60 seed.SerializeToString(&serialized_seed); |
61 return serialized_seed; | 61 return serialized_seed; |
62 } | 62 } |
63 | 63 |
64 // Compresses |data| using Gzip compression and returns the result. | 64 // Compresses |data| using Gzip compression and returns the result. |
65 std::string Compress(const std::string& data) { | 65 std::string Compress(const std::string& data) { |
66 std::string compressed; | 66 std::string compressed; |
67 const bool result = metrics::GzipCompress(data, &compressed); | 67 const bool result = compression::GzipCompress(data, &compressed); |
68 EXPECT_TRUE(result); | 68 EXPECT_TRUE(result); |
69 return compressed; | 69 return compressed; |
70 } | 70 } |
71 | 71 |
72 // Serializes |seed| to compressed base64-encoded protobuf binary format. | 72 // Serializes |seed| to compressed base64-encoded protobuf binary format. |
73 std::string SerializeSeedBase64(const variations::VariationsSeed& seed) { | 73 std::string SerializeSeedBase64(const variations::VariationsSeed& seed) { |
74 std::string serialized_seed = SerializeSeed(seed); | 74 std::string serialized_seed = SerializeSeed(seed); |
75 std::string base64_serialized_seed; | 75 std::string base64_serialized_seed; |
76 base::Base64Encode(Compress(serialized_seed), &base64_serialized_seed); | 76 base::Base64Encode(Compress(serialized_seed), &base64_serialized_seed); |
77 return base64_serialized_seed; | 77 return base64_serialized_seed; |
(...skipping 262 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
340 EXPECT_TRUE(base::Base64Decode(base64_after_seed_data, &after_seed_data)); | 340 EXPECT_TRUE(base::Base64Decode(base64_after_seed_data, &after_seed_data)); |
341 EXPECT_TRUE(base::Base64Decode(base64_delta_data, &delta_data)); | 341 EXPECT_TRUE(base::Base64Decode(base64_delta_data, &delta_data)); |
342 | 342 |
343 std::string output; | 343 std::string output; |
344 EXPECT_TRUE(VariationsSeedStore::ApplyDeltaPatch(before_seed_data, delta_data, | 344 EXPECT_TRUE(VariationsSeedStore::ApplyDeltaPatch(before_seed_data, delta_data, |
345 &output)); | 345 &output)); |
346 EXPECT_EQ(after_seed_data, output); | 346 EXPECT_EQ(after_seed_data, output); |
347 } | 347 } |
348 | 348 |
349 } // namespace chrome_variations | 349 } // namespace chrome_variations |
OLD | NEW |