Changeset 267640 in webkit
- Timestamp:
- Sep 26, 2020 4:23:24 PM (4 years ago)
- Location:
- trunk/Tools
- Files:
-
- 11 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Tools/ChangeLog
r267618 r267640 1 2020-09-25 Darin Adler <darin@apple.com> 2 3 Change dumpAsText to strip trailing spaces 4 https://bugs.webkit.org/show_bug.cgi?id=216944 5 6 Reviewed by Alan Bujtas. 7 8 * DumpRenderTree/mac/DumpRenderTree.mm: 9 (dumpFramesAsText): Strip trailing spaces. 10 * DumpRenderTree/mac/FrameLoadDelegate.mm: 11 (-[FrameLoadDelegate webView:willPerformClientRedirectToURL:delay:fireDate:forFrame:]): 12 Don't add trailing space. 13 * DumpRenderTree/mac/UIDelegate.mm: 14 (-[UIDelegate webView:addMessageToConsole:withSource:]): Ditto. 15 (addLeadingSpaceStripTrailingSpaces): Added. 16 (stripTrailingSpaces): Added. 17 (-[UIDelegate webView:runJavaScriptAlertPanelWithMessage:initiatedByFrame:]): Don't add trailing space. 18 (-[UIDelegate webView:runJavaScriptConfirmPanelWithMessage:initiatedByFrame:]): Ditto. 19 (-[UIDelegate webView:runJavaScriptTextInputPanelWithPrompt:defaultText:initiatedByFrame:]): Ditto. 20 (-[UIDelegate webView:runBeforeUnloadConfirmPanelWithMessage:initiatedByFrame:]): Ditto. 21 (-[UIDelegate webView:setStatusText:]): Ditto. 22 23 * DumpRenderTree/win/DumpRenderTree.cpp: 24 (dumpFramesAsText): Strip trailing spaces. 25 * DumpRenderTree/win/FrameLoadDelegate.cpp: 26 (FrameLoadDelegate::willPerformClientRedirectToURL): Don't add trailing space. 27 * DumpRenderTree/win/UIDelegate.cpp: 28 (toMessage): Changed to return std::wstring. 29 (stripTrailingSpaces): Added. 30 (addLeadingSpaceStripTrailingSpaces): Added. 31 (UIDelegate::runJavaScriptAlertPanelWithMessage): Don't add trailing space. 32 (UIDelegate::runJavaScriptConfirmPanelWithMessage): Ditto. 33 (UIDelegate::runJavaScriptTextInputPanelWithPrompt): Ditto. 34 (UIDelegate::runBeforeUnloadConfirmPanelWithMessage): Ditto. 35 (UIDelegate::webViewAddMessageToConsole): Ditto. 36 (UIDelegate::setStatusText): Ditto. 37 38 * Scripts/webkitpy/port/base.py: 39 (Port.do_text_results_differ): Strip trailing spaces from expected text. 40 Plan is to remove this after stripping the actual expected.txt files. 41 42 * Scripts/webkitpy/port/win.py: 43 (WinPort.do_text_results_differ): Call through to base. 44 45 * WebKitTestRunner/InjectedBundle/InjectedBundlePage.cpp: 46 (WTR::dumpFrameText): Strip trailing spaces. 47 (WTR::InjectedBundlePage::willPerformClientRedirectForFrame): Don't add trailing space. 48 (WTR::InjectedBundlePage::decidePolicyForNavigationAction): Ditto. 49 (WTR::stripTrailingSpaces): Added. 50 (WTR::addLeadingSpaceStripTrailingSpaces): Added. 51 (WTR::InjectedBundlePage::willAddMessageToConsole): Don't add trailing space. 52 (WTR::InjectedBundlePage::willRunJavaScriptAlert): Ditto. 53 (WTR::InjectedBundlePage::willRunJavaScriptConfirm): Ditto. 54 (WTR::InjectedBundlePage::willRunJavaScriptPrompt): Ditto. 55 1 56 2020-09-25 Alex Christensen <achristensen@webkit.org> 2 57 -
trunk/Tools/DumpRenderTree/mac/DumpRenderTree.mm
r267592 r267640 1516 1516 } 1517 1517 1518 // To keep things tidy, strip all trailing spaces: they are not a meaningful part of dumpAsText test output. 1519 [result replaceOccurrencesOfString:@" +\n" withString:@"\n" options:NSRegularExpressionSearch range:NSMakeRange(0, result.length)]; 1520 [result replaceOccurrencesOfString:@" +$" withString:@"" options:NSRegularExpressionSearch range:NSMakeRange(0, result.length)]; 1521 1518 1522 return result; 1519 1523 } -
trunk/Tools/DumpRenderTree/mac/EventSendingController.mm
r263396 r267640 1271 1271 1272 1272 if ([event isKindOfClass:[DOMKeyboardEvent class]]) { 1273 printf(" keyIdentifier: %s\n", [[(DOMKeyboardEvent*)event keyIdentifier] UTF8String]); 1273 auto keyIdentifier = [(DOMKeyboardEvent*)event keyIdentifier]; 1274 printf(" keyIdentifier:%s%s\n", keyIdentifier.length ? " " : "", [keyIdentifier UTF8String]); 1274 1275 printf(" keyLocation: %d\n", [(DOMKeyboardEvent*)event location]); 1275 1276 printf(" modifier keys: c:%d s:%d a:%d m:%d\n", -
trunk/Tools/DumpRenderTree/mac/FrameLoadDelegate.mm
r266988 r267640 413 413 { 414 414 if (!done && gTestRunner->dumpFrameLoadCallbacks()) { 415 NSString *string = [NSString stringWithFormat:@"%@ - willPerformClientRedirectToURL: %@ 415 NSString *string = [NSString stringWithFormat:@"%@ - willPerformClientRedirectToURL: %@", [frame _drt_descriptionSuitableForTestResult], [URL _drt_descriptionSuitableForTestResult]]; 416 416 printf ("%s\n", [string UTF8String]); 417 417 } -
trunk/Tools/DumpRenderTree/mac/UIDelegate.mm
r260485 r267640 77 77 } 78 78 79 static NSString *stripTrailingSpaces(NSString *string) 80 { 81 auto result = [string stringByReplacingOccurrencesOfString:@" +\n" withString:@"\n" options:NSRegularExpressionSearch range:NSMakeRange(0, string.length)]; 82 return [result stringByReplacingOccurrencesOfString:@" +$" withString:@"" options:NSRegularExpressionSearch range:NSMakeRange(0, result.length)]; 83 } 84 85 static NSString *addLeadingSpaceStripTrailingSpaces(NSString *string) 86 { 87 auto result = stripTrailingSpaces(string); 88 return (result.length && ![result hasPrefix:@"\n"]) ? [@" " stringByAppendingString:result] : result; 89 } 90 79 91 - (void)webView:(WebView *)sender addMessageToConsole:(NSDictionary *)dictionary withSource:(NSString *)source 80 92 { … … 88 100 message = [[message substringToIndex:range.location] stringByAppendingString:[[message substringFromIndex:NSMaxRange(range)] lastPathComponent]]; 89 101 90 auto out = gTestRunner->dumpJSConsoleLogInStdErr() ? stderr : stdout; 91 fprintf(out, "CONSOLE MESSAGE: "); 92 fprintf(out, "%s\n", [message UTF8String]); 102 fprintf(gTestRunner->dumpJSConsoleLogInStdErr() ? stderr : stdout, "CONSOLE MESSAGE:%s\n", addLeadingSpaceStripTrailingSpaces(message).UTF8String ?: " (null)"); 93 103 } 94 104 … … 114 124 { 115 125 if (!done) { 116 printf("ALERT: %s\n", [message UTF8String]);126 printf("ALERT:%s\n", addLeadingSpaceStripTrailingSpaces(message).UTF8String ?: " (null)"); 117 127 fflush(stdout); 118 128 } … … 122 132 { 123 133 if (!done) 124 printf("CONFIRM: %s\n", [message UTF8String]);134 printf("CONFIRM:%s\n", addLeadingSpaceStripTrailingSpaces(message).UTF8String ?: " (null)"); 125 135 return YES; 126 136 } … … 129 139 { 130 140 if (!done) 131 printf("PROMPT: %s, default text: %s\n", [prompt UTF8String], [defaultText UTF8String]);141 printf("PROMPT: %s, default text:%s\n", prompt.UTF8String, addLeadingSpaceStripTrailingSpaces(defaultText).UTF8String ?: " (null)"); 132 142 return defaultText; 133 143 } … … 136 146 { 137 147 if (!done) 138 printf("CONFIRM NAVIGATION: %s\n", [message UTF8String]); 139 148 printf("CONFIRM NAVIGATION:%s\n", addLeadingSpaceStripTrailingSpaces(message).UTF8String ?: " (null)"); 140 149 return !gTestRunner->shouldStayOnPageAfterHandlingBeforeUnload(); 141 150 } … … 236 245 { 237 246 if (!done && gTestRunner->dumpStatusCallbacks()) 238 printf("UI DELEGATE STATUS CALLBACK: setStatusText:%s\n", [text UTF8String]);247 printf("UI DELEGATE STATUS CALLBACK: setStatusText:%s\n", stripTrailingSpaces(text).UTF8String); 239 248 } 240 249 -
trunk/Tools/DumpRenderTree/win/DumpRenderTree.cpp
r267592 r267640 489 489 } 490 490 491 // To keep things tidy, strip all trailing spaces: they are not a meaningful part of dumpAsText test output. 492 std::wstring::size_type spacePosition; 493 while ((spacePosition = result.find(L" \n")) != std::wstring::npos) 494 result.erase(spacePosition, 1); 495 while (!result.empty() && result.back() == ' ') 496 result.pop_back(); 497 491 498 return result; 492 499 } -
trunk/Tools/DumpRenderTree/win/FrameLoadDelegate.cpp
r266988 r267640 293 293 { 294 294 if (!done && gTestRunner->dumpFrameLoadCallbacks()) 295 fprintf(testResult, "%s - willPerformClientRedirectToURL: %S 295 fprintf(testResult, "%s - willPerformClientRedirectToURL: %S\n", descriptionSuitableForTestResult(frame).c_str(), 296 296 urlSuitableForTestResult(std::wstring(url, ::SysStringLen(url))).c_str()); 297 297 -
trunk/Tools/DumpRenderTree/win/UIDelegate.cpp
r263379 r267640 1 1 /* 2 * Copyright (C) 2005-20 08, 2014-2015Apple Inc. All rights reserved.2 * Copyright (C) 2005-2020 Apple Inc. All rights reserved. 3 3 * 4 4 * Redistribution and use in source and binary forms, with or without … … 454 454 } 455 455 456 const wchar_t* toMessage(const BSTR message) 456 static std::string stripTrailingSpaces(const std::string& string) 457 { 458 auto result = string; 459 std::wstring::size_type spacePosition; 460 while ((spacePosition = result.find(" \n")) != std::wstring::npos) 461 result.erase(spacePosition, 1); 462 while (!result.empty() && result.back() == ' ') 463 result.pop_back(); 464 return result; 465 } 466 467 static std::string addLeadingSpaceStripTrailingSpaces(const std::string& string) 468 { 469 auto result = stripTrailingSpaces(string); 470 return (result.empty() || result.front() == '\n') ? result : ' ' + result; 471 } 472 473 static std::string addLeadingSpaceStripTrailingSpaces(const std::wstring& string) 474 { 475 return addLeadingSpaceStripTrailingSpaces(toUTF8(string)); 476 } 477 478 std::string toMessage(BSTR message) 457 479 { 458 480 auto length = SysStringLen(message); 459 481 if (!length) 460 return message;482 return ""; 461 483 // Return "(null)" for an invalid UTF-16 sequence to align with WebKitTestRunner. 462 auto utf8 = StringView(ucharFrom(message), length).tryGetUtf8(StrictConversion); 463 if (!utf8) 464 return L"(null)"; 465 return message; 484 // FIXME: Could probably take advantage of WC_ERR_INVALID_CHARS and avoid converting to UTF-8 twice. 485 if (!StringView(ucharFrom(message), length).tryGetUtf8(StrictConversion)) 486 return "(null)"; 487 return toUTF8(message); 488 } 489 490 static std::string addLeadingSpaceStripTrailingSpaces(BSTR message) 491 { 492 return addLeadingSpaceStripTrailingSpaces(toMessage(message)); 493 } 494 495 static std::string stripTrailingSpaces(BSTR message) 496 { 497 return stripTrailingSpaces(toMessage(message)); 466 498 } 467 499 … … 469 501 { 470 502 if (!done) { 471 fprintf(testResult, "ALERT: %S\n", toMessage(message));503 fprintf(testResult, "ALERT:%s\n", addLeadingSpaceStripTrailingSpaces(message).c_str()); 472 504 fflush(testResult); 473 505 } … … 479 511 { 480 512 if (!done) 481 fprintf(testResult, "CONFIRM: %S\n", toMessage(message));513 fprintf(testResult, "CONFIRM:%s\n", addLeadingSpaceStripTrailingSpaces(message).c_str()); 482 514 483 515 *result = TRUE; … … 489 521 { 490 522 if (!done) 491 fprintf(testResult, "PROMPT: % S, default text: %S\n", toMessage(message), toMessage(defaultText));523 fprintf(testResult, "PROMPT: %s, default text:%s\n", toMessage(message).c_str(), addLeadingSpaceStripTrailingSpaces(defaultText).c_str()); 492 524 493 525 *result = SysAllocString(defaultText); … … 502 534 503 535 if (!done) 504 fprintf(testResult, "CONFIRM NAVIGATION: %S\n", toMessage(message));536 fprintf(testResult, "CONFIRM NAVIGATION:%s\n", addLeadingSpaceStripTrailingSpaces(message).c_str()); 505 537 506 538 *result = !gTestRunner->shouldStayOnPageAfterHandlingBeforeUnload(); … … 524 556 525 557 auto out = gTestRunner->dumpJSConsoleLogInStdErr() ? stderr : testResult; 526 fprintf(out, "CONSOLE MESSAGE: "); 527 fprintf(out, "%s\n", toUTF8(newMessage).c_str()); 558 fprintf(out, "CONSOLE MESSAGE:%s\n", addLeadingSpaceStripTrailingSpaces(newMessage).c_str()); 528 559 return S_OK; 529 560 } … … 674 705 { 675 706 if (!done && gTestRunner->dumpStatusCallbacks()) 676 fprintf(testResult, "UI DELEGATE STATUS CALLBACK: setStatusText:% S\n", toMessage(text));707 fprintf(testResult, "UI DELEGATE STATUS CALLBACK: setStatusText:%s\n", stripTrailingSpaces(text).c_str()); 677 708 return S_OK; 678 709 } -
trunk/Tools/Scripts/webkitpy/port/base.py
r266638 r267640 301 301 302 302 def do_text_results_differ(self, expected_text, actual_text): 303 # Ignore trailing spaces in expected files. We will remove this code after removing trailing spaces from all expected.txt files. 304 if not expected_text.startswith("<?xml"): 305 expected_text = re.compile(" +$", re.MULTILINE).sub("", expected_text) 303 306 return expected_text != actual_text 304 307 -
trunk/Tools/Scripts/webkitpy/port/win.py
r265191 r267640 104 104 105 105 def do_text_results_differ(self, expected_text, actual_text): 106 # Sanity was restored in WK2, so we don't need this hack there. 107 if self.get_option('webkit_test_runner'): 108 return ApplePort.do_text_results_differ(self, expected_text, actual_text) 109 110 # This is a hack (which dates back to ORWT). 111 # Windows does not have an EDITING DELEGATE, so we strip any EDITING DELEGATE 112 # messages to make more of the tests pass. 113 # It's possible more of the ports might want this and this could move down into WebKitPort. 114 delegate_regexp = re.compile("^EDITING DELEGATE: .*?\n", re.MULTILINE) 115 expected_text = delegate_regexp.sub("", expected_text) 116 actual_text = delegate_regexp.sub("", actual_text) 117 return expected_text != actual_text 106 # Sanity was restored in WebKitTestRunner, so we don't need this hack there. 107 if not self.get_option('webkit_test_runner'): 108 # Windows does not have an EDITING DELEGATE, so strip those messages to make more tests pass. 109 # It's possible other ports might want this, and if so, this could move down into WebKitPort. 110 delegate_regexp = re.compile("^EDITING DELEGATE: .*?\n", re.MULTILINE) 111 expected_text = delegate_regexp.sub("", expected_text) 112 actual_text = delegate_regexp.sub("", actual_text) 113 return ApplePort.do_text_results_differ(self, expected_text, actual_text) 118 114 119 115 def default_baseline_search_path(self, **kwargs): -
trunk/Tools/WebKitTestRunner/InjectedBundle/InjectedBundlePage.cpp
r266988 r267640 835 835 } 836 836 837 static void dumpFrameText(WKBundleFrameRef frame, StringBuilder& stringBuilder)837 static void dumpFrameText(WKBundleFrameRef frame, StringBuilder& builder) 838 838 { 839 839 // If the frame doesn't have a document element, its inner text will be an empty string, so 840 // we'll end up just appending a single newline below. But DumpRenderTree doesn't append841 // anything in this case, so we shouldn't either.840 // we'll end up just appending a single newline below. Since DumpRenderTree didn't append 841 // anything in this case, we decided to preserve that behavior. 842 842 if (!hasDocumentElement(frame)) 843 843 return; 844 844 845 WKRetainPtr<WKStringRef> text = adoptWK(WKBundleFrameCopyInnerText(frame)); 846 stringBuilder.append(toWTFString(text)); 847 stringBuilder.append('\n'); 845 // To keep things tidy, strip all trailing spaces: they are not a meaningful part of dumpAsText test output. 846 // Breaking the string up into lines lets us efficiently strip and has a side effect of adding a newline after the last line. 847 auto text = toWTFString(adoptWK(WKBundleFrameCopyInnerText(frame))); 848 for (auto line : StringView(text).splitAllowingEmptyEntries('\n')) { 849 while (line.endsWith(' ')) 850 line = line.substring(0, line.length() - 1); 851 builder.append(line, '\n'); 852 } 848 853 } 849 854 … … 1057 1062 StringBuilder stringBuilder; 1058 1063 dumpFrameDescriptionSuitableForTestResult(frame, stringBuilder); 1059 stringBuilder.appendLiteral(" - willPerformClientRedirectToURL: "); 1060 stringBuilder.append(pathSuitableForTestResult(url)); 1061 stringBuilder.appendLiteral(" \n"); 1064 stringBuilder.append(" - willPerformClientRedirectToURL: ", pathSuitableForTestResult(url), '\n'); 1062 1065 injectedBundle.outputText(stringBuilder.toString()); 1063 1066 } … … 1346 1349 if (injectedBundle.testRunner()->shouldDumpPolicyCallbacks()) { 1347 1350 StringBuilder stringBuilder; 1348 stringBuilder.appendLiteral(" - decidePolicyForNavigationAction 1351 stringBuilder.appendLiteral(" - decidePolicyForNavigationAction\n"); 1349 1352 dumpRequestDescriptionSuitableForTestResult(request, stringBuilder); 1350 1353 stringBuilder.appendLiteral(" is main frame - "); … … 1450 1453 } 1451 1454 1455 static WTF::String stripTrailingSpacesAddNewline(const WTF::String& string) 1456 { 1457 StringBuilder builder; 1458 for (auto line : StringView(string).splitAllowingEmptyEntries('\n')) { 1459 while (line.endsWith(' ')) 1460 line = line.substring(0, line.length() - 1); 1461 builder.append(line, '\n'); 1462 } 1463 return builder.toString(); 1464 } 1465 1466 static WTF::String addLeadingSpaceStripTrailingSpacesAddNewline(const WTF::String& string) 1467 { 1468 auto result = stripTrailingSpacesAddNewline(string); 1469 return (result.isEmpty() || result.startsWith('\n')) ? result : makeString(' ', result); 1470 } 1471 1452 1472 static WTF::String lastFileURLPathComponent(const WTF::String& path) 1453 1473 { … … 1486 1506 messageString = messageString.substring(0, fileProtocolStart) + lastFileURLPathComponent(messageString.substring(fileProtocolStart)); 1487 1507 1488 StringBuilder stringBuilder; 1489 stringBuilder.appendLiteral("CONSOLE MESSAGE: "); 1490 stringBuilder.append(messageString); 1491 stringBuilder.append('\n'); 1492 1508 messageString = makeString("CONSOLE MESSAGE:", addLeadingSpaceStripTrailingSpacesAddNewline(messageString)); 1493 1509 if (injectedBundle.dumpJSConsoleLogInStdErr()) 1494 injectedBundle.dumpToStdErr( stringBuilder.toString());1510 injectedBundle.dumpToStdErr(messageString); 1495 1511 else 1496 injectedBundle.outputText( stringBuilder.toString());1512 injectedBundle.outputText(messageString); 1497 1513 } 1498 1514 … … 1519 1535 return; 1520 1536 1521 StringBuilder stringBuilder; 1522 stringBuilder.appendLiteral("ALERT: "); 1523 stringBuilder.append(toWTFString(message)); 1524 stringBuilder.append('\n'); 1525 injectedBundle.outputText(stringBuilder.toString()); 1537 injectedBundle.outputText(makeString("ALERT:", addLeadingSpaceStripTrailingSpacesAddNewline(toWTFString(message)))); 1526 1538 } 1527 1539 … … 1532 1544 return; 1533 1545 1534 StringBuilder stringBuilder; 1535 stringBuilder.appendLiteral("CONFIRM: "); 1536 stringBuilder.append(toWTFString(message)); 1537 stringBuilder.append('\n'); 1538 injectedBundle.outputText(stringBuilder.toString()); 1546 injectedBundle.outputText(makeString("CONFIRM:", addLeadingSpaceStripTrailingSpacesAddNewline(toWTFString(message)))); 1539 1547 } 1540 1548 1541 1549 void InjectedBundlePage::willRunJavaScriptPrompt(WKStringRef message, WKStringRef defaultValue, WKBundleFrameRef) 1542 1550 { 1543 StringBuilder stringBuilder; 1544 stringBuilder.appendLiteral("PROMPT: "); 1545 stringBuilder.append(toWTFString(message)); 1546 stringBuilder.appendLiteral(", default text: "); 1547 stringBuilder.append(toWTFString(defaultValue)); 1548 stringBuilder.append('\n'); 1549 InjectedBundle::singleton().outputText(stringBuilder.toString()); 1551 InjectedBundle::singleton().outputText(makeString("PROMPT: ", toWTFString(message), ", default text:", addLeadingSpaceStripTrailingSpacesAddNewline(toWTFString(defaultValue)))); 1550 1552 } 1551 1553
Note: See TracChangeset
for help on using the changeset viewer.