[Extra zoom mode] Injected bundle form client should be notified when editing text...
authorwenson_hsieh@apple.com <wenson_hsieh@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 20 Apr 2018 22:21:54 +0000 (22:21 +0000)
committerwenson_hsieh@apple.com <wenson_hsieh@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 20 Apr 2018 22:21:54 +0000 (22:21 +0000)
https://bugs.webkit.org/show_bug.cgi?id=184822
<rdar://problem/38807319>

Reviewed by Tim Horton.

Source/WebCore:

Export the constructor and destructor of UserTypingGestureIndicator for use in WebKit (see WebPage.cpp).

Test: fast/forms/extrazoom/edit-text-field-calls-injected-bundle.html

* dom/UserTypingGestureIndicator.h:

Source/WebKit:

Fixes the bug by making a couple of tweaks: (1) don't use a separate codepath for inserting text in text inputs,
and (2) force a user typing gesture when inserting text using this codepath (i.e. WKTextInputListViewController).
Also adds plumbing to enable testing text entry with WKTextInputListViewController in extra zoom mode.

* UIProcess/API/Cocoa/WKWebView.mm:
(-[WKWebView _simulateTextEntered:]):
* UIProcess/API/Cocoa/WKWebViewPrivate.h:

Introduce testing SPI to simulate text entry. Additionally, add a missing availability annotation around testing
SPI added in 2017 to help test drag and drop for iOS 11.

* UIProcess/ios/WKContentViewInteraction.h:
* UIProcess/ios/WKContentViewInteraction.mm:
(-[WKContentView _simulateTextEntered:]):
* WebProcess/WebPage/WebPage.cpp:
(WebKit::WebPage::setTextAsync):

Tools:

Add WebKitTestRunner support for listening to form editing SPI hooks in the injected bundle. The new layout test
installs callbacks that listen for "begin editing", "end editing", and "text changed" calls to injected bundle
SPI. See other ChangeLogs for more detail.

* DumpRenderTree/ios/UIScriptControllerIOS.mm:
(WTR::UIScriptController::enterText):
* TestRunnerShared/UIScriptContext/Bindings/UIScriptController.idl:

Add UIScriptController support for simulating text entry in the currently focused element.

* TestRunnerShared/UIScriptContext/UIScriptController.cpp:
(WTR::UIScriptController::enterText):
* TestRunnerShared/UIScriptContext/UIScriptController.h:
* WebKitTestRunner/InjectedBundle/Bindings/TestRunner.idl:

Add TestRunner bindings for registering injected bundle form client callbacks.

* WebKitTestRunner/InjectedBundle/InjectedBundle.cpp:
(WTR::handleTextDidChangeInTextField):
(WTR::handleTextFieldDidBeginEditing):
(WTR::handleTextFieldDidEndEditing):
(WTR::InjectedBundle::didCreatePage):

Set the injected bundle form editor client.

(WTR::InjectedBundle::setUpInjectedBundleClients):
(WTR::InjectedBundle::textDidChangeInTextField):
(WTR::InjectedBundle::textFieldDidBeginEditing):
(WTR::InjectedBundle::textFieldDidEndEditing):
* WebKitTestRunner/InjectedBundle/InjectedBundle.h:
* WebKitTestRunner/InjectedBundle/TestRunner.cpp:
(WTR::TestRunner::installTextDidChangeInTextFieldCallback):
(WTR::TestRunner::textDidChangeInTextFieldCallback):
(WTR::TestRunner::installTextFieldDidBeginEditingCallback):
(WTR::TestRunner::textFieldDidBeginEditingCallback):
(WTR::TestRunner::installTextFieldDidEndEditingCallback):
(WTR::TestRunner::textFieldDidEndEditingCallback):
* WebKitTestRunner/InjectedBundle/TestRunner.h:
* WebKitTestRunner/ios/UIScriptControllerIOS.mm:
(WTR::UIScriptController::enterText):

LayoutTests:

Add a new layout test that focuses an input field, simulates text entry, and verifies that the injected bundle
form client's textDidChangeInTextField, textFieldDidBeginEditing and textFieldDidEndEditing functions are called.

* TestExpectations:

Skip tests in fast/forms/extrazoom by default.

* fast/forms/extrazoom/edit-text-field-calls-injected-bundle-expected.txt: Added.
* fast/forms/extrazoom/edit-text-field-calls-injected-bundle.html: Added.
* resources/ui-helper.js:
(window.UIHelper.enterText):

Introduce a new UIHelper method to simulate text entry in the currently focused element.

(window.UIHelper):

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

24 files changed:
LayoutTests/ChangeLog
LayoutTests/TestExpectations
LayoutTests/fast/forms/extrazoom/edit-text-field-calls-injected-bundle-expected.txt [new file with mode: 0644]
LayoutTests/fast/forms/extrazoom/edit-text-field-calls-injected-bundle.html [new file with mode: 0644]
LayoutTests/resources/ui-helper.js
Source/WebCore/ChangeLog
Source/WebCore/dom/UserTypingGestureIndicator.h
Source/WebKit/ChangeLog
Source/WebKit/UIProcess/API/Cocoa/WKWebView.mm
Source/WebKit/UIProcess/API/Cocoa/WKWebViewPrivate.h
Source/WebKit/UIProcess/ios/WKContentViewInteraction.h
Source/WebKit/UIProcess/ios/WKContentViewInteraction.mm
Source/WebKit/WebProcess/WebPage/WebPage.cpp
Tools/ChangeLog
Tools/DumpRenderTree/ios/UIScriptControllerIOS.mm
Tools/TestRunnerShared/UIScriptContext/Bindings/UIScriptController.idl
Tools/TestRunnerShared/UIScriptContext/UIScriptController.cpp
Tools/TestRunnerShared/UIScriptContext/UIScriptController.h
Tools/WebKitTestRunner/InjectedBundle/Bindings/TestRunner.idl
Tools/WebKitTestRunner/InjectedBundle/InjectedBundle.cpp
Tools/WebKitTestRunner/InjectedBundle/InjectedBundle.h
Tools/WebKitTestRunner/InjectedBundle/TestRunner.cpp
Tools/WebKitTestRunner/InjectedBundle/TestRunner.h
Tools/WebKitTestRunner/ios/UIScriptControllerIOS.mm

index 57848bf..6b4a07e 100644 (file)
@@ -1,3 +1,27 @@
+2018-04-20  Wenson Hsieh  <wenson_hsieh@apple.com>
+
+        [Extra zoom mode] Injected bundle form client should be notified when editing text fields
+        https://bugs.webkit.org/show_bug.cgi?id=184822
+        <rdar://problem/38807319>
+
+        Reviewed by Tim Horton.
+
+        Add a new layout test that focuses an input field, simulates text entry, and verifies that the injected bundle
+        form client's textDidChangeInTextField, textFieldDidBeginEditing and textFieldDidEndEditing functions are called.
+
+        * TestExpectations:
+
+        Skip tests in fast/forms/extrazoom by default.
+
+        * fast/forms/extrazoom/edit-text-field-calls-injected-bundle-expected.txt: Added.
+        * fast/forms/extrazoom/edit-text-field-calls-injected-bundle.html: Added.
+        * resources/ui-helper.js:
+        (window.UIHelper.enterText):
+
+        Introduce a new UIHelper method to simulate text entry in the currently focused element.
+
+        (window.UIHelper):
+
 2018-04-20  Youenn Fablet  <youenn@apple.com>
 
         Refactor NetworkResourceLoader to check for m_networkLoadChecker presence before using it
index 01ee214..567c6d3 100644 (file)
@@ -18,6 +18,7 @@ editing/caret/ios [ Skip ]
 editing/pasteboard/gtk [ Skip ]
 editing/selection/ios [ Skip ]
 tiled-drawing [ Skip ]
+fast/forms/extrazoom [ Skip ]
 fast/visual-viewport/extrazoom [ Skip ]
 fast/visual-viewport/tiled-drawing [ Skip ]
 swipe [ Skip ]
diff --git a/LayoutTests/fast/forms/extrazoom/edit-text-field-calls-injected-bundle-expected.txt b/LayoutTests/fast/forms/extrazoom/edit-text-field-calls-injected-bundle-expected.txt
new file mode 100644 (file)
index 0000000..1b86503
--- /dev/null
@@ -0,0 +1,7 @@
+TextFieldDidBeginEditing ('')
+TextDidChangeInTextField ('Hello world')
+TextFieldDidEndEditing ('Hello world')
+PASS successfullyParsed is true
+
+TEST COMPLETE
+
diff --git a/LayoutTests/fast/forms/extrazoom/edit-text-field-calls-injected-bundle.html b/LayoutTests/fast/forms/extrazoom/edit-text-field-calls-injected-bundle.html
new file mode 100644 (file)
index 0000000..122ee0e
--- /dev/null
@@ -0,0 +1,37 @@
+<!DOCTYPE html> <!-- webkit-test-runner [ useFlexibleViewport=true ] -->
+<html>
+<meta name="viewport" content="width=device-width">
+<head>
+<script src="../../../resources/js-test.js"></script>
+<script src="../../../resources/ui-helper.js"></script>
+<script>
+doneCount = 0;
+jsTestIsAsync = true;
+
+async function runTest() {
+    if (!window.testRunner) {
+        description(`This test requires WebKitTestRunner.`);
+        return;
+    }
+
+    testRunner.installTextFieldDidBeginEditingCallback(() => debug(`TextFieldDidBeginEditing ('${field.value}')`));
+    testRunner.installTextDidChangeInTextFieldCallback(() => debug(`TextDidChangeInTextField ('${field.value}')`));
+    testRunner.installTextFieldDidEndEditingCallback(() => debug(`TextFieldDidEndEditing ('${field.value}')`));
+
+    await UIHelper.activateAndWaitForInputSessionAt(75, 75);
+    UIHelper.waitForKeyboardToHide().then(checkDone);
+    UIHelper.enterText("Hello world");
+}
+
+function checkDone() {
+    doneCount++;
+    if (doneCount == 3)
+        finishJSTest();
+}
+</script>
+</head>
+
+<body onload="runTest()">
+<input id="field" style="width: 320px; height: 568px;" onchange="checkDone()" onblur="checkDone()"></input>
+</body>
+</html>
index 099df83..fd700f6 100644 (file)
@@ -186,4 +186,11 @@ window.UIHelper = class UIHelper {
             })()`, resolve);
         });
     }
+
+    static enterText(text)
+    {
+        const escapedText = text.replace(/`/g, "\\`");
+        const enterTextScript = `(() => uiController.enterText(\`${escapedText}\`))()`;
+        return new Promise(resolve => testRunner.runUIScript(enterTextScript, resolve));
+    }
 }
index 9aae509..f0f1398 100644 (file)
@@ -1,3 +1,17 @@
+2018-04-20  Wenson Hsieh  <wenson_hsieh@apple.com>
+
+        [Extra zoom mode] Injected bundle form client should be notified when editing text fields
+        https://bugs.webkit.org/show_bug.cgi?id=184822
+        <rdar://problem/38807319>
+
+        Reviewed by Tim Horton.
+
+        Export the constructor and destructor of UserTypingGestureIndicator for use in WebKit (see WebPage.cpp).
+
+        Test: fast/forms/extrazoom/edit-text-field-calls-injected-bundle.html
+
+        * dom/UserTypingGestureIndicator.h:
+
 2018-04-18  Jer Noble  <jer.noble@apple.com>
 
         Don't put build products into WK_ALTERNATE_WEBKIT_SDK_PATH for engineering builds
index 02c2d4c..a2b9119 100644 (file)
@@ -39,8 +39,8 @@ public:
     WEBCORE_EXPORT static bool processingUserTypingGesture();
     WEBCORE_EXPORT static Node* focusedElementAtGestureStart();
 
-    explicit UserTypingGestureIndicator(Frame&);
-    ~UserTypingGestureIndicator();
+    WEBCORE_EXPORT explicit UserTypingGestureIndicator(Frame&);
+    WEBCORE_EXPORT ~UserTypingGestureIndicator();
 
 private:
     bool m_previousProcessingUserTypingGesture;
index b0650c7..bf8c305 100644 (file)
@@ -1,3 +1,28 @@
+2018-04-20  Wenson Hsieh  <wenson_hsieh@apple.com>
+
+        [Extra zoom mode] Injected bundle form client should be notified when editing text fields
+        https://bugs.webkit.org/show_bug.cgi?id=184822
+        <rdar://problem/38807319>
+
+        Reviewed by Tim Horton.
+
+        Fixes the bug by making a couple of tweaks: (1) don't use a separate codepath for inserting text in text inputs,
+        and (2) force a user typing gesture when inserting text using this codepath (i.e. WKTextInputListViewController).
+        Also adds plumbing to enable testing text entry with WKTextInputListViewController in extra zoom mode.
+
+        * UIProcess/API/Cocoa/WKWebView.mm:
+        (-[WKWebView _simulateTextEntered:]):
+        * UIProcess/API/Cocoa/WKWebViewPrivate.h:
+
+        Introduce testing SPI to simulate text entry. Additionally, add a missing availability annotation around testing
+        SPI added in 2017 to help test drag and drop for iOS 11.
+
+        * UIProcess/ios/WKContentViewInteraction.h:
+        * UIProcess/ios/WKContentViewInteraction.mm:
+        (-[WKContentView _simulateTextEntered:]):
+        * WebProcess/WebPage/WebPage.cpp:
+        (WebKit::WebPage::setTextAsync):
+
 2018-04-20  Jeremy Jones  <jeremyj@apple.com>
 
         EnterFullscreen must update the minimum and maximum layout sizes.
index 859bffb..5ed963b 100644 (file)
@@ -6361,6 +6361,11 @@ static WebCore::UserInterfaceLayoutDirection toUserInterfaceLayoutDirection(UISe
     [_contentView _simulateLongPressActionAtLocation:location];
 }
 
+- (void)_simulateTextEntered:(NSString *)text
+{
+    [_contentView _simulateTextEntered:text];
+}
+
 #endif // PLATFORM(IOS)
 
 - (BOOL)_beginBackSwipeForTesting
index 63dd1b8..7781a91 100644 (file)
@@ -401,7 +401,8 @@ typedef NS_OPTIONS(NSUInteger, _WKRectEdge) {
 @property (nonatomic, readonly) NSNumber *_stableStateOverride WK_API_AVAILABLE(ios(10.3));
 
 - (NSDictionary *)_propertiesOfLayerWithID:(unsigned long long)layerID WK_API_AVAILABLE(ios(11.0));
-- (void)_simulateLongPressActionAtLocation:(CGPoint)location;
+- (void)_simulateLongPressActionAtLocation:(CGPoint)location WK_API_AVAILABLE(ios(11.0));
+- (void)_simulateTextEntered:(NSString *)text WK_API_AVAILABLE(ios(WK_IOS_TBA));
 
 @property (nonatomic, readonly) CGRect _dragCaretRect WK_API_AVAILABLE(ios(11.0));
 
index 92c36b4..0291415 100644 (file)
@@ -359,6 +359,7 @@ FOR_EACH_WKCONTENTVIEW_ACTION(DECLARE_WKCONTENTVIEW_ACTION_FOR_WEB_VIEW)
 @interface WKContentView (WKTesting)
 
 - (void)_simulateLongPressActionAtLocation:(CGPoint)location;
+- (void)_simulateTextEntered:(NSString *)text;
 - (void)selectFormAccessoryPickerRow:(NSInteger)rowIndex;
 - (NSDictionary *)_contentsOfUserInterfaceItem:(NSString *)userInterfaceItem;
 
index f5e08bb..cc5a987 100644 (file)
@@ -5460,6 +5460,16 @@ static NSArray<UIItemProvider *> *extractItemProvidersFromDropSession(id <UIDrop
 
 @implementation WKContentView (WKTesting)
 
+- (void)_simulateTextEntered:(NSString *)text
+{
+#if ENABLE(EXTRA_ZOOM_MODE)
+    if ([_presentedFullScreenInputViewController isKindOfClass:[WKTextInputListViewController class]])
+        [(WKTextInputListViewController *)_presentedFullScreenInputViewController.get() enterText:text];
+#else
+    [self insertText:text];
+#endif
+}
+
 - (void)_simulateLongPressActionAtLocation:(CGPoint)location
 {
     RetainPtr<WKContentView> protectedSelf = self;
index 00c5dc0..b84c0eb 100644 (file)
 #include <WebCore/UserInputBridge.h>
 #include <WebCore/UserScript.h>
 #include <WebCore/UserStyleSheet.h>
+#include <WebCore/UserTypingGestureIndicator.h>
 #include <WebCore/VisiblePosition.h>
 #include <WebCore/VisibleUnits.h>
 #include <WebCore/WebGLStateTracker.h>
@@ -4615,15 +4616,11 @@ bool WebPage::shouldUseCustomContentProviderForResponse(const ResourceResponse&
 
 void WebPage::setTextAsync(const String& text)
 {
-    if (is<HTMLInputElement>(m_assistedNode.get())) {
-        downcast<HTMLInputElement>(*m_assistedNode).setValueForUser(text);
-        return;
-    }
-
     auto frame = makeRef(m_page->focusController().focusedOrMainFrame());
     if (!frame->selection().selection().isContentEditable())
         return;
 
+    UserTypingGestureIndicator indicator(frame.get());
     frame->selection().selectAll();
     frame->editor().insertText(text, nullptr, TextEventInputKeyboard);
 }
index ec518db..f43502a 100644 (file)
@@ -1,3 +1,52 @@
+2018-04-20  Wenson Hsieh  <wenson_hsieh@apple.com>
+
+        [Extra zoom mode] Injected bundle form client should be notified when editing text fields
+        https://bugs.webkit.org/show_bug.cgi?id=184822
+        <rdar://problem/38807319>
+
+        Reviewed by Tim Horton.
+
+        Add WebKitTestRunner support for listening to form editing SPI hooks in the injected bundle. The new layout test
+        installs callbacks that listen for "begin editing", "end editing", and "text changed" calls to injected bundle
+        SPI. See other ChangeLogs for more detail.
+
+        * DumpRenderTree/ios/UIScriptControllerIOS.mm:
+        (WTR::UIScriptController::enterText):
+        * TestRunnerShared/UIScriptContext/Bindings/UIScriptController.idl:
+
+        Add UIScriptController support for simulating text entry in the currently focused element.
+
+        * TestRunnerShared/UIScriptContext/UIScriptController.cpp:
+        (WTR::UIScriptController::enterText):
+        * TestRunnerShared/UIScriptContext/UIScriptController.h:
+        * WebKitTestRunner/InjectedBundle/Bindings/TestRunner.idl:
+
+        Add TestRunner bindings for registering injected bundle form client callbacks.
+
+        * WebKitTestRunner/InjectedBundle/InjectedBundle.cpp:
+        (WTR::handleTextDidChangeInTextField):
+        (WTR::handleTextFieldDidBeginEditing):
+        (WTR::handleTextFieldDidEndEditing):
+        (WTR::InjectedBundle::didCreatePage):
+
+        Set the injected bundle form editor client.
+
+        (WTR::InjectedBundle::setUpInjectedBundleClients):
+        (WTR::InjectedBundle::textDidChangeInTextField):
+        (WTR::InjectedBundle::textFieldDidBeginEditing):
+        (WTR::InjectedBundle::textFieldDidEndEditing):
+        * WebKitTestRunner/InjectedBundle/InjectedBundle.h:
+        * WebKitTestRunner/InjectedBundle/TestRunner.cpp:
+        (WTR::TestRunner::installTextDidChangeInTextFieldCallback):
+        (WTR::TestRunner::textDidChangeInTextFieldCallback):
+        (WTR::TestRunner::installTextFieldDidBeginEditingCallback):
+        (WTR::TestRunner::textFieldDidBeginEditingCallback):
+        (WTR::TestRunner::installTextFieldDidEndEditingCallback):
+        (WTR::TestRunner::textFieldDidEndEditingCallback):
+        * WebKitTestRunner/InjectedBundle/TestRunner.h:
+        * WebKitTestRunner/ios/UIScriptControllerIOS.mm:
+        (WTR::UIScriptController::enterText):
+
 2018-04-20  Youenn Fablet  <youenn@apple.com>
 
         WebPage sometimes incorrectly rules out PDF as a mime type that can be showed
index b5506ca..6a90c27 100644 (file)
@@ -135,6 +135,10 @@ void UIScriptController::sendEventStream(JSStringRef eventsJSON, JSValueRef call
 {
 }
 
+void UIScriptController::enterText(JSStringRef)
+{
+}
+
 void UIScriptController::typeCharacterUsingHardwareKeyboard(JSStringRef character, JSValueRef callback)
 {
 }
index 79ec491..d73fd7b 100644 (file)
@@ -58,6 +58,7 @@ interface UIScriptController {
     void stylusUpAtPoint(long x, long y, object callback);
     void stylusTapAtPoint(long x, long y, float azimuthAngle, float altitudeAngle, float pressure, object callback);
 
+    void enterText(DOMString text);
     void typeCharacterUsingHardwareKeyboard(DOMString character, object callback);
     void keyDownUsingHardwareKeyboard(DOMString character, object callback);
     void keyUpUsingHardwareKeyboard(DOMString character, object callback);
index 9a6b71c..83c2f59 100644 (file)
@@ -270,6 +270,10 @@ void UIScriptController::sendEventStream(JSStringRef eventsJSON, JSValueRef call
 {
 }
 
+void UIScriptController::enterText(JSStringRef)
+{
+}
+
 void UIScriptController::typeCharacterUsingHardwareKeyboard(JSStringRef, JSValueRef)
 {
 }
index e266558..54ff4d6 100644 (file)
@@ -84,6 +84,7 @@ public:
 
     void sendEventStream(JSStringRef eventsJSON, JSValueRef callback);
 
+    void enterText(JSStringRef);
     void typeCharacterUsingHardwareKeyboard(JSStringRef character, JSValueRef callback);
     void keyDownUsingHardwareKeyboard(JSStringRef character, JSValueRef callback);
     void keyUpUsingHardwareKeyboard(JSStringRef character, JSValueRef callback);
index 7b1e6b9..7baa854 100644 (file)
@@ -309,6 +309,11 @@ interface TestRunner {
     void statisticsClearThroughWebsiteDataRemoval(object callback);
     void statisticsResetToConsistentState();
 
+    // Injected bundle form client.
+    void installTextDidChangeInTextFieldCallback(object callback);
+    void installTextFieldDidBeginEditingCallback(object callback);
+    void installTextFieldDidEndEditingCallback(object callback);
+
     // Storage Access API
     void setStorageAccessAPIEnabled(boolean enabled);
     void getAllStorageAccessEntries(object callback);
index 14cbabf..6eb3540 100644 (file)
 
 namespace WTR {
 
+static void handleTextDidChangeInTextField(WKBundlePageRef, WKBundleNodeHandleRef, WKBundleFrameRef, const void* context)
+{
+    static_cast<InjectedBundle*>(const_cast<void*>(context))->textDidChangeInTextField();
+}
+
+static void handleTextFieldDidBeginEditing(WKBundlePageRef, WKBundleNodeHandleRef, WKBundleFrameRef, const void* context)
+{
+    static_cast<InjectedBundle*>(const_cast<void*>(context))->textFieldDidBeginEditing();
+}
+
+static void handleTextFieldDidEndEditing(WKBundlePageRef, WKBundleNodeHandleRef, WKBundleFrameRef, const void* context)
+{
+    static_cast<InjectedBundle*>(const_cast<void*>(context))->textFieldDidEndEditing();
+}
+
 InjectedBundle& InjectedBundle::singleton()
 {
     static InjectedBundle& shared = *new InjectedBundle;
@@ -106,6 +121,8 @@ void InjectedBundle::initialize(WKBundleRef bundle, WKTypeRef initializationUser
 void InjectedBundle::didCreatePage(WKBundlePageRef page)
 {
     m_pages.append(std::make_unique<InjectedBundlePage>(page));
+
+    setUpInjectedBundleClients(page);
 }
 
 void InjectedBundle::willDestroyPage(WKBundlePageRef page)
@@ -120,6 +137,24 @@ void InjectedBundle::didInitializePageGroup(WKBundlePageGroupRef pageGroup)
     m_pageGroup = pageGroup;
 }
 
+void InjectedBundle::setUpInjectedBundleClients(WKBundlePageRef page)
+{
+    WKBundlePageFormClientV2 formClient = {
+        { 2, this },
+        handleTextFieldDidBeginEditing,
+        handleTextFieldDidEndEditing,
+        handleTextDidChangeInTextField,
+        0, // textDidChangeInTextArea
+        0, // shouldPerformActionInTextField
+        0, // willSubmitForm
+        0, // willSendSubmitEvent
+        0, // didFocusTextField
+        0, // shouldNotifyOnFormChanges
+        0, // didAssociateFormControls
+    };
+    WKBundlePageSetFormClient(page, &formClient.base);
+}
+
 InjectedBundlePage* InjectedBundle::page() const
 {
     // It might be better to have the UI process send over a reference to the main
@@ -877,4 +912,19 @@ void InjectedBundle::statisticsNotifyObserver()
     WKBundleResourceLoadStatisticsNotifyObserver(m_bundle);
 }
 
+void InjectedBundle::textDidChangeInTextField()
+{
+    m_testRunner->textDidChangeInTextFieldCallback();
+}
+
+void InjectedBundle::textFieldDidBeginEditing()
+{
+    m_testRunner->textFieldDidBeginEditingCallback();
+}
+
+void InjectedBundle::textFieldDidEndEditing()
+{
+    m_testRunner->textFieldDidEndEditingCallback();
+}
+
 } // namespace WTR
index 0432313..f5eef39 100644 (file)
@@ -136,6 +136,10 @@ public:
 
     void statisticsNotifyObserver();
 
+    void textDidChangeInTextField();
+    void textFieldDidBeginEditing();
+    void textFieldDidEndEditing();
+
 private:
     InjectedBundle();
     ~InjectedBundle();
@@ -152,6 +156,8 @@ private:
     void didReceiveMessage(WKStringRef messageName, WKTypeRef messageBody);
     void didReceiveMessageToPage(WKBundlePageRef, WKStringRef messageName, WKTypeRef messageBody);
 
+    void setUpInjectedBundleClients(WKBundlePageRef);
+
     void platformInitialize(WKTypeRef initializationUserData);
     void resetLocalSettings();
 
index 9e7d88b..e62eb93 100644 (file)
@@ -676,6 +676,9 @@ enum {
     AllStorageAccessEntriesCallbackID,
     DidRemoveAllSessionCredentialsCallbackID,
     GetApplicationManifestCallbackID,
+    TextDidChangeInTextFieldCallbackID,
+    TextFieldDidBeginEditingCallbackID,
+    TextFieldDidEndEditingCallbackID,
     FirstUIScriptCallbackID = 100
 };
 
@@ -1823,6 +1826,36 @@ void TestRunner::statisticsResetToConsistentState()
     WKBundlePostSynchronousMessage(InjectedBundle::singleton().bundle(), messageName.get(), 0, nullptr);
 }
 
+void TestRunner::installTextDidChangeInTextFieldCallback(JSValueRef callback)
+{
+    cacheTestRunnerCallback(TextDidChangeInTextFieldCallbackID, callback);
+}
+
+void TestRunner::textDidChangeInTextFieldCallback()
+{
+    callTestRunnerCallback(TextDidChangeInTextFieldCallbackID);
+}
+
+void TestRunner::installTextFieldDidBeginEditingCallback(JSValueRef callback)
+{
+    cacheTestRunnerCallback(TextFieldDidBeginEditingCallbackID, callback);
+}
+
+void TestRunner::textFieldDidBeginEditingCallback()
+{
+    callTestRunnerCallback(TextFieldDidBeginEditingCallbackID);
+}
+
+void TestRunner::installTextFieldDidEndEditingCallback(JSValueRef callback)
+{
+    cacheTestRunnerCallback(TextFieldDidEndEditingCallbackID, callback);
+}
+
+void TestRunner::textFieldDidEndEditingCallback()
+{
+    callTestRunnerCallback(TextFieldDidEndEditingCallbackID);
+}
+
 void TestRunner::setStorageAccessAPIEnabled(bool enabled)
 {
     WKRetainPtr<WKStringRef> messageName(AdoptWK, WKStringCreateWithUTF8CString("SetStorageAccessAPIEnabled"));
index 784f7a3..85bfbcf 100644 (file)
@@ -413,6 +413,14 @@ public:
     void statisticsCallClearThroughWebsiteDataRemovalCallback();
     void statisticsResetToConsistentState();
 
+    // Injected bundle form client.
+    void installTextDidChangeInTextFieldCallback(JSValueRef callback);
+    void textDidChangeInTextFieldCallback();
+    void installTextFieldDidBeginEditingCallback(JSValueRef callback);
+    void textFieldDidBeginEditingCallback();
+    void installTextFieldDidEndEditingCallback(JSValueRef callback);
+    void textFieldDidEndEditingCallback();
+
     // Storage Access API
     void setStorageAccessAPIEnabled(bool);
     void getAllStorageAccessEntries(JSValueRef callback);
index 0546ddf..a727e23 100644 (file)
@@ -331,6 +331,13 @@ void UIScriptController::longPressAtPoint(long x, long y, JSValueRef callback)
     }];
 }
 
+void UIScriptController::enterText(JSStringRef text)
+{
+    TestRunnerWKWebView *webView = TestController::singleton().mainWebView()->platformView();
+    auto textAsCFString = adoptCF(JSStringCopyCFString(kCFAllocatorDefault, text));
+    [webView _simulateTextEntered:(NSString *)textAsCFString.get()];
+}
+
 void UIScriptController::typeCharacterUsingHardwareKeyboard(JSStringRef character, JSValueRef callback)
 {
     unsigned callbackID = m_context->prepareForAsyncTask(callback, CallbackTypeNonPersistent);