diff --git a/libcef/browser/xml_reader_impl.cc b/libcef/browser/xml_reader_impl.cc index c8a29db83..af9fc4efd 100644 --- a/libcef/browser/xml_reader_impl.cc +++ b/libcef/browser/xml_reader_impl.cc @@ -4,6 +4,8 @@ #include "cef/libcef/browser/xml_reader_impl.h" +#include + #include "base/logging.h" #include "base/notreached.h" #include "cef/include/cef_stream.h" @@ -62,13 +64,13 @@ void XMLCALL xml_error_callback(void* arg, error_str.resize(error_str.length() - 1); } - std::stringstream ss; - ss << error_str << ", line " << xmlTextReaderLocatorLineNumber(locator); + auto formatted_error = std::format("{}, line {}", error_str, + xmlTextReaderLocatorLineNumber(locator)); - LOG(INFO) << ss.str(); + LOG(INFO) << formatted_error; CefRefPtr impl(static_cast(arg)); - impl->AppendError(ss.str()); + impl->AppendError(formatted_error); } /** @@ -90,13 +92,12 @@ void XMLCALL xml_structured_error_callback(void* userData, error_str.resize(error_str.length() - 1); } - std::stringstream ss; - ss << error_str << ", line " << error->line; + auto formatted_error = std::format("{}, line {}", error_str, error->line); - LOG(INFO) << ss.str(); + LOG(INFO) << formatted_error; CefRefPtr impl(static_cast(userData)); - impl->AppendError(ss.str()); + impl->AppendError(formatted_error); } CefString xmlCharToString(const xmlChar* xmlStr, bool free) { @@ -205,7 +206,7 @@ bool CefXmlReaderImpl::HasError() { return false; } - return !error_buf_.str().empty(); + return !error_buf_.empty(); } CefString CefXmlReaderImpl::GetError() { @@ -213,7 +214,7 @@ CefString CefXmlReaderImpl::GetError() { return CefString(); } - return error_buf_.str(); + return error_buf_; } CefXmlReader::NodeType CefXmlReaderImpl::GetType() { @@ -476,10 +477,10 @@ bool CefXmlReaderImpl::MoveToCarryingElement() { } void CefXmlReaderImpl::AppendError(const CefString& error_str) { - if (!error_buf_.str().empty()) { - error_buf_ << L"\n"; + if (!error_buf_.empty()) { + error_buf_ += '\n'; } - error_buf_ << error_str.ToString(); + error_buf_ += error_str.ToString(); } bool CefXmlReaderImpl::VerifyContext() { diff --git a/libcef/browser/xml_reader_impl.h b/libcef/browser/xml_reader_impl.h index d9ab1b95b..ab8972e2e 100644 --- a/libcef/browser/xml_reader_impl.h +++ b/libcef/browser/xml_reader_impl.h @@ -8,7 +8,7 @@ #include -#include +#include #include "base/threading/platform_thread.h" #include "cef/include/cef_xml_reader.h" @@ -67,7 +67,7 @@ class CefXmlReaderImpl : public CefXmlReader { base::PlatformThreadId supported_thread_id_; CefRefPtr stream_; xmlTextReaderPtr reader_ = nullptr; - std::stringstream error_buf_; + std::string error_buf_; IMPLEMENT_REFCOUNTING(CefXmlReaderImpl); }; diff --git a/libcef/browser/zip_reader_impl.h b/libcef/browser/zip_reader_impl.h index a999dc1ea..8c2585325 100644 --- a/libcef/browser/zip_reader_impl.h +++ b/libcef/browser/zip_reader_impl.h @@ -6,8 +6,6 @@ #define CEF_LIBCEF_BROWSER_ZIP_READER_IMPL_H_ #pragma once -#include - #include "base/threading/platform_thread.h" #include "cef/include/cef_zip_reader.h" #include "third_party/zlib/contrib/minizip/unzip.h" diff --git a/libcef/common/parser_impl.cc b/libcef/common/parser_impl.cc index 6f6c3eb73..000b8c5bc 100644 --- a/libcef/common/parser_impl.cc +++ b/libcef/common/parser_impl.cc @@ -2,7 +2,7 @@ // reserved. Use of this source code is governed by a BSD-style license that can // be found in the LICENSE file. -#include +#include #include "base/base64.h" #include "base/strings/escape.h" @@ -67,29 +67,32 @@ bool CefCreateURL(const CefURLParts& parts, CefString& url) { if (!spec.empty()) { gurl = GURL(spec); } else if (!scheme.empty() && !host.empty()) { - std::stringstream ss; - ss << scheme << "://"; + std::string url_str = scheme + "://"; if (!username.empty()) { - ss << username; + url_str += username; if (!password.empty()) { - ss << ":" << password; + url_str += ':'; + url_str += password; } - ss << "@"; + url_str += '@'; } - ss << host; + url_str += host; if (!port.empty()) { - ss << ":" << port; + url_str += ':'; + url_str += port; } if (!path.empty()) { - ss << path; + url_str += path; } if (!query.empty()) { - ss << "?" << query; + url_str += '?'; + url_str += query; } if (!fragment.empty()) { - ss << "#" << fragment; + url_str += '#'; + url_str += fragment; } - gurl = GURL(ss.str()); + gurl = GURL(url_str); } if (gurl.is_valid()) { diff --git a/libcef_dll/base/cef_logging.cc b/libcef_dll/base/cef_logging.cc index d7b6701b6..4eb0b23ac 100644 --- a/libcef_dll/base/cef_logging.cc +++ b/libcef_dll/base/cef_logging.cc @@ -24,9 +24,9 @@ #include #endif -#include +#include #include -#include +#include #include "include/base/cef_immediate_crash.h" @@ -353,31 +353,30 @@ void ScopedEarlySupport::log(const char* file, std::min(std::size_t{6}, strlen(file))) : file; - std::stringstream stream; - - stream << '['; + std::string log_line = "["; if (config.log_prefix) { - stream << config.log_prefix << ':'; + log_line += config.log_prefix; + log_line += ':'; } if (config.log_process_id) { #if defined(OS_WIN) - stream << ::GetCurrentProcessId() << ':'; + log_line += std::format("{}:", ::GetCurrentProcessId()); #elif defined(OS_POSIX) - stream << getpid() << ':'; + log_line += std::format("{}:", getpid()); #else #error Unsupported platform #endif } if (config.log_thread_id) { #if defined(OS_WIN) - stream << ::GetCurrentThreadId() << ':'; + log_line += std::format("{}:", ::GetCurrentThreadId()); #elif defined(OS_APPLE) uint64_t tid; if (pthread_threadid_np(nullptr, &tid) == 0) { - stream << tid << ':'; + log_line += std::format("{}:", tid); } #elif defined(OS_POSIX) - stream << pthread_self() << ':'; + log_line += std::format("{}:", pthread_self()); #else #error Unsupported platform #endif @@ -386,11 +385,10 @@ void ScopedEarlySupport::log(const char* file, #if defined(OS_WIN) SYSTEMTIME local_time; GetLocalTime(&local_time); - stream << std::setfill('0') << std::setw(2) << local_time.wMonth - << std::setw(2) << local_time.wDay << '/' << std::setw(2) - << local_time.wHour << std::setw(2) << local_time.wMinute - << std::setw(2) << local_time.wSecond << '.' << std::setw(3) - << local_time.wMilliseconds << ':'; + log_line += + std::format("{:02}{:02}/{:02}{:02}{:02}.{:03}:", local_time.wMonth, + local_time.wDay, local_time.wHour, local_time.wMinute, + local_time.wSecond, local_time.wMilliseconds); #elif defined(OS_POSIX) timeval tv; gettimeofday(&tv, nullptr); @@ -398,26 +396,23 @@ void ScopedEarlySupport::log(const char* file, struct tm local_time; localtime_r(&t, &local_time); struct tm* tm_time = &local_time; - stream << std::setfill('0') << std::setw(2) << 1 + tm_time->tm_mon - << std::setw(2) << tm_time->tm_mday << '/' << std::setw(2) - << tm_time->tm_hour << std::setw(2) << tm_time->tm_min - << std::setw(2) << tm_time->tm_sec << '.' << std::setw(6) - << tv.tv_usec << ':'; + log_line += + std::format("{:02}{:02}/{:02}{:02}{:02}.{:06}:", 1 + tm_time->tm_mon, + tm_time->tm_mday, tm_time->tm_hour, tm_time->tm_min, + tm_time->tm_sec, tv.tv_usec); #else #error Unsupported platform #endif } if (config.log_tickcount) { - stream << TickCount() << ':'; + log_line += std::format("{}:", TickCount()); } if (severity >= 0) { - stream << log_severity_name(severity); + log_line += log_severity_name(severity); } else { - stream << "VERBOSE" << -severity; + log_line += std::format("VERBOSE{}", -severity); } - stream << ":" << filename << ":" << line << "] " << message; - - const std::string& log_line = stream.str(); + log_line += std::format(":{}:{}] {}", filename, line, message); if (!config.formatted_log_handler || !config.formatted_log_handler(log_line.c_str())) { @@ -521,17 +516,15 @@ std::string SystemErrorCodeToString(SystemErrorCode error_code) { DWORD flags = FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS; DWORD len = FormatMessageA(flags, NULL, error_code, 0, msgbuf, static_cast(std::size(msgbuf)), NULL); - std::stringstream ss; if (len) { std::string s(msgbuf); // Messages returned by system end with line breaks. s.erase(std::remove_if(s.begin(), s.end(), ::isspace), s.end()); - ss << s << " (0x" << std::hex << error_code << ")"; + return std::format("{} ({:#x})", s, error_code); } else { - ss << "Error (0x" << std::hex << GetLastError() - << ") while retrieving error. (0x" << error_code << ")"; + return std::format("Error ({:#x}) while retrieving error. ({:#x})", + GetLastError(), error_code); } - return ss.str(); } #elif defined(OS_POSIX) std::string SystemErrorCodeToString(SystemErrorCode error_code) { diff --git a/libcef_dll/wrapper/cef_scoped_library_loader_mac.mm b/libcef_dll/wrapper/cef_scoped_library_loader_mac.mm index 9eaa6f3f0..290db22fa 100644 --- a/libcef_dll/wrapper/cef_scoped_library_loader_mac.mm +++ b/libcef_dll/wrapper/cef_scoped_library_loader_mac.mm @@ -6,8 +6,8 @@ #include #include +#include #include -#include #include "include/wrapper/cef_library_loader.h" @@ -38,10 +38,9 @@ } // Append the relative path to the framework. - std::stringstream ss; - ss << parent_dir << "/" << (helper ? kPathFromHelperExe : kPathFromMainExe) - << "/" << kFrameworkPath; - return ss.str(); + return std::format("{}/{}/{}", parent_dir, + helper ? kPathFromHelperExe : kPathFromMainExe, + kFrameworkPath); } } // namespace diff --git a/libcef_dll/wrapper/cef_scoped_sandbox_context_mac.mm b/libcef_dll/wrapper/cef_scoped_sandbox_context_mac.mm index 784c698b2..e98633cfe 100644 --- a/libcef_dll/wrapper/cef_scoped_sandbox_context_mac.mm +++ b/libcef_dll/wrapper/cef_scoped_sandbox_context_mac.mm @@ -7,8 +7,8 @@ #include #include +#include #include -#include #include "include/cef_sandbox_mac.h" @@ -39,9 +39,7 @@ } // Append the relative path to the library. - std::stringstream ss; - ss << parent_dir << "/" << kLibraryPath; - return ss.str(); + return std::format("{}/{}", parent_dir, kLibraryPath); } void* LoadLibrary(const char* path) { diff --git a/libcef_dll/wrapper/cef_xml_object.cc b/libcef_dll/wrapper/cef_xml_object.cc index 1ff6f388d..017a4f5ad 100644 --- a/libcef_dll/wrapper/cef_xml_object.cc +++ b/libcef_dll/wrapper/cef_xml_object.cc @@ -4,7 +4,8 @@ #include "include/wrapper/cef_xml_object.h" -#include +#include +#include #include "include/base/cef_logging.h" #include "include/cef_stream.h" @@ -34,7 +35,7 @@ class CefXmlObjectLoader { CefXmlObject::ObjectVector queue; int cur_depth, value_depth = -1; CefXmlReader::NodeType cur_type; - std::stringstream cur_value; + std::string cur_value; bool last_has_ns = false; queue.push_back(root_object_); @@ -50,20 +51,19 @@ class CefXmlObjectLoader { if (cur_type == XML_NODE_ELEMENT_START) { if (cur_depth == value_depth) { // Add to the current value. - cur_value << std::string(reader->GetOuterXml()); + cur_value += std::string(reader->GetOuterXml()); continue; } else if (last_has_ns && reader->GetPrefix().empty()) { if (!cur_object->HasChildren()) { // Start a new value because the last element has a namespace and // this element does not. value_depth = cur_depth; - cur_value << std::string(reader->GetOuterXml()); + cur_value += std::string(reader->GetOuterXml()); } else { // Value following a child element is not allowed. - std::stringstream ss; - ss << "Value following child element, line " - << reader->GetLineNumber(); - load_error_ = ss.str(); + load_error_ = + std::format("Value following child element, line {}", + reader->GetLineNumber()); ret = false; break; } @@ -95,8 +95,8 @@ class CefXmlObjectLoader { continue; } else if (cur_depth < value_depth) { // Done with parsing the value portion of the current element. - cur_object->SetValue(cur_value.str()); - cur_value.str(""); + cur_object->SetValue(cur_value); + cur_value.clear(); value_depth = -1; } @@ -108,11 +108,9 @@ class CefXmlObjectLoader { // Open tag without close tag or close tag without open tag should // never occur (the parser catches this error). DCHECK(false); - std::stringstream ss; - ss << "Mismatched end tag for " - << std::string(cur_object->GetName()) << ", line " - << reader->GetLineNumber(); - load_error_ = ss.str(); + load_error_ = std::format("Mismatched end tag for {}, line {}", + std::string(cur_object->GetName()), + reader->GetLineNumber()); ret = false; break; } @@ -123,17 +121,15 @@ class CefXmlObjectLoader { cur_type == XML_NODE_ENTITY_REFERENCE) { if (cur_depth == value_depth) { // Add to the current value. - cur_value << std::string(reader->GetValue()); + cur_value += std::string(reader->GetValue()); } else if (!cur_object->HasChildren()) { // Start a new value. value_depth = cur_depth; - cur_value << std::string(reader->GetValue()); + cur_value += std::string(reader->GetValue()); } else { // Value following a child element is not allowed. - std::stringstream ss; - ss << "Value following child element, line " - << reader->GetLineNumber(); - load_error_ = ss.str(); + load_error_ = std::format("Value following child element, line {}", + reader->GetLineNumber()); ret = false; break; } diff --git a/tests/cefclient/browser/client_handler.cc b/tests/cefclient/browser/client_handler.cc index 0b8071ef5..24d127049 100644 --- a/tests/cefclient/browser/client_handler.cc +++ b/tests/cefclient/browser/client_handler.cc @@ -7,8 +7,8 @@ #include #include -#include -#include +#include +#include #include #include "include/base/cef_callback.h" @@ -93,12 +93,8 @@ std::string GetTimeString(const CefTime& value) { month = "Invalid"; } - std::stringstream ss; - ss << month << " " << value.day_of_month << ", " << value.year << " " - << std::setfill('0') << std::setw(2) << value.hour << ":" - << std::setfill('0') << std::setw(2) << value.minute << ":" - << std::setfill('0') << std::setw(2) << value.second; - return ss.str(); + return std::format("{} {}, {} {:02}:{:02}:{:02}", month, value.day_of_month, + value.year, value.hour, value.minute, value.second); } std::string GetTimeString(const CefBaseTime& value) { @@ -195,27 +191,31 @@ std::string GetCertificateInformation(CefRefPtr cert, // Build a table showing certificate information. Various types of invalid // certificates can be tested using https://badssl.com/. - std::stringstream ss; - ss << "

X.509 Certificate Information:

" - ""; + std::string result; + result.reserve(2048); + + result += + "

X.509 Certificate Information:

" + "
FieldValue
"; if (certstatus != CERT_STATUS_NONE) { - ss << ""; - } - - ss << "" - "" - "" - << "" - ""; + std::format_to(std::back_inserter(result), + "", + GetCertStatusString(certstatus)); + } + + std::format_to( + std::back_inserter(result), + "" + "" + "" + "" + "", + (subject.get() ? subject->GetDisplayName().ToString() : " "), + (issuer.get() ? issuer->GetDisplayName().ToString() : " "), + GetBinaryString(cert->GetSerialNumber()), + GetTimeString(cert->GetValidStart()), + GetTimeString(cert->GetValidExpiry())); CefX509Certificate::IssuerChainBinaryList der_chain_list; CefX509Certificate::IssuerChainBinaryList pem_chain_list; @@ -227,17 +227,15 @@ std::string GetCertificateInformation(CefRefPtr cert, pem_chain_list.insert(pem_chain_list.begin(), cert->GetPEMEncoded()); for (size_t i = 0U; i < der_chain_list.size(); ++i) { - ss << "" - "" - "" - ""; + std::format_to( + std::back_inserter(result), + R"()" + R"()", + GetBinaryString(der_chain_list[i]), GetBinaryString(pem_chain_list[i])); } - ss << "
FieldValue
Status" << GetCertStatusString(certstatus) - << "
Subject" - << (subject.get() ? subject->GetDisplayName().ToString() : " ") - << "
Issuer" - << (issuer.get() ? issuer->GetDisplayName().ToString() : " ") - << "
Serial #*" - << GetBinaryString(cert->GetSerialNumber()) << "
Valid Start" << GetTimeString(cert->GetValidStart()) - << "
Valid Expiry" - << GetTimeString(cert->GetValidExpiry()) << "
Status{}
Subject{}
Issuer{}
Serial #*{}
Valid Start{}
Valid Expiry{}
DER Encoded*" - << GetBinaryString(der_chain_list[i]) - << "
PEM Encoded*" - << GetBinaryString(pem_chain_list[i]) << "
DER Encoded*{}
PEM Encoded*{}
* Displayed value is base64 encoded."; - return ss.str(); + result += " * Displayed value is base64 encoded."; + return result; } void OnTestProcessMessageReceived( @@ -817,29 +815,29 @@ bool ClientHandler::OnConsoleMessage(CefRefPtr browser, FILE* file = fopen(console_log_file_.c_str(), "a"); if (file) { - std::stringstream ss; - ss << "Level: "; + const char* level_str = nullptr; switch (level) { case LOGSEVERITY_DEBUG: - ss << "Debug" << NEWLINE; + level_str = "Debug"; break; case LOGSEVERITY_INFO: - ss << "Info" << NEWLINE; + level_str = "Info"; break; case LOGSEVERITY_WARNING: - ss << "Warn" << NEWLINE; + level_str = "Warn"; break; case LOGSEVERITY_ERROR: - ss << "Error" << NEWLINE; + level_str = "Error"; break; default: NOTREACHED(); break; } - ss << "Message: " << message.ToString() << NEWLINE - << "Source: " << source.ToString() << NEWLINE << "Line: " << line - << NEWLINE << "-----------------------" << NEWLINE; - fputs(ss.str().c_str(), file); + auto log_entry = std::format( + "Level: {}" NEWLINE "Message: {}" NEWLINE "Source: {}" NEWLINE + "Line: {}" NEWLINE "-----------------------" NEWLINE, + level_str, message.ToString(), source.ToString(), line); + fputs(log_entry.c_str(), file); fclose(file); } @@ -1309,7 +1307,6 @@ bool ClientHandler::HasSSLInformation(CefRefPtr browser) { } void ClientHandler::ShowSSLInformation(CefRefPtr browser) { - std::stringstream ss; CefRefPtr nav = browser->GetHost()->GetVisibleNavigationEntry(); if (!nav) { @@ -1321,39 +1318,45 @@ void ClientHandler::ShowSSLInformation(CefRefPtr browser) { return; } - ss << "SSL Information" - "" - "

SSL Connection

" - << ""; + std::string result; + result.reserve(4096); + + result += + R"html(SSL Information + +

SSL Connection

+
FieldValue
)html"; CefURLParts urlparts; if (CefParseURL(nav->GetURL(), urlparts)) { CefString port(&urlparts.port); - ss << ""; + result += ""; } - ss << ""; - ss << ""; + std::format_to(std::back_inserter(result), + "" + "", + GetSSLVersionString(ssl->GetSSLVersion()), + GetContentStatusString(ssl->GetContentStatus())); - ss << "
FieldValue
Server" << CefString(&urlparts.host).ToString(); + std::format_to(std::back_inserter(result), "
Server{}", + CefString(&urlparts.host).ToString()); if (!port.empty()) { - ss << ":" << port.ToString(); + std::format_to(std::back_inserter(result), ":{}", port.ToString()); } - ss << "
SSL Version" - << GetSSLVersionString(ssl->GetSSLVersion()) << "
Content Status" - << GetContentStatusString(ssl->GetContentStatus()) << "
SSL Version{}
Content Status{}
"; + result += ""; CefRefPtr cert = ssl->GetX509Certificate(); if (cert.get()) { - ss << GetCertificateInformation(cert, ssl->GetCertStatus()); + result += GetCertificateInformation(cert, ssl->GetCertStatus()); } - ss << ""; + result += ""; auto config = std::make_unique(); config->with_controls = false; config->with_osr = is_osr_; - config->url = test_runner::GetDataURI(ss.str(), "text/html"); + config->url = test_runner::GetDataURI(result, "text/html"); MainContext::Get()->GetRootWindowManager()->CreateRootWindow( std::move(config)); } diff --git a/tests/cefclient/browser/config_test.cc b/tests/cefclient/browser/config_test.cc index 58001c889..04992636a 100644 --- a/tests/cefclient/browser/config_test.cc +++ b/tests/cefclient/browser/config_test.cc @@ -5,7 +5,6 @@ #include "tests/cefclient/browser/config_test.h" #include -#include #include #include diff --git a/tests/cefclient/browser/preferences_test.cc b/tests/cefclient/browser/preferences_test.cc index e57ed223c..fab140417 100644 --- a/tests/cefclient/browser/preferences_test.cc +++ b/tests/cefclient/browser/preferences_test.cc @@ -4,7 +4,7 @@ #include "tests/cefclient/browser/preferences_test.h" -#include +#include #include #include @@ -162,15 +162,14 @@ class Handler : public CefMessageRouterBrowserSide::Handler { // Create a message that accurately represents the result. std::string message; if (!changed_names.empty()) { - std::stringstream ss; - ss << "Successfully changed " << changed_names.size() << " preferences; "; + message = std::format("Successfully changed {} preferences; ", + changed_names.size()); for (size_t i = 0; i < changed_names.size(); ++i) { - ss << changed_names[i]; + message += changed_names[i]; if (i < changed_names.size() - 1) { - ss << ", "; + message += ", "; } } - message = ss.str(); } if (!success) { diff --git a/tests/cefclient/browser/response_filter_test.cc b/tests/cefclient/browser/response_filter_test.cc index dbc7017be..387979198 100644 --- a/tests/cefclient/browser/response_filter_test.cc +++ b/tests/cefclient/browser/response_filter_test.cc @@ -5,7 +5,7 @@ #include "tests/cefclient/browser/response_filter_test.h" #include -#include +#include #include #include "include/base/cef_logging.h" @@ -93,9 +93,8 @@ class FindReplaceResponseFilter : public CefResponseFilter { // Matched the next character in the find string. if (++find_match_offset_ == find_size) { // Complete match of the find string. Write the replace string. - std::stringstream ss; - ss << ++replace_count_ << ". " << kReplaceString; - const std::string& replace_str = ss.str(); + const std::string replace_str = + std::format("{}. {}", ++replace_count_, kReplaceString); Write(replace_str.c_str(), replace_str.size(), WRITE_PARAMS); // Start over looking for a match. diff --git a/tests/cefclient/browser/root_window_manager.cc b/tests/cefclient/browser/root_window_manager.cc index 455f6cb29..7dfbe7bbe 100644 --- a/tests/cefclient/browser/root_window_manager.cc +++ b/tests/cefclient/browser/root_window_manager.cc @@ -4,7 +4,7 @@ #include "tests/cefclient/browser/root_window_manager.h" -#include +#include #include "include/base/cef_callback.h" #include "include/base/cef_logging.h" @@ -369,10 +369,10 @@ CefRefPtr RootWindowManager::CreateRequestContext( } else { // Give each browser a unique cache path. This will create completely // isolated context objects. - std::stringstream ss; - ss << command_line->GetSwitchValue(switches::kCachePath).ToString() - << file_util::kPathSep << time(nullptr); - CefString(&settings.cache_path) = ss.str(); + CefString(&settings.cache_path) = std::format( + "{}{}{}", + command_line->GetSwitchValue(switches::kCachePath).ToString(), + file_util::kPathSep, time(nullptr)); } } diff --git a/tests/cefclient/browser/test_runner.cc b/tests/cefclient/browser/test_runner.cc index 7057f7b40..1b5144f3a 100644 --- a/tests/cefclient/browser/test_runner.cc +++ b/tests/cefclient/browser/test_runner.cc @@ -5,9 +5,10 @@ #include "tests/cefclient/browser/test_runner.h" #include +#include +#include #include #include -#include #include #include "include/base/cef_callback.h" @@ -66,10 +67,10 @@ void RunGetSourceTest(CefRefPtr browser) { void Visit(const CefString& string) override { std::string source = AsciiStrReplace(string, "<", "<"); source = AsciiStrReplace(source, ">", ">"); - std::stringstream ss; - ss << "Source:
" << source
-         << "
"; - LoadStringResourcePage(browser_, kTestGetSourcePage, ss.str()); + auto html = std::format( + R"html(Source:
{}
)html", + source); + LoadStringResourcePage(browser_, kTestGetSourcePage, html); } private: @@ -87,10 +88,10 @@ void RunGetTextTest(CefRefPtr browser) { void Visit(const CefString& string) override { std::string text = AsciiStrReplace(string, "<", "<"); text = AsciiStrReplace(text, ">", ">"); - std::stringstream ss; - ss << "Text:
" << text
-         << "
"; - LoadStringResourcePage(browser_, kTestGetTextPage, ss.str()); + auto html = std::format( + R"html(Text:
{}
)html", + text); + LoadStringResourcePage(browser_, kTestGetTextPage, html); } private: @@ -255,11 +256,8 @@ void PromptFPS(CefRefPtr browser) { return; } - // Format the default value string. - std::stringstream ss; - ss << browser->GetHost()->GetWindowlessFrameRate(); - - Prompt(browser, kPromptFPS, "Enter FPS", ss.str()); + Prompt(browser, kPromptFPS, "Enter FPS", + std::to_string(browser->GetHost()->GetWindowlessFrameRate())); } void PromptDSF(CefRefPtr browser) { @@ -269,12 +267,9 @@ void PromptDSF(CefRefPtr browser) { return; } - // Format the default value string. - std::stringstream ss; - ss << *RootWindow::GetForBrowser(browser->GetIdentifier()) - ->GetDeviceScaleFactor(); - - Prompt(browser, kPromptDSF, "Enter Device Scale Factor", ss.str()); + Prompt(browser, kPromptDSF, "Enter Device Scale Factor", + std::to_string(*RootWindow::GetForBrowser(browser->GetIdentifier()) + ->GetDeviceScaleFactor())); } void BeginTracing() { @@ -606,19 +601,19 @@ void RunTest(CefRefPtr browser, int id) { } std::string DumpRequestContents(CefRefPtr request) { - std::stringstream ss; + std::string result; + result.reserve(512); - ss << "URL: " << std::string(request->GetURL()); - ss << "\nMethod: " << std::string(request->GetMethod()); + std::format_to(std::back_inserter(result), "URL: {}\nMethod: {}", + request->GetURL().ToString(), request->GetMethod().ToString()); CefRequest::HeaderMap headerMap; request->GetHeaderMap(headerMap); if (headerMap.size() > 0) { - ss << "\nHeaders:"; - CefRequest::HeaderMap::const_iterator it = headerMap.begin(); - for (; it != headerMap.end(); ++it) { - ss << "\n\t" << std::string((*it).first) << ": " - << std::string((*it).second); + result += "\nHeaders:"; + for (const auto& header : headerMap) { + std::format_to(std::back_inserter(result), "\n\t{}: {}", + header.first.ToString(), header.second.ToString()); } } @@ -627,32 +622,30 @@ std::string DumpRequestContents(CefRefPtr request) { CefPostData::ElementVector elements; postData->GetElements(elements); if (elements.size() > 0) { - ss << "\nPost Data:"; - CefRefPtr element; - CefPostData::ElementVector::const_iterator it = elements.begin(); - for (; it != elements.end(); ++it) { - element = (*it); + result += "\nPost Data:"; + for (const auto& element : elements) { if (element->GetType() == PDE_TYPE_BYTES) { // the element is composed of bytes - ss << "\n\tBytes: "; + result += "\n\tBytes: "; if (element->GetBytesCount() == 0) { - ss << "(empty)"; + result += "(empty)"; } else { // retrieve the data. size_t size = element->GetBytesCount(); char* bytes = new char[size]; element->GetBytes(size, bytes); - ss << std::string(bytes, size); + result += std::string(bytes, size); delete[] bytes; } } else if (element->GetType() == PDE_TYPE_FILE) { - ss << "\n\tFile: " << std::string(element->GetFile()); + std::format_to(std::back_inserter(result), "\n\tFile: {}", + element->GetFile().ToString()); } } } } - return ss.str(); + return result; } CefRefPtr GetDumpResponse( diff --git a/tests/cefclient/renderer/client_renderer.cc b/tests/cefclient/renderer/client_renderer.cc index 40862f8d7..6425d87ef 100644 --- a/tests/cefclient/renderer/client_renderer.cc +++ b/tests/cefclient/renderer/client_renderer.cc @@ -4,7 +4,6 @@ #include "tests/cefclient/renderer/client_renderer.h" -#include #include #include "include/cef_crash_util.h" diff --git a/tests/cefsimple/simple_handler.cc b/tests/cefsimple/simple_handler.cc index 41d0841a4..6d261b266 100644 --- a/tests/cefsimple/simple_handler.cc +++ b/tests/cefsimple/simple_handler.cc @@ -4,7 +4,7 @@ #include "tests/cefsimple/simple_handler.h" -#include +#include #include #include "include/base/cef_callback.h" @@ -122,13 +122,12 @@ void SimpleHandler::OnLoadError(CefRefPtr browser, } // Display a load error message using a data: URI. - std::stringstream ss; - ss << "" - "

Failed to load URL " - << std::string(failedUrl) << " with error " << std::string(errorText) - << " (" << errorCode << ").

"; + auto html = std::format( + R"html( +

Failed to load URL {} with error {} ({}).

)html", + failedUrl.ToString(), errorText.ToString(), static_cast(errorCode)); - frame->LoadURL(GetDataURI(ss.str(), "text/html")); + frame->LoadURL(GetDataURI(html, "text/html")); } void SimpleHandler::ShowMainWindow() { diff --git a/tests/ceftests/cookie_unittest.cc b/tests/ceftests/cookie_unittest.cc index 6ff941803..3978017f4 100644 --- a/tests/ceftests/cookie_unittest.cc +++ b/tests/ceftests/cookie_unittest.cc @@ -4,6 +4,7 @@ #include #include +#include #include #include "include/base/cef_callback.h" @@ -332,7 +333,6 @@ void TestInvalidCookie(CefRefPtr manager, void TestMultipleCookies(CefRefPtr manager, CefRefPtr event) { - std::stringstream ss; int i; CookieVector cookies; @@ -343,12 +343,8 @@ void TestMultipleCookies(CefRefPtr manager, for (i = 0; i < kNumCookies; i++) { CefCookie cookie; - ss << "my_cookie" << i; - CefString(&cookie.name).FromASCII(ss.str().c_str()); - ss.str(""); - ss << "My Value " << i; - CefString(&cookie.value).FromASCII(ss.str().c_str()); - ss.str(""); + CefString(&cookie.name).FromASCII(std::format("my_cookie{}", i).c_str()); + CefString(&cookie.value).FromASCII(std::format("My Value {}", i).c_str()); cookies.push_back(cookie); } @@ -366,12 +362,8 @@ void TestMultipleCookies(CefRefPtr manager, for (i = 0; it != cookies.end(); ++it, ++i) { const CefCookie& cookie = *it; - ss << "my_cookie" << i; - EXPECT_EQ(CefString(&cookie.name), ss.str()); - ss.str(""); - ss << "My Value " << i; - EXPECT_EQ(CefString(&cookie.value), ss.str()); - ss.str(""); + EXPECT_EQ(CefString(&cookie.name), std::format("my_cookie{}", i)); + EXPECT_EQ(CefString(&cookie.value), std::format("My Value {}", i)); } cookies.clear(); @@ -405,12 +397,8 @@ void TestMultipleCookies(CefRefPtr manager, for (i = 0; i < kNumCookies; i++) { CefCookie cookie; - ss << "my_cookie" << i; - CefString(&cookie.name).FromASCII(ss.str().c_str()); - ss.str(""); - ss << "My Value " << i; - CefString(&cookie.value).FromASCII(ss.str().c_str()); - ss.str(""); + CefString(&cookie.name).FromASCII(std::format("my_cookie{}", i).c_str()); + CefString(&cookie.value).FromASCII(std::format("My Value {}", i).c_str()); cookies.push_back(cookie); } @@ -1077,9 +1065,7 @@ std::string GetCookieAccessOrigin(const std::string& scheme, return test_server::GetOrigin(kUseHttpsServerScheme); } - std::stringstream ss; - ss << scheme << "://" << kCookieAccessDomain; - return ss.str(); + return std::format("{}://{}", scheme, kCookieAccessDomain); } std::string GetCookieAccessUrl1(const std::string& scheme, diff --git a/tests/ceftests/cors_unittest.cc b/tests/ceftests/cors_unittest.cc index 53e9cdb56..49ee5148b 100644 --- a/tests/ceftests/cors_unittest.cc +++ b/tests/ceftests/cors_unittest.cc @@ -3,8 +3,9 @@ // can be found in the LICENSE file. #include +#include #include -#include +#include #include #include "include/base/cef_callback.h" @@ -69,10 +70,9 @@ std::string GetOrigin(HandlerType handler) { // TODO: Only call test_server::GetOrigin() after test server // initialization. if (!kUseHttpsServerScheme) { - std::stringstream ss; - ss << "http://" << test_server::kHttpServerAddress << ":" - << test_server::kHttpServerPort; - return ss.str(); + return std::format("http://{}:{}", + std::string_view(test_server::kHttpServerAddress), + test_server::kHttpServerPort); } return test_server::GetOrigin(kUseHttpsServerScheme); case HandlerType::HTTP_SCHEME: diff --git a/tests/ceftests/devtools_message_unittest.cc b/tests/ceftests/devtools_message_unittest.cc index 7fbbb1853..a772bd169 100644 --- a/tests/ceftests/devtools_message_unittest.cc +++ b/tests/ceftests/devtools_message_unittest.cc @@ -3,7 +3,7 @@ // can be found in the LICENSE file. #include -#include +#include #include "include/base/cef_callback.h" #include "include/base/cef_callback_helpers.h" @@ -193,15 +193,16 @@ class DevToolsMessageTestHandler : public TestHandler { int message_id = next_message_id_++; - std::stringstream message; - message << "{\"id\":" << message_id << ",\"method\":\"" << method << "\""; + std::string message; if (!params.empty()) { - message << ",\"params\":" << params; + message = std::format(R"({{"id":{},"method":"{}","params":{}}})", + message_id, method, params); + } else { + message = std::format(R"({{"id":{},"method":"{}"}})", message_id, method); } - message << "}"; // Set expected result state. - pending_message_ = message.str(); + pending_message_ = message; pending_result_next_ = std::move(next_step); pending_result_ = {message_id, expected_success, expected_result}; @@ -276,13 +277,12 @@ class DevToolsMessageTestHandler : public TestHandler { pending_event_next_ = base::BindOnce(&DevToolsMessageTestHandler::AfterNavigate, this); - std::stringstream params; - params << "{\"url\":\"" << kTestUrl2 << "\"}"; + std::string params = std::format(R"({{"url":"{}"}})", kTestUrl2); // STEP 3: Page domain notifications are enabled. Now start a new // navigation (but do nothing on method result) and wait for the // "Page.frameNavigated" event. - ExecuteMethod("Page.navigate", params.str(), base::DoNothing(), + ExecuteMethod("Page.navigate", params, base::DoNothing(), /*expected_result=*/"{\"frameId\":"); } diff --git a/tests/ceftests/dom_unittest.cc b/tests/ceftests/dom_unittest.cc index 1fa601699..d85ce96d8 100644 --- a/tests/ceftests/dom_unittest.cc +++ b/tests/ceftests/dom_unittest.cc @@ -2,6 +2,8 @@ // reserved. Use of this source code is governed by a BSD-style license that // can be found in the LICENSE file. +#include + #include "include/cef_dom.h" #include "tests/ceftests/test_handler.h" #include "tests/gtest/include/gtest/gtest.h" @@ -293,18 +295,18 @@ class TestDOMHandler : public TestHandler { void RunTest() override { // Specified values are in CSS pixels. - std::stringstream mainHtml; - mainHtml << "" - "The Title" - "" - "

Hello From
" - "Main Frame

" - "
" - "" - ""; - - AddResource(kTestUrl, mainHtml.str(), "text/html"); + std::string mainHtml = + "" + "The Title" + "" + "

Hello From
" + "Main Frame

" + "
" + "" + ""; + + AddResource(kTestUrl, mainHtml, "text/html"); CreateBrowser(kTestUrl); // Time out the test after a reasonable period of time. diff --git a/tests/ceftests/frame_handler_unittest.cc b/tests/ceftests/frame_handler_unittest.cc index 5d1d25b29..671534061 100644 --- a/tests/ceftests/frame_handler_unittest.cc +++ b/tests/ceftests/frame_handler_unittest.cc @@ -2,12 +2,12 @@ // Use of this source code is governed by a BSD-style license that can be found // in the LICENSE file. +#include #include #include #include #include #include -#include #include #include "include/base/cef_callback.h" @@ -104,10 +104,8 @@ struct FrameStatus { const int expected_ct = is_temporary_ ? 0 : expected_query_ct_; #if VERBOSE_DEBUGGING if (msg) { - std::stringstream ss; - ss << ident_str_ << "(expected=" << expected_ct - << " delivered=" << delivered_query_ct_ << ")"; - *msg += ss.str(); + *msg += std::format("{}(expected={} delivered={})", ident_str_, + expected_ct, delivered_query_ct_); } #endif return delivered_query_ct_ == expected_ct; @@ -124,16 +122,15 @@ struct FrameStatus { bool IsLoaded(std::string* msg = nullptr) const { #if VERBOSE_DEBUGGING if (msg) { - std::stringstream ss; - ss << ident_str_ << "("; + *msg += ident_str_ + "("; for (int i = 0; i <= LOAD_END; ++i) { - ss << GetCallbackName(i) << "=" << got_callback_[i]; + *msg += std::format("{}={}", GetCallbackName(i), + static_cast(got_callback_[i])); if (i < LOAD_END) { - ss << " "; + *msg += " "; } } - ss << ")"; - *msg += ss.str(); + *msg += ")"; } #endif return got_callback_[LOAD_END]; @@ -165,11 +162,10 @@ struct FrameStatus { std::string GetDebugString(bool dump_state = false) const { std::string result = debug_info_ + ident_str_; if (dump_state) { - std::stringstream ss; - ss << "\nis_main=" << is_main_ << "\nis_first_main=" << is_first_main_ - << "\nis_last_main=" << is_last_main_ - << "\nis_temporary=" << is_temporary_; - result += ss.str(); + result += std::format( + "\nis_main={}\nis_first_main={}\nis_last_main={}" + "\nis_temporary={}", + is_main_, is_first_main_, is_last_main_, is_temporary_); } return result; } @@ -913,14 +909,13 @@ class NavigateOrderMainTestHandler : public OrderMainTestHandler { } std::string GetURLForNav(int nav, const std::string& suffix = "") const { - std::stringstream ss; if (cross_origin_) { - ss << kOrderMainUrlPrefix << nav << "/cross-origin" << suffix << ".html"; + return std::format("{}{}/cross-origin{}.html", kOrderMainUrlPrefix, nav, + suffix); } else { - ss << kOrderMainUrlPrefix << "/" << nav << "same-origin" << suffix - << ".html"; + return std::format("{}/{}same-origin{}.html", kOrderMainUrlPrefix, nav, + suffix); } - return ss.str(); } private: @@ -1003,10 +998,8 @@ class FrameStatusMap { if (size() != expected_frame_ct_) { #if VERBOSE_DEBUGGING if (msg) { - std::stringstream ss; - ss << " SUB COUNT MISMATCH! size=" << size() - << " expected=" << expected_frame_ct_; - *msg += ss.str(); + *msg += std::format(" SUB COUNT MISMATCH! size={} expected={}", size(), + expected_frame_ct_); } #endif return false; @@ -1031,10 +1024,8 @@ class FrameStatusMap { if (size() != expected_frame_ct_) { #if VERBOSE_DEBUGGING if (msg) { - std::stringstream ss; - ss << " SUB COUNT MISMATCH! size=" << size() - << " expected=" << expected_frame_ct_; - *msg += ss.str(); + *msg += std::format(" SUB COUNT MISMATCH! size={} expected={}", size(), + expected_frame_ct_); } #endif return false; @@ -1497,15 +1488,13 @@ class CrossOriginOrderSubTestHandler : public OrderSubTestHandler { protected: std::string GetSubURL1ForNav(int nav) const override { - std::stringstream ss; - ss << kOrderMainUrlPrefix << nav << "-sub1/sub-cross-origin.html"; - return ss.str(); + return std::format("{}{}-sub1/sub-cross-origin.html", kOrderMainUrlPrefix, + nav); } std::string GetSubURL2ForNav(int nav) const override { - std::stringstream ss; - ss << kOrderMainUrlPrefix << nav << "-sub2/sub-cross-origin.html"; - return ss.str(); + return std::format("{}{}-sub2/sub-cross-origin.html", kOrderMainUrlPrefix, + nav); } void VerifyTestResults() override { diff --git a/tests/ceftests/frame_unittest.cc b/tests/ceftests/frame_unittest.cc index c954b1b3b..0f02bc70b 100644 --- a/tests/ceftests/frame_unittest.cc +++ b/tests/ceftests/frame_unittest.cc @@ -2,6 +2,7 @@ // reserved. Use of this source code is governed by a BSD-style license that // can be found in the LICENSE file. +#include #include #include "include/base/cef_callback.h" @@ -1146,9 +1147,7 @@ class FrameNavExpectationsRendererMultiNav // Create a URL containing the nav number. std::string GetMultiNavURL(const std::string& origin, int nav) { - std::stringstream ss; - ss << origin << "nav" << nav << ".html"; - return ss.str(); + return std::format("{}nav{}.html", origin, nav); } // Extract the nav number from the URL. @@ -1829,18 +1828,16 @@ class FrameNavExpectationsBrowserTestNestedIframes return "Nav2"; + html += std::format(R"()", kBaseUrl, i * 10); } - ss << ""; + html += ""; - state.manager_->AddContentProvider(kUrl, ss.str(), "text/html", 0, - std::string()); + state.manager_->AddContentProvider(kUrl, html, "text/html", 0, std::string()); state.manager_->AddProvider(new EchoProvider(kBaseUrl), 0, std::string()); CefRefPtr handler = @@ -1075,9 +1074,7 @@ TEST(ResourceManagerTest, ManyRequests) { // Requests should complete in order due to the delay. for (size_t i = 0; i < state.messages_.size(); ++i) { - ss.str(""); - ss << kBaseUrl << (i * 10); - EXPECT_EQ(ss.str(), state.messages_[i]); + EXPECT_EQ(std::format("{}{}", kBaseUrl, i * 10), state.messages_[i]); } } diff --git a/tests/ceftests/resource_request_handler_unittest.cc b/tests/ceftests/resource_request_handler_unittest.cc index 2e80f9de7..90801b661 100644 --- a/tests/ceftests/resource_request_handler_unittest.cc +++ b/tests/ceftests/resource_request_handler_unittest.cc @@ -4,8 +4,8 @@ #include #include +#include #include -#include #include #include "include/base/cef_callback.h" @@ -2219,33 +2219,26 @@ class SubresourceResponseTest : public RoutingTestHandler { } std::string GetMainResponseBody() const { - std::stringstream html; - html << ""; - + std::string content; if (subframe_) { const std::string& url = GetSubURL(); - html << ""; + content = std::format(R"()", url); } else { const std::string& url = GetStartupURL(); - html << ""; + content = std::format( + R"()", url); } - - html << "

Main

"; - return html.str(); + return std::format("{}

Main

", + content); } std::string GetSubResponseBody() const { EXPECT_TRUE(subframe_); - std::stringstream html; - html << ""; - const std::string& url = GetStartupURL(); - html << ""; - - html << "

Sub

"; - return html.str(); + return std::format( + R"(

Sub

)", + url); } std::string GetResponseBody() const { @@ -2776,14 +2769,10 @@ class RedirectResponseTest : public TestHandler { private: std::string GetHtml() const { - std::stringstream html; - html << ""; - const std::string& url = resource_test_->start_url(); - html << ""; - - html << "

Main

"; - return html.str(); + return std::format( + R"(

Main

)", + url); } class ResourceTest { diff --git a/tests/ceftests/scheme_handler_unittest.cc b/tests/ceftests/scheme_handler_unittest.cc index 681b46be0..ed639c5ac 100644 --- a/tests/ceftests/scheme_handler_unittest.cc +++ b/tests/ceftests/scheme_handler_unittest.cc @@ -3,7 +3,7 @@ // can be found in the LICENSE file. #include -#include +#include #include #include "include/base/cef_callback.h" @@ -708,51 +708,50 @@ void SetUpXHR(TestResults* test_results, const XHRTestSettings& settings) { } test_results->url = settings.url; - std::stringstream ss; - ss << "" - "" - "" - "Running execXMLHttpRequest..." - ""; - test_results->html = ss.str(); + test_results->html = std::format( + R"html( + + +Running execXMLHttpRequest... +)html", + xhr_code); test_results->exit_url = "https://tests/exit"; } @@ -780,34 +779,33 @@ void SetUpFetch(TestResults* test_results, const FetchTestSettings& settings) { } test_results->url = settings.url; - std::stringstream ss; - ss << "" - "" - "" - "Running execFetchHttpRequest..." - ""; - test_results->html = ss.str(); + test_results->html = std::format( + R"html( + + +Running execFetchHttpRequest... +)html", + request_url); test_results->exit_url = "https://tests/exit"; } // namespace @@ -821,54 +819,49 @@ void SetUpXSS(TestResults* test_results, // 3. |sub_url| tries to call a JS function in |url|. // 4. |url| tries to call a JS function in |sub_url|. - std::stringstream ss; std::string domain_line; if (!domain.empty()) { - domain_line = "document.domain = '" + domain + "';"; + domain_line = std::format("document.domain = '{}';", domain); if (url.find("http") == 0 && sub_url.find("http") == 0) { test_results->needs_same_origin_policy_relaxation = true; } } test_results->sub_url = sub_url; - ss << "" - "" - "" - "Running execXSSRequest..." - ""; - test_results->sub_html = ss.str(); + test_results->sub_html = std::format( + R"html( + + +Running execXSSRequest... +)html", + domain_line); test_results->url = url; - ss.str(""); - ss << "" - "" - "" - "