Skip to content

Commit 1cbff93

Browse files
[url_launcher] Fix supportsCloseForLaunchMode to query close support (flutter#12926)
Fixes flutter#192758 `supportsCloseForLaunchMode` was calling `UrlLauncherPlatform.supportsMode` (the launch-support check) instead of `supportsCloseForMode`, so it reported whether a mode can be launched rather than whether an in-app web view opened with that mode can be closed. This changes it to call `supportsCloseForMode`, and adds a regression test (the shared mock is extended so the two platform methods can return different values).
1 parent 57dde33 commit 1cbff93

8 files changed

Lines changed: 84 additions & 63 deletions

File tree

‎packages/url_launcher/url_launcher/CHANGELOG.md‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
1-
## NEXT
1+
## 6.3.3
22

3+
* Fixes `supportsCloseForLaunchMode` reporting launch support instead of close
4+
support.
35
* Updates minimum supported SDK version to Flutter 3.41/Dart 3.11.
46
* Updates README to reflect currently supported OS versions for the latest
57
versions of the endorsed platform implementations.

‎packages/url_launcher/url_launcher/lib/src/url_launcher_uri.dart‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,5 +104,5 @@ Future<bool> supportsLaunchMode(LaunchMode mode) {
104104
/// If this returns false, [closeInAppWebView] will not work when launching
105105
/// URLs with [mode].
106106
Future<bool> supportsCloseForLaunchMode(LaunchMode mode) {
107-
return UrlLauncherPlatform.instance.supportsMode(convertLaunchMode(mode));
107+
return UrlLauncherPlatform.instance.supportsCloseForMode(convertLaunchMode(mode));
108108
}

‎packages/url_launcher/url_launcher/pubspec.yaml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ description: Flutter plugin for launching a URL. Supports
33
web, phone, SMS, and email schemes.
44
repository: https://github.com/flutter/packages/tree/main/packages/url_launcher/url_launcher
55
issue_tracker: https://github.com/flutter/flutter/issues?q=is%3Aissue+is%3Aopen+label%3A%22p%3A+url_launcher%22
6-
version: 6.3.2
6+
version: 6.3.3
77

88
environment:
99
sdk: ^3.11.0

‎packages/url_launcher/url_launcher/test/link_test.dart‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ void main() {
6666
webOnlyWindowName: null,
6767
showTitle: false,
6868
)
69-
..setResponse(true);
69+
..setLaunchResponse(true);
7070
await followLink!();
7171
// Calling canLaunch just to pre-check launch is an anti-pattern, since
7272
// canLaunch doesn't always work, so ensure that it's not called.
@@ -101,7 +101,7 @@ void main() {
101101
webOnlyWindowName: null,
102102
showTitle: false,
103103
)
104-
..setResponse(true);
104+
..setLaunchResponse(true);
105105
await followLink!();
106106
// Calling canLaunch just to pre-check launch is an anti-pattern, since
107107
// canLaunch doesn't always work, so ensure that it's not called.

‎packages/url_launcher/url_launcher/test/mocks/mock_url_launcher_platform.dart‎

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@ class MockUrlLauncher extends Fake with MockPlatformInterfaceMixin implements Ur
1919
Map<String, String>? headers;
2020
String? webOnlyWindowName;
2121

22-
bool? response;
22+
bool? launchResponse;
23+
bool? closeResponse;
2324

2425
bool closeWebViewCalled = false;
2526
bool canLaunchCalled = false;
@@ -55,8 +56,13 @@ class MockUrlLauncher extends Fake with MockPlatformInterfaceMixin implements Ur
5556
}
5657

5758
// ignore: use_setters_to_change_properties
58-
void setResponse(bool response) {
59-
this.response = response;
59+
void setLaunchResponse(bool response) {
60+
launchResponse = response;
61+
}
62+
63+
// ignore: use_setters_to_change_properties
64+
void setCloseResponse(bool response) {
65+
closeResponse = response;
6066
}
6167

6268
@override
@@ -66,7 +72,7 @@ class MockUrlLauncher extends Fake with MockPlatformInterfaceMixin implements Ur
6672
Future<bool> canLaunch(String url) async {
6773
expect(url, this.url);
6874
canLaunchCalled = true;
69-
return response!;
75+
return launchResponse!;
7076
}
7177

7278
@override
@@ -90,7 +96,7 @@ class MockUrlLauncher extends Fake with MockPlatformInterfaceMixin implements Ur
9096
expect(webOnlyWindowName, this.webOnlyWindowName);
9197
expect(webOnlyWindowName, this.webOnlyWindowName);
9298
launchCalled = true;
93-
return response!;
99+
return launchResponse!;
94100
}
95101

96102
@override
@@ -103,7 +109,7 @@ class MockUrlLauncher extends Fake with MockPlatformInterfaceMixin implements Ur
103109
expect(options.browserConfiguration.showTitle, showTitle);
104110
expect(options.webOnlyWindowName, webOnlyWindowName);
105111
launchCalled = true;
106-
return response!;
112+
return launchResponse!;
107113
}
108114

109115
@override
@@ -114,12 +120,12 @@ class MockUrlLauncher extends Fake with MockPlatformInterfaceMixin implements Ur
114120
@override
115121
Future<bool> supportsMode(PreferredLaunchMode mode) async {
116122
launchMode = mode;
117-
return response!;
123+
return launchResponse!;
118124
}
119125

120126
@override
121127
Future<bool> supportsCloseForMode(PreferredLaunchMode mode) async {
122128
launchMode = mode;
123-
return response!;
129+
return closeResponse!;
124130
}
125131
}

‎packages/url_launcher/url_launcher/test/src/legacy_api_test.dart‎

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ void main() {
2424
test('returns true', () async {
2525
mock
2626
..setCanLaunchExpectations('foo')
27-
..setResponse(true);
27+
..setLaunchResponse(true);
2828

2929
final bool result = await canLaunch('foo');
3030

@@ -34,7 +34,7 @@ void main() {
3434
test('returns false', () async {
3535
mock
3636
..setCanLaunchExpectations('foo')
37-
..setResponse(false);
37+
..setLaunchResponse(false);
3838

3939
final bool result = await canLaunch('foo');
4040

@@ -55,7 +55,7 @@ void main() {
5555
webOnlyWindowName: null,
5656
showTitle: false,
5757
)
58-
..setResponse(true);
58+
..setLaunchResponse(true);
5959
expect(await launch('http://flutter.dev/'), isTrue);
6060
});
6161

@@ -72,7 +72,7 @@ void main() {
7272
webOnlyWindowName: null,
7373
showTitle: false,
7474
)
75-
..setResponse(true);
75+
..setLaunchResponse(true);
7676
expect(
7777
await launch('http://flutter.dev/', headers: <String, String>{'key': 'value'}),
7878
isTrue,
@@ -92,7 +92,7 @@ void main() {
9292
webOnlyWindowName: null,
9393
showTitle: false,
9494
)
95-
..setResponse(true);
95+
..setLaunchResponse(true);
9696
expect(await launch('http://flutter.dev/', forceSafariVC: true), isTrue);
9797
});
9898

@@ -109,7 +109,7 @@ void main() {
109109
webOnlyWindowName: null,
110110
showTitle: false,
111111
)
112-
..setResponse(true);
112+
..setLaunchResponse(true);
113113
expect(
114114
await launch('http://flutter.dev/', forceSafariVC: false, universalLinksOnly: true),
115115
isTrue,
@@ -129,7 +129,7 @@ void main() {
129129
webOnlyWindowName: null,
130130
showTitle: false,
131131
)
132-
..setResponse(true);
132+
..setLaunchResponse(true);
133133
expect(await launch('http://flutter.dev/', forceWebView: true), isTrue);
134134
});
135135

@@ -146,7 +146,7 @@ void main() {
146146
webOnlyWindowName: null,
147147
showTitle: false,
148148
)
149-
..setResponse(true);
149+
..setLaunchResponse(true);
150150
expect(
151151
await launch('http://flutter.dev/', forceWebView: true, enableJavaScript: true),
152152
isTrue,
@@ -166,7 +166,7 @@ void main() {
166166
webOnlyWindowName: null,
167167
showTitle: false,
168168
)
169-
..setResponse(true);
169+
..setLaunchResponse(true);
170170
expect(
171171
await launch('http://flutter.dev/', forceWebView: true, enableDomStorage: true),
172172
isTrue,
@@ -186,7 +186,7 @@ void main() {
186186
webOnlyWindowName: null,
187187
showTitle: false,
188188
)
189-
..setResponse(true);
189+
..setLaunchResponse(true);
190190
expect(await launch('http://flutter.dev/', forceSafariVC: false), isTrue);
191191
});
192192

@@ -210,7 +210,7 @@ void main() {
210210
webOnlyWindowName: null,
211211
showTitle: false,
212212
)
213-
..setResponse(true);
213+
..setLaunchResponse(true);
214214
expect(await launch('mailto:[email protected]?subject=Hello'), isTrue);
215215
});
216216

@@ -252,7 +252,7 @@ void main() {
252252
webOnlyWindowName: null,
253253
showTitle: false,
254254
)
255-
..setResponse(true);
255+
..setLaunchResponse(true);
256256

257257
final TestWidgetsFlutterBinding binding = TestWidgetsFlutterBinding.ensureInitialized();
258258
debugDefaultTargetPlatformOverride = TargetPlatform.iOS;
@@ -285,7 +285,7 @@ void main() {
285285
webOnlyWindowName: null,
286286
showTitle: false,
287287
)
288-
..setResponse(true);
288+
..setLaunchResponse(true);
289289

290290
final TestWidgetsFlutterBinding binding = TestWidgetsFlutterBinding.ensureInitialized();
291291
debugDefaultTargetPlatformOverride = TargetPlatform.android;
@@ -318,7 +318,7 @@ void main() {
318318
webOnlyWindowName: null,
319319
showTitle: false,
320320
)
321-
..setResponse(true);
321+
..setLaunchResponse(true);
322322
expect(
323323
await launch('rdp://full%20address=s:mypc:3389&audiomode=i:2&disable%20themes=i:1'),
324324
isTrue,

‎packages/url_launcher/url_launcher/test/src/url_launcher_string_test.dart‎

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ void main() {
1818
const urlString = 'https://flutter.dev';
1919
mock
2020
..setCanLaunchExpectations(urlString)
21-
..setResponse(true);
21+
..setLaunchResponse(true);
2222

2323
final bool result = await canLaunchUrlString(urlString);
2424

@@ -29,7 +29,7 @@ void main() {
2929
const urlString = 'https://flutter.dev';
3030
mock
3131
..setCanLaunchExpectations(urlString)
32-
..setResponse(false);
32+
..setLaunchResponse(false);
3333

3434
final bool result = await canLaunchUrlString(urlString);
3535

@@ -51,7 +51,7 @@ void main() {
5151
webOnlyWindowName: null,
5252
showTitle: false,
5353
)
54-
..setResponse(true);
54+
..setLaunchResponse(true);
5555
expect(await launchUrlString(urlString), isTrue);
5656
});
5757

@@ -68,7 +68,7 @@ void main() {
6868
webOnlyWindowName: null,
6969
showTitle: false,
7070
)
71-
..setResponse(true);
71+
..setLaunchResponse(true);
7272
expect(await launchUrlString(urlString), isTrue);
7373
});
7474

@@ -85,7 +85,7 @@ void main() {
8585
webOnlyWindowName: null,
8686
showTitle: false,
8787
)
88-
..setResponse(true);
88+
..setLaunchResponse(true);
8989
expect(await launchUrlString(urlString), isTrue);
9090
});
9191

@@ -102,7 +102,7 @@ void main() {
102102
webOnlyWindowName: null,
103103
showTitle: false,
104104
)
105-
..setResponse(true);
105+
..setLaunchResponse(true);
106106
expect(await launchUrlString(urlString), isTrue);
107107
});
108108

@@ -119,7 +119,7 @@ void main() {
119119
webOnlyWindowName: null,
120120
showTitle: false,
121121
)
122-
..setResponse(true);
122+
..setLaunchResponse(true);
123123
expect(await launchUrlString(urlString, mode: LaunchMode.inAppWebView), isTrue);
124124
});
125125

@@ -136,7 +136,7 @@ void main() {
136136
webOnlyWindowName: null,
137137
showTitle: false,
138138
)
139-
..setResponse(true);
139+
..setLaunchResponse(true);
140140
expect(await launchUrlString(urlString, mode: LaunchMode.externalApplication), isTrue);
141141
});
142142

@@ -153,7 +153,7 @@ void main() {
153153
webOnlyWindowName: null,
154154
showTitle: false,
155155
)
156-
..setResponse(true);
156+
..setLaunchResponse(true);
157157
expect(await launchUrlString(urlString, mode: LaunchMode.inAppBrowserView), isTrue);
158158
});
159159

@@ -170,7 +170,7 @@ void main() {
170170
webOnlyWindowName: null,
171171
showTitle: true,
172172
)
173-
..setResponse(true);
173+
..setLaunchResponse(true);
174174
expect(
175175
await launchUrlString(
176176
urlString,
@@ -194,7 +194,7 @@ void main() {
194194
webOnlyWindowName: null,
195195
showTitle: false,
196196
)
197-
..setResponse(true);
197+
..setLaunchResponse(true);
198198
expect(
199199
await launchUrlString(urlString, mode: LaunchMode.externalNonBrowserApplication),
200200
isTrue,
@@ -214,7 +214,7 @@ void main() {
214214
webOnlyWindowName: null,
215215
showTitle: false,
216216
)
217-
..setResponse(true);
217+
..setLaunchResponse(true);
218218
expect(
219219
await launchUrlString(
220220
urlString,
@@ -238,7 +238,7 @@ void main() {
238238
webOnlyWindowName: null,
239239
showTitle: false,
240240
)
241-
..setResponse(true);
241+
..setLaunchResponse(true);
242242
expect(
243243
await launchUrlString(
244244
urlString,
@@ -262,7 +262,7 @@ void main() {
262262
webOnlyWindowName: null,
263263
showTitle: false,
264264
)
265-
..setResponse(true);
265+
..setLaunchResponse(true);
266266
expect(
267267
await launchUrlString(
268268
urlString,
@@ -295,7 +295,7 @@ void main() {
295295
webOnlyWindowName: null,
296296
showTitle: false,
297297
)
298-
..setResponse(true);
298+
..setLaunchResponse(true);
299299
expect(await launchUrlString(emailLaunchUrlString), isTrue);
300300
});
301301

@@ -313,7 +313,7 @@ void main() {
313313
webOnlyWindowName: null,
314314
showTitle: false,
315315
)
316-
..setResponse(true);
316+
..setLaunchResponse(true);
317317
expect(await launchUrlString(urlString), isTrue);
318318
});
319319
});

0 commit comments

Comments
 (0)