Changeset 251148 in webkit


Ignore:
Timestamp:
Oct 15, 2019 11:21:52 AM (5 years ago)
Author:
jiewen_tan@apple.com
Message:

[WebAuthn] Write more tests for _WKWebAuthenticationPanel
https://bugs.webkit.org/show_bug.cgi?id=202565
<rdar://problem/55974128>

Reviewed by Brent Fulgham.

  • TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj:
  • TestWebKitAPI/Tests/WebKitCocoa/_WKWebAuthenticationPanel.mm:

(-[TestWebAuthenticationPanelDelegate panel:dismissWebAuthenticationPanelWithResult:]):
(-[TestWebAuthenticationPanelUIDelegate init]):
(-[TestWebAuthenticationPanelUIDelegate webView:runWebAuthenticationPanel:initiatedByFrame:completionHandler:]):
(TestWebKitAPI::TEST):

  • TestWebKitAPI/Tests/WebKitCocoa/web-authentication-get-assertion-hid.html: Added.
  • TestWebKitAPI/Tests/WebKitCocoa/web-authentication-get-assertion-nfc.html: Added.
Location:
trunk/Tools
Files:
2 added
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/Tools/ChangeLog

    r251138 r251148  
     12019-10-15  Jiewen Tan  <jiewen_tan@apple.com>
     2
     3        [WebAuthn] Write more tests for _WKWebAuthenticationPanel
     4        https://bugs.webkit.org/show_bug.cgi?id=202565
     5        <rdar://problem/55974128>
     6
     7        Reviewed by Brent Fulgham.
     8
     9        * TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj:
     10        * TestWebKitAPI/Tests/WebKitCocoa/_WKWebAuthenticationPanel.mm:
     11        (-[TestWebAuthenticationPanelDelegate panel:dismissWebAuthenticationPanelWithResult:]):
     12        (-[TestWebAuthenticationPanelUIDelegate init]):
     13        (-[TestWebAuthenticationPanelUIDelegate webView:runWebAuthenticationPanel:initiatedByFrame:completionHandler:]):
     14        (TestWebKitAPI::TEST):
     15        * TestWebKitAPI/Tests/WebKitCocoa/web-authentication-get-assertion-hid.html: Added.
     16        * TestWebKitAPI/Tests/WebKitCocoa/web-authentication-get-assertion-nfc.html: Added.
     17
    1182019-10-15  Alex Christensen  <achristensen@webkit.org>
    219
  • trunk/Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj

    r251008 r251148  
    337337                57599E2A1F071AA000A3FB8C /* IndexedDBStructuredCloneBackwardCompatibilityRead.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = 57599E251F07192C00A3FB8C /* IndexedDBStructuredCloneBackwardCompatibilityRead.html */; };
    338338                57599E2B1F071AA000A3FB8C /* IndexedDBStructuredCloneBackwardCompatibilityWrite.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = 57599E231F07192C00A3FB8C /* IndexedDBStructuredCloneBackwardCompatibilityWrite.html */; };
     339                57663DEA234EA66D00E85E09 /* web-authentication-get-assertion-nfc.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = 57663DE9234EA60B00E85E09 /* web-authentication-get-assertion-nfc.html */; };
     340                57663DEC234F1F9300E85E09 /* web-authentication-get-assertion-hid.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = 57663DEB234F1F8000E85E09 /* web-authentication-get-assertion-hid.html */; };
    339341                5769C50B1D9B0002000847FB /* SerializedCryptoKeyWrap.mm in Sources */ = {isa = PBXBuildFile; fileRef = 5769C50A1D9B0001000847FB /* SerializedCryptoKeyWrap.mm */; };
    340342                5774AA6821FBBF7800AF2A1B /* TestSOAuthorization.mm in Sources */ = {isa = PBXBuildFile; fileRef = 5774AA6721FBBF7800AF2A1B /* TestSOAuthorization.mm */; };
     
    14401442                                2EBD9D0A2134730D002DA758 /* video.html in Copy Resources */,
    14411443                                CD577799211CE0E4001B371E /* web-audio-only.html in Copy Resources */,
     1444                                57663DEC234F1F9300E85E09 /* web-authentication-get-assertion-hid.html in Copy Resources */,
     1445                                57663DEA234EA66D00E85E09 /* web-authentication-get-assertion-nfc.html in Copy Resources */,
    14421446                                57C624502346C21E00383FE7 /* web-authentication-get-assertion.html in Copy Resources */,
    14431447                                1C2B81861C89259D00A5529F /* webfont.html in Copy Resources */,
     
    18571861                57599E251F07192C00A3FB8C /* IndexedDBStructuredCloneBackwardCompatibilityRead.html */ = {isa = PBXFileReference; lastKnownFileType = text.html; path = IndexedDBStructuredCloneBackwardCompatibilityRead.html; sourceTree = "<group>"; };
    18581862                57599E261F07192C00A3FB8C /* IndexedDBStructuredCloneBackwardCompatibility.sqlite3-shm */ = {isa = PBXFileReference; lastKnownFileType = file; path = "IndexedDBStructuredCloneBackwardCompatibility.sqlite3-shm"; sourceTree = "<group>"; };
     1863                57663DE9234EA60B00E85E09 /* web-authentication-get-assertion-nfc.html */ = {isa = PBXFileReference; lastKnownFileType = text.html; path = "web-authentication-get-assertion-nfc.html"; sourceTree = "<group>"; };
     1864                57663DEB234F1F8000E85E09 /* web-authentication-get-assertion-hid.html */ = {isa = PBXFileReference; lastKnownFileType = text.html; path = "web-authentication-get-assertion-hid.html"; sourceTree = "<group>"; };
    18591865                5769C50A1D9B0001000847FB /* SerializedCryptoKeyWrap.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = SerializedCryptoKeyWrap.mm; sourceTree = "<group>"; };
    18601866                5774AA6721FBBF7800AF2A1B /* TestSOAuthorization.mm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.objcpp; path = TestSOAuthorization.mm; sourceTree = "<group>"; };
     
    33793385                                CD57779B211CE6CE001B371E /* video-with-audio-and-web-audio.html */,
    33803386                                CD577798211CDE8F001B371E /* web-audio-only.html */,
     3387                                57663DEB234F1F8000E85E09 /* web-authentication-get-assertion-hid.html */,
     3388                                57663DE9234EA60B00E85E09 /* web-authentication-get-assertion-nfc.html */,
    33813389                                57C6244F2346C1EC00383FE7 /* web-authentication-get-assertion.html */,
    33823390                                51714EB21CF8C761004723C4 /* WebProcessKillIDBCleanup-1.html */,
  • trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/_WKWebAuthenticationPanel.mm

    r250729 r251148  
    3131#import "PlatformUtilities.h"
    3232#import "TestWKWebView.h"
     33#import "WKWebViewConfigurationExtras.h"
    3334#import <WebKit/WKPreferencesPrivate.h>
    3435#import <WebKit/WKUIDelegatePrivate.h>
    3536#import <WebKit/_WKExperimentalFeature.h>
    3637#import <WebKit/_WKWebAuthenticationPanel.h>
     38#import <wtf/BlockPtr.h>
    3739
    3840static bool webAuthenticationPanelRan = false;
    39 static bool webAuthenticationPanelDimissed = false;
     41static bool webAuthenticationPanelFailed = false;
     42static bool webAuthenticationPanelSucceded = false;
    4043
    4144@interface TestWebAuthenticationPanelDelegate : NSObject <_WKWebAuthenticationPanelDelegate>
     
    4750{
    4851    ASSERT_NE(panel, nil);
    49     EXPECT_EQ(result, _WKWebAuthenticationResultFailed);
    50     webAuthenticationPanelDimissed = true;
     52    if (result == _WKWebAuthenticationResultFailed) {
     53        webAuthenticationPanelFailed = true;
     54        return;
     55    }
     56    if (result == _WKWebAuthenticationResultSucceeded) {
     57        webAuthenticationPanelSucceded = true;
     58        return;
     59    }
    5160}
    5261
     
    5463
    5564@interface TestWebAuthenticationPanelUIDelegate : NSObject <WKUIDelegatePrivate>
     65@property bool isRacy;
     66- (instancetype)init;
    5667@end
    5768
     
    5970    RetainPtr<_WKWebAuthenticationPanel> _panel;
    6071    RetainPtr<TestWebAuthenticationPanelDelegate> _delegate;
     72    BlockPtr<void(_WKWebAuthenticationPanelResult)> _callback;
     73}
     74
     75- (instancetype)init
     76{
     77    if (self = [super init])
     78        self.isRacy = false;
     79    return self;
    6180}
    6281
     
    7291    EXPECT_WK_STREQ([_panel relyingPartyID], "");
    7392
     93    if (_isRacy) {
     94        if (!_callback) {
     95            _callback = makeBlockPtr(completionHandler);
     96            return;
     97        }
     98        _callback(_WKWebAuthenticationPanelResultUnavailable);
     99    }
    74100    completionHandler(_WKWebAuthenticationPanelResultPresented);
    75101}
     
    80106
    81107namespace {
    82 _WKExperimentalFeature *webAuthenticationExperimentalFeature()
     108
     109static _WKExperimentalFeature *webAuthenticationExperimentalFeature()
    83110{
    84111    static RetainPtr<_WKExperimentalFeature> theFeature;
     
    95122    return theFeature.get();
    96123}
    97 }
    98 
    99 TEST(WebAuthenticationPanel, BasicTimeout)
    100 {
    101     RetainPtr<NSURL> testURL = [[NSBundle mainBundle] URLForResource:@"web-authentication-get-assertion" withExtension:@"html" subdirectory:@"TestWebKitAPI.resources"];
    102 
    103     auto configuration = adoptNS([[WKWebViewConfiguration alloc] init]);
    104     [[configuration preferences] _setEnabled:YES forExperimentalFeature:webAuthenticationExperimentalFeature()];
    105 
    106     auto webView = adoptNS([[TestWKWebView alloc] initWithFrame:NSZeroRect configuration:configuration.get()]);
    107     auto delegate = adoptNS([[TestWebAuthenticationPanelUIDelegate alloc] init]);
    108     [webView setUIDelegate:delegate.get()];
    109 
    110     // Only focused documents can trigger WebAuthn.
     124
     125// Only focused documents can trigger WebAuthn.
     126static void focus(TestWKWebView *webView)
     127{
    111128#if PLATFORM(MAC)
    112     [[webView hostWindow] makeFirstResponder:webView.get()];
     129    [[webView hostWindow] makeFirstResponder:webView];
    113130#elif PLATFORM(IOS)
    114131    [webView becomeFirstResponder];
    115132#endif
    116 
    117     [webView loadRequest:[NSURLRequest requestWithURL:testURL.get()]];
    118     Util::run(&webAuthenticationPanelRan);
    119     Util::run(&webAuthenticationPanelDimissed);
     133}
     134
     135static void reset()
     136{
     137    webAuthenticationPanelRan = false;
     138    webAuthenticationPanelFailed = false;
     139    webAuthenticationPanelSucceded = false;
     140}
     141
     142} // namesapce;
     143
     144TEST(WebAuthenticationPanel, NoPanelTimeout)
     145{
     146    RetainPtr<NSURL> testURL = [[NSBundle mainBundle] URLForResource:@"web-authentication-get-assertion-nfc" withExtension:@"html" subdirectory:@"TestWebKitAPI.resources"];
     147
     148    auto *configuration = [WKWebViewConfiguration _test_configurationWithTestPlugInClassName:@"WebProcessPlugInWithInternals" configureJSCForTesting:YES];
     149    [[configuration preferences] _setEnabled:YES forExperimentalFeature:webAuthenticationExperimentalFeature()];
     150
     151    auto webView = adoptNS([[TestWKWebView alloc] initWithFrame:NSZeroRect configuration:configuration]);
     152    focus(webView.get());
     153
     154    [webView loadRequest:[NSURLRequest requestWithURL:testURL.get()]];
     155    [webView waitForMessage:@"Operation timed out."];
     156}
     157
     158TEST(WebAuthenticationPanel, NoPanelHidSuccess)
     159{
     160    RetainPtr<NSURL> testURL = [[NSBundle mainBundle] URLForResource:@"web-authentication-get-assertion-hid" withExtension:@"html" subdirectory:@"TestWebKitAPI.resources"];
     161
     162    auto *configuration = [WKWebViewConfiguration _test_configurationWithTestPlugInClassName:@"WebProcessPlugInWithInternals" configureJSCForTesting:YES];
     163    [[configuration preferences] _setEnabled:YES forExperimentalFeature:webAuthenticationExperimentalFeature()];
     164
     165    auto webView = adoptNS([[TestWKWebView alloc] initWithFrame:NSZeroRect configuration:configuration]);
     166    focus(webView.get());
     167
     168    [webView loadRequest:[NSURLRequest requestWithURL:testURL.get()]];
     169    [webView waitForMessage:@"Succeeded!"];
     170}
     171
     172TEST(WebAuthenticationPanel, PanelTimeout)
     173{
     174    reset();
     175    RetainPtr<NSURL> testURL = [[NSBundle mainBundle] URLForResource:@"web-authentication-get-assertion" withExtension:@"html" subdirectory:@"TestWebKitAPI.resources"];
     176
     177    auto configuration = adoptNS([[WKWebViewConfiguration alloc] init]);
     178    [[configuration preferences] _setEnabled:YES forExperimentalFeature:webAuthenticationExperimentalFeature()];
     179
     180    auto webView = adoptNS([[TestWKWebView alloc] initWithFrame:NSZeroRect configuration:configuration.get()]);
     181    auto delegate = adoptNS([[TestWebAuthenticationPanelUIDelegate alloc] init]);
     182    [webView setUIDelegate:delegate.get()];
     183    focus(webView.get());
     184
     185    [webView loadRequest:[NSURLRequest requestWithURL:testURL.get()]];
     186    Util::run(&webAuthenticationPanelRan);
     187    Util::run(&webAuthenticationPanelFailed);
     188}
     189
     190TEST(WebAuthenticationPanel, PanelHidSuccess)
     191{
     192    reset();
     193    RetainPtr<NSURL> testURL = [[NSBundle mainBundle] URLForResource:@"web-authentication-get-assertion-hid" withExtension:@"html" subdirectory:@"TestWebKitAPI.resources"];
     194
     195    auto *configuration = [WKWebViewConfiguration _test_configurationWithTestPlugInClassName:@"WebProcessPlugInWithInternals" configureJSCForTesting:YES];
     196    [[configuration preferences] _setEnabled:YES forExperimentalFeature:webAuthenticationExperimentalFeature()];
     197
     198    auto webView = adoptNS([[TestWKWebView alloc] initWithFrame:NSZeroRect configuration:configuration]);
     199    auto delegate = adoptNS([[TestWebAuthenticationPanelUIDelegate alloc] init]);
     200    [webView setUIDelegate:delegate.get()];
     201    focus(webView.get());
     202
     203    [webView loadRequest:[NSURLRequest requestWithURL:testURL.get()]];
     204    Util::run(&webAuthenticationPanelRan);
     205    Util::run(&webAuthenticationPanelSucceded);
     206}
     207
     208#if HAVE(NEAR_FIELD)
     209// This test aims to see if the callback for the first ceremony could affect the second one.
     210// Therefore, the first callback will be held to return at the time when the second arrives.
     211// The first callback will return _WKWebAuthenticationPanelResultUnavailable which leads to timeout for NFC.
     212// The second callback will return _WKWebAuthenticationPanelResultPresented which leads to success.
     213TEST(WebAuthenticationPanel, PanelRacy1)
     214{
     215    reset();
     216    RetainPtr<NSURL> testURL = [[NSBundle mainBundle] URLForResource:@"web-authentication-get-assertion-nfc" withExtension:@"html" subdirectory:@"TestWebKitAPI.resources"];
     217
     218    auto *configuration = [WKWebViewConfiguration _test_configurationWithTestPlugInClassName:@"WebProcessPlugInWithInternals" configureJSCForTesting:YES];
     219    [[configuration preferences] _setEnabled:YES forExperimentalFeature:webAuthenticationExperimentalFeature()];
     220
     221    auto webView = adoptNS([[TestWKWebView alloc] initWithFrame:NSZeroRect configuration:configuration]);
     222    auto delegate = adoptNS([[TestWebAuthenticationPanelUIDelegate alloc] init]);
     223    [delegate setIsRacy:true];
     224    [webView setUIDelegate:delegate.get()];
     225    focus(webView.get());
     226
     227    [webView loadRequest:[NSURLRequest requestWithURL:testURL.get()]];
     228    Util::run(&webAuthenticationPanelRan);
     229    [webView loadRequest:[NSURLRequest requestWithURL:testURL.get()]];
     230    [webView waitForMessage:@"Succeeded!"];
     231}
     232
     233// Unlike the previous one, this one focuses on the order of the delegate callbacks.
     234TEST(WebAuthenticationPanel, PanelRacy2)
     235{
     236    reset();
     237    RetainPtr<NSURL> testURL = [[NSBundle mainBundle] URLForResource:@"web-authentication-get-assertion-nfc" withExtension:@"html" subdirectory:@"TestWebKitAPI.resources"];
     238
     239    auto *configuration = [WKWebViewConfiguration _test_configurationWithTestPlugInClassName:@"WebProcessPlugInWithInternals" configureJSCForTesting:YES];
     240    [[configuration preferences] _setEnabled:YES forExperimentalFeature:webAuthenticationExperimentalFeature()];
     241
     242    auto webView = adoptNS([[TestWKWebView alloc] initWithFrame:NSZeroRect configuration:configuration]);
     243    auto delegate = adoptNS([[TestWebAuthenticationPanelUIDelegate alloc] init]);
     244    [delegate setIsRacy:true];
     245    [webView setUIDelegate:delegate.get()];
     246    focus(webView.get());
     247
     248    [webView loadRequest:[NSURLRequest requestWithURL:testURL.get()]];
     249    Util::run(&webAuthenticationPanelRan);
     250    webAuthenticationPanelRan = false;
     251    [webView loadRequest:[NSURLRequest requestWithURL:testURL.get()]];
     252    Util::run(&webAuthenticationPanelFailed);
     253    Util::run(&webAuthenticationPanelRan);
     254    Util::run(&webAuthenticationPanelSucceded);
     255}
     256#endif // HAVE(NEAR_FIELD)
     257
     258TEST(WebAuthenticationPanel, PanelTwice)
     259{
     260    reset();
     261    RetainPtr<NSURL> testURL = [[NSBundle mainBundle] URLForResource:@"web-authentication-get-assertion-hid" withExtension:@"html" subdirectory:@"TestWebKitAPI.resources"];
     262
     263    auto *configuration = [WKWebViewConfiguration _test_configurationWithTestPlugInClassName:@"WebProcessPlugInWithInternals" configureJSCForTesting:YES];
     264    [[configuration preferences] _setEnabled:YES forExperimentalFeature:webAuthenticationExperimentalFeature()];
     265
     266    auto webView = adoptNS([[TestWKWebView alloc] initWithFrame:NSZeroRect configuration:configuration]);
     267    auto delegate = adoptNS([[TestWebAuthenticationPanelUIDelegate alloc] init]);
     268    [webView setUIDelegate:delegate.get()];
     269    focus(webView.get());
     270
     271    [webView loadRequest:[NSURLRequest requestWithURL:testURL.get()]];
     272    Util::run(&webAuthenticationPanelRan);
     273    Util::run(&webAuthenticationPanelSucceded);
     274
     275    reset();
     276    [webView loadRequest:[NSURLRequest requestWithURL:testURL.get()]];
     277    Util::run(&webAuthenticationPanelRan);
     278    Util::run(&webAuthenticationPanelSucceded);
    120279}
    121280
Note: See TracChangeset for help on using the changeset viewer.