2015-10-03 01:03:16 +02:00
|
|
|
// Copyright (c) 2015 The Chromium Embedded Framework Authors. All rights
|
|
|
|
// reserved. Use of this source code is governed by a BSD-style license that
|
|
|
|
// can be found in the LICENSE file.
|
|
|
|
|
2021-06-17 22:08:01 +02:00
|
|
|
#include "include/base/cef_callback.h"
|
2019-04-24 04:50:25 +02:00
|
|
|
#include "include/cef_request_context_handler.h"
|
2016-11-15 22:18:41 +01:00
|
|
|
#include "include/cef_waitable_event.h"
|
2015-10-03 01:03:16 +02:00
|
|
|
#include "include/wrapper/cef_closure_task.h"
|
2016-11-18 18:31:21 +01:00
|
|
|
#include "tests/ceftests/test_handler.h"
|
|
|
|
#include "tests/ceftests/test_util.h"
|
2016-11-18 00:52:42 +01:00
|
|
|
#include "tests/gtest/include/gtest/gtest.h"
|
2016-11-18 18:31:21 +01:00
|
|
|
#include "tests/shared/browser/client_app_browser.h"
|
2015-10-03 01:03:16 +02:00
|
|
|
|
|
|
|
namespace {
|
|
|
|
|
|
|
|
// Fully qualified preference names.
|
|
|
|
const char kPrefTest[] = "test";
|
|
|
|
const char kPrefTestBool[] = "test.bool";
|
|
|
|
const char kPrefTestInt[] = "test.int";
|
|
|
|
const char kPrefTestDouble[] = "test.double";
|
|
|
|
const char kPrefTestString[] = "test.string";
|
|
|
|
const char kPrefTestList[] = "test.list";
|
|
|
|
const char kPrefTestDict[] = "test.dict";
|
|
|
|
const char kPrefTestNoExist[] = "test.noexist";
|
|
|
|
|
|
|
|
// Unqualified preference names.
|
|
|
|
const char kPrefBool[] = "bool";
|
|
|
|
const char kPrefInt[] = "int";
|
|
|
|
const char kPrefDouble[] = "double";
|
|
|
|
const char kPrefString[] = "string";
|
|
|
|
const char kPrefList[] = "list";
|
|
|
|
const char kPrefDict[] = "dict";
|
|
|
|
|
2021-04-10 04:00:33 +02:00
|
|
|
std::string* PendingAction() {
|
|
|
|
static std::string str;
|
|
|
|
return &str;
|
|
|
|
}
|
|
|
|
|
2022-10-26 00:50:29 +02:00
|
|
|
CefRefPtr<CefValue> CreateBoolValue(bool value) {
|
|
|
|
auto val = CefValue::Create();
|
|
|
|
val->SetBool(value);
|
|
|
|
return val;
|
|
|
|
}
|
|
|
|
|
|
|
|
CefRefPtr<CefValue> CreateIntValue(int value) {
|
|
|
|
auto val = CefValue::Create();
|
|
|
|
val->SetInt(value);
|
|
|
|
return val;
|
|
|
|
}
|
|
|
|
|
|
|
|
CefRefPtr<CefValue> CreateDoubleValue(double value) {
|
|
|
|
auto val = CefValue::Create();
|
|
|
|
val->SetDouble(value);
|
|
|
|
return val;
|
|
|
|
}
|
|
|
|
|
|
|
|
CefRefPtr<CefValue> CreateStringValue(const std::string& value) {
|
|
|
|
auto val = CefValue::Create();
|
|
|
|
val->SetString(value);
|
|
|
|
return val;
|
|
|
|
}
|
|
|
|
|
|
|
|
CefRefPtr<CefValue> CreateListValue(CefRefPtr<CefListValue> value) {
|
|
|
|
auto val = CefValue::Create();
|
|
|
|
val->SetList(value);
|
|
|
|
return val;
|
|
|
|
}
|
|
|
|
|
|
|
|
CefRefPtr<CefValue> CreateDictionaryValue(CefRefPtr<CefDictionaryValue> value) {
|
|
|
|
auto val = CefValue::Create();
|
|
|
|
val->SetDictionary(value);
|
|
|
|
return val;
|
|
|
|
}
|
|
|
|
|
2015-10-03 01:03:16 +02:00
|
|
|
// Browser-side app delegate.
|
|
|
|
class PreferenceBrowserTest : public client::ClientAppBrowser::Delegate {
|
|
|
|
public:
|
|
|
|
PreferenceBrowserTest() {}
|
|
|
|
|
2022-10-26 00:50:29 +02:00
|
|
|
void OnRegisterCustomPreferences(
|
2015-10-03 01:03:16 +02:00
|
|
|
CefRefPtr<client::ClientAppBrowser> app,
|
2022-10-26 00:50:29 +02:00
|
|
|
cef_preferences_type_t type,
|
|
|
|
CefRawPtr<CefPreferenceRegistrar> registrar) override {
|
|
|
|
// Register test preferences.
|
|
|
|
registrar->AddPreference(kPrefTestBool, CreateBoolValue(true));
|
|
|
|
registrar->AddPreference(kPrefTestInt, CreateIntValue(2));
|
|
|
|
registrar->AddPreference(kPrefTestDouble, CreateDoubleValue(5.0));
|
|
|
|
registrar->AddPreference(kPrefTestString, CreateStringValue("default"));
|
|
|
|
registrar->AddPreference(kPrefTestList,
|
|
|
|
CreateListValue(CefListValue::Create()));
|
|
|
|
registrar->AddPreference(
|
|
|
|
kPrefTestDict, CreateDictionaryValue(CefDictionaryValue::Create()));
|
2015-10-03 01:03:16 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
IMPLEMENT_REFCOUNTING(PreferenceBrowserTest);
|
|
|
|
};
|
|
|
|
|
2022-10-26 00:50:29 +02:00
|
|
|
void ValidateReset(CefRefPtr<CefPreferenceManager> context, const char* name) {
|
2015-10-03 01:03:16 +02:00
|
|
|
EXPECT_TRUE(context->HasPreference(name));
|
|
|
|
EXPECT_TRUE(context->CanSetPreference(name));
|
|
|
|
|
|
|
|
CefString error;
|
2020-01-15 14:34:01 +01:00
|
|
|
EXPECT_TRUE(context->SetPreference(name, nullptr, error));
|
2015-10-03 01:03:16 +02:00
|
|
|
EXPECT_TRUE(error.empty());
|
|
|
|
}
|
|
|
|
|
2022-10-26 00:50:29 +02:00
|
|
|
void ValidateBool(CefRefPtr<CefPreferenceManager> context,
|
2015-10-03 01:03:16 +02:00
|
|
|
bool set,
|
|
|
|
bool expected,
|
|
|
|
const char* name = kPrefTestBool) {
|
|
|
|
EXPECT_TRUE(context->HasPreference(name));
|
|
|
|
EXPECT_TRUE(context->CanSetPreference(name));
|
|
|
|
|
|
|
|
if (set) {
|
|
|
|
CefString error;
|
2022-10-26 00:50:29 +02:00
|
|
|
EXPECT_TRUE(context->SetPreference(name, CreateBoolValue(expected), error));
|
2015-10-03 01:03:16 +02:00
|
|
|
EXPECT_TRUE(error.empty());
|
|
|
|
}
|
|
|
|
|
2022-10-26 00:50:29 +02:00
|
|
|
auto value = context->GetPreference(name);
|
2015-10-03 01:03:16 +02:00
|
|
|
EXPECT_TRUE(value.get());
|
|
|
|
EXPECT_EQ(VTYPE_BOOL, value->GetType());
|
2021-04-10 04:00:33 +02:00
|
|
|
EXPECT_EQ(expected, value->GetBool()) << *PendingAction();
|
2015-10-03 01:03:16 +02:00
|
|
|
}
|
|
|
|
|
2022-10-26 00:50:29 +02:00
|
|
|
void ValidateInt(CefRefPtr<CefPreferenceManager> context,
|
2015-10-03 01:03:16 +02:00
|
|
|
bool set,
|
|
|
|
int expected,
|
|
|
|
const char* name = kPrefTestInt) {
|
|
|
|
EXPECT_TRUE(context->HasPreference(name));
|
|
|
|
EXPECT_TRUE(context->CanSetPreference(name));
|
|
|
|
|
|
|
|
if (set) {
|
|
|
|
CefString error;
|
2022-10-26 00:50:29 +02:00
|
|
|
EXPECT_TRUE(context->SetPreference(name, CreateIntValue(expected), error));
|
2015-10-03 01:03:16 +02:00
|
|
|
EXPECT_TRUE(error.empty());
|
|
|
|
}
|
|
|
|
|
2022-10-26 00:50:29 +02:00
|
|
|
auto value = context->GetPreference(name);
|
2015-10-03 01:03:16 +02:00
|
|
|
EXPECT_TRUE(value.get());
|
|
|
|
EXPECT_EQ(VTYPE_INT, value->GetType());
|
2021-04-10 04:00:33 +02:00
|
|
|
EXPECT_EQ(expected, value->GetInt()) << *PendingAction();
|
2015-10-03 01:03:16 +02:00
|
|
|
}
|
|
|
|
|
2022-10-26 00:50:29 +02:00
|
|
|
void ValidateDouble(CefRefPtr<CefPreferenceManager> context,
|
2015-10-03 01:03:16 +02:00
|
|
|
bool set,
|
|
|
|
double expected,
|
|
|
|
const char* name = kPrefTestDouble) {
|
|
|
|
EXPECT_TRUE(context->HasPreference(name));
|
|
|
|
EXPECT_TRUE(context->CanSetPreference(name));
|
|
|
|
|
|
|
|
if (set) {
|
|
|
|
CefString error;
|
2022-10-26 00:50:29 +02:00
|
|
|
EXPECT_TRUE(
|
|
|
|
context->SetPreference(name, CreateDoubleValue(expected), error));
|
2015-10-03 01:03:16 +02:00
|
|
|
EXPECT_TRUE(error.empty());
|
|
|
|
}
|
|
|
|
|
2022-10-26 00:50:29 +02:00
|
|
|
auto value = context->GetPreference(name);
|
2015-10-03 01:03:16 +02:00
|
|
|
EXPECT_TRUE(value.get());
|
|
|
|
EXPECT_EQ(VTYPE_DOUBLE, value->GetType());
|
2021-04-10 04:00:33 +02:00
|
|
|
EXPECT_EQ(expected, value->GetDouble()) << *PendingAction();
|
2015-10-03 01:03:16 +02:00
|
|
|
}
|
|
|
|
|
2022-10-26 00:50:29 +02:00
|
|
|
void ValidateString(CefRefPtr<CefPreferenceManager> context,
|
2015-10-03 01:03:16 +02:00
|
|
|
bool set,
|
|
|
|
const std::string& expected,
|
|
|
|
const char* name = kPrefTestString) {
|
|
|
|
EXPECT_TRUE(context->HasPreference(name));
|
|
|
|
EXPECT_TRUE(context->CanSetPreference(name));
|
|
|
|
|
|
|
|
if (set) {
|
|
|
|
CefString error;
|
2022-10-26 00:50:29 +02:00
|
|
|
EXPECT_TRUE(
|
|
|
|
context->SetPreference(name, CreateStringValue(expected), error));
|
2015-10-03 01:03:16 +02:00
|
|
|
EXPECT_TRUE(error.empty());
|
|
|
|
}
|
|
|
|
|
2022-10-26 00:50:29 +02:00
|
|
|
auto value = context->GetPreference(name);
|
2015-10-03 01:03:16 +02:00
|
|
|
EXPECT_TRUE(value.get());
|
|
|
|
EXPECT_EQ(VTYPE_STRING, value->GetType());
|
2021-04-10 04:00:33 +02:00
|
|
|
EXPECT_STREQ(expected.c_str(), value->GetString().ToString().c_str())
|
|
|
|
<< *PendingAction();
|
2015-10-03 01:03:16 +02:00
|
|
|
}
|
|
|
|
|
2022-10-26 00:50:29 +02:00
|
|
|
void ValidateList(CefRefPtr<CefPreferenceManager> context,
|
2015-10-03 01:03:16 +02:00
|
|
|
bool set,
|
|
|
|
CefRefPtr<CefListValue> expected,
|
|
|
|
const char* name = kPrefTestList) {
|
|
|
|
EXPECT_TRUE(context->HasPreference(name));
|
|
|
|
EXPECT_TRUE(context->CanSetPreference(name));
|
|
|
|
|
|
|
|
if (set) {
|
|
|
|
CefString error;
|
2022-10-26 00:50:29 +02:00
|
|
|
EXPECT_TRUE(context->SetPreference(name, CreateListValue(expected), error));
|
2015-10-03 01:03:16 +02:00
|
|
|
EXPECT_TRUE(error.empty());
|
|
|
|
}
|
|
|
|
|
2022-10-26 00:50:29 +02:00
|
|
|
auto value = context->GetPreference(name);
|
2015-10-03 01:03:16 +02:00
|
|
|
EXPECT_TRUE(value.get());
|
|
|
|
EXPECT_EQ(VTYPE_LIST, value->GetType());
|
|
|
|
CefRefPtr<CefListValue> list_val = value->GetList();
|
|
|
|
EXPECT_TRUE(list_val);
|
|
|
|
TestListEqual(expected, list_val);
|
|
|
|
}
|
|
|
|
|
2022-10-26 00:50:29 +02:00
|
|
|
void ValidateDict(CefRefPtr<CefPreferenceManager> context,
|
2015-10-03 01:03:16 +02:00
|
|
|
bool set,
|
|
|
|
CefRefPtr<CefDictionaryValue> expected,
|
|
|
|
const char* name = kPrefTestDict) {
|
|
|
|
EXPECT_TRUE(context->HasPreference(name));
|
|
|
|
EXPECT_TRUE(context->CanSetPreference(name));
|
|
|
|
|
|
|
|
if (set) {
|
|
|
|
CefString error;
|
2022-10-26 00:50:29 +02:00
|
|
|
EXPECT_TRUE(
|
|
|
|
context->SetPreference(name, CreateDictionaryValue(expected), error));
|
2015-10-03 01:03:16 +02:00
|
|
|
EXPECT_TRUE(error.empty());
|
|
|
|
}
|
|
|
|
|
2022-10-26 00:50:29 +02:00
|
|
|
auto value = context->GetPreference(name);
|
2015-10-03 01:03:16 +02:00
|
|
|
EXPECT_TRUE(value.get());
|
|
|
|
EXPECT_EQ(VTYPE_DICTIONARY, value->GetType());
|
|
|
|
CefRefPtr<CefDictionaryValue> dict_val = value->GetDictionary();
|
|
|
|
EXPECT_TRUE(dict_val);
|
|
|
|
TestDictionaryEqual(expected, dict_val);
|
|
|
|
}
|
|
|
|
|
2022-10-26 00:50:29 +02:00
|
|
|
void ValidateNoExist(CefRefPtr<CefPreferenceManager> context,
|
2015-10-03 01:03:16 +02:00
|
|
|
bool set,
|
|
|
|
const char* name = kPrefTestNoExist) {
|
|
|
|
EXPECT_FALSE(context->HasPreference(name));
|
|
|
|
EXPECT_FALSE(context->CanSetPreference(name));
|
|
|
|
|
|
|
|
if (set) {
|
|
|
|
CefString error;
|
2022-10-26 00:50:29 +02:00
|
|
|
EXPECT_FALSE(context->SetPreference(name, CreateBoolValue(false), error));
|
2015-10-03 01:03:16 +02:00
|
|
|
EXPECT_FALSE(error.empty());
|
|
|
|
}
|
|
|
|
|
2022-10-26 00:50:29 +02:00
|
|
|
auto value = context->GetPreference(name);
|
2021-04-10 04:00:33 +02:00
|
|
|
EXPECT_FALSE(value.get()) << *PendingAction();
|
2015-10-03 01:03:16 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void PopulateRootDefaults(CefRefPtr<CefDictionaryValue> val) {
|
2022-10-26 00:50:29 +02:00
|
|
|
// Should match the values in OnRegisterCustomPreferences.
|
2015-10-03 01:03:16 +02:00
|
|
|
val->SetBool(kPrefBool, true);
|
|
|
|
val->SetInt(kPrefInt, 2);
|
|
|
|
val->SetDouble(kPrefDouble, 5.0);
|
|
|
|
val->SetString(kPrefString, "default");
|
|
|
|
val->SetList(kPrefList, CefListValue::Create());
|
|
|
|
val->SetDictionary(kPrefDict, CefDictionaryValue::Create());
|
|
|
|
}
|
|
|
|
|
|
|
|
void ValidateRoot(CefRefPtr<CefDictionaryValue> root,
|
|
|
|
CefRefPtr<CefDictionaryValue> expected,
|
|
|
|
const char* name = kPrefTest) {
|
|
|
|
EXPECT_TRUE(root->HasKey(kPrefTest));
|
|
|
|
EXPECT_EQ(VTYPE_DICTIONARY, root->GetType(kPrefTest));
|
|
|
|
|
|
|
|
CefRefPtr<CefDictionaryValue> actual = root->GetDictionary(kPrefTest);
|
|
|
|
TestDictionaryEqual(expected, actual);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Validate getting default values.
|
2022-10-26 00:50:29 +02:00
|
|
|
void ValidateDefaults(CefRefPtr<CefPreferenceManager> context,
|
2015-10-03 01:03:16 +02:00
|
|
|
bool reset,
|
2016-11-15 22:18:41 +01:00
|
|
|
CefRefPtr<CefWaitableEvent> event) {
|
2015-10-03 01:03:16 +02:00
|
|
|
if (!CefCurrentlyOn(TID_UI)) {
|
2021-06-19 21:54:45 +02:00
|
|
|
CefPostTask(TID_UI,
|
|
|
|
base::BindOnce(ValidateDefaults, context, reset, event));
|
2015-10-03 01:03:16 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (reset) {
|
|
|
|
// Reset default values.
|
|
|
|
ValidateReset(context, kPrefTestBool);
|
|
|
|
ValidateReset(context, kPrefTestInt);
|
|
|
|
ValidateReset(context, kPrefTestDouble);
|
|
|
|
ValidateReset(context, kPrefTestString);
|
|
|
|
ValidateReset(context, kPrefTestList);
|
|
|
|
ValidateReset(context, kPrefTestDict);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Test default values.
|
|
|
|
// Should match the values in CefBrowserPrefStore::CreateService.
|
|
|
|
ValidateBool(context, false, true);
|
|
|
|
ValidateInt(context, false, 2);
|
|
|
|
ValidateDouble(context, false, 5.0);
|
|
|
|
ValidateString(context, false, "default");
|
|
|
|
ValidateList(context, false, CefListValue::Create());
|
|
|
|
ValidateDict(context, false, CefDictionaryValue::Create());
|
|
|
|
ValidateNoExist(context, false);
|
|
|
|
|
|
|
|
// Expected value of the tests root.
|
|
|
|
CefRefPtr<CefDictionaryValue> expected = CefDictionaryValue::Create();
|
|
|
|
PopulateRootDefaults(expected);
|
|
|
|
|
|
|
|
// Test all preferences including defaults.
|
|
|
|
ValidateRoot(context->GetAllPreferences(true), expected);
|
|
|
|
|
|
|
|
// Test all preferences excluding defaults.
|
|
|
|
EXPECT_FALSE(context->GetAllPreferences(false)->HasKey(kPrefTest));
|
|
|
|
|
|
|
|
event->Signal();
|
|
|
|
}
|
|
|
|
|
|
|
|
void PopulateListValue(CefRefPtr<CefListValue> val) {
|
|
|
|
// Test list values.
|
|
|
|
val->SetInt(0, 54);
|
|
|
|
val->SetString(1, "foobar");
|
|
|
|
val->SetDouble(2, 99.7643);
|
|
|
|
}
|
|
|
|
|
|
|
|
void PopulateDictValue(CefRefPtr<CefDictionaryValue> val) {
|
|
|
|
// Test dictionary values.
|
|
|
|
val->SetString("key1", "some string");
|
|
|
|
val->SetBool("key2", false);
|
|
|
|
|
|
|
|
CefRefPtr<CefListValue> list_val = CefListValue::Create();
|
|
|
|
PopulateListValue(list_val);
|
|
|
|
val->SetList("key3", list_val);
|
|
|
|
}
|
|
|
|
|
|
|
|
void PopulateRootSet(CefRefPtr<CefDictionaryValue> val) {
|
|
|
|
CefRefPtr<CefListValue> list_val = CefListValue::Create();
|
|
|
|
CefRefPtr<CefDictionaryValue> dict_val = CefDictionaryValue::Create();
|
|
|
|
|
|
|
|
PopulateListValue(list_val);
|
|
|
|
PopulateDictValue(dict_val);
|
|
|
|
|
|
|
|
// Should match the values in ValidateSetGet and ValidateGet.
|
|
|
|
val->SetBool(kPrefBool, true);
|
|
|
|
val->SetInt(kPrefInt, 65);
|
|
|
|
val->SetDouble(kPrefDouble, 54.5443);
|
|
|
|
val->SetString(kPrefString, "My test string");
|
|
|
|
val->SetList(kPrefList, list_val);
|
|
|
|
val->SetDictionary(kPrefDict, dict_val);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Validate getting and setting values.
|
2022-10-26 00:50:29 +02:00
|
|
|
void ValidateSetGet(CefRefPtr<CefPreferenceManager> context,
|
2016-11-15 22:18:41 +01:00
|
|
|
CefRefPtr<CefWaitableEvent> event) {
|
2015-10-03 01:03:16 +02:00
|
|
|
if (!CefCurrentlyOn(TID_UI)) {
|
2021-06-19 21:54:45 +02:00
|
|
|
CefPostTask(TID_UI, base::BindOnce(ValidateSetGet, context, event));
|
2015-10-03 01:03:16 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
CefRefPtr<CefListValue> list_val = CefListValue::Create();
|
|
|
|
CefRefPtr<CefDictionaryValue> dict_val = CefDictionaryValue::Create();
|
|
|
|
|
|
|
|
PopulateListValue(list_val);
|
|
|
|
PopulateDictValue(dict_val);
|
|
|
|
|
|
|
|
// Test setting/getting values.
|
|
|
|
// Should match the values in PopulateRootSet and ValidateGet.
|
|
|
|
ValidateBool(context, true, true);
|
|
|
|
ValidateInt(context, true, 65);
|
|
|
|
ValidateDouble(context, true, 54.5443);
|
|
|
|
ValidateString(context, true, "My test string");
|
|
|
|
ValidateList(context, true, list_val);
|
|
|
|
ValidateDict(context, true, dict_val);
|
|
|
|
ValidateNoExist(context, true);
|
|
|
|
|
|
|
|
// Expected value of the tests root.
|
|
|
|
CefRefPtr<CefDictionaryValue> expected = CefDictionaryValue::Create();
|
|
|
|
PopulateRootSet(expected);
|
|
|
|
|
|
|
|
// Validate all preferences including defaults.
|
|
|
|
ValidateRoot(context->GetAllPreferences(true), expected);
|
|
|
|
|
|
|
|
// Validate all preferences excluding defaults.
|
|
|
|
ValidateRoot(context->GetAllPreferences(false), expected);
|
|
|
|
|
|
|
|
event->Signal();
|
|
|
|
}
|
|
|
|
|
|
|
|
// Validate getting values.
|
2022-10-26 00:50:29 +02:00
|
|
|
void ValidateGet(CefRefPtr<CefPreferenceManager> context,
|
2016-11-15 22:18:41 +01:00
|
|
|
CefRefPtr<CefWaitableEvent> event) {
|
2015-10-03 01:03:16 +02:00
|
|
|
if (!CefCurrentlyOn(TID_UI)) {
|
2021-06-19 21:54:45 +02:00
|
|
|
CefPostTask(TID_UI, base::BindOnce(ValidateGet, context, event));
|
2015-10-03 01:03:16 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
CefRefPtr<CefListValue> list_val = CefListValue::Create();
|
|
|
|
CefRefPtr<CefDictionaryValue> dict_val = CefDictionaryValue::Create();
|
|
|
|
|
|
|
|
PopulateListValue(list_val);
|
|
|
|
PopulateDictValue(dict_val);
|
|
|
|
|
|
|
|
// Test getting values.
|
|
|
|
// Should match the values in PopulateRootSet and ValidateSetGet.
|
|
|
|
ValidateBool(context, false, true);
|
|
|
|
ValidateInt(context, false, 65);
|
|
|
|
ValidateDouble(context, false, 54.5443);
|
|
|
|
ValidateString(context, false, "My test string");
|
|
|
|
ValidateList(context, false, list_val);
|
|
|
|
ValidateDict(context, false, dict_val);
|
|
|
|
ValidateNoExist(context, false);
|
|
|
|
|
|
|
|
// Expected value of the tests root.
|
|
|
|
CefRefPtr<CefDictionaryValue> expected = CefDictionaryValue::Create();
|
|
|
|
PopulateRootSet(expected);
|
|
|
|
|
|
|
|
// Validate all preferences including defaults.
|
|
|
|
ValidateRoot(context->GetAllPreferences(true), expected);
|
|
|
|
|
|
|
|
// Validate all preferences excluding defaults.
|
|
|
|
ValidateRoot(context->GetAllPreferences(false), expected);
|
|
|
|
|
|
|
|
event->Signal();
|
|
|
|
}
|
|
|
|
|
|
|
|
// No-op implementation.
|
|
|
|
class TestRequestContextHandler : public CefRequestContextHandler {
|
|
|
|
public:
|
|
|
|
TestRequestContextHandler() {}
|
2021-04-15 01:28:22 +02:00
|
|
|
explicit TestRequestContextHandler(CefRefPtr<CefWaitableEvent> event)
|
|
|
|
: event_(event) {}
|
|
|
|
|
|
|
|
void OnRequestContextInitialized(
|
|
|
|
CefRefPtr<CefRequestContext> context) override {
|
|
|
|
if (event_) {
|
|
|
|
event_->Signal();
|
|
|
|
event_ = nullptr;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
CefRefPtr<CefWaitableEvent> event_;
|
2015-10-03 01:03:16 +02:00
|
|
|
|
|
|
|
IMPLEMENT_REFCOUNTING(TestRequestContextHandler);
|
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace
|
|
|
|
|
2022-10-26 00:50:29 +02:00
|
|
|
// Verify default preference values on the global state.
|
2015-10-03 01:03:16 +02:00
|
|
|
TEST(PreferenceTest, GlobalDefaults) {
|
2016-11-15 22:18:41 +01:00
|
|
|
CefRefPtr<CefWaitableEvent> event =
|
|
|
|
CefWaitableEvent::CreateWaitableEvent(true, false);
|
2015-10-03 01:03:16 +02:00
|
|
|
|
2022-10-26 00:50:29 +02:00
|
|
|
auto context = CefPreferenceManager::GetGlobalPreferenceManager();
|
2015-10-03 01:03:16 +02:00
|
|
|
EXPECT_TRUE(context.get());
|
|
|
|
|
2016-11-15 22:18:41 +01:00
|
|
|
ValidateDefaults(context, false, event);
|
|
|
|
event->Wait();
|
2015-10-03 01:03:16 +02:00
|
|
|
}
|
|
|
|
|
2022-10-26 00:50:29 +02:00
|
|
|
// Verify setting/getting preference values on the global state.
|
2015-10-03 01:03:16 +02:00
|
|
|
TEST(PreferenceTest, GlobalSetGet) {
|
2016-11-15 22:18:41 +01:00
|
|
|
CefRefPtr<CefWaitableEvent> event =
|
|
|
|
CefWaitableEvent::CreateWaitableEvent(true, false);
|
2015-10-03 01:03:16 +02:00
|
|
|
|
2022-10-26 00:50:29 +02:00
|
|
|
auto context = CefPreferenceManager::GetGlobalPreferenceManager();
|
|
|
|
EXPECT_TRUE(context.get());
|
|
|
|
|
|
|
|
ValidateSetGet(context, event);
|
|
|
|
event->Wait();
|
|
|
|
|
|
|
|
// Reset to the default values.
|
|
|
|
ValidateDefaults(context, true, event);
|
|
|
|
event->Wait();
|
|
|
|
}
|
|
|
|
|
|
|
|
// Verify default preference values on the global request context.
|
|
|
|
TEST(PreferenceTest, RequestContextGlobalDefaults) {
|
|
|
|
CefRefPtr<CefWaitableEvent> event =
|
|
|
|
CefWaitableEvent::CreateWaitableEvent(true, false);
|
|
|
|
|
|
|
|
CefRefPtr<CefRequestContext> context = CefRequestContext::GetGlobalContext();
|
|
|
|
EXPECT_TRUE(context.get());
|
|
|
|
|
|
|
|
ValidateDefaults(context, false, event);
|
|
|
|
event->Wait();
|
|
|
|
}
|
|
|
|
|
|
|
|
// Verify setting/getting preference values on the global request context.
|
|
|
|
TEST(PreferenceTest, RequestContextGlobalSetGet) {
|
|
|
|
CefRefPtr<CefWaitableEvent> event =
|
|
|
|
CefWaitableEvent::CreateWaitableEvent(true, false);
|
|
|
|
|
2015-10-03 01:03:16 +02:00
|
|
|
CefRefPtr<CefRequestContext> context = CefRequestContext::GetGlobalContext();
|
|
|
|
EXPECT_TRUE(context.get());
|
|
|
|
|
2016-11-15 22:18:41 +01:00
|
|
|
ValidateSetGet(context, event);
|
|
|
|
event->Wait();
|
2015-10-03 01:03:16 +02:00
|
|
|
|
|
|
|
// Reset to the default values.
|
2016-11-15 22:18:41 +01:00
|
|
|
ValidateDefaults(context, true, event);
|
|
|
|
event->Wait();
|
2015-10-03 01:03:16 +02:00
|
|
|
}
|
|
|
|
|
2022-10-26 00:50:29 +02:00
|
|
|
// Verify setting/getting preference values on shared global request contexts.
|
|
|
|
TEST(PreferenceTest, RequestContextGlobalSetGetShared) {
|
2016-11-15 22:18:41 +01:00
|
|
|
CefRefPtr<CefWaitableEvent> event =
|
|
|
|
CefWaitableEvent::CreateWaitableEvent(true, false);
|
2015-10-03 01:03:16 +02:00
|
|
|
|
|
|
|
CefRefPtr<CefRequestContext> context = CefRequestContext::GetGlobalContext();
|
|
|
|
EXPECT_TRUE(context.get());
|
|
|
|
|
|
|
|
// Sharing storage.
|
|
|
|
CefRefPtr<CefRequestContext> context2 =
|
2020-01-15 14:34:01 +01:00
|
|
|
CefRequestContext::CreateContext(context, nullptr);
|
2015-10-03 01:03:16 +02:00
|
|
|
EXPECT_TRUE(context2.get());
|
|
|
|
|
|
|
|
// Sharing storage.
|
|
|
|
CefRefPtr<CefRequestContext> context3 =
|
|
|
|
CefRequestContext::CreateContext(context, new TestRequestContextHandler);
|
|
|
|
EXPECT_TRUE(context3.get());
|
|
|
|
|
|
|
|
// Unassociated context.
|
|
|
|
CefRequestContextSettings settings;
|
2021-04-15 01:28:22 +02:00
|
|
|
CefRefPtr<CefRequestContext> context4 = CefRequestContext::CreateContext(
|
|
|
|
settings, new TestRequestContextHandler(event));
|
2021-04-10 04:00:33 +02:00
|
|
|
EXPECT_TRUE(context4.get());
|
2021-04-15 01:28:22 +02:00
|
|
|
// Wait for the context to be fully initialized.
|
|
|
|
event->Wait();
|
2015-10-03 01:03:16 +02:00
|
|
|
|
|
|
|
// Set/get the values on the first context.
|
2021-04-10 04:00:33 +02:00
|
|
|
*PendingAction() = "Set/get the values on the first context";
|
2016-11-15 22:18:41 +01:00
|
|
|
ValidateSetGet(context, event);
|
|
|
|
event->Wait();
|
2015-10-03 01:03:16 +02:00
|
|
|
|
|
|
|
// Get the values from the 2nd and 3rd contexts. They should be the same.
|
2021-04-10 04:00:33 +02:00
|
|
|
*PendingAction() = "Get the values from the 2nd context.";
|
2016-11-15 22:18:41 +01:00
|
|
|
ValidateGet(context2, event);
|
|
|
|
event->Wait();
|
2021-04-10 04:00:33 +02:00
|
|
|
*PendingAction() = "Get the values from the 3rd context.";
|
2016-11-15 22:18:41 +01:00
|
|
|
ValidateGet(context3, event);
|
|
|
|
event->Wait();
|
2015-10-03 01:03:16 +02:00
|
|
|
|
2021-04-10 04:00:33 +02:00
|
|
|
// 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);
|
|
|
|
}
|
2016-11-15 22:18:41 +01:00
|
|
|
event->Wait();
|
2015-10-03 01:03:16 +02:00
|
|
|
|
|
|
|
// Reset to the default values.
|
2021-04-10 04:00:33 +02:00
|
|
|
*PendingAction() = "Reset to the default values.";
|
2016-11-15 22:18:41 +01:00
|
|
|
ValidateDefaults(context, true, event);
|
|
|
|
event->Wait();
|
2015-10-03 01:03:16 +02:00
|
|
|
}
|
|
|
|
|
2022-10-26 00:50:29 +02:00
|
|
|
// Verify default preference values on a custom request context.
|
|
|
|
TEST(PreferenceTest, RequestContextCustomDefaults) {
|
2016-11-15 22:18:41 +01:00
|
|
|
CefRefPtr<CefWaitableEvent> event =
|
|
|
|
CefWaitableEvent::CreateWaitableEvent(true, false);
|
2015-10-03 01:03:16 +02:00
|
|
|
|
|
|
|
CefRequestContextSettings settings;
|
2021-04-15 01:28:22 +02:00
|
|
|
CefRefPtr<CefRequestContext> context = CefRequestContext::CreateContext(
|
|
|
|
settings, new TestRequestContextHandler(event));
|
2015-10-03 01:03:16 +02:00
|
|
|
EXPECT_TRUE(context.get());
|
2021-04-15 01:28:22 +02:00
|
|
|
// Wait for the context to be fully initialized.
|
|
|
|
event->Wait();
|
2015-10-03 01:03:16 +02:00
|
|
|
|
2016-11-15 22:18:41 +01:00
|
|
|
ValidateDefaults(context, false, event);
|
|
|
|
event->Wait();
|
2015-10-03 01:03:16 +02:00
|
|
|
}
|
|
|
|
|
2022-10-26 00:50:29 +02:00
|
|
|
// Verify setting/getting preference values on a custom request context.
|
|
|
|
TEST(PreferenceTest, RequestContextCustomSetGet) {
|
2016-11-15 22:18:41 +01:00
|
|
|
CefRefPtr<CefWaitableEvent> event =
|
|
|
|
CefWaitableEvent::CreateWaitableEvent(true, false);
|
2015-10-03 01:03:16 +02:00
|
|
|
|
|
|
|
CefRequestContextSettings settings;
|
2021-04-15 01:28:22 +02:00
|
|
|
CefRefPtr<CefRequestContext> context = CefRequestContext::CreateContext(
|
|
|
|
settings, new TestRequestContextHandler(event));
|
2015-10-03 01:03:16 +02:00
|
|
|
EXPECT_TRUE(context.get());
|
2021-04-15 01:28:22 +02:00
|
|
|
// Wait for the context to be fully initialized.
|
|
|
|
event->Wait();
|
2015-10-03 01:03:16 +02:00
|
|
|
|
2016-11-15 22:18:41 +01:00
|
|
|
ValidateSetGet(context, event);
|
|
|
|
event->Wait();
|
2015-10-03 01:03:16 +02:00
|
|
|
|
|
|
|
// Reset to the default values.
|
2016-11-15 22:18:41 +01:00
|
|
|
ValidateDefaults(context, true, event);
|
|
|
|
event->Wait();
|
2015-10-03 01:03:16 +02:00
|
|
|
}
|
|
|
|
|
2022-10-26 00:50:29 +02:00
|
|
|
// Verify setting/getting preference values on shared custom request contexts.
|
|
|
|
TEST(PreferenceTest, RequestContextCustomSetGetShared) {
|
2016-11-15 22:18:41 +01:00
|
|
|
CefRefPtr<CefWaitableEvent> event =
|
|
|
|
CefWaitableEvent::CreateWaitableEvent(true, false);
|
2015-10-03 01:03:16 +02:00
|
|
|
|
|
|
|
CefRequestContextSettings settings;
|
2021-04-15 01:28:22 +02:00
|
|
|
CefRefPtr<CefRequestContext> context = CefRequestContext::CreateContext(
|
|
|
|
settings, new TestRequestContextHandler(event));
|
2015-10-03 01:03:16 +02:00
|
|
|
EXPECT_TRUE(context.get());
|
2021-04-15 01:28:22 +02:00
|
|
|
// Wait for the context to be fully initialized.
|
|
|
|
event->Wait();
|
2015-10-03 01:03:16 +02:00
|
|
|
|
|
|
|
// Sharing storage.
|
|
|
|
CefRefPtr<CefRequestContext> context2 =
|
2020-01-15 14:34:01 +01:00
|
|
|
CefRequestContext::CreateContext(context, nullptr);
|
2015-10-03 01:03:16 +02:00
|
|
|
EXPECT_TRUE(context2.get());
|
|
|
|
|
|
|
|
// Sharing storage.
|
|
|
|
CefRefPtr<CefRequestContext> context3 =
|
|
|
|
CefRequestContext::CreateContext(context, new TestRequestContextHandler);
|
|
|
|
EXPECT_TRUE(context3.get());
|
|
|
|
|
|
|
|
// Unassociated context.
|
2021-04-15 01:28:22 +02:00
|
|
|
CefRefPtr<CefRequestContext> context4 = CefRequestContext::CreateContext(
|
|
|
|
settings, new TestRequestContextHandler(event));
|
2021-04-10 04:00:33 +02:00
|
|
|
EXPECT_TRUE(context4.get());
|
2021-04-15 01:28:22 +02:00
|
|
|
// Wait for the context to be fully initialized.
|
|
|
|
event->Wait();
|
2015-10-03 01:03:16 +02:00
|
|
|
|
|
|
|
// Set/get the values on the first context.
|
2021-04-10 04:00:33 +02:00
|
|
|
*PendingAction() = "Set/get the values on the first context";
|
2016-11-15 22:18:41 +01:00
|
|
|
ValidateSetGet(context, event);
|
|
|
|
event->Wait();
|
2015-10-03 01:03:16 +02:00
|
|
|
|
|
|
|
// Get the values from the 2nd and 3d contexts. They should be the same.
|
2021-04-10 04:00:33 +02:00
|
|
|
*PendingAction() = "Get the values from the 2nd context.";
|
2016-11-15 22:18:41 +01:00
|
|
|
ValidateGet(context2, event);
|
|
|
|
event->Wait();
|
2021-04-10 04:00:33 +02:00
|
|
|
*PendingAction() = "Get the values from the 3rd context.";
|
2016-11-15 22:18:41 +01:00
|
|
|
ValidateGet(context3, event);
|
|
|
|
event->Wait();
|
2015-10-03 01:03:16 +02:00
|
|
|
|
|
|
|
// Get the values from the 4th context. They should be at the default.
|
2021-04-10 04:00:33 +02:00
|
|
|
// 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.";
|
2016-11-15 22:18:41 +01:00
|
|
|
ValidateDefaults(context4, false, event);
|
|
|
|
event->Wait();
|
2015-10-03 01:03:16 +02:00
|
|
|
|
|
|
|
// Reset to the default values.
|
2021-04-10 04:00:33 +02:00
|
|
|
*PendingAction() = "Reset to the default values.";
|
2016-11-15 22:18:41 +01:00
|
|
|
ValidateDefaults(context, true, event);
|
|
|
|
event->Wait();
|
2015-10-03 01:03:16 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// Entry point for creating preference browser test objects.
|
|
|
|
// Called from client_app_delegates.cc.
|
|
|
|
void CreatePreferenceBrowserTests(
|
|
|
|
client::ClientAppBrowser::DelegateSet& delegates) {
|
|
|
|
delegates.insert(new PreferenceBrowserTest);
|
|
|
|
}
|