Title: [206135] trunk
Revision
206135
Author
wenson_hs...@apple.com
Date
2016-09-19 18:02:40 -0700 (Mon, 19 Sep 2016)

Log Message

Add a unit test covering <https://trac.webkit.org/changeset/205983>
https://bugs.webkit.org/show_bug.cgi?id=162112

Reviewed by Beth Dakin.

Source/WebKit2:

Adds some a test support method as SPI on WKWebView to determine whether to request candidates. See
Tools/ChangeLog for more details.

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

Tools:

Adds a new unit test covering the changes in r205983 along with the infrastructure needed to support it. Also
further refactors the TestWKWebView used by VideoControlsManager and WKWebViewCandidateTests so that in both
cases, we add the WKWebView to a visible key window, and when sending a mouse down event, we propagate the event
at the window level rather than the view level, allowing greater flexibility to simulate behaviors such as
pressure-sensitive events that are needed for the new test.

Also rewrites currently disabled unit tests in CandidateTests as WebKit2 unit tests in WKWebViewCandidateTests,
checking whether or not to should be requesting candidates in password and non-password fields.

* TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj:
* TestWebKitAPI/Tests/WebKit2Cocoa/VideoControlsManager.mm:
(TestWebKitAPI::setUpWebViewForTestingVideoControlsManager):
(TestWebKitAPI::TEST):
* TestWebKitAPI/Tests/WebKit2Cocoa/WKWebViewCandidateTests.mm:
(-[CandidateTestWebView typeString:inputMessage:]):
(+[CandidateTestWebView setUpWithFrame:testPage:]):
* TestWebKitAPI/Tests/WebKit2Cocoa/large-input-field-focus-onload.html: Added.
* TestWebKitAPI/Tests/WebKit2Cocoa/text-and-password-inputs.html: Added.
* TestWebKitAPI/mac/TestWKWebViewMac.h:
* TestWebKitAPI/mac/TestWKWebViewMac.mm:
(__simulated_forceClickAssociatedEventsMask):
(-[TestWKWebViewHostWindow _mouseDownAtPoint:simulatePressure:]):
(-[TestWKWebView initWithFrame:]):
(-[TestWKWebView initWithFrame:configuration:]):
(-[TestWKWebView _setUpTestWindow:]):
(-[TestWKWebView mouseDownAtPoint:simulatePressure:]):
(-[TestWKWebView typeCharacter:]):
(-[TestWKWebView mouseDownAtPoint:]): Deleted.

Modified Paths

Added Paths

Diff

Modified: trunk/Source/WebKit2/ChangeLog (206134 => 206135)


--- trunk/Source/WebKit2/ChangeLog	2016-09-20 00:48:39 UTC (rev 206134)
+++ trunk/Source/WebKit2/ChangeLog	2016-09-20 01:02:40 UTC (rev 206135)
@@ -1,3 +1,18 @@
+2016-09-19  Wenson Hsieh  <wenson_hs...@apple.com>
+
+        Add a unit test covering <https://trac.webkit.org/changeset/205983>
+        https://bugs.webkit.org/show_bug.cgi?id=162112
+
+        Reviewed by Beth Dakin.
+
+        Adds some a test support method as SPI on WKWebView to determine whether to request candidates. See
+        Tools/ChangeLog for more details.
+
+        * UIProcess/API/Cocoa/WKWebView.mm:
+        (-[WKWebView _shouldRequestCandidates]):
+        (-[WKWebView _forceRequestCandidates]): Deleted.
+        * UIProcess/API/Cocoa/WKWebViewPrivate.h:
+
 2016-09-19  Anders Carlsson  <ander...@apple.com>
 
         Suppress _javascript_ prompts early on in certain cases

Modified: trunk/Source/WebKit2/UIProcess/API/Cocoa/WKWebView.mm (206134 => 206135)


--- trunk/Source/WebKit2/UIProcess/API/Cocoa/WKWebView.mm	2016-09-20 00:48:39 UTC (rev 206134)
+++ trunk/Source/WebKit2/UIProcess/API/Cocoa/WKWebView.mm	2016-09-20 01:02:40 UTC (rev 206135)
@@ -4586,6 +4586,11 @@
 {
     _impl->forceRequestCandidatesForTesting();
 }
+
+- (BOOL)_shouldRequestCandidates
+{
+    return _impl->shouldRequestCandidates();
+}
 #endif // PLATFORM(MAC)
 
 // Execute the supplied block after the next transaction from the WebProcess.

Modified: trunk/Source/WebKit2/UIProcess/API/Cocoa/WKWebViewPrivate.h (206134 => 206135)


--- trunk/Source/WebKit2/UIProcess/API/Cocoa/WKWebViewPrivate.h	2016-09-20 00:48:39 UTC (rev 206134)
+++ trunk/Source/WebKit2/UIProcess/API/Cocoa/WKWebViewPrivate.h	2016-09-20 01:02:40 UTC (rev 206135)
@@ -277,6 +277,7 @@
 - (void)_didHandleAcceptedCandidate WK_API_AVAILABLE(macosx(WK_MAC_TBA));
 - (void)_forceRequestCandidates WK_API_AVAILABLE(macosx(WK_MAC_TBA));
 - (void)_didUpdateCandidateListVisibility:(BOOL)visible WK_API_AVAILABLE(macosx(WK_MAC_TBA));
+@property (nonatomic, readonly) BOOL _shouldRequestCandidates WK_API_AVAILABLE(macosx(WK_MAC_TBA));
 #endif
 
 - (void)_doAfterNextPresentationUpdate:(void (^)(void))updateBlock WK_API_AVAILABLE(macosx(10.12), ios(10.0));

Modified: trunk/Tools/ChangeLog (206134 => 206135)


--- trunk/Tools/ChangeLog	2016-09-20 00:48:39 UTC (rev 206134)
+++ trunk/Tools/ChangeLog	2016-09-20 01:02:40 UTC (rev 206135)
@@ -1,3 +1,39 @@
+2016-09-19  Wenson Hsieh  <wenson_hs...@apple.com>
+
+        Add a unit test covering <https://trac.webkit.org/changeset/205983>
+        https://bugs.webkit.org/show_bug.cgi?id=162112
+
+        Reviewed by Beth Dakin.
+
+        Adds a new unit test covering the changes in r205983 along with the infrastructure needed to support it. Also
+        further refactors the TestWKWebView used by VideoControlsManager and WKWebViewCandidateTests so that in both
+        cases, we add the WKWebView to a visible key window, and when sending a mouse down event, we propagate the event
+        at the window level rather than the view level, allowing greater flexibility to simulate behaviors such as
+        pressure-sensitive events that are needed for the new test.
+
+        Also rewrites currently disabled unit tests in CandidateTests as WebKit2 unit tests in WKWebViewCandidateTests,
+        checking whether or not to should be requesting candidates in password and non-password fields.
+
+        * TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj:
+        * TestWebKitAPI/Tests/WebKit2Cocoa/VideoControlsManager.mm:
+        (TestWebKitAPI::setUpWebViewForTestingVideoControlsManager):
+        (TestWebKitAPI::TEST):
+        * TestWebKitAPI/Tests/WebKit2Cocoa/WKWebViewCandidateTests.mm:
+        (-[CandidateTestWebView typeString:inputMessage:]):
+        (+[CandidateTestWebView setUpWithFrame:testPage:]):
+        * TestWebKitAPI/Tests/WebKit2Cocoa/large-input-field-focus-onload.html: Added.
+        * TestWebKitAPI/Tests/WebKit2Cocoa/text-and-password-inputs.html: Added.
+        * TestWebKitAPI/mac/TestWKWebViewMac.h:
+        * TestWebKitAPI/mac/TestWKWebViewMac.mm:
+        (__simulated_forceClickAssociatedEventsMask):
+        (-[TestWKWebViewHostWindow _mouseDownAtPoint:simulatePressure:]):
+        (-[TestWKWebView initWithFrame:]):
+        (-[TestWKWebView initWithFrame:configuration:]):
+        (-[TestWKWebView _setUpTestWindow:]):
+        (-[TestWKWebView mouseDownAtPoint:simulatePressure:]):
+        (-[TestWKWebView typeCharacter:]):
+        (-[TestWKWebView mouseDownAtPoint:]): Deleted.
+
 2016-09-19  Alex Christensen  <achristen...@webkit.org>
 
         URLParser can read memory out of bounds

Modified: trunk/Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj (206134 => 206135)


--- trunk/Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj	2016-09-20 00:48:39 UTC (rev 206134)
+++ trunk/Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj	2016-09-20 01:02:40 UTC (rev 206135)
@@ -75,6 +75,7 @@
 		2E691AF31D79E75E00129407 /* large-video-playing-scroll-away.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = 2E691AF21D79E75400129407 /* large-video-playing-scroll-away.html */; };
 		2E7765CD16C4D80A00BA2BB1 /* mainIOS.mm in Sources */ = {isa = PBXBuildFile; fileRef = 2E7765CC16C4D80A00BA2BB1 /* mainIOS.mm */; };
 		2E7765CF16C4D81100BA2BB1 /* mainMac.mm in Sources */ = {isa = PBXBuildFile; fileRef = 2E7765CE16C4D81100BA2BB1 /* mainMac.mm */; };
+		2E9896151D8F093800739892 /* text-and-password-inputs.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = 2E9896141D8F092B00739892 /* text-and-password-inputs.html */; };
 		2EFF06C31D88621E0004BB30 /* large-video-offscreen.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = 2EFF06C21D8862120004BB30 /* large-video-offscreen.html */; };
 		2EFF06C51D8867760004BB30 /* change-video-source-on-click.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = 2EFF06C41D8867700004BB30 /* change-video-source-on-click.html */; };
 		2EFF06C71D886A580004BB30 /* change-video-source-on-end.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = 2EFF06C61D886A560004BB30 /* change-video-source-on-end.html */; };
@@ -473,6 +474,7 @@
 		CEBABD491B71687C0051210A /* should-open-external-schemes.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = CEBABD481B71687C0051210A /* should-open-external-schemes.html */; };
 		E1220DCA155B28AA0013E2FC /* MemoryCacheDisableWithinResourceLoadDelegate.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = E1220DC9155B287D0013E2FC /* MemoryCacheDisableWithinResourceLoadDelegate.html */; };
 		E194E1BD177E53C7009C4D4E /* StopLoadingFromDidReceiveResponse.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = E194E1BC177E534A009C4D4E /* StopLoadingFromDidReceiveResponse.html */; };
+		F42DA5161D8CEFE400336F40 /* large-input-field-focus-onload.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = F42DA5151D8CEFDB00336F40 /* large-input-field-focus-onload.html */; };
 		F4F405BC1D4C0D1C007A9707 /* full-size-autoplaying-video-with-audio.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = F4F405BA1D4C0CF8007A9707 /* full-size-autoplaying-video-with-audio.html */; };
 		F4F405BD1D4C0D1C007A9707 /* skinny-autoplaying-video-with-audio.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = F4F405BB1D4C0CF8007A9707 /* skinny-autoplaying-video-with-audio.html */; };
 		F660AA1115A5F631003A1243 /* GetInjectedBundleInitializationUserDataCallback_Bundle.cpp in Sources */ = {isa = PBXBuildFile; fileRef = F660AA0F15A5F624003A1243 /* GetInjectedBundleInitializationUserDataCallback_Bundle.cpp */; };
@@ -544,6 +546,8 @@
 			dstPath = TestWebKitAPI.resources;
 			dstSubfolderSpec = 7;
 			files = (
+				2E9896151D8F093800739892 /* text-and-password-inputs.html in Copy Resources */,
+				F42DA5161D8CEFE400336F40 /* large-input-field-focus-onload.html in Copy Resources */,
 				2EFF06CD1D8A429A0004BB30 /* input-field-in-scrollable-document.html in Copy Resources */,
 				2EFF06C71D886A580004BB30 /* change-video-source-on-end.html in Copy Resources */,
 				2EFF06C51D8867760004BB30 /* change-video-source-on-click.html in Copy Resources */,
@@ -790,6 +794,7 @@
 		2E691AF21D79E75400129407 /* large-video-playing-scroll-away.html */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.html; path = "large-video-playing-scroll-away.html"; sourceTree = "<group>"; };
 		2E7765CC16C4D80A00BA2BB1 /* mainIOS.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = mainIOS.mm; sourceTree = "<group>"; };
 		2E7765CE16C4D81100BA2BB1 /* mainMac.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = mainMac.mm; sourceTree = "<group>"; };
+		2E9896141D8F092B00739892 /* text-and-password-inputs.html */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.html; path = "text-and-password-inputs.html"; sourceTree = "<group>"; };
 		2EFF06C21D8862120004BB30 /* large-video-offscreen.html */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.html; path = "large-video-offscreen.html"; sourceTree = "<group>"; };
 		2EFF06C41D8867700004BB30 /* change-video-source-on-click.html */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.html; path = "change-video-source-on-click.html"; sourceTree = "<group>"; };
 		2EFF06C61D886A560004BB30 /* change-video-source-on-end.html */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.html; path = "change-video-source-on-end.html"; sourceTree = "<group>"; };
@@ -1178,6 +1183,7 @@
 		E4A757D3178AEA5B00B5D7A4 /* Deque.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = Deque.cpp; sourceTree = "<group>"; };
 		E4C9ABC71B3DB1710040A987 /* RunLoop.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = RunLoop.cpp; sourceTree = "<group>"; };
 		F3FC3EE213678B7300126A65 /* libgtest.a */ = {isa = PBXFileReference; lastKnownFileType = archive.ar; path = libgtest.a; sourceTree = BUILT_PRODUCTS_DIR; };
+		F42DA5151D8CEFDB00336F40 /* large-input-field-focus-onload.html */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.html; name = "large-input-field-focus-onload.html"; path = "Tests/WebKit2Cocoa/large-input-field-focus-onload.html"; sourceTree = SOURCE_ROOT; };
 		F4F405BA1D4C0CF8007A9707 /* full-size-autoplaying-video-with-audio.html */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.html; path = "full-size-autoplaying-video-with-audio.html"; sourceTree = "<group>"; };
 		F4F405BB1D4C0CF8007A9707 /* skinny-autoplaying-video-with-audio.html */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.html; path = "skinny-autoplaying-video-with-audio.html"; sourceTree = "<group>"; };
 		F660AA0C15A5F061003A1243 /* GetInjectedBundleInitializationUserDataCallback.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = GetInjectedBundleInitializationUserDataCallback.cpp; sourceTree = "<group>"; };
@@ -1473,6 +1479,7 @@
 		A16F66B81C40E9E100BD4D24 /* Resources */ = {
 			isa = PBXGroup;
 			children = (
+				2E9896141D8F092B00739892 /* text-and-password-inputs.html */,
 				2EFF06CC1D8A42910004BB30 /* input-field-in-scrollable-document.html */,
 				2EFF06C61D886A560004BB30 /* change-video-source-on-end.html */,
 				2EFF06C41D8867700004BB30 /* change-video-source-on-click.html */,
@@ -1917,6 +1924,7 @@
 		C07E6CB013FD737C0038B22B /* Resources */ = {
 			isa = PBXGroup;
 			children = (
+				F42DA5151D8CEFDB00336F40 /* large-input-field-focus-onload.html */,
 				379028B814FABE49007E6B43 /* acceptsFirstMouse.html */,
 				B55F11B9151916E600915916 /* Ahem.ttf */,
 				B55F11B01517A2C400915916 /* attributedStringCustomFont.html */,

Modified: trunk/Tools/TestWebKitAPI/Tests/WebKit2Cocoa/VideoControlsManager.mm (206134 => 206135)


--- trunk/Tools/TestWebKitAPI/Tests/WebKit2Cocoa/VideoControlsManager.mm	2016-09-20 00:48:39 UTC (rev 206134)
+++ trunk/Tools/TestWebKitAPI/Tests/WebKit2Cocoa/VideoControlsManager.mm	2016-09-20 01:02:40 UTC (rev 206135)
@@ -121,11 +121,7 @@
 {
     RetainPtr<WKWebViewConfiguration> configuration = adoptNS([[WKWebViewConfiguration alloc] init]);
     configuration.get().mediaTypesRequiringUserActionForPlayback = WKAudiovisualMediaTypeNone;
-    RetainPtr<VideoControlsManagerTestWebView> webView = adoptNS([[VideoControlsManagerTestWebView alloc] initWithFrame:frame configuration:configuration.get()]);
-    RetainPtr<NSWindow> window = adoptNS([[NSWindow alloc] initWithContentRect:[webView frame] styleMask:NSBorderlessWindowMask backing:NSBackingStoreBuffered defer:NO]);
-    [[window contentView] addSubview:webView.get()];
-
-    return webView;
+    return adoptNS([[VideoControlsManagerTestWebView alloc] initWithFrame:frame configuration:configuration.get()]);
 }
 
 TEST(VideoControlsManager, VideoControlsManagerSingleLargeVideo)
@@ -210,7 +206,7 @@
     [webView loadTestPageNamed:@"large-videos-autoplaying-click-to-pause"];
     [webView waitForPageToLoadWithAutoplayingVideos:2];
 
-    [webView mouseDownAtPoint:clickPoint];
+    [webView mouseDownAtPoint:clickPoint simulatePressure:YES];
 
     __block bool firstVideoPaused = false;
     __block bool secondVideoPaused = false;
@@ -221,7 +217,7 @@
             secondVideoPaused = true;
         } else {
             EXPECT_TRUE([controlledElementID isEqualToString:@"first"]);
-            [webView mouseDownAtPoint:clickPoint];
+            [webView mouseDownAtPoint:clickPoint simulatePressure:YES];
         }
         firstVideoPaused = true;
     }];
@@ -259,7 +255,7 @@
     [webView loadTestPageNamed:@"autoplaying-video-with-audio"];
     [webView waitForPageToLoadWithAutoplayingVideos:1];
 
-    [webView mouseDownAtPoint:NSMakePoint(50, 50)];
+    [webView mouseDownAtPoint:NSMakePoint(50, 50) simulatePressure:YES];
     [webView expectControlsManager:YES afterReceivingMessage:@"paused"];
 }
 
@@ -291,7 +287,7 @@
 
     [webView loadTestPageNamed:@"large-video-hides-controls-after-seek-to-end"];
     [webView waitForPageToLoadWithAutoplayingVideos:1];
-    [webView mouseDownAtPoint:NSMakePoint(50, 50)];
+    [webView mouseDownAtPoint:NSMakePoint(50, 50) simulatePressure:YES];
 
     // We expect there to be media controls, since this is a user gestured seek to the end.
     // This is akin to seeking to the end by scrubbing in the controls.
@@ -342,7 +338,7 @@
     RetainPtr<VideoControlsManagerTestWebView*> webView = setUpWebViewForTestingVideoControlsManager(NSMakeRect(0, 0, 1024, 768));
 
     [webView loadTestPageNamed:@"large-video-offscreen"];
-    [webView expectControlsManager:NO afterReceivingMessage:@"moved"];
+    [webView waitForMediaControlsToHide];
 }
 
 TEST(VideoControlsManager, VideoControlsManagerKeepsControlsStableDuringSrcChangeOnClick)
@@ -351,7 +347,7 @@
 
     [webView loadTestPageNamed:@"change-video-source-on-click"];
     [webView waitForPageToLoadWithAutoplayingVideos:1];
-    [webView mouseDownAtPoint:NSMakePoint(400, 300)];
+    [webView mouseDownAtPoint:NSMakePoint(400, 300) simulatePressure:YES];
 
     [webView expectControlsManager:YES afterReceivingMessage:@"changed"];
 }

Modified: trunk/Tools/TestWebKitAPI/Tests/WebKit2Cocoa/WKWebViewCandidateTests.mm (206134 => 206135)


--- trunk/Tools/TestWebKitAPI/Tests/WebKit2Cocoa/WKWebViewCandidateTests.mm	2016-09-20 00:48:39 UTC (rev 206134)
+++ trunk/Tools/TestWebKitAPI/Tests/WebKit2Cocoa/WKWebViewCandidateTests.mm	2016-09-20 01:02:40 UTC (rev 206135)
@@ -30,6 +30,7 @@
 #import "PlatformUtilities.h"
 #import "TestWKWebViewMac.h"
 
+#import <Carbon/Carbon.h>
 #import <WebKit/WebKitPrivate.h>
 
 static NSString *GetInputValueJSExpression = @"document.querySelector('input').value";
@@ -112,27 +113,41 @@
         _candidateListVisibilityChangeCount++;
 }
 
+- (void)typeString:(NSString *)string inputMessage:(NSString *)inputMessage
+{
+    for (uint64_t i = 0; i < string.length; ++i) {
+        dispatch_async(dispatch_get_main_queue(), ^()
+        {
+            [self typeCharacter:[string characterAtIndex:i]];
+        });
+        [self waitForMessage:inputMessage];
+    }
+}
+
++ (instancetype)setUpWithFrame:(NSRect)frame testPage:(NSString *)testPageName
+{
+    CandidateTestWebView *wkWebView = [[CandidateTestWebView alloc] initWithFrame:frame];
+
+    [wkWebView loadTestPageNamed:testPageName];
+    [wkWebView waitForMessage:@"focused"];
+    [wkWebView _forceRequestCandidates];
+
+    return wkWebView;
+}
+
 @end
 
 TEST(WKWebViewCandidateTests, SoftSpaceReplacementAfterCandidateInsertionWithoutReplacement)
 {
-    CandidateTestWebView *wkWebView = [[CandidateTestWebView alloc] initWithFrame:NSMakeRect(0, 0, 800, 600)];
+    CandidateTestWebView *wkWebView = [CandidateTestWebView setUpWithFrame:NSMakeRect(0, 0, 800, 600) testPage:@"input-field-in-scrollable-document"];
 
-    NSURL *contentURL = [[NSBundle mainBundle] URLForResource:@"input-field-in-scrollable-document" withExtension:@"html" subdirectory:@"TestWebKitAPI.resources"];
-    [wkWebView loadRequest:[NSURLRequest requestWithURL:contentURL]];
-
-    [wkWebView waitForMessage:@"focused"];
-    [wkWebView _forceRequestCandidates];
     [wkWebView insertCandidatesAndWaitForResponse:@"apple " range:NSMakeRange(0, 0)];
-
     EXPECT_TRUE([[wkWebView stringByEvaluatingJavaScript:GetInputValueJSExpression] isEqualToString:@"apple "]);
 
     [wkWebView expectCandidateListVisibilityUpdates:0 whenPerformingActions:^()
     {
-        [wkWebView typeCharacter:' '];
-        [wkWebView waitForMessage:@"input"];
+        [wkWebView typeString:@" " inputMessage:@"input"];
     }];
-
     EXPECT_TRUE([[wkWebView stringByEvaluatingJavaScript:GetInputValueJSExpression] isEqualToString:@"apple "]);
     EXPECT_EQ([[wkWebView stringByEvaluatingJavaScript:GetDocumentScrollTopJSExpression] doubleValue], 0);
 }
@@ -139,54 +154,93 @@
 
 TEST(WKWebViewCandidateTests, InsertCharactersAfterCandidateInsertionWithSoftSpace)
 {
-    CandidateTestWebView *wkWebView = [[CandidateTestWebView alloc] initWithFrame:NSMakeRect(0, 0, 800, 600)];
+    CandidateTestWebView *wkWebView = [CandidateTestWebView setUpWithFrame:NSMakeRect(0, 0, 800, 600) testPage:@"input-field-in-scrollable-document"];
 
-    NSURL *contentURL = [[NSBundle mainBundle] URLForResource:@"input-field-in-scrollable-document" withExtension:@"html" subdirectory:@"TestWebKitAPI.resources"];
-    [wkWebView loadRequest:[NSURLRequest requestWithURL:contentURL]];
-
-    [wkWebView waitForMessage:@"focused"];
-    [wkWebView _forceRequestCandidates];
     [wkWebView insertCandidatesAndWaitForResponse:@"foo " range:NSMakeRange(0, 0)];
-
     EXPECT_TRUE([[wkWebView stringByEvaluatingJavaScript:GetInputValueJSExpression] isEqualToString:@"foo "]);
 
-    [wkWebView typeCharacter:'a'];
-    [wkWebView waitForMessage:@"input"];
-
+    [wkWebView typeString:@"a" inputMessage:@"input"];
     EXPECT_TRUE([[wkWebView stringByEvaluatingJavaScript:GetInputValueJSExpression] isEqualToString:@"foo a"]);
 }
 
 TEST(WKWebViewCandidateTests, InsertCandidateFromPartiallyTypedPhraseWithSoftSpace)
 {
-    CandidateTestWebView *wkWebView = [[CandidateTestWebView alloc] initWithFrame:NSMakeRect(0, 0, 800, 600)];
+    CandidateTestWebView *wkWebView = [CandidateTestWebView setUpWithFrame:NSMakeRect(0, 0, 800, 600) testPage:@"input-field-in-scrollable-document"];
 
-    NSURL *contentURL = [[NSBundle mainBundle] URLForResource:@"input-field-in-scrollable-document" withExtension:@"html" subdirectory:@"TestWebKitAPI.resources"];
-    [wkWebView loadRequest:[NSURLRequest requestWithURL:contentURL]];
-
-    [wkWebView waitForMessage:@"focused"];
-    [wkWebView _forceRequestCandidates];
-
-    NSString *initialValue = @"hel";
-    for (uint64_t i = 0; i < initialValue.length; ++i) {
-        [wkWebView typeCharacter:[initialValue characterAtIndex:i]];
-        [wkWebView waitForMessage:@"input"];
-    }
-
+    [wkWebView typeString:@"hel" inputMessage:@"input"];
     [wkWebView insertCandidatesAndWaitForResponse:@"hello " range:NSMakeRange(0, 3)];
     EXPECT_TRUE([[wkWebView stringByEvaluatingJavaScript:GetInputValueJSExpression] isEqualToString:@"hello "]);
 
     [wkWebView expectCandidateListVisibilityUpdates:0 whenPerformingActions:^()
     {
-        [wkWebView typeCharacter:' '];
-        [wkWebView waitForMessage:@"input"];
+        [wkWebView typeString:@" " inputMessage:@"input"];
         EXPECT_TRUE([[wkWebView stringByEvaluatingJavaScript:GetInputValueJSExpression] isEqualToString:@"hello "]);
         EXPECT_EQ([[wkWebView stringByEvaluatingJavaScript:GetDocumentScrollTopJSExpression] doubleValue], 0);
 
-        [wkWebView typeCharacter:' '];
-        [wkWebView waitForMessage:@"input"];
+        [wkWebView typeString:@" " inputMessage:@"input"];
         EXPECT_TRUE([[wkWebView stringByEvaluatingJavaScript:GetInputValueJSExpression] isEqualToString:@"hello  "]);
         EXPECT_EQ([[wkWebView stringByEvaluatingJavaScript:GetDocumentScrollTopJSExpression] doubleValue], 0);
     }];
 }
 
+TEST(WKWebViewCandidateTests, ClickingInTextFieldDoesNotThrashCandidateVisibility)
+{
+    CandidateTestWebView *wkWebView = [CandidateTestWebView setUpWithFrame:NSMakeRect(0, 0, 800, 600) testPage:@"large-input-field-focus-onload"];
+
+    [wkWebView typeString:@"test" inputMessage:@"input"];
+    [wkWebView expectCandidateListVisibilityUpdates:0 whenPerformingActions:^()
+    {
+        dispatch_async(dispatch_get_main_queue(), ^()
+        {
+            [wkWebView mouseDownAtPoint:NSMakePoint(100, 300) simulatePressure:YES];
+        });
+        [wkWebView waitForMessage:@"mousedown"];
+    }];
+    EXPECT_TRUE([[wkWebView stringByEvaluatingJavaScript:GetInputValueJSExpression] isEqualToString:@"test"]);
+}
+
+TEST(WKWebViewCandidateTests, ShouldNotRequestCandidatesInPasswordField)
+{
+    CandidateTestWebView *wkWebView = [[CandidateTestWebView alloc] initWithFrame:NSMakeRect(0, 0, 800, 600)];
+    [wkWebView loadTestPageNamed:@"text-and-password-inputs"];
+    [wkWebView waitForMessage:@"loaded"];
+    [wkWebView _forceRequestCandidates];
+
+    dispatch_async(dispatch_get_main_queue(), ^()
+    {
+        [wkWebView mouseDownAtPoint:NSMakePoint(400, 150) simulatePressure:YES];
+    });
+    [wkWebView waitForMessage:@"password-focused"];
+
+    [wkWebView typeString:@"foo" inputMessage:@"password-input"];
+    EXPECT_FALSE([wkWebView _shouldRequestCandidates]);
+
+    NSString *passwordFieldValue = [wkWebView stringByEvaluatingJavaScript:@"document.querySelector('#password').value"];
+    EXPECT_STREQ(passwordFieldValue.UTF8String, "foo");
+}
+
+#if USE(APPLE_INTERNAL_SDK)
+
+TEST(WKWebViewCandidateTests, ShouldRequestCandidatesInTextField)
+{
+    CandidateTestWebView *wkWebView = [[CandidateTestWebView alloc] initWithFrame:NSMakeRect(0, 0, 800, 600)];
+    [wkWebView loadTestPageNamed:@"text-and-password-inputs"];
+    [wkWebView waitForMessage:@"loaded"];
+    [wkWebView _forceRequestCandidates];
+
+    dispatch_async(dispatch_get_main_queue(), ^()
+    {
+        [wkWebView mouseDownAtPoint:NSMakePoint(400, 450) simulatePressure:YES];
+    });
+    [wkWebView waitForMessage:@"text-focused"];
+
+    [wkWebView typeString:@"bar" inputMessage:@"text-input"];
+    EXPECT_TRUE([wkWebView _shouldRequestCandidates]);
+
+    NSString *textFieldValue = [wkWebView stringByEvaluatingJavaScript:@"document.querySelector('#text').value"];
+    EXPECT_STREQ(textFieldValue.UTF8String, "bar");
+}
+
+#endif
+
 #endif /* WK_API_ENABLED && PLATFORM(MAC) && __MAC_OS_X_VERSION_MIN_REQUIRED >= 101200 */

Added: trunk/Tools/TestWebKitAPI/Tests/WebKit2Cocoa/large-input-field-focus-onload.html (0 => 206135)


--- trunk/Tools/TestWebKitAPI/Tests/WebKit2Cocoa/large-input-field-focus-onload.html	                        (rev 0)
+++ trunk/Tools/TestWebKitAPI/Tests/WebKit2Cocoa/large-input-field-focus-onload.html	2016-09-20 01:02:40 UTC (rev 206135)
@@ -0,0 +1,38 @@
+<html>
+
+<head>
+    <style>
+        body {
+            margin: 0;
+        }
+
+        input {
+            width: 100vw;
+            height: 100vh;
+            font-size: 50vh;
+        }
+    </style>
+    <script type="text/_javascript_">
+        function loaded() {
+            document.querySelector("input").focus();
+        }
+
+        function focused() {
+            setTimeout(() => window.webkit.messageHandlers.testHandler.postMessage("focused"), 0);
+        }
+
+        function input() {
+            setTimeout(() => window.webkit.messageHandlers.testHandler.postMessage("input"), 0);
+        }
+
+        function mousedown() {
+            setTimeout(() => window.webkit.messageHandlers.testHandler.postMessage("mousedown"), 0);
+        }
+    </script>
+</head>
+
+<body _onload_=loaded()>
+    <input _onfocus_=focused() _oninput_=input() _onmousedown_=mousedown()></input>
+</body>
+
+</html>

Added: trunk/Tools/TestWebKitAPI/Tests/WebKit2Cocoa/text-and-password-inputs.html (0 => 206135)


--- trunk/Tools/TestWebKitAPI/Tests/WebKit2Cocoa/text-and-password-inputs.html	                        (rev 0)
+++ trunk/Tools/TestWebKitAPI/Tests/WebKit2Cocoa/text-and-password-inputs.html	2016-09-20 01:02:40 UTC (rev 206135)
@@ -0,0 +1,39 @@
+<html>
+<head>
+    <script>
+    function loaded() {
+        setTimeout(() => window.webkit.messageHandlers.testHandler.postMessage("loaded"), 0);
+    }
+
+    function textFocused() {
+        setTimeout(() => window.webkit.messageHandlers.testHandler.postMessage("text-focused"), 0);
+    }
+
+    function textInput() {
+        setTimeout(() => window.webkit.messageHandlers.testHandler.postMessage("text-input"), 0);
+    }
+
+    function passwordFocused() {
+        setTimeout(() => window.webkit.messageHandlers.testHandler.postMessage("password-focused"), 0);
+    }
+
+    function passwordInput() {
+        setTimeout(() => window.webkit.messageHandlers.testHandler.postMessage("password-input"), 0);
+    }
+    </script>
+
+    <style>
+    input {
+        width: 100%;
+        height: 50%;
+        font-size: 100px;
+    }
+    body { margin: 0; }
+    </style>
+</head>
+
+<body _onload_=loaded() _onmousedown_=mousedown(event)>
+    <input id="text" type="text" _onfocus_=textFocused() _oninput_=textInput()></input>
+    <input id="password" type="password" _onfocus_=passwordFocused() _oninput_=passwordInput()></input>
+</body>
+</html>

Modified: trunk/Tools/TestWebKitAPI/mac/TestWKWebViewMac.h (206134 => 206135)


--- trunk/Tools/TestWebKitAPI/mac/TestWKWebViewMac.h	2016-09-20 00:48:39 UTC (rev 206134)
+++ trunk/Tools/TestWebKitAPI/mac/TestWKWebViewMac.h	2016-09-20 01:02:40 UTC (rev 206135)
@@ -35,7 +35,11 @@
 @end
 
 @interface TestWKWebView : WKWebView
-- (void)mouseDownAtPoint:(NSPoint)point;
+- (instancetype)initWithFrame:(CGRect)frame configuration:(WKWebViewConfiguration *)configuration NS_DESIGNATED_INITIALIZER;
+- (instancetype)initWithCoder:(NSCoder *)coder NS_UNAVAILABLE;
+
+// Simulates clicking with a pressure-sensitive device, if possible.
+- (void)mouseDownAtPoint:(NSPoint)point simulatePressure:(BOOL)simulatePressure;
 - (void)performAfterReceivingMessage:(NSString *)message action:(dispatch_block_t)action;
 - (void)loadTestPageNamed:(NSString *)pageName;
 - (void)typeCharacter:(char)character;

Modified: trunk/Tools/TestWebKitAPI/mac/TestWKWebViewMac.mm (206134 => 206135)


--- trunk/Tools/TestWebKitAPI/mac/TestWKWebViewMac.mm	2016-09-20 00:48:39 UTC (rev 206134)
+++ trunk/Tools/TestWebKitAPI/mac/TestWKWebViewMac.mm	2016-09-20 01:02:40 UTC (rev 206135)
@@ -33,6 +33,7 @@
 #import <AppKit/AppKit.h>
 #import <Carbon/Carbon.h>
 #import <WebKit/WebKitPrivate.h>
+#import <objc/runtime.h>
 #import <wtf/RetainPtr.h>
 
 @implementation TestMessageHandler {
@@ -59,18 +60,90 @@
 
 @end
 
-@implementation TestWKWebView
+@interface TestWKWebViewHostWindow : NSWindow
+@end
 
-- (void)mouseDownAtPoint:(NSPoint)point
+@implementation TestWKWebViewHostWindow
+
+static int gEventNumber = 1;
+
+#if __MAC_OS_X_VERSION_MIN_REQUIRED >= 101003
+NSEventMask __simulated_forceClickAssociatedEventsMask(id self, SEL _cmd)
 {
+    return NSEventMaskPressure | NSEventMaskLeftMouseDown | NSEventMaskLeftMouseUp | NSEventMaskLeftMouseDragged;
+}
+#endif
+
+- (void)_mouseDownAtPoint:(NSPoint)point simulatePressure:(BOOL)simulatePressure
+{
 #if __MAC_OS_X_VERSION_MIN_REQUIRED >= 101200
     NSEventType mouseEventType = NSEventTypeLeftMouseDown;
 #else
     NSEventType mouseEventType = NSLeftMouseDown;
 #endif
-    [self mouseDown:[NSEvent mouseEventWithType:mouseEventType location:NSMakePoint(point.x, point.y) modifierFlags:0 timestamp:GetCurrentEventTime() windowNumber:0 context:[NSGraphicsContext currentContext] eventNumber:0 clickCount:0 pressure:0]];
+
+    NSEventMask modifierFlags = 0;
+#if __MAC_OS_X_VERSION_MIN_REQUIRED >= 101003
+    if (simulatePressure)
+        modifierFlags |= NSEventMaskPressure;
+#else
+    simulatePressure = NO;
+#endif
+
+    NSEvent *event = [NSEvent mouseEventWithType:mouseEventType location:point modifierFlags:modifierFlags timestamp:GetCurrentEventTime() windowNumber:self.windowNumber context:[NSGraphicsContext currentContext] eventNumber:++gEventNumber clickCount:1 pressure:simulatePressure];
+    if (!simulatePressure) {
+        [self sendEvent:event];
+        return;
+    }
+
+#if __MAC_OS_X_VERSION_MIN_REQUIRED >= 101003
+    IMP simulatedAssociatedEventsMaskImpl = (IMP)__simulated_forceClickAssociatedEventsMask;
+    Method associatedEventsMaskMethod = class_getInstanceMethod([NSEvent class], @selector(associatedEventsMask));
+    IMP originalAssociatedEventsMaskImpl = method_setImplementation(associatedEventsMaskMethod, simulatedAssociatedEventsMaskImpl);
+    @try {
+        [self sendEvent:event];
+    } @finally {
+        // In the case where event sending raises an exception, we still want to restore the original implementation
+        // to prevent subsequent event sending tests from being affected.
+        method_setImplementation(associatedEventsMaskMethod, originalAssociatedEventsMaskImpl);
+    }
+#endif
 }
 
+@end
+
+@implementation TestWKWebView {
+    TestWKWebViewHostWindow *_hostWindow;
+}
+
+- (instancetype)initWithFrame:(CGRect)frame
+{
+    WKWebViewConfiguration *defaultConfiguration = [[WKWebViewConfiguration alloc] init];
+    return [self initWithFrame:frame configuration:defaultConfiguration];
+}
+
+- (instancetype)initWithFrame:(CGRect)frame configuration:(WKWebViewConfiguration *)configuration
+{
+    if (self = [super initWithFrame:frame configuration:configuration])
+        [self _setUpTestWindow:frame];
+
+    return self;
+}
+
+- (void)_setUpTestWindow:(NSRect)frame
+{
+    _hostWindow = [[TestWKWebViewHostWindow alloc] initWithContentRect:frame styleMask:NSBorderlessWindowMask backing:NSBackingStoreBuffered defer:NO];
+    [_hostWindow setFrameOrigin:NSMakePoint(0, 0)];
+    [[_hostWindow contentView] addSubview:self];
+    [_hostWindow setIsVisible:YES];
+    [_hostWindow makeKeyAndOrderFront:self];
+}
+
+- (void)mouseDownAtPoint:(NSPoint)point simulatePressure:(BOOL)simulatePressure
+{
+    [_hostWindow _mouseDownAtPoint:point simulatePressure:simulatePressure];
+}
+
 - (void)performAfterReceivingMessage:(NSString *)message action:(dispatch_block_t)action
 {
     RetainPtr<TestMessageHandler> handler = adoptNS([[TestMessageHandler alloc] initWithMessage:message handler:action]);
@@ -94,8 +167,8 @@
     NSEventType keyDownEventType = NSKeyDown;
     NSEventType keyUpEventType = NSKeyUp;
 #endif
-    [self keyDown:[NSEvent keyEventWithType:keyDownEventType location:NSZeroPoint modifierFlags:0 timestamp:GetCurrentEventTime() windowNumber:0 context:nil characters:characterAsString charactersIgnoringModifiers:characterAsString isARepeat:NO keyCode:character]];
-    [self keyUp:[NSEvent keyEventWithType:keyUpEventType location:NSZeroPoint modifierFlags:0 timestamp:GetCurrentEventTime() windowNumber:0 context:nil characters:characterAsString charactersIgnoringModifiers:characterAsString isARepeat:NO keyCode:character]];
+    [self keyDown:[NSEvent keyEventWithType:keyDownEventType location:NSZeroPoint modifierFlags:0 timestamp:GetCurrentEventTime() windowNumber:_hostWindow.windowNumber context:nil characters:characterAsString charactersIgnoringModifiers:characterAsString isARepeat:NO keyCode:character]];
+    [self keyUp:[NSEvent keyEventWithType:keyUpEventType location:NSZeroPoint modifierFlags:0 timestamp:GetCurrentEventTime() windowNumber:_hostWindow.windowNumber context:nil characters:characterAsString charactersIgnoringModifiers:characterAsString isARepeat:NO keyCode:character]];
 }
 
 - (NSString *)stringByEvaluatingJavaScript:(NSString *)script
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to