0
Files
src/fuchsia_web/webengine/web_engine_integration_logging_test.cc
Arthur Sonzogni 59ac8227c5 Rename {absl => std}::optional in minor top-level dirs
Automated patch, intended to be effectively a no-op.

This patch gather the changes for every top-level directories with less
than 150 files modified:
 #  directory
--- ---------------
150 remoting
98  gpu
87  chromecast
79  mojo
70  storage
65  fuchsia_web
46  sandbox
44  android_webview
38  google_apis
27  pdf
25  printing
20  headless
13  ipc
11  crypto
10  sql
3   dbus
2   testing
2   skia
2   gin
2   apps
1   rlz
1   codelabs

Context:
https://groups.google.com/a/chromium.org/g/cxx/c/nBD_1LaanTc/m/ghh-ZZhWAwAJ?utm_medium=email&utm_source=footer

As of https://crrev.com/1204351, absl::optional is now a type alias for
std::optional. We should migrate toward it.

Script:
```

function replace {
  echo "Replacing $1 by $2"
  git grep -l "$1" \
		| cut -f1 -d: \
		| grep \
			-e "^codelabs" \
			-e "^rlz" \
			-e "^apps" \
			-e "^gin" \
			-e "^skia" \
			-e "^testing" \
			-e "^dbus" \
			-e "^sql" \
			-e "^crypto" \
			-e "^ipc" \
			-e "^headless" \
			-e "^printing" \
			-e "^pdf" \
			-e "^google_apis" \
			-e "^android_webview" \
			-e "^sandbox" \
			-e "^fuchsia_web" \
			-e "^storage" \
			-e "^mojo" \
			-e "^chromecast" \
			-e "^gpu" \
			-e "^remoting" \
		| sort \
		| uniq \
		| grep \
			-e "\.h" \
			-e "\.cc" \
			-e "\.mm" \
			-e "\.py" \
	  | xargs sed -i "s/$1/$2/g"
}

replace "absl::make_optional" "std::make_optional"
replace "absl::optional" "std::optional"
replace "absl::nullopt" "std::nullopt"
replace "absl::in_place" "std::in_place"
replace "absl::in_place_t" "std::in_place_t"
replace "\"third_party\/abseil-cpp\/absl\/types\/optional.h\"" "<optional>"
git cl format
```

CQ_INCLUDE_TRYBOTS=luci.chrome.try:chromeos-betty-pi-arc-chrome

Bug: chromium:1500249
Change-Id: I0eca8ff96f5712ba746ac8d8da93d03a86d8292c
AX-Relnotes: n/a.
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/5009410
Reviewed-by: danakj <danakj@chromium.org>
Owners-Override: danakj <danakj@chromium.org>
Commit-Queue: Arthur Sonzogni <arthursonzogni@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1222826}
2023-11-10 09:46:54 +00:00

113 lines
4.4 KiB
C++

// Copyright 2020 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include <fidl/fuchsia.logger/cpp/fidl.h>
#include <cstring>
#include <optional>
#include "base/containers/contains.h"
#include "base/fuchsia/test_log_listener_safe.h"
#include "base/strings/string_piece.h"
#include "base/strings/stringprintf.h"
#include "fuchsia_web/common/test/frame_test_util.h"
#include "fuchsia_web/webengine/test/context_provider_for_test.h"
#include "fuchsia_web/webengine/test/isolated_archivist.h"
#include "fuchsia_web/webengine/web_engine_integration_test_base.h"
namespace {
// Name of the console logging test page.
constexpr char kLogTestPageFileName[] = "console_logging.html";
constexpr char kLogTestPageDebugMessage[] = "This is a debug() message.";
// Debug name to create Frames with, to use as their logging tag.
constexpr char kFrameLogTag[] = "Test🖼🪵";
constexpr char kNormalizedPortNumber[] = "678";
// Replaces the line number in frame_impl.cc with kNormalizedLineNumber and
// the port with kNormalizedPortNumber to enable reliable comparison of
// console log messages.
std::string NormalizeConsoleLogMessage(base::StringPiece original) {
const char kSchemePortColon[] = "http://127.0.0.1:";
size_t port_begin =
original.find(kSchemePortColon) + strlen(kSchemePortColon);
size_t path_begin = original.find("/", port_begin);
return std::string(original).replace(port_begin, path_begin - port_begin,
kNormalizedPortNumber);
}
} // namespace
class WebEngineIntegrationLoggingTest : public WebEngineIntegrationTestBase {
protected:
WebEngineIntegrationLoggingTest()
: isolated_archivist_(
*filtered_service_directory().outgoing_directory()) {}
~WebEngineIntegrationLoggingTest() override {
// We're about to shut down the realm; unbind to unhook the error handler.
frame_.Unbind();
context_.Unbind();
}
void StartWebEngine(base::CommandLine command_line) override {
context_provider_.emplace(
ContextProviderForTest::Create(std::move(command_line)));
context_provider_->ptr().set_error_handler(
[](zx_status_t status) { FAIL() << zx_status_get_string(status); });
}
fuchsia::web::ContextProvider* GetContextProvider() override {
return context_provider_->get();
}
fidl::Client<fuchsia_logger::Log>& log() { return isolated_archivist_.log(); }
IsolatedArchivist isolated_archivist_;
std::optional<ContextProviderForTest> context_provider_;
};
// Verifies that calling messages from console.debug() calls go to the Fuchsia
// system log when the script log level is set to DEBUG.
TEST_F(WebEngineIntegrationLoggingTest, SetJavaScriptLogLevel_DEBUG) {
StartWebEngine(base::CommandLine(base::CommandLine::NO_PROGRAM));
base::SimpleTestLogListener log_listener;
log_listener.ListenToLog(log(), nullptr);
// Create the Context & Frame with all log severities enabled.
CreateContext(TestContextParams());
fuchsia::web::CreateFrameParams frame_params;
frame_params.set_debug_name(kFrameLogTag);
CreateFrameWithParams(std::move(frame_params));
frame_->SetJavaScriptLogLevel(fuchsia::web::ConsoleLogLevel::DEBUG);
// Navigate to the test page, which will emit console logging.
ASSERT_NO_FATAL_FAILURE(LoadUrlAndExpectResponse(
embedded_test_server_.GetURL(std::string("/") + kLogTestPageFileName)
.spec()));
navigation_listener()->RunUntilTitleEquals("ended");
// Run until the message passed to console.debug() is received.
std::optional<fuchsia_logger::LogMessage> logged_message =
log_listener.RunUntilMessageReceived(kLogTestPageDebugMessage);
ASSERT_TRUE(logged_message.has_value());
// console.debug() should map to Fuchsia's DEBUG log severity.
EXPECT_EQ(logged_message->severity(),
static_cast<int32_t>(fuchsia_logger::LogLevelFilter::kDebug));
// Verify that the Frame's |debug_name| is amongst the log message tags.
EXPECT_FALSE(logged_message->tags().empty());
EXPECT_TRUE(base::Contains(logged_message->tags(), kFrameLogTag));
// Verify that the message is formatted as expected.
EXPECT_EQ(NormalizeConsoleLogMessage(logged_message->msg()),
base::StringPrintf("[http://127.0.0.1:%s/console_logging.html(8)] "
"This is a debug() message.",
kNormalizedPortNumber));
}