1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79
|
// Copyright 2014 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "extensions/shell/browser/shell_prefs.h"
#include "base/path_service.h"
#include "build/build_config.h"
#include "build/chromeos_buildflags.h"
#include "components/prefs/pref_service.h"
#include "components/user_prefs/user_prefs.h"
#include "content/public/test/browser_task_environment.h"
#include "content/public/test/test_browser_context.h"
#include "extensions/common/extension_paths.h"
#include "testing/gtest/include/gtest/gtest.h"
namespace extensions {
namespace {
// A BrowserContext that uses a test data directory as its data path.
class PrefsTestBrowserContext : public content::TestBrowserContext {
public:
PrefsTestBrowserContext() {}
PrefsTestBrowserContext(const PrefsTestBrowserContext&) = delete;
PrefsTestBrowserContext& operator=(const PrefsTestBrowserContext&) = delete;
~PrefsTestBrowserContext() override {}
// content::BrowserContext:
base::FilePath GetPath() override {
base::FilePath path;
base::PathService::Get(extensions::DIR_TEST_DATA, &path);
return path.AppendASCII("shell_prefs");
}
};
class ShellPrefsTest : public testing::Test {
public:
ShellPrefsTest() {}
~ShellPrefsTest() override {}
protected:
content::BrowserTaskEnvironment task_environment_;
PrefsTestBrowserContext browser_context_;
};
TEST_F(ShellPrefsTest, CreateLocalState) {
std::unique_ptr<PrefService> local_state =
shell_prefs::CreateLocalState(browser_context_.GetPath());
ASSERT_TRUE(local_state);
#if BUILDFLAG(IS_CHROMEOS)
// Verify prefs were registered.
EXPECT_TRUE(local_state->FindPreference("hardware.audio_output_enabled"));
// Verify the test values were read.
EXPECT_FALSE(local_state->GetBoolean("hardware.audio_output_enabled"));
#endif
}
TEST_F(ShellPrefsTest, CreateUserPrefService) {
// Create the pref service. This loads the test pref file.
std::unique_ptr<PrefService> service =
shell_prefs::CreateUserPrefService(&browser_context_);
// Some basic extension preferences are registered.
EXPECT_TRUE(service->FindPreference("extensions.settings"));
EXPECT_FALSE(service->FindPreference("should.not.exist"));
// User prefs from the file have been read correctly.
EXPECT_EQ("1.2.3.4", service->GetString("extensions.last_chrome_version"));
// The user prefs system has been initialized.
EXPECT_EQ(service.get(), user_prefs::UserPrefs::Get(&browser_context_));
}
} // namespace
} // namespace extensions
|