1 // Copyright 2014 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 "extensions/shell/browser/shell_prefs.h"
7 #include "base/path_service.h"
8 #include "base/prefs/pref_service.h"
9 #include "components/user_prefs/user_prefs.h"
10 #include "content/public/test/test_browser_context.h"
11 #include "content/public/test/test_browser_thread_bundle.h"
12 #include "extensions/common/extension_paths.h"
13 #include "testing/gtest/include/gtest/gtest.h"
15 namespace extensions
{
18 // A BrowserContext that uses a test data directory as its data path.
19 class PrefsTestBrowserContext
: public content::TestBrowserContext
{
21 PrefsTestBrowserContext() {}
22 ~PrefsTestBrowserContext() override
{}
24 // content::BrowserContext:
25 base::FilePath
GetPath() const override
{
27 PathService::Get(extensions::DIR_TEST_DATA
, &path
);
28 return path
.AppendASCII("shell_prefs");
32 DISALLOW_COPY_AND_ASSIGN(PrefsTestBrowserContext
);
35 class ShellPrefsTest
: public testing::Test
{
38 ~ShellPrefsTest() override
{}
41 content::TestBrowserThreadBundle thread_bundle_
;
42 PrefsTestBrowserContext browser_context_
;
45 TEST_F(ShellPrefsTest
, CreateLocalState
) {
46 scoped_ptr
<PrefService
> local_state
=
47 shell_prefs::CreateLocalState(browser_context_
.GetPath());
48 ASSERT_TRUE(local_state
);
50 #if defined(OS_CHROMEOS)
51 // Verify prefs were registered.
52 EXPECT_TRUE(local_state
->FindPreference("hardware.audio_output_enabled"));
54 // Verify the test values were read.
55 EXPECT_FALSE(local_state
->GetBoolean("hardware.audio_output_enabled"));
59 TEST_F(ShellPrefsTest
, CreateUserPrefService
) {
60 // Create the pref service. This loads the test pref file.
61 scoped_ptr
<PrefService
> service
=
62 shell_prefs::CreateUserPrefService(&browser_context_
);
64 // Some basic extension preferences are registered.
65 EXPECT_TRUE(service
->FindPreference("extensions.settings"));
66 EXPECT_TRUE(service
->FindPreference("extensions.toolbarsize"));
67 EXPECT_FALSE(service
->FindPreference("should.not.exist"));
69 // User prefs from the file have been read correctly.
70 EXPECT_EQ("1.2.3.4", service
->GetString("extensions.last_chrome_version"));
71 EXPECT_EQ(123, service
->GetInteger("extensions.toolbarsize"));
73 // The user prefs system has been initialized.
74 EXPECT_EQ(service
.get(), user_prefs::UserPrefs::Get(&browser_context_
));
78 } // namespace extensions