tests: Fix SchemeHandlerTest failure with ReduceAcceptLanguage trial

This commit is contained in:
Marshall Greenblatt 2024-05-23 15:39:07 -04:00
parent 701fc03f00
commit bd1e188c77
8 changed files with 91 additions and 9 deletions

View File

@ -33,7 +33,7 @@
// by hand. See the translator.README.txt file in the tools directory for
// more information.
//
// $hash=db81a65aba3c2d1213744ad4251322acf97c608c$
// $hash=da2edf5e08eb45942b6a82109aa86682c202ccac$
//
#ifndef CEF_INCLUDE_CAPI_TEST_CEF_TEST_HELPERS_CAPI_H_
@ -67,6 +67,14 @@ CEF_EXPORT void cef_execute_java_script_with_user_gesture_for_tests(
///
CEF_EXPORT void cef_set_data_directory_for_tests(const cef_string_t* dir);
///
/// Returns true (1) if |feature_name| is enabled by default, command line or
/// field trial. This supports a short list of curated values that are queried
/// by unit tests.
///
CEF_EXPORT int cef_is_feature_enabled_for_tests(
const cef_string_t* feature_name);
#ifdef __cplusplus
}
#endif

View File

@ -42,13 +42,13 @@
// way that may cause binary incompatibility with other builds. The universal
// hash value will change if any platform is affected whereas the platform hash
// values will change only if that particular platform is affected.
#define CEF_API_HASH_UNIVERSAL "a600703f7e1ff2c897b6ee0a77123fdfe25501f7"
#define CEF_API_HASH_UNIVERSAL "100bd8428968266a67128c02f63e2fd5aaa90d28"
#if defined(OS_WIN)
#define CEF_API_HASH_PLATFORM "1af2a8ac18627ab06e6012ab57f0e3edb9bbd426"
#define CEF_API_HASH_PLATFORM "d5cba94f734fb1966f098fad5cc5f342a5d14afe"
#elif defined(OS_MAC)
#define CEF_API_HASH_PLATFORM "7b7d434bce93b2176cd1bb9332f12929db1e85b9"
#define CEF_API_HASH_PLATFORM "f5554ef4857432df5d22a14a9df7f3b1248c3265"
#elif defined(OS_LINUX)
#define CEF_API_HASH_PLATFORM "51042cfa82f6dd179acba9848cb7418b2c24b514"
#define CEF_API_HASH_PLATFORM "5c283fac1f398ae4a5a5c2f16a4984267034950f"
#endif
#ifdef __cplusplus

View File

@ -67,4 +67,12 @@ void CefExecuteJavaScriptWithUserGestureForTests(CefRefPtr<CefFrame> frame,
/*--cef()--*/
void CefSetDataDirectoryForTests(const CefString& dir);
///
/// Returns true if |feature_name| is enabled by default, command line or field
/// trial. This supports a short list of curated values that are queried by unit
/// tests.
///
/*--cef()--*/
bool CefIsFeatureEnabledForTests(const CefString& feature_name);
#endif // CEF_INCLUDE_TEST_CEF_TEST_HELPERS_H_

View File

@ -2,12 +2,30 @@
// reserved. Use of this source code is governed by a BSD-style license that
// can be found in the LICENSE file.
#include "base/feature_list.h"
#include "base/files/file_path.h"
#include "base/path_service.h"
#include "cef/include/test/cef_test_helpers.h"
#include "services/network/public/cpp/features.h"
void CefSetDataDirectoryForTests(const CefString& dir) {
base::PathService::OverrideAndCreateIfNeeded(
base::DIR_SRC_TEST_DATA_ROOT, base::FilePath(dir), /*is_absolute=*/true,
/*create=*/false);
}
bool CefIsFeatureEnabledForTests(const CefString& feature_name) {
// Only includes values that are queried by unit tests.
const base::Feature* features[] = {
&network::features::kReduceAcceptLanguage,
};
const std::string& name = feature_name;
for (auto* feature : features) {
if (feature->name == name) {
return base::FeatureList::IsEnabled(*feature);
}
}
LOG(FATAL) << "Feature " << name << " is not supported";
}

View File

@ -9,7 +9,7 @@
// implementations. See the translator.README.txt file in the tools directory
// for more information.
//
// $hash=716d8a4bb86c9ee9ebe8dfe28ec2c37411507830$
// $hash=bc230d77e2985959bc5a6a2af80b500eec070384$
//
#include "include/capi/cef_app_capi.h"
@ -948,3 +948,20 @@ CEF_EXPORT void cef_set_data_directory_for_tests(const cef_string_t* dir) {
// Execute
CefSetDataDirectoryForTests(CefString(dir));
}
CEF_EXPORT int cef_is_feature_enabled_for_tests(
const cef_string_t* feature_name) {
// AUTO-GENERATED CONTENT - DELETE THIS COMMENT BEFORE MODIFYING
// Verify param: feature_name; type: string_byref_const
DCHECK(feature_name);
if (!feature_name) {
return 0;
}
// Execute
bool _retval = CefIsFeatureEnabledForTests(CefString(feature_name));
// Return type: bool
return _retval;
}

View File

@ -9,7 +9,7 @@
// implementations. See the translator.README.txt file in the tools directory
// for more information.
//
// $hash=fd77a51eeea378bb56d43ba2995a0417d905c247$
// $hash=641096b7a6d43e8f7fbb4aad3c5ee870717b7f32$
//
#include <dlfcn.h>
@ -146,6 +146,7 @@ struct libcef_pointers {
decltype(&cef_execute_java_script_with_user_gesture_for_tests)
cef_execute_java_script_with_user_gesture_for_tests;
decltype(&cef_set_data_directory_for_tests) cef_set_data_directory_for_tests;
decltype(&cef_is_feature_enabled_for_tests) cef_is_feature_enabled_for_tests;
decltype(&cef_browser_host_create_browser) cef_browser_host_create_browser;
decltype(&cef_browser_host_create_browser_sync)
cef_browser_host_create_browser_sync;
@ -385,6 +386,7 @@ int libcef_init_pointers(const char* path) {
INIT_ENTRY(cef_register_extension);
INIT_ENTRY(cef_execute_java_script_with_user_gesture_for_tests);
INIT_ENTRY(cef_set_data_directory_for_tests);
INIT_ENTRY(cef_is_feature_enabled_for_tests);
INIT_ENTRY(cef_browser_host_create_browser);
INIT_ENTRY(cef_browser_host_create_browser_sync);
INIT_ENTRY(cef_command_line_create);
@ -858,6 +860,11 @@ void cef_set_data_directory_for_tests(const cef_string_t* dir) {
g_libcef_pointers.cef_set_data_directory_for_tests(dir);
}
NO_SANITIZE("cfi-icall")
int cef_is_feature_enabled_for_tests(const cef_string_t* feature_name) {
return g_libcef_pointers.cef_is_feature_enabled_for_tests(feature_name);
}
NO_SANITIZE("cfi-icall")
int cef_browser_host_create_browser(
const struct _cef_window_info_t* windowInfo,

View File

@ -9,7 +9,7 @@
// implementations. See the translator.README.txt file in the tools directory
// for more information.
//
// $hash=23f943f8e59a48f29ba3095642bc05d7f987a2f2$
// $hash=16d4e51ecbe1fd8eb6915d951a84f707f73dfb1a$
//
#include "include/capi/cef_app_capi.h"
@ -885,3 +885,20 @@ CEF_GLOBAL void CefSetDataDirectoryForTests(const CefString& dir) {
// Execute
cef_set_data_directory_for_tests(dir.GetStruct());
}
NO_SANITIZE("cfi-icall")
CEF_GLOBAL bool CefIsFeatureEnabledForTests(const CefString& feature_name) {
// AUTO-GENERATED CONTENT - DELETE THIS COMMENT BEFORE MODIFYING
// Verify param: feature_name; type: string_byref_const
DCHECK(!feature_name.empty());
if (feature_name.empty()) {
return false;
}
// Execute
int _retval = cef_is_feature_enabled_for_tests(feature_name.GetStruct());
// Return type: bool
return _retval ? true : false;
}

View File

@ -11,6 +11,7 @@
#include "include/cef_request_context.h"
#include "include/cef_request_context_handler.h"
#include "include/cef_scheme.h"
#include "include/test/cef_test_helpers.h"
#include "include/wrapper/cef_closure_task.h"
#include "tests/ceftests/test_handler.h"
#include "tests/ceftests/test_suite.h"
@ -465,7 +466,13 @@ class ClientSchemeHandler : public CefResourceHandler {
// CEF_SETTINGS_ACCEPT_LANGUAGE value from
// CefSettings.accept_language_list set in CefTestSuite::GetSettings()
// and expanded internally by ComputeAcceptLanguageFromPref.
EXPECT_STREQ("en-GB,en;q=0.9", accept_language.data());
if (CefIsFeatureEnabledForTests("ReduceAcceptLanguage")) {
EXPECT_TRUE(accept_language == "en-GB" ||
accept_language == "en-GB,en;q=0.9")
<< accept_language;
} else {
EXPECT_STREQ("en-GB,en;q=0.9", accept_language.data());
}
}
// Continue or cancel the request immediately based on the return value.