Changeset 206135 in webkit
- Timestamp:
- Sep 19, 2016 6:02:40 PM (8 years ago)
- Location:
- trunk
- Files:
-
- 2 added
- 9 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/WebKit2/ChangeLog
r206132 r206135 1 2016-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 1 16 2016-09-19 Anders Carlsson <andersca@apple.com> 2 17 -
trunk/Source/WebKit2/UIProcess/API/Cocoa/WKWebView.mm
r206033 r206135 4587 4587 _impl->forceRequestCandidatesForTesting(); 4588 4588 } 4589 4590 - (BOOL)_shouldRequestCandidates 4591 { 4592 return _impl->shouldRequestCandidates(); 4593 } 4589 4594 #endif // PLATFORM(MAC) 4590 4595 -
trunk/Source/WebKit2/UIProcess/API/Cocoa/WKWebViewPrivate.h
r206033 r206135 278 278 - (void)_forceRequestCandidates WK_API_AVAILABLE(macosx(WK_MAC_TBA)); 279 279 - (void)_didUpdateCandidateListVisibility:(BOOL)visible WK_API_AVAILABLE(macosx(WK_MAC_TBA)); 280 @property (nonatomic, readonly) BOOL _shouldRequestCandidates WK_API_AVAILABLE(macosx(WK_MAC_TBA)); 280 281 #endif 281 282 -
trunk/Tools/ChangeLog
r206126 r206135 1 2016-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 1 37 2016-09-19 Alex Christensen <achristensen@webkit.org> 2 38 -
trunk/Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj
r206033 r206135 76 76 2E7765CD16C4D80A00BA2BB1 /* mainIOS.mm in Sources */ = {isa = PBXBuildFile; fileRef = 2E7765CC16C4D80A00BA2BB1 /* mainIOS.mm */; }; 77 77 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 */; }; 78 79 2EFF06C31D88621E0004BB30 /* large-video-offscreen.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = 2EFF06C21D8862120004BB30 /* large-video-offscreen.html */; }; 79 80 2EFF06C51D8867760004BB30 /* change-video-source-on-click.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = 2EFF06C41D8867700004BB30 /* change-video-source-on-click.html */; }; … … 474 475 E1220DCA155B28AA0013E2FC /* MemoryCacheDisableWithinResourceLoadDelegate.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = E1220DC9155B287D0013E2FC /* MemoryCacheDisableWithinResourceLoadDelegate.html */; }; 475 476 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 */; }; 476 478 F4F405BC1D4C0D1C007A9707 /* full-size-autoplaying-video-with-audio.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = F4F405BA1D4C0CF8007A9707 /* full-size-autoplaying-video-with-audio.html */; }; 477 479 F4F405BD1D4C0D1C007A9707 /* skinny-autoplaying-video-with-audio.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = F4F405BB1D4C0CF8007A9707 /* skinny-autoplaying-video-with-audio.html */; }; … … 545 547 dstSubfolderSpec = 7; 546 548 files = ( 549 2E9896151D8F093800739892 /* text-and-password-inputs.html in Copy Resources */, 550 F42DA5161D8CEFE400336F40 /* large-input-field-focus-onload.html in Copy Resources */, 547 551 2EFF06CD1D8A429A0004BB30 /* input-field-in-scrollable-document.html in Copy Resources */, 548 552 2EFF06C71D886A580004BB30 /* change-video-source-on-end.html in Copy Resources */, … … 791 795 2E7765CC16C4D80A00BA2BB1 /* mainIOS.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = mainIOS.mm; sourceTree = "<group>"; }; 792 796 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>"; }; 793 798 2EFF06C21D8862120004BB30 /* large-video-offscreen.html */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.html; path = "large-video-offscreen.html"; sourceTree = "<group>"; }; 794 799 2EFF06C41D8867700004BB30 /* change-video-source-on-click.html */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.html; path = "change-video-source-on-click.html"; sourceTree = "<group>"; }; … … 1179 1184 E4C9ABC71B3DB1710040A987 /* RunLoop.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = RunLoop.cpp; sourceTree = "<group>"; }; 1180 1185 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; }; 1181 1187 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>"; }; 1182 1188 F4F405BB1D4C0CF8007A9707 /* skinny-autoplaying-video-with-audio.html */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.html; path = "skinny-autoplaying-video-with-audio.html"; sourceTree = "<group>"; }; … … 1474 1480 isa = PBXGroup; 1475 1481 children = ( 1482 2E9896141D8F092B00739892 /* text-and-password-inputs.html */, 1476 1483 2EFF06CC1D8A42910004BB30 /* input-field-in-scrollable-document.html */, 1477 1484 2EFF06C61D886A560004BB30 /* change-video-source-on-end.html */, … … 1918 1925 isa = PBXGroup; 1919 1926 children = ( 1927 F42DA5151D8CEFDB00336F40 /* large-input-field-focus-onload.html */, 1920 1928 379028B814FABE49007E6B43 /* acceptsFirstMouse.html */, 1921 1929 B55F11B9151916E600915916 /* Ahem.ttf */, -
trunk/Tools/TestWebKitAPI/Tests/WebKit2Cocoa/VideoControlsManager.mm
r206033 r206135 122 122 RetainPtr<WKWebViewConfiguration> configuration = adoptNS([[WKWebViewConfiguration alloc] init]); 123 123 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()]); 129 125 } 130 126 … … 211 207 [webView waitForPageToLoadWithAutoplayingVideos:2]; 212 208 213 [webView mouseDownAtPoint:clickPoint ];209 [webView mouseDownAtPoint:clickPoint simulatePressure:YES]; 214 210 215 211 __block bool firstVideoPaused = false; … … 222 218 } else { 223 219 EXPECT_TRUE([controlledElementID isEqualToString:@"first"]); 224 [webView mouseDownAtPoint:clickPoint ];220 [webView mouseDownAtPoint:clickPoint simulatePressure:YES]; 225 221 } 226 222 firstVideoPaused = true; … … 260 256 [webView waitForPageToLoadWithAutoplayingVideos:1]; 261 257 262 [webView mouseDownAtPoint:NSMakePoint(50, 50) ];258 [webView mouseDownAtPoint:NSMakePoint(50, 50) simulatePressure:YES]; 263 259 [webView expectControlsManager:YES afterReceivingMessage:@"paused"]; 264 260 } … … 292 288 [webView loadTestPageNamed:@"large-video-hides-controls-after-seek-to-end"]; 293 289 [webView waitForPageToLoadWithAutoplayingVideos:1]; 294 [webView mouseDownAtPoint:NSMakePoint(50, 50) ];290 [webView mouseDownAtPoint:NSMakePoint(50, 50) simulatePressure:YES]; 295 291 296 292 // We expect there to be media controls, since this is a user gestured seek to the end. … … 343 339 344 340 [webView loadTestPageNamed:@"large-video-offscreen"]; 345 [webView expectControlsManager:NO afterReceivingMessage:@"moved"];341 [webView waitForMediaControlsToHide]; 346 342 } 347 343 … … 352 348 [webView loadTestPageNamed:@"change-video-source-on-click"]; 353 349 [webView waitForPageToLoadWithAutoplayingVideos:1]; 354 [webView mouseDownAtPoint:NSMakePoint(400, 300) ];350 [webView mouseDownAtPoint:NSMakePoint(400, 300) simulatePressure:YES]; 355 351 356 352 [webView expectControlsManager:YES afterReceivingMessage:@"changed"]; -
trunk/Tools/TestWebKitAPI/Tests/WebKit2Cocoa/WKWebViewCandidateTests.mm
r206033 r206135 31 31 #import "TestWKWebViewMac.h" 32 32 33 #import <Carbon/Carbon.h> 33 34 #import <WebKit/WebKitPrivate.h> 34 35 … … 113 114 } 114 115 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]; 124 132 [wkWebView waitForMessage:@"focused"]; 125 133 [wkWebView _forceRequestCandidates]; 134 135 return wkWebView; 136 } 137 138 @end 139 140 TEST(WKWebViewCandidateTests, SoftSpaceReplacementAfterCandidateInsertionWithoutReplacement) 141 { 142 CandidateTestWebView *wkWebView = [CandidateTestWebView setUpWithFrame:NSMakeRect(0, 0, 800, 600) testPage:@"input-field-in-scrollable-document"]; 143 126 144 [wkWebView insertCandidatesAndWaitForResponse:@"apple " range:NSMakeRange(0, 0)]; 127 128 145 EXPECT_TRUE([[wkWebView stringByEvaluatingJavaScript:GetInputValueJSExpression] isEqualToString:@"apple "]); 129 146 130 147 [wkWebView expectCandidateListVisibilityUpdates:0 whenPerformingActions:^() 131 148 { 132 [wkWebView typeCharacter:' ']; 133 [wkWebView waitForMessage:@"input"]; 149 [wkWebView typeString:@" " inputMessage:@"input"]; 134 150 }]; 135 136 151 EXPECT_TRUE([[wkWebView stringByEvaluatingJavaScript:GetInputValueJSExpression] isEqualToString:@"apple "]); 137 152 EXPECT_EQ([[wkWebView stringByEvaluatingJavaScript:GetDocumentScrollTopJSExpression] doubleValue], 0); … … 140 155 TEST(WKWebViewCandidateTests, InsertCharactersAfterCandidateInsertionWithSoftSpace) 141 156 { 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 149 159 [wkWebView insertCandidatesAndWaitForResponse:@"foo " range:NSMakeRange(0, 0)]; 150 151 160 EXPECT_TRUE([[wkWebView stringByEvaluatingJavaScript:GetInputValueJSExpression] isEqualToString:@"foo "]); 152 161 153 [wkWebView typeCharacter:'a']; 154 [wkWebView waitForMessage:@"input"]; 155 162 [wkWebView typeString:@"a" inputMessage:@"input"]; 156 163 EXPECT_TRUE([[wkWebView stringByEvaluatingJavaScript:GetInputValueJSExpression] isEqualToString:@"foo a"]); 157 164 } … … 159 166 TEST(WKWebViewCandidateTests, InsertCandidateFromPartiallyTypedPhraseWithSoftSpace) 160 167 { 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"]; 175 171 [wkWebView insertCandidatesAndWaitForResponse:@"hello " range:NSMakeRange(0, 3)]; 176 172 EXPECT_TRUE([[wkWebView stringByEvaluatingJavaScript:GetInputValueJSExpression] isEqualToString:@"hello "]); … … 178 174 [wkWebView expectCandidateListVisibilityUpdates:0 whenPerformingActions:^() 179 175 { 180 [wkWebView typeCharacter:' ']; 181 [wkWebView waitForMessage:@"input"]; 176 [wkWebView typeString:@" " inputMessage:@"input"]; 182 177 EXPECT_TRUE([[wkWebView stringByEvaluatingJavaScript:GetInputValueJSExpression] isEqualToString:@"hello "]); 183 178 EXPECT_EQ([[wkWebView stringByEvaluatingJavaScript:GetDocumentScrollTopJSExpression] doubleValue], 0); 184 179 185 [wkWebView typeCharacter:' ']; 186 [wkWebView waitForMessage:@"input"]; 180 [wkWebView typeString:@" " inputMessage:@"input"]; 187 181 EXPECT_TRUE([[wkWebView stringByEvaluatingJavaScript:GetInputValueJSExpression] isEqualToString:@"hello "]); 188 182 EXPECT_EQ([[wkWebView stringByEvaluatingJavaScript:GetDocumentScrollTopJSExpression] doubleValue], 0); … … 190 184 } 191 185 186 TEST(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 202 TEST(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 224 TEST(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 192 246 #endif /* WK_API_ENABLED && PLATFORM(MAC) && __MAC_OS_X_VERSION_MIN_REQUIRED >= 101200 */ -
trunk/Tools/TestWebKitAPI/mac/TestWKWebViewMac.h
r206033 r206135 36 36 37 37 @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; 39 43 - (void)performAfterReceivingMessage:(NSString *)message action:(dispatch_block_t)action; 40 44 - (void)loadTestPageNamed:(NSString *)pageName; -
trunk/Tools/TestWebKitAPI/mac/TestWKWebViewMac.mm
r206033 r206135 34 34 #import <Carbon/Carbon.h> 35 35 #import <WebKit/WebKitPrivate.h> 36 #import <objc/runtime.h> 36 37 #import <wtf/RetainPtr.h> 37 38 … … 60 61 @end 61 62 62 @implementation TestWKWebView 63 64 - (void)mouseDownAtPoint:(NSPoint)point 63 @interface TestWKWebViewHostWindow : NSWindow 64 @end 65 66 @implementation TestWKWebViewHostWindow 67 68 static int gEventNumber = 1; 69 70 #if __MAC_OS_X_VERSION_MIN_REQUIRED >= 101003 71 NSEventMask __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 65 78 { 66 79 #if __MAC_OS_X_VERSION_MIN_REQUIRED >= 101200 … … 69 82 NSEventType mouseEventType = NSLeftMouseDown; 70 83 #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]; 72 145 } 73 146 … … 95 168 NSEventType keyUpEventType = NSKeyUp; 96 169 #endif 97 [self keyDown:[NSEvent keyEventWithType:keyDownEventType location:NSZeroPoint modifierFlags:0 timestamp:GetCurrentEventTime() windowNumber: 0context:nil characters:characterAsString charactersIgnoringModifiers:characterAsString isARepeat:NO keyCode:character]];98 [self keyUp:[NSEvent keyEventWithType:keyUpEventType location:NSZeroPoint modifierFlags:0 timestamp:GetCurrentEventTime() windowNumber: 0context: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]]; 99 172 } 100 173
Note: See TracChangeset
for help on using the changeset viewer.