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

Side by Side Diff: chrome/browser/prefs/tracked/segregated_pref_store_unittest.cc

Issue 257003007: Introduce a new framework for back-and-forth tracked/protected preferences migration. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: comment nit Created 6 years, 7 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 | Annotate | Revision Log
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 "chrome/browser/prefs/tracked/segregated_pref_store.h" 5 #include "chrome/browser/prefs/tracked/segregated_pref_store.h"
6 6
7 #include <set> 7 #include <set>
8 #include <string> 8 #include <string>
9 9
10 #include "base/bind.h" 10 #include "base/bind.h"
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
50 50
51 private: 51 private:
52 Data* data_; 52 Data* data_;
53 }; 53 };
54 54
55 } // namespace 55 } // namespace
56 56
57 class SegregatedPrefStoreTest : public testing::Test { 57 class SegregatedPrefStoreTest : public testing::Test {
58 public: 58 public:
59 SegregatedPrefStoreTest() 59 SegregatedPrefStoreTest()
60 : initialization_callback_invoked_(false), 60 : read_error_delegate_data_(false,
61 read_error_delegate_data_(false,
62 PersistentPrefStore::PREF_READ_ERROR_NONE), 61 PersistentPrefStore::PREF_READ_ERROR_NONE),
63 read_error_delegate_( 62 read_error_delegate_(
64 new MockReadErrorDelegate(&read_error_delegate_data_)) {} 63 new MockReadErrorDelegate(&read_error_delegate_data_)) {}
65 64
66 virtual void SetUp() OVERRIDE { 65 virtual void SetUp() OVERRIDE {
67 selected_store_ = new TestingPrefStore; 66 selected_store_ = new TestingPrefStore;
68 default_store_ = new TestingPrefStore; 67 default_store_ = new TestingPrefStore;
69 68
70 std::set<std::string> selected_pref_names; 69 std::set<std::string> selected_pref_names;
71 selected_pref_names.insert(kSelectedPref); 70 selected_pref_names.insert(kSelectedPref);
72 71
73 segregated_store_ = new SegregatedPrefStore( 72 segregated_store_ = new SegregatedPrefStore(
74 default_store_, 73 default_store_,
75 selected_store_, 74 selected_store_,
76 selected_pref_names, 75 selected_pref_names);
77 base::Bind(&SegregatedPrefStoreTest::InitializationCallback,
78 base::Unretained(this)));
79 76
80 segregated_store_->AddObserver(&observer_); 77 segregated_store_->AddObserver(&observer_);
81 } 78 }
82 79
83 virtual void TearDown() OVERRIDE { 80 virtual void TearDown() OVERRIDE {
84 segregated_store_->RemoveObserver(&observer_); 81 segregated_store_->RemoveObserver(&observer_);
85 } 82 }
86 83
87 protected: 84 protected:
88 scoped_ptr<PersistentPrefStore::ReadErrorDelegate> GetReadErrorDelegate() { 85 scoped_ptr<PersistentPrefStore::ReadErrorDelegate> GetReadErrorDelegate() {
89 EXPECT_TRUE(read_error_delegate_); 86 EXPECT_TRUE(read_error_delegate_);
90 return read_error_delegate_ 87 return read_error_delegate_
91 .PassAs<PersistentPrefStore::ReadErrorDelegate>(); 88 .PassAs<PersistentPrefStore::ReadErrorDelegate>();
92 } 89 }
93 90
94 PrefStoreObserverMock observer_; 91 PrefStoreObserverMock observer_;
95 bool initialization_callback_invoked_;
96 92
97 scoped_refptr<TestingPrefStore> default_store_; 93 scoped_refptr<TestingPrefStore> default_store_;
98 scoped_refptr<TestingPrefStore> selected_store_; 94 scoped_refptr<TestingPrefStore> selected_store_;
99 scoped_refptr<SegregatedPrefStore> segregated_store_; 95 scoped_refptr<SegregatedPrefStore> segregated_store_;
100 96
101 MockReadErrorDelegate::Data read_error_delegate_data_; 97 MockReadErrorDelegate::Data read_error_delegate_data_;
102 98
103 private: 99 private:
104 void InitializationCallback() {
105 EXPECT_FALSE(observer_.initialized);
106 EXPECT_FALSE(initialization_callback_invoked_);
107 initialization_callback_invoked_ = true;
108 }
109
110 scoped_ptr<MockReadErrorDelegate> read_error_delegate_; 100 scoped_ptr<MockReadErrorDelegate> read_error_delegate_;
111 }; 101 };
112 102
113 TEST_F(SegregatedPrefStoreTest, StoreValues) { 103 TEST_F(SegregatedPrefStoreTest, StoreValues) {
114 ASSERT_EQ(PersistentPrefStore::PREF_READ_ERROR_NONE, 104 ASSERT_EQ(PersistentPrefStore::PREF_READ_ERROR_NONE,
115 segregated_store_->ReadPrefs()); 105 segregated_store_->ReadPrefs());
116 106
117 // Properly stores new values. 107 // Properly stores new values.
118 segregated_store_->SetValue(kSelectedPref, new base::StringValue(kValue1)); 108 segregated_store_->SetValue(kSelectedPref, new base::StringValue(kValue1));
119 segregated_store_->SetValue(kUnselectedPref, new base::StringValue(kValue2)); 109 segregated_store_->SetValue(kUnselectedPref, new base::StringValue(kValue2));
(...skipping 28 matching lines...) Expand all
148 138
149 ASSERT_TRUE(selected_store_->GetValue(kSelectedPref, NULL)); 139 ASSERT_TRUE(selected_store_->GetValue(kSelectedPref, NULL));
150 ASSERT_FALSE(selected_store_->GetValue(kUnselectedPref, NULL)); 140 ASSERT_FALSE(selected_store_->GetValue(kUnselectedPref, NULL));
151 ASSERT_FALSE(default_store_->GetValue(kSelectedPref, NULL)); 141 ASSERT_FALSE(default_store_->GetValue(kSelectedPref, NULL));
152 ASSERT_TRUE(default_store_->GetValue(kUnselectedPref, NULL)); 142 ASSERT_TRUE(default_store_->GetValue(kUnselectedPref, NULL));
153 143
154 ASSERT_TRUE(segregated_store_->GetValue(kSelectedPref, NULL)); 144 ASSERT_TRUE(segregated_store_->GetValue(kSelectedPref, NULL));
155 ASSERT_TRUE(segregated_store_->GetValue(kUnselectedPref, NULL)); 145 ASSERT_TRUE(segregated_store_->GetValue(kUnselectedPref, NULL));
156 } 146 }
157 147
158 TEST_F(SegregatedPrefStoreTest, PreviouslySelected) {
159 selected_store_->SetValue(kUnselectedPref, new base::StringValue(kValue1));
160 segregated_store_->ReadPrefs();
161 // It will read from the selected store.
162 ASSERT_TRUE(segregated_store_->GetValue(kUnselectedPref, NULL));
163 ASSERT_TRUE(selected_store_->GetValue(kUnselectedPref, NULL));
164 ASSERT_FALSE(default_store_->GetValue(kUnselectedPref, NULL));
165
166 // But when we update the value...
167 segregated_store_->SetValue(kUnselectedPref, new base::StringValue(kValue2));
168 // ...it will be migrated.
169 ASSERT_TRUE(segregated_store_->GetValue(kUnselectedPref, NULL));
170 ASSERT_FALSE(selected_store_->GetValue(kUnselectedPref, NULL));
171 ASSERT_TRUE(default_store_->GetValue(kUnselectedPref, NULL));
172 }
173
174 TEST_F(SegregatedPrefStoreTest, Observer) { 148 TEST_F(SegregatedPrefStoreTest, Observer) {
175 EXPECT_EQ(PersistentPrefStore::PREF_READ_ERROR_NONE, 149 EXPECT_EQ(PersistentPrefStore::PREF_READ_ERROR_NONE,
176 segregated_store_->ReadPrefs()); 150 segregated_store_->ReadPrefs());
177 EXPECT_TRUE(initialization_callback_invoked_);
178 EXPECT_TRUE(observer_.initialized); 151 EXPECT_TRUE(observer_.initialized);
179 EXPECT_TRUE(observer_.initialization_success); 152 EXPECT_TRUE(observer_.initialization_success);
180 EXPECT_TRUE(observer_.changed_keys.empty()); 153 EXPECT_TRUE(observer_.changed_keys.empty());
181 segregated_store_->SetValue(kSelectedPref, new base::StringValue(kValue1)); 154 segregated_store_->SetValue(kSelectedPref, new base::StringValue(kValue1));
182 observer_.VerifyAndResetChangedKey(kSelectedPref); 155 observer_.VerifyAndResetChangedKey(kSelectedPref);
183 segregated_store_->SetValue(kUnselectedPref, new base::StringValue(kValue2)); 156 segregated_store_->SetValue(kUnselectedPref, new base::StringValue(kValue2));
184 observer_.VerifyAndResetChangedKey(kUnselectedPref); 157 observer_.VerifyAndResetChangedKey(kUnselectedPref);
185 } 158 }
186 159
187 TEST_F(SegregatedPrefStoreTest, SelectedPrefReadNoFileError) { 160 TEST_F(SegregatedPrefStoreTest, SelectedPrefReadNoFileError) {
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after
290 selected_store_->SetBlockAsyncRead(true); 263 selected_store_->SetBlockAsyncRead(true);
291 default_store_->SetBlockAsyncRead(true); 264 default_store_->SetBlockAsyncRead(true);
292 EXPECT_FALSE(segregated_store_->IsInitializationComplete()); 265 EXPECT_FALSE(segregated_store_->IsInitializationComplete());
293 segregated_store_->ReadPrefsAsync(NULL); 266 segregated_store_->ReadPrefsAsync(NULL);
294 EXPECT_FALSE(segregated_store_->IsInitializationComplete()); 267 EXPECT_FALSE(segregated_store_->IsInitializationComplete());
295 selected_store_->SetBlockAsyncRead(false); 268 selected_store_->SetBlockAsyncRead(false);
296 EXPECT_FALSE(segregated_store_->IsInitializationComplete()); 269 EXPECT_FALSE(segregated_store_->IsInitializationComplete());
297 default_store_->SetBlockAsyncRead(false); 270 default_store_->SetBlockAsyncRead(false);
298 EXPECT_TRUE(segregated_store_->IsInitializationComplete()); 271 EXPECT_TRUE(segregated_store_->IsInitializationComplete());
299 } 272 }
OLDNEW
« no previous file with comments | « chrome/browser/prefs/tracked/segregated_pref_store.cc ('k') | chrome/browser/prefs/tracked/tracked_preferences_migration.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698