[iOS] Expose SPI to access the current sentence boundary and selection state
authorwenson_hsieh@apple.com <wenson_hsieh@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 14 Jan 2019 20:09:58 +0000 (20:09 +0000)
committerwenson_hsieh@apple.com <wenson_hsieh@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 14 Jan 2019 20:09:58 +0000 (20:09 +0000)
https://bugs.webkit.org/show_bug.cgi?id=193398
<rdar://problem/45893108>

Reviewed by Dean Jackson.

Source/WebKit:

Expose SPI on WKWebView for internal clients to grab information about attributes at the current selection; so
far, this only includes whether the selection is a caret or a range, and whether or not the start of the
selection is at the start of a new sentence.

Test: EditorStateTests.ObserveSelectionAttributeChanges

* Shared/EditorState.cpp:
(WebKit::EditorState::PostLayoutData::encode const):
(WebKit::EditorState::PostLayoutData::decode):
* Shared/EditorState.h:

Add a new bit in EditorState on iOS to compute whether or not the start of the selection is at the start of a
new sentence. This is computed and set when sending post-layout data in `WebPageIOS.mm`.

* UIProcess/API/Cocoa/WKWebView.mm:
(selectionAttributes):
(-[WKWebView _didChangeEditorState]):
(-[WKWebView _selectionAttributes]):

Make the new SPI property support KVO by invoking `-willChangeValueForKey:` and `-didChangeValueForKey:`
whenever the selection attributes change.

* UIProcess/API/Cocoa/WKWebViewPrivate.h:
* WebProcess/WebPage/ios/WebPageIOS.mm:
(WebKit::WebPage::platformEditorState const):

Tools:

Add an API test to verify that an SPI client can observe changes in the `@"_selectionAttributes"` key path on
WKWebView, and that inserting text, deleting, and changing the selection cause selection attributes to change as
expected.

* TestWebKitAPI/EditingTestHarness.h:
* TestWebKitAPI/EditingTestHarness.mm:
(-[EditingTestHarness moveBackward]):
(-[EditingTestHarness moveForward]):
(-[EditingTestHarness moveForwardAndExpectEditorStateWith:]):

Add a couple of new helper methods on EditingTestHarness.

* TestWebKitAPI/Tests/WebKitCocoa/EditorStateTests.mm:
(-[SelectionChangeObserver initWithWebView:]):
(-[SelectionChangeObserver webView]):
(-[SelectionChangeObserver observeValueForKeyPath:ofObject:change:context:]):
(-[SelectionChangeObserver currentSelectionAttributes]):

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@239931 268f45cc-cd09-0410-ab3c-d52691b4dbfc

Source/WebKit/ChangeLog
Source/WebKit/Shared/EditorState.cpp
Source/WebKit/Shared/EditorState.h
Source/WebKit/UIProcess/API/Cocoa/WKWebView.mm
Source/WebKit/UIProcess/API/Cocoa/WKWebViewPrivate.h
Source/WebKit/WebProcess/WebPage/ios/WebPageIOS.mm
Tools/ChangeLog
Tools/TestWebKitAPI/EditingTestHarness.h
Tools/TestWebKitAPI/EditingTestHarness.mm
Tools/TestWebKitAPI/Tests/WebKitCocoa/EditorStateTests.mm

index 618ce99..d7d7e9e 100644 (file)
@@ -1,3 +1,37 @@
+2019-01-14  Wenson Hsieh  <wenson_hsieh@apple.com>
+
+        [iOS] Expose SPI to access the current sentence boundary and selection state
+        https://bugs.webkit.org/show_bug.cgi?id=193398
+        <rdar://problem/45893108>
+
+        Reviewed by Dean Jackson.
+
+        Expose SPI on WKWebView for internal clients to grab information about attributes at the current selection; so
+        far, this only includes whether the selection is a caret or a range, and whether or not the start of the
+        selection is at the start of a new sentence.
+
+        Test: EditorStateTests.ObserveSelectionAttributeChanges
+
+        * Shared/EditorState.cpp:
+        (WebKit::EditorState::PostLayoutData::encode const):
+        (WebKit::EditorState::PostLayoutData::decode):
+        * Shared/EditorState.h:
+
+        Add a new bit in EditorState on iOS to compute whether or not the start of the selection is at the start of a
+        new sentence. This is computed and set when sending post-layout data in `WebPageIOS.mm`.
+
+        * UIProcess/API/Cocoa/WKWebView.mm:
+        (selectionAttributes):
+        (-[WKWebView _didChangeEditorState]):
+        (-[WKWebView _selectionAttributes]):
+
+        Make the new SPI property support KVO by invoking `-willChangeValueForKey:` and `-didChangeValueForKey:`
+        whenever the selection attributes change.
+
+        * UIProcess/API/Cocoa/WKWebViewPrivate.h:
+        * WebProcess/WebPage/ios/WebPageIOS.mm:
+        (WebKit::WebPage::platformEditorState const):
+
 2019-01-14  Carlos Garcia Campos  <cgarcia@igalia.com>
 
         Unreviewed. Update OptionsGTK.cmake and NEWS for 2.23.3 release
 2019-01-14  Carlos Garcia Campos  <cgarcia@igalia.com>
 
         Unreviewed. Update OptionsGTK.cmake and NEWS for 2.23.3 release
index 896c03b..22b8b14 100644 (file)
@@ -132,6 +132,7 @@ void EditorState::PostLayoutData::encode(IPC::Encoder& encoder) const
     encoder << hasPlainText;
     encoder << elementIsTransparentOrFullyClipped;
     encoder << caretColor;
     encoder << hasPlainText;
     encoder << elementIsTransparentOrFullyClipped;
     encoder << caretColor;
+    encoder << atStartOfSentence;
 #endif
 #if PLATFORM(MAC)
     encoder << candidateRequestStartPosition;
 #endif
 #if PLATFORM(MAC)
     encoder << candidateRequestStartPosition;
@@ -191,6 +192,8 @@ bool EditorState::PostLayoutData::decode(IPC::Decoder& decoder, PostLayoutData&
         return false;
     if (!decoder.decode(result.caretColor))
         return false;
         return false;
     if (!decoder.decode(result.caretColor))
         return false;
+    if (!decoder.decode(result.atStartOfSentence))
+        return false;
 #endif
 #if PLATFORM(MAC)
     if (!decoder.decode(result.candidateRequestStartPosition))
 #endif
 #if PLATFORM(MAC)
     if (!decoder.decode(result.candidateRequestStartPosition))
index 0cc25cd..5ee4105 100644 (file)
@@ -109,6 +109,7 @@ struct EditorState {
         bool hasPlainText { false };
         bool elementIsTransparentOrFullyClipped { false };
         WebCore::Color caretColor;
         bool hasPlainText { false };
         bool elementIsTransparentOrFullyClipped { false };
         WebCore::Color caretColor;
+        bool atStartOfSentence { false };
 #endif
 #if PLATFORM(MAC)
         uint64_t candidateRequestStartPosition { 0 };
 #endif
 #if PLATFORM(MAC)
         uint64_t candidateRequestStartPosition { 0 };
index 11633c6..074cddf 100644 (file)
@@ -377,6 +377,7 @@ static Optional<WebCore::ScrollbarOverlayStyle> toCoreScrollbarStyle(_WKOverlayS
     std::unique_ptr<WebKit::WebViewImpl> _impl;
     RetainPtr<WKTextFinderClient> _textFinderClient;
 #endif
     std::unique_ptr<WebKit::WebViewImpl> _impl;
     RetainPtr<WKTextFinderClient> _textFinderClient;
 #endif
+    _WKSelectionAttributes _selectionAttributes;
     CGFloat _minimumEffectiveDeviceWidth;
 }
 
     CGFloat _minimumEffectiveDeviceWidth;
 }
 
@@ -1267,17 +1268,51 @@ static NSDictionary *dictionaryRepresentationForEditorState(const WebKit::Editor
     };
 }
 
     };
 }
 
+static _WKSelectionAttributes selectionAttributes(const WebKit::EditorState& editorState, _WKSelectionAttributes previousAttributes)
+{
+    _WKSelectionAttributes attributes = _WKSelectionAttributeNoSelection;
+    if (editorState.selectionIsNone)
+        return attributes;
+
+    if (editorState.selectionIsRange)
+        attributes |= _WKSelectionAttributeIsRange;
+    else
+        attributes |= _WKSelectionAttributeIsCaret;
+
+    if (!editorState.isMissingPostLayoutData) {
+#if PLATFORM(IOS_FAMILY)
+        if (editorState.postLayoutData().atStartOfSentence)
+            attributes |= _WKSelectionAttributeAtStartOfSentence;
+#endif
+    } else if (previousAttributes & _WKSelectionAttributeAtStartOfSentence)
+        attributes |= _WKSelectionAttributeAtStartOfSentence;
+
+    return attributes;
+}
+
 - (void)_didChangeEditorState
 {
 - (void)_didChangeEditorState
 {
-    id <WKUIDelegatePrivate> uiDelegate = (id <WKUIDelegatePrivate>)self.UIDelegate;
+    auto newSelectionAttributes = selectionAttributes(_page->editorState(), _selectionAttributes);
+    if (_selectionAttributes != newSelectionAttributes) {
+        NSString *selectionAttributesKey = NSStringFromSelector(@selector(_selectionAttributes));
+        [self willChangeValueForKey:selectionAttributesKey];
+        _selectionAttributes = newSelectionAttributes;
+        [self didChangeValueForKey:selectionAttributesKey];
+    }
 
     // FIXME: We should either rename -_webView:editorStateDidChange: to clarify that it's only intended for use when testing,
     // or remove it entirely and use -_webView:didChangeFontAttributes: instead once text alignment is supported in the set of
     // font attributes.
 
     // FIXME: We should either rename -_webView:editorStateDidChange: to clarify that it's only intended for use when testing,
     // or remove it entirely and use -_webView:didChangeFontAttributes: instead once text alignment is supported in the set of
     // font attributes.
+    id <WKUIDelegatePrivate> uiDelegate = (id <WKUIDelegatePrivate>)self.UIDelegate;
     if ([uiDelegate respondsToSelector:@selector(_webView:editorStateDidChange:)])
         [uiDelegate _webView:self editorStateDidChange:dictionaryRepresentationForEditorState(_page->editorState())];
 }
 
     if ([uiDelegate respondsToSelector:@selector(_webView:editorStateDidChange:)])
         [uiDelegate _webView:self editorStateDidChange:dictionaryRepresentationForEditorState(_page->editorState())];
 }
 
+- (_WKSelectionAttributes)_selectionAttributes
+{
+    return _selectionAttributes;
+}
+
 - (void)_showSafeBrowsingWarning:(const WebKit::SafeBrowsingWarning&)warning completionHandler:(CompletionHandler<void(Variant<WebKit::ContinueUnsafeLoad, URL>&&)>&&)completionHandler
 {
     _safeBrowsingWarning = adoptNS([[WKSafeBrowsingWarning alloc] initWithFrame:self.bounds safeBrowsingWarning:warning completionHandler:[weakSelf = WeakObjCPtr<WKWebView>(self), completionHandler = WTFMove(completionHandler)] (auto&& result) mutable {
 - (void)_showSafeBrowsingWarning:(const WebKit::SafeBrowsingWarning&)warning completionHandler:(CompletionHandler<void(Variant<WebKit::ContinueUnsafeLoad, URL>&&)>&&)completionHandler
 {
     _safeBrowsingWarning = adoptNS([[WKSafeBrowsingWarning alloc] initWithFrame:self.bounds safeBrowsingWarning:warning completionHandler:[weakSelf = WeakObjCPtr<WKWebView>(self), completionHandler = WTFMove(completionHandler)] (auto&& result) mutable {
index 29ae793..26c0c34 100644 (file)
@@ -63,6 +63,13 @@ typedef NS_OPTIONS(NSUInteger, _WKCaptureDevices) {
     _WKCaptureDeviceDisplay = 1 << 2,
 } WK_API_AVAILABLE(macosx(10.13), ios(11.0));
 
     _WKCaptureDeviceDisplay = 1 << 2,
 } WK_API_AVAILABLE(macosx(10.13), ios(11.0));
 
+typedef NS_OPTIONS(NSUInteger, _WKSelectionAttributes) {
+    _WKSelectionAttributeNoSelection = 0,
+    _WKSelectionAttributeIsCaret = 1 << 0,
+    _WKSelectionAttributeIsRange = 1 << 1,
+    _WKSelectionAttributeAtStartOfSentence = 1 << 2,
+} WK_API_AVAILABLE(macosx(WK_MAC_TBA), ios(WK_IOS_TBA));
+
 #if TARGET_OS_IPHONE
 
 typedef NS_ENUM(NSUInteger, _WKDragInteractionPolicy) {
 #if TARGET_OS_IPHONE
 
 typedef NS_ENUM(NSUInteger, _WKDragInteractionPolicy) {
@@ -220,6 +227,7 @@ typedef NS_OPTIONS(NSUInteger, _WKRectEdge) {
 - (IBAction)_takeFindStringFromSelection:(id)sender WK_API_AVAILABLE(macosx(WK_MAC_TBA), ios(WK_IOS_TBA));
 
 @property (class, nonatomic, copy, setter=_setStringForFind:) NSString *_stringForFind WK_API_AVAILABLE(macosx(WK_MAC_TBA), ios(WK_IOS_TBA));
 - (IBAction)_takeFindStringFromSelection:(id)sender WK_API_AVAILABLE(macosx(WK_MAC_TBA), ios(WK_IOS_TBA));
 
 @property (class, nonatomic, copy, setter=_setStringForFind:) NSString *_stringForFind WK_API_AVAILABLE(macosx(WK_MAC_TBA), ios(WK_IOS_TBA));
+@property (nonatomic, readonly) _WKSelectionAttributes _selectionAttributes WK_API_AVAILABLE(macosx(WK_MAC_TBA), ios(WK_IOS_TBA));
 
 #if TARGET_OS_IPHONE
 
 
 #if TARGET_OS_IPHONE
 
index 0947f06..c74a636 100644 (file)
@@ -240,6 +240,7 @@ void WebPage::platformEditorState(Frame& frame, EditorState& result, IncludePost
         // FIXME: We should disallow replace when the string contains only CJ characters.
         postLayoutData.isReplaceAllowed = result.isContentEditable && !result.isInPasswordField && !selectedText.isAllSpecialCharacters<isHTMLSpace>();
     }
         // FIXME: We should disallow replace when the string contains only CJ characters.
         postLayoutData.isReplaceAllowed = result.isContentEditable && !result.isInPasswordField && !selectedText.isAllSpecialCharacters<isHTMLSpace>();
     }
+    postLayoutData.atStartOfSentence = frame.selection().selectionAtSentenceStart();
     postLayoutData.insideFixedPosition = startNodeIsInsideFixedPosition || endNodeIsInsideFixedPosition;
     if (!selection.isNone()) {
         if (m_focusedElement && m_focusedElement->renderer()) {
     postLayoutData.insideFixedPosition = startNodeIsInsideFixedPosition || endNodeIsInsideFixedPosition;
     if (!selection.isNone()) {
         if (m_focusedElement && m_focusedElement->renderer()) {
index 79e58ef..7f24d1b 100644 (file)
@@ -1,3 +1,29 @@
+2019-01-14  Wenson Hsieh  <wenson_hsieh@apple.com>
+
+        [iOS] Expose SPI to access the current sentence boundary and selection state
+        https://bugs.webkit.org/show_bug.cgi?id=193398
+        <rdar://problem/45893108>
+
+        Reviewed by Dean Jackson.
+
+        Add an API test to verify that an SPI client can observe changes in the `@"_selectionAttributes"` key path on
+        WKWebView, and that inserting text, deleting, and changing the selection cause selection attributes to change as
+        expected.
+
+        * TestWebKitAPI/EditingTestHarness.h:
+        * TestWebKitAPI/EditingTestHarness.mm:
+        (-[EditingTestHarness moveBackward]):
+        (-[EditingTestHarness moveForward]):
+        (-[EditingTestHarness moveForwardAndExpectEditorStateWith:]):
+
+        Add a couple of new helper methods on EditingTestHarness.
+
+        * TestWebKitAPI/Tests/WebKitCocoa/EditorStateTests.mm:
+        (-[SelectionChangeObserver initWithWebView:]):
+        (-[SelectionChangeObserver webView]):
+        (-[SelectionChangeObserver observeValueForKeyPath:ofObject:change:context:]):
+        (-[SelectionChangeObserver currentSelectionAttributes]):
+
 2019-01-14  Zalan Bujtas  <zalan@apple.com>
 
         [LFC][BFC] Add basic box-sizing support.
 2019-01-14  Zalan Bujtas  <zalan@apple.com>
 
         [LFC][BFC] Add basic box-sizing support.
index 29af321..2f05d9e 100644 (file)
@@ -46,6 +46,8 @@
 - (void)insertHTML:(NSString *)html;
 - (void)selectAll;
 - (void)deleteBackwards;
 - (void)insertHTML:(NSString *)html;
 - (void)selectAll;
 - (void)deleteBackwards;
+- (void)moveBackward;
+- (void)moveForward;
 - (void)insertParagraphAndExpectEditorStateWith:(NSDictionary<NSString *, id> *)entries;
 - (void)insertText:(NSString *)text andExpectEditorStateWith:(NSDictionary<NSString *, id> *)entries;
 - (void)insertHTML:(NSString *)html andExpectEditorStateWith:(NSDictionary<NSString *, id> *)entries;
 - (void)insertParagraphAndExpectEditorStateWith:(NSDictionary<NSString *, id> *)entries;
 - (void)insertText:(NSString *)text andExpectEditorStateWith:(NSDictionary<NSString *, id> *)entries;
 - (void)insertHTML:(NSString *)html andExpectEditorStateWith:(NSDictionary<NSString *, id> *)entries;
index 92b1b9e..0dc5277 100644 (file)
     [self deleteBackwardAndExpectEditorStateWith:nil];
 }
 
     [self deleteBackwardAndExpectEditorStateWith:nil];
 }
 
+- (void)moveBackward
+{
+    [self moveBackwardAndExpectEditorStateWith:nil];
+}
+
+- (void)moveForward
+{
+    [self moveForwardAndExpectEditorStateWith:nil];
+}
+
 - (void)insertText:(NSString *)text andExpectEditorStateWith:(NSDictionary<NSString *, id> *)entries
 {
     [self _execCommand:@"InsertText" argument:text expectEntries:entries];
 - (void)insertText:(NSString *)text andExpectEditorStateWith:(NSDictionary<NSString *, id> *)entries
 {
     [self _execCommand:@"InsertText" argument:text expectEntries:entries];
     [self _execCommand:@"MoveWordBackward" argument:nil expectEntries:entries];
 }
 
     [self _execCommand:@"MoveWordBackward" argument:nil expectEntries:entries];
 }
 
+- (void)moveForwardAndExpectEditorStateWith:(NSDictionary<NSString *, id> *)entries
+{
+    [self _execCommand:@"MoveForward" argument:nil expectEntries:entries];
+}
+
 - (void)toggleBold
 {
     [self _execCommand:@"ToggleBold" argument:nil expectEntries:nil];
 - (void)toggleBold
 {
     [self _execCommand:@"ToggleBold" argument:nil expectEntries:nil];
index 146f951..d787dcd 100644 (file)
 #import "PlatformUtilities.h"
 #import "TestWKWebView.h"
 #import <WebKit/WKWebViewPrivate.h>
 #import "PlatformUtilities.h"
 #import "TestWKWebView.h"
 #import <WebKit/WKWebViewPrivate.h>
+#import <wtf/Vector.h>
 
 #if PLATFORM(IOS_FAMILY)
 #import "UIKitSPI.h"
 #import <UIKit/UIKit.h>
 #endif
 
 
 #if PLATFORM(IOS_FAMILY)
 #import "UIKitSPI.h"
 #import <UIKit/UIKit.h>
 #endif
 
+static void* const SelectionAttributesObservationContext = (void*)&SelectionAttributesObservationContext;
+
+@interface SelectionChangeObserver : NSObject
+- (instancetype)initWithWebView:(TestWKWebView *)webView;
+@property (nonatomic, readonly) TestWKWebView *webView;
+@property (nonatomic, readonly) _WKSelectionAttributes currentSelectionAttributes;
+@end
+
+@implementation SelectionChangeObserver {
+    RetainPtr<TestWKWebView> _webView;
+    Vector<_WKSelectionAttributes> _observedSelectionAttributes;
+}
+
+- (instancetype)initWithWebView:(TestWKWebView *)webView
+{
+    if (!(self = [super init]))
+        return nil;
+
+    _webView = webView;
+    [_webView addObserver:self forKeyPath:@"_selectionAttributes" options:NSKeyValueObservingOptionOld | NSKeyValueObservingOptionNew context:SelectionAttributesObservationContext];
+    return self;
+}
+
+- (TestWKWebView *)webView
+{
+    return _webView.get();
+}
+
+- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary<NSKeyValueChangeKey, id> *)change context:(void *)context
+{
+    if (context == SelectionAttributesObservationContext) {
+        if (!_observedSelectionAttributes.isEmpty())
+            EXPECT_EQ(_observedSelectionAttributes.last(), [change[NSKeyValueChangeOldKey] unsignedIntValue]);
+        _observedSelectionAttributes.append([change[NSKeyValueChangeNewKey] unsignedIntValue]);
+        return;
+    }
+    [super observeValueForKeyPath:keyPath ofObject:object change:change context:context];
+}
+
+- (_WKSelectionAttributes)currentSelectionAttributes
+{
+    return _observedSelectionAttributes.isEmpty() ? _WKSelectionAttributeNoSelection : _observedSelectionAttributes.last();
+}
+
+@end
+
 namespace TestWebKitAPI {
 
 static RetainPtr<EditingTestHarness> setUpEditorStateTestHarness()
 namespace TestWebKitAPI {
 
 static RetainPtr<EditingTestHarness> setUpEditorStateTestHarness()
@@ -312,7 +359,47 @@ TEST(EditorStateTests, CaretColorInContentEditable)
     auto cgRedColor = adoptCF(CGColorCreateCopyByMatchingToColorSpace(colorSpace.get(), kCGRenderingIntentDefault, redColor.CGColor, NULL));
     EXPECT_TRUE(CGColorEqualToColor(cgInsertionPointColor.get(), cgRedColor.get()));
 }
     auto cgRedColor = adoptCF(CGColorCreateCopyByMatchingToColorSpace(colorSpace.get(), kCGRenderingIntentDefault, redColor.CGColor, NULL));
     EXPECT_TRUE(CGColorEqualToColor(cgInsertionPointColor.get(), cgRedColor.get()));
 }
-#endif
+
+TEST(EditorStateTests, ObserveSelectionAttributeChanges)
+{
+    auto webView = adoptNS([[TestWKWebView alloc] initWithFrame:CGRectMake(0, 0, 320, 500)]);
+    auto editor = adoptNS([[EditingTestHarness alloc] initWithWebView:webView.get()]);
+    [webView _setEditable:YES];
+    [webView synchronouslyLoadHTMLString:@"<body></body>"];
+
+    auto observer = adoptNS([[SelectionChangeObserver alloc] initWithWebView:webView.get()]);
+
+    [webView evaluateJavaScript:@"document.body.focus()" completionHandler:nil];
+    [webView waitForNextPresentationUpdate];
+    EXPECT_EQ(_WKSelectionAttributeIsCaret | _WKSelectionAttributeAtStartOfSentence, [observer currentSelectionAttributes]);
+
+    [editor insertText:@"Hello"];
+    EXPECT_EQ(_WKSelectionAttributeIsCaret, [observer currentSelectionAttributes]);
+
+    [editor insertText:@"."];
+    EXPECT_EQ(_WKSelectionAttributeIsCaret | _WKSelectionAttributeAtStartOfSentence, [observer currentSelectionAttributes]);
+
+    [editor moveBackward];
+    EXPECT_EQ(_WKSelectionAttributeIsCaret, [observer currentSelectionAttributes]);
+
+    [editor moveForward];
+    EXPECT_EQ(_WKSelectionAttributeIsCaret | _WKSelectionAttributeAtStartOfSentence, [observer currentSelectionAttributes]);
+
+    [editor deleteBackwards];
+    EXPECT_EQ(_WKSelectionAttributeIsCaret, [observer currentSelectionAttributes]);
+
+    [editor insertParagraph];
+    EXPECT_EQ(_WKSelectionAttributeIsCaret | _WKSelectionAttributeAtStartOfSentence, [observer currentSelectionAttributes]);
+
+    [editor selectAll];
+    EXPECT_EQ(_WKSelectionAttributeIsRange | _WKSelectionAttributeAtStartOfSentence, [observer currentSelectionAttributes]);
+
+    [webView evaluateJavaScript:@"getSelection().removeAllRanges()" completionHandler:nil];
+    [webView waitForNextPresentationUpdate];
+    EXPECT_EQ(_WKSelectionAttributeNoSelection, [observer currentSelectionAttributes]);
+}
+
+#endif // PLATFORM(IOS_FAMILY)
 
 } // namespace TestWebKitAPI
 
 
 } // namespace TestWebKitAPI