|
26 | 26 | #import <XCTest/XCTest.h> |
27 | 27 | #import "MSIDAADOAuthEmbeddedWebviewController.h" |
28 | 28 | #import "MSIDWKNavigationActionMock.h" |
| 29 | +#import "MSIDWebAuthNUtil.h" |
29 | 30 |
|
30 | 31 | #if !MSID_EXCLUDE_WEBKIT |
31 | 32 |
|
@@ -195,6 +196,45 @@ - (void)testDecidePolicyForNavigationAction_whenExternalDecidePolicyForBrowserAc |
195 | 196 | XCTAssertTrue(result); |
196 | 197 | } |
197 | 198 |
|
| 199 | +- (void)testDecidePolicyForNavigationAction_whenExternalDecidePolicyForBrowserActionLegacyFlow_shouldCancelActionAndReturnYesAndCallExternalMethod |
| 200 | +{ |
| 201 | + [MSIDWebAuthNUtil setAmIRunningInExtension:NO]; |
| 202 | + |
| 203 | + MSIDAADOAuthEmbeddedWebviewController *webVC = [[MSIDAADOAuthEmbeddedWebviewController alloc] |
| 204 | + initWithStartURL:[NSURL URLWithString:@"https://contoso.com/oauth/authorize"] |
| 205 | + endURL:[NSURL URLWithString:@"endurl://host"] |
| 206 | + webview:nil |
| 207 | + customHeaders:nil |
| 208 | + platfromParams:nil |
| 209 | + context:nil]; |
| 210 | + |
| 211 | + NSURLRequest *request = [[NSURLRequest alloc] initWithURL:[[NSURL alloc] initWithString:@"https://www.web-cp.com/check"]]; |
| 212 | + MSIDWKNavigationActionMock *action = [[MSIDWKNavigationActionMock alloc] initWithRequest:request]; |
| 213 | + |
| 214 | + XCTestExpectation *expectationExternalDecisionHandler = [self expectationWithDescription:@"external decision handler"]; |
| 215 | + XCTestExpectation *expectationDecisionHandler = [self expectationWithDescription:@"decision handler"]; |
| 216 | + |
| 217 | + webVC.externalDecidePolicyForBrowserAction = ^NSURLRequest *(MSIDOAuth2EmbeddedWebviewController *webView, NSURL *url) { |
| 218 | + |
| 219 | + XCTAssertNotNil(webView); |
| 220 | + XCTAssertEqualObjects([url absoluteString], @"browser://www.web-cp.com/check"); |
| 221 | + [expectationExternalDecisionHandler fulfill]; |
| 222 | + |
| 223 | + return [[NSURLRequest alloc] initWithURL:url]; |
| 224 | + }; |
| 225 | + |
| 226 | + |
| 227 | + BOOL result = [webVC decidePolicyAADForNavigationAction:action decisionHandler:^(WKNavigationActionPolicy decision) { |
| 228 | + |
| 229 | + XCTAssertEqual(decision, WKNavigationActionPolicyCancel); |
| 230 | + [expectationDecisionHandler fulfill]; |
| 231 | + }]; |
| 232 | + |
| 233 | + [self waitForExpectationsWithTimeout:1.0 handler:nil]; |
| 234 | + |
| 235 | + XCTAssertTrue(result); |
| 236 | +} |
| 237 | + |
198 | 238 | @end |
199 | 239 |
|
200 | 240 | #endif |
0 commit comments