REGRESSION (r215784): The title of right-to-left pages are empty
authordbates@webkit.org <dbates@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 12 Sep 2017 16:34:23 +0000 (16:34 +0000)
committerdbates@webkit.org <dbates@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 12 Sep 2017 16:34:23 +0000 (16:34 +0000)
https://bugs.webkit.org/show_bug.cgi?id=176746
<rdar://problem/34211419>

Reviewed by Brent Fulgham.

Source/WebCore:

Left truncate a long right-to-left title.

Right-to-left text represents the visual ordering of text. Internally WebKit stores
right-to-left text identically to left-to-right text in memory. So, we can use the
same string operation to truncate right-to-left text as we do to truncate left-to-right
text.

* platform/text/StringWithDirection.h:
(WebCore::truncateFromEnd):

Tools:

Add unit test to ensure we do not regress StringWithDirection.truncateFromEnd().

* TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj:
* TestWebKitAPI/Tests/WebCore/StringWithDirection.cpp: Added.
(TestWebKitAPI::TEST):

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@221921 268f45cc-cd09-0410-ab3c-d52691b4dbfc

Source/WebCore/ChangeLog
Source/WebCore/platform/text/StringWithDirection.h
Tools/ChangeLog
Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj
Tools/TestWebKitAPI/Tests/WebCore/StringWithDirection.cpp [new file with mode: 0644]

index 3e6306a..75a2ee4 100644 (file)
@@ -1,3 +1,21 @@
+2017-09-12  Daniel Bates  <dabates@apple.com>
+
+        REGRESSION (r215784): The title of right-to-left pages are empty
+        https://bugs.webkit.org/show_bug.cgi?id=176746
+        <rdar://problem/34211419>
+
+        Reviewed by Brent Fulgham.
+
+        Left truncate a long right-to-left title.
+
+        Right-to-left text represents the visual ordering of text. Internally WebKit stores
+        right-to-left text identically to left-to-right text in memory. So, we can use the
+        same string operation to truncate right-to-left text as we do to truncate left-to-right
+        text.
+
+        * platform/text/StringWithDirection.h:
+        (WebCore::truncateFromEnd):
+
 2017-09-12  Chris Fleizach  <cfleizach@apple.com>
 
         AX: On generic container elements, WebKit should distinguish between tooltip (e.g. @title) and label (e.g. @aria-label) attributes
index 4727a9f..c860429 100644 (file)
@@ -70,9 +70,7 @@ inline bool operator!=(const StringWithDirection& a, const StringWithDirection&
 
 inline StringWithDirection truncateFromEnd(const StringWithDirection& string, unsigned maxLength)
 {
-    if (string.direction == LTR)
-        return { string.string.left(maxLength), LTR };
-    return { string.string.right(maxLength), RTL };
+    return { string.string.left(maxLength), string.direction };
 }
 
 }
index a1a4e21..579d883 100644 (file)
@@ -1,3 +1,17 @@
+2017-09-12  Daniel Bates  <dabates@apple.com>
+
+        REGRESSION (r215784): The title of right-to-left pages are empty
+        https://bugs.webkit.org/show_bug.cgi?id=176746
+        <rdar://problem/34211419>
+
+        Reviewed by Brent Fulgham.
+
+        Add unit test to ensure we do not regress StringWithDirection.truncateFromEnd().
+
+        * TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj:
+        * TestWebKitAPI/Tests/WebCore/StringWithDirection.cpp: Added.
+        (TestWebKitAPI::TEST):
+
 2017-09-12  Alex Christensen  <achristensen@webkit.org>
 
         Add WKUIDelegatePrivate equivalent of WKPageUIClient's decidePolicyForNotificationPermissionRequest
index d738cb1..beb39ba 100644 (file)
                CE3524F81B1431F60028A7C5 /* TextFieldDidBeginAndEndEditing_Bundle.cpp in Sources */ = {isa = PBXBuildFile; fileRef = CE3524F21B142B8D0028A7C5 /* TextFieldDidBeginAndEndEditing_Bundle.cpp */; };
                CE3524F91B1441C40028A7C5 /* TextFieldDidBeginAndEndEditing.cpp in Sources */ = {isa = PBXBuildFile; fileRef = CE3524F11B142B8D0028A7C5 /* TextFieldDidBeginAndEndEditing.cpp */; };
                CE3524FA1B1443890028A7C5 /* input-focus-blur.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = CE3524F51B142BBB0028A7C5 /* input-focus-blur.html */; };
+               CE4D5DE71F6743BA0072CFC6 /* StringWithDirection.cpp in Sources */ = {isa = PBXBuildFile; fileRef = CE4D5DE51F6743BA0072CFC6 /* StringWithDirection.cpp */; };
                CEA6CF2819CCF69D0064F5A7 /* open-and-close-window.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = CEA6CF2719CCF69D0064F5A7 /* open-and-close-window.html */; };
                CEBABD491B71687C0051210A /* should-open-external-schemes.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = CEBABD481B71687C0051210A /* should-open-external-schemes.html */; };
                CEBCA12F1E3A660100C73293 /* OverrideContentSecurityPolicy.mm in Sources */ = {isa = PBXBuildFile; fileRef = CEBCA12E1E3A660100C73293 /* OverrideContentSecurityPolicy.mm */; };
                CE3524F11B142B8D0028A7C5 /* TextFieldDidBeginAndEndEditing.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = TextFieldDidBeginAndEndEditing.cpp; sourceTree = "<group>"; };
                CE3524F21B142B8D0028A7C5 /* TextFieldDidBeginAndEndEditing_Bundle.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = TextFieldDidBeginAndEndEditing_Bundle.cpp; sourceTree = "<group>"; };
                CE3524F51B142BBB0028A7C5 /* input-focus-blur.html */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.html; path = "input-focus-blur.html"; sourceTree = "<group>"; };
+               CE4D5DE51F6743BA0072CFC6 /* StringWithDirection.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = StringWithDirection.cpp; sourceTree = "<group>"; };
                CE50D8C81C8665CE0072EA5A /* OptionSet.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = OptionSet.cpp; sourceTree = "<group>"; };
                CEA6CF2219CCF5BD0064F5A7 /* OpenAndCloseWindow.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = OpenAndCloseWindow.mm; sourceTree = "<group>"; };
                CEA6CF2719CCF69D0064F5A7 /* open-and-close-window.html */ = {isa = PBXFileReference; lastKnownFileType = text.html; path = "open-and-close-window.html"; sourceTree = "<group>"; };
                                A17991891E1CA24100A505ED /* SharedBufferTest.cpp */,
                                A179918A1E1CA24100A505ED /* SharedBufferTest.h */,
                                ECA680CD1E68CC0900731D20 /* StringUtilities.mm */,
+                               CE4D5DE51F6743BA0072CFC6 /* StringWithDirection.cpp */,
                                CDC2C7141797089D00E627FB /* TimeRanges.cpp */,
                                7AD3FE8D1D75FB8D00B169A4 /* TransformationMatrix.cpp */,
                                440A1D3814A0103A008A66F2 /* URL.cpp */,
                                7CCE7ED01A411A7E00447C4C /* StringByEvaluatingJavaScriptFromString.mm in Sources */,
                                7CCE7ED11A411A7E00447C4C /* StringTruncator.mm in Sources */,
                                ECA680CE1E68CC0900731D20 /* StringUtilities.mm in Sources */,
+                               CE4D5DE71F6743BA0072CFC6 /* StringWithDirection.cpp in Sources */,
                                7CCE7ED21A411A7E00447C4C /* SubresourceErrorCrash.mm in Sources */,
                                7CCE7EA81A411A1900447C4C /* SyntheticBackingScaleFactorWindow.m in Sources */,
                                7CCE7F161A411AE600447C4C /* TerminateTwice.cpp in Sources */,
diff --git a/Tools/TestWebKitAPI/Tests/WebCore/StringWithDirection.cpp b/Tools/TestWebKitAPI/Tests/WebCore/StringWithDirection.cpp
new file mode 100644 (file)
index 0000000..3ef86b3
--- /dev/null
@@ -0,0 +1,80 @@
+/*
+ * Copyright (C) 2017 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "config.h"
+
+#include "Test.h"
+#include "WTFStringUtilities.h"
+#include <WebCore/StringWithDirection.h>
+
+using namespace WebCore;
+
+namespace TestWebKitAPI {
+
+TEST(StringWithDirection, TruncateAtEndWithLeftToRightString)
+{
+    StringWithDirection string { "Cappuccino", LTR };
+    StringWithDirection result;
+
+    result = truncateFromEnd(string, 0);
+    EXPECT_EQ(LTR, result.direction);
+    EXPECT_EQ("", result.string);
+
+    result = truncateFromEnd(string, 1);
+    EXPECT_EQ(LTR, result.direction);
+    EXPECT_EQ("C", result.string);
+
+    result = truncateFromEnd(string, 2);
+    EXPECT_EQ(LTR, result.direction);
+    EXPECT_EQ("Ca", result.string);
+
+    result = truncateFromEnd(string, 1000);
+    EXPECT_EQ(LTR, result.direction);
+    EXPECT_EQ("Cappuccino", result.string);
+}
+
+TEST(StringWithDirection, TruncateAtEndWithRightToLeftString)
+{
+    StringWithDirection string { String::fromUTF8("קָפּוּצִ'ינוֹ"), RTL };
+    StringWithDirection result;
+
+    result = truncateFromEnd(string, 0);
+    EXPECT_EQ(RTL, result.direction);
+    EXPECT_EQ("", result.string);
+
+    result = truncateFromEnd(string, 1);
+    EXPECT_EQ(RTL, result.direction);
+    EXPECT_EQ(String::fromUTF8("ק"), result.string);
+
+    result = truncateFromEnd(string, 2);
+    EXPECT_EQ(RTL, result.direction);
+    EXPECT_EQ(String::fromUTF8("קָ"), result.string);
+
+    result = truncateFromEnd(string, 1000);
+    EXPECT_EQ(RTL, result.direction);
+    EXPECT_EQ(String::fromUTF8("קָפּוּצִ'ינוֹ"), result.string);
+}
+
+} // namespace TestWebKitAPI