Commit 75996c7a authored by David Dorwin's avatar David Dorwin Committed by Chromium LUCI CQ

[fuchsia] Fix a bug in NormalizeConsoleLogMessage

Previously, the string positions were calculated then used to replace
parts of the string left to right, which produced the wrong string when
code was added earlier in the file causing the messages to be logged
from a four-digit line number in frame_impl.cc. (It would have also
failed had the function been moved to the beginning of the file and had
a two-digit line number.)

Bug: 1136681
Change-Id: Ia5e9a7f11a676d8fc538a19322274ae66e47d9a0
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2573198
Commit-Queue: Wez <wez@chromium.org>
Reviewed-by: default avatarWez <wez@chromium.org>
Reviewed-by: default avatarSergey Ulanov <sergeyu@chromium.org>
Cr-Commit-Position: refs/heads/master@{#834030}
parent 8c875677
...@@ -19,8 +19,26 @@ namespace { ...@@ -19,8 +19,26 @@ namespace {
constexpr char kLogTestPageFileName[] = "console_logging.html"; constexpr char kLogTestPageFileName[] = "console_logging.html";
constexpr char kWebEngineLogTag[] = "web_engine_exe"; constexpr char kWebEngineLogTag[] = "web_engine_exe";
constexpr char kNormalizedLineNumber[] = "123"; constexpr char kNormalizedLineNumber[] = "12345";
constexpr char kNormalizedPortNumber[] = "456"; 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) {
size_t line_number_begin = original.find("(") + 1;
size_t close_parenthesis = original.find(")", line_number_begin);
std::string normalized = original.as_string().replace(
line_number_begin, close_parenthesis - line_number_begin,
kNormalizedLineNumber);
const char kSchemePortColon[] = "http://127.0.0.1:";
size_t port_begin =
normalized.find(kSchemePortColon) + strlen(kSchemePortColon);
size_t path_begin = normalized.find("/", port_begin);
return normalized.replace(port_begin, path_begin - port_begin,
kNormalizedPortNumber);
}
} // namespace } // namespace
...@@ -132,24 +150,6 @@ class WebEngineIntegrationLoggingTest : public WebEngineIntegrationTestBase { ...@@ -132,24 +150,6 @@ class WebEngineIntegrationLoggingTest : public WebEngineIntegrationTestBase {
.spec())); .spec()));
} }
// 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) {
size_t line_number_begin = original.find("(") + 1;
size_t close_parenthesis = original.find(")", line_number_begin);
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 original.as_string()
.replace(line_number_begin, close_parenthesis - line_number_begin,
kNormalizedLineNumber)
.replace(port_begin, path_begin - port_begin, kNormalizedPortNumber);
}
fuchsia::sys::ComponentControllerPtr archivist_controller_; fuchsia::sys::ComponentControllerPtr archivist_controller_;
sys::ServiceDirectory isolated_archivist_service_dir_; sys::ServiceDirectory isolated_archivist_service_dir_;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment