[Cocoa] Some fields are not identified as [WKWebProcessPlugInNodeHandle isTextField]
authorcommit-queue@webkit.org <commit-queue@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 9 May 2018 20:31:13 +0000 (20:31 +0000)
committercommit-queue@webkit.org <commit-queue@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 9 May 2018 20:31:13 +0000 (20:31 +0000)
https://bugs.webkit.org/show_bug.cgi?id=185260
<rdar://problem/39290394>

Source/WebKit:

INPUT element are not considered to be text fields when
calling -[WKWebProcessPlugInNodeHandle isTextField]
when they are of type number.

Patch by Richard Houle <rhoule@apple.com> on 2018-05-09
Reviewed by Tim Horton.

* WebProcess/InjectedBundle/DOM/InjectedBundleNodeHandle.cpp:
(WebKit::InjectedBundleNodeHandle::isTextField const):

Tools:

Patch by Richard Houle <rhoule@apple.com> on 2018-05-09
Reviewed by Tim Horton.

* TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj:
* TestWebKitAPI/Tests/WebKitCocoa/InjectedBundleNodeHandleIsTextField.mm: Added.
(-[InjectedBundleNodeHandleIsTextField isTextFieldForHTMLInputType:document:jsContext:]):
(-[InjectedBundleNodeHandleIsTextField webProcessPlugIn:didCreateBrowserContextController:]):
* TestWebKitAPI/Tests/WebKitCocoa/UIDelegate.mm:
(-[InjectedBundleNodeHandleIsTextFieldDelegate webView:runJavaScriptAlertPanelWithMessage:initiatedByFrame:completionHandler:]):

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

Source/WebKit/ChangeLog
Source/WebKit/WebProcess/InjectedBundle/DOM/InjectedBundleNodeHandle.cpp
Tools/ChangeLog
Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj
Tools/TestWebKitAPI/Tests/WebKitCocoa/InjectedBundleNodeHandleIsTextField.mm [new file with mode: 0644]
Tools/TestWebKitAPI/Tests/WebKitCocoa/UIDelegate.mm

index be5b7f4..b334b79 100644 (file)
@@ -1,3 +1,18 @@
+2018-05-09  Richard Houle  <rhoule@apple.com>
+
+        [Cocoa] Some fields are not identified as [WKWebProcessPlugInNodeHandle isTextField]
+        https://bugs.webkit.org/show_bug.cgi?id=185260
+        <rdar://problem/39290394>
+
+        INPUT element are not considered to be text fields when
+        calling -[WKWebProcessPlugInNodeHandle isTextField]
+        when they are of type number.
+
+        Reviewed by Tim Horton.
+
+        * WebProcess/InjectedBundle/DOM/InjectedBundleNodeHandle.cpp:
+        (WebKit::InjectedBundleNodeHandle::isTextField const):
+
 2018-05-09  Youenn Fablet  <youenn@apple.com>
 
         Allow WebResourceLoader to cancel a load served from a service worker
index 117cc21..b7f7439 100644 (file)
@@ -334,7 +334,7 @@ bool InjectedBundleNodeHandle::isTextField() const
     if (!is<HTMLInputElement>(m_node))
         return false;
 
-    return downcast<HTMLInputElement>(m_node.get()).isText();
+    return downcast<HTMLInputElement>(m_node.get()).isTextField();
 }
 
 RefPtr<InjectedBundleNodeHandle> InjectedBundleNodeHandle::htmlTableCellElementCellAbove()
index 3c2c06a..ad3133b 100644 (file)
@@ -1,3 +1,18 @@
+2018-05-09  Richard Houle  <rhoule@apple.com>
+
+        [Cocoa] Some fields are not identified as [WKWebProcessPlugInNodeHandle isTextField]
+        https://bugs.webkit.org/show_bug.cgi?id=185260
+        <rdar://problem/39290394>
+
+        Reviewed by Tim Horton.
+
+        * TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj:
+        * TestWebKitAPI/Tests/WebKitCocoa/InjectedBundleNodeHandleIsTextField.mm: Added.
+        (-[InjectedBundleNodeHandleIsTextField isTextFieldForHTMLInputType:document:jsContext:]):
+        (-[InjectedBundleNodeHandleIsTextField webProcessPlugIn:didCreateBrowserContextController:]):
+        * TestWebKitAPI/Tests/WebKitCocoa/UIDelegate.mm:
+        (-[InjectedBundleNodeHandleIsTextFieldDelegate webView:runJavaScriptAlertPanelWithMessage:initiatedByFrame:completionHandler:]):
+
 2018-05-09  Thibault Saunier  <tsaunier@igalia.com>
 
         [tests][GStreamer]: Pass USE_PLAYBIN3 to the tests subprocess
index 2c67684..ce7eab2 100644 (file)
                7673499D1930C5BB00E44DF9 /* StopLoadingDuringDidFailProvisionalLoad_bundle.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 7673499A1930182E00E44DF9 /* StopLoadingDuringDidFailProvisionalLoad_bundle.cpp */; };
                76E182DD1547569100F1FADD /* WillSendSubmitEvent_Bundle.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 76E182DC1547569100F1FADD /* WillSendSubmitEvent_Bundle.cpp */; };
                76E182DF154767E600F1FADD /* auto-submitting-form.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = 76E182DE15475A8300F1FADD /* auto-submitting-form.html */; };
+               79C5D431209D768300F1E7CA /* InjectedBundleNodeHandleIsTextField.mm in Sources */ = {isa = PBXBuildFile; fileRef = 79C5D430209D768300F1E7CA /* InjectedBundleNodeHandleIsTextField.mm */; };
                7A010BCB1D877C0500EDE72A /* CoreGraphics.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 7A010BCA1D877C0500EDE72A /* CoreGraphics.framework */; };
                7A010BCD1D877C0D00EDE72A /* QuartzCore.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 7A010BCC1D877C0D00EDE72A /* QuartzCore.framework */; };
                7A0509411FB9F06400B33FB8 /* JSONValue.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 7A0509401FB9F04400B33FB8 /* JSONValue.cpp */; };
                76E182D91547550100F1FADD /* WillSendSubmitEvent.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = WillSendSubmitEvent.cpp; sourceTree = "<group>"; };
                76E182DC1547569100F1FADD /* WillSendSubmitEvent_Bundle.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = WillSendSubmitEvent_Bundle.cpp; sourceTree = "<group>"; };
                76E182DE15475A8300F1FADD /* auto-submitting-form.html */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.html; path = "auto-submitting-form.html"; sourceTree = "<group>"; };
+               79C5D430209D768300F1E7CA /* InjectedBundleNodeHandleIsTextField.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = InjectedBundleNodeHandleIsTextField.mm; sourceTree = "<group>"; };
                7A010BCA1D877C0500EDE72A /* CoreGraphics.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = CoreGraphics.framework; path = System/Library/Frameworks/CoreGraphics.framework; sourceTree = SDKROOT; };
                7A010BCC1D877C0D00EDE72A /* QuartzCore.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = QuartzCore.framework; path = System/Library/Frameworks/QuartzCore.framework; sourceTree = SDKROOT; };
                7A0509401FB9F04400B33FB8 /* JSONValue.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = JSONValue.cpp; sourceTree = "<group>"; };
                                57599E201F07191700A3FB8C /* IndexedDBStructuredCloneBackwardCompatibility.mm */,
                                5198A23F1EA7E595008910B7 /* InitialWarmedProcessUsed.mm */,
                                2DB0232E1E4E871800707123 /* InteractionDeadlockAfterCrash.mm */,
+                               79C5D430209D768300F1E7CA /* InjectedBundleNodeHandleIsTextField.mm */,
                                5C69BDD41F82A7EB000F4F4B /* JavaScriptDuringNavigation.mm */,
                                C25CCA051E51380B0026CB8A /* LineBreaking.mm */,
                                37D36ED61AF42ECD00BAF5D9 /* LoadAlternateHTMLString.mm */,
                                A13EBBB01B87436F00097110 /* BundleParametersPlugIn.mm in Sources */,
                                37A709AF1E3EA97E00CA5969 /* BundleRangeHandlePlugIn.mm in Sources */,
                                1C2B81831C891F0900A5529F /* CancelFontSubresourcePlugIn.mm in Sources */,
+                               79C5D431209D768300F1E7CA /* InjectedBundleNodeHandleIsTextField.mm in Sources */,
                                5CB18BA81F5645E300EE23C4 /* ClickAutoFillButton.mm in Sources */,
                                A14FC58B1B89927100D107EB /* ContentFilteringPlugIn.mm in Sources */,
                                CEA7F57D2089624B0078EF6E /* DidResignInputElementStrongPasswordAppearance.mm in Sources */,
diff --git a/Tools/TestWebKitAPI/Tests/WebKitCocoa/InjectedBundleNodeHandleIsTextField.mm b/Tools/TestWebKitAPI/Tests/WebKitCocoa/InjectedBundleNodeHandleIsTextField.mm
new file mode 100644 (file)
index 0000000..a512c3d
--- /dev/null
@@ -0,0 +1,99 @@
+/*
+ * Copyright (C) 2018 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.
+ */
+
+#import "config.h"
+
+#if WK_API_ENABLED
+
+#import <WebKit/WKDOMDocument.h>
+#import <WebKit/WKDOMElement.h>
+#import <WebKit/WKDOMNodePrivate.h>
+#import <WebKit/WKWebProcessPlugIn.h>
+#import <WebKit/WKWebProcessPlugInBrowserContextControllerPrivate.h>
+#import <WebKit/WKWebProcessPlugInFrame.h>
+#import <WebKit/WKWebProcessPlugInNodeHandlePrivate.h>
+#import <WebKit/WKWebProcessPlugInScriptWorld.h>
+
+@interface InjectedBundleNodeHandleIsTextField : NSObject <WKWebProcessPlugIn>
+@end
+
+@implementation InjectedBundleNodeHandleIsTextField
+
+- (void)verifyTextFieldForHTMLInputType:(NSString *)htmlInputType document:(WKDOMDocument *)document jsContext:(JSContext *)jsContext expectedResult:(BOOL)expectedResult failedInputTypes:(NSMutableArray <NSString *> *)failedInputTypes
+{
+    WKDOMElement *inputElement = [document createElement:@"input"];
+    [inputElement setAttribute:@"type" value:htmlInputType];
+    [[document body] appendChild:inputElement];
+
+    auto *jsValue = [jsContext evaluateScript:@"document.querySelector('input')"];
+    auto* nodeHandle = [WKWebProcessPlugInNodeHandle nodeHandleWithJSValue:jsValue inContext:jsContext];
+    if ([nodeHandle isTextField] != expectedResult)
+        [failedInputTypes addObject:htmlInputType];
+
+    [[document body] removeChild:inputElement];
+}
+
+- (void)webProcessPlugIn:(WKWebProcessPlugInController *)plugInController didCreateBrowserContextController:(WKWebProcessPlugInBrowserContextController *)browserContextController
+{
+    WKDOMDocument *document = [browserContextController mainFrameDocument];
+    auto *jsContext = [[browserContextController mainFrame] jsContextForWorld:[WKWebProcessPlugInScriptWorld normalWorld]];
+
+    NSMutableArray <NSString *> *failedInputTypes = [NSMutableArray array];
+
+    [self verifyTextFieldForHTMLInputType:@"date" document:document jsContext:jsContext expectedResult:YES failedInputTypes:failedInputTypes];
+    [self verifyTextFieldForHTMLInputType:@"datetime" document:document jsContext:jsContext expectedResult:YES failedInputTypes:failedInputTypes];
+    [self verifyTextFieldForHTMLInputType:@"datetime-local" document:document jsContext:jsContext expectedResult:YES failedInputTypes:failedInputTypes];
+    [self verifyTextFieldForHTMLInputType:@"email" document:document jsContext:jsContext expectedResult:YES failedInputTypes:failedInputTypes];
+    [self verifyTextFieldForHTMLInputType:@"month" document:document jsContext:jsContext expectedResult:YES failedInputTypes:failedInputTypes];
+    [self verifyTextFieldForHTMLInputType:@"number" document:document jsContext:jsContext expectedResult:YES failedInputTypes:failedInputTypes];
+    [self verifyTextFieldForHTMLInputType:@"password" document:document jsContext:jsContext expectedResult:YES failedInputTypes:failedInputTypes];
+    [self verifyTextFieldForHTMLInputType:@"search" document:document jsContext:jsContext expectedResult:YES failedInputTypes:failedInputTypes];
+    [self verifyTextFieldForHTMLInputType:@"tel" document:document jsContext:jsContext expectedResult:YES failedInputTypes:failedInputTypes];
+    [self verifyTextFieldForHTMLInputType:@"text" document:document jsContext:jsContext expectedResult:YES failedInputTypes:failedInputTypes];
+    [self verifyTextFieldForHTMLInputType:@"time" document:document jsContext:jsContext expectedResult:YES failedInputTypes:failedInputTypes];
+    [self verifyTextFieldForHTMLInputType:@"url" document:document jsContext:jsContext expectedResult:YES failedInputTypes:failedInputTypes];
+    [self verifyTextFieldForHTMLInputType:@"week" document:document jsContext:jsContext expectedResult:YES failedInputTypes:failedInputTypes];
+
+    [self verifyTextFieldForHTMLInputType:@"button" document:document jsContext:jsContext expectedResult:NO failedInputTypes:failedInputTypes];
+    [self verifyTextFieldForHTMLInputType:@"color" document:document jsContext:jsContext expectedResult:NO failedInputTypes:failedInputTypes];
+    [self verifyTextFieldForHTMLInputType:@"file" document:document jsContext:jsContext expectedResult:NO failedInputTypes:failedInputTypes];
+    [self verifyTextFieldForHTMLInputType:@"hidden" document:document jsContext:jsContext expectedResult:NO failedInputTypes:failedInputTypes];
+    [self verifyTextFieldForHTMLInputType:@"image" document:document jsContext:jsContext expectedResult:NO failedInputTypes:failedInputTypes];
+    [self verifyTextFieldForHTMLInputType:@"radio" document:document jsContext:jsContext expectedResult:NO failedInputTypes:failedInputTypes];
+    [self verifyTextFieldForHTMLInputType:@"range" document:document jsContext:jsContext expectedResult:NO failedInputTypes:failedInputTypes];
+    [self verifyTextFieldForHTMLInputType:@"reset" document:document jsContext:jsContext expectedResult:NO failedInputTypes:failedInputTypes];
+    [self verifyTextFieldForHTMLInputType:@"submit" document:document jsContext:jsContext expectedResult:NO failedInputTypes:failedInputTypes];
+
+    if (!failedInputTypes.count) {
+        [[[browserContextController mainFrame] jsContextForWorld:[WKWebProcessPlugInScriptWorld normalWorld]] evaluateScript:@"alert('isTextField success')"];
+        return;
+    }
+
+    [[[browserContextController mainFrame] jsContextForWorld:[WKWebProcessPlugInScriptWorld normalWorld]] evaluateScript:[NSString stringWithFormat:@"alert('isTextField failed for %@')", [failedInputTypes componentsJoinedByString:@", "]]];
+}
+
+@end
+
+#endif // WK_API_ENABLED
index 722d623..d43be87 100644 (file)
@@ -627,6 +627,30 @@ TEST(WebKit, AutoFillAvailable)
     TestWebKitAPI::Util::run(&done);
 }
 
+@interface InjectedBundleNodeHandleIsTextFieldDelegate : NSObject <WKUIDelegatePrivate>
+@end
+
+@implementation InjectedBundleNodeHandleIsTextFieldDelegate
+
+- (void)webView:(WKWebView *)webView runJavaScriptAlertPanelWithMessage:(NSString *)message initiatedByFrame:(WKFrameInfo *)frame completionHandler:(void (^)())completionHandler
+{
+    completionHandler();
+    ASSERT_STREQ(message.UTF8String, "isTextField success");
+    done = true;
+}
+
+@end
+
+TEST(WebKit, InjectedBundleNodeHandleIsTextField)
+{
+    WKWebViewConfiguration *configuration = [WKWebViewConfiguration _test_configurationWithTestPlugInClassName:@"InjectedBundleNodeHandleIsTextField"];
+
+    auto webView = adoptNS([[TestWKWebView alloc] initWithFrame:CGRectMake(0, 0, 800, 600) configuration:configuration]);
+    auto delegate = adoptNS([[InjectedBundleNodeHandleIsTextFieldDelegate alloc] init]);
+    [webView setUIDelegate:delegate.get()];
+    TestWebKitAPI::Util::run(&done);
+}
+
 @interface PinnedStateObserver : NSObject
 @end