| 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 "components/user_prefs/tracked/segregated_pref_store.h" | 5 #include "components/user_prefs/tracked/segregated_pref_store.h" |
| 6 | 6 |
| 7 #include <memory> | 7 #include <memory> |
| 8 #include <set> | 8 #include <set> |
| 9 #include <string> | 9 #include <string> |
| 10 #include <utility> | 10 #include <utility> |
| (...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 97 private: | 97 private: |
| 98 std::unique_ptr<MockReadErrorDelegate> read_error_delegate_; | 98 std::unique_ptr<MockReadErrorDelegate> read_error_delegate_; |
| 99 }; | 99 }; |
| 100 | 100 |
| 101 TEST_F(SegregatedPrefStoreTest, StoreValues) { | 101 TEST_F(SegregatedPrefStoreTest, StoreValues) { |
| 102 ASSERT_EQ(PersistentPrefStore::PREF_READ_ERROR_NONE, | 102 ASSERT_EQ(PersistentPrefStore::PREF_READ_ERROR_NONE, |
| 103 segregated_store_->ReadPrefs()); | 103 segregated_store_->ReadPrefs()); |
| 104 | 104 |
| 105 // Properly stores new values. | 105 // Properly stores new values. |
| 106 segregated_store_->SetValue(kSelectedPref, | 106 segregated_store_->SetValue(kSelectedPref, |
| 107 base::WrapUnique(new base::StringValue(kValue1)), | 107 base::MakeUnique<base::StringValue>(kValue1), |
| 108 WriteablePrefStore::DEFAULT_PREF_WRITE_FLAGS); | 108 WriteablePrefStore::DEFAULT_PREF_WRITE_FLAGS); |
| 109 segregated_store_->SetValue(kUnselectedPref, | 109 segregated_store_->SetValue(kUnselectedPref, |
| 110 base::WrapUnique(new base::StringValue(kValue2)), | 110 base::MakeUnique<base::StringValue>(kValue2), |
| 111 WriteablePrefStore::DEFAULT_PREF_WRITE_FLAGS); | 111 WriteablePrefStore::DEFAULT_PREF_WRITE_FLAGS); |
| 112 | 112 |
| 113 ASSERT_TRUE(selected_store_->GetValue(kSelectedPref, NULL)); | 113 ASSERT_TRUE(selected_store_->GetValue(kSelectedPref, NULL)); |
| 114 ASSERT_FALSE(selected_store_->GetValue(kUnselectedPref, NULL)); | 114 ASSERT_FALSE(selected_store_->GetValue(kUnselectedPref, NULL)); |
| 115 ASSERT_FALSE(default_store_->GetValue(kSelectedPref, NULL)); | 115 ASSERT_FALSE(default_store_->GetValue(kSelectedPref, NULL)); |
| 116 ASSERT_TRUE(default_store_->GetValue(kUnselectedPref, NULL)); | 116 ASSERT_TRUE(default_store_->GetValue(kUnselectedPref, NULL)); |
| 117 | 117 |
| 118 ASSERT_TRUE(segregated_store_->GetValue(kSelectedPref, NULL)); | 118 ASSERT_TRUE(segregated_store_->GetValue(kSelectedPref, NULL)); |
| 119 ASSERT_TRUE(segregated_store_->GetValue(kUnselectedPref, NULL)); | 119 ASSERT_TRUE(segregated_store_->GetValue(kUnselectedPref, NULL)); |
| 120 | 120 |
| 121 ASSERT_FALSE(selected_store_->committed()); | 121 ASSERT_FALSE(selected_store_->committed()); |
| 122 ASSERT_FALSE(default_store_->committed()); | 122 ASSERT_FALSE(default_store_->committed()); |
| 123 | 123 |
| 124 segregated_store_->CommitPendingWrite(); | 124 segregated_store_->CommitPendingWrite(); |
| 125 | 125 |
| 126 ASSERT_TRUE(selected_store_->committed()); | 126 ASSERT_TRUE(selected_store_->committed()); |
| 127 ASSERT_TRUE(default_store_->committed()); | 127 ASSERT_TRUE(default_store_->committed()); |
| 128 } | 128 } |
| 129 | 129 |
| 130 TEST_F(SegregatedPrefStoreTest, ReadValues) { | 130 TEST_F(SegregatedPrefStoreTest, ReadValues) { |
| 131 selected_store_->SetValue(kSelectedPref, | 131 selected_store_->SetValue(kSelectedPref, |
| 132 base::WrapUnique(new base::StringValue(kValue1)), | 132 base::MakeUnique<base::StringValue>(kValue1), |
| 133 WriteablePrefStore::DEFAULT_PREF_WRITE_FLAGS); | 133 WriteablePrefStore::DEFAULT_PREF_WRITE_FLAGS); |
| 134 default_store_->SetValue(kUnselectedPref, | 134 default_store_->SetValue(kUnselectedPref, |
| 135 base::WrapUnique(new base::StringValue(kValue2)), | 135 base::MakeUnique<base::StringValue>(kValue2), |
| 136 WriteablePrefStore::DEFAULT_PREF_WRITE_FLAGS); | 136 WriteablePrefStore::DEFAULT_PREF_WRITE_FLAGS); |
| 137 | 137 |
| 138 // Works properly with values that are already there. | 138 // Works properly with values that are already there. |
| 139 ASSERT_EQ(PersistentPrefStore::PREF_READ_ERROR_NONE, | 139 ASSERT_EQ(PersistentPrefStore::PREF_READ_ERROR_NONE, |
| 140 segregated_store_->ReadPrefs()); | 140 segregated_store_->ReadPrefs()); |
| 141 ASSERT_EQ(PersistentPrefStore::PREF_READ_ERROR_NONE, | 141 ASSERT_EQ(PersistentPrefStore::PREF_READ_ERROR_NONE, |
| 142 segregated_store_->GetReadError()); | 142 segregated_store_->GetReadError()); |
| 143 | 143 |
| 144 ASSERT_TRUE(selected_store_->GetValue(kSelectedPref, NULL)); | 144 ASSERT_TRUE(selected_store_->GetValue(kSelectedPref, NULL)); |
| 145 ASSERT_FALSE(selected_store_->GetValue(kUnselectedPref, NULL)); | 145 ASSERT_FALSE(selected_store_->GetValue(kUnselectedPref, NULL)); |
| 146 ASSERT_FALSE(default_store_->GetValue(kSelectedPref, NULL)); | 146 ASSERT_FALSE(default_store_->GetValue(kSelectedPref, NULL)); |
| 147 ASSERT_TRUE(default_store_->GetValue(kUnselectedPref, NULL)); | 147 ASSERT_TRUE(default_store_->GetValue(kUnselectedPref, NULL)); |
| 148 | 148 |
| 149 ASSERT_TRUE(segregated_store_->GetValue(kSelectedPref, NULL)); | 149 ASSERT_TRUE(segregated_store_->GetValue(kSelectedPref, NULL)); |
| 150 ASSERT_TRUE(segregated_store_->GetValue(kUnselectedPref, NULL)); | 150 ASSERT_TRUE(segregated_store_->GetValue(kUnselectedPref, NULL)); |
| 151 } | 151 } |
| 152 | 152 |
| 153 TEST_F(SegregatedPrefStoreTest, Observer) { | 153 TEST_F(SegregatedPrefStoreTest, Observer) { |
| 154 EXPECT_EQ(PersistentPrefStore::PREF_READ_ERROR_NONE, | 154 EXPECT_EQ(PersistentPrefStore::PREF_READ_ERROR_NONE, |
| 155 segregated_store_->ReadPrefs()); | 155 segregated_store_->ReadPrefs()); |
| 156 EXPECT_TRUE(observer_.initialized); | 156 EXPECT_TRUE(observer_.initialized); |
| 157 EXPECT_TRUE(observer_.initialization_success); | 157 EXPECT_TRUE(observer_.initialization_success); |
| 158 EXPECT_TRUE(observer_.changed_keys.empty()); | 158 EXPECT_TRUE(observer_.changed_keys.empty()); |
| 159 segregated_store_->SetValue(kSelectedPref, | 159 segregated_store_->SetValue(kSelectedPref, |
| 160 base::WrapUnique(new base::StringValue(kValue1)), | 160 base::MakeUnique<base::StringValue>(kValue1), |
| 161 WriteablePrefStore::DEFAULT_PREF_WRITE_FLAGS); | 161 WriteablePrefStore::DEFAULT_PREF_WRITE_FLAGS); |
| 162 observer_.VerifyAndResetChangedKey(kSelectedPref); | 162 observer_.VerifyAndResetChangedKey(kSelectedPref); |
| 163 segregated_store_->SetValue(kUnselectedPref, | 163 segregated_store_->SetValue(kUnselectedPref, |
| 164 base::WrapUnique(new base::StringValue(kValue2)), | 164 base::MakeUnique<base::StringValue>(kValue2), |
| 165 WriteablePrefStore::DEFAULT_PREF_WRITE_FLAGS); | 165 WriteablePrefStore::DEFAULT_PREF_WRITE_FLAGS); |
| 166 observer_.VerifyAndResetChangedKey(kUnselectedPref); | 166 observer_.VerifyAndResetChangedKey(kUnselectedPref); |
| 167 } | 167 } |
| 168 | 168 |
| 169 TEST_F(SegregatedPrefStoreTest, SelectedPrefReadNoFileError) { | 169 TEST_F(SegregatedPrefStoreTest, SelectedPrefReadNoFileError) { |
| 170 // PREF_READ_ERROR_NO_FILE for the selected prefs file is silently converted | 170 // PREF_READ_ERROR_NO_FILE for the selected prefs file is silently converted |
| 171 // to PREF_READ_ERROR_NONE. | 171 // to PREF_READ_ERROR_NONE. |
| 172 selected_store_->set_read_error(PersistentPrefStore::PREF_READ_ERROR_NO_FILE); | 172 selected_store_->set_read_error(PersistentPrefStore::PREF_READ_ERROR_NO_FILE); |
| 173 EXPECT_EQ(PersistentPrefStore::PREF_READ_ERROR_NONE, | 173 EXPECT_EQ(PersistentPrefStore::PREF_READ_ERROR_NONE, |
| 174 segregated_store_->ReadPrefs()); | 174 segregated_store_->ReadPrefs()); |
| (...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 267 selected_store_->SetBlockAsyncRead(true); | 267 selected_store_->SetBlockAsyncRead(true); |
| 268 default_store_->SetBlockAsyncRead(true); | 268 default_store_->SetBlockAsyncRead(true); |
| 269 EXPECT_FALSE(segregated_store_->IsInitializationComplete()); | 269 EXPECT_FALSE(segregated_store_->IsInitializationComplete()); |
| 270 segregated_store_->ReadPrefsAsync(NULL); | 270 segregated_store_->ReadPrefsAsync(NULL); |
| 271 EXPECT_FALSE(segregated_store_->IsInitializationComplete()); | 271 EXPECT_FALSE(segregated_store_->IsInitializationComplete()); |
| 272 selected_store_->SetBlockAsyncRead(false); | 272 selected_store_->SetBlockAsyncRead(false); |
| 273 EXPECT_FALSE(segregated_store_->IsInitializationComplete()); | 273 EXPECT_FALSE(segregated_store_->IsInitializationComplete()); |
| 274 default_store_->SetBlockAsyncRead(false); | 274 default_store_->SetBlockAsyncRead(false); |
| 275 EXPECT_TRUE(segregated_store_->IsInitializationComplete()); | 275 EXPECT_TRUE(segregated_store_->IsInitializationComplete()); |
| 276 } | 276 } |
| OLD | NEW |