Skip to content
Merged
Show file tree
Hide file tree
Changes from 32 commits
Commits
Show all changes
38 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
9f591e3
resolving merge conflicts
chrisdlangham Sep 13, 2023
13cd002
updated tests and formated pigeon file
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
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
3ee9d96
resolving merge conflicts
chrisdlangham Sep 28, 2023
d90702f
Merge branch 'main' into coverting-objc-to-swift
chrisdlangham Oct 7, 2023
7241d20
adds in missing throws keyword
chrisdlangham Oct 7, 2023
9d578f2
addresses feedback
chrisdlangham Oct 7, 2023
657c011
changes pigeon api to not throw errors, and let the dart side throw e…
chrisdlangham Oct 11, 2023
7a2fac5
Merge branch 'main' into coverting-objc-to-swift
chrisdlangham Oct 19, 2023
4d4f1bb
addresses feedback
chrisdlangham Oct 19, 2023
7b6272f
addressing feedback
chrisdlangham Oct 26, 2023
b91dca7
Merge branch 'main' into coverting-objc-to-swift
stuartmorgan-g Oct 26, 2023
e7e011a
Replace default launcher implementation with conformance extension
stuartmorgan-g Oct 26, 2023
d955ef8
swift-format
stuartmorgan-g Oct 26, 2023
1297683
Rework return enum to have different versions
stuartmorgan-g Oct 26, 2023
43966a0
Improve invalid URL testing
stuartmorgan-g Oct 26, 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
4 changes: 4 additions & 0 deletions packages/url_launcher/url_launcher_ios/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 6.1.6

* Migrates plugin from Objective-C to Swift.

## 6.1.5

* Adds pub topics to package metadata.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -631,6 +631,7 @@
baseConfigurationReference = 666BCD7C181C34F8BE58929B /* Pods-RunnerTests.debug.xcconfig */;
buildSettings = {
BUNDLE_LOADER = "$(TEST_HOST)";
CLANG_ENABLE_MODULES = YES;
CODE_SIGN_STYLE = Automatic;
INFOPLIST_FILE = RunnerTests/Info.plist;
LD_RUNPATH_SEARCH_PATHS = (
Expand All @@ -651,6 +652,7 @@
baseConfigurationReference = D25C434271ACF6555E002440 /* Pods-RunnerTests.release.xcconfig */;
buildSettings = {
BUNDLE_LOADER = "$(TEST_HOST)";
CLANG_ENABLE_MODULES = YES;
CODE_SIGN_STYLE = Automatic;
INFOPLIST_FILE = RunnerTests/Info.plist;
LD_RUNPATH_SEARCH_PATHS = (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,57 +9,42 @@ import XCTest

final class URLLauncherTests: XCTestCase {

private func createPlugin() -> FLTURLLauncherPlugin {
private func createPlugin() -> URLLauncherPlugin {
let launcher = FakeLauncher()
return FLTURLLauncherPlugin(launcher: launcher)
return URLLauncherPlugin(launcher: launcher)
}

private func createPlugin(launcher: FakeLauncher) -> FLTURLLauncherPlugin {
FLTURLLauncherPlugin(launcher: launcher)
private func createPlugin(launcher: FakeLauncher) -> URLLauncherPlugin {
return URLLauncherPlugin(launcher: launcher)
}

func testCanLaunchSuccess() {
var error: FlutterError?
let result = createPlugin().canLaunchURL("good://url", error: &error)

XCTAssertNotNil(result)
XCTAssertTrue(result?.boolValue ?? false)
XCTAssertNil(error)
let result = createPlugin().canLaunchUrl(url: "good://url")
XCTAssertEqual(result, .success)
}

func testCanLaunchFailure() {
var error: FlutterError?
let result = createPlugin().canLaunchURL("bad://url", error: &error)

XCTAssertNotNil(result)
XCTAssertFalse(result?.boolValue ?? true)
let result = createPlugin().canLaunchUrl(url: "bad://url")
XCTAssertEqual(result, .failedToLoad)
}

func testCanLaunchFailureWithInvalidURL() {
var error: FlutterError?
let result = createPlugin().canLaunchURL("urls can't have spaces", error: &error)

if (error == nil) {
// When linking against the iOS 17 SDK or later, NSURL uses a lenient parser, and won't
// fail to parse URLs, so the test must allow for either outcome.
XCTAssertNotNil(result)
XCTAssertFalse(result?.boolValue ?? true)
XCTAssertNil(error)
} else {
XCTAssertNil(result)
XCTAssertNotNil(error)
XCTAssertEqual(error?.code, "argument_error")
XCTAssertEqual(error?.message, "Unable to parse URL")
XCTAssertEqual(error?.details as? String, "Provided URL: urls can't have spaces")
}
let result = createPlugin().canLaunchUrl(url: "urls can't have spaces")

// When linking against the iOS 17 SDK or later, NSURL uses a lenient parser, and won't
// fail to parse URLs, so the test must allow for either outcome.
XCTAssertTrue(result == .failedToLoad || result == .invalidUrl)
}

func testLaunchSuccess() {
let expectation = XCTestExpectation(description: "completion called")
createPlugin().launchURL("good://url", universalLinksOnly: false) { result, error in
XCTAssertNotNil(result)
XCTAssertTrue(result?.boolValue ?? false)
XCTAssertNil(error)
createPlugin().launchUrl(url: "good://url", universalLinksOnly: false) { result in
switch result {
case .success(let details):
XCTAssertEqual(details, .success)
case .failure(let error):
XCTFail("Unexpected error: \(error)")
}
expectation.fulfill()
}

Expand All @@ -68,11 +53,13 @@ final class URLLauncherTests: XCTestCase {

func testLaunchFailure() {
let expectation = XCTestExpectation(description: "completion called")

createPlugin().launchURL("bad://url", universalLinksOnly: false) { result, error in
XCTAssertNotNil(result)
XCTAssertFalse(result?.boolValue ?? true)
XCTAssertNil(error)
createPlugin().launchUrl(url: "bad://url", universalLinksOnly: false) { result in
switch result {
case .success(let details):
XCTAssertEqual(details, .failedToLoad)
case .failure(let error):
XCTFail("Unexpected error: \(error)")
}
expectation.fulfill()
}

Expand All @@ -81,22 +68,15 @@ final class URLLauncherTests: XCTestCase {

func testLaunchFailureWithInvalidURL() {
let expectation = XCTestExpectation(description: "completion called")

createPlugin().launchURL("urls can't have spaces", universalLinksOnly: false) { result, error in
if (error == nil) {
createPlugin().launchUrl(url: "urls can't have spaces", universalLinksOnly: false) { result in
switch result {
case .success(let details):
// When linking against the iOS 17 SDK or later, NSURL uses a lenient parser, and won't
// fail to parse URLs, so the test must allow for either outcome.
XCTAssertNotNil(result)
XCTAssertFalse(result?.boolValue ?? true)
XCTAssertNil(error)
} else {
XCTAssertNil(result)
XCTAssertNotNil(error)
XCTAssertEqual(error?.code, "argument_error")
XCTAssertEqual(error?.message, "Unable to parse URL")
XCTAssertEqual(error?.details as? String, "Provided URL: urls can't have spaces")
XCTAssertTrue(details == .failedToLoad || details == .invalidUrl)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

which case will it actually be?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It depends on the iOS version the tests are being run on. I think @stuartmorgan can explain it better, but on iOS 17 we should get .failedToLoad, and on older versions, we should get .invalidUrl

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you do "if iOS 17 else".

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unfortunately Swift apparently has no equivalent to Obj-C SDK preprocessor checks, and that's the determining factor. We don't want to switch on whether it's running on iOS 17, we want to switch on whether it was linked against the iOS 17 SDK, and that's apparently not expressible in Swift. (The best I can find is people suggesting mapping from the SDK to the version of Xcode that introduced that SDK, and then from there to the version of Swift introduced by that version of Xcode, but that's extremely gross since this has nothing to do with Swift language version.)

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I realized there's a better option; I've added a utility method in the test file that checks the NSURL behavior directly, and then switches based on that in the tests.

case .failure(let error):
XCTFail("Unexpected error: \(error)")
}

expectation.fulfill()
}

Expand All @@ -108,13 +88,17 @@ final class URLLauncherTests: XCTestCase {
let plugin = createPlugin(launcher: launcher)

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

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

XCTAssertEqual(launcher.passedOptions?[.universalLinksOnly] as? Bool, false)
}

Expand All @@ -123,31 +107,35 @@ final class URLLauncherTests: XCTestCase {
let plugin = createPlugin(launcher: launcher)

let expectation = XCTestExpectation(description: "completion called")

plugin.launchURL("good://url", universalLinksOnly: true) { result, error in
XCTAssertNil(error)
plugin.launchUrl(url: "good://url", universalLinksOnly: true) { result in
switch result {
case .success(let details):
XCTAssertEqual(details, .success)
case .failure(let error):
XCTFail("Unexpected error: \(error)")
}
expectation.fulfill()
}

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

XCTAssertEqual(launcher.passedOptions?[.universalLinksOnly] as? Bool, true)
}

}

final private class FakeLauncher: NSObject, FULLauncher {
final private class FakeLauncher: NSObject, Launcher {
var passedOptions: [UIApplication.OpenExternalURLOptionsKey: Any]?

func canOpen(_ url: URL) -> Bool {
return url.scheme == "good"
func canOpenURL(_ url: URL) -> Bool {
url.scheme == "good"
}

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

This file was deleted.

Loading