Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
43 commits
Select commit Hold shift + click to select a range
1d5609f
converting url_launcher from objc to swift
chrisdlangham Aug 18, 2023
d5727dd
converting tests to swift
chrisdlangham Aug 22, 2023
c4e55fb
converting tests to swift
chrisdlangham Aug 22, 2023
050d6b3
fixing issue where pigeon and method channels were not setup right
chrisdlangham Aug 22, 2023
5278199
formatting
chrisdlangham Aug 22, 2023
55a345b
reverting unintentional local changes
chrisdlangham Aug 22, 2023
8356d7a
fixing issues with Ui tests
chrisdlangham Aug 22, 2023
120b2d4
formating
chrisdlangham Aug 22, 2023
1316f3c
Merge branch 'main' into coverting-objc-to-swift
chrisdlangham Aug 22, 2023
7bd3553
updating version and change log
chrisdlangham Aug 22, 2023
2741de4
converting tests to swift
chrisdlangham Aug 22, 2023
495de26
converting unit tests to swift
chrisdlangham Aug 23, 2023
c898698
Merge branch 'main' into converting-url-launcher-ios-tests-to-swift
chrisdlangham Aug 23, 2023
6a6c8d5
updating change log
chrisdlangham Aug 23, 2023
254b9af
resolving merge conflicts
chrisdlangham Aug 23, 2023
869f18f
formatting
chrisdlangham Aug 23, 2023
1120baa
making test class final and private
chrisdlangham Aug 29, 2023
1429244
adding example app for platform
chrisdlangham Sep 2, 2023
a4a6683
formatting and addressing linting errors
chrisdlangham Sep 2, 2023
30a95d5
updating version and change log
chrisdlangham Sep 2, 2023
52623eb
Merge branch 'main' into platform-example-app
chrisdlangham Sep 12, 2023
8a6442d
cleaning up example pubspec
chrisdlangham Sep 12, 2023
2f05893
renaming org in example app and removing web
chrisdlangham Sep 12, 2023
167353a
updating change log
chrisdlangham Sep 12, 2023
8152b72
adds comments
chrisdlangham Sep 12, 2023
dc4de8a
addresses validation steps
chrisdlangham Sep 12, 2023
0c1651e
adds platform example android app to dependabot
chrisdlangham Sep 13, 2023
9f591e3
resolving merge conflicts
chrisdlangham Sep 13, 2023
13cd002
updated tests and formated pigeon file
chrisdlangham Sep 13, 2023
7e486d7
updates test name
chrisdlangham Sep 13, 2023
f8f5f0b
updates changelog
chrisdlangham Sep 13, 2023
827204a
Update CHANGELOG.md
chrisdlangham Sep 14, 2023
30568fd
Merge branch 'main' into coverting-objc-to-swift
chrisdlangham Sep 14, 2023
2360fc7
Merge branch 'main' into platform-example-app
chrisdlangham Sep 14, 2023
d320c35
deletes unknown file
chrisdlangham Sep 14, 2023
6b5e4cd
uses latest version of pigeon
chrisdlangham Sep 15, 2023
3651a97
updates change log
chrisdlangham Sep 15, 2023
257b7cc
moves setting up the pigeon api to the register function instead of t…
chrisdlangham Sep 15, 2023
3a1190e
Merge branch 'coverting-objc-to-swift' into platform-example-app
chrisdlangham Sep 28, 2023
1fb2d10
Revert "Merge branch 'coverting-objc-to-swift' into platform-example-…
chrisdlangham Sep 28, 2023
f71e763
Merge branch 'main' into platform-example-app
chrisdlangham Sep 28, 2023
7b0e411
attempt to fix linux web tests
chrisdlangham Sep 30, 2023
6f86e64
cleans up comments and boilerplate code
chrisdlangham Sep 30, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
formatting
  • Loading branch information
chrisdlangham committed Aug 23, 2023
commit 869f18f8e6dcc1d9c6a5b7d22f6bc8aa88e669b4
Original file line number Diff line number Diff line change
Expand Up @@ -8,112 +8,112 @@ import XCTest
@testable import url_launcher_ios

class URLLauncherTests: XCTestCase {
var plugin: URLLauncherPlugin!
var launcher: FakeLauncher!
var plugin: URLLauncherPlugin!
var launcher: FakeLauncher!

override func setUp() {
launcher = FakeLauncher()
plugin = URLLauncherPlugin(launcher: launcher, binaryMessenger: FakeFlutterBinaryMessenger())
}
override func setUp() {
launcher = FakeLauncher()
plugin = URLLauncherPlugin(launcher: launcher, binaryMessenger: FakeFlutterBinaryMessenger())
}

func testCanLaunchSuccess() {
let result = plugin.canLaunchUrl(url: "good://url")
func testCanLaunchSuccess() {
let result = plugin.canLaunchUrl(url: "good://url")

XCTAssertTrue(result)
}
XCTAssertTrue(result)
}

func testCanLaunchFailure() {
let result = plugin.canLaunchUrl(url: "bad://url")
func testCanLaunchFailure() {
let result = plugin.canLaunchUrl(url: "bad://url")

XCTAssertFalse(result)
}
XCTAssertFalse(result)
}

func testCanLaunchFailureWithInvalidURL() {
let result = plugin.canLaunchUrl(url: "urls can't have spaces")
func testCanLaunchFailureWithInvalidURL() {
let result = plugin.canLaunchUrl(url: "urls can't have spaces")

XCTAssertFalse(result)
}
XCTAssertFalse(result)
}

func testLaunchSuccess() {
let expectation = XCTestExpectation(description: "completion called")
plugin.launchUrl(url: "good://url", universalLinksOnly: false) { result in
switch result {
case .success(let success):
XCTAssertTrue(success)
case .failure(let error):
XCTFail("Unexpected error: \(error)")
}
expectation.fulfill()
}

wait(for: [expectation], timeout: 1)
func testLaunchSuccess() {
let expectation = XCTestExpectation(description: "completion called")
plugin.launchUrl(url: "good://url", universalLinksOnly: false) { result in
switch result {
case .success(let success):
XCTAssertTrue(success)
case .failure(let error):
XCTFail("Unexpected error: \(error)")
}
expectation.fulfill()
}

func testLaunchFailure() {
let expectation = XCTestExpectation(description: "completion called")
plugin.launchUrl(url: "bad://url", universalLinksOnly: false) { result in
switch result {
case .success(let success):
XCTAssertFalse(success)
case .failure(let error):
XCTFail("Unexpected error: \(error)")
}
expectation.fulfill()
}

wait(for: [expectation], timeout: 1)
wait(for: [expectation], timeout: 1)
}

func testLaunchFailure() {
let expectation = XCTestExpectation(description: "completion called")
plugin.launchUrl(url: "bad://url", universalLinksOnly: false) { result in
switch result {
case .success(let success):
XCTAssertFalse(success)
case .failure(let error):
XCTFail("Unexpected error: \(error)")
}
expectation.fulfill()
}

func testLaunchFailureWithInvalidURL() {
let expectation = XCTestExpectation(description: "completion called")
plugin.launchUrl(url: "urls can't have spaces", universalLinksOnly: false) { result in
switch result {
case .success(_):
XCTFail("Expected an error")
case .failure(let error):
let generalError = error as! GeneralError
XCTAssertEqual(generalError.code, "argument_error")
XCTAssertEqual(generalError.message, "Unable to parse URL")
XCTAssertEqual(generalError.details, "Provided URL: urls can't have spaces")
}
expectation.fulfill()
}

wait(for: [expectation], timeout: 1)
wait(for: [expectation], timeout: 1)
}

func testLaunchFailureWithInvalidURL() {
let expectation = XCTestExpectation(description: "completion called")
plugin.launchUrl(url: "urls can't have spaces", universalLinksOnly: false) { result in
switch result {
case .success(_):
XCTFail("Expected an error")
case .failure(let error):
let generalError = error as! GeneralError
XCTAssertEqual(generalError.code, "argument_error")
XCTAssertEqual(generalError.message, "Unable to parse URL")
XCTAssertEqual(generalError.details, "Provided URL: urls can't have spaces")
}
expectation.fulfill()
}

func testLaunchWithoutUniversalLinks() {
let expectation = XCTestExpectation(description: "completion called")
plugin.launchUrl(url: "good://url", universalLinksOnly: false) { result in
switch result {
case .success(let success):
XCTAssertTrue(success)
case .failure(let error):
XCTFail("Unexpected error: \(error)")
}
expectation.fulfill()
}

wait(for: [expectation], timeout: 1)
XCTAssertEqual(launcher.passedOptions?[.universalLinksOnly] as? Bool, false)
wait(for: [expectation], timeout: 1)
}

func testLaunchWithoutUniversalLinks() {
let expectation = XCTestExpectation(description: "completion called")
plugin.launchUrl(url: "good://url", universalLinksOnly: false) { result in
switch result {
case .success(let success):
XCTAssertTrue(success)
case .failure(let error):
XCTFail("Unexpected error: \(error)")
}
expectation.fulfill()
}

func testLaunchWithUniversalLinks() {
let expectation = XCTestExpectation(description: "completion called")
plugin.launchUrl(url: "good://url", universalLinksOnly: true) { result in
switch result {
case .success(let success):
XCTAssertTrue(success)
case .failure(let error):
XCTFail("Unexpected error: \(error)")
}
expectation.fulfill()
}

wait(for: [expectation], timeout: 1)
XCTAssertEqual(launcher.passedOptions?[.universalLinksOnly] as? Bool, true)
wait(for: [expectation], timeout: 1)
XCTAssertEqual(launcher.passedOptions?[.universalLinksOnly] as? Bool, false)
}

func testLaunchWithUniversalLinks() {
let expectation = XCTestExpectation(description: "completion called")
plugin.launchUrl(url: "good://url", universalLinksOnly: true) { result in
switch result {
case .success(let success):
XCTAssertTrue(success)
case .failure(let error):
XCTFail("Unexpected error: \(error)")
}
expectation.fulfill()
}

wait(for: [expectation], timeout: 1)
XCTAssertEqual(launcher.passedOptions?[.universalLinksOnly] as? Bool, true)
}

}

class FakeLauncher: Launcher {
Expand All @@ -123,20 +123,27 @@ class FakeLauncher: Launcher {
return url.scheme == "good"
}

func openURL(_ url: URL, options: [UIApplication.OpenExternalURLOptionsKey: Any] = [:], completionHandler: ((Bool) -> Void)? = nil) {
func openURL(
_ url: URL, options: [UIApplication.OpenExternalURLOptionsKey: Any] = [:],
completionHandler: ((Bool) -> Void)? = nil
) {
self.passedOptions = options
completionHandler?(url.scheme == "good")
}
}

class FakeFlutterBinaryMessenger: NSObject, FlutterBinaryMessenger {
func send(onChannel channel: String, message: Data?) { }
func send(onChannel channel: String, message: Data?) {}

func send(onChannel channel: String, message: Data?, binaryReply callback: FlutterBinaryReply? = nil) { }
func send(
onChannel channel: String, message: Data?, binaryReply callback: FlutterBinaryReply? = nil
) {}

func setMessageHandlerOnChannel(_ channel: String, binaryMessageHandler handler: FlutterBinaryMessageHandler? = nil) -> FlutterBinaryMessengerConnection {
123
}
func setMessageHandlerOnChannel(
_ channel: String, binaryMessageHandler handler: FlutterBinaryMessageHandler? = nil
) -> FlutterBinaryMessengerConnection {
123
}

func cleanUpConnection(_ connection: FlutterBinaryMessengerConnection) { }
func cleanUpConnection(_ connection: FlutterBinaryMessengerConnection) {}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,33 +5,33 @@
import XCTest

class URLLauncherUITests: XCTestCase {
var app: XCUIApplication!
var app: XCUIApplication!

override func setUp() {
continueAfterFailure = false
override func setUp() {
continueAfterFailure = false

app = XCUIApplication()
app.launch()
}
app = XCUIApplication()
app.launch()
}

func testLaunch() {
let app = self.app!
func testLaunch() {
let app = self.app!

let buttonNames: [String] = [
"Launch in app", "Launch in app(JavaScript ON)", "Launch in app(DOM storage ON)",
"Launch a universal link in a native app, fallback to Safari.(Youtube)"
]
for buttonName in buttonNames {
let button = app.buttons[buttonName]
XCTAssertTrue(button.waitForExistence(timeout: 30.0))
XCTAssertEqual(app.webViews.count, 0)
button.tap()
let webView = app.webViews.firstMatch
XCTAssertTrue(webView.waitForExistence(timeout: 30.0))
XCTAssertTrue(app.buttons["ForwardButton"].waitForExistence(timeout: 30.0))
XCTAssertTrue(app.buttons["Share"].exists)
XCTAssertTrue(app.buttons["OpenInSafariButton"].exists)
app.buttons["Done"].tap()
}
let buttonNames: [String] = [
"Launch in app", "Launch in app(JavaScript ON)", "Launch in app(DOM storage ON)",
"Launch a universal link in a native app, fallback to Safari.(Youtube)",
]
for buttonName in buttonNames {
let button = app.buttons[buttonName]
XCTAssertTrue(button.waitForExistence(timeout: 30.0))
XCTAssertEqual(app.webViews.count, 0)
button.tap()
let webView = app.webViews.firstMatch
XCTAssertTrue(webView.waitForExistence(timeout: 30.0))
XCTAssertTrue(app.buttons["ForwardButton"].waitForExistence(timeout: 30.0))
XCTAssertTrue(app.buttons["Share"].exists)
XCTAssertTrue(app.buttons["OpenInSafariButton"].exists)
app.buttons["Done"].tap()
}
}
}
23 changes: 14 additions & 9 deletions packages/url_launcher/url_launcher_ios/ios/Classes/Launcher.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,21 @@
// found in the LICENSE file.

protocol Launcher {
func canOpenURL(_ url: URL) -> Bool
func openURL(_ url: URL, options: [UIApplication.OpenExternalURLOptionsKey: Any], completionHandler completion: ((Bool) -> Void)?)
func canOpenURL(_ url: URL) -> Bool
func openURL(
_ url: URL, options: [UIApplication.OpenExternalURLOptionsKey: Any],
completionHandler completion: ((Bool) -> Void)?)
}

class UIApplicationLauncher: Launcher {
func canOpenURL(_ url: URL) -> Bool {
UIApplication.shared.canOpenURL(url)
}

func openURL(_ url: URL, options: [UIApplication.OpenExternalURLOptionsKey: Any], completionHandler completion: ((Bool) -> Void)?) {
UIApplication.shared.open(url, options: options, completionHandler: completion)
}
func canOpenURL(_ url: URL) -> Bool {
UIApplication.shared.canOpenURL(url)
}

func openURL(
_ url: URL, options: [UIApplication.OpenExternalURLOptionsKey: Any],
completionHandler completion: ((Bool) -> Void)?
) {
UIApplication.shared.open(url, options: options, completionHandler: completion)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,34 +7,38 @@ import SafariServices
typealias OpenInSafariVCResponse = (Result<Bool, Error>) -> Void

class URLLaunchSession: NSObject, SFSafariViewControllerDelegate {

private let completion: OpenInSafariVCResponse
private let url: URL
let safari: SFSafariViewController
var didFinish: (() -> Void)?

init(url: URL, completion: @escaping OpenInSafariVCResponse) {
self.url = url
self.completion = completion
self.safari = SFSafariViewController(url: url)
super.init()
self.safari.delegate = self
}

func safariViewController(_ controller: SFSafariViewController, didCompleteInitialLoad didLoadSuccessfully: Bool) {
if didLoadSuccessfully {
completion(Result.success(true))
} else {
completion(Result.failure(GeneralError(code: "Error", message: "Error while launching \(url)", details: nil)))
}
}

func safariViewControllerDidFinish(_ controller: SFSafariViewController) {
controller.dismiss(animated: true, completion: nil)
didFinish?()
}

func close() {
safariViewControllerDidFinish(safari)

private let completion: OpenInSafariVCResponse
private let url: URL
let safari: SFSafariViewController
var didFinish: (() -> Void)?

init(url: URL, completion: @escaping OpenInSafariVCResponse) {
self.url = url
self.completion = completion
self.safari = SFSafariViewController(url: url)
super.init()
self.safari.delegate = self
}

func safariViewController(
_ controller: SFSafariViewController, didCompleteInitialLoad didLoadSuccessfully: Bool
) {
if didLoadSuccessfully {
completion(Result.success(true))
} else {
completion(
Result.failure(
GeneralError(code: "Error", message: "Error while launching \(url)", details: nil)))
}
}

func safariViewControllerDidFinish(_ controller: SFSafariViewController) {
controller.dismiss(animated: true, completion: nil)
didFinish?()
}

func close() {
safariViewControllerDidFinish(safari)
}
}
Loading