Calling setValue() while typing should invoke -textDidChangeInTextField in the inject...
authorwenson_hsieh@apple.com <wenson_hsieh@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 18 Dec 2018 15:37:10 +0000 (15:37 +0000)
committerwenson_hsieh@apple.com <wenson_hsieh@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 18 Dec 2018 15:37:10 +0000 (15:37 +0000)
https://bugs.webkit.org/show_bug.cgi?id=192785
<rdar://problem/45321184>

Reviewed by Tim Horton.

Source/WebCore:

Makes a minor adjustment in `TextFieldInputType::setValue` to consider value changes as "user editing", if we're
currently processing a keystroke from the user. This is useful for certain private clients, such as Safari, that
need to know when the user is typing in a text form control, but the page is preventing default text insertion
behavior and instead updating values programmatically.

Test: fast/forms/call-text-did-change-in-text-field-when-typing.html

* html/TextFieldInputType.cpp:
(WebCore::TextFieldInputType::setValue):

LayoutTests:

Add a test to verify that:
1. When typing in a focused field, the injected bundle method is invoked.
2. When changing the value of the focused field under non-typing user interaction, the method isn't invoked.
3. When changing the value of the focused field programmatically without user gesture, the method isn't invoked.

* TestExpectations:
* fast/forms/call-text-did-change-in-text-field-when-typing-expected.txt: Added.
* fast/forms/call-text-did-change-in-text-field-when-typing.html: Added.
* platform/wk2/TestExpectations:

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

LayoutTests/ChangeLog
LayoutTests/TestExpectations
LayoutTests/fast/forms/call-text-did-change-in-text-field-when-typing-expected.txt [new file with mode: 0644]
LayoutTests/fast/forms/call-text-did-change-in-text-field-when-typing.html [new file with mode: 0644]
LayoutTests/platform/wk2/TestExpectations
Source/WebCore/ChangeLog
Source/WebCore/html/TextFieldInputType.cpp

index 5f72761..99b2317 100644 (file)
@@ -1,3 +1,21 @@
+2018-12-18  Wenson Hsieh  <wenson_hsieh@apple.com>
+
+        Calling setValue() while typing should invoke -textDidChangeInTextField in the injected bundle
+        https://bugs.webkit.org/show_bug.cgi?id=192785
+        <rdar://problem/45321184>
+
+        Reviewed by Tim Horton.
+
+        Add a test to verify that:
+        1. When typing in a focused field, the injected bundle method is invoked.
+        2. When changing the value of the focused field under non-typing user interaction, the method isn't invoked.
+        3. When changing the value of the focused field programmatically without user gesture, the method isn't invoked.
+
+        * TestExpectations:
+        * fast/forms/call-text-did-change-in-text-field-when-typing-expected.txt: Added.
+        * fast/forms/call-text-did-change-in-text-field-when-typing.html: Added.
+        * platform/wk2/TestExpectations:
+
 2018-12-17  Jiewen Tan  <jiewen_tan@apple.com>
 
         [Mac] Layout Test http/wpt/webauthn/public-key-credential-create-success-hid.https.html and http/wpt/webauthn/public-key-credential-get-success-hid.https.html are flaky
index d75b0e9..f5643c2 100644 (file)
@@ -129,6 +129,7 @@ http/tests/storageAccess/ [ Skip ]
 http/tests/navigation/process-swap-window-open.html [ Skip ]
 http/tests/navigation/useragent-reload.php [ Skip ]
 storage/indexeddb/modern/opendatabase-after-storage-crash.html [ Skip ]
+fast/forms/call-text-did-change-in-text-field-when-typing.html [ Skip ]
 
 # Only Mac and iOS have an implementation of UIScriptController::doAsyncTask().
 fast/harness/uiscriptcontroller [ Skip ]
diff --git a/LayoutTests/fast/forms/call-text-did-change-in-text-field-when-typing-expected.txt b/LayoutTests/fast/forms/call-text-did-change-in-text-field-when-typing-expected.txt
new file mode 100644 (file)
index 0000000..2336ace
--- /dev/null
@@ -0,0 +1,19 @@
+
+Verifies that programmatically changing text field values with user interaction invokes the -didChangeInTextField injected bundle method. This test requires WebKitTestRunner.
+
+On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
+
+1. Changing text field value with user typing gesture:
+Text did change in text field.
+The value of the text field is: "a"
+
+2. Changing text field value with non-typing user gesture:
+PASS buttonClicked became true
+The value of the text field is: "ab"
+
+3. Changing text field value without user gesture:
+The value of the text field is: "abc"
+PASS successfullyParsed is true
+
+TEST COMPLETE
+
diff --git a/LayoutTests/fast/forms/call-text-did-change-in-text-field-when-typing.html b/LayoutTests/fast/forms/call-text-did-change-in-text-field-when-typing.html
new file mode 100644 (file)
index 0000000..53ebb1d
--- /dev/null
@@ -0,0 +1,72 @@
+
+<!DOCTYPE html>
+<html>
+<head>
+    <meta name="viewport" content="width=device-width, user-scalable=no">
+    <script src="../../resources/js-test.js"></script>
+    <script src="../../resources/ui-helper.js"></script>
+    <style>
+        body {
+            margin: 0;
+        }
+
+        input, button {
+            width: 100%;
+            height: 100px;
+            display: block;
+        }
+    </style>
+</head>
+<body>
+<input type="text" id="field"></input>
+<button value="Insert text" id="button"></button>
+<div id="description"></div>
+<div id="console"></div>
+</body>
+<script>
+    description("Verifies that programmatically changing text field values with user interaction invokes the -didChangeInTextField"
+        + " injected bundle method. This test requires WebKitTestRunner.");
+
+    buttonClicked = false;
+
+    if (window.testRunner) {
+        jsTestIsAsync = true;
+        testRunner.installTextDidChangeInTextFieldCallback(() => debug("Text did change in text field."));
+    }
+
+    field.addEventListener("keypress", event => {
+        field.value += event.key;
+        event.preventDefault();
+    });
+
+    button.addEventListener("click", event => {
+        field.focus();
+        field.value += "b";
+        buttonClicked = true;
+    });
+
+    addEventListener("load", async () => {
+        if (!window.testRunner)
+            return;
+
+        await UIHelper.activateAndWaitForInputSessionAt(100, 50);
+
+        debug("1. Changing text field value with user typing gesture:");
+        await UIHelper.typeCharacter("a");
+        debug(`The value of the text field is: "${field.value}"`);
+        debug("");
+
+        debug("2. Changing text field value with non-typing user gesture:");
+        UIHelper.activateAt(100, 150);
+        await new Promise(resolve => shouldBecomeEqual("buttonClicked", "true", resolve));
+        debug(`The value of the text field is: "${field.value}"`);
+        debug("");
+
+        debug("3. Changing text field value without user gesture:");
+        field.value += "c";
+        debug(`The value of the text field is: "${field.value}"`);
+
+        finishJSTest();
+    });
+</script>
+</html>
\ No newline at end of file
index c50535d..8e959ed 100644 (file)
@@ -742,6 +742,8 @@ http/wpt/cross-origin-resource-policy/ [ Pass ]
 http/tests/navigation/useragent-reload.php [ Pass ]
 storage/indexeddb/modern/opendatabase-after-storage-crash.html [ Pass ]
 
+fast/forms/call-text-did-change-in-text-field-when-typing.html [ Pass ]
+
 ### END OF (5) Progressions, expected successes that are expected failures in WebKit1.
 ########################################
 
index 6ab1101..9796279 100644 (file)
@@ -1,3 +1,21 @@
+2018-12-18  Wenson Hsieh  <wenson_hsieh@apple.com>
+
+        Calling setValue() while typing should invoke -textDidChangeInTextField in the injected bundle
+        https://bugs.webkit.org/show_bug.cgi?id=192785
+        <rdar://problem/45321184>
+
+        Reviewed by Tim Horton.
+
+        Makes a minor adjustment in `TextFieldInputType::setValue` to consider value changes as "user editing", if we're
+        currently processing a keystroke from the user. This is useful for certain private clients, such as Safari, that
+        need to know when the user is typing in a text form control, but the page is preventing default text insertion
+        behavior and instead updating values programmatically.
+
+        Test: fast/forms/call-text-did-change-in-text-field-when-typing.html
+
+        * html/TextFieldInputType.cpp:
+        (WebCore::TextFieldInputType::setValue):
+
 2018-12-18  Zalan Bujtas  <zalan@apple.com>
 
         [LFC][BFC][MarginCollapsing] Implement marginBeforeCollapsesWithParentMarginAfter
index 471b77a..a629713 100644 (file)
@@ -57,6 +57,7 @@
 #include "TextEvent.h"
 #include "TextIterator.h"
 #include "TextNodeTraversal.h"
+#include "UserTypingGestureIndicator.h"
 #include "WheelEvent.h"
 
 #if ENABLE(DATALIST_ELEMENT)
@@ -168,6 +169,9 @@ void TextFieldInputType::setValue(const String& sanitizedValue, bool valueChange
     // FIXME: Why do we do this when eventBehavior == DispatchNoEvent
     if (!input->focused() || eventBehavior == DispatchNoEvent)
         input->setTextAsOfLastFormControlChangeEvent(sanitizedValue);
+
+    if (UserTypingGestureIndicator::processingUserTypingGesture())
+        didSetValueByUserEdit();
 }
 
 #if ENABLE(DATALIST_ELEMENT)