Diff
Modified: trunk/Tools/ChangeLog (267639 => 267640)
--- trunk/Tools/ChangeLog 2020-09-26 22:13:56 UTC (rev 267639)
+++ trunk/Tools/ChangeLog 2020-09-26 23:23:24 UTC (rev 267640)
@@ -1,3 +1,58 @@
+2020-09-25 Darin Adler <[email protected]>
+
+ Change dumpAsText to strip trailing spaces
+ https://bugs.webkit.org/show_bug.cgi?id=216944
+
+ Reviewed by Alan Bujtas.
+
+ * DumpRenderTree/mac/DumpRenderTree.mm:
+ (dumpFramesAsText): Strip trailing spaces.
+ * DumpRenderTree/mac/FrameLoadDelegate.mm:
+ (-[FrameLoadDelegate webView:willPerformClientRedirectToURL:delay:fireDate:forFrame:]):
+ Don't add trailing space.
+ * DumpRenderTree/mac/UIDelegate.mm:
+ (-[UIDelegate webView:addMessageToConsole:withSource:]): Ditto.
+ (addLeadingSpaceStripTrailingSpaces): Added.
+ (stripTrailingSpaces): Added.
+ (-[UIDelegate webView:runJavaScriptAlertPanelWithMessage:initiatedByFrame:]): Don't add trailing space.
+ (-[UIDelegate webView:runJavaScriptConfirmPanelWithMessage:initiatedByFrame:]): Ditto.
+ (-[UIDelegate webView:runJavaScriptTextInputPanelWithPrompt:defaultText:initiatedByFrame:]): Ditto.
+ (-[UIDelegate webView:runBeforeUnloadConfirmPanelWithMessage:initiatedByFrame:]): Ditto.
+ (-[UIDelegate webView:setStatusText:]): Ditto.
+
+ * DumpRenderTree/win/DumpRenderTree.cpp:
+ (dumpFramesAsText): Strip trailing spaces.
+ * DumpRenderTree/win/FrameLoadDelegate.cpp:
+ (FrameLoadDelegate::willPerformClientRedirectToURL): Don't add trailing space.
+ * DumpRenderTree/win/UIDelegate.cpp:
+ (toMessage): Changed to return std::wstring.
+ (stripTrailingSpaces): Added.
+ (addLeadingSpaceStripTrailingSpaces): Added.
+ (UIDelegate::runJavaScriptAlertPanelWithMessage): Don't add trailing space.
+ (UIDelegate::runJavaScriptConfirmPanelWithMessage): Ditto.
+ (UIDelegate::runJavaScriptTextInputPanelWithPrompt): Ditto.
+ (UIDelegate::runBeforeUnloadConfirmPanelWithMessage): Ditto.
+ (UIDelegate::webViewAddMessageToConsole): Ditto.
+ (UIDelegate::setStatusText): Ditto.
+
+ * Scripts/webkitpy/port/base.py:
+ (Port.do_text_results_differ): Strip trailing spaces from expected text.
+ Plan is to remove this after stripping the actual expected.txt files.
+
+ * Scripts/webkitpy/port/win.py:
+ (WinPort.do_text_results_differ): Call through to base.
+
+ * WebKitTestRunner/InjectedBundle/InjectedBundlePage.cpp:
+ (WTR::dumpFrameText): Strip trailing spaces.
+ (WTR::InjectedBundlePage::willPerformClientRedirectForFrame): Don't add trailing space.
+ (WTR::InjectedBundlePage::decidePolicyForNavigationAction): Ditto.
+ (WTR::stripTrailingSpaces): Added.
+ (WTR::addLeadingSpaceStripTrailingSpaces): Added.
+ (WTR::InjectedBundlePage::willAddMessageToConsole): Don't add trailing space.
+ (WTR::InjectedBundlePage::willRunJavaScriptAlert): Ditto.
+ (WTR::InjectedBundlePage::willRunJavaScriptConfirm): Ditto.
+ (WTR::InjectedBundlePage::willRunJavaScriptPrompt): Ditto.
+
2020-09-25 Alex Christensen <[email protected]>
Unreviewed, reverting r267608.
Modified: trunk/Tools/DumpRenderTree/mac/DumpRenderTree.mm (267639 => 267640)
--- trunk/Tools/DumpRenderTree/mac/DumpRenderTree.mm 2020-09-26 22:13:56 UTC (rev 267639)
+++ trunk/Tools/DumpRenderTree/mac/DumpRenderTree.mm 2020-09-26 23:23:24 UTC (rev 267640)
@@ -1515,6 +1515,10 @@
}
}
+ // To keep things tidy, strip all trailing spaces: they are not a meaningful part of dumpAsText test output.
+ [result replaceOccurrencesOfString:@" +\n" withString:@"\n" options:NSRegularExpressionSearch range:NSMakeRange(0, result.length)];
+ [result replaceOccurrencesOfString:@" +$" withString:@"" options:NSRegularExpressionSearch range:NSMakeRange(0, result.length)];
+
return result;
}
Modified: trunk/Tools/DumpRenderTree/mac/EventSendingController.mm (267639 => 267640)
--- trunk/Tools/DumpRenderTree/mac/EventSendingController.mm 2020-09-26 22:13:56 UTC (rev 267639)
+++ trunk/Tools/DumpRenderTree/mac/EventSendingController.mm 2020-09-26 23:23:24 UTC (rev 267640)
@@ -1270,7 +1270,8 @@
}
if ([event isKindOfClass:[DOMKeyboardEvent class]]) {
- printf(" keyIdentifier: %s\n", [[(DOMKeyboardEvent*)event keyIdentifier] UTF8String]);
+ auto keyIdentifier = [(DOMKeyboardEvent*)event keyIdentifier];
+ printf(" keyIdentifier:%s%s\n", keyIdentifier.length ? " " : "", [keyIdentifier UTF8String]);
printf(" keyLocation: %d\n", [(DOMKeyboardEvent*)event location]);
printf(" modifier keys: c:%d s:%d a:%d m:%d\n",
[(DOMKeyboardEvent*)event ctrlKey] ? 1 : 0,
Modified: trunk/Tools/DumpRenderTree/mac/FrameLoadDelegate.mm (267639 => 267640)
--- trunk/Tools/DumpRenderTree/mac/FrameLoadDelegate.mm 2020-09-26 22:13:56 UTC (rev 267639)
+++ trunk/Tools/DumpRenderTree/mac/FrameLoadDelegate.mm 2020-09-26 23:23:24 UTC (rev 267640)
@@ -412,7 +412,7 @@
- (void)webView:(WebView *)sender willPerformClientRedirectToURL:(NSURL *)URL delay:(NSTimeInterval)seconds fireDate:(NSDate *)date forFrame:(WebFrame *)frame
{
if (!done && gTestRunner->dumpFrameLoadCallbacks()) {
- NSString *string = [NSString stringWithFormat:@"%@ - willPerformClientRedirectToURL: %@ ", [frame _drt_descriptionSuitableForTestResult], [URL _drt_descriptionSuitableForTestResult]];
+ NSString *string = [NSString stringWithFormat:@"%@ - willPerformClientRedirectToURL: %@", [frame _drt_descriptionSuitableForTestResult], [URL _drt_descriptionSuitableForTestResult]];
printf ("%s\n", [string UTF8String]);
}
Modified: trunk/Tools/DumpRenderTree/mac/UIDelegate.mm (267639 => 267640)
--- trunk/Tools/DumpRenderTree/mac/UIDelegate.mm 2020-09-26 22:13:56 UTC (rev 267639)
+++ trunk/Tools/DumpRenderTree/mac/UIDelegate.mm 2020-09-26 23:23:24 UTC (rev 267640)
@@ -76,6 +76,18 @@
return NSMakeRect(windowOrigin.x, windowOrigin.y, size.width, size.height);
}
+static NSString *stripTrailingSpaces(NSString *string)
+{
+ auto result = [string stringByReplacingOccurrencesOfString:@" +\n" withString:@"\n" options:NSRegularExpressionSearch range:NSMakeRange(0, string.length)];
+ return [result stringByReplacingOccurrencesOfString:@" +$" withString:@"" options:NSRegularExpressionSearch range:NSMakeRange(0, result.length)];
+}
+
+static NSString *addLeadingSpaceStripTrailingSpaces(NSString *string)
+{
+ auto result = stripTrailingSpaces(string);
+ return (result.length && ![result hasPrefix:@"\n"]) ? [@" " stringByAppendingString:result] : result;
+}
+
- (void)webView:(WebView *)sender addMessageToConsole:(NSDictionary *)dictionary withSource:(NSString *)source
{
if (done)
@@ -87,9 +99,7 @@
if (range.location != NSNotFound)
message = [[message substringToIndex:range.location] stringByAppendingString:[[message substringFromIndex:NSMaxRange(range)] lastPathComponent]];
- auto out = gTestRunner->dumpJSConsoleLogInStdErr() ? stderr : stdout;
- fprintf(out, "CONSOLE MESSAGE: ");
- fprintf(out, "%s\n", [message UTF8String]);
+ fprintf(gTestRunner->dumpJSConsoleLogInStdErr() ? stderr : stdout, "CONSOLE MESSAGE:%s\n", addLeadingSpaceStripTrailingSpaces(message).UTF8String ?: " (null)");
}
- (void)modalWindowWillClose:(NSNotification *)notification
@@ -113,7 +123,7 @@
- (void)webView:(WebView *)sender runJavaScriptAlertPanelWithMessage:(NSString *)message initiatedByFrame:(WebFrame *)frame
{
if (!done) {
- printf("ALERT: %s\n", [message UTF8String]);
+ printf("ALERT:%s\n", addLeadingSpaceStripTrailingSpaces(message).UTF8String ?: " (null)");
fflush(stdout);
}
}
@@ -121,7 +131,7 @@
- (BOOL)webView:(WebView *)sender runJavaScriptConfirmPanelWithMessage:(NSString *)message initiatedByFrame:(WebFrame *)frame
{
if (!done)
- printf("CONFIRM: %s\n", [message UTF8String]);
+ printf("CONFIRM:%s\n", addLeadingSpaceStripTrailingSpaces(message).UTF8String ?: " (null)");
return YES;
}
@@ -128,7 +138,7 @@
- (NSString *)webView:(WebView *)sender runJavaScriptTextInputPanelWithPrompt:(NSString *)prompt defaultText:(NSString *)defaultText initiatedByFrame:(WebFrame *)frame
{
if (!done)
- printf("PROMPT: %s, default text: %s\n", [prompt UTF8String], [defaultText UTF8String]);
+ printf("PROMPT: %s, default text:%s\n", prompt.UTF8String, addLeadingSpaceStripTrailingSpaces(defaultText).UTF8String ?: " (null)");
return defaultText;
}
@@ -135,8 +145,7 @@
- (BOOL)webView:(WebView *)c runBeforeUnloadConfirmPanelWithMessage:(NSString *)message initiatedByFrame:(WebFrame *)frame
{
if (!done)
- printf("CONFIRM NAVIGATION: %s\n", [message UTF8String]);
-
+ printf("CONFIRM NAVIGATION:%s\n", addLeadingSpaceStripTrailingSpaces(message).UTF8String ?: " (null)");
return !gTestRunner->shouldStayOnPageAfterHandlingBeforeUnload();
}
@@ -235,7 +244,7 @@
- (void)webView:(WebView *)sender setStatusText:(NSString *)text
{
if (!done && gTestRunner->dumpStatusCallbacks())
- printf("UI DELEGATE STATUS CALLBACK: setStatusText:%s\n", [text UTF8String]);
+ printf("UI DELEGATE STATUS CALLBACK: setStatusText:%s\n", stripTrailingSpaces(text).UTF8String);
}
- (void)webView:(WebView *)webView decidePolicyForGeolocationRequestFromOrigin:(WebSecurityOrigin *)origin frame:(WebFrame *)frame listener:(id<WebAllowDenyPolicyListener>)listener
Modified: trunk/Tools/DumpRenderTree/win/DumpRenderTree.cpp (267639 => 267640)
--- trunk/Tools/DumpRenderTree/win/DumpRenderTree.cpp 2020-09-26 22:13:56 UTC (rev 267639)
+++ trunk/Tools/DumpRenderTree/win/DumpRenderTree.cpp 2020-09-26 23:23:24 UTC (rev 267640)
@@ -488,6 +488,13 @@
}
}
+ // To keep things tidy, strip all trailing spaces: they are not a meaningful part of dumpAsText test output.
+ std::wstring::size_type spacePosition;
+ while ((spacePosition = result.find(L" \n")) != std::wstring::npos)
+ result.erase(spacePosition, 1);
+ while (!result.empty() && result.back() == ' ')
+ result.pop_back();
+
return result;
}
Modified: trunk/Tools/DumpRenderTree/win/FrameLoadDelegate.cpp (267639 => 267640)
--- trunk/Tools/DumpRenderTree/win/FrameLoadDelegate.cpp 2020-09-26 22:13:56 UTC (rev 267639)
+++ trunk/Tools/DumpRenderTree/win/FrameLoadDelegate.cpp 2020-09-26 23:23:24 UTC (rev 267640)
@@ -292,7 +292,7 @@
HRESULT FrameLoadDelegate::willPerformClientRedirectToURL(_In_opt_ IWebView*, _In_ BSTR url, double /*delaySeconds*/, DATE /*fireDate*/, _In_opt_ IWebFrame* frame)
{
if (!done && gTestRunner->dumpFrameLoadCallbacks())
- fprintf(testResult, "%s - willPerformClientRedirectToURL: %S \n", descriptionSuitableForTestResult(frame).c_str(),
+ fprintf(testResult, "%s - willPerformClientRedirectToURL: %S\n", descriptionSuitableForTestResult(frame).c_str(),
urlSuitableForTestResult(std::wstring(url, ::SysStringLen(url))).c_str());
return S_OK;
Modified: trunk/Tools/DumpRenderTree/win/UIDelegate.cpp (267639 => 267640)
--- trunk/Tools/DumpRenderTree/win/UIDelegate.cpp 2020-09-26 22:13:56 UTC (rev 267639)
+++ trunk/Tools/DumpRenderTree/win/UIDelegate.cpp 2020-09-26 23:23:24 UTC (rev 267640)
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2005-2008, 2014-2015 Apple Inc. All rights reserved.
+ * Copyright (C) 2005-2020 Apple Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
@@ -453,22 +453,54 @@
return S_OK;
}
-const wchar_t* toMessage(const BSTR message)
+static std::string stripTrailingSpaces(const std::string& string)
{
+ auto result = string;
+ std::wstring::size_type spacePosition;
+ while ((spacePosition = result.find(" \n")) != std::wstring::npos)
+ result.erase(spacePosition, 1);
+ while (!result.empty() && result.back() == ' ')
+ result.pop_back();
+ return result;
+}
+
+static std::string addLeadingSpaceStripTrailingSpaces(const std::string& string)
+{
+ auto result = stripTrailingSpaces(string);
+ return (result.empty() || result.front() == '\n') ? result : ' ' + result;
+}
+
+static std::string addLeadingSpaceStripTrailingSpaces(const std::wstring& string)
+{
+ return addLeadingSpaceStripTrailingSpaces(toUTF8(string));
+}
+
+std::string toMessage(BSTR message)
+{
auto length = SysStringLen(message);
if (!length)
- return message;
+ return "";
// Return "(null)" for an invalid UTF-16 sequence to align with WebKitTestRunner.
- auto utf8 = StringView(ucharFrom(message), length).tryGetUtf8(StrictConversion);
- if (!utf8)
- return L"(null)";
- return message;
+ // FIXME: Could probably take advantage of WC_ERR_INVALID_CHARS and avoid converting to UTF-8 twice.
+ if (!StringView(ucharFrom(message), length).tryGetUtf8(StrictConversion))
+ return "(null)";
+ return toUTF8(message);
}
+static std::string addLeadingSpaceStripTrailingSpaces(BSTR message)
+{
+ return addLeadingSpaceStripTrailingSpaces(toMessage(message));
+}
+
+static std::string stripTrailingSpaces(BSTR message)
+{
+ return stripTrailingSpaces(toMessage(message));
+}
+
HRESULT UIDelegate::runJavaScriptAlertPanelWithMessage(_In_opt_ IWebView* /*sender*/, _In_ BSTR message)
{
if (!done) {
- fprintf(testResult, "ALERT: %S\n", toMessage(message));
+ fprintf(testResult, "ALERT:%s\n", addLeadingSpaceStripTrailingSpaces(message).c_str());
fflush(testResult);
}
@@ -478,7 +510,7 @@
HRESULT UIDelegate::runJavaScriptConfirmPanelWithMessage(_In_opt_ IWebView* /*sender*/, _In_ BSTR message, _Out_ BOOL* result)
{
if (!done)
- fprintf(testResult, "CONFIRM: %S\n", toMessage(message));
+ fprintf(testResult, "CONFIRM:%s\n", addLeadingSpaceStripTrailingSpaces(message).c_str());
*result = TRUE;
@@ -488,7 +520,7 @@
HRESULT UIDelegate::runJavaScriptTextInputPanelWithPrompt(_In_opt_ IWebView* /*sender*/, _In_ BSTR message, _In_ BSTR defaultText, __deref_opt_out BSTR* result)
{
if (!done)
- fprintf(testResult, "PROMPT: %S, default text: %S\n", toMessage(message), toMessage(defaultText));
+ fprintf(testResult, "PROMPT: %s, default text:%s\n", toMessage(message).c_str(), addLeadingSpaceStripTrailingSpaces(defaultText).c_str());
*result = SysAllocString(defaultText);
@@ -501,7 +533,7 @@
return E_POINTER;
if (!done)
- fprintf(testResult, "CONFIRM NAVIGATION: %S\n", toMessage(message));
+ fprintf(testResult, "CONFIRM NAVIGATION:%s\n", addLeadingSpaceStripTrailingSpaces(message).c_str());
*result = !gTestRunner->shouldStayOnPageAfterHandlingBeforeUnload();
@@ -523,8 +555,7 @@
}
auto out = gTestRunner->dumpJSConsoleLogInStdErr() ? stderr : testResult;
- fprintf(out, "CONSOLE MESSAGE: ");
- fprintf(out, "%s\n", toUTF8(newMessage).c_str());
+ fprintf(out, "CONSOLE MESSAGE:%s\n", addLeadingSpaceStripTrailingSpaces(newMessage).c_str());
return S_OK;
}
@@ -673,7 +704,7 @@
HRESULT UIDelegate::setStatusText(_In_opt_ IWebView*, _In_ BSTR text)
{
if (!done && gTestRunner->dumpStatusCallbacks())
- fprintf(testResult, "UI DELEGATE STATUS CALLBACK: setStatusText:%S\n", toMessage(text));
+ fprintf(testResult, "UI DELEGATE STATUS CALLBACK: setStatusText:%s\n", stripTrailingSpaces(text).c_str());
return S_OK;
}
Modified: trunk/Tools/Scripts/webkitpy/port/base.py (267639 => 267640)
--- trunk/Tools/Scripts/webkitpy/port/base.py 2020-09-26 22:13:56 UTC (rev 267639)
+++ trunk/Tools/Scripts/webkitpy/port/base.py 2020-09-26 23:23:24 UTC (rev 267640)
@@ -300,6 +300,9 @@
return False
def do_text_results_differ(self, expected_text, actual_text):
+ # Ignore trailing spaces in expected files. We will remove this code after removing trailing spaces from all expected.txt files.
+ if not expected_text.startswith("<?xml"):
+ expected_text = re.compile(" +$", re.MULTILINE).sub("", expected_text)
return expected_text != actual_text
def do_audio_results_differ(self, expected_audio, actual_audio):
Modified: trunk/Tools/Scripts/webkitpy/port/win.py (267639 => 267640)
--- trunk/Tools/Scripts/webkitpy/port/win.py 2020-09-26 22:13:56 UTC (rev 267639)
+++ trunk/Tools/Scripts/webkitpy/port/win.py 2020-09-26 23:23:24 UTC (rev 267640)
@@ -103,19 +103,15 @@
self._os_version = self.host.platform.os_version
def do_text_results_differ(self, expected_text, actual_text):
- # Sanity was restored in WK2, so we don't need this hack there.
- if self.get_option('webkit_test_runner'):
- return ApplePort.do_text_results_differ(self, expected_text, actual_text)
+ # Sanity was restored in WebKitTestRunner, so we don't need this hack there.
+ if not self.get_option('webkit_test_runner'):
+ # Windows does not have an EDITING DELEGATE, so strip those messages to make more tests pass.
+ # It's possible other ports might want this, and if so, this could move down into WebKitPort.
+ delegate_regexp = re.compile("^EDITING DELEGATE: .*?\n", re.MULTILINE)
+ expected_text = delegate_regexp.sub("", expected_text)
+ actual_text = delegate_regexp.sub("", actual_text)
+ return ApplePort.do_text_results_differ(self, expected_text, actual_text)
- # This is a hack (which dates back to ORWT).
- # Windows does not have an EDITING DELEGATE, so we strip any EDITING DELEGATE
- # messages to make more of the tests pass.
- # It's possible more of the ports might want this and this could move down into WebKitPort.
- delegate_regexp = re.compile("^EDITING DELEGATE: .*?\n", re.MULTILINE)
- expected_text = delegate_regexp.sub("", expected_text)
- actual_text = delegate_regexp.sub("", actual_text)
- return expected_text != actual_text
-
def default_baseline_search_path(self, **kwargs):
version_name_map = VersionNameMap.map(self.host.platform)
if self._os_version < self.VERSION_MIN or self._os_version > self.VERSION_MAX:
Modified: trunk/Tools/WebKitTestRunner/InjectedBundle/InjectedBundlePage.cpp (267639 => 267640)
--- trunk/Tools/WebKitTestRunner/InjectedBundle/InjectedBundlePage.cpp 2020-09-26 22:13:56 UTC (rev 267639)
+++ trunk/Tools/WebKitTestRunner/InjectedBundle/InjectedBundlePage.cpp 2020-09-26 23:23:24 UTC (rev 267640)
@@ -834,17 +834,22 @@
return JSValueToBoolean(context, documentElementValue);
}
-static void dumpFrameText(WKBundleFrameRef frame, StringBuilder& stringBuilder)
+static void dumpFrameText(WKBundleFrameRef frame, StringBuilder& builder)
{
// If the frame doesn't have a document element, its inner text will be an empty string, so
- // we'll end up just appending a single newline below. But DumpRenderTree doesn't append
- // anything in this case, so we shouldn't either.
+ // we'll end up just appending a single newline below. Since DumpRenderTree didn't append
+ // anything in this case, we decided to preserve that behavior.
if (!hasDocumentElement(frame))
return;
- WKRetainPtr<WKStringRef> text = adoptWK(WKBundleFrameCopyInnerText(frame));
- stringBuilder.append(toWTFString(text));
- stringBuilder.append('\n');
+ // To keep things tidy, strip all trailing spaces: they are not a meaningful part of dumpAsText test output.
+ // Breaking the string up into lines lets us efficiently strip and has a side effect of adding a newline after the last line.
+ auto text = toWTFString(adoptWK(WKBundleFrameCopyInnerText(frame)));
+ for (auto line : StringView(text).splitAllowingEmptyEntries('\n')) {
+ while (line.endsWith(' '))
+ line = line.substring(0, line.length() - 1);
+ builder.append(line, '\n');
+ }
}
static void dumpDescendantFramesText(WKBundleFrameRef frame, StringBuilder& stringBuilder)
@@ -1056,9 +1061,7 @@
StringBuilder stringBuilder;
dumpFrameDescriptionSuitableForTestResult(frame, stringBuilder);
- stringBuilder.appendLiteral(" - willPerformClientRedirectToURL: ");
- stringBuilder.append(pathSuitableForTestResult(url));
- stringBuilder.appendLiteral(" \n");
+ stringBuilder.append(" - willPerformClientRedirectToURL: ", pathSuitableForTestResult(url), '\n');
injectedBundle.outputText(stringBuilder.toString());
}
@@ -1345,7 +1348,7 @@
if (injectedBundle.testRunner()->shouldDumpPolicyCallbacks()) {
StringBuilder stringBuilder;
- stringBuilder.appendLiteral(" - decidePolicyForNavigationAction \n");
+ stringBuilder.appendLiteral(" - decidePolicyForNavigationAction\n");
dumpRequestDescriptionSuitableForTestResult(request, stringBuilder);
stringBuilder.appendLiteral(" is main frame - ");
stringBuilder.append(WKBundleFrameIsMainFrame(frame) ? "yes" : "no");
@@ -1449,6 +1452,23 @@
return static_cast<InjectedBundlePage*>(const_cast<void*>(clientInfo))->didExceedDatabaseQuota(origin, databaseName, databaseDisplayName, currentQuotaBytes, currentOriginUsageBytes, currentDatabaseUsageBytes, expectedUsageBytes);
}
+static WTF::String stripTrailingSpacesAddNewline(const WTF::String& string)
+{
+ StringBuilder builder;
+ for (auto line : StringView(string).splitAllowingEmptyEntries('\n')) {
+ while (line.endsWith(' '))
+ line = line.substring(0, line.length() - 1);
+ builder.append(line, '\n');
+ }
+ return builder.toString();
+}
+
+static WTF::String addLeadingSpaceStripTrailingSpacesAddNewline(const WTF::String& string)
+{
+ auto result = stripTrailingSpacesAddNewline(string);
+ return (result.isEmpty() || result.startsWith('\n')) ? result : makeString(' ', result);
+}
+
static WTF::String lastFileURLPathComponent(const WTF::String& path)
{
size_t pos = path.find("file://");
@@ -1485,15 +1505,11 @@
// FIXME: The code below does not handle additional text after url nor multiple urls. This matches DumpRenderTree implementation.
messageString = messageString.substring(0, fileProtocolStart) + lastFileURLPathComponent(messageString.substring(fileProtocolStart));
- StringBuilder stringBuilder;
- stringBuilder.appendLiteral("CONSOLE MESSAGE: ");
- stringBuilder.append(messageString);
- stringBuilder.append('\n');
-
+ messageString = makeString("CONSOLE MESSAGE:", addLeadingSpaceStripTrailingSpacesAddNewline(messageString));
if (injectedBundle.dumpJSConsoleLogInStdErr())
- injectedBundle.dumpToStdErr(stringBuilder.toString());
+ injectedBundle.dumpToStdErr(messageString);
else
- injectedBundle.outputText(stringBuilder.toString());
+ injectedBundle.outputText(messageString);
}
void InjectedBundlePage::willSetStatusbarText(WKStringRef statusbarText)
@@ -1518,11 +1534,7 @@
if (!injectedBundle.isTestRunning())
return;
- StringBuilder stringBuilder;
- stringBuilder.appendLiteral("ALERT: ");
- stringBuilder.append(toWTFString(message));
- stringBuilder.append('\n');
- injectedBundle.outputText(stringBuilder.toString());
+ injectedBundle.outputText(makeString("ALERT:", addLeadingSpaceStripTrailingSpacesAddNewline(toWTFString(message))));
}
void InjectedBundlePage::willRunJavaScriptConfirm(WKStringRef message, WKBundleFrameRef)
@@ -1531,22 +1543,12 @@
if (!injectedBundle.isTestRunning())
return;
- StringBuilder stringBuilder;
- stringBuilder.appendLiteral("CONFIRM: ");
- stringBuilder.append(toWTFString(message));
- stringBuilder.append('\n');
- injectedBundle.outputText(stringBuilder.toString());
+ injectedBundle.outputText(makeString("CONFIRM:", addLeadingSpaceStripTrailingSpacesAddNewline(toWTFString(message))));
}
void InjectedBundlePage::willRunJavaScriptPrompt(WKStringRef message, WKStringRef defaultValue, WKBundleFrameRef)
{
- StringBuilder stringBuilder;
- stringBuilder.appendLiteral("PROMPT: ");
- stringBuilder.append(toWTFString(message));
- stringBuilder.appendLiteral(", default text: ");
- stringBuilder.append(toWTFString(defaultValue));
- stringBuilder.append('\n');
- InjectedBundle::singleton().outputText(stringBuilder.toString());
+ InjectedBundle::singleton().outputText(makeString("PROMPT: ", toWTFString(message), ", default text:", addLeadingSpaceStripTrailingSpacesAddNewline(toWTFString(defaultValue))));
}
void InjectedBundlePage::didReachApplicationCacheOriginQuota(WKSecurityOriginRef origin, int64_t totalBytesNeeded)