diff options
Diffstat (limited to 'chrome/test')
-rw-r--r-- | chrome/test/testing_pref_service.cc | 65 | ||||
-rw-r--r-- | chrome/test/testing_pref_service.h | 31 | ||||
-rw-r--r-- | chrome/test/testing_profile.cc | 29 | ||||
-rw-r--r-- | chrome/test/testing_profile.h | 19 |
4 files changed, 93 insertions, 51 deletions
diff --git a/chrome/test/testing_pref_service.cc b/chrome/test/testing_pref_service.cc index acb4be2..afcb1c5 100644 --- a/chrome/test/testing_pref_service.cc +++ b/chrome/test/testing_pref_service.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2010 The Chromium Authors. All rights reserved. +// 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. @@ -6,59 +6,76 @@ #include "chrome/browser/policy/configuration_policy_pref_store.h" #include "chrome/browser/prefs/command_line_pref_store.h" +#include "chrome/browser/prefs/default_pref_store.h" #include "chrome/browser/prefs/pref_notifier.h" #include "chrome/browser/prefs/pref_value_store.h" #include "chrome/browser/prefs/testing_pref_store.h" -// TODO(pamg): Instantiate no PrefStores by default. Allow callers to specify -// which they want, and expand usage of this class to more unit tests. -TestingPrefService::TestingPrefService() - : PrefService( - managed_platform_prefs_ = new TestingPrefStore(), - device_management_prefs_ = new TestingPrefStore(), - NULL, - NULL, - user_prefs_ = new TestingPrefStore(), - NULL) { +TestingPrefServiceBase::TestingPrefServiceBase( + TestingPrefStore* managed_platform_prefs, + TestingPrefStore* device_management_prefs, + TestingPrefStore* user_prefs) + : PrefService(managed_platform_prefs, + device_management_prefs, + NULL, + NULL, + user_prefs, + NULL, + new DefaultPrefStore()), + managed_platform_prefs_(managed_platform_prefs), + device_management_prefs_(device_management_prefs), + user_prefs_(user_prefs) { +} + +TestingPrefServiceBase::~TestingPrefServiceBase() { } -const Value* TestingPrefService::GetManagedPref(const char* path) const { +const Value* TestingPrefServiceBase::GetManagedPref(const char* path) const { return GetPref(managed_platform_prefs_, path); } -void TestingPrefService::SetManagedPref(const char* path, Value* value) { +void TestingPrefServiceBase::SetManagedPref(const char* path, Value* value) { SetPref(managed_platform_prefs_, path, value); } -void TestingPrefService::RemoveManagedPref(const char* path) { +void TestingPrefServiceBase::RemoveManagedPref(const char* path) { RemovePref(managed_platform_prefs_, path); } -const Value* TestingPrefService::GetUserPref(const char* path) const { +const Value* TestingPrefServiceBase::GetUserPref(const char* path) const { return GetPref(user_prefs_, path); } -void TestingPrefService::SetUserPref(const char* path, Value* value) { +void TestingPrefServiceBase::SetUserPref(const char* path, Value* value) { SetPref(user_prefs_, path, value); } -void TestingPrefService::RemoveUserPref(const char* path) { +void TestingPrefServiceBase::RemoveUserPref(const char* path) { RemovePref(user_prefs_, path); } -const Value* TestingPrefService::GetPref(TestingPrefStore* pref_store, - const char* path) const { +const Value* TestingPrefServiceBase::GetPref(TestingPrefStore* pref_store, + const char* path) const { Value* res; return pref_store->GetValue(path, &res) == PrefStore::READ_OK ? res : NULL; } -void TestingPrefService::SetPref(TestingPrefStore* pref_store, - const char* path, - Value* value) { +void TestingPrefServiceBase::SetPref(TestingPrefStore* pref_store, + const char* path, + Value* value) { pref_store->SetValue(path, value); } -void TestingPrefService::RemovePref(TestingPrefStore* pref_store, - const char* path) { +void TestingPrefServiceBase::RemovePref(TestingPrefStore* pref_store, + const char* path) { pref_store->RemoveValue(path); } + +TestingPrefService::TestingPrefService() + : TestingPrefServiceBase(new TestingPrefStore(), + new TestingPrefStore(), + new TestingPrefStore()) { +} + +TestingPrefService::~TestingPrefService() { +} diff --git a/chrome/test/testing_pref_service.h b/chrome/test/testing_pref_service.h index 25349b6..7429145 100644 --- a/chrome/test/testing_pref_service.h +++ b/chrome/test/testing_pref_service.h @@ -1,4 +1,4 @@ -// Copyright (c) 2010 The Chromium Authors. All rights reserved. +// 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. @@ -6,6 +6,7 @@ #define CHROME_TEST_TESTING_PREF_SERVICE_H_ #pragma once +#include "base/ref_counted.h" #include "chrome/browser/prefs/pref_service.h" class TestingPrefStore; @@ -13,11 +14,9 @@ class TestingPrefStore; // 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 { +class TestingPrefServiceBase : public PrefService { public: - // Create an empty instance. - TestingPrefService(); - virtual ~TestingPrefService() {} + virtual ~TestingPrefServiceBase(); // Read the value of a preference from the managed layer. Returns NULL if the // preference is not defined at the managed layer. @@ -36,6 +35,12 @@ class TestingPrefService : public PrefService { void SetUserPref(const char* path, Value* value); void RemoveUserPref(const char* path); + protected: + TestingPrefServiceBase( + TestingPrefStore* managed_platform_prefs, + TestingPrefStore* device_management_prefs, + TestingPrefStore* user_prefs); + private: // Reads the value of the preference indicated by |path| from |pref_store|. // Returns NULL if the preference was not found. @@ -48,10 +53,20 @@ class TestingPrefService : public PrefService { void RemovePref(TestingPrefStore* pref_store, const char* path); // Pointers to the pref stores our value store uses. - TestingPrefStore* managed_platform_prefs_; // weak - TestingPrefStore* device_management_prefs_; // weak - TestingPrefStore* user_prefs_; // weak + scoped_refptr<TestingPrefStore> managed_platform_prefs_; + scoped_refptr<TestingPrefStore> device_management_prefs_; + scoped_refptr<TestingPrefStore> user_prefs_; + + DISALLOW_COPY_AND_ASSIGN(TestingPrefServiceBase); +}; +// Class for simplified construction of TestPrefServiceBase objects. +class TestingPrefService : public TestingPrefServiceBase { + public: + TestingPrefService(); + virtual ~TestingPrefService(); + + private: DISALLOW_COPY_AND_ASSIGN(TestingPrefService); }; diff --git a/chrome/test/testing_profile.cc b/chrome/test/testing_profile.cc index 4f3b40b..6b584af 100644 --- a/chrome/test/testing_profile.cc +++ b/chrome/test/testing_profile.cc @@ -17,8 +17,8 @@ #include "chrome/browser/browser_thread.h" #include "chrome/browser/content_settings/host_content_settings_map.h" #include "chrome/browser/dom_ui/ntp_resource_cache.h" -#include "chrome/browser/extensions/extension_pref_store.h" #include "chrome/browser/extensions/extension_service.h" +#include "chrome/browser/extensions/extension_pref_value_map.h" #include "chrome/browser/favicon_service.h" #include "chrome/browser/geolocation/geolocation_content_settings_map.h" #include "chrome/browser/geolocation/geolocation_permission_context.h" @@ -30,6 +30,7 @@ #include "chrome/browser/net/pref_proxy_config_service.h" #include "chrome/browser/notifications/desktop_notification_service.h" #include "chrome/browser/prefs/browser_prefs.h" +#include "chrome/browser/prefs/testing_pref_store.h" #include "chrome/browser/search_engines/template_url_fetcher.h" #include "chrome/browser/search_engines/template_url_model.h" #include "chrome/browser/sessions/session_service.h" @@ -48,7 +49,6 @@ #include "net/url_request/url_request_unittest.h" #include "testing/gmock/include/gmock/gmock.h" #include "webkit/database/database_tracker.h" - #if defined(OS_LINUX) && !defined(TOOLKIT_VIEWS) #include "chrome/browser/ui/gtk/gtk_theme_provider.h" #endif @@ -326,18 +326,25 @@ void TestingProfile::UseThemeProvider(BrowserThemeProvider* theme_provider) { theme_provider_.reset(theme_provider); } -scoped_refptr<ExtensionService> TestingProfile::CreateExtensionService( +ExtensionService* TestingProfile::CreateExtensionService( const CommandLine* command_line, const FilePath& install_directory) { - extension_pref_store_.reset(new ExtensionPrefStore); - extension_prefs_.reset(new ExtensionPrefs(GetPrefs(), - install_directory, - extension_pref_store_.get())); + // Extension pref store, created for use by |extension_prefs_|. + + extension_pref_value_map_.reset(new ExtensionPrefValueMap); + // Note that the GetPrefs() creates a TestingPrefService, therefore + // the extension controlled pref values set in extension_prefs_ + // are not reflected in the pref service. One would need to + // inject a new ExtensionPrefStore(extension_pref_value_map_.get(), false). + extension_prefs_.reset( + new ExtensionPrefs(GetPrefs(), + install_directory, + extension_pref_value_map_.get())); extensions_service_ = new ExtensionService(this, - command_line, - install_directory, - extension_prefs_.get(), - false); + command_line, + install_directory, + extension_prefs_.get(), + false); return extensions_service_; } diff --git a/chrome/test/testing_profile.h b/chrome/test/testing_profile.h index 181e375..e1e5d8b 100644 --- a/chrome/test/testing_profile.h +++ b/chrome/test/testing_profile.h @@ -1,4 +1,4 @@ -// Copyright (c) 2010 The Chromium Authors. All rights reserved. +// 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. @@ -25,8 +25,9 @@ class BookmarkModel; class BrowserThemeProvider; class CommandLine; class DesktopNotificationService; -class ExtensionPrefStore; class ExtensionPrefs; +class ExtensionPrefStore; +class ExtensionPrefValueMap; class FaviconService; class FindBarState; class GeolocationContentSettingsMap; @@ -115,9 +116,8 @@ class TestingProfile : public Profile { // returns it. The profile keeps its own copy of a scoped_refptr to the // ExtensionService to make sure that is still alive to be notified when the // profile is destroyed. - scoped_refptr<ExtensionService> CreateExtensionService( - const CommandLine* command_line, - const FilePath& install_directory); + ExtensionService* CreateExtensionService(const CommandLine* command_line, + const FilePath& install_directory); TestingPrefService* GetTestingPrefService(); @@ -322,6 +322,10 @@ class TestingProfile : public Profile { virtual PrerenderManager* GetPrerenderManager() { return NULL; } protected: + virtual ExtensionPrefValueMap* GetExtensionPrefValueMap() { + return extension_pref_value_map_.get(); + } + base::Time start_time_; scoped_ptr<PrefService> prefs_; // ref only for right type, lifecycle is managed by prefs_ @@ -411,9 +415,6 @@ class TestingProfile : public Profile { FilePath last_selected_directory_; scoped_refptr<history::TopSites> top_sites_; // For history and thumbnails. - // Extension pref store, created for use by |extension_prefs_|. - scoped_ptr<ExtensionPrefStore> extension_pref_store_; - // The Extension Preferences. Only created if CreateExtensionService is // invoked. scoped_ptr<ExtensionPrefs> extension_prefs_; @@ -422,6 +423,8 @@ class TestingProfile : public Profile { // is disposed. scoped_refptr<ExtensionService> extensions_service_; + scoped_ptr<ExtensionPrefValueMap> extension_pref_value_map_; + // The proxy prefs tracker. scoped_refptr<PrefProxyConfigTracker> pref_proxy_config_tracker_; |