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

Unified Diff: blimp/engine/common/blimp_pref_store_unittest.cc

Issue 1881253003: Create a PrefStore in support of Blimp metrics collection. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Additional test to confirm proper observer calls. 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « blimp/engine/common/blimp_pref_store.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: blimp/engine/common/blimp_pref_store_unittest.cc
diff --git a/blimp/engine/common/blimp_pref_store_unittest.cc b/blimp/engine/common/blimp_pref_store_unittest.cc
new file mode 100644
index 0000000000000000000000000000000000000000..f31b5b208df2d595ba0f980a589c0803ced2388f
--- /dev/null
+++ b/blimp/engine/common/blimp_pref_store_unittest.cc
@@ -0,0 +1,87 @@
+// Copyright 2016 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 "blimp/engine/common/blimp_pref_store.h"
+
+#include "base/values.h"
+#include "components/prefs/pref_store_observer_mock.h"
+#include "testing/gmock/include/gmock/gmock.h"
+#include "testing/gtest/include/gtest/gtest.h"
+
+namespace blimp {
+namespace engine {
+namespace {
+const char kTestPref[] = "test.pref";
+
+class BlimpPrefStoreTest : public testing::Test {
+ public:
+ BlimpPrefStoreTest() { }
+
+ void SetUp() override { store_ = new BlimpPrefStore(); }
+ protected:
+ scoped_refptr<BlimpPrefStore> store_;
+ PrefStoreObserverMock observer_;
+};
+
+TEST_F(BlimpPrefStoreTest, SetGetValue) {
+ const base::Value* value = NULL;
+ base::Value* mutable_value = NULL;
+ EXPECT_FALSE(store_->GetValue(kTestPref, &value));
+ EXPECT_FALSE(store_->GetMutableValue(kTestPref, &mutable_value));
+
+ store_->SetValue(kTestPref, make_scoped_ptr(new base::FundamentalValue(42)),
+ WriteablePrefStore::DEFAULT_PREF_WRITE_FLAGS);
+ EXPECT_TRUE(store_->GetValue(kTestPref, &value));
+ EXPECT_TRUE(base::FundamentalValue(42).Equals(value));
+ EXPECT_TRUE(store_->GetMutableValue(kTestPref, &mutable_value));
+ EXPECT_TRUE(base::FundamentalValue(42).Equals(mutable_value));
+
+ store_->RemoveValue(kTestPref, WriteablePrefStore::DEFAULT_PREF_WRITE_FLAGS);
+ EXPECT_FALSE(store_->GetValue(kTestPref, &value));
+ EXPECT_FALSE(store_->GetMutableValue(kTestPref, &mutable_value));
+}
+
+TEST_F(BlimpPrefStoreTest, GetSetObserver) {
+ // Starts with no observers.
+ EXPECT_FALSE(store_->HasObservers());
+ // Add one.
Kevin M 2016/04/20 23:03:35 Add newlines before commented blocks, so... EXPEC
Jess 2016/04/20 23:32:06 Done.
+ store_->AddObserver(&observer_);
+ EXPECT_TRUE(store_->HasObservers());
+ // Remove only observer.
+ store_->RemoveObserver(&observer_);
+ EXPECT_FALSE(store_->HasObservers());
+}
+
+TEST_F(BlimpPrefStoreTest, CallObserver) {
+ // With observer included.
+ store_->AddObserver(&observer_);
+ // Triggers on SetValue.
+ store_->SetValue(kTestPref, make_scoped_ptr(new base::FundamentalValue(42)),
+ WriteablePrefStore::DEFAULT_PREF_WRITE_FLAGS);
+ observer_.VerifyAndResetChangedKey(kTestPref);
+ // And RemoveValue.
+ store_->RemoveValue(kTestPref, WriteablePrefStore::DEFAULT_PREF_WRITE_FLAGS);
+ observer_.VerifyAndResetChangedKey(kTestPref);
+ // But not SetValueSilently.
+ store_->SetValueSilently(kTestPref,
+ make_scoped_ptr(new base::FundamentalValue(42)),
+ WriteablePrefStore::DEFAULT_PREF_WRITE_FLAGS);
+ EXPECT_EQ(0u, observer_.changed_keys.size());
+ // On multiple RemoveValues only the first one triggers observer.
+ store_->RemoveValue(kTestPref, WriteablePrefStore::DEFAULT_PREF_WRITE_FLAGS);
+ observer_.VerifyAndResetChangedKey(kTestPref);
+ store_->RemoveValue(kTestPref, WriteablePrefStore::DEFAULT_PREF_WRITE_FLAGS);
+ EXPECT_EQ(0u, observer_.changed_keys.size());
+
+ // Doesn't make call on removed observers.
+ store_->RemoveObserver(&observer_);
+ store_->SetValue(kTestPref, make_scoped_ptr(new base::FundamentalValue(42)),
+ WriteablePrefStore::DEFAULT_PREF_WRITE_FLAGS);
+ store_->RemoveValue(kTestPref, WriteablePrefStore::DEFAULT_PREF_WRITE_FLAGS);
+ EXPECT_EQ(0u, observer_.changed_keys.size());
+}
+
+} // namespace
+} // namespace engine
+} // namespace blimp
« no previous file with comments | « blimp/engine/common/blimp_pref_store.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698