Popular sites on the NTP: check that experiment group StartsWith (rather than IS...
[chromium-blink-merge.git] / chrome / browser / ui / prefs / prefs_tab_helper_browsertest.cc
blobc17e83bd9ed9305b956cdbdcd1f472ea47c4bc9f
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "base/files/file_util.h"
6 #include "base/path_service.h"
7 #include "base/prefs/pref_service.h"
8 #include "chrome/browser/profiles/profile.h"
9 #include "chrome/browser/ui/browser.h"
10 #include "chrome/common/chrome_constants.h"
11 #include "chrome/common/chrome_paths.h"
12 #include "chrome/common/pref_names.h"
13 #include "chrome/test/base/in_process_browser_test.h"
14 #include "chrome/test/base/testing_profile.h"
16 class PrefsTabHelperBrowserTest : public InProcessBrowserTest {
17 protected:
18 virtual base::FilePath GetPreferencesFilePath() {
19 base::FilePath test_data_directory;
20 PathService::Get(chrome::DIR_TEST_DATA, &test_data_directory);
21 return test_data_directory
22 .AppendASCII("profiles")
23 .AppendASCII("web_prefs")
24 .AppendASCII("Default")
25 .Append(chrome::kPreferencesFilename);
28 bool SetUpUserDataDirectory() override {
29 base::FilePath user_data_directory;
30 PathService::Get(chrome::DIR_USER_DATA, &user_data_directory);
31 base::FilePath default_profile =
32 user_data_directory.AppendASCII(TestingProfile::kTestUserProfileDir);
33 if (!base::CreateDirectory(default_profile)) {
34 LOG(ERROR) << "Can't create " << default_profile.MaybeAsASCII();
35 return false;
37 base::FilePath pref_file = GetPreferencesFilePath();
38 if (!base::PathExists(pref_file)) {
39 LOG(ERROR) << "Doesn't exist " << pref_file.MaybeAsASCII();
40 return false;
42 base::FilePath default_pref_file =
43 default_profile.Append(chrome::kPreferencesFilename);
44 if (!base::CopyFile(pref_file, default_pref_file)) {
45 LOG(ERROR) << "Copy error from " << pref_file.MaybeAsASCII()
46 << " to " << default_pref_file.MaybeAsASCII();
47 return false;
50 #if defined(OS_WIN)
51 // Make the copy writable. On POSIX we assume the umask allows files
52 // we create to be writable.
53 if (!::SetFileAttributesW(default_pref_file.value().c_str(),
54 FILE_ATTRIBUTE_NORMAL)) return false;
55 #endif
56 return true;
60 // Tests that a sampling of web prefs are registered and ones with values in the
61 // test user preferences file take on those values.
62 IN_PROC_BROWSER_TEST_F(PrefsTabHelperBrowserTest, WebPrefs) {
63 PrefService* prefs = browser()->profile()->GetPrefs();
65 EXPECT_TRUE(prefs->FindPreference(
66 prefs::kWebKitCursiveFontFamily)->IsDefaultValue());
67 EXPECT_TRUE(prefs->FindPreference(
68 prefs::kWebKitSerifFontFamily)->IsDefaultValue());
69 EXPECT_TRUE(prefs->FindPreference(
70 prefs::kWebKitSerifFontFamilyJapanese)->IsDefaultValue());
72 EXPECT_EQ("windows-1251", prefs->GetString(prefs::kDefaultCharset));
73 EXPECT_EQ(16, prefs->GetInteger(prefs::kWebKitDefaultFontSize));
74 EXPECT_EQ("Nanum Gothic",
75 prefs->GetString(prefs::kWebKitStandardFontFamilyKorean));
76 EXPECT_EQ("Tinos", prefs->GetString(prefs::kWebKitStandardFontFamily));
77 EXPECT_EQ("DejaVu Sans", prefs->GetString(prefs::kWebKitSansSerifFontFamily));