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

Unified Diff: base/prefs/overlay_user_pref_store_unittest.cc

Issue 210063003: Refactor TestingPrefStore to make it useful to some tests of load errors and asynchrony. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Adopt a non-gmock approach in the clients. Created 6 years, 9 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | base/prefs/pref_store_observer_mock.h » ('j') | base/prefs/testing_pref_store.h » ('J')
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: base/prefs/overlay_user_pref_store_unittest.cc
diff --git a/base/prefs/overlay_user_pref_store_unittest.cc b/base/prefs/overlay_user_pref_store_unittest.cc
index c4e980bbae3e0c8b9877c6b265a64984c998930f..0ff0aa1b03e56c111c2e5198ada514bce620c6c1 100644
--- a/base/prefs/overlay_user_pref_store_unittest.cc
+++ b/base/prefs/overlay_user_pref_store_unittest.cc
@@ -26,6 +26,15 @@ const char* regular_key = kShowBookmarkBar;
const char* mapped_overlay_key = "test.per_tab.javascript_enabled";
const char* mapped_underlay_key = "test.per_profile.javascript_enabled";
+void ExpectAndPopOneValue(const std::string& value,
Mattias Nissler (ping if slow) 2014/03/27 20:28:05 It'd probably make sense to turn this into: void
+ std::vector<std::string>* collection) {
+ EXPECT_EQ(1u, collection->size());
+ if (collection->size() >= 1) {
+ EXPECT_EQ(value, collection->front());
+ collection->erase(collection->begin());
+ }
+}
+
} // namespace
class OverlayUserPrefStoreTest : public testing::Test {
@@ -48,47 +57,39 @@ TEST_F(OverlayUserPrefStoreTest, Observer) {
overlay_->AddObserver(&obs);
// Check that underlay first value is reported.
- EXPECT_CALL(obs, OnPrefValueChanged(StrEq(overlay_key))).Times(1);
underlay_->SetValue(overlay_key, new FundamentalValue(42));
- Mock::VerifyAndClearExpectations(&obs);
+ ExpectAndPopOneValue(overlay_key, &obs.changed_keys);
// Check that underlay overwriting is reported.
- EXPECT_CALL(obs, OnPrefValueChanged(StrEq(overlay_key))).Times(1);
underlay_->SetValue(overlay_key, new FundamentalValue(43));
- Mock::VerifyAndClearExpectations(&obs);
+ ExpectAndPopOneValue(overlay_key, &obs.changed_keys);
// Check that overwriting change in overlay is reported.
- EXPECT_CALL(obs, OnPrefValueChanged(StrEq(overlay_key))).Times(1);
overlay_->SetValue(overlay_key, new FundamentalValue(44));
- Mock::VerifyAndClearExpectations(&obs);
+ ExpectAndPopOneValue(overlay_key, &obs.changed_keys);
// Check that hidden underlay change is not reported.
- EXPECT_CALL(obs, OnPrefValueChanged(StrEq(overlay_key))).Times(0);
underlay_->SetValue(overlay_key, new FundamentalValue(45));
- Mock::VerifyAndClearExpectations(&obs);
+ EXPECT_TRUE(obs.changed_keys.empty());
// Check that overlay remove is reported.
- EXPECT_CALL(obs, OnPrefValueChanged(StrEq(overlay_key))).Times(1);
overlay_->RemoveValue(overlay_key);
- Mock::VerifyAndClearExpectations(&obs);
+ ExpectAndPopOneValue(overlay_key, &obs.changed_keys);
// Check that underlay remove is reported.
- EXPECT_CALL(obs, OnPrefValueChanged(StrEq(overlay_key))).Times(1);
underlay_->RemoveValue(overlay_key);
- Mock::VerifyAndClearExpectations(&obs);
+ ExpectAndPopOneValue(overlay_key, &obs.changed_keys);
// Check respecting of silence.
- EXPECT_CALL(obs, OnPrefValueChanged(StrEq(overlay_key))).Times(0);
overlay_->SetValueSilently(overlay_key, new FundamentalValue(46));
- Mock::VerifyAndClearExpectations(&obs);
+ EXPECT_TRUE(obs.changed_keys.empty());
overlay_->RemoveObserver(&obs);
// Check successful unsubscription.
- EXPECT_CALL(obs, OnPrefValueChanged(StrEq(overlay_key))).Times(0);
underlay_->SetValue(overlay_key, new FundamentalValue(47));
overlay_->SetValue(overlay_key, new FundamentalValue(48));
- Mock::VerifyAndClearExpectations(&obs);
+ EXPECT_TRUE(obs.changed_keys.empty());
}
TEST_F(OverlayUserPrefStoreTest, GetAndSet) {
@@ -154,23 +155,20 @@ TEST_F(OverlayUserPrefStoreTest, GlobalPref) {
const Value* value = NULL;
// Check that underlay first value is reported.
- EXPECT_CALL(obs, OnPrefValueChanged(StrEq(regular_key))).Times(1);
underlay_->SetValue(regular_key, new FundamentalValue(42));
- Mock::VerifyAndClearExpectations(&obs);
+ ExpectAndPopOneValue(regular_key, &obs.changed_keys);
// Check that underlay overwriting is reported.
- EXPECT_CALL(obs, OnPrefValueChanged(StrEq(regular_key))).Times(1);
underlay_->SetValue(regular_key, new FundamentalValue(43));
- Mock::VerifyAndClearExpectations(&obs);
+ ExpectAndPopOneValue(regular_key, &obs.changed_keys);
// Check that we get this value from the overlay
EXPECT_TRUE(overlay_->GetValue(regular_key, &value));
EXPECT_TRUE(base::FundamentalValue(43).Equals(value));
// Check that overwriting change in overlay is reported.
- EXPECT_CALL(obs, OnPrefValueChanged(StrEq(regular_key))).Times(1);
overlay_->SetValue(regular_key, new FundamentalValue(44));
- Mock::VerifyAndClearExpectations(&obs);
+ ExpectAndPopOneValue(regular_key, &obs.changed_keys);
// Check that we get this value from the overlay and the underlay.
EXPECT_TRUE(overlay_->GetValue(regular_key, &value));
@@ -179,26 +177,23 @@ TEST_F(OverlayUserPrefStoreTest, GlobalPref) {
EXPECT_TRUE(base::FundamentalValue(44).Equals(value));
// Check that overlay remove is reported.
- EXPECT_CALL(obs, OnPrefValueChanged(StrEq(regular_key))).Times(1);
overlay_->RemoveValue(regular_key);
- Mock::VerifyAndClearExpectations(&obs);
+ ExpectAndPopOneValue(regular_key, &obs.changed_keys);
// Check that value was removed from overlay and underlay
EXPECT_FALSE(overlay_->GetValue(regular_key, &value));
EXPECT_FALSE(underlay_->GetValue(regular_key, &value));
// Check respecting of silence.
- EXPECT_CALL(obs, OnPrefValueChanged(StrEq(regular_key))).Times(0);
overlay_->SetValueSilently(regular_key, new FundamentalValue(46));
- Mock::VerifyAndClearExpectations(&obs);
+ EXPECT_TRUE(obs.changed_keys.empty());
overlay_->RemoveObserver(&obs);
// Check successful unsubscription.
- EXPECT_CALL(obs, OnPrefValueChanged(StrEq(regular_key))).Times(0);
underlay_->SetValue(regular_key, new FundamentalValue(47));
overlay_->SetValue(regular_key, new FundamentalValue(48));
- Mock::VerifyAndClearExpectations(&obs);
+ EXPECT_TRUE(obs.changed_keys.empty());
}
// Check that names mapping works correctly.
@@ -210,14 +205,12 @@ TEST_F(OverlayUserPrefStoreTest, NamesMapping) {
// Check that if there is no override in the overlay, changing underlay value
// is reported as changing an overlay value.
- EXPECT_CALL(obs, OnPrefValueChanged(StrEq(mapped_overlay_key))).Times(1);
underlay_->SetValue(mapped_underlay_key, new FundamentalValue(42));
- Mock::VerifyAndClearExpectations(&obs);
+ ExpectAndPopOneValue(mapped_overlay_key, &obs.changed_keys);
// Check that underlay overwriting is reported.
- EXPECT_CALL(obs, OnPrefValueChanged(StrEq(mapped_overlay_key))).Times(1);
underlay_->SetValue(mapped_underlay_key, new FundamentalValue(43));
- Mock::VerifyAndClearExpectations(&obs);
+ ExpectAndPopOneValue(mapped_overlay_key, &obs.changed_keys);
// Check that we get this value from the overlay with both keys
EXPECT_TRUE(overlay_->GetValue(mapped_overlay_key, &value));
@@ -227,9 +220,8 @@ TEST_F(OverlayUserPrefStoreTest, NamesMapping) {
EXPECT_TRUE(base::FundamentalValue(43).Equals(value));
// Check that overwriting change in overlay is reported.
- EXPECT_CALL(obs, OnPrefValueChanged(StrEq(mapped_overlay_key))).Times(1);
overlay_->SetValue(mapped_overlay_key, new FundamentalValue(44));
- Mock::VerifyAndClearExpectations(&obs);
+ ExpectAndPopOneValue(mapped_overlay_key, &obs.changed_keys);
// Check that we get an overriden value from overlay, while reading the
// value from underlay still holds an old value.
@@ -241,38 +233,31 @@ TEST_F(OverlayUserPrefStoreTest, NamesMapping) {
EXPECT_TRUE(base::FundamentalValue(43).Equals(value));
// Check that hidden underlay change is not reported.
- EXPECT_CALL(obs, OnPrefValueChanged(StrEq(mapped_overlay_key))).Times(0);
underlay_->SetValue(mapped_underlay_key, new FundamentalValue(45));
- Mock::VerifyAndClearExpectations(&obs);
+ EXPECT_TRUE(obs.changed_keys.empty());
// Check that overlay remove is reported.
- EXPECT_CALL(obs, OnPrefValueChanged(StrEq(mapped_overlay_key))).Times(1);
overlay_->RemoveValue(mapped_overlay_key);
- Mock::VerifyAndClearExpectations(&obs);
+ ExpectAndPopOneValue(mapped_overlay_key, &obs.changed_keys);
// Check that underlay remove is reported.
- EXPECT_CALL(obs, OnPrefValueChanged(StrEq(mapped_overlay_key))).Times(1);
underlay_->RemoveValue(mapped_underlay_key);
- Mock::VerifyAndClearExpectations(&obs);
+ ExpectAndPopOneValue(mapped_overlay_key, &obs.changed_keys);
// Check that value was removed.
EXPECT_FALSE(overlay_->GetValue(mapped_overlay_key, &value));
EXPECT_FALSE(overlay_->GetValue(mapped_underlay_key, &value));
// Check respecting of silence.
- EXPECT_CALL(obs, OnPrefValueChanged(StrEq(mapped_overlay_key))).Times(0);
- EXPECT_CALL(obs, OnPrefValueChanged(StrEq(mapped_underlay_key))).Times(0);
overlay_->SetValueSilently(mapped_overlay_key, new FundamentalValue(46));
- Mock::VerifyAndClearExpectations(&obs);
+ EXPECT_TRUE(obs.changed_keys.empty());
overlay_->RemoveObserver(&obs);
// Check successful unsubscription.
- EXPECT_CALL(obs, OnPrefValueChanged(StrEq(mapped_overlay_key))).Times(0);
- EXPECT_CALL(obs, OnPrefValueChanged(StrEq(mapped_underlay_key))).Times(0);
underlay_->SetValue(mapped_underlay_key, new FundamentalValue(47));
overlay_->SetValue(mapped_overlay_key, new FundamentalValue(48));
- Mock::VerifyAndClearExpectations(&obs);
+ EXPECT_TRUE(obs.changed_keys.empty());
}
} // namespace base
« no previous file with comments | « no previous file | base/prefs/pref_store_observer_mock.h » ('j') | base/prefs/testing_pref_store.h » ('J')

Powered by Google App Engine
This is Rietveld 408576698