Changeset 206135 in webkit


Ignore:
Timestamp:
Sep 19, 2016 6:02:40 PM (8 years ago)
Author:
Wenson Hsieh
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.

Location:
trunk
Files:
2 added
9 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebKit2/ChangeLog

    r206132 r206135  
     12016-09-19  Wenson Hsieh  <wenson_hsieh@apple.com>
     2
     3        Add a unit test covering <https://trac.webkit.org/changeset/205983>
     4        https://bugs.webkit.org/show_bug.cgi?id=162112
     5
     6        Reviewed by Beth Dakin.
     7
     8        Adds some a test support method as SPI on WKWebView to determine whether to request candidates. See
     9        Tools/ChangeLog for more details.
     10
     11        * UIProcess/API/Cocoa/WKWebView.mm:
     12        (-[WKWebView _shouldRequestCandidates]):
     13        (-[WKWebView _forceRequestCandidates]): Deleted.
     14        * UIProcess/API/Cocoa/WKWebViewPrivate.h:
     15
    1162016-09-19  Anders Carlsson  <andersca@apple.com>
    217
  • trunk/Source/WebKit2/UIProcess/API/Cocoa/WKWebView.mm

    r206033 r206135  
    45874587    _impl->forceRequestCandidatesForTesting();
    45884588}
     4589
     4590- (BOOL)_shouldRequestCandidates
     4591{
     4592    return _impl->shouldRequestCandidates();
     4593}
    45894594#endif // PLATFORM(MAC)
    45904595
  • trunk/Source/WebKit2/UIProcess/API/Cocoa/WKWebViewPrivate.h

    r206033 r206135  
    278278- (void)_forceRequestCandidates WK_API_AVAILABLE(macosx(WK_MAC_TBA));
    279279- (void)_didUpdateCandidateListVisibility:(BOOL)visible WK_API_AVAILABLE(macosx(WK_MAC_TBA));
     280@property (nonatomic, readonly) BOOL _shouldRequestCandidates WK_API_AVAILABLE(macosx(WK_MAC_TBA));
    280281#endif
    281282
  • trunk/Tools/ChangeLog

    r206126 r206135  
     12016-09-19  Wenson Hsieh  <wenson_hsieh@apple.com>
     2
     3        Add a unit test covering <https://trac.webkit.org/changeset/205983>
     4        https://bugs.webkit.org/show_bug.cgi?id=162112
     5
     6        Reviewed by Beth Dakin.
     7
     8        Adds a new unit test covering the changes in r205983 along with the infrastructure needed to support it. Also
     9        further refactors the TestWKWebView used by VideoControlsManager and WKWebViewCandidateTests so that in both
     10        cases, we add the WKWebView to a visible key window, and when sending a mouse down event, we propagate the event
     11        at the window level rather than the view level, allowing greater flexibility to simulate behaviors such as
     12        pressure-sensitive events that are needed for the new test.
     13
     14        Also rewrites currently disabled unit tests in CandidateTests as WebKit2 unit tests in WKWebViewCandidateTests,
     15        checking whether or not to should be requesting candidates in password and non-password fields.
     16
     17        * TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj:
     18        * TestWebKitAPI/Tests/WebKit2Cocoa/VideoControlsManager.mm:
     19        (TestWebKitAPI::setUpWebViewForTestingVideoControlsManager):
     20        (TestWebKitAPI::TEST):
     21        * TestWebKitAPI/Tests/WebKit2Cocoa/WKWebViewCandidateTests.mm:
     22        (-[CandidateTestWebView typeString:inputMessage:]):
     23        (+[CandidateTestWebView setUpWithFrame:testPage:]):
     24        * TestWebKitAPI/Tests/WebKit2Cocoa/large-input-field-focus-onload.html: Added.
     25        * TestWebKitAPI/Tests/WebKit2Cocoa/text-and-password-inputs.html: Added.
     26        * TestWebKitAPI/mac/TestWKWebViewMac.h:
     27        * TestWebKitAPI/mac/TestWKWebViewMac.mm:
     28        (__simulated_forceClickAssociatedEventsMask):
     29        (-[TestWKWebViewHostWindow _mouseDownAtPoint:simulatePressure:]):
     30        (-[TestWKWebView initWithFrame:]):
     31        (-[TestWKWebView initWithFrame:configuration:]):
     32        (-[TestWKWebView _setUpTestWindow:]):
     33        (-[TestWKWebView mouseDownAtPoint:simulatePressure:]):
     34        (-[TestWKWebView typeCharacter:]):
     35        (-[TestWKWebView mouseDownAtPoint:]): Deleted.
     36
    1372016-09-19  Alex Christensen  <achristensen@webkit.org>
    238
  • trunk/Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj

    r206033 r206135  
    7676                2E7765CD16C4D80A00BA2BB1 /* mainIOS.mm in Sources */ = {isa = PBXBuildFile; fileRef = 2E7765CC16C4D80A00BA2BB1 /* mainIOS.mm */; };
    7777                2E7765CF16C4D81100BA2BB1 /* mainMac.mm in Sources */ = {isa = PBXBuildFile; fileRef = 2E7765CE16C4D81100BA2BB1 /* mainMac.mm */; };
     78                2E9896151D8F093800739892 /* text-and-password-inputs.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = 2E9896141D8F092B00739892 /* text-and-password-inputs.html */; };
    7879                2EFF06C31D88621E0004BB30 /* large-video-offscreen.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = 2EFF06C21D8862120004BB30 /* large-video-offscreen.html */; };
    7980                2EFF06C51D8867760004BB30 /* change-video-source-on-click.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = 2EFF06C41D8867700004BB30 /* change-video-source-on-click.html */; };
     
    474475                E1220DCA155B28AA0013E2FC /* MemoryCacheDisableWithinResourceLoadDelegate.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = E1220DC9155B287D0013E2FC /* MemoryCacheDisableWithinResourceLoadDelegate.html */; };
    475476                E194E1BD177E53C7009C4D4E /* StopLoadingFromDidReceiveResponse.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = E194E1BC177E534A009C4D4E /* StopLoadingFromDidReceiveResponse.html */; };
     477                F42DA5161D8CEFE400336F40 /* large-input-field-focus-onload.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = F42DA5151D8CEFDB00336F40 /* large-input-field-focus-onload.html */; };
    476478                F4F405BC1D4C0D1C007A9707 /* full-size-autoplaying-video-with-audio.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = F4F405BA1D4C0CF8007A9707 /* full-size-autoplaying-video-with-audio.html */; };
    477479                F4F405BD1D4C0D1C007A9707 /* skinny-autoplaying-video-with-audio.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = F4F405BB1D4C0CF8007A9707 /* skinny-autoplaying-video-with-audio.html */; };
     
    545547                        dstSubfolderSpec = 7;
    546548                        files = (
     549                                2E9896151D8F093800739892 /* text-and-password-inputs.html in Copy Resources */,
     550                                F42DA5161D8CEFE400336F40 /* large-input-field-focus-onload.html in Copy Resources */,
    547551                                2EFF06CD1D8A429A0004BB30 /* input-field-in-scrollable-document.html in Copy Resources */,
    548552                                2EFF06C71D886A580004BB30 /* change-video-source-on-end.html in Copy Resources */,
     
    791795                2E7765CC16C4D80A00BA2BB1 /* mainIOS.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = mainIOS.mm; sourceTree = "<group>"; };
    792796                2E7765CE16C4D81100BA2BB1 /* mainMac.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = mainMac.mm; sourceTree = "<group>"; };
     797                2E9896141D8F092B00739892 /* text-and-password-inputs.html */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.html; path = "text-and-password-inputs.html"; sourceTree = "<group>"; };
    793798                2EFF06C21D8862120004BB30 /* large-video-offscreen.html */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.html; path = "large-video-offscreen.html"; sourceTree = "<group>"; };
    794799                2EFF06C41D8867700004BB30 /* change-video-source-on-click.html */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.html; path = "change-video-source-on-click.html"; sourceTree = "<group>"; };
     
    11791184                E4C9ABC71B3DB1710040A987 /* RunLoop.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = RunLoop.cpp; sourceTree = "<group>"; };
    11801185                F3FC3EE213678B7300126A65 /* libgtest.a */ = {isa = PBXFileReference; lastKnownFileType = archive.ar; path = libgtest.a; sourceTree = BUILT_PRODUCTS_DIR; };
     1186                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; };
    11811187                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>"; };
    11821188                F4F405BB1D4C0CF8007A9707 /* skinny-autoplaying-video-with-audio.html */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.html; path = "skinny-autoplaying-video-with-audio.html"; sourceTree = "<group>"; };
     
    14741480                        isa = PBXGroup;
    14751481                        children = (
     1482                                2E9896141D8F092B00739892 /* text-and-password-inputs.html */,
    14761483                                2EFF06CC1D8A42910004BB30 /* input-field-in-scrollable-document.html */,
    14771484                                2EFF06C61D886A560004BB30 /* change-video-source-on-end.html */,
     
    19181925                        isa = PBXGroup;
    19191926                        children = (
     1927                                F42DA5151D8CEFDB00336F40 /* large-input-field-focus-onload.html */,
    19201928                                379028B814FABE49007E6B43 /* acceptsFirstMouse.html */,
    19211929                                B55F11B9151916E600915916 /* Ahem.ttf */,
  • trunk/Tools/TestWebKitAPI/Tests/WebKit2Cocoa/VideoControlsManager.mm

    r206033 r206135  
    122122    RetainPtr<WKWebViewConfiguration> configuration = adoptNS([[WKWebViewConfiguration alloc] init]);
    123123    configuration.get().mediaTypesRequiringUserActionForPlayback = WKAudiovisualMediaTypeNone;
    124     RetainPtr<VideoControlsManagerTestWebView> webView = adoptNS([[VideoControlsManagerTestWebView alloc] initWithFrame:frame configuration:configuration.get()]);
    125     RetainPtr<NSWindow> window = adoptNS([[NSWindow alloc] initWithContentRect:[webView frame] styleMask:NSBorderlessWindowMask backing:NSBackingStoreBuffered defer:NO]);
    126     [[window contentView] addSubview:webView.get()];
    127 
    128     return webView;
     124    return adoptNS([[VideoControlsManagerTestWebView alloc] initWithFrame:frame configuration:configuration.get()]);
    129125}
    130126
     
    211207    [webView waitForPageToLoadWithAutoplayingVideos:2];
    212208
    213     [webView mouseDownAtPoint:clickPoint];
     209    [webView mouseDownAtPoint:clickPoint simulatePressure:YES];
    214210
    215211    __block bool firstVideoPaused = false;
     
    222218        } else {
    223219            EXPECT_TRUE([controlledElementID isEqualToString:@"first"]);
    224             [webView mouseDownAtPoint:clickPoint];
     220            [webView mouseDownAtPoint:clickPoint simulatePressure:YES];
    225221        }
    226222        firstVideoPaused = true;
     
    260256    [webView waitForPageToLoadWithAutoplayingVideos:1];
    261257
    262     [webView mouseDownAtPoint:NSMakePoint(50, 50)];
     258    [webView mouseDownAtPoint:NSMakePoint(50, 50) simulatePressure:YES];
    263259    [webView expectControlsManager:YES afterReceivingMessage:@"paused"];
    264260}
     
    292288    [webView loadTestPageNamed:@"large-video-hides-controls-after-seek-to-end"];
    293289    [webView waitForPageToLoadWithAutoplayingVideos:1];
    294     [webView mouseDownAtPoint:NSMakePoint(50, 50)];
     290    [webView mouseDownAtPoint:NSMakePoint(50, 50) simulatePressure:YES];
    295291
    296292    // We expect there to be media controls, since this is a user gestured seek to the end.
     
    343339
    344340    [webView loadTestPageNamed:@"large-video-offscreen"];
    345     [webView expectControlsManager:NO afterReceivingMessage:@"moved"];
     341    [webView waitForMediaControlsToHide];
    346342}
    347343
     
    352348    [webView loadTestPageNamed:@"change-video-source-on-click"];
    353349    [webView waitForPageToLoadWithAutoplayingVideos:1];
    354     [webView mouseDownAtPoint:NSMakePoint(400, 300)];
     350    [webView mouseDownAtPoint:NSMakePoint(400, 300) simulatePressure:YES];
    355351
    356352    [webView expectControlsManager:YES afterReceivingMessage:@"changed"];
  • trunk/Tools/TestWebKitAPI/Tests/WebKit2Cocoa/WKWebViewCandidateTests.mm

    r206033 r206135  
    3131#import "TestWKWebViewMac.h"
    3232
     33#import <Carbon/Carbon.h>
    3334#import <WebKit/WebKitPrivate.h>
    3435
     
    113114}
    114115
    115 @end
    116 
    117 TEST(WKWebViewCandidateTests, SoftSpaceReplacementAfterCandidateInsertionWithoutReplacement)
    118 {
    119     CandidateTestWebView *wkWebView = [[CandidateTestWebView alloc] initWithFrame:NSMakeRect(0, 0, 800, 600)];
    120 
    121     NSURL *contentURL = [[NSBundle mainBundle] URLForResource:@"input-field-in-scrollable-document" withExtension:@"html" subdirectory:@"TestWebKitAPI.resources"];
    122     [wkWebView loadRequest:[NSURLRequest requestWithURL:contentURL]];
    123 
     116- (void)typeString:(NSString *)string inputMessage:(NSString *)inputMessage
     117{
     118    for (uint64_t i = 0; i < string.length; ++i) {
     119        dispatch_async(dispatch_get_main_queue(), ^()
     120        {
     121            [self typeCharacter:[string characterAtIndex:i]];
     122        });
     123        [self waitForMessage:inputMessage];
     124    }
     125}
     126
     127+ (instancetype)setUpWithFrame:(NSRect)frame testPage:(NSString *)testPageName
     128{
     129    CandidateTestWebView *wkWebView = [[CandidateTestWebView alloc] initWithFrame:frame];
     130
     131    [wkWebView loadTestPageNamed:testPageName];
    124132    [wkWebView waitForMessage:@"focused"];
    125133    [wkWebView _forceRequestCandidates];
     134
     135    return wkWebView;
     136}
     137
     138@end
     139
     140TEST(WKWebViewCandidateTests, SoftSpaceReplacementAfterCandidateInsertionWithoutReplacement)
     141{
     142    CandidateTestWebView *wkWebView = [CandidateTestWebView setUpWithFrame:NSMakeRect(0, 0, 800, 600) testPage:@"input-field-in-scrollable-document"];
     143
    126144    [wkWebView insertCandidatesAndWaitForResponse:@"apple " range:NSMakeRange(0, 0)];
    127 
    128145    EXPECT_TRUE([[wkWebView stringByEvaluatingJavaScript:GetInputValueJSExpression] isEqualToString:@"apple "]);
    129146
    130147    [wkWebView expectCandidateListVisibilityUpdates:0 whenPerformingActions:^()
    131148    {
    132         [wkWebView typeCharacter:' '];
    133         [wkWebView waitForMessage:@"input"];
     149        [wkWebView typeString:@" " inputMessage:@"input"];
    134150    }];
    135 
    136151    EXPECT_TRUE([[wkWebView stringByEvaluatingJavaScript:GetInputValueJSExpression] isEqualToString:@"apple "]);
    137152    EXPECT_EQ([[wkWebView stringByEvaluatingJavaScript:GetDocumentScrollTopJSExpression] doubleValue], 0);
     
    140155TEST(WKWebViewCandidateTests, InsertCharactersAfterCandidateInsertionWithSoftSpace)
    141156{
    142     CandidateTestWebView *wkWebView = [[CandidateTestWebView alloc] initWithFrame:NSMakeRect(0, 0, 800, 600)];
    143 
    144     NSURL *contentURL = [[NSBundle mainBundle] URLForResource:@"input-field-in-scrollable-document" withExtension:@"html" subdirectory:@"TestWebKitAPI.resources"];
    145     [wkWebView loadRequest:[NSURLRequest requestWithURL:contentURL]];
    146 
    147     [wkWebView waitForMessage:@"focused"];
    148     [wkWebView _forceRequestCandidates];
     157    CandidateTestWebView *wkWebView = [CandidateTestWebView setUpWithFrame:NSMakeRect(0, 0, 800, 600) testPage:@"input-field-in-scrollable-document"];
     158
    149159    [wkWebView insertCandidatesAndWaitForResponse:@"foo " range:NSMakeRange(0, 0)];
    150 
    151160    EXPECT_TRUE([[wkWebView stringByEvaluatingJavaScript:GetInputValueJSExpression] isEqualToString:@"foo "]);
    152161
    153     [wkWebView typeCharacter:'a'];
    154     [wkWebView waitForMessage:@"input"];
    155 
     162    [wkWebView typeString:@"a" inputMessage:@"input"];
    156163    EXPECT_TRUE([[wkWebView stringByEvaluatingJavaScript:GetInputValueJSExpression] isEqualToString:@"foo a"]);
    157164}
     
    159166TEST(WKWebViewCandidateTests, InsertCandidateFromPartiallyTypedPhraseWithSoftSpace)
    160167{
    161     CandidateTestWebView *wkWebView = [[CandidateTestWebView alloc] initWithFrame:NSMakeRect(0, 0, 800, 600)];
    162 
    163     NSURL *contentURL = [[NSBundle mainBundle] URLForResource:@"input-field-in-scrollable-document" withExtension:@"html" subdirectory:@"TestWebKitAPI.resources"];
    164     [wkWebView loadRequest:[NSURLRequest requestWithURL:contentURL]];
    165 
    166     [wkWebView waitForMessage:@"focused"];
    167     [wkWebView _forceRequestCandidates];
    168 
    169     NSString *initialValue = @"hel";
    170     for (uint64_t i = 0; i < initialValue.length; ++i) {
    171         [wkWebView typeCharacter:[initialValue characterAtIndex:i]];
    172         [wkWebView waitForMessage:@"input"];
    173     }
    174 
     168    CandidateTestWebView *wkWebView = [CandidateTestWebView setUpWithFrame:NSMakeRect(0, 0, 800, 600) testPage:@"input-field-in-scrollable-document"];
     169
     170    [wkWebView typeString:@"hel" inputMessage:@"input"];
    175171    [wkWebView insertCandidatesAndWaitForResponse:@"hello " range:NSMakeRange(0, 3)];
    176172    EXPECT_TRUE([[wkWebView stringByEvaluatingJavaScript:GetInputValueJSExpression] isEqualToString:@"hello "]);
     
    178174    [wkWebView expectCandidateListVisibilityUpdates:0 whenPerformingActions:^()
    179175    {
    180         [wkWebView typeCharacter:' '];
    181         [wkWebView waitForMessage:@"input"];
     176        [wkWebView typeString:@" " inputMessage:@"input"];
    182177        EXPECT_TRUE([[wkWebView stringByEvaluatingJavaScript:GetInputValueJSExpression] isEqualToString:@"hello "]);
    183178        EXPECT_EQ([[wkWebView stringByEvaluatingJavaScript:GetDocumentScrollTopJSExpression] doubleValue], 0);
    184179
    185         [wkWebView typeCharacter:' '];
    186         [wkWebView waitForMessage:@"input"];
     180        [wkWebView typeString:@" " inputMessage:@"input"];
    187181        EXPECT_TRUE([[wkWebView stringByEvaluatingJavaScript:GetInputValueJSExpression] isEqualToString:@"hello  "]);
    188182        EXPECT_EQ([[wkWebView stringByEvaluatingJavaScript:GetDocumentScrollTopJSExpression] doubleValue], 0);
     
    190184}
    191185
     186TEST(WKWebViewCandidateTests, ClickingInTextFieldDoesNotThrashCandidateVisibility)
     187{
     188    CandidateTestWebView *wkWebView = [CandidateTestWebView setUpWithFrame:NSMakeRect(0, 0, 800, 600) testPage:@"large-input-field-focus-onload"];
     189
     190    [wkWebView typeString:@"test" inputMessage:@"input"];
     191    [wkWebView expectCandidateListVisibilityUpdates:0 whenPerformingActions:^()
     192    {
     193        dispatch_async(dispatch_get_main_queue(), ^()
     194        {
     195            [wkWebView mouseDownAtPoint:NSMakePoint(100, 300) simulatePressure:YES];
     196        });
     197        [wkWebView waitForMessage:@"mousedown"];
     198    }];
     199    EXPECT_TRUE([[wkWebView stringByEvaluatingJavaScript:GetInputValueJSExpression] isEqualToString:@"test"]);
     200}
     201
     202TEST(WKWebViewCandidateTests, ShouldNotRequestCandidatesInPasswordField)
     203{
     204    CandidateTestWebView *wkWebView = [[CandidateTestWebView alloc] initWithFrame:NSMakeRect(0, 0, 800, 600)];
     205    [wkWebView loadTestPageNamed:@"text-and-password-inputs"];
     206    [wkWebView waitForMessage:@"loaded"];
     207    [wkWebView _forceRequestCandidates];
     208
     209    dispatch_async(dispatch_get_main_queue(), ^()
     210    {
     211        [wkWebView mouseDownAtPoint:NSMakePoint(400, 150) simulatePressure:YES];
     212    });
     213    [wkWebView waitForMessage:@"password-focused"];
     214
     215    [wkWebView typeString:@"foo" inputMessage:@"password-input"];
     216    EXPECT_FALSE([wkWebView _shouldRequestCandidates]);
     217
     218    NSString *passwordFieldValue = [wkWebView stringByEvaluatingJavaScript:@"document.querySelector('#password').value"];
     219    EXPECT_STREQ(passwordFieldValue.UTF8String, "foo");
     220}
     221
     222#if USE(APPLE_INTERNAL_SDK)
     223
     224TEST(WKWebViewCandidateTests, ShouldRequestCandidatesInTextField)
     225{
     226    CandidateTestWebView *wkWebView = [[CandidateTestWebView alloc] initWithFrame:NSMakeRect(0, 0, 800, 600)];
     227    [wkWebView loadTestPageNamed:@"text-and-password-inputs"];
     228    [wkWebView waitForMessage:@"loaded"];
     229    [wkWebView _forceRequestCandidates];
     230
     231    dispatch_async(dispatch_get_main_queue(), ^()
     232    {
     233        [wkWebView mouseDownAtPoint:NSMakePoint(400, 450) simulatePressure:YES];
     234    });
     235    [wkWebView waitForMessage:@"text-focused"];
     236
     237    [wkWebView typeString:@"bar" inputMessage:@"text-input"];
     238    EXPECT_TRUE([wkWebView _shouldRequestCandidates]);
     239
     240    NSString *textFieldValue = [wkWebView stringByEvaluatingJavaScript:@"document.querySelector('#text').value"];
     241    EXPECT_STREQ(textFieldValue.UTF8String, "bar");
     242}
     243
     244#endif
     245
    192246#endif /* WK_API_ENABLED && PLATFORM(MAC) && __MAC_OS_X_VERSION_MIN_REQUIRED >= 101200 */
  • trunk/Tools/TestWebKitAPI/mac/TestWKWebViewMac.h

    r206033 r206135  
    3636
    3737@interface TestWKWebView : WKWebView
    38 - (void)mouseDownAtPoint:(NSPoint)point;
     38- (instancetype)initWithFrame:(CGRect)frame configuration:(WKWebViewConfiguration *)configuration NS_DESIGNATED_INITIALIZER;
     39- (instancetype)initWithCoder:(NSCoder *)coder NS_UNAVAILABLE;
     40
     41// Simulates clicking with a pressure-sensitive device, if possible.
     42- (void)mouseDownAtPoint:(NSPoint)point simulatePressure:(BOOL)simulatePressure;
    3943- (void)performAfterReceivingMessage:(NSString *)message action:(dispatch_block_t)action;
    4044- (void)loadTestPageNamed:(NSString *)pageName;
  • trunk/Tools/TestWebKitAPI/mac/TestWKWebViewMac.mm

    r206033 r206135  
    3434#import <Carbon/Carbon.h>
    3535#import <WebKit/WebKitPrivate.h>
     36#import <objc/runtime.h>
    3637#import <wtf/RetainPtr.h>
    3738
     
    6061@end
    6162
    62 @implementation TestWKWebView
    63 
    64 - (void)mouseDownAtPoint:(NSPoint)point
     63@interface TestWKWebViewHostWindow : NSWindow
     64@end
     65
     66@implementation TestWKWebViewHostWindow
     67
     68static int gEventNumber = 1;
     69
     70#if __MAC_OS_X_VERSION_MIN_REQUIRED >= 101003
     71NSEventMask __simulated_forceClickAssociatedEventsMask(id self, SEL _cmd)
     72{
     73    return NSEventMaskPressure | NSEventMaskLeftMouseDown | NSEventMaskLeftMouseUp | NSEventMaskLeftMouseDragged;
     74}
     75#endif
     76
     77- (void)_mouseDownAtPoint:(NSPoint)point simulatePressure:(BOOL)simulatePressure
    6578{
    6679#if __MAC_OS_X_VERSION_MIN_REQUIRED >= 101200
     
    6982    NSEventType mouseEventType = NSLeftMouseDown;
    7083#endif
    71     [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]];
     84
     85    NSEventMask modifierFlags = 0;
     86#if __MAC_OS_X_VERSION_MIN_REQUIRED >= 101003
     87    if (simulatePressure)
     88        modifierFlags |= NSEventMaskPressure;
     89#else
     90    simulatePressure = NO;
     91#endif
     92
     93    NSEvent *event = [NSEvent mouseEventWithType:mouseEventType location:point modifierFlags:modifierFlags timestamp:GetCurrentEventTime() windowNumber:self.windowNumber context:[NSGraphicsContext currentContext] eventNumber:++gEventNumber clickCount:1 pressure:simulatePressure];
     94    if (!simulatePressure) {
     95        [self sendEvent:event];
     96        return;
     97    }
     98
     99#if __MAC_OS_X_VERSION_MIN_REQUIRED >= 101003
     100    IMP simulatedAssociatedEventsMaskImpl = (IMP)__simulated_forceClickAssociatedEventsMask;
     101    Method associatedEventsMaskMethod = class_getInstanceMethod([NSEvent class], @selector(associatedEventsMask));
     102    IMP originalAssociatedEventsMaskImpl = method_setImplementation(associatedEventsMaskMethod, simulatedAssociatedEventsMaskImpl);
     103    @try {
     104        [self sendEvent:event];
     105    } @finally {
     106        // In the case where event sending raises an exception, we still want to restore the original implementation
     107        // to prevent subsequent event sending tests from being affected.
     108        method_setImplementation(associatedEventsMaskMethod, originalAssociatedEventsMaskImpl);
     109    }
     110#endif
     111}
     112
     113@end
     114
     115@implementation TestWKWebView {
     116    TestWKWebViewHostWindow *_hostWindow;
     117}
     118
     119- (instancetype)initWithFrame:(CGRect)frame
     120{
     121    WKWebViewConfiguration *defaultConfiguration = [[WKWebViewConfiguration alloc] init];
     122    return [self initWithFrame:frame configuration:defaultConfiguration];
     123}
     124
     125- (instancetype)initWithFrame:(CGRect)frame configuration:(WKWebViewConfiguration *)configuration
     126{
     127    if (self = [super initWithFrame:frame configuration:configuration])
     128        [self _setUpTestWindow:frame];
     129
     130    return self;
     131}
     132
     133- (void)_setUpTestWindow:(NSRect)frame
     134{
     135    _hostWindow = [[TestWKWebViewHostWindow alloc] initWithContentRect:frame styleMask:NSBorderlessWindowMask backing:NSBackingStoreBuffered defer:NO];
     136    [_hostWindow setFrameOrigin:NSMakePoint(0, 0)];
     137    [[_hostWindow contentView] addSubview:self];
     138    [_hostWindow setIsVisible:YES];
     139    [_hostWindow makeKeyAndOrderFront:self];
     140}
     141
     142- (void)mouseDownAtPoint:(NSPoint)point simulatePressure:(BOOL)simulatePressure
     143{
     144    [_hostWindow _mouseDownAtPoint:point simulatePressure:simulatePressure];
    72145}
    73146
     
    95168    NSEventType keyUpEventType = NSKeyUp;
    96169#endif
    97     [self keyDown:[NSEvent keyEventWithType:keyDownEventType location:NSZeroPoint modifierFlags:0 timestamp:GetCurrentEventTime() windowNumber:0 context:nil characters:characterAsString charactersIgnoringModifiers:characterAsString isARepeat:NO keyCode:character]];
    98     [self keyUp:[NSEvent keyEventWithType:keyUpEventType location:NSZeroPoint modifierFlags:0 timestamp:GetCurrentEventTime() windowNumber:0 context:nil characters:characterAsString charactersIgnoringModifiers:characterAsString isARepeat:NO keyCode:character]];
     170    [self keyDown:[NSEvent keyEventWithType:keyDownEventType location:NSZeroPoint modifierFlags:0 timestamp:GetCurrentEventTime() windowNumber:_hostWindow.windowNumber context:nil characters:characterAsString charactersIgnoringModifiers:characterAsString isARepeat:NO keyCode:character]];
     171    [self keyUp:[NSEvent keyEventWithType:keyUpEventType location:NSZeroPoint modifierFlags:0 timestamp:GetCurrentEventTime() windowNumber:_hostWindow.windowNumber context:nil characters:characterAsString charactersIgnoringModifiers:characterAsString isARepeat:NO keyCode:character]];
    99172}
    100173
Note: See TracChangeset for help on using the changeset viewer.