https://bugs.webkit.org/show_bug.cgi?id=174793
Reviewed by Tim Horton.
Adds a new unit test that invokes some asynchronous NSTextInputClient SPI methods as the web view is tearing
down. Without r219765, this test will dereference null and crash.
* TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj:
* TestWebKitAPI/Tests/TestWebKitAPI/mac/NSTextInputClientSPI.h: Added.
* TestWebKitAPI/Tests/mac/WKWebViewSelectionTests.mm:
(TEST):
git-svn-id: https://svn.webkit.org/repository/webkit/trunk@219836
268f45cc-cd09-0410-ab3c-
d52691b4dbfc
+2017-07-24 Wenson Hsieh <wenson_hsieh@apple.com>
+
+ [Mac WK2] Add an API test to cover r219765 (null dereference in [WKWebView dealloc])
+ https://bugs.webkit.org/show_bug.cgi?id=174793
+
+ Reviewed by Tim Horton.
+
+ Adds a new unit test that invokes some asynchronous NSTextInputClient SPI methods as the web view is tearing
+ down. Without r219765, this test will dereference null and crash.
+
+ * TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj:
+ * TestWebKitAPI/Tests/TestWebKitAPI/mac/NSTextInputClientSPI.h: Added.
+ * TestWebKitAPI/Tests/mac/WKWebViewSelectionTests.mm:
+ (TEST):
+
2017-07-24 Basuke Suzuki <Basuke.Suzuki@sony.com>
[Win] Implement Authentication dialog in MiniBrowser
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>"; };
+ 2E7EF7AC1F266A8100DFB67C /* NSTextInputClientSPI.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = NSTextInputClientSPI.h; sourceTree = "<group>"; };
2E9896141D8F092B00739892 /* text-and-password-inputs.html */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.html; path = "text-and-password-inputs.html"; sourceTree = "<group>"; };
2ECFF5541D9B12F800B55394 /* NowPlayingControlsTests.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = NowPlayingControlsTests.mm; sourceTree = "<group>"; };
2EFF06C21D8862120004BB30 /* large-video-offscreen.html */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.html; path = "large-video-offscreen.html"; sourceTree = "<group>"; };
isa = PBXGroup;
children = (
C08587FB13FEC39B001EF4E5 /* InstanceMethodSwizzler.mm */,
+ 2E7EF7AC1F266A8100DFB67C /* NSTextInputClientSPI.h */,
);
path = mac;
sourceTree = "<group>";
--- /dev/null
+/*
+ * Copyright (C) 2017 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.
+ */
+
+#if PLATFORM(MAC)
+
+#if USE(APPLE_INTERNAL_SDK)
+
+#import <AppKit/NSTextInputClient_Private.h>
+
+#else
+
+@protocol NSTextInputClient_Async
+- (void)selectedRangeWithCompletionHandler:(void(^)(NSRange selectedRange))completionHandler;
+- (void)markedRangeWithCompletionHandler:(void(^)(NSRange markedRange))completionHandler;
+- (void)hasMarkedTextWithCompletionHandler:(void(^)(BOOL hasMarkedText))completionHandler;
+@end
+
+#endif
+
+#endif // PLATFORM(MAC)
#if WK_API_ENABLED && PLATFORM(MAC)
+#import "NSTextInputClientSPI.h"
#import "PlatformUtilities.h"
#import "TestWKWebView.h"
EXPECT_STREQ("Hello", selectedText.UTF8String);
}
+TEST(WKWebViewSelectionTests, DoNotCrashWhenCallingTextInputClientMethodsWhileDeallocatingView)
+{
+ NSString *textContent = @"This test should not cause us to dereference null.";
+
+ auto webView = adoptNS([[TestWKWebView alloc] initWithFrame:NSMakeRect(0, 0, 400, 400)]);
+ [webView synchronouslyLoadHTMLString:[NSString stringWithFormat:@"<p>%@</p>", textContent]];
+ [webView removeFromSuperview];
+
+ __unsafe_unretained id <NSTextInputClient_Async> inputClient = (id <NSTextInputClient_Async>)webView.get();
+ [inputClient hasMarkedTextWithCompletionHandler:^(BOOL) {
+ [inputClient selectedRangeWithCompletionHandler:^(NSRange) {
+ [inputClient markedRangeWithCompletionHandler:^(NSRange) { }];
+ }];
+ }];
+
+ EXPECT_WK_STREQ(textContent, [webView stringByEvaluatingJavaScript:@"document.body.textContent"]);
+}
+
#endif // WK_API_ENABLED && PLATFORM(MAC)