in FBSDKCoreKit/FBSDKCoreKitTests/Internal/BridgeAPI/BridgeAPI+ApplicationOpenUrlTests.swift [431:701]
func verifyOpen(
pendingUrlCanOpenUrl: Bool,
hasSafariViewController: Bool,
isDismissingSafariViewController: Bool,
authSessionCompletionHandlerExists: Bool,
canHandleBridgeApiResponse: Bool,
expectedAuthSessionCompletionHandlerUrl: URL?,
expectedAuthSessionCompletionHandlerError: Error?,
expectAuthSessionCompletionHandlerInvoked: Bool,
expectedAuthCancelCallCount: Int,
expectedAuthSessionExists: Bool,
expectedAuthSessionCompletionExists: Bool,
expectedCanOpenUrlCalledWithUrl: URL?,
expectedCanOpenUrlSource: String?,
expectedCanOpenUrlAnnotation: String?,
expectedOpenUrlUrl: URL?,
expectedOpenUrlSource: String?,
expectedOpenUrlAnnotation: String?,
expectedPendingUrlOpenExists: Bool,
expectedIsDismissingSafariVc: Bool,
expectedSafariVcExists: Bool,
expectedReturnValue: Bool,
file: StaticString = #file,
line: UInt = #line
) {
let urlOpener = FBSDKLoginManager()
let authSessionSpy = AuthenticationSessionSpy(
url: sampleURL,
callbackURLScheme: nil
) { _, _ in
XCTFail(
"Should not invoke the completion for the authentication session",
file: file,
line: line
)
}
urlOpener.stubShouldStopPropagationOfURL(sampleURL, withValue: false)
urlOpener.stubbedCanOpenURL = pendingUrlCanOpenUrl
api.pendingURLOpen = urlOpener
if hasSafariViewController {
api.safariViewController = TestSafariViewController(url: sampleURL)
}
api.isDismissingSafariViewController = isDismissingSafariViewController
api.authenticationSessionState = .none
api.pendingRequest = makeSampleBridgeAPIRequest()
api.authenticationSession = authSessionSpy
var capturedAuthSessionCompletionHandlerURL: URL?
var capturedAuthSessionCompletionHandlerError: Error?
if authSessionCompletionHandlerExists {
api.authenticationSessionCompletionHandler = { callbackURL, error in
capturedAuthSessionCompletionHandlerURL = callbackURL
capturedAuthSessionCompletionHandlerError = error
}
}
api.pendingRequestCompletionBlock = { _ in
XCTFail(
"Should not invoke the pending request completion block",
file: file,
line: line
)
}
if canHandleBridgeApiResponse {
appURLSchemeProvider.appURLScheme = URLScheme.http.rawValue
api.pendingRequestCompletionBlock = nil
} else {
appURLSchemeProvider.appURLScheme = "foo"
}
let urlToOpen = (canHandleBridgeApiResponse ? validBridgeResponseURL : sampleURL)
let returnValue = api.application(
UIApplication.shared,
open: urlToOpen,
sourceApplication: sampleSource,
annotation: sampleAnnotation
)
XCTAssertEqual(
returnValue,
expectedReturnValue,
"The return value for the overall method should be \(expectedReturnValue)",
file: file,
line: line
)
if authSessionCompletionHandlerExists && expectAuthSessionCompletionHandlerInvoked {
XCTAssertEqual(
capturedAuthSessionCompletionHandlerURL,
expectedAuthSessionCompletionHandlerUrl,
"Should invoke the authentication session completion handler with the expected URL",
file: file,
line: line
)
XCTAssertEqual(
capturedAuthSessionCompletionHandlerError as NSError?,
expectedAuthSessionCompletionHandlerError as NSError?,
"Should invoke the authentication session completion handler with the expected error",
file: file,
line: line
)
} else {
XCTAssertNil(
capturedAuthSessionCompletionHandlerURL,
"Should not invoke the authentication session completion handler",
file: file,
line: line
)
XCTAssertNil(
capturedAuthSessionCompletionHandlerError,
"Should not invoke the authentication session completion handler",
file: file,
line: line
)
}
if expectedAuthSessionExists {
XCTAssertNotNil(
api.authenticationSession,
"The authentication session should not be nil",
file: file,
line: line
)
} else {
XCTAssertNil(
api.authenticationSession,
"The authentication session should be nil",
file: file,
line: line
)
}
if expectedAuthSessionCompletionExists {
XCTAssertNotNil(
api.authenticationSessionCompletionHandler,
"The authentication session completion handler should not be nil",
file: file,
line: line
)
} else {
XCTAssertNil(
api.authenticationSessionCompletionHandler,
"The authentication session completion handler should be nil",
file: file,
line: line
)
}
XCTAssertEqual(
authSessionSpy.cancelCallCount,
expectedAuthCancelCallCount,
"The authentication session should be cancelled the expected number of times",
file: file,
line: line
)
XCTAssertEqual(
api.authenticationSessionState,
.none,
"The authentication session state should not change",
file: file,
line: line
)
XCTAssertEqual(
urlOpener.capturedCanOpenURL,
expectedCanOpenUrlCalledWithUrl,
"The url opener's can open url method should be called with the expected URL",
file: file,
line: line
)
XCTAssertEqual(
urlOpener.capturedCanOpenSourceApplication,
expectedCanOpenUrlSource,
"The url opener's can open url method should be called with the expected source application",
file: file,
line: line
)
XCTAssertEqual(
urlOpener.capturedCanOpenAnnotation,
expectedCanOpenUrlAnnotation,
"The url opener's can open url method should be called with the expected annotation",
file: file,
line: line
)
XCTAssertEqual(
FBSDKLoginManager.capturedOpenURL,
expectedOpenUrlUrl,
"The url opener's open url method should be called with the expected URL",
file: file,
line: line
)
XCTAssertEqual(
FBSDKLoginManager.capturedSourceApplication,
expectedOpenUrlSource,
"The url opener's open url method should be called with the expected source application",
file: file,
line: line
)
XCTAssertEqual(
FBSDKLoginManager.capturedAnnotation,
expectedOpenUrlAnnotation,
"The url opener's open url method should be called with the expected annotation",
file: file,
line: line
)
if pendingUrlCanOpenUrl {
XCTAssertNotNil(
api.pendingRequest,
"The pending request should be nil",
file: file,
line: line
)
} else {
XCTAssertNil(
api.pendingRequest,
"The pending request should be nil",
file: file,
line: line
)
XCTAssertNil(
api.pendingRequestCompletionBlock,
"The pending request completion block should be nil",
file: file,
line: line
)
}
if expectedPendingUrlOpenExists {
XCTAssertNotNil(
api.pendingURLOpen,
"The reference to the url opener should not be nil",
file: file,
line: line
)
} else {
XCTAssertNil(
api.pendingURLOpen,
"The reference to the url opener should be nil",
file: file,
line: line
)
}
if expectedSafariVcExists {
XCTAssertNotNil(
api.safariViewController,
"Safari view controller should not be nil",
file: file,
line: line
)
} else {
XCTAssertNil(
api.safariViewController,
"Safari view controller should be nil",
file: file,
line: line
)
}
XCTAssertEqual(
api.isDismissingSafariViewController,
expectedIsDismissingSafariVc,
"Should set isDismissingSafariViewController to the expected value",
file: file,
line: line
)
}