Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
converting unit tests to swift
  • Loading branch information
chrisdlangham committed Aug 23, 2023
commit 495de26facb37bad2857fca64cdc01d516ced7cd
Original file line number Diff line number Diff line change
Expand Up @@ -589,7 +589,10 @@
"$(PROJECT_DIR)/Flutter",
);
INFOPLIST_FILE = Runner/Info.plist;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
LD_RUNPATH_SEARCH_PATHS = (
"$(inherited)",
"@executable_path/Frameworks",
);
LIBRARY_SEARCH_PATHS = (
"$(inherited)",
"$(PROJECT_DIR)/Flutter",
Expand All @@ -610,7 +613,10 @@
"$(PROJECT_DIR)/Flutter",
);
INFOPLIST_FILE = Runner/Info.plist;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
LD_RUNPATH_SEARCH_PATHS = (
"$(inherited)",
"@executable_path/Frameworks",
);
LIBRARY_SEARCH_PATHS = (
"$(inherited)",
"$(PROJECT_DIR)/Flutter",
Expand All @@ -627,10 +633,15 @@
BUNDLE_LOADER = "$(TEST_HOST)";
CODE_SIGN_STYLE = Automatic;
INFOPLIST_FILE = RunnerTests/Info.plist;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
LD_RUNPATH_SEARCH_PATHS = (
"$(inherited)",
"@executable_path/Frameworks",
"@loader_path/Frameworks",
);
MTL_FAST_MATH = YES;
PRODUCT_BUNDLE_IDENTIFIER = dev.flutter.plugins.RunnerTests;
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_VERSION = 5.0;
TEST_HOST = "$(BUILT_PRODUCTS_DIR)/Runner.app/Runner";
};
name = Debug;
Expand All @@ -642,10 +653,15 @@
BUNDLE_LOADER = "$(TEST_HOST)";
CODE_SIGN_STYLE = Automatic;
INFOPLIST_FILE = RunnerTests/Info.plist;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
LD_RUNPATH_SEARCH_PATHS = (
"$(inherited)",
"@executable_path/Frameworks",
"@loader_path/Frameworks",
);
MTL_FAST_MATH = YES;
PRODUCT_BUNDLE_IDENTIFIER = dev.flutter.plugins.RunnerTests;
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_VERSION = 5.0;
TEST_HOST = "$(BUILT_PRODUCTS_DIR)/Runner.app/Runner";
};
name = Release;
Expand All @@ -655,10 +671,15 @@
buildSettings = {
CODE_SIGN_STYLE = Automatic;
INFOPLIST_FILE = RunnerUITests/Info.plist;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
LD_RUNPATH_SEARCH_PATHS = (
"$(inherited)",
"@executable_path/Frameworks",
"@loader_path/Frameworks",
);
MTL_FAST_MATH = YES;
PRODUCT_BUNDLE_IDENTIFIER = dev.flutter.plugins.RunnerUITests;
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_VERSION = 5.0;
TEST_TARGET_NAME = Runner;
};
name = Debug;
Expand All @@ -668,10 +689,15 @@
buildSettings = {
CODE_SIGN_STYLE = Automatic;
INFOPLIST_FILE = RunnerUITests/Info.plist;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
LD_RUNPATH_SEARCH_PATHS = (
"$(inherited)",
"@executable_path/Frameworks",
"@loader_path/Frameworks",
);
MTL_FAST_MATH = YES;
PRODUCT_BUNDLE_IDENTIFIER = dev.flutter.plugins.RunnerUITests;
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_VERSION = 5.0;
TEST_TARGET_NAME = Runner;
};
name = Release;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,135 +8,134 @@ import XCTest
@testable import url_launcher_ios

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

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

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

XCTAssertTrue(result)
}
XCTAssertTrue(result!.boolValue)
XCTAssertNil(error)
}

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

XCTAssertFalse(result)
}
XCTAssertFalse(result!.boolValue)
}

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

XCTAssertFalse(result)
}
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")
}

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("good://url", universalLinksOnly: false) { result, error in
XCTAssertTrue(result!.boolValue)
XCTAssertNil(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("bad://url", universalLinksOnly: false) { result, error in
XCTAssertFalse(result!.boolValue)
XCTAssertNil(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("urls can't have spaces", universalLinksOnly: false) { result, error in
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")

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("good://url", universalLinksOnly: false) { result, error in
XCTAssertNil(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("good://url", universalLinksOnly: true) { result, error in
XCTAssertNil(error)
expectation.fulfill()
}


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

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

}

class FakeLauncher: Launcher {
class FakeLauncher: NSObject, FULLauncher {
var passedOptions: [UIApplication.OpenExternalURLOptionsKey: Any]?
func canOpenURL(_ url: URL) -> Bool {

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

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

func open(
_ 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()
}
}
}