summaryrefslogtreecommitdiffstats
path: root/chrome/browser/prefs/pref_set_observer_unittest.cc
diff options
context:
space:
mode:
authorevan@chromium.org <evan@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-08-26 00:22:02 +0000
committerevan@chromium.org <evan@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-08-26 00:22:02 +0000
commit37858e5c2f58f4b46117c65df2ab3da8a7b2e6e2 (patch)
treef3acb53adbd2d0ffe5e113d6c057fdee9bcc6dcd /chrome/browser/prefs/pref_set_observer_unittest.cc
parentfeecbf07dbc4b4c94dceb5e0043889126d213f6e (diff)
downloadchromium_src-37858e5c2f58f4b46117c65df2ab3da8a7b2e6e2.zip
chromium_src-37858e5c2f58f4b46117c65df2ab3da8a7b2e6e2.tar.gz
chromium_src-37858e5c2f58f4b46117c65df2ab3da8a7b2e6e2.tar.bz2
Move prefs-related files under chrome/browser/ into a prefs/ subdir.
Rename includes, resort header include order in places where the rename changed the order. BUG=50548 TEST=compiles Review URL: http://codereview.chromium.org/3203008 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@57434 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/prefs/pref_set_observer_unittest.cc')
-rw-r--r--chrome/browser/prefs/pref_set_observer_unittest.cc89
1 files changed, 89 insertions, 0 deletions
diff --git a/chrome/browser/prefs/pref_set_observer_unittest.cc b/chrome/browser/prefs/pref_set_observer_unittest.cc
new file mode 100644
index 0000000..f77bb6c
--- /dev/null
+++ b/chrome/browser/prefs/pref_set_observer_unittest.cc
@@ -0,0 +1,89 @@
+// Copyright (c) 2010 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 "chrome/browser/prefs/pref_set_observer.h"
+#include "chrome/common/notification_details.h"
+#include "chrome/common/notification_observer_mock.h"
+#include "chrome/common/notification_source.h"
+#include "chrome/common/pref_names.h"
+#include "chrome/test/testing_pref_service.h"
+#include "testing/gmock/include/gmock/gmock.h"
+#include "testing/gtest/include/gtest/gtest.h"
+
+// Unit tests for PrefSetObserver.
+class PrefSetObserverTest : public testing::Test {
+ public:
+ virtual void SetUp() {
+ pref_service_.reset(new TestingPrefService);
+ pref_service_->RegisterStringPref(prefs::kHomePage, "http://google.com");
+ pref_service_->RegisterBooleanPref(prefs::kHomePageIsNewTabPage, false);
+ pref_service_->RegisterStringPref(prefs::kApplicationLocale, "");
+ }
+
+ PrefSetObserver* CreatePrefSetObserver(NotificationObserver* observer) {
+ PrefSetObserver* pref_set =
+ new PrefSetObserver(pref_service_.get(), observer);
+ pref_set->AddPref(prefs::kHomePage);
+ pref_set->AddPref(prefs::kHomePageIsNewTabPage);
+ return pref_set;
+ }
+
+ scoped_ptr<TestingPrefService> pref_service_;
+};
+
+TEST_F(PrefSetObserverTest, IsObserved) {
+ scoped_ptr<PrefSetObserver> pref_set(CreatePrefSetObserver(NULL));
+ EXPECT_TRUE(pref_set->IsObserved(prefs::kHomePage));
+ EXPECT_TRUE(pref_set->IsObserved(prefs::kHomePageIsNewTabPage));
+ EXPECT_FALSE(pref_set->IsObserved(prefs::kApplicationLocale));
+}
+
+TEST_F(PrefSetObserverTest, IsManaged) {
+ scoped_ptr<PrefSetObserver> pref_set(CreatePrefSetObserver(NULL));
+ EXPECT_FALSE(pref_set->IsManaged());
+ pref_service_->SetManagedPref(prefs::kHomePage,
+ Value::CreateStringValue("http://crbug.com"));
+ EXPECT_TRUE(pref_set->IsManaged());
+ pref_service_->SetManagedPref(prefs::kHomePageIsNewTabPage,
+ Value::CreateBooleanValue(true));
+ EXPECT_TRUE(pref_set->IsManaged());
+ pref_service_->RemoveManagedPref(prefs::kHomePage);
+ EXPECT_TRUE(pref_set->IsManaged());
+ pref_service_->RemoveManagedPref(prefs::kHomePageIsNewTabPage);
+ EXPECT_FALSE(pref_set->IsManaged());
+}
+
+MATCHER_P(PrefNameDetails, name, "details references named preference") {
+ std::string* pstr = reinterpret_cast<const Details<std::string>&>(arg).ptr();
+ return pstr && *pstr == name;
+}
+
+TEST_F(PrefSetObserverTest, Observe) {
+ using testing::_;
+ using testing::Mock;
+
+ NotificationObserverMock observer;
+ scoped_ptr<PrefSetObserver> pref_set(CreatePrefSetObserver(&observer));
+
+ EXPECT_CALL(observer,
+ Observe(NotificationType(NotificationType::PREF_CHANGED),
+ Source<PrefService>(pref_service_.get()),
+ PrefNameDetails(prefs::kHomePage)));
+ pref_service_->SetUserPref(prefs::kHomePage,
+ Value::CreateStringValue("http://crbug.com"));
+ Mock::VerifyAndClearExpectations(&observer);
+
+ EXPECT_CALL(observer,
+ Observe(NotificationType(NotificationType::PREF_CHANGED),
+ Source<PrefService>(pref_service_.get()),
+ PrefNameDetails(prefs::kHomePageIsNewTabPage)));
+ pref_service_->SetUserPref(prefs::kHomePageIsNewTabPage,
+ Value::CreateBooleanValue(true));
+ Mock::VerifyAndClearExpectations(&observer);
+
+ EXPECT_CALL(observer, Observe(_, _, _)).Times(0);
+ pref_service_->SetUserPref(prefs::kApplicationLocale,
+ Value::CreateStringValue("en_US.utf8"));
+ Mock::VerifyAndClearExpectations(&observer);
+}