-
Notifications
You must be signed in to change notification settings - Fork 3.6k
[url_launcher] migrating objc plugin to swift #4753
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 32 commits
1d5609f
d5727dd
c4e55fb
050d6b3
5278199
55a345b
8356d7a
120b2d4
1316f3c
7bd3553
2741de4
495de26
c898698
6a6c8d5
254b9af
869f18f
1120baa
9f591e3
13cd002
f8f5f0b
827204a
30568fd
6b5e4cd
3651a97
257b7cc
3ee9d96
d90702f
7241d20
9d578f2
657c011
7a2fac5
4d4f1bb
7b6272f
b91dca7
e7e011a
d955ef8
1297683
43966a0
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| 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. | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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() | ||
| } | ||
|
|
||
|
|
@@ -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() | ||
| } | ||
|
|
||
|
|
@@ -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) | ||
|
||
| case .failure(let error): | ||
| XCTFail("Unexpected error: \(error)") | ||
| } | ||
|
|
||
| expectation.fulfill() | ||
| } | ||
|
|
||
|
|
@@ -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) | ||
| } | ||
|
|
||
|
|
@@ -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)? | ||
hellohuanlin marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| ) { | ||
| self.passedOptions = options | ||
| completionHandler?(url.scheme == "good") | ||
| completion?(url.scheme == "good") | ||
| } | ||
| } | ||
This file was deleted.
Uh oh!
There was an error while loading. Please reload this page.