summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--chrome/browser/dom_ui/new_tab_ui_uitest.cc9
-rw-r--r--chrome/browser/dom_ui/shown_sections_handler_unittest.cc13
-rw-r--r--chrome/browser/managed_prefs_banner_base_unittest.cc28
-rw-r--r--chrome/browser/pref_member_unittest.cc13
-rw-r--r--chrome/browser/pref_service.cc42
-rw-r--r--chrome/browser/pref_service.h11
-rw-r--r--chrome/browser/pref_service_unittest.cc26
-rw-r--r--chrome/browser/pref_value_store.cc20
-rw-r--r--chrome/browser/pref_value_store.h12
-rw-r--r--chrome/browser/sync/glue/preference_change_processor.cc17
-rw-r--r--chrome/browser/sync/glue/preference_model_associator.cc12
-rw-r--r--chrome/browser/sync/profile_sync_service_preference_unittest.cc34
-rw-r--r--chrome/browser/tab_contents/web_contents_unittest.cc48
-rw-r--r--chrome/chrome_tests.gypi2
-rw-r--r--chrome/test/data/profiles/chrome_prefs/History0
-rw-r--r--chrome/test/data/profiles/chrome_prefs/Preferences20
-rw-r--r--chrome/test/testing_pref_service.cc60
-rw-r--r--chrome/test/testing_pref_service.h51
-rw-r--r--chrome/test/testing_profile.h10
19 files changed, 270 insertions, 158 deletions
diff --git a/chrome/browser/dom_ui/new_tab_ui_uitest.cc b/chrome/browser/dom_ui/new_tab_ui_uitest.cc
index 1265cbe..e2a33688 100644
--- a/chrome/browser/dom_ui/new_tab_ui_uitest.cc
+++ b/chrome/browser/dom_ui/new_tab_ui_uitest.cc
@@ -1,4 +1,4 @@
-// Copyright (c) 2009 The Chromium Authors. All rights reserved.
+// 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.
@@ -8,13 +8,13 @@
#include "chrome/app/chrome_dll_resource.h"
#include "chrome/browser/chrome_thread.h"
#include "chrome/browser/dom_ui/new_tab_ui.h"
-#include "chrome/browser/pref_service.h"
#include "chrome/browser/pref_value_store.h"
#include "chrome/common/json_pref_store.h"
#include "chrome/common/pref_names.h"
#include "chrome/test/automation/browser_proxy.h"
#include "chrome/test/automation/tab_proxy.h"
#include "chrome/test/automation/window_proxy.h"
+#include "chrome/test/testing_pref_service.h"
class NewTabUITest : public UITest {
public:
@@ -75,9 +75,7 @@ TEST_F(NewTabUITest, FLAKY_ChromeInternalLoadsNTP) {
TEST_F(NewTabUITest, UpdateUserPrefsVersion) {
// PrefService with JSON user-pref file only, no enforced or advised prefs.
- FilePath user_prefs = FilePath();
- scoped_ptr<PrefService> prefs(
- PrefService::CreateUserPrefService(user_prefs));
+ scoped_ptr<PrefService> prefs(new TestingPrefService);
// Does the migration
NewTabUI::RegisterUserPrefs(prefs.get());
@@ -164,4 +162,3 @@ TEST_F(NewTabUITest, HomePageLink) {
&is_home_page));
ASSERT_TRUE(is_home_page);
}
-
diff --git a/chrome/browser/dom_ui/shown_sections_handler_unittest.cc b/chrome/browser/dom_ui/shown_sections_handler_unittest.cc
index 42fa47a..934c55a 100644
--- a/chrome/browser/dom_ui/shown_sections_handler_unittest.cc
+++ b/chrome/browser/dom_ui/shown_sections_handler_unittest.cc
@@ -1,4 +1,4 @@
-// Copyright (c) 2009 The Chromium Authors. All rights reserved.
+// 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.
@@ -7,20 +7,17 @@
#include "base/file_path.h"
#include "base/scoped_ptr.h"
#include "chrome/browser/chrome_thread.h"
-#include "chrome/browser/pref_service.h"
#include "chrome/browser/pref_value_store.h"
#include "chrome/common/json_pref_store.h"
#include "chrome/common/pref_names.h"
+#include "chrome/test/testing_pref_service.h"
#include "testing/gtest/include/gtest/gtest.h"
class ShownSectionsHandlerTest : public testing::Test {
};
TEST_F(ShownSectionsHandlerTest, MigrateUserPrefs) {
- // Create a preference value that has only user defined
- // preference values.
- FilePath user_prefs = FilePath();
- scoped_ptr<PrefService> pref(PrefService::CreateUserPrefService(user_prefs));
+ scoped_ptr<PrefService> pref(new TestingPrefService);
// Set an *old* value
pref->RegisterIntegerPref(prefs::kNTPShownSections, 0);
@@ -38,8 +35,7 @@ TEST_F(ShownSectionsHandlerTest, MigrateUserPrefs) {
}
TEST_F(ShownSectionsHandlerTest, MigrateUserPrefs1To2) {
- FilePath user_prefs = FilePath();
- scoped_ptr<PrefService> pref(PrefService::CreateUserPrefService(user_prefs));
+ scoped_ptr<PrefService> pref(new TestingPrefService);
// Set an *old* value
pref->RegisterIntegerPref(prefs::kNTPShownSections, 0);
@@ -52,4 +48,3 @@ TEST_F(ShownSectionsHandlerTest, MigrateUserPrefs1To2) {
EXPECT_TRUE(shown_sections & THUMB);
EXPECT_FALSE(shown_sections & LIST);
}
-
diff --git a/chrome/browser/managed_prefs_banner_base_unittest.cc b/chrome/browser/managed_prefs_banner_base_unittest.cc
index 7955ebf..60bad07 100644
--- a/chrome/browser/managed_prefs_banner_base_unittest.cc
+++ b/chrome/browser/managed_prefs_banner_base_unittest.cc
@@ -4,8 +4,8 @@
#include "chrome/browser/dummy_pref_store.h"
#include "chrome/browser/managed_prefs_banner_base.h"
-#include "chrome/browser/pref_service.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"
@@ -20,37 +20,25 @@ const wchar_t* kDummyPref = L"dummy";
class ManagedPrefsBannerBaseTest : public testing::Test {
public:
virtual void SetUp() {
- managed_prefs_ = new DummyPrefStore;
- extension_prefs_ = new DummyPrefStore;
- command_line_prefs_ = new DummyPrefStore;
- user_prefs_ = new DummyPrefStore;
- default_prefs_ = new DummyPrefStore;
- pref_service_.reset(new PrefService(new PrefValueStore(managed_prefs_,
- extension_prefs_,
- command_line_prefs_,
- user_prefs_,
- default_prefs_)));
+ pref_service_.reset(new TestingPrefService);
pref_service_->RegisterStringPref(prefs::kHomePage, "http://google.com");
pref_service_->RegisterBooleanPref(prefs::kHomePageIsNewTabPage, false);
pref_service_->RegisterBooleanPref(kDummyPref, false);
}
- scoped_ptr<PrefService> pref_service_;
- DummyPrefStore* managed_prefs_;
- DummyPrefStore* extension_prefs_;
- DummyPrefStore* command_line_prefs_;
- DummyPrefStore* user_prefs_;
- DummyPrefStore* default_prefs_;
+ scoped_ptr<TestingPrefService> pref_service_;
};
TEST_F(ManagedPrefsBannerBaseTest, VisibilityTest) {
ManagedPrefsBannerBase banner(pref_service_.get(), OPTIONS_PAGE_GENERAL);
EXPECT_FALSE(banner.DetermineVisibility());
- managed_prefs_->prefs()->SetBoolean(kDummyPref, true);
+ pref_service_->SetManagedPref(kDummyPref, Value::CreateBooleanValue(true));
EXPECT_FALSE(banner.DetermineVisibility());
- user_prefs_->prefs()->SetString(prefs::kHomePage, "http://foo.com");
+ pref_service_->SetUserPref(prefs::kHomePage,
+ Value::CreateStringValue("http://foo.com"));
EXPECT_FALSE(banner.DetermineVisibility());
- managed_prefs_->prefs()->SetString(prefs::kHomePage, "http://bar.com");
+ pref_service_->SetManagedPref(prefs::kHomePage,
+ Value::CreateStringValue("http://bar.com"));
EXPECT_TRUE(banner.DetermineVisibility());
}
diff --git a/chrome/browser/pref_member_unittest.cc b/chrome/browser/pref_member_unittest.cc
index 98d11a7..b0379d6 100644
--- a/chrome/browser/pref_member_unittest.cc
+++ b/chrome/browser/pref_member_unittest.cc
@@ -1,13 +1,13 @@
-// Copyright (c) 2006-2008 The Chromium Authors. All rights reserved.
+// 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 "base/file_path.h"
#include "chrome/browser/dummy_pref_store.h"
#include "chrome/browser/pref_member.h"
-#include "chrome/browser/pref_service.h"
#include "chrome/browser/pref_value_store.h"
#include "chrome/common/notification_service.h"
+#include "chrome/test/testing_pref_service.h"
#include "testing/gtest/include/gtest/gtest.h"
namespace {
@@ -53,8 +53,7 @@ class PrefMemberTestClass : public NotificationObserver {
} // anonymous namespace
TEST(PrefMemberTest, BasicGetAndSet) {
- PrefService prefs(new PrefValueStore(NULL, NULL, NULL, new DummyPrefStore(),
- NULL));
+ TestingPrefService prefs;
RegisterTestPrefs(&prefs);
// Test bool
@@ -144,8 +143,7 @@ TEST(PrefMemberTest, BasicGetAndSet) {
TEST(PrefMemberTest, TwoPrefs) {
// Make sure two RealPrefMembers stay in sync.
- PrefService prefs(new PrefValueStore(NULL, NULL, NULL, new DummyPrefStore(),
- NULL));
+ TestingPrefService prefs;
RegisterTestPrefs(&prefs);
RealPrefMember pref1;
@@ -165,8 +163,7 @@ TEST(PrefMemberTest, TwoPrefs) {
}
TEST(PrefMemberTest, Observer) {
- PrefService prefs(new PrefValueStore(NULL, NULL, NULL, new DummyPrefStore(),
- NULL));
+ TestingPrefService prefs;
RegisterTestPrefs(&prefs);
PrefMemberTestClass test_obj(&prefs);
diff --git a/chrome/browser/pref_service.cc b/chrome/browser/pref_service.cc
index 9db99bc..f441520 100644
--- a/chrome/browser/pref_service.cc
+++ b/chrome/browser/pref_service.cc
@@ -421,6 +421,25 @@ void PrefService::FireObserversIfChanged(const wchar_t* path,
FireObservers(path);
}
+void PrefService::FireObservers(const wchar_t* path) {
+ DCHECK(CalledOnValidThread());
+
+ // Convert path to a std::wstring because the Details constructor requires a
+ // class.
+ std::wstring path_str(path);
+ PrefObserverMap::iterator observer_iterator = pref_observers_.find(path_str);
+ if (observer_iterator == pref_observers_.end())
+ return;
+
+ NotificationObserverList::Iterator it(*(observer_iterator->second));
+ NotificationObserver* observer;
+ while ((observer = it.GetNext()) != NULL) {
+ observer->Observe(NotificationType::PREF_CHANGED,
+ Source<PrefService>(this),
+ Details<std::wstring>(&path_str));
+ }
+}
+
bool PrefService::PrefIsChanged(const wchar_t* path,
const Value* old_value) {
Value* new_value = NULL;
@@ -791,25 +810,6 @@ Value* PrefService::GetPrefCopy(const wchar_t* path) {
return pref->GetValue()->DeepCopy();
}
-void PrefService::FireObservers(const wchar_t* path) {
- DCHECK(CalledOnValidThread());
-
- // Convert path to a std::wstring because the Details constructor requires a
- // class.
- std::wstring path_str(path);
- PrefObserverMap::iterator observer_iterator = pref_observers_.find(path_str);
- if (observer_iterator == pref_observers_.end())
- return;
-
- NotificationObserverList::Iterator it(*(observer_iterator->second));
- NotificationObserver* observer;
- while ((observer = it.GetNext()) != NULL) {
- observer->Observe(NotificationType::PREF_CHANGED,
- Source<PrefService>(this),
- Details<std::wstring>(&path_str));
- }
-}
-
///////////////////////////////////////////////////////////////////////////////
// PrefService::Preference
@@ -872,3 +872,7 @@ bool PrefService::Preference::IsExtensionControlled() const {
bool PrefService::Preference::IsUserControlled() const {
return pref_value_store_->PrefValueFromUserStore(name_.c_str());
}
+
+bool PrefService::Preference::IsUserModifiable() const {
+ return pref_value_store_->PrefValueUserModifiable(name_.c_str());
+}
diff --git a/chrome/browser/pref_service.h b/chrome/browser/pref_service.h
index 255214a..5c105b6f 100644
--- a/chrome/browser/pref_service.h
+++ b/chrome/browser/pref_service.h
@@ -73,6 +73,11 @@ class PrefService : public NonThreadSafe {
// user setting, and not by any higher-priority source.
bool IsUserControlled() const;
+ // Returns true if the user can change the Preference value, which is the
+ // case if no higher-priority source than the user store controls the
+ // Preference.
+ bool IsUserModifiable() const;
+
private:
friend class PrefService;
@@ -221,6 +226,9 @@ class PrefService : public NonThreadSafe {
bool read_only() const { return pref_value_store_->ReadOnly(); }
protected:
+ // For the given pref_name, fire any observer of the pref.
+ void FireObservers(const wchar_t* pref_name);
+
// This should only be accessed by subclasses for unit-testing.
bool PrefIsChanged(const wchar_t* path, const Value* old_value);
@@ -233,9 +241,6 @@ class PrefService : public NonThreadSafe {
// deleting the returned object.
Value* GetPrefCopy(const wchar_t* pref_name);
- // For the given pref_name, fire any observer of the pref.
- void FireObservers(const wchar_t* pref_name);
-
// Load from disk. Returns a non-zero error code on failure.
PrefStore::PrefReadError LoadPersistentPrefs();
diff --git a/chrome/browser/pref_service_unittest.cc b/chrome/browser/pref_service_unittest.cc
index 45b840d..967c0cb 100644
--- a/chrome/browser/pref_service_unittest.cc
+++ b/chrome/browser/pref_service_unittest.cc
@@ -1,4 +1,4 @@
-// Copyright (c) 2009 The Chromium Authors. All rights reserved.
+// 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.
@@ -8,13 +8,13 @@
#include "base/scoped_ptr.h"
#include "base/values.h"
#include "chrome/browser/dummy_pref_store.h"
-#include "chrome/browser/pref_service.h"
#include "chrome/browser/pref_value_store.h"
#include "chrome/common/chrome_paths.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 "chrome/test/testing_pref_service.h"
#include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h"
@@ -64,8 +64,7 @@ class TestPrefObserver : public NotificationObserver {
// TODO(port): port this test to POSIX.
#if defined(OS_WIN)
TEST(PrefServiceTest, LocalizedPrefs) {
- PrefService prefs(new PrefValueStore(NULL, NULL, NULL, new DummyPrefStore(),
- NULL));
+ TestingPrefService prefs;
const wchar_t kBoolean[] = L"boolean";
const wchar_t kInteger[] = L"integer";
const wchar_t kString[] = L"string";
@@ -88,8 +87,7 @@ TEST(PrefServiceTest, LocalizedPrefs) {
#endif
TEST(PrefServiceTest, NoObserverFire) {
- PrefService prefs(new PrefValueStore(NULL, NULL, NULL, new DummyPrefStore(),
- NULL));
+ TestingPrefService prefs;
const wchar_t pref_name[] = L"homepage";
prefs.RegisterStringPref(pref_name, "");
@@ -124,8 +122,7 @@ TEST(PrefServiceTest, NoObserverFire) {
}
TEST(PrefServiceTest, HasPrefPath) {
- PrefService prefs(new PrefValueStore(NULL, NULL, NULL, new DummyPrefStore(),
- NULL));
+ TestingPrefService prefs;
const wchar_t path[] = L"fake.path";
@@ -145,11 +142,8 @@ TEST(PrefServiceTest, HasPrefPath) {
TEST(PrefServiceTest, Observers) {
const wchar_t pref_name[] = L"homepage";
- DictionaryValue* dict = new DictionaryValue();
- dict->SetString(pref_name, std::string("http://www.cnn.com"));
- DummyPrefStore* pref_store = new DummyPrefStore();
- pref_store->set_prefs(dict);
- PrefService prefs(new PrefValueStore(NULL, NULL, NULL, pref_store, NULL));
+ TestingPrefService prefs;
+ prefs.SetUserPref(pref_name, Value::CreateStringValue(L"http://www.cnn.com"));
prefs.RegisterStringPref(pref_name, "");
const std::string new_pref_value("http://www.google.com/");
@@ -190,9 +184,7 @@ class PrefServiceSetValueTest : public testing::Test {
static const char value_[];
PrefServiceSetValueTest()
- : prefs_(new PrefValueStore(NULL, NULL, NULL, new DummyPrefStore(),
- NULL)),
- name_string_(name_),
+ : name_string_(name_),
null_value_(Value::CreateNullValue()) {}
void SetExpectNoNotification() {
@@ -206,7 +198,7 @@ class PrefServiceSetValueTest : public testing::Test {
Pointee(name_string_))));
}
- PrefService prefs_;
+ TestingPrefService prefs_;
std::wstring name_string_;
scoped_ptr<Value> null_value_;
NotificationObserverMock observer_;
diff --git a/chrome/browser/pref_value_store.cc b/chrome/browser/pref_value_store.cc
index a5fae75..0988b9c 100644
--- a/chrome/browser/pref_value_store.cc
+++ b/chrome/browser/pref_value_store.cc
@@ -100,11 +100,16 @@ bool PrefValueStore::PrefValueInUserStore(const wchar_t* name) {
}
bool PrefValueStore::PrefValueFromExtensionStore(const wchar_t* name) {
- return PrefValueFromStore(name, EXTENSION);
+ return ControllingPrefStoreForPref(name) == EXTENSION;
}
bool PrefValueStore::PrefValueFromUserStore(const wchar_t* name) {
- return PrefValueFromStore(name, USER);
+ return ControllingPrefStoreForPref(name) == USER;
+}
+
+bool PrefValueStore::PrefValueUserModifiable(const wchar_t* name) {
+ PrefStoreType effective_store = ControllingPrefStoreForPref(name);
+ return effective_store >= USER || effective_store == INVALID;
}
bool PrefValueStore::PrefValueInStore(const wchar_t* name, PrefStoreType type) {
@@ -116,12 +121,11 @@ bool PrefValueStore::PrefValueInStore(const wchar_t* name, PrefStoreType type) {
return pref_stores_[type]->prefs()->Get(name, &tmp_value);
}
-bool PrefValueStore::PrefValueFromStore(const wchar_t* name,
- PrefStoreType type) {
- // No need to look in PrefStores with lower priority than the one we want.
- for (int i = 0; i <= type; ++i) {
+PrefValueStore::PrefStoreType PrefValueStore::ControllingPrefStoreForPref(
+ const wchar_t* name) {
+ for (int i = 0; i <= PREF_STORE_TYPE_MAX; ++i) {
if (PrefValueInStore(name, static_cast<PrefStoreType>(i)))
- return (i == type);
+ return static_cast<PrefStoreType>(i);
}
- return false;
+ return INVALID;
}
diff --git a/chrome/browser/pref_value_store.h b/chrome/browser/pref_value_store.h
index 885b7c0..9dcce64 100644
--- a/chrome/browser/pref_value_store.h
+++ b/chrome/browser/pref_value_store.h
@@ -96,9 +96,16 @@ class PrefValueStore {
bool PrefValueFromExtensionStore(const wchar_t* name);
bool PrefValueFromUserStore(const wchar_t* name);
+ // Check whether a Preference value is modifiable by the user, i.e. whether
+ // there is no higher-priority source controlling it.
+ bool PrefValueUserModifiable(const wchar_t* name);
+
private:
// PrefStores must be listed here in order from highest to lowest priority.
enum PrefStoreType {
+ // Not associated with an actual PrefStore but used as invalid marker, e.g.
+ // as return value.
+ INVALID = -1,
MANAGED = 0,
EXTENSION,
COMMAND_LINE,
@@ -111,7 +118,10 @@ class PrefValueStore {
bool PrefValueInStore(const wchar_t* name, PrefStoreType type);
- bool PrefValueFromStore(const wchar_t* name, PrefStoreType type);
+ // Returns the pref store type identifying the source that controls the
+ // Preference identified by |name|. If none of the sources has a value,
+ // INVALID is returned.
+ PrefStoreType ControllingPrefStoreForPref(const wchar_t* name);
DISALLOW_COPY_AND_ASSIGN(PrefValueStore);
};
diff --git a/chrome/browser/sync/glue/preference_change_processor.cc b/chrome/browser/sync/glue/preference_change_processor.cc
index 0958bec..2b8a6fe 100644
--- a/chrome/browser/sync/glue/preference_change_processor.cc
+++ b/chrome/browser/sync/glue/preference_change_processor.cc
@@ -1,4 +1,4 @@
-// Copyright (c) 2006-2009 The Chromium Authors. All rights reserved.
+// 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.
@@ -48,12 +48,13 @@ void PreferenceChangeProcessor::Observe(NotificationType type,
pref_service_->FindPreference((*name).c_str());
DCHECK(preference);
- // TODO(mnissler): Detect preference->IsManaged() state changes here and call
- // into PreferenceModelAssociator to associate/disassociate sync nodes when
- // the state changes.
+ // TODO(mnissler): Detect preference->IsUserControlled() state changes here
+ // and call into PreferenceModelAssociator to associate/disassociate sync
+ // nodes when the state changes.
- // Do not pollute sync data with values coming from policy.
- if (preference->IsManaged())
+ // Do not pollute sync data with values coming from policy, extensions or the
+ // commandline.
+ if (!preference->IsUserModifiable())
return;
sync_api::WriteTransaction trans(share_handle());
@@ -141,11 +142,11 @@ void PreferenceChangeProcessor::ApplyChangesFromSyncModel(
if (model_associator_->synced_preferences().count(pref_name) == 0)
continue;
- // Don't try to overwrite preferences controlled by policy.
+ // Don't try to overwrite preferences not controllable by the user.
const PrefService::Preference* pref =
pref_service_->FindPreference(pref_name);
DCHECK(pref);
- if (pref->IsManaged())
+ if (!pref->IsUserModifiable())
continue;
if (sync_api::SyncManager::ChangeRecord::ACTION_DELETE ==
diff --git a/chrome/browser/sync/glue/preference_model_associator.cc b/chrome/browser/sync/glue/preference_model_associator.cc
index 89eb674..5dad397 100644
--- a/chrome/browser/sync/glue/preference_model_associator.cc
+++ b/chrome/browser/sync/glue/preference_model_associator.cc
@@ -73,11 +73,12 @@ bool PreferenceModelAssociator::AssociateModels() {
sync_api::WriteNode node(&trans);
if (node.InitByClientTagLookup(syncable::PREFERENCES, tag)) {
+ // The server has a value for the preference.
const sync_pb::PreferenceSpecifics& preference(
node.GetPreferenceSpecifics());
DCHECK_EQ(tag, preference.name());
- if (!pref->IsManaged()) {
+ if (pref->IsUserModifiable()) {
scoped_ptr<Value> value(
reader.JsonToValue(preference.value(), false, false));
std::wstring pref_name = UTF8ToWide(preference.name());
@@ -104,12 +105,9 @@ bool PreferenceModelAssociator::AssociateModels() {
return false;
}
Associate(pref, node.GetId());
- } else if (!pref->IsManaged()) {
- // If there is no server value for this preference and it is
- // currently its default value, don't create a new server node.
- if (pref->IsDefaultValue())
- continue;
-
+ } else if (pref->IsUserControlled()) {
+ // The server doesn't have a value, but we have a user-controlled value,
+ // so we push it to the server.
sync_api::WriteNode write_node(&trans);
if (!write_node.InitUniqueByCreation(syncable::PREFERENCES, root, tag)) {
LOG(ERROR) << "Failed to create preference sync node.";
diff --git a/chrome/browser/sync/profile_sync_service_preference_unittest.cc b/chrome/browser/sync/profile_sync_service_preference_unittest.cc
index 6556c83..94ae735 100644
--- a/chrome/browser/sync/profile_sync_service_preference_unittest.cc
+++ b/chrome/browser/sync/profile_sync_service_preference_unittest.cc
@@ -173,7 +173,7 @@ class ProfileSyncServicePreferenceTest
friend class AddPreferenceEntriesTask;
scoped_ptr<TestingProfile> profile_;
- PrefService* prefs_;
+ TestingPrefService* prefs_;
PreferenceModelAssociator* model_associator_;
PreferenceChangeProcessor* change_processor_;
@@ -411,3 +411,35 @@ TEST_F(ProfileSyncServicePreferenceTest, UpdatedSyncNodeUnknownPreference) {
// Nothing interesting happens on the client when it gets an update
// of an unknown preference. We just should not crash.
}
+
+TEST_F(ProfileSyncServicePreferenceTest, ManagedPreferences) {
+ // Make the homepage preference managed.
+ scoped_ptr<Value> managed_value(
+ Value::CreateStringValue(L"http://example.com"));
+ prefs_->SetManagedPref(prefs::kHomePage, managed_value->DeepCopy());
+
+ CreateRootTask task(this, syncable::PREFERENCES);
+ ASSERT_TRUE(StartSyncService(&task, false));
+ ASSERT_TRUE(task.success());
+
+ // Changing the homepage preference should not sync anything.
+ scoped_ptr<Value> user_value(
+ Value::CreateStringValue(L"http://chromium..com"));
+ prefs_->SetUserPref(prefs::kHomePage, user_value->DeepCopy());
+ EXPECT_EQ(NULL, GetSyncedValue(prefs::kHomePage));
+
+ // An incoming sync transaction shouldn't change the user value.
+ scoped_ptr<Value> sync_value(
+ Value::CreateStringValue(L"http://crbug.com"));
+ int64 node_id = SetSyncedValue(prefs::kHomePage, *sync_value);
+ ASSERT_NE(node_id, sync_api::kInvalidId);
+ scoped_ptr<SyncManager::ChangeRecord> record(new SyncManager::ChangeRecord);
+ record->action = SyncManager::ChangeRecord::ACTION_UPDATE;
+ record->id = node_id;
+ {
+ sync_api::WriteTransaction trans(backend()->GetUserShareHandle());
+ change_processor_->ApplyChangesFromSyncModel(&trans, record.get(), 1);
+ }
+ EXPECT_TRUE(managed_value->Equals(prefs_->GetManagedPref(prefs::kHomePage)));
+ EXPECT_TRUE(user_value->Equals(prefs_->GetUserPref(prefs::kHomePage)));
+}
diff --git a/chrome/browser/tab_contents/web_contents_unittest.cc b/chrome/browser/tab_contents/web_contents_unittest.cc
index 1ece79f..cb3d4d4 100644
--- a/chrome/browser/tab_contents/web_contents_unittest.cc
+++ b/chrome/browser/tab_contents/web_contents_unittest.cc
@@ -15,6 +15,7 @@
#include "chrome/browser/tab_contents/navigation_entry.h"
#include "chrome/browser/tab_contents/test_tab_contents.h"
#include "chrome/common/chrome_paths.h"
+#include "chrome/common/pref_names.h"
#include "chrome/common/render_messages.h"
#include "chrome/common/url_constants.h"
#include "chrome/test/testing_profile.h"
@@ -40,30 +41,6 @@ static void InitNavigateParams(ViewHostMsg_FrameNavigate_Params* params,
params->is_post = false;
}
-// Subclass the TestingProfile so that it can return certain services we need.
-class TabContentsTestingProfile : public TestingProfile {
- public:
- TabContentsTestingProfile() : TestingProfile() {
- CreateBookmarkModel(false);
- }
-
- virtual PrefService* GetPrefs() {
- if (!prefs_.get()) {
- FilePath source_path;
- PathService::Get(chrome::DIR_TEST_DATA, &source_path);
- source_path = source_path.AppendASCII("profiles")
- .AppendASCII("chrome_prefs").AppendASCII("Preferences");
-
- // Create a preference service that only contains user defined
- // preference values.
- prefs_.reset(PrefService::CreateUserPrefService(source_path));
- Profile::RegisterUserPrefs(prefs_.get());
- browser::RegisterAllPrefs(prefs_.get(), prefs_.get());
- }
- return prefs_.get();
- }
-};
-
class TestInterstitialPage : public InterstitialPage {
public:
enum InterstitialState {
@@ -206,7 +183,28 @@ class TabContentsTest : public RenderViewHostTestHarness {
// Supply our own profile so we use the correct profile data. The test harness
// is not supposed to overwrite a profile if it's already created.
virtual void SetUp() {
- profile_.reset(new TabContentsTestingProfile());
+ TestingProfile* profile = new TestingProfile();
+ profile->CreateBookmarkModel(false);
+ profile_.reset(profile);
+
+ // Set some (WebKit) user preferences.
+ TestingPrefService* pref_services = profile->GetPrefs();
+#if defined(TOOLKIT_USES_GTK)
+ pref_services->SetUserPref(prefs::kUsesSystemTheme,
+ Value::CreateBooleanValue(false));
+#endif
+ pref_services->SetUserPref(prefs::kDefaultCharset,
+ Value::CreateStringValue("utf8"));
+ pref_services->SetUserPref(prefs::kWebKitDefaultFontSize,
+ Value::CreateIntegerValue(20));
+ pref_services->SetUserPref(prefs::kWebKitTextAreasAreResizable,
+ Value::CreateBooleanValue(false));
+ pref_services->SetUserPref(prefs::kWebKitUsesUniversalDetector,
+ Value::CreateBooleanValue(true));
+ pref_services->SetUserPref(prefs::kWebKitStandardFontIsSerif,
+ Value::CreateBooleanValue(true));
+ pref_services->SetUserPref(L"webkit.webprefs.foo",
+ Value::CreateStringValue(L"bar"));
RenderViewHostTestHarness::SetUp();
}
diff --git a/chrome/chrome_tests.gypi b/chrome/chrome_tests.gypi
index bb9998c..7101011 100644
--- a/chrome/chrome_tests.gypi
+++ b/chrome/chrome_tests.gypi
@@ -116,6 +116,8 @@
'test/profile_mock.h',
'test/test_browser_window.h',
'test/test_location_bar.h',
+ 'test/testing_pref_service.cc',
+ 'test/testing_pref_service.h',
'test/testing_profile.cc',
'test/testing_profile.h',
'test/thread_observer_helper.h',
diff --git a/chrome/test/data/profiles/chrome_prefs/History b/chrome/test/data/profiles/chrome_prefs/History
deleted file mode 100644
index e69de29..0000000
--- a/chrome/test/data/profiles/chrome_prefs/History
+++ /dev/null
diff --git a/chrome/test/data/profiles/chrome_prefs/Preferences b/chrome/test/data/profiles/chrome_prefs/Preferences
deleted file mode 100644
index 4510e2f..0000000
--- a/chrome/test/data/profiles/chrome_prefs/Preferences
+++ /dev/null
@@ -1,20 +0,0 @@
-{
- "extensions": {
- "theme": {
- "use_system": false
- }
- },
- "intl": {
- "charset_default": "utf8"
- },
- "webkit": {
- "webprefs": {
- "default_font_size": 20,
- "text_areas_are_resizable": false,
- "uses_universal_detector": true,
-
- "foo": "bar",
- "standard_font_family": true
- }
- }
-}
diff --git a/chrome/test/testing_pref_service.cc b/chrome/test/testing_pref_service.cc
new file mode 100644
index 0000000..e6dde83
--- /dev/null
+++ b/chrome/test/testing_pref_service.cc
@@ -0,0 +1,60 @@
+// 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/test/testing_pref_service.h"
+
+#include "chrome/browser/dummy_pref_store.h"
+#include "chrome/browser/pref_value_store.h"
+
+TestingPrefService::TestingPrefService()
+ : PrefService(new PrefValueStore(
+ managed_prefs_ = new DummyPrefStore(),
+ NULL,
+ NULL,
+ user_prefs_ = new DummyPrefStore(),
+ NULL)) {
+}
+
+const Value* TestingPrefService::GetManagedPref(const wchar_t* path) {
+ return GetPref(managed_prefs_, path);
+}
+
+void TestingPrefService::SetManagedPref(const wchar_t* path, Value* value) {
+ SetPref(managed_prefs_, path, value);
+}
+
+void TestingPrefService::RemoveManagedPref(const wchar_t* path) {
+ RemovePref(managed_prefs_, path);
+}
+
+const Value* TestingPrefService::GetUserPref(const wchar_t* path) {
+ return GetPref(user_prefs_, path);
+}
+
+void TestingPrefService::SetUserPref(const wchar_t* path, Value* value) {
+ SetPref(user_prefs_, path, value);
+}
+
+void TestingPrefService::RemoveUserPref(const wchar_t* path) {
+ RemovePref(user_prefs_, path);
+}
+
+const Value* TestingPrefService::GetPref(PrefStore* pref_store,
+ const wchar_t* path) {
+ Value* result;
+ return pref_store->prefs()->Get(path, &result) ? result : NULL;
+}
+
+void TestingPrefService::SetPref(PrefStore* pref_store,
+ const wchar_t* path,
+ Value* value) {
+ pref_store->prefs()->Set(path, value);
+ FireObservers(path);
+}
+
+void TestingPrefService::RemovePref(PrefStore* pref_store,
+ const wchar_t* path) {
+ pref_store->prefs()->Remove(path, NULL);
+ FireObservers(path);
+}
diff --git a/chrome/test/testing_pref_service.h b/chrome/test/testing_pref_service.h
new file mode 100644
index 0000000..8155a84
--- /dev/null
+++ b/chrome/test/testing_pref_service.h
@@ -0,0 +1,51 @@
+// 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.
+
+#ifndef CHROME_TEST_TESTING_PREF_SERVICE_H_
+#define CHROME_TEST_TESTING_PREF_SERVICE_H_
+
+#include <chrome/browser/pref_service.h>
+
+// A PrefService subclass for testing. It operates totally in memory and
+// provides additional API for manipulating preferences at the different levels
+// (managed, extension, user) conveniently.
+class TestingPrefService : public PrefService {
+ public:
+ // Create an empty instance.
+ TestingPrefService();
+
+ // Read the value of a preference from the managed layer. Returns NULL if the
+ // preference is not defined at the managed layer.
+ const Value* GetManagedPref(const wchar_t* path);
+
+ // Set a preference on the managed layer and fire observers if the preference
+ // changed. Assumes ownership of |value|.
+ void SetManagedPref(const wchar_t* path, Value* value);
+
+ // Clear the preference on the managed layer and fire observers if the
+ // preference has been defined previously.
+ void RemoveManagedPref(const wchar_t* path);
+
+ // Similar to the above, but for user preferences.
+ const Value* GetUserPref(const wchar_t* path);
+ void SetUserPref(const wchar_t* path, Value* value);
+ void RemoveUserPref(const wchar_t* path);
+
+ private:
+ // Reads the value of the preference indicated by |path| from |pref_store|.
+ // Returns NULL if the preference was not found.
+ const Value* GetPref(PrefStore* pref_store, const wchar_t* path);
+
+ // Sets the value for |path| in |pref_store|.
+ void SetPref(PrefStore* pref_store, const wchar_t* path, Value* value);
+
+ // Removes the preference identified by |path| from |pref_store|.
+ void RemovePref(PrefStore* pref_store, const wchar_t* path);
+
+ // Pointers to the pref stores our value store uses.
+ PrefStore* managed_prefs_;
+ PrefStore* user_prefs_;
+};
+
+#endif // CHROME_TEST_TESTING_PREF_SERVICE_H_
diff --git a/chrome/test/testing_profile.h b/chrome/test/testing_profile.h
index 8421570..b23435e 100644
--- a/chrome/test/testing_profile.h
+++ b/chrome/test/testing_profile.h
@@ -27,6 +27,7 @@
#include "chrome/browser/search_engines/template_url_model.h"
#include "chrome/common/json_pref_store.h"
#include "chrome/common/net/url_request_context_getter.h"
+#include "chrome/test/testing_pref_service.h"
#include "net/base/cookie_monster.h"
class ProfileSyncService;
@@ -149,12 +150,9 @@ class TestingProfile : public Profile {
virtual PasswordStore* GetPasswordStore(ServiceAccessType access) {
return NULL;
}
- virtual PrefService* GetPrefs() {
+ virtual TestingPrefService* GetPrefs() {
if (!prefs_.get()) {
- FilePath prefs_filename =
- path_.Append(FILE_PATH_LITERAL("TestPreferences"));
-
- prefs_.reset(PrefService::CreateUserPrefService(prefs_filename));
+ prefs_.reset(new TestingPrefService());
Profile::RegisterUserPrefs(prefs_.get());
browser::RegisterAllPrefs(prefs_.get(), prefs_.get());
}
@@ -292,7 +290,7 @@ class TestingProfile : public Profile {
// to this.
FilePath path_;
base::Time start_time_;
- scoped_ptr<PrefService> prefs_;
+ scoped_ptr<TestingPrefService> prefs_;
private:
// Destroys favicon service if it has been created.