[Form Validation] "character" in maxlength validation message should be singular...
authorcdumez@apple.com <cdumez@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 6 Jan 2017 18:55:35 +0000 (18:55 +0000)
committercdumez@apple.com <cdumez@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 6 Jan 2017 18:55:35 +0000 (18:55 +0000)
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:

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

12 files changed:
LayoutTests/ChangeLog
LayoutTests/fast/forms/validation-message-maxLength-expected.txt [new file with mode: 0644]
LayoutTests/fast/forms/validation-message-maxLength.html [new file with mode: 0644]
LayoutTests/platform/ios-simulator/TestExpectations
Source/WebCore/ChangeLog
Source/WebCore/English.lproj/Localizable.strings
Source/WebCore/English.lproj/Localizable.stringsdict [new file with mode: 0644]
Source/WebCore/WebCore.xcodeproj/project.pbxproj
Source/WebCore/extract-localizable-strings.pl
Source/WebCore/platform/LocalizedStrings.cpp
Source/WebCore/platform/LocalizedStrings.h
Source/WebCore/platform/cocoa/LocalizedStringsCocoa.mm

index 429f7c3..afca8ba 100644 (file)
@@ -1,3 +1,17 @@
+2017-01-06  Chris Dumez  <cdumez@apple.com>
+
+        [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  <jer.noble@apple.com>
 
         Add support for MediaKeySystemAccess.createMediaKeys()
diff --git a/LayoutTests/fast/forms/validation-message-maxLength-expected.txt b/LayoutTests/fast/forms/validation-message-maxLength-expected.txt
new file mode 100644 (file)
index 0000000..19472ee
--- /dev/null
@@ -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
diff --git a/LayoutTests/fast/forms/validation-message-maxLength.html b/LayoutTests/fast/forms/validation-message-maxLength.html
new file mode 100644 (file)
index 0000000..f59276c
--- /dev/null
@@ -0,0 +1,39 @@
+<!DOCTYPE html>
+<html>
+<body>
+<script src="../../resources/js-test-pre.js"></script>
+<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="../../resources/js-test-post.js"></script>
+</body>
+</html>
index f3b7377..d0a0562 100644 (file)
@@ -349,6 +349,7 @@ fast/text/all-small-caps-whitespace.html [ Skip ]
 
 # 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 ]
index aaea2af..2720885 100644 (file)
@@ -1,3 +1,26 @@
+2017-01-06  Chris Dumez  <cdumez@apple.com>
+
+        [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  <jer.noble@apple.com>
 
         Add support for MediaKeySystemAccess.createMediaKeys()
index b1cae48..c4ab532 100644 (file)
 "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 */
 /* 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";
 
 /* 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 */
diff --git a/Source/WebCore/English.lproj/Localizable.stringsdict b/Source/WebCore/English.lproj/Localizable.stringsdict
new file mode 100644 (file)
index 0000000..970c1a3
--- /dev/null
@@ -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>
index 2effefd..2f92cf1 100644 (file)
                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 */; };
                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>"; };
                                7CC7E3D617208C0F003C5277 /* IDNScriptWhiteList.txt */,
                                2D9F0E1214FF1CBF00BA0FF7 /* linearSRGB.icc */,
                                BCAD1808131C7A0D00990406 /* Localizable.strings */,
+                               837A80111E1E127300026B9F /* Localizable.stringsdict */,
                                7A1D7FC918F85F0F00C385AD /* mediaControlsLocalizedStrings.js */,
                                93153BE114195A5700FCF5BE /* missingImage.png */,
                                93153BD914181F7A00FCF5BE /* missingImage@2x.png */,
                                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 */,
                        name = mediaControlsLocalizedStrings.js;
                        sourceTree = "<group>";
                };
+               837A80111E1E127300026B9F /* Localizable.stringsdict */ = {
+                       isa = PBXVariantGroup;
+                       children = (
+                               837A80121E1E127300026B9F /* English */,
+                       );
+                       name = Localizable.stringsdict;
+                       sourceTree = "<group>";
+               };
                BCAD1808131C7A0D00990406 /* Localizable.strings */ = {
                        isa = PBXVariantGroup;
                        children = (
index 4dd19ac..b2c6939 100755 (executable)
@@ -153,7 +153,11 @@ for my $file (sort @files) {
         # 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 @@ handleString:
                     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;
index cda2a88..58a969b 100644 (file)
@@ -1146,11 +1146,15 @@ String validationMessageTooShortText(int, int minLength)
     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)
index 5328078..526adff 100644 (file)
@@ -312,6 +312,11 @@ namespace WebCore {
 
     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
index ad33430..fb596f2 100644 (file)
@@ -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>
 
 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>.
     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 String(result.get());
+    return localizedNSString((NSString *)keyString.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