Index: chrome/browser/prefs/overlay_persistent_pref_store_unittest.cc |
diff --git a/chrome/browser/prefs/overlay_persistent_pref_store_unittest.cc b/chrome/browser/prefs/overlay_persistent_pref_store_unittest.cc |
new file mode 100644 |
index 0000000000000000000000000000000000000000..64c84c0fd763633c1196797c2a17c5938c71532a |
--- /dev/null |
+++ b/chrome/browser/prefs/overlay_persistent_pref_store_unittest.cc |
@@ -0,0 +1,124 @@ |
+// Copyright (c) 2011 The Chromium Authors. All rights reserved. |
+// Use of this source code is governed by a BSD-style license that can be |
+// found in the LICENSE file. |
+ |
+#include "base/values.h" |
+#include "chrome/browser/prefs/overlay_persistent_pref_store.h" |
+#include "chrome/browser/prefs/testing_pref_store.h" |
+#include "testing/gmock/include/gmock/gmock.h" |
+#include "testing/gtest/include/gtest/gtest.h" |
+ |
+using ::testing::Mock; |
+using ::testing::StrEq; |
+ |
+const char key[] = "test.key"; |
+ |
+class OverlayPersistentPrefStoreTest : public testing::Test { |
+ public: |
+ OverlayPersistentPrefStoreTest() |
+ : underlay_(new TestingPrefStore()), |
+ overlay_(new OverlayPersistentPrefStore(underlay_.get())) { |
+ } |
+ |
+ scoped_refptr<TestingPrefStore> underlay_; |
+ scoped_refptr<OverlayPersistentPrefStore> overlay_; |
+}; |
+ |
+class PrefStoreObserverMock : public PrefStore::Observer { |
Mattias Nissler (ping if slow)
2011/01/05 12:08:07
Use pref_store_observer_mock.h?
battre
2011/01/05 20:23:08
Done.
|
+ public: |
+ MOCK_METHOD1(OnPrefValueChanged, void(const std::string& key)); |
+ MOCK_METHOD0(OnInitializationCompleted, void()); |
+}; |
+ |
+TEST_F(OverlayPersistentPrefStoreTest, Observer) { |
+ PrefStoreObserverMock obs; |
+ overlay_->AddObserver(&obs); |
+ |
+ // check that underlay first value is reported |
Mattias Nissler (ping if slow)
2011/01/05 12:08:07
Make it a proper sentence.
battre
2011/01/05 20:23:08
Done.
|
+ EXPECT_CALL(obs, OnPrefValueChanged(StrEq(key))).Times(1); |
+ underlay_->SetValue(key, Value::CreateIntegerValue(42)); |
+ Mock::VerifyAndClearExpectations(&obs); |
+ |
+ // check that underlay overwriting is reported |
+ EXPECT_CALL(obs, OnPrefValueChanged(StrEq(key))).Times(1); |
+ underlay_->SetValue(key, Value::CreateIntegerValue(43)); |
+ Mock::VerifyAndClearExpectations(&obs); |
+ |
+ // check that overwriting change in overlay is reported |
+ EXPECT_CALL(obs, OnPrefValueChanged(StrEq(key))).Times(1); |
+ overlay_->SetValue(key, Value::CreateIntegerValue(44)); |
+ Mock::VerifyAndClearExpectations(&obs); |
+ |
+ // check that hidden underlay change is not reported |
+ EXPECT_CALL(obs, OnPrefValueChanged(StrEq(key))).Times(0); |
+ underlay_->SetValue(key, Value::CreateIntegerValue(45)); |
+ Mock::VerifyAndClearExpectations(&obs); |
+ |
+ // check that overlay remove is reported |
+ EXPECT_CALL(obs, OnPrefValueChanged(StrEq(key))).Times(1); |
+ overlay_->RemoveValue(key); |
+ Mock::VerifyAndClearExpectations(&obs); |
+ |
+ // check that underlay remove is reported |
+ EXPECT_CALL(obs, OnPrefValueChanged(StrEq(key))).Times(1); |
+ underlay_->RemoveValue(key); |
+ Mock::VerifyAndClearExpectations(&obs); |
+ |
+ // check respecting of silence |
+ EXPECT_CALL(obs, OnPrefValueChanged(StrEq(key))).Times(0); |
+ overlay_->SetValueSilently(key, Value::CreateIntegerValue(46)); |
+ Mock::VerifyAndClearExpectations(&obs); |
+ |
+ overlay_->RemoveObserver(&obs); |
+ |
+ // check successful unsubscription |
+ EXPECT_CALL(obs, OnPrefValueChanged(StrEq(key))).Times(0); |
+ underlay_->SetValue(key, Value::CreateIntegerValue(47)); |
+ overlay_->SetValue(key, Value::CreateIntegerValue(48)); |
+ Mock::VerifyAndClearExpectations(&obs); |
+} |
+ |
+TEST_F(OverlayPersistentPrefStoreTest, GetAndSet) { |
+ Value* value = NULL; |
+ int i = -1; |
+ EXPECT_EQ(PrefStore::READ_NO_VALUE, overlay_->GetValue(key, &value)); |
+ EXPECT_EQ(PrefStore::READ_NO_VALUE, underlay_->GetValue(key, &value)); |
+ |
+ underlay_->SetValue(key, Value::CreateIntegerValue(42)); |
+ |
+ // value shines through: |
+ EXPECT_EQ(PrefStore::READ_OK, overlay_->GetValue(key, &value)); |
+ ASSERT_TRUE(value); |
+ EXPECT_TRUE(value->GetAsInteger(&i)); |
+ EXPECT_EQ(42, i); |
+ |
+ EXPECT_EQ(PrefStore::READ_OK, underlay_->GetValue(key, &value)); |
+ ASSERT_TRUE(value); |
+ EXPECT_TRUE(value->GetAsInteger(&i)); |
+ EXPECT_EQ(42, i); |
+ |
+ overlay_->SetValue(key, Value::CreateIntegerValue(43)); |
+ |
+ EXPECT_EQ(PrefStore::READ_OK, overlay_->GetValue(key, &value)); |
+ ASSERT_TRUE(value); |
+ EXPECT_TRUE(value->GetAsInteger(&i)); |
+ EXPECT_EQ(43, i); |
+ |
+ EXPECT_EQ(PrefStore::READ_OK, underlay_->GetValue(key, &value)); |
+ ASSERT_TRUE(value); |
+ EXPECT_TRUE(value->GetAsInteger(&i)); |
+ EXPECT_EQ(42, i); |
+ |
+ overlay_->RemoveValue(key); |
+ |
+ // value shines through: |
+ EXPECT_EQ(PrefStore::READ_OK, overlay_->GetValue(key, &value)); |
+ ASSERT_TRUE(value); |
+ EXPECT_TRUE(value->GetAsInteger(&i)); |
+ EXPECT_EQ(42, i); |
+ |
+ EXPECT_EQ(PrefStore::READ_OK, underlay_->GetValue(key, &value)); |
+ ASSERT_TRUE(value); |
+ EXPECT_TRUE(value->GetAsInteger(&i)); |
+ EXPECT_EQ(42, i); |
+} |