Changeset 251148 in webkit
- Timestamp:
- Oct 15, 2019 11:21:52 AM (5 years ago)
- Location:
- trunk/Tools
- Files:
-
- 2 added
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Tools/ChangeLog
r251138 r251148 1 2019-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 1 18 2019-10-15 Alex Christensen <achristensen@webkit.org> 2 19 -
trunk/Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj
r251008 r251148 337 337 57599E2A1F071AA000A3FB8C /* IndexedDBStructuredCloneBackwardCompatibilityRead.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = 57599E251F07192C00A3FB8C /* IndexedDBStructuredCloneBackwardCompatibilityRead.html */; }; 338 338 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 */; }; 339 341 5769C50B1D9B0002000847FB /* SerializedCryptoKeyWrap.mm in Sources */ = {isa = PBXBuildFile; fileRef = 5769C50A1D9B0001000847FB /* SerializedCryptoKeyWrap.mm */; }; 340 342 5774AA6821FBBF7800AF2A1B /* TestSOAuthorization.mm in Sources */ = {isa = PBXBuildFile; fileRef = 5774AA6721FBBF7800AF2A1B /* TestSOAuthorization.mm */; }; … … 1440 1442 2EBD9D0A2134730D002DA758 /* video.html in Copy Resources */, 1441 1443 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 */, 1442 1446 57C624502346C21E00383FE7 /* web-authentication-get-assertion.html in Copy Resources */, 1443 1447 1C2B81861C89259D00A5529F /* webfont.html in Copy Resources */, … … 1857 1861 57599E251F07192C00A3FB8C /* IndexedDBStructuredCloneBackwardCompatibilityRead.html */ = {isa = PBXFileReference; lastKnownFileType = text.html; path = IndexedDBStructuredCloneBackwardCompatibilityRead.html; sourceTree = "<group>"; }; 1858 1862 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>"; }; 1859 1865 5769C50A1D9B0001000847FB /* SerializedCryptoKeyWrap.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = SerializedCryptoKeyWrap.mm; sourceTree = "<group>"; }; 1860 1866 5774AA6721FBBF7800AF2A1B /* TestSOAuthorization.mm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.objcpp; path = TestSOAuthorization.mm; sourceTree = "<group>"; }; … … 3379 3385 CD57779B211CE6CE001B371E /* video-with-audio-and-web-audio.html */, 3380 3386 CD577798211CDE8F001B371E /* web-audio-only.html */, 3387 57663DEB234F1F8000E85E09 /* web-authentication-get-assertion-hid.html */, 3388 57663DE9234EA60B00E85E09 /* web-authentication-get-assertion-nfc.html */, 3381 3389 57C6244F2346C1EC00383FE7 /* web-authentication-get-assertion.html */, 3382 3390 51714EB21CF8C761004723C4 /* WebProcessKillIDBCleanup-1.html */, -
trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/_WKWebAuthenticationPanel.mm
r250729 r251148 31 31 #import "PlatformUtilities.h" 32 32 #import "TestWKWebView.h" 33 #import "WKWebViewConfigurationExtras.h" 33 34 #import <WebKit/WKPreferencesPrivate.h> 34 35 #import <WebKit/WKUIDelegatePrivate.h> 35 36 #import <WebKit/_WKExperimentalFeature.h> 36 37 #import <WebKit/_WKWebAuthenticationPanel.h> 38 #import <wtf/BlockPtr.h> 37 39 38 40 static bool webAuthenticationPanelRan = false; 39 static bool webAuthenticationPanelDimissed = false; 41 static bool webAuthenticationPanelFailed = false; 42 static bool webAuthenticationPanelSucceded = false; 40 43 41 44 @interface TestWebAuthenticationPanelDelegate : NSObject <_WKWebAuthenticationPanelDelegate> … … 47 50 { 48 51 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 } 51 60 } 52 61 … … 54 63 55 64 @interface TestWebAuthenticationPanelUIDelegate : NSObject <WKUIDelegatePrivate> 65 @property bool isRacy; 66 - (instancetype)init; 56 67 @end 57 68 … … 59 70 RetainPtr<_WKWebAuthenticationPanel> _panel; 60 71 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; 61 80 } 62 81 … … 72 91 EXPECT_WK_STREQ([_panel relyingPartyID], ""); 73 92 93 if (_isRacy) { 94 if (!_callback) { 95 _callback = makeBlockPtr(completionHandler); 96 return; 97 } 98 _callback(_WKWebAuthenticationPanelResultUnavailable); 99 } 74 100 completionHandler(_WKWebAuthenticationPanelResultPresented); 75 101 } … … 80 106 81 107 namespace { 82 _WKExperimentalFeature *webAuthenticationExperimentalFeature() 108 109 static _WKExperimentalFeature *webAuthenticationExperimentalFeature() 83 110 { 84 111 static RetainPtr<_WKExperimentalFeature> theFeature; … … 95 122 return theFeature.get(); 96 123 } 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. 126 static void focus(TestWKWebView *webView) 127 { 111 128 #if PLATFORM(MAC) 112 [[webView hostWindow] makeFirstResponder:webView .get()];129 [[webView hostWindow] makeFirstResponder:webView]; 113 130 #elif PLATFORM(IOS) 114 131 [webView becomeFirstResponder]; 115 132 #endif 116 117 [webView loadRequest:[NSURLRequest requestWithURL:testURL.get()]]; 118 Util::run(&webAuthenticationPanelRan); 119 Util::run(&webAuthenticationPanelDimissed); 133 } 134 135 static void reset() 136 { 137 webAuthenticationPanelRan = false; 138 webAuthenticationPanelFailed = false; 139 webAuthenticationPanelSucceded = false; 140 } 141 142 } // namesapce; 143 144 TEST(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 158 TEST(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 172 TEST(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 190 TEST(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. 213 TEST(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. 234 TEST(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 258 TEST(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); 120 279 } 121 280
Note: See TracChangeset
for help on using the changeset viewer.