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

Side by Side Diff: components/user_prefs/tracked/segregated_pref_store_unittest.cc

Issue 1908143002: Convert //components/user_prefs from scoped_ptr to std::unique_ptr (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Restore the rightful glory of <windows.h> Created 4 years, 8 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/user_prefs/tracked/segregated_pref_store.h" 5 #include "components/user_prefs/tracked/segregated_pref_store.h"
6 6
7 #include <memory>
7 #include <set> 8 #include <set>
8 #include <string> 9 #include <string>
9 #include <utility> 10 #include <utility>
10 11
11 #include "base/bind.h" 12 #include "base/bind.h"
12 #include "base/callback.h" 13 #include "base/callback.h"
14 #include "base/memory/ptr_util.h"
13 #include "base/memory/ref_counted.h" 15 #include "base/memory/ref_counted.h"
14 #include "base/memory/scoped_ptr.h"
15 #include "base/values.h" 16 #include "base/values.h"
16 #include "components/prefs/persistent_pref_store.h" 17 #include "components/prefs/persistent_pref_store.h"
17 #include "components/prefs/pref_store_observer_mock.h" 18 #include "components/prefs/pref_store_observer_mock.h"
18 #include "components/prefs/testing_pref_store.h" 19 #include "components/prefs/testing_pref_store.h"
19 #include "components/user_prefs/tracked/segregated_pref_store.h" 20 #include "components/user_prefs/tracked/segregated_pref_store.h"
20 #include "testing/gtest/include/gtest/gtest.h" 21 #include "testing/gtest/include/gtest/gtest.h"
21 22
22 namespace { 23 namespace {
23 24
24 const char kSelectedPref[] = "selected_pref"; 25 const char kSelectedPref[] = "selected_pref";
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
72 73
73 segregated_store_ = new SegregatedPrefStore(default_store_, selected_store_, 74 segregated_store_ = new SegregatedPrefStore(default_store_, selected_store_,
74 selected_pref_names); 75 selected_pref_names);
75 76
76 segregated_store_->AddObserver(&observer_); 77 segregated_store_->AddObserver(&observer_);
77 } 78 }
78 79
79 void TearDown() override { segregated_store_->RemoveObserver(&observer_); } 80 void TearDown() override { segregated_store_->RemoveObserver(&observer_); }
80 81
81 protected: 82 protected:
82 scoped_ptr<PersistentPrefStore::ReadErrorDelegate> GetReadErrorDelegate() { 83 std::unique_ptr<PersistentPrefStore::ReadErrorDelegate>
84 GetReadErrorDelegate() {
83 EXPECT_TRUE(read_error_delegate_); 85 EXPECT_TRUE(read_error_delegate_);
84 return std::move(read_error_delegate_); 86 return std::move(read_error_delegate_);
85 } 87 }
86 88
87 PrefStoreObserverMock observer_; 89 PrefStoreObserverMock observer_;
88 90
89 scoped_refptr<TestingPrefStore> default_store_; 91 scoped_refptr<TestingPrefStore> default_store_;
90 scoped_refptr<TestingPrefStore> selected_store_; 92 scoped_refptr<TestingPrefStore> selected_store_;
91 scoped_refptr<SegregatedPrefStore> segregated_store_; 93 scoped_refptr<SegregatedPrefStore> segregated_store_;
92 94
93 MockReadErrorDelegate::Data read_error_delegate_data_; 95 MockReadErrorDelegate::Data read_error_delegate_data_;
94 96
95 private: 97 private:
96 scoped_ptr<MockReadErrorDelegate> read_error_delegate_; 98 std::unique_ptr<MockReadErrorDelegate> read_error_delegate_;
97 }; 99 };
98 100
99 TEST_F(SegregatedPrefStoreTest, StoreValues) { 101 TEST_F(SegregatedPrefStoreTest, StoreValues) {
100 ASSERT_EQ(PersistentPrefStore::PREF_READ_ERROR_NONE, 102 ASSERT_EQ(PersistentPrefStore::PREF_READ_ERROR_NONE,
101 segregated_store_->ReadPrefs()); 103 segregated_store_->ReadPrefs());
102 104
103 // Properly stores new values. 105 // Properly stores new values.
104 segregated_store_->SetValue(kSelectedPref, 106 segregated_store_->SetValue(kSelectedPref,
105 make_scoped_ptr(new base::StringValue(kValue1)), 107 base::WrapUnique(new base::StringValue(kValue1)),
106 WriteablePrefStore::DEFAULT_PREF_WRITE_FLAGS); 108 WriteablePrefStore::DEFAULT_PREF_WRITE_FLAGS);
107 segregated_store_->SetValue(kUnselectedPref, 109 segregated_store_->SetValue(kUnselectedPref,
108 make_scoped_ptr(new base::StringValue(kValue2)), 110 base::WrapUnique(new base::StringValue(kValue2)),
109 WriteablePrefStore::DEFAULT_PREF_WRITE_FLAGS); 111 WriteablePrefStore::DEFAULT_PREF_WRITE_FLAGS);
110 112
111 ASSERT_TRUE(selected_store_->GetValue(kSelectedPref, NULL)); 113 ASSERT_TRUE(selected_store_->GetValue(kSelectedPref, NULL));
112 ASSERT_FALSE(selected_store_->GetValue(kUnselectedPref, NULL)); 114 ASSERT_FALSE(selected_store_->GetValue(kUnselectedPref, NULL));
113 ASSERT_FALSE(default_store_->GetValue(kSelectedPref, NULL)); 115 ASSERT_FALSE(default_store_->GetValue(kSelectedPref, NULL));
114 ASSERT_TRUE(default_store_->GetValue(kUnselectedPref, NULL)); 116 ASSERT_TRUE(default_store_->GetValue(kUnselectedPref, NULL));
115 117
116 ASSERT_TRUE(segregated_store_->GetValue(kSelectedPref, NULL)); 118 ASSERT_TRUE(segregated_store_->GetValue(kSelectedPref, NULL));
117 ASSERT_TRUE(segregated_store_->GetValue(kUnselectedPref, NULL)); 119 ASSERT_TRUE(segregated_store_->GetValue(kUnselectedPref, NULL));
118 120
119 ASSERT_FALSE(selected_store_->committed()); 121 ASSERT_FALSE(selected_store_->committed());
120 ASSERT_FALSE(default_store_->committed()); 122 ASSERT_FALSE(default_store_->committed());
121 123
122 segregated_store_->CommitPendingWrite(); 124 segregated_store_->CommitPendingWrite();
123 125
124 ASSERT_TRUE(selected_store_->committed()); 126 ASSERT_TRUE(selected_store_->committed());
125 ASSERT_TRUE(default_store_->committed()); 127 ASSERT_TRUE(default_store_->committed());
126 } 128 }
127 129
128 TEST_F(SegregatedPrefStoreTest, ReadValues) { 130 TEST_F(SegregatedPrefStoreTest, ReadValues) {
129 selected_store_->SetValue(kSelectedPref, 131 selected_store_->SetValue(kSelectedPref,
130 make_scoped_ptr(new base::StringValue(kValue1)), 132 base::WrapUnique(new base::StringValue(kValue1)),
131 WriteablePrefStore::DEFAULT_PREF_WRITE_FLAGS); 133 WriteablePrefStore::DEFAULT_PREF_WRITE_FLAGS);
132 default_store_->SetValue(kUnselectedPref, 134 default_store_->SetValue(kUnselectedPref,
133 make_scoped_ptr(new base::StringValue(kValue2)), 135 base::WrapUnique(new base::StringValue(kValue2)),
134 WriteablePrefStore::DEFAULT_PREF_WRITE_FLAGS); 136 WriteablePrefStore::DEFAULT_PREF_WRITE_FLAGS);
135 137
136 // Works properly with values that are already there. 138 // Works properly with values that are already there.
137 ASSERT_EQ(PersistentPrefStore::PREF_READ_ERROR_NONE, 139 ASSERT_EQ(PersistentPrefStore::PREF_READ_ERROR_NONE,
138 segregated_store_->ReadPrefs()); 140 segregated_store_->ReadPrefs());
139 ASSERT_EQ(PersistentPrefStore::PREF_READ_ERROR_NONE, 141 ASSERT_EQ(PersistentPrefStore::PREF_READ_ERROR_NONE,
140 segregated_store_->GetReadError()); 142 segregated_store_->GetReadError());
141 143
142 ASSERT_TRUE(selected_store_->GetValue(kSelectedPref, NULL)); 144 ASSERT_TRUE(selected_store_->GetValue(kSelectedPref, NULL));
143 ASSERT_FALSE(selected_store_->GetValue(kUnselectedPref, NULL)); 145 ASSERT_FALSE(selected_store_->GetValue(kUnselectedPref, NULL));
144 ASSERT_FALSE(default_store_->GetValue(kSelectedPref, NULL)); 146 ASSERT_FALSE(default_store_->GetValue(kSelectedPref, NULL));
145 ASSERT_TRUE(default_store_->GetValue(kUnselectedPref, NULL)); 147 ASSERT_TRUE(default_store_->GetValue(kUnselectedPref, NULL));
146 148
147 ASSERT_TRUE(segregated_store_->GetValue(kSelectedPref, NULL)); 149 ASSERT_TRUE(segregated_store_->GetValue(kSelectedPref, NULL));
148 ASSERT_TRUE(segregated_store_->GetValue(kUnselectedPref, NULL)); 150 ASSERT_TRUE(segregated_store_->GetValue(kUnselectedPref, NULL));
149 } 151 }
150 152
151 TEST_F(SegregatedPrefStoreTest, Observer) { 153 TEST_F(SegregatedPrefStoreTest, Observer) {
152 EXPECT_EQ(PersistentPrefStore::PREF_READ_ERROR_NONE, 154 EXPECT_EQ(PersistentPrefStore::PREF_READ_ERROR_NONE,
153 segregated_store_->ReadPrefs()); 155 segregated_store_->ReadPrefs());
154 EXPECT_TRUE(observer_.initialized); 156 EXPECT_TRUE(observer_.initialized);
155 EXPECT_TRUE(observer_.initialization_success); 157 EXPECT_TRUE(observer_.initialization_success);
156 EXPECT_TRUE(observer_.changed_keys.empty()); 158 EXPECT_TRUE(observer_.changed_keys.empty());
157 segregated_store_->SetValue(kSelectedPref, 159 segregated_store_->SetValue(kSelectedPref,
158 make_scoped_ptr(new base::StringValue(kValue1)), 160 base::WrapUnique(new base::StringValue(kValue1)),
159 WriteablePrefStore::DEFAULT_PREF_WRITE_FLAGS); 161 WriteablePrefStore::DEFAULT_PREF_WRITE_FLAGS);
160 observer_.VerifyAndResetChangedKey(kSelectedPref); 162 observer_.VerifyAndResetChangedKey(kSelectedPref);
161 segregated_store_->SetValue(kUnselectedPref, 163 segregated_store_->SetValue(kUnselectedPref,
162 make_scoped_ptr(new base::StringValue(kValue2)), 164 base::WrapUnique(new base::StringValue(kValue2)),
163 WriteablePrefStore::DEFAULT_PREF_WRITE_FLAGS); 165 WriteablePrefStore::DEFAULT_PREF_WRITE_FLAGS);
164 observer_.VerifyAndResetChangedKey(kUnselectedPref); 166 observer_.VerifyAndResetChangedKey(kUnselectedPref);
165 } 167 }
166 168
167 TEST_F(SegregatedPrefStoreTest, SelectedPrefReadNoFileError) { 169 TEST_F(SegregatedPrefStoreTest, SelectedPrefReadNoFileError) {
168 // 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
169 // to PREF_READ_ERROR_NONE. 171 // to PREF_READ_ERROR_NONE.
170 selected_store_->set_read_error(PersistentPrefStore::PREF_READ_ERROR_NO_FILE); 172 selected_store_->set_read_error(PersistentPrefStore::PREF_READ_ERROR_NO_FILE);
171 EXPECT_EQ(PersistentPrefStore::PREF_READ_ERROR_NONE, 173 EXPECT_EQ(PersistentPrefStore::PREF_READ_ERROR_NONE,
172 segregated_store_->ReadPrefs()); 174 segregated_store_->ReadPrefs());
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after
265 selected_store_->SetBlockAsyncRead(true); 267 selected_store_->SetBlockAsyncRead(true);
266 default_store_->SetBlockAsyncRead(true); 268 default_store_->SetBlockAsyncRead(true);
267 EXPECT_FALSE(segregated_store_->IsInitializationComplete()); 269 EXPECT_FALSE(segregated_store_->IsInitializationComplete());
268 segregated_store_->ReadPrefsAsync(NULL); 270 segregated_store_->ReadPrefsAsync(NULL);
269 EXPECT_FALSE(segregated_store_->IsInitializationComplete()); 271 EXPECT_FALSE(segregated_store_->IsInitializationComplete());
270 selected_store_->SetBlockAsyncRead(false); 272 selected_store_->SetBlockAsyncRead(false);
271 EXPECT_FALSE(segregated_store_->IsInitializationComplete()); 273 EXPECT_FALSE(segregated_store_->IsInitializationComplete());
272 default_store_->SetBlockAsyncRead(false); 274 default_store_->SetBlockAsyncRead(false);
273 EXPECT_TRUE(segregated_store_->IsInitializationComplete()); 275 EXPECT_TRUE(segregated_store_->IsInitializationComplete());
274 } 276 }
OLDNEW
« no previous file with comments | « components/user_prefs/tracked/segregated_pref_store.cc ('k') | components/user_prefs/tracked/tracked_preferences_migration.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698