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

Side by Side Diff: components/variations/variations_seed_store_unittest.cc

Issue 2919223002: [Cleanup] Remove the obsolete variations_seed pref. (Closed)
Patch Set: Fix the test Created 3 years, 6 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 unified diff | Download patch
OLDNEW
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 "components/variations/variations_seed_store.h" 5 #include "components/variations/variations_seed_store.h"
6 6
7 #include "base/base64.h" 7 #include "base/base64.h"
8 #include "base/macros.h" 8 #include "base/macros.h"
9 #include "build/build_config.h" 9 #include "build/build_config.h"
10 #include "components/prefs/testing_pref_service.h" 10 #include "components/prefs/testing_pref_service.h"
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after
120 EXPECT_TRUE(PrefHasDefaultValue(prefs, prefs::kVariationsCompressedSeed)); 120 EXPECT_TRUE(PrefHasDefaultValue(prefs, prefs::kVariationsCompressedSeed));
121 EXPECT_TRUE(PrefHasDefaultValue(prefs, prefs::kVariationsSeedDate)); 121 EXPECT_TRUE(PrefHasDefaultValue(prefs, prefs::kVariationsSeedDate));
122 EXPECT_TRUE(PrefHasDefaultValue(prefs, prefs::kVariationsSeedSignature)); 122 EXPECT_TRUE(PrefHasDefaultValue(prefs, prefs::kVariationsSeedSignature));
123 123
124 // Check that having no seed in prefs results in a return value of false. 124 // Check that having no seed in prefs results in a return value of false.
125 prefs.ClearPref(prefs::kVariationsCompressedSeed); 125 prefs.ClearPref(prefs::kVariationsCompressedSeed);
126 EXPECT_FALSE(seed_store.LoadSeed(&loaded_seed)); 126 EXPECT_FALSE(seed_store.LoadSeed(&loaded_seed));
127 } 127 }
128 128
129 TEST(VariationsSeedStoreTest, GetInvalidSignature) { 129 TEST(VariationsSeedStoreTest, GetInvalidSignature) {
130 const variations::VariationsSeed seed = CreateTestSeed();
131 const std::string base64_seed = SerializeSeedBase64(seed);
132
133 TestingPrefServiceSimple prefs; 130 TestingPrefServiceSimple prefs;
134 VariationsSeedStore::RegisterPrefs(prefs.registry()); 131 VariationsSeedStore::RegisterPrefs(prefs.registry());
135 prefs.SetString(prefs::kVariationsSeed, base64_seed);
136 132
137 // The below seed and signature pair were generated using the server's 133 // The below seed and signature pair were generated using the server's
138 // private key. 134 // private key.
139 const std::string base64_seed_data = 135 const std::string uncompressed_base64_seed_data =
140 "CigxZDI5NDY0ZmIzZDc4ZmYxNTU2ZTViNTUxYzY0NDdjYmM3NGU1ZmQwEr0BCh9VTUEtVW5p" 136 "CigxZDI5NDY0ZmIzZDc4ZmYxNTU2ZTViNTUxYzY0NDdjYmM3NGU1ZmQwEr0BCh9VTUEtVW5p"
141 "Zm9ybWl0eS1UcmlhbC0xMC1QZXJjZW50GICckqUFOAFCB2RlZmF1bHRKCwoHZGVmYXVsdBAB" 137 "Zm9ybWl0eS1UcmlhbC0xMC1QZXJjZW50GICckqUFOAFCB2RlZmF1bHRKCwoHZGVmYXVsdBAB"
142 "SgwKCGdyb3VwXzAxEAFKDAoIZ3JvdXBfMDIQAUoMCghncm91cF8wMxABSgwKCGdyb3VwXzA0" 138 "SgwKCGdyb3VwXzAxEAFKDAoIZ3JvdXBfMDIQAUoMCghncm91cF8wMxABSgwKCGdyb3VwXzA0"
143 "EAFKDAoIZ3JvdXBfMDUQAUoMCghncm91cF8wNhABSgwKCGdyb3VwXzA3EAFKDAoIZ3JvdXBf" 139 "EAFKDAoIZ3JvdXBfMDUQAUoMCghncm91cF8wNhABSgwKCGdyb3VwXzA3EAFKDAoIZ3JvdXBf"
144 "MDgQAUoMCghncm91cF8wORAB"; 140 "MDgQAUoMCghncm91cF8wORAB";
145 const std::string base64_seed_signature = 141 const std::string base64_seed_signature =
146 "MEQCIDD1IVxjzWYncun+9IGzqYjZvqxxujQEayJULTlbTGA/AiAr0oVmEgVUQZBYq5VLOSvy" 142 "MEQCIDD1IVxjzWYncun+9IGzqYjZvqxxujQEayJULTlbTGA/AiAr0oVmEgVUQZBYq5VLOSvy"
147 "96JkMYgzTkHPwbv7K/CmgA=="; 143 "96JkMYgzTkHPwbv7K/CmgA==";
148 const std::string base64_seed_signature_invalid = 144 const std::string base64_seed_signature_invalid =
149 "AEQCIDD1IVxjzWYncun+9IGzqYjZvqxxujQEayJULTlbTGA/AiAr0oVmEgVUQZBYq5VLOSvy" 145 "AEQCIDD1IVxjzWYncun+9IGzqYjZvqxxujQEayJULTlbTGA/AiAr0oVmEgVUQZBYq5VLOSvy"
150 "96JkMYgzTkHPwbv7K/CmgA=="; 146 "96JkMYgzTkHPwbv7K/CmgA==";
151 147
148 std::string uncompressed_seed_data;
149 ASSERT_TRUE(base::Base64Decode(uncompressed_base64_seed_data,
150 &uncompressed_seed_data));
151 std::string compressed_base64_seed_data;
152 base::Base64Encode(Compress(uncompressed_seed_data),
153 &compressed_base64_seed_data);
154
152 // Set seed and valid signature in prefs. 155 // Set seed and valid signature in prefs.
153 prefs.SetString(prefs::kVariationsSeed, base64_seed_data); 156 prefs.SetString(prefs::kVariationsCompressedSeed,
157 compressed_base64_seed_data);
154 prefs.SetString(prefs::kVariationsSeedSignature, base64_seed_signature); 158 prefs.SetString(prefs::kVariationsSeedSignature, base64_seed_signature);
155 159
156 VariationsSeedStore seed_store(&prefs); 160 VariationsSeedStore seed_store(&prefs);
157 variations::VariationsSeed loaded_seed; 161 variations::VariationsSeed loaded_seed;
158 seed_store.LoadSeed(&loaded_seed); 162 seed_store.LoadSeed(&loaded_seed);
159 std::string invalid_signature = seed_store.GetInvalidSignature(); 163 std::string invalid_signature = seed_store.GetInvalidSignature();
160 // Valid signature so we get an empty string. 164 // Valid signature so we get an empty string.
161 EXPECT_EQ(std::string(), invalid_signature); 165 EXPECT_EQ(std::string(), invalid_signature);
162 166
163 prefs.SetString(prefs::kVariationsSeedSignature, 167 prefs.SetString(prefs::kVariationsSeedSignature,
(...skipping 244 matching lines...) Expand 10 before | Expand all | Expand 10 after
408 &response_date, &is_gzip_compressed); 412 &response_date, &is_gzip_compressed);
409 EXPECT_EQ("", seed_data); 413 EXPECT_EQ("", seed_data);
410 EXPECT_EQ("", seed_signature); 414 EXPECT_EQ("", seed_signature);
411 EXPECT_EQ("", seed_country); 415 EXPECT_EQ("", seed_country);
412 EXPECT_EQ("", response_date); 416 EXPECT_EQ("", response_date);
413 EXPECT_FALSE(is_gzip_compressed); 417 EXPECT_FALSE(is_gzip_compressed);
414 } 418 }
415 #endif // OS_ANDROID 419 #endif // OS_ANDROID
416 420
417 } // namespace variations 421 } // namespace variations
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698