Skip to content

Commit 0cfda40

Browse files
committed
Add unit test
1 parent 152b9aa commit 0cfda40

File tree

1 file changed

+40
-0
lines changed

1 file changed

+40
-0
lines changed

IdentityCore/tests/MSIDAADOAuthEmbeddedWebviewControllerTests.m

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
#import <XCTest/XCTest.h>
2727
#import "MSIDAADOAuthEmbeddedWebviewController.h"
2828
#import "MSIDWKNavigationActionMock.h"
29+
#import "MSIDWebAuthNUtil.h"
2930

3031
#if !MSID_EXCLUDE_WEBKIT
3132

@@ -195,6 +196,45 @@ - (void)testDecidePolicyForNavigationAction_whenExternalDecidePolicyForBrowserAc
195196
XCTAssertTrue(result);
196197
}
197198

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+
198238
@end
199239

200240
#endif

0 commit comments

Comments
 (0)