This repository was archived by the owner on Feb 22, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 9.7k
[url_launcher] Migrate to Swift #7103
Closed
Closed
Changes from 7 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
3dbda71
migrate to Swift
Serdnad 710a1d7
bump version
Serdnad 42564fc
update copyright
Serdnad f04747f
swift-format
Serdnad 8f7f08f
migrate existing tests
Serdnad d4a374e
update copyright
Serdnad ceaf459
update tests + example project
Serdnad a7896da
revert xcode changes
Serdnad 6041767
Apply suggestions from code review
Serdnad File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,7 @@ | ||
| ## 6.1.1 | ||
|
|
||
| * Migrates iOS plugin to Swift. | ||
|
|
||
| ## 6.1.0 | ||
|
|
||
| * Updates minimum Flutter version to 3.3 and iOS 11. | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
18 changes: 0 additions & 18 deletions
18
packages/url_launcher/url_launcher_ios/example/ios/RunnerTests/URLLauncherTests.m
This file was deleted.
Oops, something went wrong.
132 changes: 132 additions & 0 deletions
132
packages/url_launcher/url_launcher_ios/example/ios/RunnerTests/URLLauncherTests.swift
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,132 @@ | ||
| // Copyright 2013 The Flutter Authors. All rights reserved. | ||
| // Use of this source code is governed by a BSD-style license that can be | ||
| // found in the LICENSE file. | ||
|
|
||
| import Foundation | ||
| import XCTest | ||
| import Flutter | ||
|
|
||
| @testable import url_launcher_ios | ||
|
|
||
| class URLLauncherTests: XCTestCase { | ||
| override func setUp() { | ||
| self.continueAfterFailure = false | ||
| } | ||
|
|
||
| func testCreatePlugin() { | ||
| let plugin = URLLauncherPlugin() | ||
| XCTAssertNotNil(plugin) | ||
| } | ||
|
|
||
| func testHandleMethodCall_canLaunch() { | ||
| let plugin = URLLauncherPlugin() | ||
|
|
||
| let testCases = [[ | ||
| "url": "https://www.flutter.dev", | ||
| "expected": true | ||
| ], [ | ||
| "url": "invalidURL", | ||
| "expected": false | ||
| ]] | ||
|
|
||
| for testCase in testCases { | ||
| let call = FlutterMethodCall(methodName: "canLaunch", arguments: ["url": testCase["url"]]) | ||
| let resultExpectation = expectation(description: "result block must be called.") | ||
|
|
||
| plugin.handle(call) { result in | ||
| XCTAssertEqual( | ||
| result as? Bool, Optional(testCase["expected"]! as! Bool), | ||
| "result of canLaunch was not the expected result") | ||
| resultExpectation.fulfill() | ||
| } | ||
|
|
||
| waitForExpectations(timeout: 1) | ||
| } | ||
| } | ||
|
|
||
| func testHandleMethodCall_launch() { | ||
| let plugin = URLLauncherPlugin() | ||
| let call = FlutterMethodCall(methodName: "launch", arguments: ["url": "https://flutter.dev"]) | ||
| let resultExpectation = expectation(description: "result block must be called.") | ||
|
|
||
| plugin.handle(call) { result in | ||
| XCTAssertEqual( | ||
| result as? Bool, Optional(true), | ||
| "result block should be called with true on successful launch") | ||
| resultExpectation.fulfill() | ||
|
|
||
| XCTAssertNil(plugin.currentSession) | ||
| } | ||
|
|
||
| waitForExpectations(timeout: 1) | ||
| } | ||
|
|
||
| func testHandleMethodCall_launchInVC() { | ||
| let plugin = URLLauncherPlugin() | ||
| let call = FlutterMethodCall(methodName: "launch", arguments: ["url": "https://flutter.dev", "useSafariVC": true]) | ||
| let resultExpectation = expectation(description: "result block must be called.") | ||
|
|
||
| plugin.handle(call) { result in | ||
| XCTAssertEqual( | ||
| result as? Bool, Optional(true), | ||
| "result block should be called with true on successful launch") | ||
| resultExpectation.fulfill() | ||
|
|
||
| XCTAssertNotNil(plugin.currentSession?.safari) | ||
| XCTAssertTrue(plugin.currentSession?.safari.isViewLoaded ?? false) | ||
| } | ||
|
|
||
| waitForExpectations(timeout: 1) | ||
| } | ||
|
|
||
| func testHandleMethodCall_closeWebView() { | ||
| let plugin = URLLauncherPlugin() | ||
|
|
||
| // launch webview in separate VC | ||
| var call = FlutterMethodCall(methodName: "launch", arguments: ["url": "https://flutter.dev", "useSafariVC": true]) | ||
| var resultExpectation = expectation(description: "result block must be called.") | ||
|
|
||
| plugin.handle(call) { result in | ||
| XCTAssertEqual( | ||
| result as? Bool, Optional(true), | ||
| "result block should be called with true on successful launch") | ||
| resultExpectation.fulfill() | ||
|
|
||
| XCTAssertNotNil(plugin.currentSession?.safari) | ||
| } | ||
|
|
||
| waitForExpectations(timeout: 1) | ||
|
|
||
| // close webview | ||
| call = FlutterMethodCall(methodName: "close", arguments: nil) | ||
| resultExpectation = expectation(description: "result block must be called.") | ||
|
|
||
| plugin.handle(call) { result in | ||
| XCTAssertEqual( | ||
| result as? Bool, nil, | ||
| "result block should be called with nil on close") | ||
| resultExpectation.fulfill() | ||
|
|
||
| // test should pass if the safari VC is being dismissed or the | ||
| // currentSession has already been updated to nil | ||
| XCTAssertFalse(plugin.currentSession?.safari.isBeingDismissed ?? false) | ||
| } | ||
|
|
||
| waitForExpectations(timeout: 1) | ||
| } | ||
|
|
||
| func testHandleMethodCall_nonExistentMethod() { | ||
| let plugin = URLLauncherPlugin() | ||
| let call = FlutterMethodCall(methodName: "nonExistent", arguments: nil) | ||
| let resultExpectation = expectation(description: "result block must be called.") | ||
|
|
||
| plugin.handle(call) { result in | ||
| XCTAssertEqual( | ||
| result as? NSObject, FlutterMethodNotImplemented, | ||
| "result block must be called with FlutterMethodNotImplemented") | ||
| resultExpectation.fulfill() | ||
| } | ||
|
|
||
| waitForExpectations(timeout: 1) | ||
| } | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.