This source file includes following definitions.
- TEST
- SetUp
- ClearListValue
- ClearDictionaryValue
- SetUp
- TEST_F
#include "base/command_line.h"
#include "base/file_util.h"
#include "base/files/scoped_temp_dir.h"
#include "base/memory/scoped_ptr.h"
#include "base/path_service.h"
#include "base/prefs/pref_registry_simple.h"
#include "base/prefs/scoped_user_pref_update.h"
#include "base/strings/utf_string_conversions.h"
#include "base/values.h"
#include "chrome/browser/prefs/browser_prefs.h"
#include "chrome/browser/prefs/command_line_pref_store.h"
#include "chrome/browser/prefs/pref_service_mock_factory.h"
#include "chrome/common/chrome_paths.h"
#include "chrome/common/chrome_switches.h"
#include "chrome/common/pref_names.h"
#include "chrome/test/base/chrome_render_view_host_test_harness.h"
#include "chrome/test/base/testing_pref_service_syncable.h"
#include "chrome/test/base/testing_profile.h"
#include "components/policy/core/browser/configuration_policy_pref_store.h"
#include "components/policy/core/common/mock_configuration_policy_provider.h"
#include "components/user_prefs/pref_registry_syncable.h"
#include "content/public/test/web_contents_tester.h"
#include "ui/base/test/data/resource.h"
#include "webkit/common/webpreferences.h"
using content::WebContentsTester;
TEST(ChromePrefServiceTest, UpdateCommandLinePrefStore) {
TestingPrefServiceSimple prefs;
prefs.registry()->RegisterBooleanPref(prefs::kCloudPrintProxyEnabled, false);
const PrefService::Preference* pref =
prefs.FindPreference(prefs::kCloudPrintProxyEnabled);
ASSERT_TRUE(pref);
const base::Value* value = pref->GetValue();
ASSERT_TRUE(value);
EXPECT_EQ(base::Value::TYPE_BOOLEAN, value->GetType());
bool actual_bool_value = true;
EXPECT_TRUE(value->GetAsBoolean(&actual_bool_value));
EXPECT_FALSE(actual_bool_value);
CommandLine cmd_line(CommandLine::NO_PROGRAM);
cmd_line.AppendSwitch(switches::kEnableCloudPrintProxy);
prefs.UpdateCommandLinePrefStore(new CommandLinePrefStore(&cmd_line));
pref = prefs.FindPreference(prefs::kCloudPrintProxyEnabled);
ASSERT_TRUE(pref);
value = pref->GetValue();
ASSERT_TRUE(value);
EXPECT_EQ(base::Value::TYPE_BOOLEAN, value->GetType());
actual_bool_value = false;
EXPECT_TRUE(value->GetAsBoolean(&actual_bool_value));
EXPECT_TRUE(actual_bool_value);
}
class ChromePrefServiceUserFilePrefsTest : public testing::Test {
protected:
virtual void SetUp() {
ASSERT_TRUE(temp_dir_.CreateUniqueTempDir());
ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &data_dir_));
data_dir_ = data_dir_.AppendASCII("pref_service");
ASSERT_TRUE(base::PathExists(data_dir_));
}
void ClearListValue(PrefService* prefs, const char* key) {
ListPrefUpdate updater(prefs, key);
updater->Clear();
}
void ClearDictionaryValue(PrefService* prefs, const char* key) {
DictionaryPrefUpdate updater(prefs, key);
updater->Clear();
}
base::ScopedTempDir temp_dir_;
base::FilePath data_dir_;
base::MessageLoop message_loop_;
};
class ChromePrefServiceWebKitPrefs : public ChromeRenderViewHostTestHarness {
protected:
virtual void SetUp() {
ChromeRenderViewHostTestHarness::SetUp();
TestingPrefServiceSyncable* pref_services =
profile()->GetTestingPrefService();
#if defined(TOOLKIT_GTK)
pref_services->SetUserPref(prefs::kUsesSystemTheme,
base::Value::CreateBooleanValue(false));
#endif
pref_services->SetUserPref(prefs::kDefaultCharset,
base::Value::CreateStringValue("utf8"));
pref_services->SetUserPref(prefs::kWebKitDefaultFontSize,
base::Value::CreateIntegerValue(20));
pref_services->SetUserPref(prefs::kWebKitTextAreasAreResizable,
base::Value::CreateBooleanValue(false));
pref_services->SetUserPref(prefs::kWebKitUsesUniversalDetector,
base::Value::CreateBooleanValue(true));
pref_services->SetUserPref("webkit.webprefs.foo",
base::Value::CreateStringValue("bar"));
}
};
TEST_F(ChromePrefServiceWebKitPrefs, PrefsCopied) {
WebPreferences webkit_prefs =
WebContentsTester::For(web_contents())->TestGetWebkitPrefs();
EXPECT_EQ("UTF-8", webkit_prefs.default_encoding);
EXPECT_EQ(20, webkit_prefs.default_font_size);
EXPECT_FALSE(webkit_prefs.text_areas_are_resizable);
EXPECT_TRUE(webkit_prefs.uses_universal_detector);
#if defined(OS_MACOSX)
const char kDefaultFont[] = "Times";
#elif defined(OS_CHROMEOS)
const char kDefaultFont[] = "Tinos";
#else
const char kDefaultFont[] = "Times New Roman";
#endif
EXPECT_EQ(base::ASCIIToUTF16(kDefaultFont),
webkit_prefs.standard_font_family_map[prefs::kWebKitCommonScript]);
EXPECT_TRUE(webkit_prefs.javascript_enabled);
}