Bug 212098 - Inserting a no-break space before or after a marker removes the marker
Summary: Inserting a no-break space before or after a marker removes the marker
Status: NEW
Alias: None
Product: WebKit
Classification: Unclassified
Component: WebCore Misc. (show other bugs)
Version: WebKit Local Build
Hardware: Unspecified Unspecified
: P2 Normal
Assignee: Nobody
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2020-05-19 11:56 PDT by Daniel Bates
Modified: 2020-05-20 08:57 PDT (History)
0 users

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Daniel Bates 2020-05-19 11:56:47 PDT
This affects all markers by code inspection, but is user visible with a dictation alternative marker. (Not user visible with spelling and grammar markers because engine re-runs spell check, which masks the bug).

Steps to reproduce:
1. Add the following test case:

[[

#include "config.h"

#if PLATFORM(IOS_FAMILY)

#import "PlatformUtilities.h"
#import "TestInputDelegate.h"
#import "TestWKWebView.h"
#import "UIKitSPI.h"
#import "WKWebViewConfigurationExtras.h"
#import <WebKit/WKWebViewPrivate.h>
#import <wtf/unicode/CharacterNames.h>

namespace TestWebKitAPI {

static inline NSString *makeNSStringWithCharacter(unichar c)
{
    return [NSString stringWithCharacters:&c length:1];
};

TEST(InsertTextAlternatives, InsertLeadingNoBreakSpace)
{
    auto *configuration = [WKWebViewConfiguration _test_configurationWithTestPlugInClassName:@"WebProcessPlugInWithInternals" configureJSCForTesting:YES];
    auto webView = adoptNS([[TestWKWebView alloc] initWithFrame:NSMakeRect(0, 0, 300, 300) configuration:configuration]);
    auto inputDelegate = adoptNS([[TestInputDelegate alloc] init]);
    [inputDelegate setFocusStartsInputSessionPolicyHandler:[] (WKWebView *, id <_WKFocusedElementInfo>) { return _WKFocusStartsInputSessionPolicyAllow; }];
    [webView _setInputDelegate:inputDelegate.get()];

    [webView synchronouslyLoadHTMLString:@"<body contenteditable='true'></body>"];
    [webView evaluateJavaScriptAndWaitForInputSessionToChange:@"document.body.focus()"];
    [[webView textInputContentView] insertText:@"hello" alternatives:@[@"yellow"] style:UITextAlternativeStyleNone];
    [webView waitForNextPresentationUpdate];

    [webView _synchronouslyExecuteEditCommand:@"MoveToBeginningOfDocument" argument:nil];
    [[webView textInputContentView] insertText:makeNSStringWithCharacter(noBreakSpace)];
    [webView _synchronouslyExecuteEditCommand:@"MoveToBeginningOfDocument" argument:nil];
    [webView waitForNextPresentationUpdate];

    EXPECT_FALSE([[webView objectByEvaluatingJavaScript:@"internals.hasDictationAlternativesMarker(0, 1)"] boolValue]); // <no-break space>
    EXPECT_TRUE([[webView objectByEvaluatingJavaScript:@"internals.hasDictationAlternativesMarker(1, 5)"] boolValue]); // hello
}

TEST(InsertTextAlternatives, InsertTrailingNoBreakSpace)
{
    auto *configuration = [WKWebViewConfiguration _test_configurationWithTestPlugInClassName:@"WebProcessPlugInWithInternals" configureJSCForTesting:YES];
    auto webView = adoptNS([[TestWKWebView alloc] initWithFrame:NSMakeRect(0, 0, 300, 300) configuration:configuration]);
    auto inputDelegate = adoptNS([[TestInputDelegate alloc] init]);
    [inputDelegate setFocusStartsInputSessionPolicyHandler:[] (WKWebView *, id <_WKFocusedElementInfo>) { return _WKFocusStartsInputSessionPolicyAllow; }];
    [webView _setInputDelegate:inputDelegate.get()];

    [webView synchronouslyLoadHTMLString:@"<body contenteditable='true'></body>"];
    [webView evaluateJavaScriptAndWaitForInputSessionToChange:@"document.body.focus()"];
    [[webView textInputContentView] insertText:@"hello" alternatives:@[@"yellow"] style:UITextAlternativeStyleNone];
    [[webView textInputContentView] insertText:makeNSStringWithCharacter(noBreakSpace)];
    [webView _synchronouslyExecuteEditCommand:@"MoveToBeginningOfDocument" argument:nil];
    [webView waitForNextPresentationUpdate];

    EXPECT_TRUE([[webView objectByEvaluatingJavaScript:@"internals.hasDictationAlternativesMarker(0, 5)"] boolValue]); // hello
    EXPECT_FALSE([[webView objectByEvaluatingJavaScript:@"internals.hasDictationAlternativesMarker(5, 1)"] boolValue]); // <no-break space>
}

} // namespace TestWebKitAPI

#endif // PLATFORM(IOS_FAMILY)
]]

2.Run them

Then InsertLeadingNoBreakSpace fails because of:

EXPECT_TRUE([[webView objectByEvaluatingJavaScript:@"internals.hasDictationAlternativesMarker(1, 5)"] boolValue]); // hello

And InsertTrailingNoBreakSpace because of:

EXPECT_TRUE([[webView objectByEvaluatingJavaScript:@"internals.hasDictationAlternativesMarker(0, 5)"] boolValue]); // hello
Comment 1 Daniel Bates 2020-05-20 08:57:17 PDT
I committed failing version of ^^^ in bug #212097.