mirror of
https://bitbucket.org/chromiumembedded/cef
synced 2025-06-05 21:39:12 +02:00
chrome: Fix PreferenceTest failures (see issue #2969)
This commit is contained in:
@@ -88,6 +88,20 @@ std::string GetAcceptLanguageList(Profile* profile) {
|
|||||||
const char kUserPrefsFileName[] = "UserPrefs.json";
|
const char kUserPrefsFileName[] = "UserPrefs.json";
|
||||||
const char kLocalPrefsFileName[] = "LocalPrefs.json";
|
const char kLocalPrefsFileName[] = "LocalPrefs.json";
|
||||||
|
|
||||||
|
void RegisterProfilePrefs(PrefRegistrySimple* registry) {
|
||||||
|
const base::CommandLine* command_line =
|
||||||
|
base::CommandLine::ForCurrentProcess();
|
||||||
|
if (command_line->HasSwitch(switches::kEnablePreferenceTesting)) {
|
||||||
|
// Preferences used with unit tests.
|
||||||
|
registry->RegisterBooleanPref("test.bool", true);
|
||||||
|
registry->RegisterIntegerPref("test.int", 2);
|
||||||
|
registry->RegisterDoublePref("test.double", 5.0);
|
||||||
|
registry->RegisterStringPref("test.string", "default");
|
||||||
|
registry->RegisterListPref("test.list");
|
||||||
|
registry->RegisterDictionaryPref("test.dict");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
std::unique_ptr<PrefService> CreatePrefService(Profile* profile,
|
std::unique_ptr<PrefService> CreatePrefService(Profile* profile,
|
||||||
const base::FilePath& cache_path,
|
const base::FilePath& cache_path,
|
||||||
bool persist_user_preferences) {
|
bool persist_user_preferences) {
|
||||||
@@ -209,16 +223,6 @@ std::unique_ptr<PrefService> CreatePrefService(Profile* profile,
|
|||||||
false);
|
false);
|
||||||
registry->RegisterBooleanPref(prefs::kWebRTCAllowLegacyTLSProtocols, false);
|
registry->RegisterBooleanPref(prefs::kWebRTCAllowLegacyTLSProtocols, false);
|
||||||
|
|
||||||
if (command_line->HasSwitch(switches::kEnablePreferenceTesting)) {
|
|
||||||
// Preferences used with unit tests.
|
|
||||||
registry->RegisterBooleanPref("test.bool", true);
|
|
||||||
registry->RegisterIntegerPref("test.int", 2);
|
|
||||||
registry->RegisterDoublePref("test.double", 5.0);
|
|
||||||
registry->RegisterStringPref("test.string", "default");
|
|
||||||
registry->RegisterListPref("test.list");
|
|
||||||
registry->RegisterDictionaryPref("test.dict");
|
|
||||||
}
|
|
||||||
|
|
||||||
if (profile) {
|
if (profile) {
|
||||||
// Call RegisterProfilePrefs() for all services listed by
|
// Call RegisterProfilePrefs() for all services listed by
|
||||||
// EnsureBrowserContextKeyedServiceFactoriesBuilt().
|
// EnsureBrowserContextKeyedServiceFactoriesBuilt().
|
||||||
@@ -235,6 +239,7 @@ std::unique_ptr<PrefService> CreatePrefService(Profile* profile,
|
|||||||
MediaDeviceIDSalt::RegisterProfilePrefs(registry.get());
|
MediaDeviceIDSalt::RegisterProfilePrefs(registry.get());
|
||||||
ProfileNetworkContextService::RegisterProfilePrefs(registry.get());
|
ProfileNetworkContextService::RegisterProfilePrefs(registry.get());
|
||||||
safe_browsing::RegisterProfilePrefs(registry.get());
|
safe_browsing::RegisterProfilePrefs(registry.get());
|
||||||
|
RegisterProfilePrefs(registry.get());
|
||||||
|
|
||||||
const std::string& locale =
|
const std::string& locale =
|
||||||
command_line->GetSwitchValueASCII(switches::kLang);
|
command_line->GetSwitchValueASCII(switches::kLang);
|
||||||
|
@@ -11,6 +11,7 @@ namespace base {
|
|||||||
class FilePath;
|
class FilePath;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
class PrefRegistrySimple;
|
||||||
class PrefService;
|
class PrefService;
|
||||||
class Profile;
|
class Profile;
|
||||||
|
|
||||||
@@ -19,6 +20,9 @@ namespace browser_prefs {
|
|||||||
// Name for the user prefs JSON file.
|
// Name for the user prefs JSON file.
|
||||||
extern const char kUserPrefsFileName[];
|
extern const char kUserPrefsFileName[];
|
||||||
|
|
||||||
|
// Register preferences specific to CEF.
|
||||||
|
void RegisterProfilePrefs(PrefRegistrySimple* registry);
|
||||||
|
|
||||||
// Create the PrefService used to manage pref registration and storage.
|
// Create the PrefService used to manage pref registration and storage.
|
||||||
// |profile| will be nullptr for the system-level PrefService.
|
// |profile| will be nullptr for the system-level PrefService.
|
||||||
std::unique_ptr<PrefService> CreatePrefService(Profile* profile,
|
std::unique_ptr<PrefService> CreatePrefService(Profile* profile,
|
||||||
|
@@ -178,3 +178,37 @@ index 29ba5f21b38f..3ce05420eb78 100644
|
|||||||
}
|
}
|
||||||
|
|
||||||
base::FilePath ChromeContentBrowserClient::GetDefaultDownloadDirectory() {
|
base::FilePath ChromeContentBrowserClient::GetDefaultDownloadDirectory() {
|
||||||
|
diff --git chrome/browser/prefs/browser_prefs.cc chrome/browser/prefs/browser_prefs.cc
|
||||||
|
index fbfeff04ce25..f5ab9f9bb8cf 100644
|
||||||
|
--- chrome/browser/prefs/browser_prefs.cc
|
||||||
|
+++ chrome/browser/prefs/browser_prefs.cc
|
||||||
|
@@ -10,6 +10,7 @@
|
||||||
|
#include "build/branding_buildflags.h"
|
||||||
|
#include "build/build_config.h"
|
||||||
|
#include "build/chromeos_buildflags.h"
|
||||||
|
+#include "cef/libcef/features/features.h"
|
||||||
|
#include "chrome/browser/about_flags.h"
|
||||||
|
#include "chrome/browser/accessibility/accessibility_labels_service.h"
|
||||||
|
#include "chrome/browser/accessibility/accessibility_ui.h"
|
||||||
|
@@ -160,6 +161,10 @@
|
||||||
|
#include "chrome/browser/background/background_mode_manager.h"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
+#if BUILDFLAG(ENABLE_CEF)
|
||||||
|
+#include "cef/libcef/browser/prefs/browser_prefs.h"
|
||||||
|
+#endif
|
||||||
|
+
|
||||||
|
#if BUILDFLAG(ENABLE_EXTENSIONS)
|
||||||
|
#include "chrome/browser/accessibility/animation_policy_prefs.h"
|
||||||
|
#include "chrome/browser/apps/platform_apps/shortcut_manager.h"
|
||||||
|
@@ -959,6 +964,10 @@ void RegisterProfilePrefs(user_prefs::PrefRegistrySyncable* registry,
|
||||||
|
RegisterSessionServiceLogProfilePrefs(registry);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
+#if BUILDFLAG(ENABLE_CEF)
|
||||||
|
+ browser_prefs::RegisterProfilePrefs(registry);
|
||||||
|
+#endif
|
||||||
|
+
|
||||||
|
#if BUILDFLAG(ENABLE_EXTENSIONS)
|
||||||
|
ExtensionWebUI::RegisterProfilePrefs(registry);
|
||||||
|
RegisterAnimationPolicyPrefs(registry);
|
||||||
|
@@ -31,6 +31,11 @@ const char kPrefString[] = "string";
|
|||||||
const char kPrefList[] = "list";
|
const char kPrefList[] = "list";
|
||||||
const char kPrefDict[] = "dict";
|
const char kPrefDict[] = "dict";
|
||||||
|
|
||||||
|
std::string* PendingAction() {
|
||||||
|
static std::string str;
|
||||||
|
return &str;
|
||||||
|
}
|
||||||
|
|
||||||
// Browser-side app delegate.
|
// Browser-side app delegate.
|
||||||
class PreferenceBrowserTest : public client::ClientAppBrowser::Delegate {
|
class PreferenceBrowserTest : public client::ClientAppBrowser::Delegate {
|
||||||
public:
|
public:
|
||||||
@@ -77,7 +82,7 @@ void ValidateBool(CefRefPtr<CefRequestContext> context,
|
|||||||
value = context->GetPreference(name);
|
value = context->GetPreference(name);
|
||||||
EXPECT_TRUE(value.get());
|
EXPECT_TRUE(value.get());
|
||||||
EXPECT_EQ(VTYPE_BOOL, value->GetType());
|
EXPECT_EQ(VTYPE_BOOL, value->GetType());
|
||||||
EXPECT_EQ(expected, value->GetBool());
|
EXPECT_EQ(expected, value->GetBool()) << *PendingAction();
|
||||||
}
|
}
|
||||||
|
|
||||||
void ValidateInt(CefRefPtr<CefRequestContext> context,
|
void ValidateInt(CefRefPtr<CefRequestContext> context,
|
||||||
@@ -100,7 +105,7 @@ void ValidateInt(CefRefPtr<CefRequestContext> context,
|
|||||||
value = context->GetPreference(name);
|
value = context->GetPreference(name);
|
||||||
EXPECT_TRUE(value.get());
|
EXPECT_TRUE(value.get());
|
||||||
EXPECT_EQ(VTYPE_INT, value->GetType());
|
EXPECT_EQ(VTYPE_INT, value->GetType());
|
||||||
EXPECT_EQ(expected, value->GetInt());
|
EXPECT_EQ(expected, value->GetInt()) << *PendingAction();
|
||||||
}
|
}
|
||||||
|
|
||||||
void ValidateDouble(CefRefPtr<CefRequestContext> context,
|
void ValidateDouble(CefRefPtr<CefRequestContext> context,
|
||||||
@@ -123,7 +128,7 @@ void ValidateDouble(CefRefPtr<CefRequestContext> context,
|
|||||||
value = context->GetPreference(name);
|
value = context->GetPreference(name);
|
||||||
EXPECT_TRUE(value.get());
|
EXPECT_TRUE(value.get());
|
||||||
EXPECT_EQ(VTYPE_DOUBLE, value->GetType());
|
EXPECT_EQ(VTYPE_DOUBLE, value->GetType());
|
||||||
EXPECT_EQ(expected, value->GetDouble());
|
EXPECT_EQ(expected, value->GetDouble()) << *PendingAction();
|
||||||
}
|
}
|
||||||
|
|
||||||
void ValidateString(CefRefPtr<CefRequestContext> context,
|
void ValidateString(CefRefPtr<CefRequestContext> context,
|
||||||
@@ -146,7 +151,8 @@ void ValidateString(CefRefPtr<CefRequestContext> context,
|
|||||||
value = context->GetPreference(name);
|
value = context->GetPreference(name);
|
||||||
EXPECT_TRUE(value.get());
|
EXPECT_TRUE(value.get());
|
||||||
EXPECT_EQ(VTYPE_STRING, value->GetType());
|
EXPECT_EQ(VTYPE_STRING, value->GetType());
|
||||||
EXPECT_STREQ(expected.c_str(), value->GetString().ToString().c_str());
|
EXPECT_STREQ(expected.c_str(), value->GetString().ToString().c_str())
|
||||||
|
<< *PendingAction();
|
||||||
}
|
}
|
||||||
|
|
||||||
void ValidateList(CefRefPtr<CefRequestContext> context,
|
void ValidateList(CefRefPtr<CefRequestContext> context,
|
||||||
@@ -216,7 +222,7 @@ void ValidateNoExist(CefRefPtr<CefRequestContext> context,
|
|||||||
}
|
}
|
||||||
|
|
||||||
value = context->GetPreference(name);
|
value = context->GetPreference(name);
|
||||||
EXPECT_FALSE(value.get());
|
EXPECT_FALSE(value.get()) << *PendingAction();
|
||||||
}
|
}
|
||||||
|
|
||||||
void PopulateRootDefaults(CefRefPtr<CefDictionaryValue> val) {
|
void PopulateRootDefaults(CefRefPtr<CefDictionaryValue> val) {
|
||||||
@@ -448,23 +454,37 @@ TEST(PreferenceTest, GlobalSetGetShared) {
|
|||||||
CefRequestContextSettings settings;
|
CefRequestContextSettings settings;
|
||||||
CefRefPtr<CefRequestContext> context4 =
|
CefRefPtr<CefRequestContext> context4 =
|
||||||
CefRequestContext::CreateContext(settings, nullptr);
|
CefRequestContext::CreateContext(settings, nullptr);
|
||||||
EXPECT_TRUE(context.get());
|
EXPECT_TRUE(context4.get());
|
||||||
|
|
||||||
// Set/get the values on the first context.
|
// Set/get the values on the first context.
|
||||||
|
*PendingAction() = "Set/get the values on the first context";
|
||||||
ValidateSetGet(context, event);
|
ValidateSetGet(context, event);
|
||||||
event->Wait();
|
event->Wait();
|
||||||
|
|
||||||
// Get the values from the 2nd and 3rd contexts. They should be the same.
|
// Get the values from the 2nd and 3rd contexts. They should be the same.
|
||||||
|
*PendingAction() = "Get the values from the 2nd context.";
|
||||||
ValidateGet(context2, event);
|
ValidateGet(context2, event);
|
||||||
event->Wait();
|
event->Wait();
|
||||||
|
*PendingAction() = "Get the values from the 3rd context.";
|
||||||
ValidateGet(context3, event);
|
ValidateGet(context3, event);
|
||||||
event->Wait();
|
event->Wait();
|
||||||
|
|
||||||
// Get the values from the 4th context. They should be at the default.
|
// Get the values from the 4th context.
|
||||||
|
*PendingAction() = "Get the values from the 4th context.";
|
||||||
|
if (IsChromeRuntimeEnabled()) {
|
||||||
|
// With the Chrome runtime, prefs set via an incognito profile will become
|
||||||
|
// an overlay on top of the global (parent) profile. The incognito profile
|
||||||
|
// shares the prefs in this case because they were set via the global
|
||||||
|
// profile.
|
||||||
|
ValidateGet(context4, event);
|
||||||
|
} else {
|
||||||
|
// They should be at the default.
|
||||||
ValidateDefaults(context4, false, event);
|
ValidateDefaults(context4, false, event);
|
||||||
|
}
|
||||||
event->Wait();
|
event->Wait();
|
||||||
|
|
||||||
// Reset to the default values.
|
// Reset to the default values.
|
||||||
|
*PendingAction() = "Reset to the default values.";
|
||||||
ValidateDefaults(context, true, event);
|
ValidateDefaults(context, true, event);
|
||||||
event->Wait();
|
event->Wait();
|
||||||
}
|
}
|
||||||
@@ -524,23 +544,30 @@ TEST(PreferenceTest, CustomSetGetShared) {
|
|||||||
// Unassociated context.
|
// Unassociated context.
|
||||||
CefRefPtr<CefRequestContext> context4 =
|
CefRefPtr<CefRequestContext> context4 =
|
||||||
CefRequestContext::CreateContext(settings, nullptr);
|
CefRequestContext::CreateContext(settings, nullptr);
|
||||||
EXPECT_TRUE(context.get());
|
EXPECT_TRUE(context4.get());
|
||||||
|
|
||||||
// Set/get the values on the first context.
|
// Set/get the values on the first context.
|
||||||
|
*PendingAction() = "Set/get the values on the first context";
|
||||||
ValidateSetGet(context, event);
|
ValidateSetGet(context, event);
|
||||||
event->Wait();
|
event->Wait();
|
||||||
|
|
||||||
// Get the values from the 2nd and 3d contexts. They should be the same.
|
// Get the values from the 2nd and 3d contexts. They should be the same.
|
||||||
|
*PendingAction() = "Get the values from the 2nd context.";
|
||||||
ValidateGet(context2, event);
|
ValidateGet(context2, event);
|
||||||
event->Wait();
|
event->Wait();
|
||||||
|
*PendingAction() = "Get the values from the 3rd context.";
|
||||||
ValidateGet(context3, event);
|
ValidateGet(context3, event);
|
||||||
event->Wait();
|
event->Wait();
|
||||||
|
|
||||||
// Get the values from the 4th context. They should be at the default.
|
// Get the values from the 4th context. They should be at the default.
|
||||||
|
// This works with the Chrome runtime because the preference changes only
|
||||||
|
// exist in the other incognito profile's overlay.
|
||||||
|
*PendingAction() = "Get the values from the 4th context.";
|
||||||
ValidateDefaults(context4, false, event);
|
ValidateDefaults(context4, false, event);
|
||||||
event->Wait();
|
event->Wait();
|
||||||
|
|
||||||
// Reset to the default values.
|
// Reset to the default values.
|
||||||
|
*PendingAction() = "Reset to the default values.";
|
||||||
ValidateDefaults(context, true, event);
|
ValidateDefaults(context, true, event);
|
||||||
event->Wait();
|
event->Wait();
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user