diff --git a/Source/WebCore/html/HTMLPlugInImageElement.h b/Source/WebCore/html/HTMLPlugInImageElement.h index 644040afd2b33..c050f1c45095c 100644 --- a/Source/WebCore/html/HTMLPlugInImageElement.h +++ b/Source/WebCore/html/HTMLPlugInImageElement.h @@ -45,6 +45,8 @@ class HTMLPlugInImageElement : public HTMLPlugInElement { bool needsWidgetUpdate() const { return m_needsWidgetUpdate; } void setNeedsWidgetUpdate(bool needsWidgetUpdate) { m_needsWidgetUpdate = needsWidgetUpdate; } + + bool shouldBypassCSPForPDFPlugin(const String& contentType) const; protected: HTMLPlugInImageElement(const QualifiedName& tagName, Document&); @@ -68,7 +70,6 @@ class HTMLPlugInImageElement : public HTMLPlugInElement { private: bool isPlugInImageElement() const final { return true; } - bool shouldBypassCSPForPDFPlugin(const String&) const; bool canLoadPlugInContent(const String& relativeURL, const String& mimeType) const; bool canLoadURL(const URL&) const; diff --git a/Source/WebCore/loader/SubframeLoader.cpp b/Source/WebCore/loader/SubframeLoader.cpp index 96a6ea249b99b..dc06ef31367db 100644 --- a/Source/WebCore/loader/SubframeLoader.cpp +++ b/Source/WebCore/loader/SubframeLoader.cpp @@ -128,10 +128,11 @@ bool FrameLoader::SubframeLoader::resourceWillUsePlugin(const String& url, const return shouldUsePlugin(completedURL, mimeType, false, useFallback); } -bool FrameLoader::SubframeLoader::pluginIsLoadable(const URL& url) +bool FrameLoader::SubframeLoader::pluginIsLoadable(const URL& url, const HTMLPlugInImageElement& ownerElement, const String& mimeType) const { if (RefPtr document = m_frame->document()) { - if (document->isSandboxed(SandboxFlag::Plugins)) + bool isFullMainFramePlugin = m_frame->isMainFrame() && dynamicDowncast(m_frame->document()); + if (document->isSandboxed(SandboxFlag::Plugins) && !(isFullMainFramePlugin && ownerElement.shouldBypassCSPForPDFPlugin(mimeType))) return false; Ref securityOrigin = document->securityOrigin(); @@ -185,7 +186,7 @@ bool FrameLoader::SubframeLoader::requestPlugin(HTMLPlugInImageElement& ownerEle if (!(m_frame->settings().legacyPluginQuirkForMailSignaturesEnabled() || MIMETypeRegistry::isApplicationPluginMIMEType(mimeType))) return false; - if (!pluginIsLoadable(url)) + if (!pluginIsLoadable(url, ownerElement, mimeType)) return false; ASSERT(ownerElement.hasTagName(objectTag) || ownerElement.hasTagName(embedTag)); diff --git a/Source/WebCore/loader/SubframeLoader.h b/Source/WebCore/loader/SubframeLoader.h index 9eae505d33cbd..4f801e09207da 100644 --- a/Source/WebCore/loader/SubframeLoader.h +++ b/Source/WebCore/loader/SubframeLoader.h @@ -67,7 +67,7 @@ class FrameLoader::SubframeLoader { bool loadPlugin(HTMLPlugInImageElement&, const URL&, const String& mimeType, const Vector& paramNames, const Vector& paramValues, bool useFallback); bool shouldUsePlugin(const URL&, const String& mimeType, bool hasFallback, bool& useFallback); - bool pluginIsLoadable(const URL&); + bool pluginIsLoadable(const URL&, const HTMLPlugInImageElement&, const String& mimeType) const; URL completeURL(const String&) const; diff --git a/Tools/TestWebKitAPI/SourcesCocoa.txt b/Tools/TestWebKitAPI/SourcesCocoa.txt index ff17e9d2ef24e..5f2b140d43f2e 100644 --- a/Tools/TestWebKitAPI/SourcesCocoa.txt +++ b/Tools/TestWebKitAPI/SourcesCocoa.txt @@ -86,6 +86,7 @@ Tests/WebKitCocoa/ConsoleMessageWithDetails.mm Tests/WebKitCocoa/ContentFiltering.mm Tests/WebKitCocoa/ContentRuleListNotification.mm Tests/WebKitCocoa/ContentSecurityPolicy.mm +Tests/WebKitCocoa/ContentSecurityPolicyTestHelpers.mm Tests/WebKitCocoa/ContextMenus.mm Tests/WebKitCocoa/CookieAcceptPolicy.mm Tests/WebKitCocoa/CookiePrivateBrowsing.mm diff --git a/Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj b/Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj index 7294247967aa1..6797551717eb5 100644 --- a/Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj +++ b/Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj @@ -2436,6 +2436,8 @@ 33BE5AF8137B5AAE00705813 /* MouseMoveAfterCrash_Bundle.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = MouseMoveAfterCrash_Bundle.cpp; sourceTree = ""; }; 33C2C9C02651F5B900E407F6 /* SmallSet.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = SmallSet.cpp; sourceTree = ""; }; 33C39CFF2B07D4B9008FA14B /* WKWebExtensionAPIDeclarativeNetRequest.mm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.objcpp; path = WKWebExtensionAPIDeclarativeNetRequest.mm; sourceTree = ""; }; + 33D799652D0BBC3500B63ED5 /* ContentSecurityPolicyTestHelpers.mm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.objcpp; path = ContentSecurityPolicyTestHelpers.mm; sourceTree = ""; }; + 33D799662D0BBC3500B63ED5 /* ContentSecurityPolicyTestHelpers.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = ContentSecurityPolicyTestHelpers.h; sourceTree = ""; }; 33DB57422CFD46700045C37C /* metalSpecTOC.pdf */ = {isa = PBXFileReference; lastKnownFileType = image.pdf; path = metalSpecTOC.pdf; sourceTree = ""; }; 33DB57442CFD9D100045C37C /* WKWebViewForTestingImmediateActions.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = WKWebViewForTestingImmediateActions.h; sourceTree = ""; }; 33DB57452CFD9D100045C37C /* WKWebViewForTestingImmediateActions.mm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.objcpp; path = WKWebViewForTestingImmediateActions.mm; sourceTree = ""; }; @@ -4285,6 +4287,8 @@ A14FC5891B89927100D107EB /* ContentFilteringPlugIn.mm */, 5CA1DED81F74A87100E71BD3 /* ContentRuleListNotification.mm */, CEBCA12E1E3A660100C73293 /* ContentSecurityPolicy.mm */, + 33D799662D0BBC3500B63ED5 /* ContentSecurityPolicyTestHelpers.h */, + 33D799652D0BBC3500B63ED5 /* ContentSecurityPolicyTestHelpers.mm */, 5C121E8C2410703200486F9B /* ContentWorldPlugIn.mm */, 5C3B1D2522A74EA400BCF4D0 /* ContextMenus.mm */, 5C2936911D5BF63E00DEAB1E /* CookieAcceptPolicy.mm */, diff --git a/Tools/TestWebKitAPI/Tests/WebKit/WKThumbnailView.mm b/Tools/TestWebKitAPI/Tests/WebKit/WKThumbnailView.mm index 3e6ac38f7cfaf..2cab691c7cac1 100644 --- a/Tools/TestWebKitAPI/Tests/WebKit/WKThumbnailView.mm +++ b/Tools/TestWebKitAPI/Tests/WebKit/WKThumbnailView.mm @@ -35,6 +35,7 @@ #import "TestWKWebView.h" #import "UISideCompositingScope.h" #import "WKWebViewConfigurationExtras.h" +#import #import #import #import diff --git a/Tools/TestWebKitAPI/Tests/WebKitCocoa/ContentSecurityPolicy.mm b/Tools/TestWebKitAPI/Tests/WebKitCocoa/ContentSecurityPolicy.mm index 966a0c0b248a9..f620de6cdc0ab 100644 --- a/Tools/TestWebKitAPI/Tests/WebKitCocoa/ContentSecurityPolicy.mm +++ b/Tools/TestWebKitAPI/Tests/WebKitCocoa/ContentSecurityPolicy.mm @@ -25,6 +25,7 @@ #import "config.h" +#import "ContentSecurityPolicyTestHelpers.h" #import "HTTPServer.h" #import "TestNavigationDelegate.h" #import "TestWKWebView.h" @@ -126,3 +127,8 @@ [webView loadRequest:server.request()]; [webView _test_waitForDidFinishNavigation]; } + +TEST(ContentSecurityPolicy, LoadPDFWithSandboxCSPDirective) +{ + TestWebKitAPI::runLoadPDFWithSandboxCSPDirectiveTest([[TestWKWebView alloc] initWithFrame:NSMakeRect(0, 0, 800, 600)]); +} diff --git a/Tools/TestWebKitAPI/Tests/WebKitCocoa/ContentSecurityPolicyTestHelpers.h b/Tools/TestWebKitAPI/Tests/WebKitCocoa/ContentSecurityPolicyTestHelpers.h new file mode 100644 index 0000000000000..9f3e8db07a2e0 --- /dev/null +++ b/Tools/TestWebKitAPI/Tests/WebKitCocoa/ContentSecurityPolicyTestHelpers.h @@ -0,0 +1,34 @@ +/* + * Copyright (C) 2024 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. + */ + +#pragma once + +OBJC_CLASS TestWKWebView; + +namespace TestWebKitAPI { + +void runLoadPDFWithSandboxCSPDirectiveTest(TestWKWebView *); + +} diff --git a/Tools/TestWebKitAPI/Tests/WebKitCocoa/ContentSecurityPolicyTestHelpers.mm b/Tools/TestWebKitAPI/Tests/WebKitCocoa/ContentSecurityPolicyTestHelpers.mm new file mode 100644 index 0000000000000..f6c61ba27b639 --- /dev/null +++ b/Tools/TestWebKitAPI/Tests/WebKitCocoa/ContentSecurityPolicyTestHelpers.mm @@ -0,0 +1,59 @@ +/* + * Copyright (C) 2024 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. + */ + +#import "config.h" +#import "ContentSecurityPolicyTestHelpers.h" + +#import "HTTPServer.h" +#import "PlatformUtilities.h" +#import "TestWKWebView.h" +#import +#import +#import + +namespace TestWebKitAPI { + +static HTTPServer pdfServerWithSandboxCSPDirective() +{ + RetainPtr pdfURL = [NSBundle.test_resourcesBundle URLForResource:@"test" withExtension:@"pdf"]; + HTTPResponse response { [NSData dataWithContentsOfURL:pdfURL.get()] }; + response.headerFields.set("Content-Security-Policy"_s, "sandbox allow-scripts;"_s); + return { { { "/"_s, response } } }; +} + +void runLoadPDFWithSandboxCSPDirectiveTest(TestWKWebView *webView) +{ + HTTPServer server { pdfServerWithSandboxCSPDirective() }; + + [webView synchronouslyLoadRequest:[NSURLRequest requestWithURL:[NSBundle.test_resourcesBundle URLForResource:@"test" withExtension:@"pdf"]]]; + auto colorsWithPlainResponse = [webView sampleColors]; + + [webView synchronouslyLoadRequest:server.request()]; + auto colorsWithCSPResponse = [webView sampleColors]; + + EXPECT_EQ(colorsWithPlainResponse, colorsWithCSPResponse); +} + +} diff --git a/Tools/TestWebKitAPI/Tests/WebKitCocoa/CookieAcceptPolicy.mm b/Tools/TestWebKitAPI/Tests/WebKitCocoa/CookieAcceptPolicy.mm index 22b93785fb3a7..cecf82c3ed1a1 100644 --- a/Tools/TestWebKitAPI/Tests/WebKitCocoa/CookieAcceptPolicy.mm +++ b/Tools/TestWebKitAPI/Tests/WebKitCocoa/CookieAcceptPolicy.mm @@ -26,11 +26,18 @@ #import "config.h" #import "DeprecatedGlobalValues.h" +#import "HTTPServer.h" #import "PlatformUtilities.h" +#import "TestNavigationDelegate.h" +#import "TestUIDelegate.h" +#import "TestWKWebView.h" #import #import #import #import +#import +#import +#import #import #import #import diff --git a/Tools/TestWebKitAPI/Tests/WebKitCocoa/DocumentEditingContext.mm b/Tools/TestWebKitAPI/Tests/WebKitCocoa/DocumentEditingContext.mm index 8e4bfb71b9878..409a97c025822 100644 --- a/Tools/TestWebKitAPI/Tests/WebKitCocoa/DocumentEditingContext.mm +++ b/Tools/TestWebKitAPI/Tests/WebKitCocoa/DocumentEditingContext.mm @@ -32,6 +32,7 @@ #import "TestInputDelegate.h" #import "TestWKWebView.h" #import "UIKitSPIForTesting.h" +#import #import #import #import @@ -208,16 +209,20 @@ - (CGRect)waitForFirstSelectionRectToChange:(CGRect)previousRect @end -static NSString *applyStyle(NSString *htmlString) +namespace DocumentEditingContextTestHelpers { + +NSString *applyStyle(NSString *htmlString) { return [@"" stringByAppendingString:htmlString]; } constexpr unsigned glyphWidth { 25 }; // pixels -static NSString *applyAhemStyle(NSString *htmlString) +NSString *applyAhemStyle(NSString *htmlString) { - return [NSString stringWithFormat:@"%@", glyphWidth, htmlString]; + return [NSString stringWithFormat:@"%@", DocumentEditingContextTestHelpers::glyphWidth, htmlString]; +} + } TEST(DocumentEditingContext, Simple) @@ -226,7 +231,7 @@ - (CGRect)waitForFirstSelectionRectToChange:(CGRect)previousRect UIWKDocumentContext *context; - [webView synchronouslyLoadHTMLString:applyStyle(@"The quick brown fox jumps over the lazy dog.")]; + [webView synchronouslyLoadHTMLString:DocumentEditingContextTestHelpers::applyStyle(@"The quick brown fox jumps over the lazy dog.")]; [webView stringByEvaluatingJavaScript:@"getSelection().setBaseAndExtent(jumps, 0, jumps, 1)"]; context = [webView synchronouslyRequestDocumentContext:makeRequest(UIWKDocumentRequestText, UITextGranularityWord, 1)]; @@ -303,7 +308,7 @@ - (CGRect)waitForFirstSelectionRectToChange:(CGRect)previousRect EXPECT_NSSTRING_EQ("jumps", context.selectedText); // Text rects. - [webView synchronouslyLoadHTMLString:applyAhemStyle(@"MMMM MMM MM M")]; + [webView synchronouslyLoadHTMLString:DocumentEditingContextTestHelpers::applyAhemStyle(@"MMMM MMM MM M")]; [webView stringByEvaluatingJavaScript:@"getSelection().setBaseAndExtent(four, 0, four, 1)"]; context = [webView synchronouslyRequestDocumentContext:makeRequest(UIWKDocumentRequestText | UIWKDocumentRequestRects, UITextGranularityWord, 0)]; EXPECT_NOT_NULL(context); @@ -316,15 +321,15 @@ - (CGRect)waitForFirstSelectionRectToChange:(CGRect)previousRect }]; EXPECT_EQ(4UL, rects.count); #if PLATFORM(MACCATALYST) - EXPECT_EQ(CGRectMake(0, -1, glyphWidth, glyphWidth + 1), rects[0].CGRectValue); - EXPECT_EQ(CGRectMake(glyphWidth, -1, glyphWidth, glyphWidth + 1), rects[1].CGRectValue); - EXPECT_EQ(CGRectMake(2 * glyphWidth, -1, glyphWidth, glyphWidth + 1), rects[2].CGRectValue); - EXPECT_EQ(CGRectMake(3 * glyphWidth, -1, glyphWidth, glyphWidth + 1), rects[3].CGRectValue); + EXPECT_EQ(CGRectMake(0, -1, DocumentEditingContextTestHelpers::glyphWidth, DocumentEditingContextTestHelpers::glyphWidth + 1), rects[0].CGRectValue); + EXPECT_EQ(CGRectMake(DocumentEditingContextTestHelpers::glyphWidth, -1, DocumentEditingContextTestHelpers::glyphWidth, DocumentEditingContextTestHelpers::glyphWidth + 1), rects[1].CGRectValue); + EXPECT_EQ(CGRectMake(2 * DocumentEditingContextTestHelpers::glyphWidth, -1, DocumentEditingContextTestHelpers::glyphWidth, DocumentEditingContextTestHelpers::glyphWidth + 1), rects[2].CGRectValue); + EXPECT_EQ(CGRectMake(3 * DocumentEditingContextTestHelpers::glyphWidth, -1, DocumentEditingContextTestHelpers::glyphWidth, DocumentEditingContextTestHelpers::glyphWidth + 1), rects[3].CGRectValue); #else - EXPECT_EQ(CGRectMake(0, 0, glyphWidth, glyphWidth), rects[0].CGRectValue); - EXPECT_EQ(CGRectMake(glyphWidth, 0, glyphWidth, glyphWidth), rects[1].CGRectValue); - EXPECT_EQ(CGRectMake(2 * glyphWidth, 0, glyphWidth, glyphWidth), rects[2].CGRectValue); - EXPECT_EQ(CGRectMake(3 * glyphWidth, 0, glyphWidth, glyphWidth), rects[3].CGRectValue); + EXPECT_EQ(CGRectMake(0, 0, DocumentEditingContextTestHelpers::glyphWidth, DocumentEditingContextTestHelpers::glyphWidth), rects[0].CGRectValue); + EXPECT_EQ(CGRectMake(DocumentEditingContextTestHelpers::glyphWidth, 0, DocumentEditingContextTestHelpers::glyphWidth, DocumentEditingContextTestHelpers::glyphWidth), rects[1].CGRectValue); + EXPECT_EQ(CGRectMake(2 * DocumentEditingContextTestHelpers::glyphWidth, 0, DocumentEditingContextTestHelpers::glyphWidth, DocumentEditingContextTestHelpers::glyphWidth), rects[2].CGRectValue); + EXPECT_EQ(CGRectMake(3 * DocumentEditingContextTestHelpers::glyphWidth, 0, DocumentEditingContextTestHelpers::glyphWidth, DocumentEditingContextTestHelpers::glyphWidth), rects[3].CGRectValue); #endif rects = [context characterRectsForCharacterRange:NSMakeRange(5, 1)]; EXPECT_EQ(0UL, rects.count); @@ -334,20 +339,20 @@ - (CGRect)waitForFirstSelectionRectToChange:(CGRect)previousRect rects = [context characterRectsForCharacterRange:NSMakeRange(0, 1)]; EXPECT_EQ(1UL, rects.count); #if PLATFORM(MACCATALYST) - EXPECT_EQ(CGRectMake(0, -1, glyphWidth, glyphWidth + 1), rects.firstObject.CGRectValue); + EXPECT_EQ(CGRectMake(0, -1, DocumentEditingContextTestHelpers::glyphWidth, DocumentEditingContextTestHelpers::glyphWidth + 1), rects.firstObject.CGRectValue); #else - EXPECT_EQ(CGRectMake(0, 0, glyphWidth, glyphWidth), rects.firstObject.CGRectValue); + EXPECT_EQ(CGRectMake(0, 0, DocumentEditingContextTestHelpers::glyphWidth, DocumentEditingContextTestHelpers::glyphWidth), rects.firstObject.CGRectValue); #endif rects = [context characterRectsForCharacterRange:NSMakeRange(6, 1)]; EXPECT_EQ(1UL, rects.count); #if PLATFORM(MACCATALYST) - EXPECT_EQ(CGRectMake(6 * glyphWidth, -1, glyphWidth, glyphWidth + 1), rects.firstObject.CGRectValue); + EXPECT_EQ(CGRectMake(6 * DocumentEditingContextTestHelpers::glyphWidth, -1, DocumentEditingContextTestHelpers::glyphWidth, DocumentEditingContextTestHelpers::glyphWidth + 1), rects.firstObject.CGRectValue); #else - EXPECT_EQ(CGRectMake(6 * glyphWidth, 0, glyphWidth, glyphWidth), rects.firstObject.CGRectValue); + EXPECT_EQ(CGRectMake(6 * DocumentEditingContextTestHelpers::glyphWidth, 0, DocumentEditingContextTestHelpers::glyphWidth, DocumentEditingContextTestHelpers::glyphWidth), rects.firstObject.CGRectValue); #endif // Text Input Context - [webView synchronouslyLoadHTMLString:applyStyle(@"")]; + [webView synchronouslyLoadHTMLString:DocumentEditingContextTestHelpers::applyStyle(@"")]; NSArray<_WKTextInputContext *> *textInputContexts = [webView synchronouslyRequestTextInputContextsInRect:[webView frame]]; EXPECT_EQ(1UL, textInputContexts.count); EXPECT_EQ(CGRectMake(0, 0, 50, 50), textInputContexts[0].boundingRect); @@ -459,7 +464,7 @@ - (CGRect)waitForFirstSelectionRectToChange:(CGRect)previousRect TEST(DocumentEditingContext, RequestMarkedTextRectsAndTextOnly) { auto webView = adoptNS([[TestWKWebView alloc] initWithFrame:NSMakeRect(0, 0, 800, 600)]); - [webView synchronouslyLoadHTMLString:applyAhemStyle(@"")]; + [webView synchronouslyLoadHTMLString:DocumentEditingContextTestHelpers::applyAhemStyle(@"")]; [webView stringByEvaluatingJavaScript:@"document.querySelector('input').focus()"]; [webView _synchronouslyExecuteEditCommand:@"InsertText" argument:@"Hello world"]; @@ -525,7 +530,7 @@ static CGRect CGRectFromJSONEncodedDOMRectJSValue(id jsValue) { auto webView = adoptNS([[TestWKWebView alloc] initWithFrame:NSMakeRect(0, 0, 800, 600)]); - [webView synchronouslyLoadHTMLString:applyAhemStyle(@"

Test



")]; + [webView synchronouslyLoadHTMLString:DocumentEditingContextTestHelpers::applyAhemStyle(@"

Test



")]; [webView stringByEvaluatingJavaScript:@"getSelection().setBaseAndExtent(text.lastChild, text.lastChild.length, text.lastChild, text.lastChild.length)"]; // Will focus

. NSArray<_WKTextInputContext *> *textInputContexts = [webView synchronouslyRequestTextInputContextsInRect:[webView frame]]; @@ -550,7 +555,7 @@ static CGRect CGRectFromJSONEncodedDOMRectJSValue(id jsValue) { auto webView = adoptNS([[TestWKWebView alloc] initWithFrame:NSMakeRect(0, 0, 800, 600)]); - [webView synchronouslyLoadHTMLString:applyAhemStyle(@"

Test



")]; + [webView synchronouslyLoadHTMLString:DocumentEditingContextTestHelpers::applyAhemStyle(@"
Test



")]; [webView stringByEvaluatingJavaScript:@"getSelection().setBaseAndExtent(text.lastChild, text.lastChild.length, text.lastChild, text.lastChild.length)"]; // Will focus

. NSArray<_WKTextInputContext *> *textInputContexts = [webView synchronouslyRequestTextInputContextsInRect:[webView frame]]; @@ -575,7 +580,7 @@ static CGRect CGRectFromJSONEncodedDOMRectJSValue(id jsValue) { auto webView = adoptNS([[TestWKWebView alloc] initWithFrame:NSMakeRect(0, 0, 800, 600)]); - [webView synchronouslyLoadHTMLString:applyAhemStyle(@"")]; + [webView synchronouslyLoadHTMLString:DocumentEditingContextTestHelpers::applyAhemStyle(@"")]; [webView stringByEvaluatingJavaScript:@"passwordField.focus(); passwordField.select();"]; auto *context = [webView synchronouslyRequestDocumentContext:makeRequest(UIWKDocumentRequestText, UITextGranularityWord, 1)]; @@ -590,7 +595,7 @@ static CGRect CGRectFromJSONEncodedDOMRectJSValue(id jsValue) auto webView = adoptNS([[TestWKWebView alloc] initWithFrame:NSMakeRect(0, 0, 980, 600)]); // Use "padding: 0" as the default user-agent stylesheet can effect text wrapping. - [webView synchronouslyLoadHTMLString:applyAhemStyle(@"before after")]; // Word wraps "over" onto next line + [webView synchronouslyLoadHTMLString:DocumentEditingContextTestHelpers::applyAhemStyle(@"before after")]; // Word wraps "over" onto next line NSArray<_WKTextInputContext *> *textInputContexts = [webView synchronouslyRequestTextInputContextsInRect:[webView frame]]; EXPECT_EQ(1UL, textInputContexts.count); @@ -606,16 +611,16 @@ static CGRect CGRectFromJSONEncodedDOMRectJSValue(id jsValue) auto webView = adoptNS([[TestWKWebView alloc] initWithFrame:NSMakeRect(0, 0, 980, 600)]); // Use "padding: 0" as the default user-agent stylesheet can effect text wrapping. - [webView synchronouslyLoadHTMLString:applyAhemStyle(@"before after")]; // Word wraps "over" onto next line + [webView synchronouslyLoadHTMLString:DocumentEditingContextTestHelpers::applyAhemStyle(@"before after")]; // Word wraps "over" onto next line NSArray<_WKTextInputContext *> *textInputContexts = [webView synchronouslyRequestTextInputContextsInRect:[webView frame]]; EXPECT_EQ(1UL, textInputContexts.count); auto documentRect = CGRectFromJSONEncodedDOMRectJSValue([webView objectByEvaluatingJavaScript:@"test.getBoundingClientRect().toJSON()"]); - documentRect.origin.x -= glyphWidth * 2; - documentRect.origin.y -= glyphWidth * 2; - documentRect.size.width = glyphWidth; - documentRect.size.height = glyphWidth; + documentRect.origin.x -= DocumentEditingContextTestHelpers::glyphWidth * 2; + documentRect.origin.y -= DocumentEditingContextTestHelpers::glyphWidth * 2; + documentRect.size.width = DocumentEditingContextTestHelpers::glyphWidth; + documentRect.size.height = DocumentEditingContextTestHelpers::glyphWidth; auto *context = [webView synchronouslyRequestDocumentContext:makeRequest(UIWKDocumentRequestText | UIWKDocumentRequestSpatial, UITextGranularityWord, 200, documentRect, textInputContexts[0])]; EXPECT_NULL(context.contextBefore); @@ -628,16 +633,16 @@ static CGRect CGRectFromJSONEncodedDOMRectJSValue(id jsValue) auto webView = adoptNS([[TestWKWebView alloc] initWithFrame:NSMakeRect(0, 0, 980, 600)]); // Use "padding: 0" as the default user-agent stylesheet can effect text wrapping. - [webView synchronouslyLoadHTMLString:applyAhemStyle(@"before after")]; // Word wraps "over" onto next line + [webView synchronouslyLoadHTMLString:DocumentEditingContextTestHelpers::applyAhemStyle(@"before after")]; // Word wraps "over" onto next line NSArray<_WKTextInputContext *> *textInputContexts = [webView synchronouslyRequestTextInputContextsInRect:[webView frame]]; EXPECT_EQ(1UL, textInputContexts.count); auto documentRect = CGRectFromJSONEncodedDOMRectJSValue([webView objectByEvaluatingJavaScript:@"test.getBoundingClientRect().toJSON()"]); - documentRect.origin.x += (documentRect.size.width / 2) - (glyphWidth * 2); - documentRect.origin.y += (documentRect.size.height / 2) - (glyphWidth * 2); - documentRect.size.width = glyphWidth; - documentRect.size.height = glyphWidth; + documentRect.origin.x += (documentRect.size.width / 2) - (DocumentEditingContextTestHelpers::glyphWidth * 2); + documentRect.origin.y += (documentRect.size.height / 2) - (DocumentEditingContextTestHelpers::glyphWidth * 2); + documentRect.size.width = DocumentEditingContextTestHelpers::glyphWidth; + documentRect.size.height = DocumentEditingContextTestHelpers::glyphWidth; auto *context = [webView synchronouslyRequestDocumentContext:makeRequest(UIWKDocumentRequestText | UIWKDocumentRequestSpatial, UITextGranularityWord, 200, documentRect, textInputContexts[0])]; EXPECT_NSSTRING_EQ("The quick b", context.contextBefore); @@ -650,16 +655,16 @@ static CGRect CGRectFromJSONEncodedDOMRectJSValue(id jsValue) auto webView = adoptNS([[TestWKWebView alloc] initWithFrame:NSMakeRect(0, 0, 980, 600)]); // Use "padding: 0" as the default user-agent stylesheet can effect text wrapping. - [webView synchronouslyLoadHTMLString:applyAhemStyle(@"before after")]; // Word wraps "over" onto next line + [webView synchronouslyLoadHTMLString:DocumentEditingContextTestHelpers::applyAhemStyle(@"before after")]; // Word wraps "over" onto next line NSArray<_WKTextInputContext *> *textInputContexts = [webView synchronouslyRequestTextInputContextsInRect:[webView frame]]; EXPECT_EQ(1UL, textInputContexts.count); auto documentRect = CGRectFromJSONEncodedDOMRectJSValue([webView objectByEvaluatingJavaScript:@"test.getBoundingClientRect().toJSON()"]); - documentRect.origin.x += documentRect.size.width + glyphWidth; - documentRect.origin.y += documentRect.size.height + glyphWidth; - documentRect.size.width = glyphWidth; - documentRect.size.height = glyphWidth; + documentRect.origin.x += documentRect.size.width + DocumentEditingContextTestHelpers::glyphWidth; + documentRect.origin.y += documentRect.size.height + DocumentEditingContextTestHelpers::glyphWidth; + documentRect.size.width = DocumentEditingContextTestHelpers::glyphWidth; + documentRect.size.height = DocumentEditingContextTestHelpers::glyphWidth; auto *context = [webView synchronouslyRequestDocumentContext:makeRequest(UIWKDocumentRequestText | UIWKDocumentRequestSpatial, UITextGranularityWord, 200, documentRect, textInputContexts[0])]; EXPECT_NSSTRING_EQ("The quick brown fox jumps over the lazy dog.", context.contextBefore); @@ -670,14 +675,14 @@ static CGRect CGRectFromJSONEncodedDOMRectJSValue(id jsValue) TEST(DocumentEditingContext, SpatialAndCurrentSelectionRequest_RectBeforeRangeSelection) { auto webView = adoptNS([[TestWKWebView alloc] initWithFrame:NSMakeRect(0, 0, 980, 600)]); - [webView synchronouslyLoadHTMLStringAndWaitUntilAllImmediateChildFramesPaint:applyAhemStyle(@"The quick brown fox jumps over the dog.")]; + [webView synchronouslyLoadHTMLStringAndWaitUntilAllImmediateChildFramesPaint:DocumentEditingContextTestHelpers::applyAhemStyle(@"The quick brown fox jumps over the dog.")]; [webView stringByEvaluatingJavaScript:@"getSelection().setBaseAndExtent(jumps, 0, jumps, 1)"]; // Hit testing below the last line is treated as if the line was hit. So, use height of 1 // to ensure we aren't even close to the line height. auto spatialBoxRect = CGRectFromJSONEncodedDOMRectJSValue([webView objectByEvaluatingJavaScript:@"spatialBox.getBoundingClientRect().toJSON()"]); spatialBoxRect.size.height = 1; - EXPECT_EQ(CGRectMake(0, 0, 3 * glyphWidth, 1), spatialBoxRect); + EXPECT_EQ(CGRectMake(0, 0, 3 * DocumentEditingContextTestHelpers::glyphWidth, 1), spatialBoxRect); auto *context = [webView synchronouslyRequestDocumentContext:makeRequest(UIWKDocumentRequestText | UIWKDocumentRequestSpatialAndCurrentSelection, UITextGranularityWord, 2, spatialBoxRect)]; EXPECT_NOT_NULL(context); @@ -689,14 +694,14 @@ static CGRect CGRectFromJSONEncodedDOMRectJSValue(id jsValue) TEST(DocumentEditingContext, SpatialAndCurrentSelectionRequest_RectAfterRangeSelection) { auto webView = adoptNS([[TestWKWebView alloc] initWithFrame:NSMakeRect(0, 0, 980, 600)]); - [webView synchronouslyLoadHTMLStringAndWaitUntilAllImmediateChildFramesPaint:applyAhemStyle(@"The quick brown fox jumps over the dog.")]; + [webView synchronouslyLoadHTMLStringAndWaitUntilAllImmediateChildFramesPaint:DocumentEditingContextTestHelpers::applyAhemStyle(@"The quick brown fox jumps over the dog.")]; [webView stringByEvaluatingJavaScript:@"getSelection().setBaseAndExtent(jumps, 0, jumps, 1)"]; // Hit testing below the last line is treated as if the line was hit. So, use height of 1 // to ensure we aren't even close to the line height. auto spatialBoxRect = CGRectFromJSONEncodedDOMRectJSValue([webView objectByEvaluatingJavaScript:@"spatialBox.getBoundingClientRect().toJSON()"]); spatialBoxRect.size.height = 1; - EXPECT_EQ(CGRectMake(39 * glyphWidth, 0, 0, 1), spatialBoxRect); + EXPECT_EQ(CGRectMake(39 * DocumentEditingContextTestHelpers::glyphWidth, 0, 0, 1), spatialBoxRect); auto *context = [webView synchronouslyRequestDocumentContext:makeRequest(UIWKDocumentRequestText | UIWKDocumentRequestSpatialAndCurrentSelection, UITextGranularityWord, 2, spatialBoxRect)]; EXPECT_NOT_NULL(context); @@ -708,14 +713,14 @@ static CGRect CGRectFromJSONEncodedDOMRectJSValue(id jsValue) TEST(DocumentEditingContext, SpatialAndCurrentSelectionRequest_RectAroundRangeSelection) { auto webView = adoptNS([[TestWKWebView alloc] initWithFrame:NSMakeRect(0, 0, 980, 600)]); - [webView synchronouslyLoadHTMLStringAndWaitUntilAllImmediateChildFramesPaint:applyAhemStyle(@"The quick brown fox jumps over the dog.")]; + [webView synchronouslyLoadHTMLStringAndWaitUntilAllImmediateChildFramesPaint:DocumentEditingContextTestHelpers::applyAhemStyle(@"The quick brown fox jumps over the dog.")]; [webView stringByEvaluatingJavaScript:@"getSelection().setBaseAndExtent(jumps, 0, jumps, 1)"]; // Hit testing below the last line is treated as if the line was hit. So, use height of 1 // to ensure we aren't even close to the line height. auto spatialBoxRect = CGRectFromJSONEncodedDOMRectJSValue([webView objectByEvaluatingJavaScript:@"spatialBox.getBoundingClientRect().toJSON()"]); spatialBoxRect.size.height = 1; - EXPECT_EQ(CGRectMake(16 * glyphWidth, 0, 10 * glyphWidth, 1), spatialBoxRect); + EXPECT_EQ(CGRectMake(16 * DocumentEditingContextTestHelpers::glyphWidth, 0, 10 * DocumentEditingContextTestHelpers::glyphWidth, 1), spatialBoxRect); auto *context = [webView synchronouslyRequestDocumentContext:makeRequest(UIWKDocumentRequestText | UIWKDocumentRequestSpatialAndCurrentSelection, UITextGranularityWord, 2, spatialBoxRect)]; EXPECT_NOT_NULL(context); @@ -727,14 +732,14 @@ static CGRect CGRectFromJSONEncodedDOMRectJSValue(id jsValue) TEST(DocumentEditingContext, SpatialAndCurrentSelectionRequest_RectBeforeCaretSelection) { auto webView = adoptNS([[TestWKWebView alloc] initWithFrame:NSMakeRect(0, 0, 980, 600)]); - [webView synchronouslyLoadHTMLStringAndWaitUntilAllImmediateChildFramesPaint:applyAhemStyle(@"The quick brown fox jumps over the dog.")]; + [webView synchronouslyLoadHTMLStringAndWaitUntilAllImmediateChildFramesPaint:DocumentEditingContextTestHelpers::applyAhemStyle(@"The quick brown fox jumps over the dog.")]; [webView stringByEvaluatingJavaScript:@"getSelection().setBaseAndExtent(jumps, 0, jumps, 0)"]; // Hit testing below the last line is treated as if the line was hit. So, use height of 1 // to ensure we aren't even close to the line height. auto spatialBoxRect = CGRectFromJSONEncodedDOMRectJSValue([webView objectByEvaluatingJavaScript:@"spatialBox.getBoundingClientRect().toJSON()"]); spatialBoxRect.size.height = 1; - EXPECT_EQ(CGRectMake(0, 0, 3 * glyphWidth, 1), spatialBoxRect); + EXPECT_EQ(CGRectMake(0, 0, 3 * DocumentEditingContextTestHelpers::glyphWidth, 1), spatialBoxRect); auto *context = [webView synchronouslyRequestDocumentContext:makeRequest(UIWKDocumentRequestText | UIWKDocumentRequestSpatialAndCurrentSelection, UITextGranularityWord, 2, spatialBoxRect)]; EXPECT_NOT_NULL(context); @@ -746,14 +751,14 @@ static CGRect CGRectFromJSONEncodedDOMRectJSValue(id jsValue) TEST(DocumentEditingContext, SpatialAndCurrentSelectionRequest_RectAfterCaretSelection) { auto webView = adoptNS([[TestWKWebView alloc] initWithFrame:NSMakeRect(0, 0, 980, 600)]); - [webView synchronouslyLoadHTMLStringAndWaitUntilAllImmediateChildFramesPaint:applyAhemStyle(@"The quick brown fox jumps over the dog.")]; + [webView synchronouslyLoadHTMLStringAndWaitUntilAllImmediateChildFramesPaint:DocumentEditingContextTestHelpers::applyAhemStyle(@"The quick brown fox jumps over the dog.")]; [webView stringByEvaluatingJavaScript:@"getSelection().setBaseAndExtent(jumps, 0, jumps, 0)"]; // Hit testing below the last line is treated as if the line was hit. So, use height of 1 // to ensure we aren't even close to the line height. auto spatialBoxRect = CGRectFromJSONEncodedDOMRectJSValue([webView objectByEvaluatingJavaScript:@"spatialBox.getBoundingClientRect().toJSON()"]); spatialBoxRect.size.height = 1; - EXPECT_EQ(CGRectMake(39 * glyphWidth, 0, 0, 1), spatialBoxRect); + EXPECT_EQ(CGRectMake(39 * DocumentEditingContextTestHelpers::glyphWidth, 0, 0, 1), spatialBoxRect); auto *context = [webView synchronouslyRequestDocumentContext:makeRequest(UIWKDocumentRequestText | UIWKDocumentRequestSpatialAndCurrentSelection, UITextGranularityWord, 2, spatialBoxRect)]; EXPECT_NOT_NULL(context); @@ -765,14 +770,14 @@ static CGRect CGRectFromJSONEncodedDOMRectJSValue(id jsValue) TEST(DocumentEditingContext, SpatialAndCurrentSelectionRequest_RectAroundCaretSelection) { auto webView = adoptNS([[TestWKWebView alloc] initWithFrame:NSMakeRect(0, 0, 980, 600)]); - [webView synchronouslyLoadHTMLStringAndWaitUntilAllImmediateChildFramesPaint:applyAhemStyle(@"The quick brown fox jumps over the dog.")]; + [webView synchronouslyLoadHTMLStringAndWaitUntilAllImmediateChildFramesPaint:DocumentEditingContextTestHelpers::applyAhemStyle(@"The quick brown fox jumps over the dog.")]; [webView stringByEvaluatingJavaScript:@"getSelection().setBaseAndExtent(jumps, 0, jumps, 0)"]; // Hit testing below the last line is treated as if the line was hit. So, use height of 1 // to ensure we aren't even close to the line height. auto spatialBoxRect = CGRectFromJSONEncodedDOMRectJSValue([webView objectByEvaluatingJavaScript:@"spatialBox.getBoundingClientRect().toJSON()"]); spatialBoxRect.size.height = 1; - EXPECT_EQ(CGRectMake(16 * glyphWidth, 0, 10 * glyphWidth, 1), spatialBoxRect); + EXPECT_EQ(CGRectMake(16 * DocumentEditingContextTestHelpers::glyphWidth, 0, 10 * DocumentEditingContextTestHelpers::glyphWidth, 1), spatialBoxRect); auto *context = [webView synchronouslyRequestDocumentContext:makeRequest(UIWKDocumentRequestText | UIWKDocumentRequestSpatialAndCurrentSelection, UITextGranularityWord, 2, spatialBoxRect)]; EXPECT_NOT_NULL(context); @@ -786,7 +791,7 @@ static CGRect CGRectFromJSONEncodedDOMRectJSValue(id jsValue) auto webView = adoptNS([[TestWKWebView alloc] initWithFrame:NSMakeRect(0, 0, 980, 600)]); // Use "padding: 0" as the default user-agent stylesheet can effect text wrapping. - [webView synchronouslyLoadHTMLString:applyAhemStyle(@"before The quick brown fox jumps over the lazy dog. after")]; // Word wraps "over" onto next line + [webView synchronouslyLoadHTMLString:DocumentEditingContextTestHelpers::applyAhemStyle(@"before The quick brown fox jumps over the lazy dog. after")]; // Word wraps "over" onto next line [webView stringByEvaluatingJavaScript:@"getSelection().setBaseAndExtent(fox_jumps_over, 0, fox_jumps_over, 1)"]; NSArray<_WKTextInputContext *> *textInputContexts = [webView synchronouslyRequestTextInputContextsInRect:[webView frame]]; @@ -803,17 +808,17 @@ static CGRect CGRectFromJSONEncodedDOMRectJSValue(id jsValue) auto webView = adoptNS([[TestWKWebView alloc] initWithFrame:NSMakeRect(0, 0, 980, 600)]); // Use "padding: 0" as the default user-agent stylesheet can effect text wrapping. - [webView synchronouslyLoadHTMLString:applyAhemStyle(@"before The quick brown fox jumps over the lazy dog. after")]; // Word wraps "over" onto next line + [webView synchronouslyLoadHTMLString:DocumentEditingContextTestHelpers::applyAhemStyle(@"before The quick brown fox jumps over the lazy dog. after")]; // Word wraps "over" onto next line [webView stringByEvaluatingJavaScript:@"getSelection().setBaseAndExtent(fox_jumps_over, 0, fox_jumps_over, 1)"]; NSArray<_WKTextInputContext *> *textInputContexts = [webView synchronouslyRequestTextInputContextsInRect:[webView frame]]; EXPECT_EQ(1UL, textInputContexts.count); auto documentRect = CGRectFromJSONEncodedDOMRectJSValue([webView objectByEvaluatingJavaScript:@"test.getBoundingClientRect().toJSON()"]); - documentRect.origin.x -= glyphWidth * 2; - documentRect.origin.y -= glyphWidth * 2; - documentRect.size.width = glyphWidth; - documentRect.size.height = glyphWidth; + documentRect.origin.x -= DocumentEditingContextTestHelpers::glyphWidth * 2; + documentRect.origin.y -= DocumentEditingContextTestHelpers::glyphWidth * 2; + documentRect.size.width = DocumentEditingContextTestHelpers::glyphWidth; + documentRect.size.height = DocumentEditingContextTestHelpers::glyphWidth; auto *context = [webView synchronouslyRequestDocumentContext:makeRequest(UIWKDocumentRequestText | UIWKDocumentRequestSpatialAndCurrentSelection, UITextGranularityWord, 200, documentRect, textInputContexts[0])]; EXPECT_NSSTRING_EQ("The quick brown ", context.contextBefore); @@ -826,7 +831,7 @@ static CGRect CGRectFromJSONEncodedDOMRectJSValue(id jsValue) auto webView = adoptNS([[TestWKWebView alloc] initWithFrame:NSMakeRect(0, 0, 980, 600)]); // Use "padding: 0" as the default user-agent stylesheet can effect text wrapping. - [webView synchronouslyLoadHTMLString:applyAhemStyle(@"before The quick brown fox jumps over the lazy dog. after")]; // Word wraps "over" onto next line + [webView synchronouslyLoadHTMLString:DocumentEditingContextTestHelpers::applyAhemStyle(@"before The quick brown fox jumps over the lazy dog. after")]; // Word wraps "over" onto next line [webView stringByEvaluatingJavaScript:@"getSelection().setBaseAndExtent(fox_jumps_over, 0, fox_jumps_over, 1)"]; NSArray<_WKTextInputContext *> *textInputContexts = [webView synchronouslyRequestTextInputContextsInRect:[webView frame]]; @@ -835,10 +840,10 @@ static CGRect CGRectFromJSONEncodedDOMRectJSValue(id jsValue) auto selectionBoxRect = CGRectFromJSONEncodedDOMRectJSValue([webView objectByEvaluatingJavaScript:@"fox_jumps_over.getBoundingClientRect().toJSON()"]); auto documentRect = CGRectFromJSONEncodedDOMRectJSValue([webView objectByEvaluatingJavaScript:@"test.getBoundingClientRect().toJSON()"]); - documentRect.origin.x = ((documentRect.origin.x + selectionBoxRect.origin.x) / 2) - (glyphWidth * 2); - documentRect.origin.y = ((documentRect.origin.y + selectionBoxRect.origin.y) / 2) - (glyphWidth * 2); - documentRect.size.width = glyphWidth; - documentRect.size.height = glyphWidth; + documentRect.origin.x = ((documentRect.origin.x + selectionBoxRect.origin.x) / 2) - (DocumentEditingContextTestHelpers::glyphWidth * 2); + documentRect.origin.y = ((documentRect.origin.y + selectionBoxRect.origin.y) / 2) - (DocumentEditingContextTestHelpers::glyphWidth * 2); + documentRect.size.width = DocumentEditingContextTestHelpers::glyphWidth; + documentRect.size.height = DocumentEditingContextTestHelpers::glyphWidth; auto *context = [webView synchronouslyRequestDocumentContext:makeRequest(UIWKDocumentRequestText | UIWKDocumentRequestSpatialAndCurrentSelection, UITextGranularityWord, 200, documentRect, textInputContexts[0])]; EXPECT_NSSTRING_EQ("The quick brown ", context.contextBefore); @@ -851,7 +856,7 @@ static CGRect CGRectFromJSONEncodedDOMRectJSValue(id jsValue) auto webView = adoptNS([[TestWKWebView alloc] initWithFrame:NSMakeRect(0, 0, 980, 600)]); // Use "padding: 0" as the default user-agent stylesheet can effect text wrapping. - [webView synchronouslyLoadHTMLString:applyAhemStyle(@"before The quick brown fox jumps over the lazy dog. after")]; // Word wraps "over" onto next line + [webView synchronouslyLoadHTMLString:DocumentEditingContextTestHelpers::applyAhemStyle(@"before The quick brown fox jumps over the lazy dog. after")]; // Word wraps "over" onto next line [webView stringByEvaluatingJavaScript:@"getSelection().setBaseAndExtent(fox_jumps_over, 0, fox_jumps_over, 1)"]; NSArray<_WKTextInputContext *> *textInputContexts = [webView synchronouslyRequestTextInputContextsInRect:[webView frame]]; @@ -860,10 +865,10 @@ static CGRect CGRectFromJSONEncodedDOMRectJSValue(id jsValue) auto selectionBoxRect = CGRectFromJSONEncodedDOMRectJSValue([webView objectByEvaluatingJavaScript:@"fox_jumps_over.getBoundingClientRect().toJSON()"]); auto documentRect = CGRectFromJSONEncodedDOMRectJSValue([webView objectByEvaluatingJavaScript:@"test.getBoundingClientRect().toJSON()"]); - documentRect.origin.x = ((documentRect.origin.x + documentRect.size.width + selectionBoxRect.origin.x + selectionBoxRect.size.width) / 2) + glyphWidth; - documentRect.origin.y = ((documentRect.origin.y + documentRect.size.height + selectionBoxRect.origin.y + selectionBoxRect.size.height) / 2) + glyphWidth; - documentRect.size.width = glyphWidth; - documentRect.size.height = glyphWidth; + documentRect.origin.x = ((documentRect.origin.x + documentRect.size.width + selectionBoxRect.origin.x + selectionBoxRect.size.width) / 2) + DocumentEditingContextTestHelpers::glyphWidth; + documentRect.origin.y = ((documentRect.origin.y + documentRect.size.height + selectionBoxRect.origin.y + selectionBoxRect.size.height) / 2) + DocumentEditingContextTestHelpers::glyphWidth; + documentRect.size.width = DocumentEditingContextTestHelpers::glyphWidth; + documentRect.size.height = DocumentEditingContextTestHelpers::glyphWidth; auto *context = [webView synchronouslyRequestDocumentContext:makeRequest(UIWKDocumentRequestText | UIWKDocumentRequestSpatialAndCurrentSelection, UITextGranularityWord, 200, documentRect, textInputContexts[0])]; EXPECT_NSSTRING_EQ("The quick brown ", context.contextBefore); @@ -876,17 +881,17 @@ static CGRect CGRectFromJSONEncodedDOMRectJSValue(id jsValue) auto webView = adoptNS([[TestWKWebView alloc] initWithFrame:NSMakeRect(0, 0, 980, 600)]); // Use "padding: 0" as the default user-agent stylesheet can effect text wrapping. - [webView synchronouslyLoadHTMLString:applyAhemStyle(@"before The quick brown fox jumps over the lazy dog. after")]; // Word wraps "over" onto next line + [webView synchronouslyLoadHTMLString:DocumentEditingContextTestHelpers::applyAhemStyle(@"before The quick brown fox jumps over the lazy dog. after")]; // Word wraps "over" onto next line [webView stringByEvaluatingJavaScript:@"getSelection().setBaseAndExtent(fox_jumps_over, 0, fox_jumps_over, 1)"]; NSArray<_WKTextInputContext *> *textInputContexts = [webView synchronouslyRequestTextInputContextsInRect:[webView frame]]; EXPECT_EQ(1UL, textInputContexts.count); auto documentRect = CGRectFromJSONEncodedDOMRectJSValue([webView objectByEvaluatingJavaScript:@"test.getBoundingClientRect().toJSON()"]); - documentRect.origin.x += documentRect.size.width + (glyphWidth * 2); - documentRect.origin.y += documentRect.size.height + (glyphWidth * 2); - documentRect.size.width = glyphWidth; - documentRect.size.height = glyphWidth; + documentRect.origin.x += documentRect.size.width + (DocumentEditingContextTestHelpers::glyphWidth * 2); + documentRect.origin.y += documentRect.size.height + (DocumentEditingContextTestHelpers::glyphWidth * 2); + documentRect.size.width = DocumentEditingContextTestHelpers::glyphWidth; + documentRect.size.height = DocumentEditingContextTestHelpers::glyphWidth; auto *context = [webView synchronouslyRequestDocumentContext:makeRequest(UIWKDocumentRequestText | UIWKDocumentRequestSpatialAndCurrentSelection, UITextGranularityWord, 200, documentRect, textInputContexts[0])]; EXPECT_NSSTRING_EQ("The quick brown ", context.contextBefore); @@ -898,7 +903,7 @@ static CGRect CGRectFromJSONEncodedDOMRectJSValue(id jsValue) { auto webView = adoptNS([[TestWKWebView alloc] initWithFrame:CGRectMake(0, 0, 980, 600)]); - [webView synchronouslyLoadHTMLString:applyAhemStyle(@"hello world this is a test")]; + [webView synchronouslyLoadHTMLString:DocumentEditingContextTestHelpers::applyAhemStyle(@"hello world this is a test")]; [webView stringByEvaluatingJavaScript:@"document.querySelector('textarea').select()"]; auto *context = [webView synchronouslyRequestDocumentContext:makeRequest(UIWKDocumentRequestText | UIWKDocumentRequestSpatialAndCurrentSelection, UITextGranularityWord, 200, CGRectMake(0, 0, 980, 600))]; @@ -911,7 +916,7 @@ static CGRect CGRectFromJSONEncodedDOMRectJSValue(id jsValue) { auto webView = adoptNS([[TestWKWebView alloc] initWithFrame:NSMakeRect(0, 0, 800, 600)]); // Use "padding: 0" as the default user-agent stylesheet can effect text wrapping. - [webView synchronouslyLoadHTMLString:applyAhemStyle(@"")]; // Word wraps "over" onto next line + [webView synchronouslyLoadHTMLString:DocumentEditingContextTestHelpers::applyAhemStyle(@"")]; // Word wraps "over" onto next line [webView stringByEvaluatingJavaScript:@"test.focus(); test.setSelectionRange(25, 25)"]; // Place caret after 's' in "jumps". auto *context = [webView synchronouslyRequestDocumentContext:makeRequest(UIWKDocumentRequestText | UIWKDocumentRequestRects, UITextGranularityWord, 2)]; @@ -931,26 +936,26 @@ static CGRect CGRectFromJSONEncodedDOMRectJSValue(id jsValue) if (textRects.count >= 18) { CGFloat x = 401; - EXPECT_EQ(CGRectMake(x + 0 * glyphWidth, yPos, 25, height), textRects[0].CGRectValue); // f - EXPECT_EQ(CGRectMake(x + 1 * glyphWidth, yPos, 25, height), textRects[1].CGRectValue); // o - EXPECT_EQ(CGRectMake(x + 2 * glyphWidth, yPos, 25, height), textRects[2].CGRectValue); // x - EXPECT_EQ(CGRectMake(x + 3 * glyphWidth, yPos, 25, height), textRects[3].CGRectValue); // - EXPECT_EQ(CGRectMake(x + 4 * glyphWidth, yPos, 25, height), textRects[4].CGRectValue); // j - EXPECT_EQ(CGRectMake(x + 5 * glyphWidth, yPos, 25, height), textRects[5].CGRectValue); // u - EXPECT_EQ(CGRectMake(x + 6 * glyphWidth, yPos, 25, height), textRects[6].CGRectValue); // m - EXPECT_EQ(CGRectMake(x + 7 * glyphWidth, yPos, 25, height), textRects[7].CGRectValue); // p - EXPECT_EQ(CGRectMake(x + 8 * glyphWidth, yPos, 25, height), textRects[8].CGRectValue); // s - EXPECT_EQ(CGRectMake(x + 9 * glyphWidth, yPos, 25, height), textRects[9].CGRectValue); // + EXPECT_EQ(CGRectMake(x + 0 * DocumentEditingContextTestHelpers::glyphWidth, yPos, 25, height), textRects[0].CGRectValue); // f + EXPECT_EQ(CGRectMake(x + 1 * DocumentEditingContextTestHelpers::glyphWidth, yPos, 25, height), textRects[1].CGRectValue); // o + EXPECT_EQ(CGRectMake(x + 2 * DocumentEditingContextTestHelpers::glyphWidth, yPos, 25, height), textRects[2].CGRectValue); // x + EXPECT_EQ(CGRectMake(x + 3 * DocumentEditingContextTestHelpers::glyphWidth, yPos, 25, height), textRects[3].CGRectValue); // + EXPECT_EQ(CGRectMake(x + 4 * DocumentEditingContextTestHelpers::glyphWidth, yPos, 25, height), textRects[4].CGRectValue); // j + EXPECT_EQ(CGRectMake(x + 5 * DocumentEditingContextTestHelpers::glyphWidth, yPos, 25, height), textRects[5].CGRectValue); // u + EXPECT_EQ(CGRectMake(x + 6 * DocumentEditingContextTestHelpers::glyphWidth, yPos, 25, height), textRects[6].CGRectValue); // m + EXPECT_EQ(CGRectMake(x + 7 * DocumentEditingContextTestHelpers::glyphWidth, yPos, 25, height), textRects[7].CGRectValue); // p + EXPECT_EQ(CGRectMake(x + 8 * DocumentEditingContextTestHelpers::glyphWidth, yPos, 25, height), textRects[8].CGRectValue); // s + EXPECT_EQ(CGRectMake(x + 9 * DocumentEditingContextTestHelpers::glyphWidth, yPos, 25, height), textRects[9].CGRectValue); // x = 1; - EXPECT_EQ(CGRectMake(x + 0 * glyphWidth, 25 + yPos, 25, height), textRects[10].CGRectValue); // o - EXPECT_EQ(CGRectMake(x + 1 * glyphWidth, 25 + yPos, 25, height), textRects[11].CGRectValue); // v - EXPECT_EQ(CGRectMake(x + 2 * glyphWidth, 25 + yPos, 25, height), textRects[12].CGRectValue); // e - EXPECT_EQ(CGRectMake(x + 3 * glyphWidth, 25 + yPos, 25, height), textRects[13].CGRectValue); // r - EXPECT_EQ(CGRectMake(x + 4 * glyphWidth, 25 + yPos, 25, height), textRects[14].CGRectValue); // - EXPECT_EQ(CGRectMake(x + 5 * glyphWidth, 25 + yPos, 25, height), textRects[15].CGRectValue); // t - EXPECT_EQ(CGRectMake(x + 6 * glyphWidth, 25 + yPos, 25, height), textRects[16].CGRectValue); // h - EXPECT_EQ(CGRectMake(x + 7 * glyphWidth, 25 + yPos, 25, height), textRects[17].CGRectValue); // e + EXPECT_EQ(CGRectMake(x + 0 * DocumentEditingContextTestHelpers::glyphWidth, 25 + yPos, 25, height), textRects[10].CGRectValue); // o + EXPECT_EQ(CGRectMake(x + 1 * DocumentEditingContextTestHelpers::glyphWidth, 25 + yPos, 25, height), textRects[11].CGRectValue); // v + EXPECT_EQ(CGRectMake(x + 2 * DocumentEditingContextTestHelpers::glyphWidth, 25 + yPos, 25, height), textRects[12].CGRectValue); // e + EXPECT_EQ(CGRectMake(x + 3 * DocumentEditingContextTestHelpers::glyphWidth, 25 + yPos, 25, height), textRects[13].CGRectValue); // r + EXPECT_EQ(CGRectMake(x + 4 * DocumentEditingContextTestHelpers::glyphWidth, 25 + yPos, 25, height), textRects[14].CGRectValue); // + EXPECT_EQ(CGRectMake(x + 5 * DocumentEditingContextTestHelpers::glyphWidth, 25 + yPos, 25, height), textRects[15].CGRectValue); // t + EXPECT_EQ(CGRectMake(x + 6 * DocumentEditingContextTestHelpers::glyphWidth, 25 + yPos, 25, height), textRects[16].CGRectValue); // h + EXPECT_EQ(CGRectMake(x + 7 * DocumentEditingContextTestHelpers::glyphWidth, 25 + yPos, 25, height), textRects[17].CGRectValue); // e } } @@ -958,7 +963,7 @@ static CGRect CGRectFromJSONEncodedDOMRectJSValue(id jsValue) { auto webView = adoptNS([[TestWKWebView alloc] initWithFrame:NSMakeRect(0, 0, 800, 600)]); // Use "padding: 0" for the ")])]; + [webView synchronouslyLoadHTMLString:DocumentEditingContextTestHelpers::applyAhemStyle([NSString stringWithFormat:@"", DocumentEditingContextTestHelpers::applyAhemStyle(@"")])]; auto *context = [webView synchronouslyRequestDocumentContext:makeRequest(UIWKDocumentRequestText | UIWKDocumentRequestRects, UITextGranularityWord, 1)]; EXPECT_NOT_NULL(context); @@ -977,9 +982,9 @@ static CGRect CGRectFromJSONEncodedDOMRectJSValue(id jsValue) if (textRects.count >= 3) { CGFloat x = 26; - EXPECT_EQ(CGRectMake(x + 0 * glyphWidth, yPos, 25, height), textRects[0].CGRectValue); // T - EXPECT_EQ(CGRectMake(x + 1 * glyphWidth, yPos, 25, height), textRects[1].CGRectValue); // h - EXPECT_EQ(CGRectMake(x + 2 * glyphWidth, yPos, 25, height), textRects[2].CGRectValue); // e + EXPECT_EQ(CGRectMake(x + 0 * DocumentEditingContextTestHelpers::glyphWidth, yPos, 25, height), textRects[0].CGRectValue); // T + EXPECT_EQ(CGRectMake(x + 1 * DocumentEditingContextTestHelpers::glyphWidth, yPos, 25, height), textRects[1].CGRectValue); // h + EXPECT_EQ(CGRectMake(x + 2 * DocumentEditingContextTestHelpers::glyphWidth, yPos, 25, height), textRects[2].CGRectValue); // e } } @@ -988,8 +993,8 @@ static CGRect CGRectFromJSONEncodedDOMRectJSValue(id jsValue) { auto webView = adoptNS([[TestWKWebView alloc] initWithFrame:NSMakeRect(0, 0, 800, 600)]); // Use "padding: 0" for the " + [webView synchronouslyLoadHTMLString:DocumentEditingContextTestHelpers::applyAhemStyle([NSString stringWithFormat:@"", + DocumentEditingContextTestHelpers::applyAhemStyle(@"

" "")])]; @@ -1009,9 +1014,9 @@ static CGRect CGRectFromJSONEncodedDOMRectJSValue(id jsValue) if (textRects.count >= 3) { CGFloat x = 26; - EXPECT_EQ(CGRectMake(x + 0 * glyphWidth, yPos, 25, height), textRects[0].CGRectValue); // T - EXPECT_EQ(CGRectMake(x + 1 * glyphWidth, yPos, 25, height), textRects[1].CGRectValue); // h - EXPECT_EQ(CGRectMake(x + 2 * glyphWidth, yPos, 25, height), textRects[2].CGRectValue); // e + EXPECT_EQ(CGRectMake(x + 0 * DocumentEditingContextTestHelpers::glyphWidth, yPos, 25, height), textRects[0].CGRectValue); // T + EXPECT_EQ(CGRectMake(x + 1 * DocumentEditingContextTestHelpers::glyphWidth, yPos, 25, height), textRects[1].CGRectValue); // h + EXPECT_EQ(CGRectMake(x + 2 * DocumentEditingContextTestHelpers::glyphWidth, yPos, 25, height), textRects[2].CGRectValue); // e } } @@ -1020,7 +1025,7 @@ static CGRect CGRectFromJSONEncodedDOMRectJSValue(id jsValue) TEST(DocumentEditingContext, RequestFirstTwoWords) { auto webView = adoptNS([[TestWKWebView alloc] initWithFrame:NSMakeRect(0, 0, 800, 600)]); - [webView synchronouslyLoadHTMLString:applyAhemStyle(@"

The quick brown fox jumps over the lazy dog.

")]; + [webView synchronouslyLoadHTMLString:DocumentEditingContextTestHelpers::applyAhemStyle(@"

The quick brown fox jumps over the lazy dog.

")]; [webView stringByEvaluatingJavaScript:@"getSelection().setBaseAndExtent(text.firstChild, 0, text.firstChild, 0)"]; // Will focus

. auto *context = [webView synchronouslyRequestDocumentContext:makeRequest(UIWKDocumentRequestText | UIWKDocumentRequestRects, UITextGranularityWord, 2)]; @@ -1057,7 +1062,7 @@ static CGRect CGRectFromJSONEncodedDOMRectJSValue(id jsValue) TEST(DocumentEditingContext, RequestFirstTwoWordWithLeadingNonBreakableSpace) { auto webView = adoptNS([[TestWKWebView alloc] initWithFrame:NSMakeRect(0, 0, 800, 600)]); - [webView synchronouslyLoadHTMLString:applyAhemStyle(@"

 The quick brown fox jumps over the lazy dog.

")]; + [webView synchronouslyLoadHTMLString:DocumentEditingContextTestHelpers::applyAhemStyle(@"

 The quick brown fox jumps over the lazy dog.

")]; [webView stringByEvaluatingJavaScript:@"getSelection().setBaseAndExtent(text.firstChild, 0, text.firstChild, 0)"]; // Will focus

. auto *context = [webView synchronouslyRequestDocumentContext:makeRequest(UIWKDocumentRequestText | UIWKDocumentRequestRects, UITextGranularityWord, 1)]; @@ -1084,7 +1089,7 @@ static CGRect CGRectFromJSONEncodedDOMRectJSValue(id jsValue) TEST(DocumentEditingContext, RequestLastWord) { auto webView = adoptNS([[TestWKWebView alloc] initWithFrame:NSMakeRect(0, 0, 800, 600)]); - [webView synchronouslyLoadHTMLString:applyAhemStyle(@"

The quick brown fox jumps over the lazy dog.

")]; + [webView synchronouslyLoadHTMLString:DocumentEditingContextTestHelpers::applyAhemStyle(@"

The quick brown fox jumps over the lazy dog.

")]; [webView stringByEvaluatingJavaScript:@"getSelection().setBaseAndExtent(text.firstChild, text.firstChild.length, text.firstChild, text.firstChild.length)"]; // Will focus

. auto *context = [webView synchronouslyRequestDocumentContext:makeRequest(UIWKDocumentRequestText | UIWKDocumentRequestRects, UITextGranularityWord, 1)]; @@ -1111,7 +1116,7 @@ static CGRect CGRectFromJSONEncodedDOMRectJSValue(id jsValue) TEST(DocumentEditingContext, RequestLastWordWithTrailingNonBreakableSpace) { auto webView = adoptNS([[TestWKWebView alloc] initWithFrame:NSMakeRect(0, 0, 800, 600)]); - [webView synchronouslyLoadHTMLString:applyAhemStyle(@"

The quick brown fox jumps over the lazy dog. 

")]; + [webView synchronouslyLoadHTMLString:DocumentEditingContextTestHelpers::applyAhemStyle(@"

The quick brown fox jumps over the lazy dog. 

")]; [webView stringByEvaluatingJavaScript:@"getSelection().setBaseAndExtent(text.firstChild, text.firstChild.length, text.firstChild, text.firstChild.length)"]; // Will focus

. auto *context = [webView synchronouslyRequestDocumentContext:makeRequest(UIWKDocumentRequestText | UIWKDocumentRequestRects, UITextGranularityWord, 1)]; @@ -1140,7 +1145,7 @@ static CGRect CGRectFromJSONEncodedDOMRectJSValue(id jsValue) TEST(DocumentEditingContext, RequestTwoWordsAroundSelection) { auto webView = adoptNS([[TestWKWebView alloc] initWithFrame:NSMakeRect(0, 0, 800, 600)]); - [webView synchronouslyLoadHTMLString:applyStyle(@"The quick brown fox jumps over the lazy dog.")]; + [webView synchronouslyLoadHTMLString:DocumentEditingContextTestHelpers::applyStyle(@"The quick brown fox jumps over the lazy dog.")]; [webView stringByEvaluatingJavaScript:@"getSelection().setBaseAndExtent(jumps, 0, jumps, 1)"]; auto *context = [webView synchronouslyRequestDocumentContext:makeRequest(UIWKDocumentRequestText, UITextGranularityWord, 2)]; @@ -1153,7 +1158,7 @@ static CGRect CGRectFromJSONEncodedDOMRectJSValue(id jsValue) TEST(DocumentEditingContext, RequestThreeWordsAroundSelection) { auto webView = adoptNS([[TestWKWebView alloc] initWithFrame:NSMakeRect(0, 0, 800, 600)]); - [webView synchronouslyLoadHTMLString:applyStyle(@"The quick brown fox jumps over the lazy dog.")]; + [webView synchronouslyLoadHTMLString:DocumentEditingContextTestHelpers::applyStyle(@"The quick brown fox jumps over the lazy dog.")]; [webView stringByEvaluatingJavaScript:@"getSelection().setBaseAndExtent(jumps, 0, jumps, 1)"]; auto *context = [webView synchronouslyRequestDocumentContext:makeRequest(UIWKDocumentRequestText, UITextGranularityWord, 3)]; @@ -1166,7 +1171,7 @@ static CGRect CGRectFromJSONEncodedDOMRectJSValue(id jsValue) TEST(DocumentEditingContext, RequestBeforeInlinePlaceholder) { auto webView = adoptNS([[TestWKWebView alloc] initWithFrame:NSMakeRect(0, 0, 800, 600)]); - [webView synchronouslyLoadHTMLString:applyStyle(@"hello world")]; + [webView synchronouslyLoadHTMLString:DocumentEditingContextTestHelpers::applyStyle(@"hello world")]; [webView stringByEvaluatingJavaScript:@"getSelection().setPosition(wrapper.firstChild, 5)"]; // Place cursor after "hello". auto *placeholder = [webView synchronouslyInsertTextPlaceholderWithSize:CGSizeMake(5, 5)]; @@ -1183,7 +1188,7 @@ static CGRect CGRectFromJSONEncodedDOMRectJSValue(id jsValue) TEST(DocumentEditingContext, RequestAfterInlinePlaceholder) { auto webView = adoptNS([[TestWKWebView alloc] initWithFrame:NSMakeRect(0, 0, 800, 600)]); - [webView synchronouslyLoadHTMLString:applyStyle(@"hello world")]; + [webView synchronouslyLoadHTMLString:DocumentEditingContextTestHelpers::applyStyle(@"hello world")]; [webView stringByEvaluatingJavaScript:@"getSelection().setPosition(wrapper.firstChild, 6)"]; // Place cursor before "world". auto *placeholder = [webView synchronouslyInsertTextPlaceholderWithSize:CGSizeMake(5, 5)]; @@ -1200,7 +1205,7 @@ static CGRect CGRectFromJSONEncodedDOMRectJSValue(id jsValue) TEST(DocumentEditingContext, RequestBeforeBlockPlaceholder) { auto webView = adoptNS([[TestWKWebView alloc] initWithFrame:NSMakeRect(0, 0, 800, 600)]); - [webView synchronouslyLoadHTMLString:applyStyle(@"hello world")]; + [webView synchronouslyLoadHTMLString:DocumentEditingContextTestHelpers::applyStyle(@"hello world")]; [webView stringByEvaluatingJavaScript:@"getSelection().setPosition(wrapper.firstChild, 5)"]; // Place cursor after "hello". auto *placeholder = [webView synchronouslyInsertTextPlaceholderWithSize:CGSizeMake(0, 5)]; @@ -1217,7 +1222,7 @@ static CGRect CGRectFromJSONEncodedDOMRectJSValue(id jsValue) TEST(DocumentEditingContext, RequestAfterBlockPlaceholder) { auto webView = adoptNS([[TestWKWebView alloc] initWithFrame:NSMakeRect(0, 0, 800, 600)]); - [webView synchronouslyLoadHTMLString:applyStyle(@"hello world")]; + [webView synchronouslyLoadHTMLString:DocumentEditingContextTestHelpers::applyStyle(@"hello world")]; [webView stringByEvaluatingJavaScript:@"getSelection().setPosition(wrapper.firstChild, 6)"]; // Place cursor before "world". auto *placeholder = [webView synchronouslyInsertTextPlaceholderWithSize:CGSizeMake(0, 5)]; @@ -1238,7 +1243,7 @@ static CGRect CGRectFromJSONEncodedDOMRectJSValue(id jsValue) TEST(DocumentEditingContext, RequestFirstTwoSentences) { auto webView = adoptNS([[TestWKWebView alloc] initWithFrame:NSMakeRect(0, 0, 800, 600)]); - [webView synchronouslyLoadHTMLString:applyStyle(threeSentencesExample)]; + [webView synchronouslyLoadHTMLString:DocumentEditingContextTestHelpers::applyStyle(threeSentencesExample)]; [webView stringByEvaluatingJavaScript:@"getSelection().setBaseAndExtent(text.firstChild, 0, text.firstChild, 0)"]; // Will focus

. auto *context = [webView synchronouslyRequestDocumentContext:makeRequest(UIWKDocumentRequestText, UITextGranularitySentence, 2)]; @@ -1251,7 +1256,7 @@ static CGRect CGRectFromJSONEncodedDOMRectJSValue(id jsValue) TEST(DocumentEditingContext, RequestFirstTwoSentencesNoSpaces) { auto webView = adoptNS([[TestWKWebView alloc] initWithFrame:NSMakeRect(0, 0, 800, 600)]); - [webView synchronouslyLoadHTMLString:applyStyle(@"

The first sentence.The second sentence.The third sentence.

")]; + [webView synchronouslyLoadHTMLString:DocumentEditingContextTestHelpers::applyStyle(@"

The first sentence.The second sentence.The third sentence.

")]; [webView stringByEvaluatingJavaScript:@"getSelection().setBaseAndExtent(text.firstChild, 0, text.firstChild, 0)"]; // Will focus

. auto *context = [webView synchronouslyRequestDocumentContext:makeRequest(UIWKDocumentRequestText, UITextGranularitySentence, 2)]; @@ -1264,7 +1269,7 @@ static CGRect CGRectFromJSONEncodedDOMRectJSValue(id jsValue) TEST(DocumentEditingContext, RequestLastSentence) { auto webView = adoptNS([[TestWKWebView alloc] initWithFrame:NSMakeRect(0, 0, 800, 600)]); - [webView synchronouslyLoadHTMLString:applyStyle(threeSentencesExample)]; + [webView synchronouslyLoadHTMLString:DocumentEditingContextTestHelpers::applyStyle(threeSentencesExample)]; [webView stringByEvaluatingJavaScript:@"getSelection().setBaseAndExtent(text.firstChild, text.firstChild.length, text.firstChild, text.firstChild.length)"]; // Will focus

. auto *context = [webView synchronouslyRequestDocumentContext:makeRequest(UIWKDocumentRequestText, UITextGranularitySentence, 1)]; @@ -1277,7 +1282,7 @@ static CGRect CGRectFromJSONEncodedDOMRectJSValue(id jsValue) TEST(DocumentEditingContext, RequestLastTwoSentences) { auto webView = adoptNS([[TestWKWebView alloc] initWithFrame:NSMakeRect(0, 0, 800, 600)]); - [webView synchronouslyLoadHTMLString:applyStyle(threeSentencesExample)]; + [webView synchronouslyLoadHTMLString:DocumentEditingContextTestHelpers::applyStyle(threeSentencesExample)]; [webView stringByEvaluatingJavaScript:@"getSelection().setBaseAndExtent(text.firstChild, text.firstChild.length, text.firstChild, text.firstChild.length)"]; // Will focus

. auto *context = [webView synchronouslyRequestDocumentContext:makeRequest(UIWKDocumentRequestText, UITextGranularitySentence, 2)]; @@ -1294,7 +1299,7 @@ static CGRect CGRectFromJSONEncodedDOMRectJSValue(id jsValue) TEST(DocumentEditingContext, RequestFirstParagraph) { auto webView = adoptNS([[TestWKWebView alloc] initWithFrame:NSMakeRect(0, 0, 800, 600)]); - [webView synchronouslyLoadHTMLString:applyStyle(threeParagraphsExample)]; + [webView synchronouslyLoadHTMLString:DocumentEditingContextTestHelpers::applyStyle(threeParagraphsExample)]; [webView stringByEvaluatingJavaScript:@"getSelection().setBaseAndExtent(text.firstChild, 0, text.firstChild, 0)"]; // Will focus

. auto *context = [webView synchronouslyRequestDocumentContext:makeRequest(UIWKDocumentRequestText, UITextGranularityParagraph, 1)]; @@ -1307,7 +1312,7 @@ static CGRect CGRectFromJSONEncodedDOMRectJSValue(id jsValue) TEST(DocumentEditingContext, RequestFirstTwoParagraphs) { auto webView = adoptNS([[TestWKWebView alloc] initWithFrame:NSMakeRect(0, 0, 800, 600)]); - [webView synchronouslyLoadHTMLString:applyStyle(threeParagraphsExample)]; + [webView synchronouslyLoadHTMLString:DocumentEditingContextTestHelpers::applyStyle(threeParagraphsExample)]; [webView stringByEvaluatingJavaScript:@"getSelection().setBaseAndExtent(text.firstChild, 0, text.firstChild, 0)"]; // Will focus

. auto *context = [webView synchronouslyRequestDocumentContext:makeRequest(UIWKDocumentRequestText, UITextGranularityParagraph, 2)]; @@ -1320,7 +1325,7 @@ static CGRect CGRectFromJSONEncodedDOMRectJSValue(id jsValue) TEST(DocumentEditingContext, RequestLastParagraph) { auto webView = adoptNS([[TestWKWebView alloc] initWithFrame:NSMakeRect(0, 0, 800, 600)]); - [webView synchronouslyLoadHTMLString:applyStyle(threeParagraphsExample)]; + [webView synchronouslyLoadHTMLString:DocumentEditingContextTestHelpers::applyStyle(threeParagraphsExample)]; [webView stringByEvaluatingJavaScript:@"getSelection().setBaseAndExtent(text.firstChild, text.firstChild.length, text.firstChild, text.firstChild.length)"]; // Will focus

. auto *context = [webView synchronouslyRequestDocumentContext:makeRequest(UIWKDocumentRequestText, UITextGranularityParagraph, 1)]; @@ -1333,7 +1338,7 @@ static CGRect CGRectFromJSONEncodedDOMRectJSValue(id jsValue) TEST(DocumentEditingContext, RequestLastTwoParagraphs) { auto webView = adoptNS([[TestWKWebView alloc] initWithFrame:NSMakeRect(0, 0, 800, 600)]); - [webView synchronouslyLoadHTMLString:applyStyle(threeParagraphsExample)]; + [webView synchronouslyLoadHTMLString:DocumentEditingContextTestHelpers::applyStyle(threeParagraphsExample)]; [webView stringByEvaluatingJavaScript:@"getSelection().setBaseAndExtent(text.firstChild, text.firstChild.length, text.firstChild, text.firstChild.length)"]; // Will focus

. auto *context = [webView synchronouslyRequestDocumentContext:makeRequest(UIWKDocumentRequestText, UITextGranularityParagraph, 2)]; @@ -1346,7 +1351,7 @@ static CGRect CGRectFromJSONEncodedDOMRectJSValue(id jsValue) TEST(DocumentEditingContext, RequestLastTwoParagraphsWithSelectiontWithinParagraph) { auto webView = adoptNS([[TestWKWebView alloc] initWithFrame:NSMakeRect(0, 0, 800, 600)]); - [webView synchronouslyLoadHTMLString:applyAhemStyle(@"The quick brown fox jumps over the lazy dog.")]; + [webView synchronouslyLoadHTMLString:DocumentEditingContextTestHelpers::applyAhemStyle(@"The quick brown fox jumps over the lazy dog.")]; [webView stringByEvaluatingJavaScript:@"getSelection().setBaseAndExtent(jumps, 0, jumps, 1)"]; // Will focus

. auto *context = [webView synchronouslyRequestDocumentContext:makeRequest(UIWKDocumentRequestText, UITextGranularityParagraph, 2)]; @@ -1362,7 +1367,7 @@ static CGRect CGRectFromJSONEncodedDOMRectJSValue(id jsValue) TEST(DocumentEditingContext, RequestFirstCharacter) { auto webView = adoptNS([[TestWKWebView alloc] initWithFrame:NSMakeRect(0, 0, 800, 600)]); - [webView synchronouslyLoadHTMLString:applyStyle(threeParagraphsExample)]; + [webView synchronouslyLoadHTMLString:DocumentEditingContextTestHelpers::applyStyle(threeParagraphsExample)]; [webView stringByEvaluatingJavaScript:@"getSelection().setBaseAndExtent(text.firstChild, 0, text.firstChild, 0)"]; // Will focus

. auto *context = [webView synchronouslyRequestDocumentContext:makeRequest(UIWKDocumentRequestText, UITextGranularityCharacter, 1)]; @@ -1375,7 +1380,7 @@ static CGRect CGRectFromJSONEncodedDOMRectJSValue(id jsValue) TEST(DocumentEditingContext, RequestFirstWordUsingCharacterGranularity) { auto webView = adoptNS([[TestWKWebView alloc] initWithFrame:NSMakeRect(0, 0, 800, 600)]); - [webView synchronouslyLoadHTMLString:applyStyle(threeParagraphsExample)]; + [webView synchronouslyLoadHTMLString:DocumentEditingContextTestHelpers::applyStyle(threeParagraphsExample)]; [webView stringByEvaluatingJavaScript:@"getSelection().setBaseAndExtent(text.firstChild, 0, text.firstChild, 0)"]; // Will focus

. auto *context = [webView synchronouslyRequestDocumentContext:makeRequest(UIWKDocumentRequestText, UITextGranularityCharacter, 3)]; @@ -1388,7 +1393,7 @@ static CGRect CGRectFromJSONEncodedDOMRectJSValue(id jsValue) TEST(DocumentEditingContext, RequestFirstWordPlusTrailingSpaceUsingCharacterGranularity) { auto webView = adoptNS([[TestWKWebView alloc] initWithFrame:NSMakeRect(0, 0, 800, 600)]); - [webView synchronouslyLoadHTMLString:applyStyle(threeParagraphsExample)]; + [webView synchronouslyLoadHTMLString:DocumentEditingContextTestHelpers::applyStyle(threeParagraphsExample)]; [webView stringByEvaluatingJavaScript:@"getSelection().setBaseAndExtent(text.firstChild, 0, text.firstChild, 0)"]; // Will focus

. auto *context = [webView synchronouslyRequestDocumentContext:makeRequest(UIWKDocumentRequestText, UITextGranularityCharacter, 4)]; @@ -1403,7 +1408,7 @@ static CGRect CGRectFromJSONEncodedDOMRectJSValue(id jsValue) TEST(DocumentEditingContext, RequestFirstLine) { auto webView = adoptNS([[TestWKWebView alloc] initWithFrame:NSMakeRect(0, 0, 800, 600)]); - [webView synchronouslyLoadHTMLString:applyAhemStyle(threeParagraphsExample)]; + [webView synchronouslyLoadHTMLString:DocumentEditingContextTestHelpers::applyAhemStyle(threeParagraphsExample)]; [webView stringByEvaluatingJavaScript:@"getSelection().setBaseAndExtent(text.firstChild, 0, text.firstChild, 0)"]; // Will focus

. auto *context = [webView synchronouslyRequestDocumentContext:makeRequest(UIWKDocumentRequestText, UITextGranularityLine, 1)]; @@ -1416,7 +1421,7 @@ static CGRect CGRectFromJSONEncodedDOMRectJSValue(id jsValue) TEST(DocumentEditingContext, RequestFirstTwoLines) { auto webView = adoptNS([[TestWKWebView alloc] initWithFrame:NSMakeRect(0, 0, 800, 600)]); - [webView synchronouslyLoadHTMLString:applyAhemStyle(threeParagraphsExample)]; + [webView synchronouslyLoadHTMLString:DocumentEditingContextTestHelpers::applyAhemStyle(threeParagraphsExample)]; [webView stringByEvaluatingJavaScript:@"getSelection().setBaseAndExtent(text.firstChild, 0, text.firstChild, 0)"]; // Will focus

. auto *context = [webView synchronouslyRequestDocumentContext:makeRequest(UIWKDocumentRequestText, UITextGranularityLine, 2)]; @@ -1429,7 +1434,7 @@ static CGRect CGRectFromJSONEncodedDOMRectJSValue(id jsValue) TEST(DocumentEditingContext, RequestLastLine) { auto webView = adoptNS([[TestWKWebView alloc] initWithFrame:NSMakeRect(0, 0, 800, 600)]); - [webView synchronouslyLoadHTMLString:applyAhemStyle(threeParagraphsExample)]; + [webView synchronouslyLoadHTMLString:DocumentEditingContextTestHelpers::applyAhemStyle(threeParagraphsExample)]; [webView stringByEvaluatingJavaScript:@"getSelection().setBaseAndExtent(text.firstChild, text.firstChild.length, text.firstChild, text.firstChild.length)"]; // Will focus

. auto *context = [webView synchronouslyRequestDocumentContext:makeRequest(UIWKDocumentRequestText, UITextGranularityLine, 1)]; @@ -1442,7 +1447,7 @@ static CGRect CGRectFromJSONEncodedDOMRectJSValue(id jsValue) TEST(DocumentEditingContext, RequestLastTwoLines) { auto webView = adoptNS([[TestWKWebView alloc] initWithFrame:NSMakeRect(0, 0, 800, 600)]); - [webView synchronouslyLoadHTMLString:applyAhemStyle(threeParagraphsExample)]; + [webView synchronouslyLoadHTMLString:DocumentEditingContextTestHelpers::applyAhemStyle(threeParagraphsExample)]; [webView stringByEvaluatingJavaScript:@"getSelection().setBaseAndExtent(text.firstChild, text.firstChild.length, text.firstChild, text.firstChild.length)"]; // Will focus

. auto *context = [webView synchronouslyRequestDocumentContext:makeRequest(UIWKDocumentRequestText, UITextGranularityLine, 2)]; diff --git a/Tools/TestWebKitAPI/Tests/WebKitCocoa/EditorStateTests.mm b/Tools/TestWebKitAPI/Tests/WebKitCocoa/EditorStateTests.mm index 862618502ab8a..e8823e2484217 100644 --- a/Tools/TestWebKitAPI/Tests/WebKitCocoa/EditorStateTests.mm +++ b/Tools/TestWebKitAPI/Tests/WebKitCocoa/EditorStateTests.mm @@ -432,11 +432,15 @@ static void checkContentViewHasTextWithFailureDescription(TestWKWebView *webView EXPECT_GT([[webView textInputContentView] selectedText].length, 0U); } +namespace EditorStateTests { + constexpr unsigned glyphWidth { 25 }; // pixels -static NSString *applyAhemStyle(NSString *htmlString) +NSString *applyAhemStyle(NSString *htmlString) { - return [NSString stringWithFormat:@"%@", glyphWidth, htmlString]; + return [NSString stringWithFormat:@"%@", EditorStateTests::glyphWidth, htmlString]; +} + } TEST(EditorStateTests, MarkedTextRange_HorizontalCaretSelection) @@ -444,7 +448,7 @@ static void checkContentViewHasTextWithFailureDescription(TestWKWebView *webView IPhoneUserInterfaceSwizzler userInterfaceSwizzler; auto webView = adoptNS([[TestWKWebView alloc] initWithFrame:NSMakeRect(0, 0, 800, 600)]); - [webView synchronouslyLoadHTMLStringAndWaitUntilAllImmediateChildFramesPaint:applyAhemStyle(@".")]; // . is dummy to force Ahem to load + [webView synchronouslyLoadHTMLStringAndWaitUntilAllImmediateChildFramesPaint:EditorStateTests::applyAhemStyle(@".")]; // . is dummy to force Ahem to load [webView stringByEvaluatingJavaScript:@"document.body.focus()"]; auto *contentView = [webView textInputContentView]; @@ -454,9 +458,9 @@ static void checkContentViewHasTextWithFailureDescription(TestWKWebView *webView UITextRange *markedTextRange = [contentView markedTextRange]; NSArray *rects = [contentView selectionRectsForRange:markedTextRange]; EXPECT_EQ(1U, rects.count); - EXPECT_EQ(CGRectMake(0, 0, 5 * glyphWidth, glyphWidth), rects[0].rect); - EXPECT_EQ(CGRectMake(0, 0, 2, glyphWidth), [contentView caretRectForPosition:markedTextRange.start]); - EXPECT_EQ(CGRectMake(124, 0, 2, glyphWidth), [contentView caretRectForPosition:markedTextRange.end]); + EXPECT_EQ(CGRectMake(0, 0, 5 * EditorStateTests::glyphWidth, EditorStateTests::glyphWidth), rects[0].rect); + EXPECT_EQ(CGRectMake(0, 0, 2, EditorStateTests::glyphWidth), [contentView caretRectForPosition:markedTextRange.start]); + EXPECT_EQ(CGRectMake(124, 0, 2, EditorStateTests::glyphWidth), [contentView caretRectForPosition:markedTextRange.end]); EXPECT_FALSE(rects[0].isVertical); } @@ -465,7 +469,7 @@ static void checkContentViewHasTextWithFailureDescription(TestWKWebView *webView IPhoneUserInterfaceSwizzler userInterfaceSwizzler; auto webView = adoptNS([[TestWKWebView alloc] initWithFrame:NSMakeRect(0, 0, 800, 600)]); - [webView synchronouslyLoadHTMLStringAndWaitUntilAllImmediateChildFramesPaint:applyAhemStyle(@".")]; // . is dummy to force Ahem to load + [webView synchronouslyLoadHTMLStringAndWaitUntilAllImmediateChildFramesPaint:EditorStateTests::applyAhemStyle(@".")]; // . is dummy to force Ahem to load [webView stringByEvaluatingJavaScript:@"document.body.focus()"]; [webView _synchronouslyExecuteEditCommand:@"InsertText" argument:@"Hello world"]; @@ -477,9 +481,9 @@ static void checkContentViewHasTextWithFailureDescription(TestWKWebView *webView UITextRange *markedTextRange = [contentView markedTextRange]; NSArray *rects = [contentView selectionRectsForRange:markedTextRange]; EXPECT_EQ(1U, rects.count); - EXPECT_EQ(CGRectMake(150, 0, 5 * glyphWidth, glyphWidth), rects[0].rect); - EXPECT_EQ(CGRectMake(149, 0, 2, glyphWidth), [contentView caretRectForPosition:markedTextRange.start]); - EXPECT_EQ(CGRectMake(274, 0, 2, glyphWidth), [contentView caretRectForPosition:markedTextRange.end]); + EXPECT_EQ(CGRectMake(150, 0, 5 * EditorStateTests::glyphWidth, EditorStateTests::glyphWidth), rects[0].rect); + EXPECT_EQ(CGRectMake(149, 0, 2, EditorStateTests::glyphWidth), [contentView caretRectForPosition:markedTextRange.start]); + EXPECT_EQ(CGRectMake(274, 0, 2, EditorStateTests::glyphWidth), [contentView caretRectForPosition:markedTextRange.end]); EXPECT_FALSE(rects[0].isVertical); } @@ -488,7 +492,7 @@ static void checkContentViewHasTextWithFailureDescription(TestWKWebView *webView IPhoneUserInterfaceSwizzler userInterfaceSwizzler; auto webView = adoptNS([[TestWKWebView alloc] initWithFrame:NSMakeRect(0, 0, 800, 600)]); - [webView synchronouslyLoadHTMLStringAndWaitUntilAllImmediateChildFramesPaint:applyAhemStyle(@".")]; // . is dummy to force Ahem to load + [webView synchronouslyLoadHTMLStringAndWaitUntilAllImmediateChildFramesPaint:EditorStateTests::applyAhemStyle(@".")]; // . is dummy to force Ahem to load [webView stringByEvaluatingJavaScript:@"document.body.focus()"]; auto *contentView = [webView textInputContentView]; @@ -498,9 +502,9 @@ static void checkContentViewHasTextWithFailureDescription(TestWKWebView *webView UITextRange *markedTextRange = [contentView markedTextRange]; NSArray *rects = [contentView selectionRectsForRange:markedTextRange]; EXPECT_EQ(1U, rects.count); - EXPECT_EQ(CGRectMake(0, 0, glyphWidth, 5 * glyphWidth), rects[0].rect); - EXPECT_EQ(CGRectMake(0, 0, glyphWidth, 2), [contentView caretRectForPosition:markedTextRange.start]); - EXPECT_EQ(CGRectMake(0, 124, glyphWidth, 2), [contentView caretRectForPosition:markedTextRange.end]); + EXPECT_EQ(CGRectMake(0, 0, EditorStateTests::glyphWidth, 5 * EditorStateTests::glyphWidth), rects[0].rect); + EXPECT_EQ(CGRectMake(0, 0, EditorStateTests::glyphWidth, 2), [contentView caretRectForPosition:markedTextRange.start]); + EXPECT_EQ(CGRectMake(0, 124, EditorStateTests::glyphWidth, 2), [contentView caretRectForPosition:markedTextRange.end]); EXPECT_TRUE(rects[0].isVertical); } @@ -509,7 +513,7 @@ static void checkContentViewHasTextWithFailureDescription(TestWKWebView *webView IPhoneUserInterfaceSwizzler userInterfaceSwizzler; auto webView = adoptNS([[TestWKWebView alloc] initWithFrame:NSMakeRect(0, 0, 800, 600)]); - [webView synchronouslyLoadHTMLString:applyAhemStyle(@".")]; // . is dummy to force Ahem to load + [webView synchronouslyLoadHTMLString:EditorStateTests::applyAhemStyle(@".")]; // . is dummy to force Ahem to load [webView stringByEvaluatingJavaScript:@"document.body.focus()"]; [webView _synchronouslyExecuteEditCommand:@"InsertText" argument:@"Hello world"]; @@ -521,9 +525,9 @@ static void checkContentViewHasTextWithFailureDescription(TestWKWebView *webView UITextRange *markedTextRange = [contentView markedTextRange]; NSArray *rects = [contentView selectionRectsForRange:markedTextRange]; EXPECT_EQ(1U, rects.count); - EXPECT_EQ(CGRectMake(0, 150, glyphWidth, 5 * glyphWidth), rects[0].rect); - EXPECT_EQ(CGRectMake(0, 149, glyphWidth, 2), [contentView caretRectForPosition:markedTextRange.start]); - EXPECT_EQ(CGRectMake(0, 274, glyphWidth, 2), [contentView caretRectForPosition:markedTextRange.end]); + EXPECT_EQ(CGRectMake(0, 150, EditorStateTests::glyphWidth, 5 * EditorStateTests::glyphWidth), rects[0].rect); + EXPECT_EQ(CGRectMake(0, 149, EditorStateTests::glyphWidth, 2), [contentView caretRectForPosition:markedTextRange.start]); + EXPECT_EQ(CGRectMake(0, 274, EditorStateTests::glyphWidth, 2), [contentView caretRectForPosition:markedTextRange.end]); EXPECT_TRUE(rects[0].isVertical); } diff --git a/Tools/TestWebKitAPI/Tests/WebKitCocoa/ElementTargetingTests.mm b/Tools/TestWebKitAPI/Tests/WebKitCocoa/ElementTargetingTests.mm index b00c16de7ddeb..1cf37ee1aaaf5 100644 --- a/Tools/TestWebKitAPI/Tests/WebKitCocoa/ElementTargetingTests.mm +++ b/Tools/TestWebKitAPI/Tests/WebKitCocoa/ElementTargetingTests.mm @@ -29,6 +29,7 @@ #import "PlatformUtilities.h" #import "TestUIDelegate.h" #import "TestWKWebView.h" +#import #import #import #import diff --git a/Tools/TestWebKitAPI/Tests/WebKitCocoa/FileSystemAccess.mm b/Tools/TestWebKitAPI/Tests/WebKitCocoa/FileSystemAccess.mm index b109fbf0bc97c..dba4d86bb2c4b 100644 --- a/Tools/TestWebKitAPI/Tests/WebKitCocoa/FileSystemAccess.mm +++ b/Tools/TestWebKitAPI/Tests/WebKitCocoa/FileSystemAccess.mm @@ -422,37 +422,37 @@ async function open(shouldCreateFile) \ TestWebKitAPI::Util::run(&done); } -static NSString *mainFrameString = @" \ -