summaryrefslogtreecommitdiffstats
path: root/chrome/browser/pref_service_unittest.cc
diff options
context:
space:
mode:
authorskrul@chromium.org <skrul@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-04-02 17:36:18 +0000
committerskrul@chromium.org <skrul@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-04-02 17:36:18 +0000
commitecde2747b368a859e01614c7894fca25f670f1e5 (patch)
treedc4f54c2601f376cb60d0a45547cf85b27ee35c0 /chrome/browser/pref_service_unittest.cc
parent585d1c413d6316fc0e0be535f9eafb74ab4d0236 (diff)
downloadchromium_src-ecde2747b368a859e01614c7894fca25f670f1e5.zip
chromium_src-ecde2747b368a859e01614c7894fca25f670f1e5.tar.gz
chromium_src-ecde2747b368a859e01614c7894fca25f670f1e5.tar.bz2
Add a bunch of preferences to sync.
This includes a fix for not crashing when we encounter a preference that is not registered. BUG=39958 Review URL: http://codereview.chromium.org/1571006 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@43497 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/pref_service_unittest.cc')
-rw-r--r--chrome/browser/pref_service_unittest.cc121
1 files changed, 121 insertions, 0 deletions
diff --git a/chrome/browser/pref_service_unittest.cc b/chrome/browser/pref_service_unittest.cc
index aac27b9..e643b8c 100644
--- a/chrome/browser/pref_service_unittest.cc
+++ b/chrome/browser/pref_service_unittest.cc
@@ -2,19 +2,30 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
+#include <string>
+
#include "app/test/data/resource.h"
#include "base/file_util.h"
#include "base/message_loop.h"
#include "base/path_service.h"
+#include "base/scoped_ptr.h"
+#include "base/values.h"
#include "chrome/browser/chrome_thread.h"
#include "chrome/browser/pref_service.h"
#include "chrome/common/chrome_paths.h"
#include "chrome/common/json_value_serializer.h"
+#include "chrome/common/notification_observer_mock.h"
#include "chrome/common/notification_service.h"
#include "chrome/common/notification_type.h"
#include "chrome/common/pref_names.h"
+#include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h"
+using testing::_;
+using testing::Mock;
+using testing::Pointee;
+using testing::Property;
+
class PrefServiceTest : public testing::Test {
protected:
virtual void SetUp() {
@@ -268,3 +279,113 @@ TEST_F(PrefServiceTest, HasPrefPath) {
prefs.SetString(path, L"blah");
EXPECT_TRUE(prefs.HasPrefPath(path));
}
+
+class PrefServiceSetValueTest : public testing::Test {
+ protected:
+ static const wchar_t name_[];
+ static const wchar_t value_[];
+
+ PrefServiceSetValueTest()
+ : prefs_(FilePath()),
+ name_string_(name_),
+ null_value_(Value::CreateNullValue()) {}
+
+ void SetExpectNoNotification() {
+ EXPECT_CALL(observer_, Observe(_, _, _)).Times(0);
+ }
+
+ void SetExpectPrefChanged() {
+ EXPECT_CALL(observer_,
+ Observe(NotificationType(NotificationType::PREF_CHANGED), _,
+ Property(&Details<std::wstring>::ptr,
+ Pointee(name_string_))));
+ }
+
+ PrefService prefs_;
+ std::wstring name_string_;
+ scoped_ptr<Value> null_value_;
+ NotificationObserverMock observer_;
+};
+const wchar_t PrefServiceSetValueTest::name_[] = L"name";
+const wchar_t PrefServiceSetValueTest::value_[] = L"value";
+
+TEST_F(PrefServiceSetValueTest, SetStringValue) {
+ const wchar_t default_string[] = L"default";
+ scoped_ptr<Value> default_value(Value::CreateStringValue(default_string));
+ prefs_.RegisterStringPref(name_, default_string);
+ prefs_.AddPrefObserver(name_, &observer_);
+ SetExpectNoNotification();
+ prefs_.Set(name_, *default_value);
+ Mock::VerifyAndClearExpectations(&observer_);
+
+ scoped_ptr<Value> new_value(Value::CreateStringValue(value_));
+ SetExpectPrefChanged();
+ prefs_.Set(name_, *new_value);
+ EXPECT_EQ(value_, prefs_.GetString(name_));
+
+ prefs_.RemovePrefObserver(name_, &observer_);
+}
+
+TEST_F(PrefServiceSetValueTest, SetDictionaryValue) {
+ prefs_.RegisterDictionaryPref(name_);
+ prefs_.AddPrefObserver(name_, &observer_);
+
+ SetExpectNoNotification();
+ prefs_.Set(name_, *null_value_);
+ Mock::VerifyAndClearExpectations(&observer_);
+
+ DictionaryValue new_value;
+ new_value.SetString(name_, value_);
+ SetExpectPrefChanged();
+ prefs_.Set(name_, new_value);
+ Mock::VerifyAndClearExpectations(&observer_);
+ DictionaryValue* dict = prefs_.GetMutableDictionary(name_);
+ EXPECT_EQ(1U, dict->size());
+ std::wstring out_value;
+ dict->GetString(name_, &out_value);
+ EXPECT_EQ(value_, out_value);
+
+ SetExpectNoNotification();
+ prefs_.Set(name_, new_value);
+ Mock::VerifyAndClearExpectations(&observer_);
+
+ SetExpectPrefChanged();
+ prefs_.Set(name_, *null_value_);
+ Mock::VerifyAndClearExpectations(&observer_);
+ dict = prefs_.GetMutableDictionary(name_);
+ EXPECT_EQ(0U, dict->size());
+
+ prefs_.RemovePrefObserver(name_, &observer_);
+}
+
+TEST_F(PrefServiceSetValueTest, SetListValue) {
+ prefs_.RegisterListPref(name_);
+ prefs_.AddPrefObserver(name_, &observer_);
+
+ SetExpectNoNotification();
+ prefs_.Set(name_, *null_value_);
+ Mock::VerifyAndClearExpectations(&observer_);
+
+ ListValue new_value;
+ new_value.Append(Value::CreateStringValue(value_));
+ SetExpectPrefChanged();
+ prefs_.Set(name_, new_value);
+ Mock::VerifyAndClearExpectations(&observer_);
+ ListValue* list = prefs_.GetMutableList(name_);
+ ASSERT_EQ(1U, list->GetSize());
+ std::wstring out_value;
+ list->GetString(0, &out_value);
+ EXPECT_EQ(value_, out_value);
+
+ SetExpectNoNotification();
+ prefs_.Set(name_, new_value);
+ Mock::VerifyAndClearExpectations(&observer_);
+
+ SetExpectPrefChanged();
+ prefs_.Set(name_, *null_value_);
+ Mock::VerifyAndClearExpectations(&observer_);
+ list = prefs_.GetMutableList(name_);
+ EXPECT_EQ(0U, list->GetSize());
+
+ prefs_.RemovePrefObserver(name_, &observer_);
+}