Changeset 230663 in webkit


Ignore:
Timestamp:
Apr 15, 2018 2:21:51 PM (6 years ago)
Author:
aestes@apple.com
Message:

[iOS] Add API tests for PDF find-in-page
https://bugs.webkit.org/show_bug.cgi?id=184634

Reviewed by Dan Bernstein.

  • TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj:
  • TestWebKitAPI/Tests/WebKit/find.pdf: Added.
  • TestWebKitAPI/Tests/WebKitCocoa/WKPDFView.mm:

(-[TestFindDelegate findString]):
(-[TestFindDelegate _webView:didCountMatches:forString:]):
(-[TestFindDelegate _webView:didFindMatches:forString:withMatchIndex:]):
(-[TestFindDelegate _webView:didFailToFindString:]):
(loadWebView):
(TEST):

Location:
trunk/Tools
Files:
1 added
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/Tools/ChangeLog

    r230656 r230663  
     12018-04-15  Andy Estes  <aestes@apple.com>
     2
     3        [iOS] Add API tests for PDF find-in-page
     4        https://bugs.webkit.org/show_bug.cgi?id=184634
     5
     6        Reviewed by Dan Bernstein.
     7
     8        * TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj:
     9        * TestWebKitAPI/Tests/WebKit/find.pdf: Added.
     10        * TestWebKitAPI/Tests/WebKitCocoa/WKPDFView.mm:
     11        (-[TestFindDelegate findString]):
     12        (-[TestFindDelegate _webView:didCountMatches:forString:]):
     13        (-[TestFindDelegate _webView:didFindMatches:forString:withMatchIndex:]):
     14        (-[TestFindDelegate _webView:didFailToFindString:]):
     15        (loadWebView):
     16        (TEST):
     17
    1182018-04-13  Zalan Bujtas  <zalan@apple.com>
    219
  • trunk/Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj

    r230462 r230663  
    632632                A17991881E1C994E00A505ED /* SharedBuffer.mm in Sources */ = {isa = PBXBuildFile; fileRef = A17991861E1C994E00A505ED /* SharedBuffer.mm */; };
    633633                A179918B1E1CA24100A505ED /* SharedBufferTest.cpp in Sources */ = {isa = PBXBuildFile; fileRef = A17991891E1CA24100A505ED /* SharedBufferTest.cpp */; };
     634                A17EAC55208305A00084B41B /* find.pdf in Copy Resources */ = {isa = PBXBuildFile; fileRef = A17EAC542083056E0084B41B /* find.pdf */; };
    634635                A180C0FA1EE67DF000468F47 /* RunOpenPanel.mm in Sources */ = {isa = PBXBuildFile; fileRef = A180C0F91EE67DF000468F47 /* RunOpenPanel.mm */; };
    635636                A1C4FB731BACD1CA003742D0 /* pages.pages in Copy Resources */ = {isa = PBXBuildFile; fileRef = A1C4FB721BACD1B7003742D0 /* pages.pages */; };
     
    950951                                524BBC9E19DF72C0002F1AF1 /* file-with-video.html in Copy Resources */,
    951952                                1A02C870125D4CFD00E3F4BD /* find.html in Copy Resources */,
     953                                A17EAC55208305A00084B41B /* find.pdf in Copy Resources */,
    952954                                C5101C4F176B8D9200EE9B15 /* findRanges.html in Copy Resources */,
    953955                                932AE53D1D371047005DFFAF /* focus-inputs.html in Copy Resources */,
     
    16881690                A17991891E1CA24100A505ED /* SharedBufferTest.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = SharedBufferTest.cpp; sourceTree = "<group>"; };
    16891691                A179918A1E1CA24100A505ED /* SharedBufferTest.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SharedBufferTest.h; sourceTree = "<group>"; };
     1692                A17EAC542083056E0084B41B /* find.pdf */ = {isa = PBXFileReference; lastKnownFileType = image.pdf; name = find.pdf; path = Tests/WebKit/find.pdf; sourceTree = SOURCE_ROOT; };
    16901693                A180C0F91EE67DF000468F47 /* RunOpenPanel.mm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.objcpp; path = RunOpenPanel.mm; sourceTree = "<group>"; };
    16911694                A18AA8CC1C3FA218009B2B97 /* ContentFiltering.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ContentFiltering.h; sourceTree = "<group>"; };
     
    24642467                                F407FE381F1D0DE60017CF25 /* enormous.svg */,
    24652468                                F41AB99B1EF4692C0083FA08 /* file-uploading.html */,
     2469                                A17EAC542083056E0084B41B /* find.pdf */,
    24662470                                93575C551D30366E000D604D /* focus-inputs.html */,
    24672471                                F4F405BA1D4C0CF8007A9707 /* full-size-autoplaying-video-with-audio.html */,
  • trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/WKPDFView.mm

    r213970 r230663  
    2929#if WK_API_ENABLED && TARGET_OS_IPHONE
    3030
     31#import "PlatformUtilities.h"
    3132#import "TestNavigationDelegate.h"
     33#import "Utilities.h"
    3234#import <WebKit/WKWebViewPrivate.h>
     35#import <WebKit/_WKFindDelegate.h>
    3336#import <wtf/RetainPtr.h>
    3437
    3538static void runTest(NSURL *pdfURL)
    3639{
    37     auto webView = adoptNS([[WKWebView alloc] initWithFrame:CGRectZero]);
     40    auto webView = adoptNS([[WKWebView alloc] init]);
    3841    [webView loadRequest:[NSURLRequest requestWithURL:pdfURL]];
    3942    [webView _test_waitForDidFinishNavigation];
     
    5457}
    5558
     59static BOOL isDone;
     60static const NSUInteger maxCount = 100;
     61
     62@interface TestFindDelegate : NSObject <_WKFindDelegate>
     63@property (nonatomic, readonly) NSString *findString;
     64@property (nonatomic, readonly) NSUInteger matchesCount;
     65@property (nonatomic, readonly) NSInteger matchIndex;
     66@property (nonatomic, readonly) BOOL didFail;
     67@end
     68
     69@implementation TestFindDelegate {
     70    RetainPtr<NSString> _findString;
     71}
     72
     73- (NSString *)findString
     74{
     75    return _findString.get();
     76}
     77
     78- (void)_webView:(WKWebView *)webView didCountMatches:(NSUInteger)matches forString:(NSString *)string
     79{
     80    _findString = string;
     81    _matchesCount = matches;
     82    _didFail = NO;
     83    isDone = YES;
     84}
     85
     86- (void)_webView:(WKWebView *)webView didFindMatches:(NSUInteger)matches forString:(NSString *)string withMatchIndex:(NSInteger)matchIndex
     87{
     88    _findString = string;
     89    _matchesCount = matches;
     90    _matchIndex = matchIndex;
     91    _didFail = NO;
     92    isDone = YES;
     93}
     94
     95- (void)_webView:(WKWebView *)webView didFailToFindString:(NSString *)string
     96{
     97    _findString = string;
     98    _didFail = YES;
     99    isDone = YES;
     100}
     101
     102@end
     103
     104static void loadWebView(WKWebView *webView, TestFindDelegate *findDelegate)
     105{
     106    [webView _setFindDelegate:findDelegate];
     107    NSURL *pdfURL = [[NSBundle mainBundle] URLForResource:@"find" withExtension:@"pdf" subdirectory:@"TestWebKitAPI.resources"];
     108    [webView loadRequest:[NSURLRequest requestWithURL:pdfURL]];
     109    [webView _test_waitForDidFinishNavigation];
     110}
     111
     112TEST(WKPDFView, CountString)
     113{
     114    auto webView = adoptNS([[WKWebView alloc] init]);
     115    auto findDelegate = adoptNS([[TestFindDelegate alloc] init]);
     116    loadWebView(webView.get(), findDelegate.get());
     117
     118    NSString *expectedString = @"Two";
     119    [webView _countStringMatches:expectedString options:0 maxCount:maxCount];
     120    TestWebKitAPI::Util::run(&isDone);
     121
     122    EXPECT_EQ(1U, [findDelegate matchesCount]);
     123    EXPECT_FALSE([findDelegate didFail]);
     124    EXPECT_WK_STREQ(expectedString, [findDelegate findString]);
     125}
     126
     127TEST(WKPDFView, CountStringMissing)
     128{
     129    auto webView = adoptNS([[WKWebView alloc] init]);
     130    auto findDelegate = adoptNS([[TestFindDelegate alloc] init]);
     131    loadWebView(webView.get(), findDelegate.get());
     132
     133    NSString *expectedString = @"One";
     134    [webView _countStringMatches:expectedString options:0 maxCount:maxCount];
     135    TestWebKitAPI::Util::run(&isDone);
     136
     137    EXPECT_EQ(0U, [findDelegate matchesCount]);
     138    EXPECT_FALSE([findDelegate didFail]);
     139    EXPECT_WK_STREQ(expectedString, [findDelegate findString]);
     140}
     141
     142TEST(WKPDFView, CountStringCaseInsensitive)
     143{
     144    auto webView = adoptNS([[WKWebView alloc] init]);
     145    auto findDelegate = adoptNS([[TestFindDelegate alloc] init]);
     146    loadWebView(webView.get(), findDelegate.get());
     147
     148    NSString *expectedString = @"t";
     149    [webView _countStringMatches:expectedString options:_WKFindOptionsCaseInsensitive maxCount:maxCount];
     150    TestWebKitAPI::Util::run(&isDone);
     151
     152    EXPECT_EQ(5U, [findDelegate matchesCount]);
     153    EXPECT_FALSE([findDelegate didFail]);
     154    EXPECT_WK_STREQ(expectedString, [findDelegate findString]);
     155}
     156
     157TEST(WKPDFView, FindString)
     158{
     159    auto webView = adoptNS([[WKWebView alloc] init]);
     160    auto findDelegate = adoptNS([[TestFindDelegate alloc] init]);
     161    loadWebView(webView.get(), findDelegate.get());
     162
     163    NSString *expectedString = @"one";
     164    [webView _findString:expectedString options:0 maxCount:maxCount];
     165    TestWebKitAPI::Util::run(&isDone);
     166
     167    EXPECT_EQ(1U, [findDelegate matchesCount]);
     168    EXPECT_EQ(0, [findDelegate matchIndex]);
     169    EXPECT_FALSE([findDelegate didFail]);
     170    EXPECT_WK_STREQ(expectedString, [findDelegate findString]);
     171}
     172
     173TEST(WKPDFView, FindStringMissing)
     174{
     175    auto webView = adoptNS([[WKWebView alloc] init]);
     176    auto findDelegate = adoptNS([[TestFindDelegate alloc] init]);
     177    loadWebView(webView.get(), findDelegate.get());
     178
     179    NSString *expectedString = @"One";
     180    [webView _findString:expectedString options:0 maxCount:maxCount];
     181    TestWebKitAPI::Util::run(&isDone);
     182
     183    EXPECT_TRUE([findDelegate didFail]);
     184    EXPECT_WK_STREQ(expectedString, [findDelegate findString]);
     185}
     186
     187TEST(WKPDFView, FindStringCaseInsensitive)
     188{
     189    auto webView = adoptNS([[WKWebView alloc] init]);
     190    auto findDelegate = adoptNS([[TestFindDelegate alloc] init]);
     191    loadWebView(webView.get(), findDelegate.get());
     192
     193    NSString *expectedString = @"t";
     194    [webView _findString:expectedString options:_WKFindOptionsCaseInsensitive maxCount:maxCount];
     195    TestWebKitAPI::Util::run(&isDone);
     196
     197    EXPECT_EQ(5U, [findDelegate matchesCount]);
     198    EXPECT_EQ(0, [findDelegate matchIndex]);
     199    EXPECT_FALSE([findDelegate didFail]);
     200    EXPECT_WK_STREQ(expectedString, [findDelegate findString]);
     201
     202    isDone = NO;
     203    [webView _findString:expectedString options:_WKFindOptionsCaseInsensitive maxCount:maxCount];
     204    TestWebKitAPI::Util::run(&isDone);
     205
     206    EXPECT_EQ(5U, [findDelegate matchesCount]);
     207    EXPECT_EQ(1, [findDelegate matchIndex]);
     208    EXPECT_FALSE([findDelegate didFail]);
     209    EXPECT_WK_STREQ(expectedString, [findDelegate findString]);
     210
     211    isDone = NO;
     212    [webView _findString:expectedString options:_WKFindOptionsCaseInsensitive | _WKFindOptionsBackwards maxCount:maxCount];
     213    TestWebKitAPI::Util::run(&isDone);
     214
     215    EXPECT_EQ(5U, [findDelegate matchesCount]);
     216    EXPECT_EQ(0, [findDelegate matchIndex]);
     217    EXPECT_FALSE([findDelegate didFail]);
     218    EXPECT_WK_STREQ(expectedString, [findDelegate findString]);
     219}
     220
     221TEST(WKPDFView, FindStringBackward)
     222{
     223    auto webView = adoptNS([[WKWebView alloc] init]);
     224    auto findDelegate = adoptNS([[TestFindDelegate alloc] init]);
     225    loadWebView(webView.get(), findDelegate.get());
     226
     227    NSString *expectedString = @"t";
     228    [webView _findString:expectedString options:_WKFindOptionsCaseInsensitive | _WKFindOptionsBackwards maxCount:maxCount];
     229    TestWebKitAPI::Util::run(&isDone);
     230
     231    EXPECT_EQ(5U, [findDelegate matchesCount]);
     232    EXPECT_EQ(4, [findDelegate matchIndex]);
     233    EXPECT_FALSE([findDelegate didFail]);
     234    EXPECT_WK_STREQ(expectedString, [findDelegate findString]);
     235
     236    isDone = NO;
     237    [webView _findString:expectedString options:_WKFindOptionsCaseInsensitive | _WKFindOptionsBackwards maxCount:maxCount];
     238    TestWebKitAPI::Util::run(&isDone);
     239
     240    EXPECT_EQ(5U, [findDelegate matchesCount]);
     241    EXPECT_EQ(3, [findDelegate matchIndex]);
     242    EXPECT_FALSE([findDelegate didFail]);
     243    EXPECT_WK_STREQ(expectedString, [findDelegate findString]);
     244
     245    isDone = NO;
     246    [webView _findString:expectedString options:_WKFindOptionsCaseInsensitive maxCount:maxCount];
     247    TestWebKitAPI::Util::run(&isDone);
     248
     249    EXPECT_EQ(5U, [findDelegate matchesCount]);
     250    EXPECT_EQ(4, [findDelegate matchIndex]);
     251    EXPECT_FALSE([findDelegate didFail]);
     252    EXPECT_WK_STREQ(expectedString, [findDelegate findString]);
     253}
     254
     255TEST(WKPDFView, FindStringPastEnd)
     256{
     257    auto webView = adoptNS([[WKWebView alloc] init]);
     258    auto findDelegate = adoptNS([[TestFindDelegate alloc] init]);
     259    loadWebView(webView.get(), findDelegate.get());
     260
     261    NSString *expectedString = @"two";
     262    [webView _findString:expectedString options:_WKFindOptionsCaseInsensitive maxCount:maxCount];
     263    TestWebKitAPI::Util::run(&isDone);
     264
     265    EXPECT_EQ(2U, [findDelegate matchesCount]);
     266    EXPECT_EQ(0, [findDelegate matchIndex]);
     267    EXPECT_FALSE([findDelegate didFail]);
     268    EXPECT_WK_STREQ(expectedString, [findDelegate findString]);
     269
     270    isDone = NO;
     271    [webView _findString:expectedString options:_WKFindOptionsCaseInsensitive maxCount:maxCount];
     272    TestWebKitAPI::Util::run(&isDone);
     273
     274    EXPECT_EQ(2U, [findDelegate matchesCount]);
     275    EXPECT_EQ(1, [findDelegate matchIndex]);
     276    EXPECT_FALSE([findDelegate didFail]);
     277    EXPECT_WK_STREQ(expectedString, [findDelegate findString]);
     278
     279    isDone = NO;
     280    [webView _findString:expectedString options:_WKFindOptionsCaseInsensitive maxCount:maxCount];
     281    TestWebKitAPI::Util::run(&isDone);
     282
     283    EXPECT_TRUE([findDelegate didFail]);
     284    EXPECT_WK_STREQ(expectedString, [findDelegate findString]);
     285}
     286
     287TEST(WKPDFView, FindStringBackwardPastStart)
     288{
     289    auto webView = adoptNS([[WKWebView alloc] init]);
     290    auto findDelegate = adoptNS([[TestFindDelegate alloc] init]);
     291    loadWebView(webView.get(), findDelegate.get());
     292
     293    NSString *expectedString = @"two";
     294    [webView _findString:expectedString options:_WKFindOptionsCaseInsensitive | _WKFindOptionsBackwards maxCount:maxCount];
     295    TestWebKitAPI::Util::run(&isDone);
     296
     297    EXPECT_EQ(2U, [findDelegate matchesCount]);
     298    EXPECT_EQ(1, [findDelegate matchIndex]);
     299    EXPECT_FALSE([findDelegate didFail]);
     300    EXPECT_WK_STREQ(expectedString, [findDelegate findString]);
     301
     302    isDone = NO;
     303    [webView _findString:expectedString options:_WKFindOptionsCaseInsensitive | _WKFindOptionsBackwards maxCount:maxCount];
     304    TestWebKitAPI::Util::run(&isDone);
     305
     306    EXPECT_EQ(2U, [findDelegate matchesCount]);
     307    EXPECT_EQ(0, [findDelegate matchIndex]);
     308    EXPECT_FALSE([findDelegate didFail]);
     309    EXPECT_WK_STREQ(expectedString, [findDelegate findString]);
     310
     311    isDone = NO;
     312    [webView _findString:expectedString options:_WKFindOptionsCaseInsensitive | _WKFindOptionsBackwards maxCount:maxCount];
     313    TestWebKitAPI::Util::run(&isDone);
     314
     315    EXPECT_TRUE([findDelegate didFail]);
     316    EXPECT_WK_STREQ(expectedString, [findDelegate findString]);
     317}
     318
    56319#endif
Note: See TracChangeset for help on using the changeset viewer.