| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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/user_prefs/tracked/pref_hash_store_impl.h" | 5 #include "services/preferences/tracked/pref_hash_store_impl.h" |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 | 8 |
| 9 #include "base/macros.h" | 9 #include "base/macros.h" |
| 10 #include "base/values.h" | 10 #include "base/values.h" |
| 11 #include "components/user_prefs/tracked/dictionary_hash_store_contents.h" | 11 #include "services/preferences/tracked/dictionary_hash_store_contents.h" |
| 12 #include "components/user_prefs/tracked/hash_store_contents.h" | 12 #include "services/preferences/tracked/hash_store_contents.h" |
| 13 #include "components/user_prefs/tracked/pref_hash_store_impl.h" | 13 #include "services/preferences/tracked/pref_hash_store_transaction.h" |
| 14 #include "components/user_prefs/tracked/pref_hash_store_transaction.h" | |
| 15 #include "testing/gtest/include/gtest/gtest.h" | 14 #include "testing/gtest/include/gtest/gtest.h" |
| 16 | 15 |
| 16 using ValueState = |
| 17 prefs::mojom::TrackedPreferenceValidationDelegate::ValueState; |
| 18 |
| 17 class PrefHashStoreImplTest : public testing::Test { | 19 class PrefHashStoreImplTest : public testing::Test { |
| 18 public: | 20 public: |
| 19 PrefHashStoreImplTest() : contents_(&pref_store_contents_) {} | 21 PrefHashStoreImplTest() : contents_(&pref_store_contents_) {} |
| 20 | 22 |
| 21 protected: | 23 protected: |
| 22 HashStoreContents* GetHashStoreContents() { return &contents_; } | 24 HashStoreContents* GetHashStoreContents() { return &contents_; } |
| 23 | 25 |
| 24 private: | 26 private: |
| 25 base::DictionaryValue pref_store_contents_; | 27 base::DictionaryValue pref_store_contents_; |
| 26 // Must be declared after |pref_store_contents_| as it needs to be outlived | 28 // Must be declared after |pref_store_contents_| as it needs to be outlived |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 73 base::Value string_1("string1"); | 75 base::Value string_1("string1"); |
| 74 base::Value string_2("string2"); | 76 base::Value string_2("string2"); |
| 75 | 77 |
| 76 { | 78 { |
| 77 // 32 NULL bytes is the seed that was used to generate the legacy hash. | 79 // 32 NULL bytes is the seed that was used to generate the legacy hash. |
| 78 PrefHashStoreImpl pref_hash_store(std::string(32, 0), "device_id", true); | 80 PrefHashStoreImpl pref_hash_store(std::string(32, 0), "device_id", true); |
| 79 std::unique_ptr<PrefHashStoreTransaction> transaction( | 81 std::unique_ptr<PrefHashStoreTransaction> transaction( |
| 80 pref_hash_store.BeginTransaction(GetHashStoreContents())); | 82 pref_hash_store.BeginTransaction(GetHashStoreContents())); |
| 81 | 83 |
| 82 // Only NULL should be trusted in the absence of a hash. | 84 // Only NULL should be trusted in the absence of a hash. |
| 83 EXPECT_EQ(PrefHashStoreTransaction::UNTRUSTED_UNKNOWN_VALUE, | 85 EXPECT_EQ(ValueState::UNTRUSTED_UNKNOWN_VALUE, |
| 84 transaction->CheckValue("path1", &string_1)); | 86 transaction->CheckValue("path1", &string_1)); |
| 85 EXPECT_EQ(PrefHashStoreTransaction::TRUSTED_NULL_VALUE, | 87 EXPECT_EQ(ValueState::TRUSTED_NULL_VALUE, |
| 86 transaction->CheckValue("path1", NULL)); | 88 transaction->CheckValue("path1", NULL)); |
| 87 | 89 |
| 88 transaction->StoreHash("path1", &string_1); | 90 transaction->StoreHash("path1", &string_1); |
| 89 EXPECT_EQ(PrefHashStoreTransaction::UNCHANGED, | 91 EXPECT_EQ(ValueState::UNCHANGED, |
| 90 transaction->CheckValue("path1", &string_1)); | 92 transaction->CheckValue("path1", &string_1)); |
| 91 EXPECT_EQ(PrefHashStoreTransaction::CLEARED, | 93 EXPECT_EQ(ValueState::CLEARED, transaction->CheckValue("path1", NULL)); |
| 92 transaction->CheckValue("path1", NULL)); | |
| 93 transaction->StoreHash("path1", NULL); | 94 transaction->StoreHash("path1", NULL); |
| 94 EXPECT_EQ(PrefHashStoreTransaction::UNCHANGED, | 95 EXPECT_EQ(ValueState::UNCHANGED, transaction->CheckValue("path1", NULL)); |
| 95 transaction->CheckValue("path1", NULL)); | 96 EXPECT_EQ(ValueState::CHANGED, transaction->CheckValue("path1", &string_2)); |
| 96 EXPECT_EQ(PrefHashStoreTransaction::CHANGED, | |
| 97 transaction->CheckValue("path1", &string_2)); | |
| 98 | 97 |
| 99 base::DictionaryValue dict; | 98 base::DictionaryValue dict; |
| 100 dict.Set("a", new base::Value("foo")); | 99 dict.Set("a", new base::Value("foo")); |
| 101 dict.Set("d", new base::Value("bad")); | 100 dict.Set("d", new base::Value("bad")); |
| 102 dict.Set("b", new base::Value("bar")); | 101 dict.Set("b", new base::Value("bar")); |
| 103 dict.Set("c", new base::Value("baz")); | 102 dict.Set("c", new base::Value("baz")); |
| 104 | 103 |
| 105 transaction->StoreHash("path1", &dict); | 104 transaction->StoreHash("path1", &dict); |
| 106 EXPECT_EQ(PrefHashStoreTransaction::UNCHANGED, | 105 EXPECT_EQ(ValueState::UNCHANGED, transaction->CheckValue("path1", &dict)); |
| 107 transaction->CheckValue("path1", &dict)); | |
| 108 } | 106 } |
| 109 | 107 |
| 110 ASSERT_FALSE(GetHashStoreContents()->GetSuperMac().empty()); | 108 ASSERT_FALSE(GetHashStoreContents()->GetSuperMac().empty()); |
| 111 | 109 |
| 112 { | 110 { |
| 113 // |pref_hash_store2| should trust its initial hashes dictionary and thus | 111 // |pref_hash_store2| should trust its initial hashes dictionary and thus |
| 114 // trust new unknown values. | 112 // trust new unknown values. |
| 115 PrefHashStoreImpl pref_hash_store2(std::string(32, 0), "device_id", true); | 113 PrefHashStoreImpl pref_hash_store2(std::string(32, 0), "device_id", true); |
| 116 std::unique_ptr<PrefHashStoreTransaction> transaction( | 114 std::unique_ptr<PrefHashStoreTransaction> transaction( |
| 117 pref_hash_store2.BeginTransaction(GetHashStoreContents())); | 115 pref_hash_store2.BeginTransaction(GetHashStoreContents())); |
| 118 EXPECT_EQ(PrefHashStoreTransaction::TRUSTED_UNKNOWN_VALUE, | 116 EXPECT_EQ(ValueState::TRUSTED_UNKNOWN_VALUE, |
| 119 transaction->CheckValue("new_path", &string_1)); | 117 transaction->CheckValue("new_path", &string_1)); |
| 120 EXPECT_EQ(PrefHashStoreTransaction::TRUSTED_UNKNOWN_VALUE, | 118 EXPECT_EQ(ValueState::TRUSTED_UNKNOWN_VALUE, |
| 121 transaction->CheckValue("new_path", &string_2)); | 119 transaction->CheckValue("new_path", &string_2)); |
| 122 EXPECT_EQ(PrefHashStoreTransaction::TRUSTED_NULL_VALUE, | 120 EXPECT_EQ(ValueState::TRUSTED_NULL_VALUE, |
| 123 transaction->CheckValue("new_path", NULL)); | 121 transaction->CheckValue("new_path", NULL)); |
| 124 } | 122 } |
| 125 | 123 |
| 126 // Manually corrupt the super MAC. | 124 // Manually corrupt the super MAC. |
| 127 GetHashStoreContents()->SetSuperMac(std::string(64, 'A')); | 125 GetHashStoreContents()->SetSuperMac(std::string(64, 'A')); |
| 128 | 126 |
| 129 { | 127 { |
| 130 // |pref_hash_store3| should no longer trust its initial hashes dictionary | 128 // |pref_hash_store3| should no longer trust its initial hashes dictionary |
| 131 // and thus shouldn't trust non-NULL unknown values. | 129 // and thus shouldn't trust non-NULL unknown values. |
| 132 PrefHashStoreImpl pref_hash_store3(std::string(32, 0), "device_id", true); | 130 PrefHashStoreImpl pref_hash_store3(std::string(32, 0), "device_id", true); |
| 133 std::unique_ptr<PrefHashStoreTransaction> transaction( | 131 std::unique_ptr<PrefHashStoreTransaction> transaction( |
| 134 pref_hash_store3.BeginTransaction(GetHashStoreContents())); | 132 pref_hash_store3.BeginTransaction(GetHashStoreContents())); |
| 135 EXPECT_EQ(PrefHashStoreTransaction::UNTRUSTED_UNKNOWN_VALUE, | 133 EXPECT_EQ(ValueState::UNTRUSTED_UNKNOWN_VALUE, |
| 136 transaction->CheckValue("new_path", &string_1)); | 134 transaction->CheckValue("new_path", &string_1)); |
| 137 EXPECT_EQ(PrefHashStoreTransaction::UNTRUSTED_UNKNOWN_VALUE, | 135 EXPECT_EQ(ValueState::UNTRUSTED_UNKNOWN_VALUE, |
| 138 transaction->CheckValue("new_path", &string_2)); | 136 transaction->CheckValue("new_path", &string_2)); |
| 139 EXPECT_EQ(PrefHashStoreTransaction::TRUSTED_NULL_VALUE, | 137 EXPECT_EQ(ValueState::TRUSTED_NULL_VALUE, |
| 140 transaction->CheckValue("new_path", NULL)); | 138 transaction->CheckValue("new_path", NULL)); |
| 141 } | 139 } |
| 142 } | 140 } |
| 143 | 141 |
| 144 TEST_F(PrefHashStoreImplTest, ImportExportOperations) { | 142 TEST_F(PrefHashStoreImplTest, ImportExportOperations) { |
| 145 base::Value string_1("string1"); | 143 base::Value string_1("string1"); |
| 146 base::Value string_2("string2"); | 144 base::Value string_2("string2"); |
| 147 | 145 |
| 148 // Initial state: no super MAC. | 146 // Initial state: no super MAC. |
| 149 { | 147 { |
| 150 PrefHashStoreImpl pref_hash_store(std::string(32, 0), "device_id", true); | 148 PrefHashStoreImpl pref_hash_store(std::string(32, 0), "device_id", true); |
| 151 std::unique_ptr<PrefHashStoreTransaction> transaction( | 149 std::unique_ptr<PrefHashStoreTransaction> transaction( |
| 152 pref_hash_store.BeginTransaction(GetHashStoreContents())); | 150 pref_hash_store.BeginTransaction(GetHashStoreContents())); |
| 153 ASSERT_FALSE(transaction->IsSuperMACValid()); | 151 ASSERT_FALSE(transaction->IsSuperMACValid()); |
| 154 | 152 |
| 155 ASSERT_FALSE(transaction->HasHash("path1")); | 153 ASSERT_FALSE(transaction->HasHash("path1")); |
| 156 | 154 |
| 157 // Storing a hash will stamp the super MAC. | 155 // Storing a hash will stamp the super MAC. |
| 158 transaction->StoreHash("path1", &string_1); | 156 transaction->StoreHash("path1", &string_1); |
| 159 | 157 |
| 160 ASSERT_TRUE(transaction->HasHash("path1")); | 158 ASSERT_TRUE(transaction->HasHash("path1")); |
| 161 EXPECT_EQ(PrefHashStoreTransaction::UNCHANGED, | 159 EXPECT_EQ(ValueState::UNCHANGED, |
| 162 transaction->CheckValue("path1", &string_1)); | 160 transaction->CheckValue("path1", &string_1)); |
| 163 EXPECT_EQ(PrefHashStoreTransaction::CHANGED, | 161 EXPECT_EQ(ValueState::CHANGED, transaction->CheckValue("path1", &string_2)); |
| 164 transaction->CheckValue("path1", &string_2)); | |
| 165 } | 162 } |
| 166 | 163 |
| 167 // Make a copy of the stored hash for future use. | 164 // Make a copy of the stored hash for future use. |
| 168 const base::Value* hash = NULL; | 165 const base::Value* hash = NULL; |
| 169 ASSERT_TRUE(GetHashStoreContents()->GetContents()->Get("path1", &hash)); | 166 ASSERT_TRUE(GetHashStoreContents()->GetContents()->Get("path1", &hash)); |
| 170 std::unique_ptr<base::Value> path_1_string_1_hash_copy(hash->DeepCopy()); | 167 std::unique_ptr<base::Value> path_1_string_1_hash_copy(hash->DeepCopy()); |
| 171 hash = NULL; | 168 hash = NULL; |
| 172 | 169 |
| 173 // Verify that the super MAC was stamped. | 170 // Verify that the super MAC was stamped. |
| 174 { | 171 { |
| 175 PrefHashStoreImpl pref_hash_store(std::string(32, 0), "device_id", true); | 172 PrefHashStoreImpl pref_hash_store(std::string(32, 0), "device_id", true); |
| 176 std::unique_ptr<PrefHashStoreTransaction> transaction( | 173 std::unique_ptr<PrefHashStoreTransaction> transaction( |
| 177 pref_hash_store.BeginTransaction(GetHashStoreContents())); | 174 pref_hash_store.BeginTransaction(GetHashStoreContents())); |
| 178 ASSERT_TRUE(transaction->IsSuperMACValid()); | 175 ASSERT_TRUE(transaction->IsSuperMACValid()); |
| 179 ASSERT_TRUE(transaction->HasHash("path1")); | 176 ASSERT_TRUE(transaction->HasHash("path1")); |
| 180 | 177 |
| 181 // Clearing the hash should preserve validity. | 178 // Clearing the hash should preserve validity. |
| 182 transaction->ClearHash("path1"); | 179 transaction->ClearHash("path1"); |
| 183 | 180 |
| 184 // The effects of the clear should be immediately visible. | 181 // The effects of the clear should be immediately visible. |
| 185 ASSERT_FALSE(transaction->HasHash("path1")); | 182 ASSERT_FALSE(transaction->HasHash("path1")); |
| 186 EXPECT_EQ(PrefHashStoreTransaction::TRUSTED_NULL_VALUE, | 183 EXPECT_EQ(ValueState::TRUSTED_NULL_VALUE, |
| 187 transaction->CheckValue("path1", NULL)); | 184 transaction->CheckValue("path1", NULL)); |
| 188 EXPECT_EQ(PrefHashStoreTransaction::TRUSTED_UNKNOWN_VALUE, | 185 EXPECT_EQ(ValueState::TRUSTED_UNKNOWN_VALUE, |
| 189 transaction->CheckValue("path1", &string_1)); | 186 transaction->CheckValue("path1", &string_1)); |
| 190 } | 187 } |
| 191 | 188 |
| 192 // Verify that validity was preserved and that the clear took effect. | 189 // Verify that validity was preserved and that the clear took effect. |
| 193 { | 190 { |
| 194 PrefHashStoreImpl pref_hash_store(std::string(32, 0), "device_id", true); | 191 PrefHashStoreImpl pref_hash_store(std::string(32, 0), "device_id", true); |
| 195 std::unique_ptr<PrefHashStoreTransaction> transaction( | 192 std::unique_ptr<PrefHashStoreTransaction> transaction( |
| 196 pref_hash_store.BeginTransaction(GetHashStoreContents())); | 193 pref_hash_store.BeginTransaction(GetHashStoreContents())); |
| 197 ASSERT_TRUE(transaction->IsSuperMACValid()); | 194 ASSERT_TRUE(transaction->IsSuperMACValid()); |
| 198 ASSERT_FALSE(transaction->HasHash("path1")); | 195 ASSERT_FALSE(transaction->HasHash("path1")); |
| 199 } | 196 } |
| 200 | 197 |
| 201 // Invalidate the super MAC. | 198 // Invalidate the super MAC. |
| 202 GetHashStoreContents()->SetSuperMac(std::string()); | 199 GetHashStoreContents()->SetSuperMac(std::string()); |
| 203 | 200 |
| 204 { | 201 { |
| 205 PrefHashStoreImpl pref_hash_store(std::string(32, 0), "device_id", true); | 202 PrefHashStoreImpl pref_hash_store(std::string(32, 0), "device_id", true); |
| 206 std::unique_ptr<PrefHashStoreTransaction> transaction( | 203 std::unique_ptr<PrefHashStoreTransaction> transaction( |
| 207 pref_hash_store.BeginTransaction(GetHashStoreContents())); | 204 pref_hash_store.BeginTransaction(GetHashStoreContents())); |
| 208 ASSERT_FALSE(transaction->IsSuperMACValid()); | 205 ASSERT_FALSE(transaction->IsSuperMACValid()); |
| 209 ASSERT_FALSE(transaction->HasHash("path1")); | 206 ASSERT_FALSE(transaction->HasHash("path1")); |
| 210 | 207 |
| 211 // An import should preserve invalidity. | 208 // An import should preserve invalidity. |
| 212 transaction->ImportHash("path1", path_1_string_1_hash_copy.get()); | 209 transaction->ImportHash("path1", path_1_string_1_hash_copy.get()); |
| 213 | 210 |
| 214 ASSERT_TRUE(transaction->HasHash("path1")); | 211 ASSERT_TRUE(transaction->HasHash("path1")); |
| 215 | 212 |
| 216 // The imported hash should be usable for validating the original value. | 213 // The imported hash should be usable for validating the original value. |
| 217 EXPECT_EQ(PrefHashStoreTransaction::UNCHANGED, | 214 EXPECT_EQ(ValueState::UNCHANGED, |
| 218 transaction->CheckValue("path1", &string_1)); | 215 transaction->CheckValue("path1", &string_1)); |
| 219 } | 216 } |
| 220 | 217 |
| 221 // Verify that invalidity was preserved and that the import took effect. | 218 // Verify that invalidity was preserved and that the import took effect. |
| 222 { | 219 { |
| 223 PrefHashStoreImpl pref_hash_store(std::string(32, 0), "device_id", true); | 220 PrefHashStoreImpl pref_hash_store(std::string(32, 0), "device_id", true); |
| 224 std::unique_ptr<PrefHashStoreTransaction> transaction( | 221 std::unique_ptr<PrefHashStoreTransaction> transaction( |
| 225 pref_hash_store.BeginTransaction(GetHashStoreContents())); | 222 pref_hash_store.BeginTransaction(GetHashStoreContents())); |
| 226 ASSERT_FALSE(transaction->IsSuperMACValid()); | 223 ASSERT_FALSE(transaction->IsSuperMACValid()); |
| 227 ASSERT_TRUE(transaction->HasHash("path1")); | 224 ASSERT_TRUE(transaction->HasHash("path1")); |
| 228 EXPECT_EQ(PrefHashStoreTransaction::UNCHANGED, | 225 EXPECT_EQ(ValueState::UNCHANGED, |
| 229 transaction->CheckValue("path1", &string_1)); | 226 transaction->CheckValue("path1", &string_1)); |
| 230 | 227 |
| 231 // After clearing the hash, non-null values are UNTRUSTED_UNKNOWN. | 228 // After clearing the hash, non-null values are UNTRUSTED_UNKNOWN. |
| 232 transaction->ClearHash("path1"); | 229 transaction->ClearHash("path1"); |
| 233 | 230 |
| 234 EXPECT_EQ(PrefHashStoreTransaction::TRUSTED_NULL_VALUE, | 231 EXPECT_EQ(ValueState::TRUSTED_NULL_VALUE, |
| 235 transaction->CheckValue("path1", NULL)); | 232 transaction->CheckValue("path1", NULL)); |
| 236 EXPECT_EQ(PrefHashStoreTransaction::UNTRUSTED_UNKNOWN_VALUE, | 233 EXPECT_EQ(ValueState::UNTRUSTED_UNKNOWN_VALUE, |
| 237 transaction->CheckValue("path1", &string_1)); | 234 transaction->CheckValue("path1", &string_1)); |
| 238 } | 235 } |
| 239 | 236 |
| 240 { | 237 { |
| 241 PrefHashStoreImpl pref_hash_store(std::string(32, 0), "device_id", true); | 238 PrefHashStoreImpl pref_hash_store(std::string(32, 0), "device_id", true); |
| 242 std::unique_ptr<PrefHashStoreTransaction> transaction( | 239 std::unique_ptr<PrefHashStoreTransaction> transaction( |
| 243 pref_hash_store.BeginTransaction(GetHashStoreContents())); | 240 pref_hash_store.BeginTransaction(GetHashStoreContents())); |
| 244 ASSERT_FALSE(transaction->IsSuperMACValid()); | 241 ASSERT_FALSE(transaction->IsSuperMACValid()); |
| 245 | 242 |
| 246 // Test StampSuperMac. | 243 // Test StampSuperMac. |
| 247 transaction->StampSuperMac(); | 244 transaction->StampSuperMac(); |
| 248 } | 245 } |
| 249 | 246 |
| 250 // Verify that the store is now valid. | 247 // Verify that the store is now valid. |
| 251 { | 248 { |
| 252 PrefHashStoreImpl pref_hash_store(std::string(32, 0), "device_id", true); | 249 PrefHashStoreImpl pref_hash_store(std::string(32, 0), "device_id", true); |
| 253 std::unique_ptr<PrefHashStoreTransaction> transaction( | 250 std::unique_ptr<PrefHashStoreTransaction> transaction( |
| 254 pref_hash_store.BeginTransaction(GetHashStoreContents())); | 251 pref_hash_store.BeginTransaction(GetHashStoreContents())); |
| 255 ASSERT_TRUE(transaction->IsSuperMACValid()); | 252 ASSERT_TRUE(transaction->IsSuperMACValid()); |
| 256 | 253 |
| 257 // Store the hash of a different value to test an "over-import". | 254 // Store the hash of a different value to test an "over-import". |
| 258 transaction->StoreHash("path1", &string_2); | 255 transaction->StoreHash("path1", &string_2); |
| 259 EXPECT_EQ(PrefHashStoreTransaction::CHANGED, | 256 EXPECT_EQ(ValueState::CHANGED, transaction->CheckValue("path1", &string_1)); |
| 260 transaction->CheckValue("path1", &string_1)); | 257 EXPECT_EQ(ValueState::UNCHANGED, |
| 261 EXPECT_EQ(PrefHashStoreTransaction::UNCHANGED, | |
| 262 transaction->CheckValue("path1", &string_2)); | 258 transaction->CheckValue("path1", &string_2)); |
| 263 } | 259 } |
| 264 | 260 |
| 265 { | 261 { |
| 266 PrefHashStoreImpl pref_hash_store(std::string(32, 0), "device_id", true); | 262 PrefHashStoreImpl pref_hash_store(std::string(32, 0), "device_id", true); |
| 267 std::unique_ptr<PrefHashStoreTransaction> transaction( | 263 std::unique_ptr<PrefHashStoreTransaction> transaction( |
| 268 pref_hash_store.BeginTransaction(GetHashStoreContents())); | 264 pref_hash_store.BeginTransaction(GetHashStoreContents())); |
| 269 ASSERT_TRUE(transaction->IsSuperMACValid()); | 265 ASSERT_TRUE(transaction->IsSuperMACValid()); |
| 270 | 266 |
| 271 // "Over-import". An import should preserve validity. | 267 // "Over-import". An import should preserve validity. |
| 272 transaction->ImportHash("path1", path_1_string_1_hash_copy.get()); | 268 transaction->ImportHash("path1", path_1_string_1_hash_copy.get()); |
| 273 EXPECT_EQ(PrefHashStoreTransaction::UNCHANGED, | 269 EXPECT_EQ(ValueState::UNCHANGED, |
| 274 transaction->CheckValue("path1", &string_1)); | 270 transaction->CheckValue("path1", &string_1)); |
| 275 EXPECT_EQ(PrefHashStoreTransaction::CHANGED, | 271 EXPECT_EQ(ValueState::CHANGED, transaction->CheckValue("path1", &string_2)); |
| 276 transaction->CheckValue("path1", &string_2)); | |
| 277 } | 272 } |
| 278 | 273 |
| 279 // Verify that validity was preserved and the "over-import" took effect. | 274 // Verify that validity was preserved and the "over-import" took effect. |
| 280 { | 275 { |
| 281 PrefHashStoreImpl pref_hash_store(std::string(32, 0), "device_id", true); | 276 PrefHashStoreImpl pref_hash_store(std::string(32, 0), "device_id", true); |
| 282 std::unique_ptr<PrefHashStoreTransaction> transaction( | 277 std::unique_ptr<PrefHashStoreTransaction> transaction( |
| 283 pref_hash_store.BeginTransaction(GetHashStoreContents())); | 278 pref_hash_store.BeginTransaction(GetHashStoreContents())); |
| 284 ASSERT_TRUE(transaction->IsSuperMACValid()); | 279 ASSERT_TRUE(transaction->IsSuperMACValid()); |
| 285 EXPECT_EQ(PrefHashStoreTransaction::UNCHANGED, | 280 EXPECT_EQ(ValueState::UNCHANGED, |
| 286 transaction->CheckValue("path1", &string_1)); | 281 transaction->CheckValue("path1", &string_1)); |
| 287 EXPECT_EQ(PrefHashStoreTransaction::CHANGED, | 282 EXPECT_EQ(ValueState::CHANGED, transaction->CheckValue("path1", &string_2)); |
| 288 transaction->CheckValue("path1", &string_2)); | |
| 289 } | 283 } |
| 290 } | 284 } |
| 291 | 285 |
| 292 TEST_F(PrefHashStoreImplTest, SuperMACDisabled) { | 286 TEST_F(PrefHashStoreImplTest, SuperMACDisabled) { |
| 293 base::Value string_1("string1"); | 287 base::Value string_1("string1"); |
| 294 base::Value string_2("string2"); | 288 base::Value string_2("string2"); |
| 295 | 289 |
| 296 { | 290 { |
| 297 // Pass |use_super_mac| => false. | 291 // Pass |use_super_mac| => false. |
| 298 PrefHashStoreImpl pref_hash_store(std::string(32, 0), "device_id", false); | 292 PrefHashStoreImpl pref_hash_store(std::string(32, 0), "device_id", false); |
| 299 std::unique_ptr<PrefHashStoreTransaction> transaction( | 293 std::unique_ptr<PrefHashStoreTransaction> transaction( |
| 300 pref_hash_store.BeginTransaction(GetHashStoreContents())); | 294 pref_hash_store.BeginTransaction(GetHashStoreContents())); |
| 301 | 295 |
| 302 transaction->StoreHash("path1", &string_2); | 296 transaction->StoreHash("path1", &string_2); |
| 303 EXPECT_EQ(PrefHashStoreTransaction::UNCHANGED, | 297 EXPECT_EQ(ValueState::UNCHANGED, |
| 304 transaction->CheckValue("path1", &string_2)); | 298 transaction->CheckValue("path1", &string_2)); |
| 305 } | 299 } |
| 306 | 300 |
| 307 ASSERT_TRUE(GetHashStoreContents()->GetSuperMac().empty()); | 301 ASSERT_TRUE(GetHashStoreContents()->GetSuperMac().empty()); |
| 308 | 302 |
| 309 { | 303 { |
| 310 PrefHashStoreImpl pref_hash_store2(std::string(32, 0), "device_id", false); | 304 PrefHashStoreImpl pref_hash_store2(std::string(32, 0), "device_id", false); |
| 311 std::unique_ptr<PrefHashStoreTransaction> transaction( | 305 std::unique_ptr<PrefHashStoreTransaction> transaction( |
| 312 pref_hash_store2.BeginTransaction(GetHashStoreContents())); | 306 pref_hash_store2.BeginTransaction(GetHashStoreContents())); |
| 313 EXPECT_EQ(PrefHashStoreTransaction::UNTRUSTED_UNKNOWN_VALUE, | 307 EXPECT_EQ(ValueState::UNTRUSTED_UNKNOWN_VALUE, |
| 314 transaction->CheckValue("new_path", &string_1)); | 308 transaction->CheckValue("new_path", &string_1)); |
| 315 } | 309 } |
| 316 } | 310 } |
| 317 | 311 |
| 318 TEST_F(PrefHashStoreImplTest, SplitHashStoreAndCheck) { | 312 TEST_F(PrefHashStoreImplTest, SplitHashStoreAndCheck) { |
| 319 base::DictionaryValue dict; | 313 base::DictionaryValue dict; |
| 320 dict.Set("a", new base::Value("to be replaced")); | 314 dict.Set("a", new base::Value("to be replaced")); |
| 321 dict.Set("b", new base::Value("same")); | 315 dict.Set("b", new base::Value("same")); |
| 322 dict.Set("o", new base::Value("old")); | 316 dict.Set("o", new base::Value("old")); |
| 323 | 317 |
| 324 base::DictionaryValue modified_dict; | 318 base::DictionaryValue modified_dict; |
| 325 modified_dict.Set("a", new base::Value("replaced")); | 319 modified_dict.Set("a", new base::Value("replaced")); |
| 326 modified_dict.Set("b", new base::Value("same")); | 320 modified_dict.Set("b", new base::Value("same")); |
| 327 modified_dict.Set("c", new base::Value("new")); | 321 modified_dict.Set("c", new base::Value("new")); |
| 328 | 322 |
| 329 base::DictionaryValue empty_dict; | 323 base::DictionaryValue empty_dict; |
| 330 | 324 |
| 331 std::vector<std::string> invalid_keys; | 325 std::vector<std::string> invalid_keys; |
| 332 | 326 |
| 333 { | 327 { |
| 334 PrefHashStoreImpl pref_hash_store(std::string(32, 0), "device_id", true); | 328 PrefHashStoreImpl pref_hash_store(std::string(32, 0), "device_id", true); |
| 335 std::unique_ptr<PrefHashStoreTransaction> transaction( | 329 std::unique_ptr<PrefHashStoreTransaction> transaction( |
| 336 pref_hash_store.BeginTransaction(GetHashStoreContents())); | 330 pref_hash_store.BeginTransaction(GetHashStoreContents())); |
| 337 | 331 |
| 338 // No hashes stored yet and hashes dictionary is empty (and thus not | 332 // No hashes stored yet and hashes dictionary is empty (and thus not |
| 339 // trusted). | 333 // trusted). |
| 340 EXPECT_EQ(PrefHashStoreTransaction::UNTRUSTED_UNKNOWN_VALUE, | 334 EXPECT_EQ(ValueState::UNTRUSTED_UNKNOWN_VALUE, |
| 341 transaction->CheckSplitValue("path1", &dict, &invalid_keys)); | 335 transaction->CheckSplitValue("path1", &dict, &invalid_keys)); |
| 342 EXPECT_TRUE(invalid_keys.empty()); | 336 EXPECT_TRUE(invalid_keys.empty()); |
| 343 | 337 |
| 344 transaction->StoreSplitHash("path1", &dict); | 338 transaction->StoreSplitHash("path1", &dict); |
| 345 | 339 |
| 346 // Verify match post storage. | 340 // Verify match post storage. |
| 347 EXPECT_EQ(PrefHashStoreTransaction::UNCHANGED, | 341 EXPECT_EQ(ValueState::UNCHANGED, |
| 348 transaction->CheckSplitValue("path1", &dict, &invalid_keys)); | 342 transaction->CheckSplitValue("path1", &dict, &invalid_keys)); |
| 349 EXPECT_TRUE(invalid_keys.empty()); | 343 EXPECT_TRUE(invalid_keys.empty()); |
| 350 | 344 |
| 351 // Verify new path is still unknown. | 345 // Verify new path is still unknown. |
| 352 EXPECT_EQ(PrefHashStoreTransaction::UNTRUSTED_UNKNOWN_VALUE, | 346 EXPECT_EQ(ValueState::UNTRUSTED_UNKNOWN_VALUE, |
| 353 transaction->CheckSplitValue("path2", &dict, &invalid_keys)); | 347 transaction->CheckSplitValue("path2", &dict, &invalid_keys)); |
| 354 EXPECT_TRUE(invalid_keys.empty()); | 348 EXPECT_TRUE(invalid_keys.empty()); |
| 355 | 349 |
| 356 // Verify NULL or empty dicts are declared as having been cleared. | 350 // Verify NULL or empty dicts are declared as having been cleared. |
| 357 EXPECT_EQ(PrefHashStoreTransaction::CLEARED, | 351 EXPECT_EQ(ValueState::CLEARED, |
| 358 transaction->CheckSplitValue("path1", NULL, &invalid_keys)); | 352 transaction->CheckSplitValue("path1", NULL, &invalid_keys)); |
| 359 EXPECT_TRUE(invalid_keys.empty()); | 353 EXPECT_TRUE(invalid_keys.empty()); |
| 360 EXPECT_EQ( | 354 EXPECT_EQ(ValueState::CLEARED, transaction->CheckSplitValue( |
| 361 PrefHashStoreTransaction::CLEARED, | 355 "path1", &empty_dict, &invalid_keys)); |
| 362 transaction->CheckSplitValue("path1", &empty_dict, &invalid_keys)); | |
| 363 EXPECT_TRUE(invalid_keys.empty()); | 356 EXPECT_TRUE(invalid_keys.empty()); |
| 364 | 357 |
| 365 // Verify changes are properly detected. | 358 // Verify changes are properly detected. |
| 366 EXPECT_EQ( | 359 EXPECT_EQ(ValueState::CHANGED, transaction->CheckSplitValue( |
| 367 PrefHashStoreTransaction::CHANGED, | 360 "path1", &modified_dict, &invalid_keys)); |
| 368 transaction->CheckSplitValue("path1", &modified_dict, &invalid_keys)); | |
| 369 std::vector<std::string> expected_invalid_keys1; | 361 std::vector<std::string> expected_invalid_keys1; |
| 370 expected_invalid_keys1.push_back("a"); | 362 expected_invalid_keys1.push_back("a"); |
| 371 expected_invalid_keys1.push_back("c"); | 363 expected_invalid_keys1.push_back("c"); |
| 372 expected_invalid_keys1.push_back("o"); | 364 expected_invalid_keys1.push_back("o"); |
| 373 EXPECT_EQ(expected_invalid_keys1, invalid_keys); | 365 EXPECT_EQ(expected_invalid_keys1, invalid_keys); |
| 374 invalid_keys.clear(); | 366 invalid_keys.clear(); |
| 375 | 367 |
| 376 // Verify |dict| still matches post check. | 368 // Verify |dict| still matches post check. |
| 377 EXPECT_EQ(PrefHashStoreTransaction::UNCHANGED, | 369 EXPECT_EQ(ValueState::UNCHANGED, |
| 378 transaction->CheckSplitValue("path1", &dict, &invalid_keys)); | 370 transaction->CheckSplitValue("path1", &dict, &invalid_keys)); |
| 379 EXPECT_TRUE(invalid_keys.empty()); | 371 EXPECT_TRUE(invalid_keys.empty()); |
| 380 | 372 |
| 381 // Store hash for |modified_dict|. | 373 // Store hash for |modified_dict|. |
| 382 transaction->StoreSplitHash("path1", &modified_dict); | 374 transaction->StoreSplitHash("path1", &modified_dict); |
| 383 | 375 |
| 384 // Verify |modified_dict| is now the one that verifies correctly. | 376 // Verify |modified_dict| is now the one that verifies correctly. |
| 385 EXPECT_EQ( | 377 EXPECT_EQ( |
| 386 PrefHashStoreTransaction::UNCHANGED, | 378 ValueState::UNCHANGED, |
| 387 transaction->CheckSplitValue("path1", &modified_dict, &invalid_keys)); | 379 transaction->CheckSplitValue("path1", &modified_dict, &invalid_keys)); |
| 388 EXPECT_TRUE(invalid_keys.empty()); | 380 EXPECT_TRUE(invalid_keys.empty()); |
| 389 | 381 |
| 390 // Verify old dict no longer matches. | 382 // Verify old dict no longer matches. |
| 391 EXPECT_EQ(PrefHashStoreTransaction::CHANGED, | 383 EXPECT_EQ(ValueState::CHANGED, |
| 392 transaction->CheckSplitValue("path1", &dict, &invalid_keys)); | 384 transaction->CheckSplitValue("path1", &dict, &invalid_keys)); |
| 393 std::vector<std::string> expected_invalid_keys2; | 385 std::vector<std::string> expected_invalid_keys2; |
| 394 expected_invalid_keys2.push_back("a"); | 386 expected_invalid_keys2.push_back("a"); |
| 395 expected_invalid_keys2.push_back("o"); | 387 expected_invalid_keys2.push_back("o"); |
| 396 expected_invalid_keys2.push_back("c"); | 388 expected_invalid_keys2.push_back("c"); |
| 397 EXPECT_EQ(expected_invalid_keys2, invalid_keys); | 389 EXPECT_EQ(expected_invalid_keys2, invalid_keys); |
| 398 invalid_keys.clear(); | 390 invalid_keys.clear(); |
| 399 } | 391 } |
| 400 | 392 |
| 401 { | 393 { |
| 402 // |pref_hash_store2| should trust its initial hashes dictionary and thus | 394 // |pref_hash_store2| should trust its initial hashes dictionary and thus |
| 403 // trust new unknown values. | 395 // trust new unknown values. |
| 404 PrefHashStoreImpl pref_hash_store2(std::string(32, 0), "device_id", true); | 396 PrefHashStoreImpl pref_hash_store2(std::string(32, 0), "device_id", true); |
| 405 std::unique_ptr<PrefHashStoreTransaction> transaction( | 397 std::unique_ptr<PrefHashStoreTransaction> transaction( |
| 406 pref_hash_store2.BeginTransaction(GetHashStoreContents())); | 398 pref_hash_store2.BeginTransaction(GetHashStoreContents())); |
| 407 EXPECT_EQ(PrefHashStoreTransaction::TRUSTED_UNKNOWN_VALUE, | 399 EXPECT_EQ(ValueState::TRUSTED_UNKNOWN_VALUE, |
| 408 transaction->CheckSplitValue("new_path", &dict, &invalid_keys)); | 400 transaction->CheckSplitValue("new_path", &dict, &invalid_keys)); |
| 409 EXPECT_TRUE(invalid_keys.empty()); | 401 EXPECT_TRUE(invalid_keys.empty()); |
| 410 } | 402 } |
| 411 | 403 |
| 412 // Manually corrupt the super MAC. | 404 // Manually corrupt the super MAC. |
| 413 GetHashStoreContents()->SetSuperMac(std::string(64, 'A')); | 405 GetHashStoreContents()->SetSuperMac(std::string(64, 'A')); |
| 414 | 406 |
| 415 { | 407 { |
| 416 // |pref_hash_store3| should no longer trust its initial hashes dictionary | 408 // |pref_hash_store3| should no longer trust its initial hashes dictionary |
| 417 // and thus shouldn't trust unknown values. | 409 // and thus shouldn't trust unknown values. |
| 418 PrefHashStoreImpl pref_hash_store3(std::string(32, 0), "device_id", true); | 410 PrefHashStoreImpl pref_hash_store3(std::string(32, 0), "device_id", true); |
| 419 std::unique_ptr<PrefHashStoreTransaction> transaction( | 411 std::unique_ptr<PrefHashStoreTransaction> transaction( |
| 420 pref_hash_store3.BeginTransaction(GetHashStoreContents())); | 412 pref_hash_store3.BeginTransaction(GetHashStoreContents())); |
| 421 EXPECT_EQ(PrefHashStoreTransaction::UNTRUSTED_UNKNOWN_VALUE, | 413 EXPECT_EQ(ValueState::UNTRUSTED_UNKNOWN_VALUE, |
| 422 transaction->CheckSplitValue("new_path", &dict, &invalid_keys)); | 414 transaction->CheckSplitValue("new_path", &dict, &invalid_keys)); |
| 423 EXPECT_TRUE(invalid_keys.empty()); | 415 EXPECT_TRUE(invalid_keys.empty()); |
| 424 } | 416 } |
| 425 } | 417 } |
| 426 | 418 |
| 427 TEST_F(PrefHashStoreImplTest, EmptyAndNULLSplitDict) { | 419 TEST_F(PrefHashStoreImplTest, EmptyAndNULLSplitDict) { |
| 428 base::DictionaryValue empty_dict; | 420 base::DictionaryValue empty_dict; |
| 429 | 421 |
| 430 std::vector<std::string> invalid_keys; | 422 std::vector<std::string> invalid_keys; |
| 431 | 423 |
| 432 { | 424 { |
| 433 PrefHashStoreImpl pref_hash_store(std::string(32, 0), "device_id", true); | 425 PrefHashStoreImpl pref_hash_store(std::string(32, 0), "device_id", true); |
| 434 std::unique_ptr<PrefHashStoreTransaction> transaction( | 426 std::unique_ptr<PrefHashStoreTransaction> transaction( |
| 435 pref_hash_store.BeginTransaction(GetHashStoreContents())); | 427 pref_hash_store.BeginTransaction(GetHashStoreContents())); |
| 436 | 428 |
| 437 // Store hashes for a random dict to be overwritten below. | 429 // Store hashes for a random dict to be overwritten below. |
| 438 base::DictionaryValue initial_dict; | 430 base::DictionaryValue initial_dict; |
| 439 initial_dict.Set("a", new base::Value("foo")); | 431 initial_dict.Set("a", new base::Value("foo")); |
| 440 transaction->StoreSplitHash("path1", &initial_dict); | 432 transaction->StoreSplitHash("path1", &initial_dict); |
| 441 | 433 |
| 442 // Verify stored empty dictionary matches NULL and empty dictionary back. | 434 // Verify stored empty dictionary matches NULL and empty dictionary back. |
| 443 transaction->StoreSplitHash("path1", &empty_dict); | 435 transaction->StoreSplitHash("path1", &empty_dict); |
| 444 EXPECT_EQ(PrefHashStoreTransaction::UNCHANGED, | 436 EXPECT_EQ(ValueState::UNCHANGED, |
| 445 transaction->CheckSplitValue("path1", NULL, &invalid_keys)); | 437 transaction->CheckSplitValue("path1", NULL, &invalid_keys)); |
| 446 EXPECT_TRUE(invalid_keys.empty()); | 438 EXPECT_TRUE(invalid_keys.empty()); |
| 447 EXPECT_EQ( | 439 EXPECT_EQ(ValueState::UNCHANGED, transaction->CheckSplitValue( |
| 448 PrefHashStoreTransaction::UNCHANGED, | 440 "path1", &empty_dict, &invalid_keys)); |
| 449 transaction->CheckSplitValue("path1", &empty_dict, &invalid_keys)); | |
| 450 EXPECT_TRUE(invalid_keys.empty()); | 441 EXPECT_TRUE(invalid_keys.empty()); |
| 451 | 442 |
| 452 // Same when storing NULL directly. | 443 // Same when storing NULL directly. |
| 453 transaction->StoreSplitHash("path1", NULL); | 444 transaction->StoreSplitHash("path1", NULL); |
| 454 EXPECT_EQ(PrefHashStoreTransaction::UNCHANGED, | 445 EXPECT_EQ(ValueState::UNCHANGED, |
| 455 transaction->CheckSplitValue("path1", NULL, &invalid_keys)); | 446 transaction->CheckSplitValue("path1", NULL, &invalid_keys)); |
| 456 EXPECT_TRUE(invalid_keys.empty()); | 447 EXPECT_TRUE(invalid_keys.empty()); |
| 457 EXPECT_EQ( | 448 EXPECT_EQ(ValueState::UNCHANGED, transaction->CheckSplitValue( |
| 458 PrefHashStoreTransaction::UNCHANGED, | 449 "path1", &empty_dict, &invalid_keys)); |
| 459 transaction->CheckSplitValue("path1", &empty_dict, &invalid_keys)); | |
| 460 EXPECT_TRUE(invalid_keys.empty()); | 450 EXPECT_TRUE(invalid_keys.empty()); |
| 461 } | 451 } |
| 462 | 452 |
| 463 { | 453 { |
| 464 // |pref_hash_store2| should trust its initial hashes dictionary (and thus | 454 // |pref_hash_store2| should trust its initial hashes dictionary (and thus |
| 465 // trust new unknown values) even though the last action done was to clear | 455 // trust new unknown values) even though the last action done was to clear |
| 466 // the hashes for path1 by setting its value to NULL (this is a regression | 456 // the hashes for path1 by setting its value to NULL (this is a regression |
| 467 // test ensuring that the internal action of clearing some hashes does | 457 // test ensuring that the internal action of clearing some hashes does |
| 468 // update the stored hash of hashes). | 458 // update the stored hash of hashes). |
| 469 PrefHashStoreImpl pref_hash_store2(std::string(32, 0), "device_id", true); | 459 PrefHashStoreImpl pref_hash_store2(std::string(32, 0), "device_id", true); |
| 470 std::unique_ptr<PrefHashStoreTransaction> transaction( | 460 std::unique_ptr<PrefHashStoreTransaction> transaction( |
| 471 pref_hash_store2.BeginTransaction(GetHashStoreContents())); | 461 pref_hash_store2.BeginTransaction(GetHashStoreContents())); |
| 472 | 462 |
| 473 base::DictionaryValue tested_dict; | 463 base::DictionaryValue tested_dict; |
| 474 tested_dict.Set("a", new base::Value("foo")); | 464 tested_dict.Set("a", new base::Value("foo")); |
| 475 tested_dict.Set("b", new base::Value("bar")); | 465 tested_dict.Set("b", new base::Value("bar")); |
| 476 EXPECT_EQ( | 466 EXPECT_EQ( |
| 477 PrefHashStoreTransaction::TRUSTED_UNKNOWN_VALUE, | 467 ValueState::TRUSTED_UNKNOWN_VALUE, |
| 478 transaction->CheckSplitValue("new_path", &tested_dict, &invalid_keys)); | 468 transaction->CheckSplitValue("new_path", &tested_dict, &invalid_keys)); |
| 479 EXPECT_TRUE(invalid_keys.empty()); | 469 EXPECT_TRUE(invalid_keys.empty()); |
| 480 } | 470 } |
| 481 } | 471 } |
| 482 | 472 |
| 483 // Test that the PrefHashStore returns TRUSTED_UNKNOWN_VALUE when checking for | 473 // Test that the PrefHashStore returns TRUSTED_UNKNOWN_VALUE when checking for |
| 484 // a split preference even if there is an existing atomic preference's hash | 474 // a split preference even if there is an existing atomic preference's hash |
| 485 // stored. There is no point providing a migration path for preferences | 475 // stored. There is no point providing a migration path for preferences |
| 486 // switching strategies after their initial release as split preferences are | 476 // switching strategies after their initial release as split preferences are |
| 487 // turned into split preferences specifically because the atomic hash isn't | 477 // turned into split preferences specifically because the atomic hash isn't |
| 488 // considered useful. | 478 // considered useful. |
| 489 TEST_F(PrefHashStoreImplTest, TrustedUnknownSplitValueFromExistingAtomic) { | 479 TEST_F(PrefHashStoreImplTest, TrustedUnknownSplitValueFromExistingAtomic) { |
| 490 base::Value string("string1"); | 480 base::Value string("string1"); |
| 491 | 481 |
| 492 base::DictionaryValue dict; | 482 base::DictionaryValue dict; |
| 493 dict.Set("a", new base::Value("foo")); | 483 dict.Set("a", new base::Value("foo")); |
| 494 dict.Set("d", new base::Value("bad")); | 484 dict.Set("d", new base::Value("bad")); |
| 495 dict.Set("b", new base::Value("bar")); | 485 dict.Set("b", new base::Value("bar")); |
| 496 dict.Set("c", new base::Value("baz")); | 486 dict.Set("c", new base::Value("baz")); |
| 497 | 487 |
| 498 { | 488 { |
| 499 PrefHashStoreImpl pref_hash_store(std::string(32, 0), "device_id", true); | 489 PrefHashStoreImpl pref_hash_store(std::string(32, 0), "device_id", true); |
| 500 std::unique_ptr<PrefHashStoreTransaction> transaction( | 490 std::unique_ptr<PrefHashStoreTransaction> transaction( |
| 501 pref_hash_store.BeginTransaction(GetHashStoreContents())); | 491 pref_hash_store.BeginTransaction(GetHashStoreContents())); |
| 502 | 492 |
| 503 transaction->StoreHash("path1", &string); | 493 transaction->StoreHash("path1", &string); |
| 504 EXPECT_EQ(PrefHashStoreTransaction::UNCHANGED, | 494 EXPECT_EQ(ValueState::UNCHANGED, transaction->CheckValue("path1", &string)); |
| 505 transaction->CheckValue("path1", &string)); | |
| 506 } | 495 } |
| 507 | 496 |
| 508 { | 497 { |
| 509 // Load a new |pref_hash_store2| in which the hashes dictionary is trusted. | 498 // Load a new |pref_hash_store2| in which the hashes dictionary is trusted. |
| 510 PrefHashStoreImpl pref_hash_store2(std::string(32, 0), "device_id", true); | 499 PrefHashStoreImpl pref_hash_store2(std::string(32, 0), "device_id", true); |
| 511 std::unique_ptr<PrefHashStoreTransaction> transaction( | 500 std::unique_ptr<PrefHashStoreTransaction> transaction( |
| 512 pref_hash_store2.BeginTransaction(GetHashStoreContents())); | 501 pref_hash_store2.BeginTransaction(GetHashStoreContents())); |
| 513 std::vector<std::string> invalid_keys; | 502 std::vector<std::string> invalid_keys; |
| 514 EXPECT_EQ(PrefHashStoreTransaction::TRUSTED_UNKNOWN_VALUE, | 503 EXPECT_EQ(ValueState::TRUSTED_UNKNOWN_VALUE, |
| 515 transaction->CheckSplitValue("path1", &dict, &invalid_keys)); | 504 transaction->CheckSplitValue("path1", &dict, &invalid_keys)); |
| 516 EXPECT_TRUE(invalid_keys.empty()); | 505 EXPECT_TRUE(invalid_keys.empty()); |
| 517 } | 506 } |
| 518 } | 507 } |
| OLD | NEW |