From 64c2dc13cadd53ea74085ccc8c7120b1b8708236 Mon Sep 17 00:00:00 2001 From: Marshall Greenblatt Date: Thu, 5 Oct 2023 16:54:42 -0400 Subject: [PATCH] Remove CefBrowserSettings.accept_language_list (fixes #3555) Chromium does not support configuration of this value on a per-Browser basis. --- include/cef_api_hash.h | 8 +- include/internal/cef_types.h | 25 +- include/internal/cef_types_wrappers.h | 5 - .../resource_request_handler_wrapper.cc | 3 +- libcef/browser/prefs/browser_prefs.cc | 35 +-- libcef/browser/prefs/browser_prefs.h | 5 +- tests/ceftests/scheme_handler_unittest.cc | 296 ++++++++++-------- tests/ceftests/test_handler.cc | 1 - tests/ceftests/test_handler.h | 3 - 9 files changed, 186 insertions(+), 195 deletions(-) diff --git a/include/cef_api_hash.h b/include/cef_api_hash.h index 9784d937b..024b8ed5e 100644 --- a/include/cef_api_hash.h +++ b/include/cef_api_hash.h @@ -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 "abeac9ee5411570f5e39d9242cba575a19439f86" +#define CEF_API_HASH_UNIVERSAL "f8f0a0431b4cf46f98e3e58af93199f21d403d69" #if defined(OS_WIN) -#define CEF_API_HASH_PLATFORM "85fba672bea98e3687ccfc28c4a509ca70240990" +#define CEF_API_HASH_PLATFORM "e5142124a2c423c0c438909bbfb86cd35a2b839d" #elif defined(OS_MAC) -#define CEF_API_HASH_PLATFORM "3c960598536b6e112d3857d19d01f05e49474f86" +#define CEF_API_HASH_PLATFORM "5748f4bc71b501c804ef284e091e6eea847086d9" #elif defined(OS_LINUX) -#define CEF_API_HASH_PLATFORM "821845ef5f7ea8618f7425a4096702205f4b346b" +#define CEF_API_HASH_PLATFORM "23413591633deaf08aae5248becdb0118b105de1" #endif #ifdef __cplusplus diff --git a/include/internal/cef_types.h b/include/internal/cef_types.h index 2ff399a9c..71227a027 100644 --- a/include/internal/cef_types.h +++ b/include/internal/cef_types.h @@ -449,10 +449,9 @@ typedef struct _cef_settings_t { /// /// Comma delimited ordered list of language codes without any whitespace that - /// will be used in the "Accept-Language" HTTP header. May be overridden on a - /// per-browser basis using the CefBrowserSettings.accept_language_list value. - /// If both values are empty then "en-US,en" will be used. Can be overridden - /// for individual CefRequestContext instances via the + /// will be used in the "Accept-Language" HTTP request header and + /// "navigator.language" JS attribute. Can be overridden for individual + /// CefRequestContext instances via the /// CefRequestContextSettings.accept_language_list value. /// cef_string_t accept_language_list; @@ -515,11 +514,11 @@ typedef struct _cef_request_context_settings_t { /// /// Comma delimited ordered list of language codes without any whitespace that - /// will be used in the "Accept-Language" HTTP header. Can be set globally - /// using the CefSettings.accept_language_list value or overridden on a per- - /// browser basis using the CefBrowserSettings.accept_language_list value. If - /// all values are empty then "en-US,en" will be used. This value will be - /// ignored if |cache_path| matches the CefSettings.cache_path value. + /// will be used in the "Accept-Language" HTTP request header and + /// "navigator.language" JS attribute. Can be set globally using the + /// CefSettings.accept_language_list value. If all values are empty then + /// "en-US,en" will be used. This value will be ignored if |cache_path| + /// matches the CefSettings.cache_path value. /// cef_string_t accept_language_list; @@ -673,14 +672,6 @@ typedef struct _cef_browser_settings_t { /// cef_color_t background_color; - /// - /// Comma delimited ordered list of language codes without any whitespace that - /// will be used in the "Accept-Language" HTTP header. May be set globally - /// using the CefSettings.accept_language_list value. If both values are - /// empty then "en-US,en" will be used. - /// - cef_string_t accept_language_list; - /// /// Controls whether the Chrome status bubble will be used. Only supported /// with the Chrome runtime. For details about the status bubble see diff --git a/include/internal/cef_types_wrappers.h b/include/internal/cef_types_wrappers.h index 33a367044..9d606b355 100644 --- a/include/internal/cef_types_wrappers.h +++ b/include/internal/cef_types_wrappers.h @@ -487,7 +487,6 @@ struct CefBrowserSettingsTraits { cef_string_clear(&s->cursive_font_family); cef_string_clear(&s->fantasy_font_family); cef_string_clear(&s->default_encoding); - cef_string_clear(&s->accept_language_list); } static inline void set(const struct_type* src, @@ -536,10 +535,6 @@ struct CefBrowserSettingsTraits { target->background_color = src->background_color; - cef_string_set(src->accept_language_list.str, - src->accept_language_list.length, - &target->accept_language_list, copy); - target->chrome_status_bubble = src->chrome_status_bubble; target->chrome_zoom_bubble = src->chrome_zoom_bubble; } diff --git a/libcef/browser/net_service/resource_request_handler_wrapper.cc b/libcef/browser/net_service/resource_request_handler_wrapper.cc index de9b302ca..7efaa7e74 100644 --- a/libcef/browser/net_service/resource_request_handler_wrapper.cc +++ b/libcef/browser/net_service/resource_request_handler_wrapper.cc @@ -274,8 +274,7 @@ class InterceptedRequestHandlerWrapper : public InterceptedRequestHandler { unhandled_request_callback_ = unhandled_request_callback; // Default values for standard headers. - accept_language_ = browser_prefs::GetAcceptLanguageList( - cef_browser_context, browser.get()); + accept_language_ = browser_prefs::GetAcceptLanguageList(profile); DCHECK(!accept_language_.empty()); user_agent_ = CefAppManager::Get()->GetContentClient()->browser()->GetUserAgent(); diff --git a/libcef/browser/prefs/browser_prefs.cc b/libcef/browser/prefs/browser_prefs.cc index 73fc7c28a..1f6c2add0 100644 --- a/libcef/browser/prefs/browser_prefs.cc +++ b/libcef/browser/prefs/browser_prefs.cc @@ -5,7 +5,6 @@ #include "libcef/browser/prefs/browser_prefs.h" #include "libcef/browser/browser_context.h" -#include "libcef/browser/browser_host_base.h" #include "libcef/browser/context.h" #include "libcef/browser/media_capture_devices_dispatcher.h" #include "libcef/browser/prefs/pref_registrar.h" @@ -95,17 +94,9 @@ std::string ComputeAcceptLanguageFromPref(const std::string& language_pref) { return net::HttpUtil::GenerateAcceptLanguageHeader(accept_languages_str); } -// Return the most relevant setting based on |browser_context| and |browser|. -std::string GetAcceptLanguageListSetting(CefBrowserContext* browser_context, - CefBrowserHostBase* browser) { - if (browser) { - const auto& settings = browser->settings(); - if (settings.accept_language_list.length > 0) { - return CefString(&settings.accept_language_list); - } - } - - if (browser_context) { +// Return the most relevant setting based on |profile|. +std::string GetAcceptLanguageListSetting(Profile* profile) { + if (auto* browser_context = CefBrowserContext::FromProfile(profile)) { const auto& settings = browser_context->settings(); if (settings.accept_language_list.length > 0) { return CefString(&settings.accept_language_list); @@ -346,8 +337,8 @@ std::unique_ptr CreatePrefService(Profile* profile, // Language preferences. Used by ProfileNetworkContextService and // InterceptedRequestHandlerWrapper. - const std::string& accept_language_list = GetAcceptLanguageListSetting( - CefBrowserContext::FromProfile(profile), /*browser=*/nullptr); + const std::string& accept_language_list = + GetAcceptLanguageListSetting(profile); if (!accept_language_list.empty()) { registry->SetDefaultPrefValue(language::prefs::kAcceptLanguages, base::Value(accept_language_list)); @@ -365,19 +356,17 @@ std::unique_ptr CreatePrefService(Profile* profile, return factory.CreateSyncable(registry.get()); } -std::string GetAcceptLanguageList(CefBrowserContext* browser_context, - CefBrowserHostBase* browser) { +std::string GetAcceptLanguageList(Profile* profile) { // Always prefer to the CEF settings configuration, if specified. - std::string accept_language_list = - GetAcceptLanguageListSetting(browser_context, browser); - if (accept_language_list.empty() && browser_context) { + std::string accept_language_list = GetAcceptLanguageListSetting(profile); + if (accept_language_list.empty() && profile) { // Fall back to the preference value. For the Alloy runtime the default // value comes from browser_prefs::CreatePrefService() above. For the Chrome // runtime the default value comes from the configured locale // (IDS_ACCEPT_LANGUAGES) which is then overridden by the user preference in // chrome://settings/languages, all managed by language::LanguagePrefs. - auto prefs = browser_context->AsProfile()->GetPrefs(); - accept_language_list = prefs->GetString(language::prefs::kAcceptLanguages); + accept_language_list = + profile->GetPrefs()->GetString(language::prefs::kAcceptLanguages); } if (!accept_language_list.empty()) { @@ -390,8 +379,8 @@ void SetInitialProfilePrefs(Profile* profile) { auto* prefs = profile->GetPrefs(); // Language preferences. - const std::string& accept_language_list = GetAcceptLanguageListSetting( - CefBrowserContext::FromProfile(profile), /*browser=*/nullptr); + const std::string& accept_language_list = + GetAcceptLanguageListSetting(profile); if (!accept_language_list.empty()) { // Used by ProfileNetworkContextService and InterceptedRequestHandlerWrapper // (via GetAcceptLanguageList) for request headers, and diff --git a/libcef/browser/prefs/browser_prefs.h b/libcef/browser/prefs/browser_prefs.h index 3f1a28dc3..baad58794 100644 --- a/libcef/browser/prefs/browser_prefs.h +++ b/libcef/browser/prefs/browser_prefs.h @@ -11,8 +11,6 @@ namespace base { class FilePath; } -class CefBrowserContext; -class CefBrowserHostBase; class PrefRegistrySimple; class PrefService; class Profile; @@ -36,8 +34,7 @@ std::unique_ptr CreatePrefService(Profile* profile, // Returns the value for populating the accept-language HTTP request header. // |browser_context| and/or |browser| may be nullptr. If |expand| is true then // base languages and Q values may be added. -std::string GetAcceptLanguageList(CefBrowserContext* browser_context, - CefBrowserHostBase* browser); +std::string GetAcceptLanguageList(Profile* profile); // Set preferences for a newly initialized Profile. void SetInitialProfilePrefs(Profile* profile); diff --git a/tests/ceftests/scheme_handler_unittest.cc b/tests/ceftests/scheme_handler_unittest.cc index c4b198cff..998bb920f 100644 --- a/tests/ceftests/scheme_handler_unittest.cc +++ b/tests/ceftests/scheme_handler_unittest.cc @@ -8,6 +8,8 @@ #include "include/base/cef_callback.h" #include "include/cef_callback.h" #include "include/cef_origin_whitelist.h" +#include "include/cef_request_context.h" +#include "include/cef_request_context_handler.h" #include "include/cef_scheme.h" #include "include/wrapper/cef_closure_task.h" #include "tests/ceftests/test_handler.h" @@ -20,6 +22,9 @@ class TestResults { public: TestResults() = default; + // Used for running tests in a custom request context. + CefRefPtr request_context; + std::string url; std::string html; int status_code = 200; @@ -43,7 +48,7 @@ class TestResults { // Used for testing XSS requests bool needs_same_origin_policy_relaxation = false; - // Used for testing per-browser Accept-Language. + // Used for testing Accept-Language. std::string accept_language; // Used for testing received console messages. @@ -54,7 +59,7 @@ class TestResults { TrackCallback got_request, got_read, got_output, got_sub_output, got_redirect, got_error, got_sub_error, got_sub_redirect, got_sub_request, got_sub_read, - got_sub_success, got_exit_request; + git_exit_success, got_exit_request; }; // Current scheme handler object. Used when destroying the test from @@ -68,15 +73,8 @@ class TestSchemeHandler : public TestHandler { g_current_handler = this; } - void PopulateBrowserSettings(CefBrowserSettings* settings) override { - if (!test_results_->accept_language.empty()) { - CefString(&settings->accept_language_list) = - test_results_->accept_language; - } - } - void RunTest() override { - CreateBrowser(test_results_->url); + CreateBrowser(test_results_->url, test_results_->request_context); // Time out the test after a reasonable period of time. SetTestTimeout(); @@ -130,7 +128,7 @@ class TestSchemeHandler : public TestHandler { test_results_->got_exit_request.yes(); // XHR tests use an exit URL to destroy the test. if (newUrl.find("SUCCESS") != std::string::npos) { - test_results_->got_sub_success.yes(); + test_results_->git_exit_success.yes(); } DestroyTestIfDone(); return RV_CANCEL; @@ -273,8 +271,7 @@ class ClientSchemeHandlerOld : public CefResourceHandler { EXPECT_TRUE(!accept_language.empty()); if (!test_results_->accept_language.empty()) { - // Value from CefBrowserSettings.accept_language set in - // PopulateBrowserSettings(). + // Value from CefRequestContextSettings.accept_language_list. EXPECT_STREQ(test_results_->accept_language.data(), accept_language.data()); } else { @@ -463,8 +460,7 @@ class ClientSchemeHandler : public CefResourceHandler { EXPECT_TRUE(!accept_language.empty()); if (!test_results_->accept_language.empty()) { - // Value from CefBrowserSettings.accept_language set in - // PopulateBrowserSettings(). + // Value from CefRequestContextSettings.accept_language_list. EXPECT_STREQ(test_results_->accept_language.data(), accept_language.data()); } else { @@ -663,13 +659,22 @@ class ClientSchemeHandlerFactory : public CefSchemeHandlerFactory { void RegisterTestScheme(TestResults* test_results, const std::string& scheme, const std::string& domain) { - EXPECT_TRUE(CefRegisterSchemeHandlerFactory( - scheme, domain, new ClientSchemeHandlerFactory(test_results))); + if (test_results->request_context) { + EXPECT_TRUE(test_results->request_context->RegisterSchemeHandlerFactory( + scheme, domain, new ClientSchemeHandlerFactory(test_results))); + } else { + EXPECT_TRUE(CefRegisterSchemeHandlerFactory( + scheme, domain, new ClientSchemeHandlerFactory(test_results))); + } WaitForIOThread(); } -void ClearTestSchemes() { - EXPECT_TRUE(CefClearSchemeHandlerFactories()); +void ClearTestSchemes(TestResults* test_results) { + if (test_results->request_context) { + EXPECT_TRUE(test_results->request_context->ClearSchemeHandlerFactories()); + } else { + EXPECT_TRUE(CefClearSchemeHandlerFactories()); + } WaitForIOThread(); } @@ -910,7 +915,7 @@ TEST(SchemeHandlerTest, Registration) { EXPECT_TRUE(test_results.got_read); EXPECT_TRUE(test_results.got_output); - ClearTestSchemes(); + ClearTestSchemes(&test_results); } // Test that a custom standard scheme can return normal results. @@ -929,7 +934,7 @@ TEST(SchemeHandlerTest, CustomStandardNormalResponse) { EXPECT_TRUE(test_results.got_read); EXPECT_TRUE(test_results.got_output); - ClearTestSchemes(); + ClearTestSchemes(&test_results); } // Test that a custom standard scheme can return normal results with delayed @@ -950,7 +955,7 @@ TEST(SchemeHandlerTest, CustomStandardNormalResponseDelayed) { EXPECT_TRUE(test_results.got_read); EXPECT_TRUE(test_results.got_output); - ClearTestSchemes(); + ClearTestSchemes(&test_results); } // Test that a custom nonstandard scheme can return normal results. @@ -969,7 +974,7 @@ TEST(SchemeHandlerTest, CustomNonStandardNormalResponse) { EXPECT_TRUE(test_results.got_read); EXPECT_TRUE(test_results.got_output); - ClearTestSchemes(); + ClearTestSchemes(&test_results); } // Test that a custom standard scheme can return an error code. @@ -988,7 +993,7 @@ TEST(SchemeHandlerTest, CustomStandardErrorResponse) { EXPECT_TRUE(test_results.got_read); EXPECT_TRUE(test_results.got_output); - ClearTestSchemes(); + ClearTestSchemes(&test_results); } // Test that a custom standard scheme can return a CEF error code in the @@ -1009,7 +1014,7 @@ TEST(SchemeHandlerTest, CustomStandardErrorCodeResponse) { EXPECT_FALSE(test_results.got_output); EXPECT_TRUE(test_results.got_error); - ClearTestSchemes(); + ClearTestSchemes(&test_results); } // Test that a custom nonstandard scheme can return an error code. @@ -1028,7 +1033,7 @@ TEST(SchemeHandlerTest, CustomNonStandardErrorResponse) { EXPECT_TRUE(test_results.got_read); EXPECT_TRUE(test_results.got_output); - ClearTestSchemes(); + ClearTestSchemes(&test_results); } // Test that custom standard scheme handling fails when the scheme name is @@ -1048,7 +1053,7 @@ TEST(SchemeHandlerTest, CustomStandardNameNotHandled) { EXPECT_FALSE(test_results.got_output); EXPECT_TRUE(test_results.got_error); - ClearTestSchemes(); + ClearTestSchemes(&test_results); } // Test that custom nonstandard scheme handling fails when the scheme name is @@ -1068,7 +1073,7 @@ TEST(SchemeHandlerTest, CustomNonStandardNameNotHandled) { EXPECT_FALSE(test_results.got_output); EXPECT_TRUE(test_results.got_error); - ClearTestSchemes(); + ClearTestSchemes(&test_results); } // Test that custom standard scheme handling fails when the domain name is @@ -1088,7 +1093,7 @@ TEST(SchemeHandlerTest, CustomStandardDomainNotHandled) { EXPECT_FALSE(test_results.got_output); EXPECT_TRUE(test_results.got_error); - ClearTestSchemes(); + ClearTestSchemes(&test_results); } // Test that a custom standard scheme can return no response. @@ -1105,7 +1110,7 @@ TEST(SchemeHandlerTest, CustomStandardNoResponse) { EXPECT_FALSE(test_results.got_read); EXPECT_FALSE(test_results.got_output); - ClearTestSchemes(); + ClearTestSchemes(&test_results); } // Test that a custom nonstandard scheme can return no response. @@ -1122,7 +1127,7 @@ TEST(SchemeHandlerTest, CustomNonStandardNoResponse) { EXPECT_FALSE(test_results.got_read); EXPECT_FALSE(test_results.got_output); - ClearTestSchemes(); + ClearTestSchemes(&test_results); } // Test that a custom standard scheme can generate redirects. @@ -1143,7 +1148,7 @@ TEST(SchemeHandlerTest, CustomStandardRedirect) { EXPECT_TRUE(test_results.got_output); EXPECT_TRUE(test_results.got_redirect); - ClearTestSchemes(); + ClearTestSchemes(&test_results); } // Test that a custom nonstandard scheme can generate redirects. @@ -1164,7 +1169,7 @@ TEST(SchemeHandlerTest, CustomNonStandardRedirect) { EXPECT_TRUE(test_results.got_output); EXPECT_TRUE(test_results.got_redirect); - ClearTestSchemes(); + ClearTestSchemes(&test_results); } // Test that a custom standard scheme can generate same origin XHR requests. @@ -1186,9 +1191,9 @@ TEST(SchemeHandlerTest, CustomStandardXHRSameOriginSync) { EXPECT_TRUE(test_results.got_output); EXPECT_TRUE(test_results.got_sub_request); EXPECT_TRUE(test_results.got_sub_read); - EXPECT_TRUE(test_results.got_sub_success); + EXPECT_TRUE(test_results.git_exit_success); - ClearTestSchemes(); + ClearTestSchemes(&test_results); } // Test that a custom standard scheme can generate same origin XHR requests. @@ -1211,9 +1216,9 @@ TEST(SchemeHandlerTest, CustomStandardXHRSameOriginAsync) { EXPECT_TRUE(test_results.got_output); EXPECT_TRUE(test_results.got_sub_request); EXPECT_TRUE(test_results.got_sub_read); - EXPECT_TRUE(test_results.got_sub_success); + EXPECT_TRUE(test_results.git_exit_success); - ClearTestSchemes(); + ClearTestSchemes(&test_results); } // Test that custom nonstandard schemes are treated as unique origins that @@ -1241,9 +1246,9 @@ TEST(SchemeHandlerTest, CustomNonStandardXHRSameOriginSync) { EXPECT_TRUE(test_results.got_output); EXPECT_FALSE(test_results.got_sub_request); EXPECT_FALSE(test_results.got_sub_read); - EXPECT_FALSE(test_results.got_sub_success); + EXPECT_FALSE(test_results.git_exit_success); - ClearTestSchemes(); + ClearTestSchemes(&test_results); } // Test that custom nonstandard schemes are treated as unique origins that @@ -1272,9 +1277,9 @@ TEST(SchemeHandlerTest, CustomNonStandardXHRSameOriginAsync) { EXPECT_TRUE(test_results.got_output); EXPECT_FALSE(test_results.got_sub_request); EXPECT_FALSE(test_results.got_sub_read); - EXPECT_FALSE(test_results.got_sub_success); + EXPECT_FALSE(test_results.git_exit_success); - ClearTestSchemes(); + ClearTestSchemes(&test_results); } // Test that a non fetch enabled custom standard scheme can't generate same @@ -1301,9 +1306,9 @@ TEST(SchemeHandlerTest, CustomStandardFetchSameOrigin) { EXPECT_TRUE(test_results.got_output); EXPECT_FALSE(test_results.got_sub_request); EXPECT_FALSE(test_results.got_sub_read); - EXPECT_FALSE(test_results.got_sub_success); + EXPECT_FALSE(test_results.git_exit_success); - ClearTestSchemes(); + ClearTestSchemes(&test_results); } // Test that a fetch enabled custom standard scheme can generate same origin @@ -1326,9 +1331,9 @@ TEST(SchemeHandlerTest, FetchCustomStandardFetchSameOrigin) { EXPECT_TRUE(test_results.got_output); EXPECT_TRUE(test_results.got_sub_request); EXPECT_TRUE(test_results.got_sub_read); - EXPECT_TRUE(test_results.got_sub_success); + EXPECT_TRUE(test_results.git_exit_success); - ClearTestSchemes(); + ClearTestSchemes(&test_results); } // Test that custom nonstandard schemes are treated as unique origins that @@ -1355,9 +1360,9 @@ TEST(SchemeHandlerTest, CustomNonStandardFetchSameOrigin) { EXPECT_TRUE(test_results.got_output); EXPECT_FALSE(test_results.got_sub_request); EXPECT_FALSE(test_results.got_sub_read); - EXPECT_FALSE(test_results.got_sub_success); + EXPECT_FALSE(test_results.git_exit_success); - ClearTestSchemes(); + ClearTestSchemes(&test_results); } // Test that a custom standard scheme can generate same origin XSS requests. @@ -1376,9 +1381,9 @@ TEST(SchemeHandlerTest, CustomStandardXSSSameOrigin) { EXPECT_TRUE(test_results.got_output); EXPECT_TRUE(test_results.got_sub_request); EXPECT_TRUE(test_results.got_sub_read); - EXPECT_TRUE(test_results.got_sub_success); + EXPECT_TRUE(test_results.git_exit_success); - ClearTestSchemes(); + ClearTestSchemes(&test_results); } // Test that custom nonstandard schemes are treated as unique origins that @@ -1402,9 +1407,9 @@ TEST(SchemeHandlerTest, CustomNonStandardXSSSameOrigin) { EXPECT_TRUE(test_results.got_output); EXPECT_TRUE(test_results.got_sub_request); EXPECT_TRUE(test_results.got_sub_read); - EXPECT_FALSE(test_results.got_sub_success); + EXPECT_FALSE(test_results.git_exit_success); - ClearTestSchemes(); + ClearTestSchemes(&test_results); } // Test that a custom standard scheme cannot generate cross-domain XHR requests @@ -1434,9 +1439,9 @@ TEST(SchemeHandlerTest, CustomStandardXHRDifferentOriginSync) { EXPECT_TRUE(test_results.got_output); EXPECT_TRUE(test_results.got_sub_request); EXPECT_TRUE(test_results.got_sub_read); - EXPECT_FALSE(test_results.got_sub_success); + EXPECT_FALSE(test_results.git_exit_success); - ClearTestSchemes(); + ClearTestSchemes(&test_results); } // Test that a custom standard scheme cannot generate cross-domain XHR requests @@ -1467,9 +1472,9 @@ TEST(SchemeHandlerTest, CustomStandardXHRDifferentOriginAsync) { EXPECT_TRUE(test_results.got_output); EXPECT_TRUE(test_results.got_sub_request); EXPECT_TRUE(test_results.got_sub_read); - EXPECT_FALSE(test_results.got_sub_success); + EXPECT_FALSE(test_results.git_exit_success); - ClearTestSchemes(); + ClearTestSchemes(&test_results); } // Test that a custom standard scheme cannot generate cross-domain Fetch @@ -1500,9 +1505,9 @@ TEST(SchemeHandlerTest, CustomStandardFetchDifferentOrigin) { EXPECT_TRUE(test_results.got_output); EXPECT_TRUE(test_results.got_sub_request); EXPECT_TRUE(test_results.got_sub_read); - EXPECT_FALSE(test_results.got_sub_success); + EXPECT_FALSE(test_results.git_exit_success); - ClearTestSchemes(); + ClearTestSchemes(&test_results); } // Test that a custom standard scheme cannot generate cross-domain XSS requests @@ -1527,9 +1532,9 @@ TEST(SchemeHandlerTest, CustomStandardXSSDifferentOrigin) { EXPECT_TRUE(test_results.got_output); EXPECT_TRUE(test_results.got_sub_request); EXPECT_TRUE(test_results.got_sub_read); - EXPECT_FALSE(test_results.got_sub_success); + EXPECT_FALSE(test_results.git_exit_success); - ClearTestSchemes(); + ClearTestSchemes(&test_results); } // Test that a cross-protocol iframe load succeeds, and that the custom @@ -1554,9 +1559,9 @@ TEST(SchemeHandlerTest, CustomStandardXSSDifferentProtocolHttp) { EXPECT_TRUE(test_results.got_output); EXPECT_TRUE(test_results.got_sub_request); EXPECT_TRUE(test_results.got_sub_read); - EXPECT_FALSE(test_results.got_sub_success); + EXPECT_FALSE(test_results.git_exit_success); - ClearTestSchemes(); + ClearTestSchemes(&test_results); } // Test that a cross-protocol iframe load succeeds, and that the custom @@ -1582,9 +1587,9 @@ TEST(SchemeHandlerTest, CustomStandardXSSDifferentProtocolCustomNonStandard) { EXPECT_TRUE(test_results.got_output); EXPECT_TRUE(test_results.got_sub_request); EXPECT_TRUE(test_results.got_sub_read); - EXPECT_FALSE(test_results.got_sub_success); + EXPECT_FALSE(test_results.git_exit_success); - ClearTestSchemes(); + ClearTestSchemes(&test_results); } // Test that a cross-protocol iframe load succeeds, and that the HTTP protocol @@ -1609,9 +1614,9 @@ TEST(SchemeHandlerTest, HttpXSSDifferentProtocolCustomStandard) { EXPECT_TRUE(test_results.got_output); EXPECT_TRUE(test_results.got_sub_request); EXPECT_TRUE(test_results.got_sub_read); - EXPECT_FALSE(test_results.got_sub_success); + EXPECT_FALSE(test_results.git_exit_success); - ClearTestSchemes(); + ClearTestSchemes(&test_results); } // Test that a cross-protocol iframe load succeeds, and that the HTTP protocol @@ -1636,9 +1641,9 @@ TEST(SchemeHandlerTest, HttpXSSDifferentProtocolCustomNonStandard) { EXPECT_TRUE(test_results.got_output); EXPECT_TRUE(test_results.got_sub_request); EXPECT_TRUE(test_results.got_sub_read); - EXPECT_FALSE(test_results.got_sub_success); + EXPECT_FALSE(test_results.git_exit_success); - ClearTestSchemes(); + ClearTestSchemes(&test_results); } // Test that an HTTP scheme cannot generate cross-domain XHR requests by @@ -1668,9 +1673,9 @@ TEST(SchemeHandlerTest, HttpXHRDifferentOriginSync) { EXPECT_TRUE(test_results.got_output); EXPECT_TRUE(test_results.got_sub_request); EXPECT_TRUE(test_results.got_sub_read); - EXPECT_FALSE(test_results.got_sub_success); + EXPECT_FALSE(test_results.git_exit_success); - ClearTestSchemes(); + ClearTestSchemes(&test_results); } // Test that an HTTP scheme cannot generate cross-domain XHR requests by @@ -1701,9 +1706,9 @@ TEST(SchemeHandlerTest, HttpXHRDifferentOriginAsync) { EXPECT_TRUE(test_results.got_output); EXPECT_TRUE(test_results.got_sub_request); EXPECT_TRUE(test_results.got_sub_read); - EXPECT_FALSE(test_results.got_sub_success); + EXPECT_FALSE(test_results.git_exit_success); - ClearTestSchemes(); + ClearTestSchemes(&test_results); } // Test that an HTTP scheme cannot generate cross-domain Fetch requests by @@ -1735,9 +1740,9 @@ TEST(SchemeHandlerTest, HttpFetchDifferentOriginAsync) { EXPECT_TRUE(test_results.got_output); EXPECT_TRUE(test_results.got_sub_request); EXPECT_TRUE(test_results.got_sub_read); - EXPECT_FALSE(test_results.got_sub_success); + EXPECT_FALSE(test_results.git_exit_success); - ClearTestSchemes(); + ClearTestSchemes(&test_results); } // Test that an HTTP scheme cannot generate cross-domain XSS requests by @@ -1761,9 +1766,9 @@ TEST(SchemeHandlerTest, HttpXSSDifferentOrigin) { EXPECT_TRUE(test_results.got_output); EXPECT_TRUE(test_results.got_sub_request); EXPECT_TRUE(test_results.got_sub_read); - EXPECT_FALSE(test_results.got_sub_success); + EXPECT_FALSE(test_results.git_exit_success); - ClearTestSchemes(); + ClearTestSchemes(&test_results); } // Test that a custom standard scheme can generate cross-domain XHR requests @@ -1789,9 +1794,9 @@ TEST(SchemeHandlerTest, CustomStandardXHRDifferentOriginWithHeaderSync) { EXPECT_TRUE(test_results.got_output); EXPECT_TRUE(test_results.got_sub_request); EXPECT_TRUE(test_results.got_sub_read); - EXPECT_TRUE(test_results.got_sub_success); + EXPECT_TRUE(test_results.git_exit_success); - ClearTestSchemes(); + ClearTestSchemes(&test_results); } // Test that a custom standard scheme can generate cross-domain XHR requests @@ -1818,9 +1823,9 @@ TEST(SchemeHandlerTest, CustomStandardXHRDifferentOriginWithHeaderAsync) { EXPECT_TRUE(test_results.got_output); EXPECT_TRUE(test_results.got_sub_request); EXPECT_TRUE(test_results.got_sub_read); - EXPECT_TRUE(test_results.got_sub_success); + EXPECT_TRUE(test_results.git_exit_success); - ClearTestSchemes(); + ClearTestSchemes(&test_results); } // Test that a custom standard scheme can generate cross-domain Fetch requests @@ -1846,9 +1851,9 @@ TEST(SchemeHandlerTest, CustomStandardFetchDifferentOriginWithHeader) { EXPECT_TRUE(test_results.got_output); EXPECT_TRUE(test_results.got_sub_request); EXPECT_TRUE(test_results.got_sub_read); - EXPECT_TRUE(test_results.got_sub_success); + EXPECT_TRUE(test_results.git_exit_success); - ClearTestSchemes(); + ClearTestSchemes(&test_results); } // Test that a custom standard scheme can generate cross-domain XHR requests @@ -1876,12 +1881,12 @@ TEST(SchemeHandlerTest, CustomStandardXHRDifferentOriginWithWhitelistSync1) { EXPECT_TRUE(test_results.got_output); EXPECT_TRUE(test_results.got_sub_request); EXPECT_TRUE(test_results.got_sub_read); - EXPECT_TRUE(test_results.got_sub_success); + EXPECT_TRUE(test_results.git_exit_success); EXPECT_TRUE(CefClearCrossOriginWhitelist()); WaitForUIThread(); - ClearTestSchemes(); + ClearTestSchemes(&test_results); } // Same as above but origin whitelist matches any domain. @@ -1908,12 +1913,12 @@ TEST(SchemeHandlerTest, CustomStandardXHRDifferentOriginWithWhitelistSync2) { EXPECT_TRUE(test_results.got_output); EXPECT_TRUE(test_results.got_sub_request); EXPECT_TRUE(test_results.got_sub_read); - EXPECT_TRUE(test_results.got_sub_success); + EXPECT_TRUE(test_results.git_exit_success); EXPECT_TRUE(CefClearCrossOriginWhitelist()); WaitForUIThread(); - ClearTestSchemes(); + ClearTestSchemes(&test_results); } // Same as above but origin whitelist matches sub-domains. @@ -1940,12 +1945,12 @@ TEST(SchemeHandlerTest, CustomStandardXHRDifferentOriginWithWhitelistSync3) { EXPECT_TRUE(test_results.got_output); EXPECT_TRUE(test_results.got_sub_request); EXPECT_TRUE(test_results.got_sub_read); - EXPECT_TRUE(test_results.got_sub_success); + EXPECT_TRUE(test_results.git_exit_success); EXPECT_TRUE(CefClearCrossOriginWhitelist()); WaitForUIThread(); - ClearTestSchemes(); + ClearTestSchemes(&test_results); } // Test that a custom standard scheme can generate cross-domain XHR requests @@ -1974,12 +1979,12 @@ TEST(SchemeHandlerTest, CustomStandardXHRDifferentOriginWithWhitelistAsync1) { EXPECT_TRUE(test_results.got_output); EXPECT_TRUE(test_results.got_sub_request); EXPECT_TRUE(test_results.got_sub_read); - EXPECT_TRUE(test_results.got_sub_success); + EXPECT_TRUE(test_results.git_exit_success); EXPECT_TRUE(CefClearCrossOriginWhitelist()); WaitForUIThread(); - ClearTestSchemes(); + ClearTestSchemes(&test_results); } // Same as above but origin whitelist matches any domain. @@ -2007,12 +2012,12 @@ TEST(SchemeHandlerTest, CustomStandardXHRDifferentOriginWithWhitelistAsync2) { EXPECT_TRUE(test_results.got_output); EXPECT_TRUE(test_results.got_sub_request); EXPECT_TRUE(test_results.got_sub_read); - EXPECT_TRUE(test_results.got_sub_success); + EXPECT_TRUE(test_results.git_exit_success); EXPECT_TRUE(CefClearCrossOriginWhitelist()); WaitForUIThread(); - ClearTestSchemes(); + ClearTestSchemes(&test_results); } // Same as above but origin whitelist matches sub-domains. @@ -2040,12 +2045,12 @@ TEST(SchemeHandlerTest, CustomStandardXHRDifferentOriginWithWhitelistAsync3) { EXPECT_TRUE(test_results.got_output); EXPECT_TRUE(test_results.got_sub_request); EXPECT_TRUE(test_results.got_sub_read); - EXPECT_TRUE(test_results.got_sub_success); + EXPECT_TRUE(test_results.git_exit_success); EXPECT_TRUE(CefClearCrossOriginWhitelist()); WaitForUIThread(); - ClearTestSchemes(); + ClearTestSchemes(&test_results); } // Test that a custom standard scheme can generate cross-domain Fetch requests @@ -2073,12 +2078,12 @@ TEST(SchemeHandlerTest, CustomStandardFetchDifferentOriginWithWhitelist1) { EXPECT_TRUE(test_results.got_output); EXPECT_TRUE(test_results.got_sub_request); EXPECT_TRUE(test_results.got_sub_read); - EXPECT_TRUE(test_results.got_sub_success); + EXPECT_TRUE(test_results.git_exit_success); EXPECT_TRUE(CefClearCrossOriginWhitelist()); WaitForUIThread(); - ClearTestSchemes(); + ClearTestSchemes(&test_results); } // Same as above but origin whitelist matches any domain. @@ -2105,12 +2110,12 @@ TEST(SchemeHandlerTest, CustomStandardFetchDifferentOriginWithWhitelist2) { EXPECT_TRUE(test_results.got_output); EXPECT_TRUE(test_results.got_sub_request); EXPECT_TRUE(test_results.got_sub_read); - EXPECT_TRUE(test_results.got_sub_success); + EXPECT_TRUE(test_results.git_exit_success); EXPECT_TRUE(CefClearCrossOriginWhitelist()); WaitForUIThread(); - ClearTestSchemes(); + ClearTestSchemes(&test_results); } // Same as above but origin whitelist matches sub-domains. @@ -2137,12 +2142,12 @@ TEST(SchemeHandlerTest, CustomStandardFetchDifferentOriginWithWhitelist3) { EXPECT_TRUE(test_results.got_output); EXPECT_TRUE(test_results.got_sub_request); EXPECT_TRUE(test_results.got_sub_read); - EXPECT_TRUE(test_results.got_sub_success); + EXPECT_TRUE(test_results.git_exit_success); EXPECT_TRUE(CefClearCrossOriginWhitelist()); WaitForUIThread(); - ClearTestSchemes(); + ClearTestSchemes(&test_results); } // Test that an HTTP scheme can generate cross-domain XHR requests when setting @@ -2167,9 +2172,9 @@ TEST(SchemeHandlerTest, HttpXHRDifferentOriginWithHeaderSync) { EXPECT_TRUE(test_results.got_output); EXPECT_TRUE(test_results.got_sub_request); EXPECT_TRUE(test_results.got_sub_read); - EXPECT_TRUE(test_results.got_sub_success); + EXPECT_TRUE(test_results.git_exit_success); - ClearTestSchemes(); + ClearTestSchemes(&test_results); } // Test that an HTTP scheme can generate cross-domain XHR requests when setting @@ -2195,9 +2200,9 @@ TEST(SchemeHandlerTest, HttpXHRDifferentOriginWithHeaderAsync) { EXPECT_TRUE(test_results.got_output); EXPECT_TRUE(test_results.got_sub_request); EXPECT_TRUE(test_results.got_sub_read); - EXPECT_TRUE(test_results.got_sub_success); + EXPECT_TRUE(test_results.git_exit_success); - ClearTestSchemes(); + ClearTestSchemes(&test_results); } // Test that an HTTP scheme can generate cross-domain XHR requests when setting @@ -2222,9 +2227,9 @@ TEST(SchemeHandlerTest, HttpFetchDifferentOriginWithHeader) { EXPECT_TRUE(test_results.got_output); EXPECT_TRUE(test_results.got_sub_request); EXPECT_TRUE(test_results.got_sub_read); - EXPECT_TRUE(test_results.got_sub_success); + EXPECT_TRUE(test_results.git_exit_success); - ClearTestSchemes(); + ClearTestSchemes(&test_results); } // Test that a custom standard scheme can generate cross-domain XSS requests @@ -2245,9 +2250,9 @@ TEST(SchemeHandlerTest, CustomStandardXSSDifferentOriginWithDomain) { EXPECT_TRUE(test_results.got_output); EXPECT_TRUE(test_results.got_sub_request); EXPECT_TRUE(test_results.got_sub_read); - EXPECT_TRUE(test_results.got_sub_success); + EXPECT_TRUE(test_results.git_exit_success); - ClearTestSchemes(); + ClearTestSchemes(&test_results); } // Test that an HTTP scheme can generate cross-domain XSS requests when using @@ -2268,9 +2273,9 @@ TEST(SchemeHandlerTest, HttpXSSDifferentOriginWithDomain) { EXPECT_TRUE(test_results.got_output); EXPECT_TRUE(test_results.got_sub_request); EXPECT_TRUE(test_results.got_sub_read); - EXPECT_TRUE(test_results.got_sub_success); + EXPECT_TRUE(test_results.git_exit_success); - ClearTestSchemes(); + ClearTestSchemes(&test_results); } // Test that a custom standard scheme cannot generate cross-domain XHR requests @@ -2302,9 +2307,9 @@ TEST(SchemeHandlerTest, CustomStandardXHRDifferentOriginRedirectSync) { EXPECT_TRUE(test_results.got_sub_redirect); EXPECT_TRUE(test_results.got_sub_request); EXPECT_TRUE(test_results.got_sub_read); - EXPECT_FALSE(test_results.got_sub_success); + EXPECT_FALSE(test_results.git_exit_success); - ClearTestSchemes(); + ClearTestSchemes(&test_results); } // Test that a custom standard scheme cannot generate cross-domain XHR requests @@ -2337,9 +2342,9 @@ TEST(SchemeHandlerTest, CustomStandardXHRDifferentOriginRedirectAsync) { EXPECT_TRUE(test_results.got_sub_redirect); EXPECT_TRUE(test_results.got_sub_request); EXPECT_TRUE(test_results.got_sub_read); - EXPECT_FALSE(test_results.got_sub_success); + EXPECT_FALSE(test_results.git_exit_success); - ClearTestSchemes(); + ClearTestSchemes(&test_results); } // Test that a custom standard scheme cannot generate cross-domain Fetch @@ -2373,9 +2378,9 @@ TEST(SchemeHandlerTest, CustomStandardFetchDifferentOriginRedirect) { EXPECT_TRUE(test_results.got_sub_redirect); EXPECT_TRUE(test_results.got_sub_request); EXPECT_TRUE(test_results.got_sub_read); - EXPECT_FALSE(test_results.got_sub_success); + EXPECT_FALSE(test_results.git_exit_success); - ClearTestSchemes(); + ClearTestSchemes(&test_results); } // Test that a custom standard scheme can generate cross-domain XHR requests @@ -2406,12 +2411,12 @@ TEST(SchemeHandlerTest, EXPECT_TRUE(test_results.got_sub_redirect); EXPECT_TRUE(test_results.got_sub_request); EXPECT_TRUE(test_results.got_sub_read); - EXPECT_TRUE(test_results.got_sub_success); + EXPECT_TRUE(test_results.git_exit_success); EXPECT_TRUE(CefClearCrossOriginWhitelist()); WaitForUIThread(); - ClearTestSchemes(); + ClearTestSchemes(&test_results); } // Test that a custom standard scheme can generate cross-domain XHR requests @@ -2443,12 +2448,12 @@ TEST(SchemeHandlerTest, EXPECT_TRUE(test_results.got_sub_redirect); EXPECT_TRUE(test_results.got_sub_request); EXPECT_TRUE(test_results.got_sub_read); - EXPECT_TRUE(test_results.got_sub_success); + EXPECT_TRUE(test_results.git_exit_success); EXPECT_TRUE(CefClearCrossOriginWhitelist()); WaitForUIThread(); - ClearTestSchemes(); + ClearTestSchemes(&test_results); } // Same as above but origin whitelist matches any domain. @@ -2479,12 +2484,12 @@ TEST(SchemeHandlerTest, EXPECT_TRUE(test_results.got_sub_redirect); EXPECT_TRUE(test_results.got_sub_request); EXPECT_TRUE(test_results.got_sub_read); - EXPECT_TRUE(test_results.got_sub_success); + EXPECT_TRUE(test_results.git_exit_success); EXPECT_TRUE(CefClearCrossOriginWhitelist()); WaitForUIThread(); - ClearTestSchemes(); + ClearTestSchemes(&test_results); } // Same as above but origin whitelist matches sub-domains. @@ -2515,12 +2520,12 @@ TEST(SchemeHandlerTest, EXPECT_TRUE(test_results.got_sub_redirect); EXPECT_TRUE(test_results.got_sub_request); EXPECT_TRUE(test_results.got_sub_read); - EXPECT_TRUE(test_results.got_sub_success); + EXPECT_TRUE(test_results.git_exit_success); EXPECT_TRUE(CefClearCrossOriginWhitelist()); WaitForUIThread(); - ClearTestSchemes(); + ClearTestSchemes(&test_results); } // Test that a custom standard scheme can generate cross-domain Fetch requests @@ -2551,12 +2556,12 @@ TEST(SchemeHandlerTest, EXPECT_TRUE(test_results.got_sub_redirect); EXPECT_TRUE(test_results.got_sub_request); EXPECT_TRUE(test_results.got_sub_read); - EXPECT_TRUE(test_results.got_sub_success); + EXPECT_TRUE(test_results.git_exit_success); EXPECT_TRUE(CefClearCrossOriginWhitelist()); WaitForUIThread(); - ClearTestSchemes(); + ClearTestSchemes(&test_results); } // Same as above but origin whitelist matches any domain. @@ -2586,12 +2591,12 @@ TEST(SchemeHandlerTest, EXPECT_TRUE(test_results.got_sub_redirect); EXPECT_TRUE(test_results.got_sub_request); EXPECT_TRUE(test_results.got_sub_read); - EXPECT_TRUE(test_results.got_sub_success); + EXPECT_TRUE(test_results.git_exit_success); EXPECT_TRUE(CefClearCrossOriginWhitelist()); WaitForUIThread(); - ClearTestSchemes(); + ClearTestSchemes(&test_results); } // Same as above but origin whitelist matches sub-domains. @@ -2621,25 +2626,43 @@ TEST(SchemeHandlerTest, EXPECT_TRUE(test_results.got_sub_redirect); EXPECT_TRUE(test_results.got_sub_request); EXPECT_TRUE(test_results.got_sub_read); - EXPECT_TRUE(test_results.got_sub_success); + EXPECT_TRUE(test_results.git_exit_success); EXPECT_TRUE(CefClearCrossOriginWhitelist()); WaitForUIThread(); - ClearTestSchemes(); + ClearTestSchemes(&test_results); } -// Test per-browser setting of Accept-Language. +// Test that CefRequestContextSettings.accept_language_list configures both +// the Accept-Language request header and `navigator.language` JS attribute. TEST(SchemeHandlerTest, AcceptLanguage) { TestResults test_results; + + // Value that will be set via CefRequestContextSettings.accept_language_list. + test_results.accept_language = "uk"; + + // Create an in-memory request context with custom settings. + CefRequestContextSettings settings; + CefString(&settings.accept_language_list) = test_results.accept_language; + test_results.request_context = + CefRequestContext::CreateContext(settings, nullptr); + RegisterTestScheme(&test_results, "customstd", "test"); test_results.url = "customstd://test/run.html"; test_results.html = - "

Success!

"; - - // Value that will be set via CefBrowserSettings.accept_language in - // PopulateBrowserSettings(). - test_results.accept_language = "uk"; + "" + "" + ""; + test_results.exit_url = "https://tests/exit"; CefRefPtr handler = new TestSchemeHandler(&test_results); handler->ExecuteTest(); @@ -2648,8 +2671,9 @@ TEST(SchemeHandlerTest, AcceptLanguage) { EXPECT_TRUE(test_results.got_request); EXPECT_TRUE(test_results.got_read); EXPECT_TRUE(test_results.got_output); + EXPECT_TRUE(test_results.git_exit_success); - ClearTestSchemes(); + ClearTestSchemes(&test_results); } // Entry point for registering custom schemes. diff --git a/tests/ceftests/test_handler.cc b/tests/ceftests/test_handler.cc index 3ebf4ae16..5d4d6e363 100644 --- a/tests/ceftests/test_handler.cc +++ b/tests/ceftests/test_handler.cc @@ -370,7 +370,6 @@ void TestHandler::CreateBrowser(const CefString& url, CefWindowInfo windowInfo; CefBrowserSettings settings; - PopulateBrowserSettings(&settings); if (use_views) { // Create the BrowserView. diff --git a/tests/ceftests/test_handler.h b/tests/ceftests/test_handler.h index afb213e1f..bffd5f5f8 100644 --- a/tests/ceftests/test_handler.h +++ b/tests/ceftests/test_handler.h @@ -225,9 +225,6 @@ class TestHandler : public CefClient, // SetTestTimeout(). Calls DestroyTest() by default. virtual void OnTestTimeout(int timeout_ms, bool treat_as_error); - // Called from CreateBrowser() to optionally set per-browser settings. - virtual void PopulateBrowserSettings(CefBrowserSettings* settings) {} - void CreateBrowser(const CefString& url, CefRefPtr request_context = nullptr, CefRefPtr extra_info = nullptr);