Title: [210447] trunk
Revision
210447
Author
[email protected]
Date
2017-01-06 10:55:35 -0800 (Fri, 06 Jan 2017)

Log Message

[Form Validation] "character" in maxlength validation message should be singular when maxlength is 1
https://bugs.webkit.org/show_bug.cgi?id=166712
<rdar://problem/29872292>

Reviewed by Darin Adler.

Source/WebCore:

Fix validation message to use singular form of "character" when maxLength value is 1.

Test: fast/forms/validation-message-maxLength.html

* English.lproj/Localizable.strings:
* English.lproj/Localizable.stringsdict: Added.
* WebCore.xcodeproj/project.pbxproj:
* extract-localizable-strings.pl:
* platform/LocalizedStrings.cpp:
* platform/LocalizedStrings.h:
* platform/cocoa/LocalizedStringsCocoa.mm:
(WebCore::localizedNString):
(WebCore::localizedString):
(WebCore::validationMessageTooLongText):

LayoutTests:

Add layout test coverage.

* fast/forms/validation-message-maxLength-expected.txt: Added.
* fast/forms/validation-message-maxLength.html: Added.
* platform/ios-simulator/TestExpectations:

Modified Paths

Added Paths

Diff

Modified: trunk/LayoutTests/ChangeLog (210446 => 210447)


--- trunk/LayoutTests/ChangeLog	2017-01-06 18:50:18 UTC (rev 210446)
+++ trunk/LayoutTests/ChangeLog	2017-01-06 18:55:35 UTC (rev 210447)
@@ -1,3 +1,17 @@
+2017-01-06  Chris Dumez  <[email protected]>
+
+        [Form Validation] "character" in maxlength validation message should be singular when maxlength is 1
+        https://bugs.webkit.org/show_bug.cgi?id=166712
+        <rdar://problem/29872292>
+
+        Reviewed by Darin Adler.
+
+        Add layout test coverage.
+
+        * fast/forms/validation-message-maxLength-expected.txt: Added.
+        * fast/forms/validation-message-maxLength.html: Added.
+        * platform/ios-simulator/TestExpectations:
+
 2017-01-06  Jer Noble  <[email protected]>
 
         Add support for MediaKeySystemAccess.createMediaKeys()

Added: trunk/LayoutTests/fast/forms/validation-message-maxLength-expected.txt (0 => 210447)


--- trunk/LayoutTests/fast/forms/validation-message-maxLength-expected.txt	                        (rev 0)
+++ trunk/LayoutTests/fast/forms/validation-message-maxLength-expected.txt	2017-01-06 18:55:35 UTC (rev 210447)
@@ -0,0 +1,18 @@
+Tests the validation message when maxlength is used.
+
+On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
+
+
+PASS input.value is "abc"
+PASS input.checkValidity() is false
+PASS input.validationMessage is "Use no more than 2 characters"
+PASS input.value is "ab"
+PASS input.checkValidity() is false
+PASS input.validationMessage is "Use no more than one character"
+PASS input.value is "a"
+PASS input.checkValidity() is false
+PASS input.validationMessage is "Use no more than 0 characters"
+PASS successfullyParsed is true
+
+TEST COMPLETE
+ 

Added: trunk/LayoutTests/fast/forms/validation-message-maxLength.html (0 => 210447)


--- trunk/LayoutTests/fast/forms/validation-message-maxLength.html	                        (rev 0)
+++ trunk/LayoutTests/fast/forms/validation-message-maxLength.html	2017-01-06 18:55:35 UTC (rev 210447)
@@ -0,0 +1,39 @@
+<!DOCTYPE html>
+<html>
+<body>
+<script src=""
+<form id="testForm">
+<input type="submit" id="submitButton">
+</form>
+<script>
+description("Tests the validation message when maxlength is used.");
+
+var form = document.getElementById("testForm");
+var submit = document.getElementById("submitButton");
+
+var input = document.createElement("input");
+input.value = "abcd";
+input.maxLength = 2;
+form.prepend(input);
+
+input.focus();
+eventSender.keyDown(String.fromCharCode(0x0008)); // Delete.
+shouldBeEqualToString("input.value", "abc");
+shouldBeFalse("input.checkValidity()");
+shouldBeEqualToString("input.validationMessage", "Use no more than 2 characters");
+
+input.maxLength = 1;
+eventSender.keyDown(String.fromCharCode(0x0008)); // Delete.
+shouldBeEqualToString("input.value", "ab");
+shouldBeFalse("input.checkValidity()");
+shouldBeEqualToString("input.validationMessage", "Use no more than one character");
+
+input.maxLength = 0;
+eventSender.keyDown(String.fromCharCode(0x0008)); // Delete.
+shouldBeEqualToString("input.value", "a");
+shouldBeFalse("input.checkValidity()");
+shouldBeEqualToString("input.validationMessage", "Use no more than 0 characters");
+</script>
+<script src=""
+</body>
+</html>

Modified: trunk/LayoutTests/platform/ios-simulator/TestExpectations (210446 => 210447)


--- trunk/LayoutTests/platform/ios-simulator/TestExpectations	2017-01-06 18:50:18 UTC (rev 210446)
+++ trunk/LayoutTests/platform/ios-simulator/TestExpectations	2017-01-06 18:55:35 UTC (rev 210447)
@@ -349,6 +349,7 @@
 
 # This test relies on EventSender.keydown(), which is not supported on iOS
 webkit.org/b/155233 fast/events/max-tabindex-focus.html [ Skip ]
+fast/forms/validation-message-maxLength.html [ Skip ]
 fast/shadow-dom/shadow-host-removal-crash.html [ Skip ]
 fast/shadow-dom/input-element-in-shadow.html [ Skip ]
 fast/shadow-dom/activate-over-slotted-content.html [ Skip ]

Modified: trunk/Source/WebCore/ChangeLog (210446 => 210447)


--- trunk/Source/WebCore/ChangeLog	2017-01-06 18:50:18 UTC (rev 210446)
+++ trunk/Source/WebCore/ChangeLog	2017-01-06 18:55:35 UTC (rev 210447)
@@ -1,3 +1,26 @@
+2017-01-06  Chris Dumez  <[email protected]>
+
+        [Form Validation] "character" in maxlength validation message should be singular when maxlength is 1
+        https://bugs.webkit.org/show_bug.cgi?id=166712
+        <rdar://problem/29872292>
+
+        Reviewed by Darin Adler.
+
+        Fix validation message to use singular form of "character" when maxLength value is 1.
+
+        Test: fast/forms/validation-message-maxLength.html
+
+        * English.lproj/Localizable.strings:
+        * English.lproj/Localizable.stringsdict: Added.
+        * WebCore.xcodeproj/project.pbxproj:
+        * extract-localizable-strings.pl:
+        * platform/LocalizedStrings.cpp:
+        * platform/LocalizedStrings.h:
+        * platform/cocoa/LocalizedStringsCocoa.mm:
+        (WebCore::localizedNString):
+        (WebCore::localizedString):
+        (WebCore::validationMessageTooLongText):
+
 2017-01-06  Jer Noble  <[email protected]>
 
         Add support for MediaKeySystemAccess.createMediaKeys()

Modified: trunk/Source/WebCore/English.lproj/Localizable.strings (210446 => 210447)


--- trunk/Source/WebCore/English.lproj/Localizable.strings	2017-01-06 18:50:18 UTC (rev 210446)
+++ trunk/Source/WebCore/English.lproj/Localizable.strings	2017-01-06 18:55:35 UTC (rev 210447)
@@ -743,6 +743,9 @@
 "Use at least %d characters" = "Use at least %d characters";
 
 /* Validation message for form control elements with a value shorter than maximum allowed length */
+"Use no more than %d character(s)" = "Use no more than %d character(s)";
+
+/* Validation message for form control elements with a value shorter than maximum allowed length */
 "Use no more than %d characters" = "Use no more than %d characters";
 
 /* Description of WebCrypto master keys in Keychain */
@@ -847,12 +850,12 @@
 /* accessibility help text for elapsed time display */
 "current movie time in seconds" = "current movie time in seconds";
 
+/* accessibility role description for a date and time field. */
+"date and time field" = "date and time field";
+
 /* accessibility role description for a date field. */
 "date field" = "date field";
 
-/* accessibility role description for a date and time field */
-"date and time field" = "date and time field";
-
 /* role description of ARIA definition role */
 "definition" = "definition";
 
@@ -1210,7 +1213,7 @@
 /* An ARIA accessibility group that acts as an dialog. */
 "web dialog" = "web dialog";
 
-/* accessibility role description for a week field. */
+/* accessibility role description for a time field. */
 "week and year field" = "week and year field";
 
 /* Option in segmented control for choosing list type in text editing */

Added: trunk/Source/WebCore/English.lproj/Localizable.stringsdict (0 => 210447)


--- trunk/Source/WebCore/English.lproj/Localizable.stringsdict	                        (rev 0)
+++ trunk/Source/WebCore/English.lproj/Localizable.stringsdict	2017-01-06 18:55:35 UTC (rev 210447)
@@ -0,0 +1,22 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
+<plist version="1.0">
+<dict>
+	<key>Use no more than %d character(s)</key>
+	<dict>
+		<key>NSStringLocalizedFormatKey</key>
+		<string>Use no more than %#@characters@</string>
+		<key>characters</key>
+		<dict>
+			<key>NSStringFormatSpecTypeKey</key>
+			<string>NSStringPluralRuleType</string>
+			<key>NSStringFormatValueTypeKey</key>
+			<string>d</string>
+			<key>one</key>
+			<string>one character</string>
+			<key>other</key>
+			<string>%d characters</string>
+		</dict>
+	</dict>
+</dict>
+</plist>

Modified: trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj (210446 => 210447)


--- trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj	2017-01-06 18:50:18 UTC (rev 210446)
+++ trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj	2017-01-06 18:55:35 UTC (rev 210447)
@@ -3018,6 +3018,7 @@
 		836FBCEC178C117F00B21A15 /* SVGAnimatedProperty.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 836FBCEB178C117F00B21A15 /* SVGAnimatedProperty.cpp */; };
 		8372DB311A6780A800C697C5 /* DiagnosticLoggingResultType.h in Headers */ = {isa = PBXBuildFile; fileRef = 8372DB301A6780A800C697C5 /* DiagnosticLoggingResultType.h */; settings = {ATTRIBUTES = (Private, ); }; };
 		83765F951DAC522F00C06537 /* MouseEventInit.h in Headers */ = {isa = PBXBuildFile; fileRef = 83765F941DAC521800C06537 /* MouseEventInit.h */; settings = {ATTRIBUTES = (Private, ); }; };
+		837A80131E1E127300026B9F /* Localizable.stringsdict in Resources */ = {isa = PBXBuildFile; fileRef = 837A80111E1E127300026B9F /* Localizable.stringsdict */; };
 		837B7D201DC3F55000D051FC /* ValidationBubbleIOS.mm in Sources */ = {isa = PBXBuildFile; fileRef = 837B7D1F1DC3F54C00D051FC /* ValidationBubbleIOS.mm */; };
 		8386A96D19F61B2E00E1EC4A /* StyleBuilder.h in Headers */ = {isa = PBXBuildFile; fileRef = 8386A96C19F61B2E00E1EC4A /* StyleBuilder.h */; };
 		8386A97019F61E4F00E1EC4A /* StyleBuilder.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 8386A96E19F61E4F00E1EC4A /* StyleBuilder.cpp */; };
@@ -10528,6 +10529,7 @@
 		8372DB301A6780A800C697C5 /* DiagnosticLoggingResultType.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = DiagnosticLoggingResultType.h; sourceTree = "<group>"; };
 		83765F931DAC521800C06537 /* MouseEventInit.idl */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = MouseEventInit.idl; sourceTree = "<group>"; };
 		83765F941DAC521800C06537 /* MouseEventInit.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MouseEventInit.h; sourceTree = "<group>"; };
+		837A80121E1E127300026B9F /* English */ = {isa = PBXFileReference; lastKnownFileType = text.plist.stringsdict; name = English; path = English.lproj/Localizable.stringsdict; sourceTree = SOURCE_ROOT; };
 		837B7D1F1DC3F54C00D051FC /* ValidationBubbleIOS.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = ValidationBubbleIOS.mm; sourceTree = "<group>"; };
 		8386A96C19F61B2E00E1EC4A /* StyleBuilder.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = StyleBuilder.h; sourceTree = "<group>"; };
 		8386A96E19F61E4F00E1EC4A /* StyleBuilder.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = StyleBuilder.cpp; sourceTree = "<group>"; };
@@ -15562,6 +15564,7 @@
 				7CC7E3D617208C0F003C5277 /* IDNScriptWhiteList.txt */,
 				2D9F0E1214FF1CBF00BA0FF7 /* linearSRGB.icc */,
 				BCAD1808131C7A0D00990406 /* Localizable.strings */,
+				837A80111E1E127300026B9F /* Localizable.stringsdict */,
 				7A1D7FC918F85F0F00C385AD /* mediaControlsLocalizedStrings.js */,
 				93153BE114195A5700FCF5BE /* missingImage.png */,
 				93153BD914181F7A00FCF5BE /* [email protected] */,
@@ -28533,6 +28536,7 @@
 				7CC7E3D717208C0F003C5277 /* IDNScriptWhiteList.txt in Resources */,
 				2D9F0E1314FF1CBF00BA0FF7 /* linearSRGB.icc in Resources */,
 				BCAD180A131C7A0D00990406 /* Localizable.strings in Resources */,
+				837A80131E1E127300026B9F /* Localizable.stringsdict in Resources */,
 				311C08BD18EB7CAF00B65615 /* mediaControlsApple.css in Resources */,
 				311C08BE18EB7CAF00B65615 /* mediaControlsApple.js in Resources */,
 				311C08BF18EB7CAF00B65615 /* mediaControlsiOS.css in Resources */,
@@ -31928,6 +31932,14 @@
 			name = mediaControlsLocalizedStrings.js;
 			sourceTree = "<group>";
 		};
+		837A80111E1E127300026B9F /* Localizable.stringsdict */ = {
+			isa = PBXVariantGroup;
+			children = (
+				837A80121E1E127300026B9F /* English */,
+			);
+			name = Localizable.stringsdict;
+			sourceTree = "<group>";
+		};
 		BCAD1808131C7A0D00990406 /* Localizable.strings */ = {
 			isa = PBXVariantGroup;
 			children = (

Modified: trunk/Source/WebCore/extract-localizable-strings.pl (210446 => 210447)


--- trunk/Source/WebCore/extract-localizable-strings.pl	2017-01-06 18:50:18 UTC (rev 210446)
+++ trunk/Source/WebCore/extract-localizable-strings.pl	2017-01-06 18:55:35 UTC (rev 210447)
@@ -153,7 +153,11 @@
         # Handle all the tokens in the line.
         while (s-^\s*([#\w]+|/\*|//|[^#\w/'"()\[\],]+|.)--) {
             my $token = $1;
-            
+
+            if ($token eq "@" and $expected and $expected eq "a quoted string") {
+                next;
+            }
+
             if ($token eq "\"") {
                 if ($expected and $expected ne "a quoted string") {
                     emitError($file, $., "found a quoted string but expected $expected");
@@ -236,7 +240,7 @@
                     emitError($file, $., "found $token but expected $expected");
                     $expected = "";
                 }
-                if ($token =~ /(WEB_)?UI_STRING(_KEY)?(_INTERNAL)?$/) {
+                if (($token =~ /(WEB_)?UI_STRING(_KEY)?(_INTERNAL)?$/) || ($token =~ /WEB_UI_NSSTRING$/)) {
                     $expected = "(";
                     $macro = $token;
                     $UIString = undef;

Modified: trunk/Source/WebCore/platform/LocalizedStrings.cpp (210446 => 210447)


--- trunk/Source/WebCore/platform/LocalizedStrings.cpp	2017-01-06 18:50:18 UTC (rev 210446)
+++ trunk/Source/WebCore/platform/LocalizedStrings.cpp	2017-01-06 18:55:35 UTC (rev 210447)
@@ -1146,11 +1146,15 @@
     return formatLocalizedString(WEB_UI_STRING("Use at least %d characters", "Validation message for form control elements with a value shorter than minimum allowed length"), minLength);
 }
 
+#if !PLATFORM(COCOA)
+
 String validationMessageTooLongText(int, int maxLength)
 {
     return formatLocalizedString(WEB_UI_STRING("Use no more than %d characters", "Validation message for form control elements with a value shorter than maximum allowed length"), maxLength);
 }
 
+#endif
+
 String validationMessageRangeUnderflowText(const String& minimum)
 {
 #if USE(CF)

Modified: trunk/Source/WebCore/platform/LocalizedStrings.h (210446 => 210447)


--- trunk/Source/WebCore/platform/LocalizedStrings.h	2017-01-06 18:50:18 UTC (rev 210446)
+++ trunk/Source/WebCore/platform/LocalizedStrings.h	2017-01-06 18:55:35 UTC (rev 210447)
@@ -312,6 +312,11 @@
 
     WEBCORE_EXPORT String localizedString(const char* key);
 
+#ifdef __OBJC__
+#define WEB_UI_NSSTRING(string, description) WebCore::localizedNSString(string)
+    WEBCORE_EXPORT NSString *localizedNSString(NSString *key) NS_FORMAT_ARGUMENT(1);
+#endif
+
 } // namespace WebCore
 
 #endif // LocalizedStrings_h

Modified: trunk/Source/WebCore/platform/cocoa/LocalizedStringsCocoa.mm (210446 => 210447)


--- trunk/Source/WebCore/platform/cocoa/LocalizedStringsCocoa.mm	2017-01-06 18:50:18 UTC (rev 210446)
+++ trunk/Source/WebCore/platform/cocoa/LocalizedStringsCocoa.mm	2017-01-06 18:55:35 UTC (rev 210447)
@@ -26,7 +26,6 @@
 #include "config.h"
 #include "LocalizedStrings.h"
 
-#include <CoreFoundation/CFBundle.h>
 #include <wtf/Assertions.h>
 #include <wtf/MainThread.h>
 #include <wtf/RetainPtr.h>
@@ -34,10 +33,8 @@
 
 namespace WebCore {
 
-String localizedString(const char* key)
+NSString *localizedNSString(NSString *key)
 {
-    static CFBundleRef bundle = CFBundleGetBundleWithIdentifier(CFSTR("com.apple.WebCore"));
-
 #if !PLATFORM(IOS)
     // Can be called on a dispatch queue when initializing strings on iOS.
     // See LoadWebLocalizedStrings and <rdar://problem/7902473>.
@@ -44,16 +41,19 @@
     ASSERT(isMainThread());
 #endif
 
+    static NSBundle *bundle = [NSBundle bundleWithIdentifier:@"com.apple.WebCore"];
+    return [bundle localizedStringForKey:key value:@"localized string not found" table:nullptr];
+}
+
+String localizedString(const char* key)
+{
     RetainPtr<CFStringRef> keyString = adoptCF(CFStringCreateWithCStringNoCopy(0, key, kCFStringEncodingUTF8, kCFAllocatorNull));
-    CFStringRef notFound = CFSTR("localized string not found");
-    RetainPtr<CFStringRef> result;
-    if (bundle) {
-        result = adoptCF(CFBundleCopyLocalizedString(bundle, keyString.get(), notFound, 0));
-        ASSERT_WITH_MESSAGE(result.get() != notFound, "could not find localizable string %s in bundle", key);
-    } else
-        result = notFound;
+    return localizedNSString((NSString *)keyString.get());
+}
 
-    return String(result.get());
+String validationMessageTooLongText(int, int maxLength)
+{
+    return [NSString localizedStringWithFormat:WEB_UI_NSSTRING(@"Use no more than %d character(s)", @"Validation message for form control elements with a value shorter than maximum allowed length"), maxLength];
 }
 
 } // namespace WebCore
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to