Changeset 219836 in webkit


Ignore:
Timestamp:
Jul 24, 2017 1:58:09 PM (7 years ago)
Author:
Wenson Hsieh
Message:

[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):

Location:
trunk/Tools
Files:
3 edited
1 copied

Legend:

Unmodified
Added
Removed
  • trunk/Tools/ChangeLog

    r219830 r219836  
     12017-07-24  Wenson Hsieh  <wenson_hsieh@apple.com>
     2
     3        [Mac WK2] Add an API test to cover r219765 (null dereference in [WKWebView dealloc])
     4        https://bugs.webkit.org/show_bug.cgi?id=174793
     5
     6        Reviewed by Tim Horton.
     7
     8        Adds a new unit test that invokes some asynchronous NSTextInputClient SPI methods as the web view is tearing
     9        down. Without r219765, this test will dereference null and crash.
     10
     11        * TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj:
     12        * TestWebKitAPI/Tests/TestWebKitAPI/mac/NSTextInputClientSPI.h: Added.
     13        * TestWebKitAPI/Tests/mac/WKWebViewSelectionTests.mm:
     14        (TEST):
     15
    1162017-07-24  Basuke Suzuki  <Basuke.Suzuki@sony.com>
    217
  • trunk/Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj

    r219768 r219836  
    10891089                2E7765CC16C4D80A00BA2BB1 /* mainIOS.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = mainIOS.mm; sourceTree = "<group>"; };
    10901090                2E7765CE16C4D81100BA2BB1 /* mainMac.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = mainMac.mm; sourceTree = "<group>"; };
     1091                2E7EF7AC1F266A8100DFB67C /* NSTextInputClientSPI.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = NSTextInputClientSPI.h; sourceTree = "<group>"; };
    10911092                2E9896141D8F092B00739892 /* text-and-password-inputs.html */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.html; path = "text-and-password-inputs.html"; sourceTree = "<group>"; };
    10921093                2ECFF5541D9B12F800B55394 /* NowPlayingControlsTests.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = NowPlayingControlsTests.mm; sourceTree = "<group>"; };
     
    26492650                        children = (
    26502651                                C08587FB13FEC39B001EF4E5 /* InstanceMethodSwizzler.mm */,
     2652                                2E7EF7AC1F266A8100DFB67C /* NSTextInputClientSPI.h */,
    26512653                        );
    26522654                        path = mac;
  • trunk/Tools/TestWebKitAPI/Tests/TestWebKitAPI/mac/NSTextInputClientSPI.h

    r219833 r219836  
    2424 */
    2525
    26 #include "config.h"
     26#if PLATFORM(MAC)
    2727
    28 #if WK_API_ENABLED && PLATFORM(MAC)
     28#if USE(APPLE_INTERNAL_SDK)
    2929
    30 #import "PlatformUtilities.h"
    31 #import "TestWKWebView.h"
     30#import <AppKit/NSTextInputClient_Private.h>
    3231
    33 TEST(WKWebViewSelectionTests, DoubleClickDoesNotSelectTrailingSpace)
    34 {
    35     RetainPtr<TestWKWebView> webView = adoptNS([[TestWKWebView alloc] initWithFrame:NSMakeRect(0, 0, 400, 400)]);
    36     [webView synchronouslyLoadTestPageNamed:@"double-click-does-not-select-trailing-space"];
     32#else
    3733
    38     __block bool finishedSelectingText = false;
    39     [webView performAfterReceivingMessage:@"selected" action:^() {
    40         finishedSelectingText = true;
    41     }];
    42     [webView sendClicksAtPoint:NSMakePoint(200, 200) numberOfClicks:2];
    43     TestWebKitAPI::Util::run(&finishedSelectingText);
     34@protocol NSTextInputClient_Async
     35- (void)selectedRangeWithCompletionHandler:(void(^)(NSRange selectedRange))completionHandler;
     36- (void)markedRangeWithCompletionHandler:(void(^)(NSRange markedRange))completionHandler;
     37- (void)hasMarkedTextWithCompletionHandler:(void(^)(BOOL hasMarkedText))completionHandler;
     38@end
    4439
    45     NSString *selectedText = [webView stringByEvaluatingJavaScript:@"getSelection().getRangeAt(0).toString()"];
    46     EXPECT_STREQ("Hello", selectedText.UTF8String);
    47 }
     40#endif
    4841
    49 #endif // WK_API_ENABLED && PLATFORM(MAC)
     42#endif // PLATFORM(MAC)
  • trunk/Tools/TestWebKitAPI/Tests/mac/WKWebViewSelectionTests.mm

    r213012 r219836  
    2828#if WK_API_ENABLED && PLATFORM(MAC)
    2929
     30#import "NSTextInputClientSPI.h"
    3031#import "PlatformUtilities.h"
    3132#import "TestWKWebView.h"
     
    4748}
    4849
     50TEST(WKWebViewSelectionTests, DoNotCrashWhenCallingTextInputClientMethodsWhileDeallocatingView)
     51{
     52    NSString *textContent = @"This test should not cause us to dereference null.";
     53
     54    auto webView = adoptNS([[TestWKWebView alloc] initWithFrame:NSMakeRect(0, 0, 400, 400)]);
     55    [webView synchronouslyLoadHTMLString:[NSString stringWithFormat:@"<p>%@</p>", textContent]];
     56    [webView removeFromSuperview];
     57
     58    __unsafe_unretained id <NSTextInputClient_Async> inputClient = (id <NSTextInputClient_Async>)webView.get();
     59    [inputClient hasMarkedTextWithCompletionHandler:^(BOOL) {
     60        [inputClient selectedRangeWithCompletionHandler:^(NSRange) {
     61            [inputClient markedRangeWithCompletionHandler:^(NSRange) { }];
     62        }];
     63    }];
     64
     65    EXPECT_WK_STREQ(textContent, [webView stringByEvaluatingJavaScript:@"document.body.textContent"]);
     66}
     67
    4968#endif // WK_API_ENABLED && PLATFORM(MAC)
Note: See TracChangeset for help on using the changeset viewer.