Title: [290278] trunk/Source/WebCore
Revision
290278
Author
wenson_hs...@apple.com
Date
2022-02-21 17:37:17 -0800 (Mon, 21 Feb 2022)

Log Message

Add test coverage for the pasteboard writing codepath added in r289839
https://bugs.webkit.org/show_bug.cgi?id=236944

Reviewed by Aditya Keerthi.

Add test coverage for the changes in r289839 in the case where `ENABLE(IMAGE_ANALYSIS_ENHANCEMENTS)` is turned
on. To do this, we set the platform image analysis results to a new internal mock object,
`FakeImageAnalysisResult`, that returns a string for a given NSRange. This code is then exercised by several
existing layout tests that copy and paste text inside image overlays:

- fast/images/text-recognition/image-overlay-line-wrapping.html
- fast/images/text-recognition/image-overlay-text-without-leading-whitespace.html
- fast/images/text-recognition/mac/copy-image-overlay-text-with-context-menu.html

* testing/Internals.cpp:
(WebCore::Internals::installImageOverlay):
* testing/Internals.h:
* testing/Internals.mm:
(-[FakeImageAnalysisResult initWithString:]):
(-[FakeImageAnalysisResult _attributedStringForRange:]):
(WebCore::Internals::fakeImageAnalysisResultForTesting):

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (290277 => 290278)


--- trunk/Source/WebCore/ChangeLog	2022-02-22 01:13:21 UTC (rev 290277)
+++ trunk/Source/WebCore/ChangeLog	2022-02-22 01:37:17 UTC (rev 290278)
@@ -1,3 +1,27 @@
+2022-02-21  Wenson Hsieh  <wenson_hs...@apple.com>
+
+        Add test coverage for the pasteboard writing codepath added in r289839
+        https://bugs.webkit.org/show_bug.cgi?id=236944
+
+        Reviewed by Aditya Keerthi.
+
+        Add test coverage for the changes in r289839 in the case where `ENABLE(IMAGE_ANALYSIS_ENHANCEMENTS)` is turned
+        on. To do this, we set the platform image analysis results to a new internal mock object,
+        `FakeImageAnalysisResult`, that returns a string for a given NSRange. This code is then exercised by several
+        existing layout tests that copy and paste text inside image overlays:
+
+        - fast/images/text-recognition/image-overlay-line-wrapping.html
+        - fast/images/text-recognition/image-overlay-text-without-leading-whitespace.html
+        - fast/images/text-recognition/mac/copy-image-overlay-text-with-context-menu.html
+
+        * testing/Internals.cpp:
+        (WebCore::Internals::installImageOverlay):
+        * testing/Internals.h:
+        * testing/Internals.mm:
+        (-[FakeImageAnalysisResult initWithString:]):
+        (-[FakeImageAnalysisResult _attributedStringForRange:]):
+        (WebCore::Internals::fakeImageAnalysisResultForTesting):
+
 2022-02-21  Myles C. Maxfield  <mmaxfi...@apple.com>
 
         Sort WebCore and WebKit Xcode project files

Modified: trunk/Source/WebCore/testing/Internals.cpp (290277 => 290278)


--- trunk/Source/WebCore/testing/Internals.cpp	2022-02-22 01:13:21 UTC (rev 290277)
+++ trunk/Source/WebCore/testing/Internals.cpp	2022-02-22 01:37:17 UTC (rev 290278)
@@ -5876,6 +5876,9 @@
         , blocks.map([] (auto& block) {
             return TextRecognitionBlockData { block.text, getQuad(block) };
         })
+#if ENABLE(IMAGE_ANALYSIS_ENHANCEMENTS)
+        , fakeImageAnalysisResultForTesting(lines)
+#endif
     });
 #else
     UNUSED_PARAM(blocks);

Modified: trunk/Source/WebCore/testing/Internals.h (290277 => 290278)


--- trunk/Source/WebCore/testing/Internals.h	2022-02-22 01:13:21 UTC (rev 290277)
+++ trunk/Source/WebCore/testing/Internals.h	2022-02-22 01:37:17 UTC (rev 290278)
@@ -48,6 +48,7 @@
 #endif
 
 OBJC_CLASS DDScannerResult;
+OBJC_CLASS VKCImageAnalysis;
 
 namespace WebCore {
 
@@ -1278,6 +1279,10 @@
     ExceptionOr<RenderedDocumentMarker*> markerAt(Node&, const String& markerType, unsigned index);
     ExceptionOr<ScrollableArea*> scrollableAreaForNode(Node*) const;
 
+#if ENABLE(IMAGE_ANALYSIS_ENHANCEMENTS)
+    static RetainPtr<VKCImageAnalysis> fakeImageAnalysisResultForTesting(const Vector<ImageOverlayLine>&);
+#endif
+
 #if ENABLE(DATA_DETECTION)
     static DDScannerResult *fakeDataDetectorResultForTesting();
 #endif

Modified: trunk/Source/WebCore/testing/Internals.mm (290277 => 290278)


--- trunk/Source/WebCore/testing/Internals.mm	2022-02-22 01:13:21 UTC (rev 290277)
+++ trunk/Source/WebCore/testing/Internals.mm	2022-02-22 01:37:17 UTC (rev 290278)
@@ -46,6 +46,7 @@
 #import <wtf/cf/TypeCastsCF.h>
 #import <wtf/cocoa/NSURLExtras.h>
 #import <wtf/spi/darwin/SandboxSPI.h>
+#import <wtf/unicode/CharacterNames.h>
 
 #if PLATFORM(IOS_FAMILY)
 #import <pal/ios/UIKitSoftLink.h>
@@ -55,6 +56,36 @@
 #import <pal/cocoa/DataDetectorsCoreSoftLink.h>
 #endif
 
+#import <pal/cocoa/VisionKitCoreSoftLink.h>
+
+#if ENABLE(IMAGE_ANALYSIS_ENHANCEMENTS)
+
+@interface FakeImageAnalysisResult : NSObject
+- (instancetype)initWithString:(NSString *)fullText;
+@end
+
+@implementation FakeImageAnalysisResult {
+    RetainPtr<NSAttributedString> _string;
+}
+
+- (instancetype)initWithString:(NSString *)string
+{
+    if (!(self = [super init]))
+        return nil;
+
+    _string = adoptNS([[NSMutableAttributedString alloc] initWithString:string]);
+    return self;
+}
+
+- (NSAttributedString *)_attributedStringForRange:(NSRange)range
+{
+    return [_string attributedSubstringFromRange:range];
+}
+
+@end
+
+#endif // ENABLE(IMAGE_ANALYSIS_ENHANCEMENTS)
+
 namespace WebCore {
 
 String Internals::userVisibleString(const DOMURL& url)
@@ -204,4 +235,27 @@
     return SharedBuffer::createWithContentsOfFile([webCoreBundle pathForResource:@"missingImage" ofType:@"png"]);
 }
 
+#if ENABLE(IMAGE_ANALYSIS_ENHANCEMENTS)
+
+RetainPtr<VKCImageAnalysis> Internals::fakeImageAnalysisResultForTesting(const Vector<ImageOverlayLine>& lines)
+{
+    if (lines.isEmpty())
+        return { };
+
+    StringBuilder fullText;
+    for (auto& line : lines) {
+        for (auto& text : line.children) {
+            if (text.hasLeadingWhitespace)
+                fullText.append(space);
+            fullText.append(text.text);
+        }
+        if (line.hasTrailingNewline)
+            fullText.append(newlineCharacter);
+    }
+
+    return adoptNS((id)[[FakeImageAnalysisResult alloc] initWithString:fullText.toString()]);
+}
+
+#endif // ENABLE(IMAGE_ANALYSIS_ENHANCEMENTS)
+
 } // namespace WebCore
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to