OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 "base/values.h" | 5 #include "base/values.h" |
6 #include "chrome/browser/prefs/incognito_user_pref_store.h" | 6 #include "chrome/browser/prefs/incognito_user_pref_store.h" |
7 #include "chrome/browser/prefs/testing_pref_store.h" | 7 #include "chrome/browser/prefs/testing_pref_store.h" |
8 #include "chrome/common/pref_names.h" | 8 #include "chrome/common/pref_names.h" |
9 #include "chrome/common/pref_store_observer_mock.h" | 9 #include "chrome/common/pref_store_observer_mock.h" |
10 #include "testing/gmock/include/gmock/gmock.h" | 10 #include "testing/gmock/include/gmock/gmock.h" |
(...skipping 21 matching lines...) Expand all Loading... |
32 scoped_refptr<TestingPrefStore> underlay_; | 32 scoped_refptr<TestingPrefStore> underlay_; |
33 scoped_refptr<IncognitoUserPrefStore> overlay_; | 33 scoped_refptr<IncognitoUserPrefStore> overlay_; |
34 }; | 34 }; |
35 | 35 |
36 TEST_F(IncognitoUserPrefStoreTest, Observer) { | 36 TEST_F(IncognitoUserPrefStoreTest, Observer) { |
37 PrefStoreObserverMock obs; | 37 PrefStoreObserverMock obs; |
38 overlay_->AddObserver(&obs); | 38 overlay_->AddObserver(&obs); |
39 | 39 |
40 // Check that underlay first value is reported. | 40 // Check that underlay first value is reported. |
41 EXPECT_CALL(obs, OnPrefValueChanged(StrEq(incognito_key))).Times(1); | 41 EXPECT_CALL(obs, OnPrefValueChanged(StrEq(incognito_key))).Times(1); |
42 underlay_->SetValue(incognito_key, Value::CreateIntegerValue(42)); | 42 underlay_->SetValue(incognito_key, base::NumberValue::New(42)); |
43 Mock::VerifyAndClearExpectations(&obs); | 43 Mock::VerifyAndClearExpectations(&obs); |
44 | 44 |
45 // Check that underlay overwriting is reported. | 45 // Check that underlay overwriting is reported. |
46 EXPECT_CALL(obs, OnPrefValueChanged(StrEq(incognito_key))).Times(1); | 46 EXPECT_CALL(obs, OnPrefValueChanged(StrEq(incognito_key))).Times(1); |
47 underlay_->SetValue(incognito_key, Value::CreateIntegerValue(43)); | 47 underlay_->SetValue(incognito_key, base::NumberValue::New(43)); |
48 Mock::VerifyAndClearExpectations(&obs); | 48 Mock::VerifyAndClearExpectations(&obs); |
49 | 49 |
50 // Check that overwriting change in overlay is reported. | 50 // Check that overwriting change in overlay is reported. |
51 EXPECT_CALL(obs, OnPrefValueChanged(StrEq(incognito_key))).Times(1); | 51 EXPECT_CALL(obs, OnPrefValueChanged(StrEq(incognito_key))).Times(1); |
52 overlay_->SetValue(incognito_key, Value::CreateIntegerValue(44)); | 52 overlay_->SetValue(incognito_key, base::NumberValue::New(44)); |
53 Mock::VerifyAndClearExpectations(&obs); | 53 Mock::VerifyAndClearExpectations(&obs); |
54 | 54 |
55 // Check that hidden underlay change is not reported. | 55 // Check that hidden underlay change is not reported. |
56 EXPECT_CALL(obs, OnPrefValueChanged(StrEq(incognito_key))).Times(0); | 56 EXPECT_CALL(obs, OnPrefValueChanged(StrEq(incognito_key))).Times(0); |
57 underlay_->SetValue(incognito_key, Value::CreateIntegerValue(45)); | 57 underlay_->SetValue(incognito_key, base::NumberValue::New(45)); |
58 Mock::VerifyAndClearExpectations(&obs); | 58 Mock::VerifyAndClearExpectations(&obs); |
59 | 59 |
60 // Check that overlay remove is reported. | 60 // Check that overlay remove is reported. |
61 EXPECT_CALL(obs, OnPrefValueChanged(StrEq(incognito_key))).Times(1); | 61 EXPECT_CALL(obs, OnPrefValueChanged(StrEq(incognito_key))).Times(1); |
62 overlay_->RemoveValue(incognito_key); | 62 overlay_->RemoveValue(incognito_key); |
63 Mock::VerifyAndClearExpectations(&obs); | 63 Mock::VerifyAndClearExpectations(&obs); |
64 | 64 |
65 // Check that underlay remove is reported. | 65 // Check that underlay remove is reported. |
66 EXPECT_CALL(obs, OnPrefValueChanged(StrEq(incognito_key))).Times(1); | 66 EXPECT_CALL(obs, OnPrefValueChanged(StrEq(incognito_key))).Times(1); |
67 underlay_->RemoveValue(incognito_key); | 67 underlay_->RemoveValue(incognito_key); |
68 Mock::VerifyAndClearExpectations(&obs); | 68 Mock::VerifyAndClearExpectations(&obs); |
69 | 69 |
70 // Check respecting of silence. | 70 // Check respecting of silence. |
71 EXPECT_CALL(obs, OnPrefValueChanged(StrEq(incognito_key))).Times(0); | 71 EXPECT_CALL(obs, OnPrefValueChanged(StrEq(incognito_key))).Times(0); |
72 overlay_->SetValueSilently(incognito_key, Value::CreateIntegerValue(46)); | 72 overlay_->SetValueSilently(incognito_key, base::NumberValue::New(46)); |
73 Mock::VerifyAndClearExpectations(&obs); | 73 Mock::VerifyAndClearExpectations(&obs); |
74 | 74 |
75 overlay_->RemoveObserver(&obs); | 75 overlay_->RemoveObserver(&obs); |
76 | 76 |
77 // Check successful unsubscription. | 77 // Check successful unsubscription. |
78 EXPECT_CALL(obs, OnPrefValueChanged(StrEq(incognito_key))).Times(0); | 78 EXPECT_CALL(obs, OnPrefValueChanged(StrEq(incognito_key))).Times(0); |
79 underlay_->SetValue(incognito_key, Value::CreateIntegerValue(47)); | 79 underlay_->SetValue(incognito_key, base::NumberValue::New(47)); |
80 overlay_->SetValue(incognito_key, Value::CreateIntegerValue(48)); | 80 overlay_->SetValue(incognito_key, base::NumberValue::New(48)); |
81 Mock::VerifyAndClearExpectations(&obs); | 81 Mock::VerifyAndClearExpectations(&obs); |
82 } | 82 } |
83 | 83 |
84 TEST_F(IncognitoUserPrefStoreTest, GetAndSet) { | 84 TEST_F(IncognitoUserPrefStoreTest, GetAndSet) { |
85 const Value* value = NULL; | 85 const Value* value = NULL; |
86 int i = -1; | 86 int i = -1; |
87 EXPECT_EQ(PrefStore::READ_NO_VALUE, | 87 EXPECT_EQ(PrefStore::READ_NO_VALUE, |
88 overlay_->GetValue(incognito_key, &value)); | 88 overlay_->GetValue(incognito_key, &value)); |
89 EXPECT_EQ(PrefStore::READ_NO_VALUE, | 89 EXPECT_EQ(PrefStore::READ_NO_VALUE, |
90 underlay_->GetValue(incognito_key, &value)); | 90 underlay_->GetValue(incognito_key, &value)); |
91 | 91 |
92 underlay_->SetValue(incognito_key, Value::CreateIntegerValue(42)); | 92 underlay_->SetValue(incognito_key, base::NumberValue::New(42)); |
93 | 93 |
94 // Value shines through: | 94 // Value shines through: |
95 EXPECT_EQ(PrefStore::READ_OK, overlay_->GetValue(incognito_key, &value)); | 95 EXPECT_EQ(PrefStore::READ_OK, overlay_->GetValue(incognito_key, &value)); |
96 ASSERT_TRUE(value); | 96 ASSERT_TRUE(value); |
97 EXPECT_TRUE(value->GetAsInteger(&i)); | 97 EXPECT_TRUE(value->GetAsInteger(&i)); |
98 EXPECT_EQ(42, i); | 98 EXPECT_EQ(42, i); |
99 | 99 |
100 EXPECT_EQ(PrefStore::READ_OK, underlay_->GetValue(incognito_key, &value)); | 100 EXPECT_EQ(PrefStore::READ_OK, underlay_->GetValue(incognito_key, &value)); |
101 ASSERT_TRUE(value); | 101 ASSERT_TRUE(value); |
102 EXPECT_TRUE(value->GetAsInteger(&i)); | 102 EXPECT_TRUE(value->GetAsInteger(&i)); |
103 EXPECT_EQ(42, i); | 103 EXPECT_EQ(42, i); |
104 | 104 |
105 overlay_->SetValue(incognito_key, Value::CreateIntegerValue(43)); | 105 overlay_->SetValue(incognito_key, base::NumberValue::New(43)); |
106 | 106 |
107 EXPECT_EQ(PrefStore::READ_OK, overlay_->GetValue(incognito_key, &value)); | 107 EXPECT_EQ(PrefStore::READ_OK, overlay_->GetValue(incognito_key, &value)); |
108 ASSERT_TRUE(value); | 108 ASSERT_TRUE(value); |
109 EXPECT_TRUE(value->GetAsInteger(&i)); | 109 EXPECT_TRUE(value->GetAsInteger(&i)); |
110 EXPECT_EQ(43, i); | 110 EXPECT_EQ(43, i); |
111 | 111 |
112 EXPECT_EQ(PrefStore::READ_OK, underlay_->GetValue(incognito_key, &value)); | 112 EXPECT_EQ(PrefStore::READ_OK, underlay_->GetValue(incognito_key, &value)); |
113 ASSERT_TRUE(value); | 113 ASSERT_TRUE(value); |
114 EXPECT_TRUE(value->GetAsInteger(&i)); | 114 EXPECT_TRUE(value->GetAsInteger(&i)); |
115 EXPECT_EQ(42, i); | 115 EXPECT_EQ(42, i); |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
157 // Here we consider a global preference that is not incognito specific. | 157 // Here we consider a global preference that is not incognito specific. |
158 TEST_F(IncognitoUserPrefStoreTest, GlobalPref) { | 158 TEST_F(IncognitoUserPrefStoreTest, GlobalPref) { |
159 PrefStoreObserverMock obs; | 159 PrefStoreObserverMock obs; |
160 overlay_->AddObserver(&obs); | 160 overlay_->AddObserver(&obs); |
161 | 161 |
162 const Value* value = NULL; | 162 const Value* value = NULL; |
163 int i = -1; | 163 int i = -1; |
164 | 164 |
165 // Check that underlay first value is reported. | 165 // Check that underlay first value is reported. |
166 EXPECT_CALL(obs, OnPrefValueChanged(StrEq(regular_key))).Times(1); | 166 EXPECT_CALL(obs, OnPrefValueChanged(StrEq(regular_key))).Times(1); |
167 underlay_->SetValue(regular_key, Value::CreateIntegerValue(42)); | 167 underlay_->SetValue(regular_key, base::NumberValue::New(42)); |
168 Mock::VerifyAndClearExpectations(&obs); | 168 Mock::VerifyAndClearExpectations(&obs); |
169 | 169 |
170 // Check that underlay overwriting is reported. | 170 // Check that underlay overwriting is reported. |
171 EXPECT_CALL(obs, OnPrefValueChanged(StrEq(regular_key))).Times(1); | 171 EXPECT_CALL(obs, OnPrefValueChanged(StrEq(regular_key))).Times(1); |
172 underlay_->SetValue(regular_key, Value::CreateIntegerValue(43)); | 172 underlay_->SetValue(regular_key, base::NumberValue::New(43)); |
173 Mock::VerifyAndClearExpectations(&obs); | 173 Mock::VerifyAndClearExpectations(&obs); |
174 | 174 |
175 // Check that we get this value from the overlay | 175 // Check that we get this value from the overlay |
176 EXPECT_EQ(PrefStore::READ_OK, overlay_->GetValue(regular_key, &value)); | 176 EXPECT_EQ(PrefStore::READ_OK, overlay_->GetValue(regular_key, &value)); |
177 ASSERT_TRUE(value); | 177 ASSERT_TRUE(value); |
178 EXPECT_TRUE(value->GetAsInteger(&i)); | 178 EXPECT_TRUE(value->GetAsInteger(&i)); |
179 EXPECT_EQ(43, i); | 179 EXPECT_EQ(43, i); |
180 | 180 |
181 // Check that overwriting change in overlay is reported. | 181 // Check that overwriting change in overlay is reported. |
182 EXPECT_CALL(obs, OnPrefValueChanged(StrEq(regular_key))).Times(1); | 182 EXPECT_CALL(obs, OnPrefValueChanged(StrEq(regular_key))).Times(1); |
183 overlay_->SetValue(regular_key, Value::CreateIntegerValue(44)); | 183 overlay_->SetValue(regular_key, base::NumberValue::New(44)); |
184 Mock::VerifyAndClearExpectations(&obs); | 184 Mock::VerifyAndClearExpectations(&obs); |
185 | 185 |
186 // Check that we get this value from the overlay and the underlay. | 186 // Check that we get this value from the overlay and the underlay. |
187 EXPECT_EQ(PrefStore::READ_OK, overlay_->GetValue(regular_key, &value)); | 187 EXPECT_EQ(PrefStore::READ_OK, overlay_->GetValue(regular_key, &value)); |
188 ASSERT_TRUE(value); | 188 ASSERT_TRUE(value); |
189 EXPECT_TRUE(value->GetAsInteger(&i)); | 189 EXPECT_TRUE(value->GetAsInteger(&i)); |
190 EXPECT_EQ(44, i); | 190 EXPECT_EQ(44, i); |
191 EXPECT_EQ(PrefStore::READ_OK, underlay_->GetValue(regular_key, &value)); | 191 EXPECT_EQ(PrefStore::READ_OK, underlay_->GetValue(regular_key, &value)); |
192 ASSERT_TRUE(value); | 192 ASSERT_TRUE(value); |
193 EXPECT_TRUE(value->GetAsInteger(&i)); | 193 EXPECT_TRUE(value->GetAsInteger(&i)); |
194 EXPECT_EQ(44, i); | 194 EXPECT_EQ(44, i); |
195 | 195 |
196 // Check that overlay remove is reported. | 196 // Check that overlay remove is reported. |
197 EXPECT_CALL(obs, OnPrefValueChanged(StrEq(regular_key))).Times(1); | 197 EXPECT_CALL(obs, OnPrefValueChanged(StrEq(regular_key))).Times(1); |
198 overlay_->RemoveValue(regular_key); | 198 overlay_->RemoveValue(regular_key); |
199 Mock::VerifyAndClearExpectations(&obs); | 199 Mock::VerifyAndClearExpectations(&obs); |
200 | 200 |
201 // Check that value was removed from overlay and underlay | 201 // Check that value was removed from overlay and underlay |
202 EXPECT_EQ(PrefStore::READ_NO_VALUE, overlay_->GetValue(regular_key, &value)); | 202 EXPECT_EQ(PrefStore::READ_NO_VALUE, overlay_->GetValue(regular_key, &value)); |
203 EXPECT_EQ(PrefStore::READ_NO_VALUE, underlay_->GetValue(regular_key, &value)); | 203 EXPECT_EQ(PrefStore::READ_NO_VALUE, underlay_->GetValue(regular_key, &value)); |
204 | 204 |
205 // Check respecting of silence. | 205 // Check respecting of silence. |
206 EXPECT_CALL(obs, OnPrefValueChanged(StrEq(regular_key))).Times(0); | 206 EXPECT_CALL(obs, OnPrefValueChanged(StrEq(regular_key))).Times(0); |
207 overlay_->SetValueSilently(regular_key, Value::CreateIntegerValue(46)); | 207 overlay_->SetValueSilently(regular_key, base::NumberValue::New(46)); |
208 Mock::VerifyAndClearExpectations(&obs); | 208 Mock::VerifyAndClearExpectations(&obs); |
209 | 209 |
210 overlay_->RemoveObserver(&obs); | 210 overlay_->RemoveObserver(&obs); |
211 | 211 |
212 // Check successful unsubscription. | 212 // Check successful unsubscription. |
213 EXPECT_CALL(obs, OnPrefValueChanged(StrEq(regular_key))).Times(0); | 213 EXPECT_CALL(obs, OnPrefValueChanged(StrEq(regular_key))).Times(0); |
214 underlay_->SetValue(regular_key, Value::CreateIntegerValue(47)); | 214 underlay_->SetValue(regular_key, base::NumberValue::New(47)); |
215 overlay_->SetValue(regular_key, Value::CreateIntegerValue(48)); | 215 overlay_->SetValue(regular_key, base::NumberValue::New(48)); |
216 Mock::VerifyAndClearExpectations(&obs); | 216 Mock::VerifyAndClearExpectations(&obs); |
217 } | 217 } |
OLD | NEW |