mirror of
https://bitbucket.org/chromiumembedded/cef
synced 2025-02-28 18:07:44 +01:00
chrome: Fix PreferenceTest failures (see issue #2969)
This commit is contained in:
parent
76642ccafa
commit
5318dfe252
@ -88,6 +88,20 @@ std::string GetAcceptLanguageList(Profile* profile) {
|
||||
const char kUserPrefsFileName[] = "UserPrefs.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,
|
||||
const base::FilePath& cache_path,
|
||||
bool persist_user_preferences) {
|
||||
@ -209,16 +223,6 @@ std::unique_ptr<PrefService> CreatePrefService(Profile* profile,
|
||||
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) {
|
||||
// Call RegisterProfilePrefs() for all services listed by
|
||||
// EnsureBrowserContextKeyedServiceFactoriesBuilt().
|
||||
@ -235,6 +239,7 @@ std::unique_ptr<PrefService> CreatePrefService(Profile* profile,
|
||||
MediaDeviceIDSalt::RegisterProfilePrefs(registry.get());
|
||||
ProfileNetworkContextService::RegisterProfilePrefs(registry.get());
|
||||
safe_browsing::RegisterProfilePrefs(registry.get());
|
||||
RegisterProfilePrefs(registry.get());
|
||||
|
||||
const std::string& locale =
|
||||
command_line->GetSwitchValueASCII(switches::kLang);
|
||||
|
@ -11,6 +11,7 @@ namespace base {
|
||||
class FilePath;
|
||||
}
|
||||
|
||||
class PrefRegistrySimple;
|
||||
class PrefService;
|
||||
class Profile;
|
||||
|
||||
@ -19,6 +20,9 @@ namespace browser_prefs {
|
||||
// Name for the user prefs JSON file.
|
||||
extern const char kUserPrefsFileName[];
|
||||
|
||||
// Register preferences specific to CEF.
|
||||
void RegisterProfilePrefs(PrefRegistrySimple* registry);
|
||||
|
||||
// Create the PrefService used to manage pref registration and storage.
|
||||
// |profile| will be nullptr for the system-level PrefService.
|
||||
std::unique_ptr<PrefService> CreatePrefService(Profile* profile,
|
||||
|
@ -178,3 +178,37 @@ index 29ba5f21b38f..3ce05420eb78 100644
|
||||
}
|
||||
|
||||
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 kPrefDict[] = "dict";
|
||||
|
||||
std::string* PendingAction() {
|
||||
static std::string str;
|
||||
return &str;
|
||||
}
|
||||
|
||||
// Browser-side app delegate.
|
||||
class PreferenceBrowserTest : public client::ClientAppBrowser::Delegate {
|
||||
public:
|
||||
@ -77,7 +82,7 @@ void ValidateBool(CefRefPtr<CefRequestContext> context,
|
||||
value = context->GetPreference(name);
|
||||
EXPECT_TRUE(value.get());
|
||||
EXPECT_EQ(VTYPE_BOOL, value->GetType());
|
||||
EXPECT_EQ(expected, value->GetBool());
|
||||
EXPECT_EQ(expected, value->GetBool()) << *PendingAction();
|
||||
}
|
||||
|
||||
void ValidateInt(CefRefPtr<CefRequestContext> context,
|
||||
@ -100,7 +105,7 @@ void ValidateInt(CefRefPtr<CefRequestContext> context,
|
||||
value = context->GetPreference(name);
|
||||
EXPECT_TRUE(value.get());
|
||||
EXPECT_EQ(VTYPE_INT, value->GetType());
|
||||
EXPECT_EQ(expected, value->GetInt());
|
||||
EXPECT_EQ(expected, value->GetInt()) << *PendingAction();
|
||||
}
|
||||
|
||||
void ValidateDouble(CefRefPtr<CefRequestContext> context,
|
||||
@ -123,7 +128,7 @@ void ValidateDouble(CefRefPtr<CefRequestContext> context,
|
||||
value = context->GetPreference(name);
|
||||
EXPECT_TRUE(value.get());
|
||||
EXPECT_EQ(VTYPE_DOUBLE, value->GetType());
|
||||
EXPECT_EQ(expected, value->GetDouble());
|
||||
EXPECT_EQ(expected, value->GetDouble()) << *PendingAction();
|
||||
}
|
||||
|
||||
void ValidateString(CefRefPtr<CefRequestContext> context,
|
||||
@ -146,7 +151,8 @@ void ValidateString(CefRefPtr<CefRequestContext> context,
|
||||
value = context->GetPreference(name);
|
||||
EXPECT_TRUE(value.get());
|
||||
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,
|
||||
@ -216,7 +222,7 @@ void ValidateNoExist(CefRefPtr<CefRequestContext> context,
|
||||
}
|
||||
|
||||
value = context->GetPreference(name);
|
||||
EXPECT_FALSE(value.get());
|
||||
EXPECT_FALSE(value.get()) << *PendingAction();
|
||||
}
|
||||
|
||||
void PopulateRootDefaults(CefRefPtr<CefDictionaryValue> val) {
|
||||
@ -448,23 +454,37 @@ TEST(PreferenceTest, GlobalSetGetShared) {
|
||||
CefRequestContextSettings settings;
|
||||
CefRefPtr<CefRequestContext> context4 =
|
||||
CefRequestContext::CreateContext(settings, nullptr);
|
||||
EXPECT_TRUE(context.get());
|
||||
EXPECT_TRUE(context4.get());
|
||||
|
||||
// Set/get the values on the first context.
|
||||
*PendingAction() = "Set/get the values on the first context";
|
||||
ValidateSetGet(context, event);
|
||||
event->Wait();
|
||||
|
||||
// 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);
|
||||
event->Wait();
|
||||
*PendingAction() = "Get the values from the 3rd context.";
|
||||
ValidateGet(context3, event);
|
||||
event->Wait();
|
||||
|
||||
// Get the values from the 4th context. They should be at the default.
|
||||
ValidateDefaults(context4, false, event);
|
||||
// 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);
|
||||
}
|
||||
event->Wait();
|
||||
|
||||
// Reset to the default values.
|
||||
*PendingAction() = "Reset to the default values.";
|
||||
ValidateDefaults(context, true, event);
|
||||
event->Wait();
|
||||
}
|
||||
@ -524,23 +544,30 @@ TEST(PreferenceTest, CustomSetGetShared) {
|
||||
// Unassociated context.
|
||||
CefRefPtr<CefRequestContext> context4 =
|
||||
CefRequestContext::CreateContext(settings, nullptr);
|
||||
EXPECT_TRUE(context.get());
|
||||
EXPECT_TRUE(context4.get());
|
||||
|
||||
// Set/get the values on the first context.
|
||||
*PendingAction() = "Set/get the values on the first context";
|
||||
ValidateSetGet(context, event);
|
||||
event->Wait();
|
||||
|
||||
// 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);
|
||||
event->Wait();
|
||||
*PendingAction() = "Get the values from the 3rd context.";
|
||||
ValidateGet(context3, event);
|
||||
event->Wait();
|
||||
|
||||
// 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);
|
||||
event->Wait();
|
||||
|
||||
// Reset to the default values.
|
||||
*PendingAction() = "Reset to the default values.";
|
||||
ValidateDefaults(context, true, event);
|
||||
event->Wait();
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user