Test
Test
. 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(@"
. 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