Skip to content
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

[url_launcher] Add an inAppBrowserView mode #5155

Merged
merged 21 commits into from
Oct 24, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
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
Add desktop implementations of new methods
  • Loading branch information
stuartmorgan committed Oct 12, 2023
commit d155a015b74ee0f2033e2128140a3ba46b66fc41
Original file line number Diff line number Diff line change
Expand Up @@ -51,4 +51,16 @@ class UrlLauncherLinux extends UrlLauncherPlatform {
},
).then((bool? value) => value ?? false);
}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I didn't add launchUrl to the desktop platforms in this PR because they don't currently support any mode switches, so it didn't seem as useful. (Someday I'll update them just so we can deprecate launch.)

@override
Future<bool> supportsMode(PreferredLaunchMode mode) async {
return mode == PreferredLaunchMode.platformDefault ||
mode == PreferredLaunchMode.externalApplication;
}

@override
Future<bool> supportsCloseForMode(PreferredLaunchMode mode) async {
// No supported mode is closeable.
return false;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import 'package:url_launcher_platform_interface/url_launcher_platform_interface.
void main() {
TestWidgetsFlutterBinding.ensureInitialized();

group('$UrlLauncherLinux', () {
group('UrlLauncherLinux', () {
const MethodChannel channel =
MethodChannel('plugins.flutter.io/url_launcher_linux');
final List<MethodCall> log = <MethodCall>[];
Expand Down Expand Up @@ -142,6 +142,47 @@ void main() {

expect(launched, false);
});

group('supportsMode', () {
test('returns true for platformDefault', () async {
final UrlLauncherLinux launcher = UrlLauncherLinux();
expect(await launcher.supportsMode(PreferredLaunchMode.platformDefault),
true);
});

test('returns true for external application', () async {
final UrlLauncherLinux launcher = UrlLauncherLinux();
expect(
await launcher
.supportsMode(PreferredLaunchMode.externalApplication),
true);
});

test('returns false for other modes', () async {
final UrlLauncherLinux launcher = UrlLauncherLinux();
expect(
await launcher.supportsMode(
PreferredLaunchMode.externalNonBrowserApplication),
false);
expect(
await launcher.supportsMode(PreferredLaunchMode.inAppBrowserView),
false);
expect(await launcher.supportsMode(PreferredLaunchMode.inAppWebView),
false);
});
});

test('supportsCloseForMode returns false', () async {
final UrlLauncherLinux launcher = UrlLauncherLinux();
expect(
await launcher
.supportsCloseForMode(PreferredLaunchMode.platformDefault),
false);
expect(
await launcher
.supportsCloseForMode(PreferredLaunchMode.externalApplication),
false);
});
});
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,18 @@ class UrlLauncherMacOS extends UrlLauncherPlatform {
return result.value;
}

@override
Future<bool> supportsMode(PreferredLaunchMode mode) async {
return mode == PreferredLaunchMode.platformDefault ||
mode == PreferredLaunchMode.externalApplication;
}

@override
Future<bool> supportsCloseForMode(PreferredLaunchMode mode) async {
// No supported mode is closeable.
return false;
}

Exception _getInvalidUrlException(String url) {
// TODO(stuartmorgan): Make this an actual ArgumentError. This should be
// coordinated across all platforms as a breaking change to have them all
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,47 @@ void main() {
throwsA(isA<PlatformException>()));
});
});

group('supportsMode', () {
test('returns true for platformDefault', () async {
final UrlLauncherMacOS launcher = UrlLauncherMacOS(api: api);
expect(await launcher.supportsMode(PreferredLaunchMode.platformDefault),
true);
});

test('returns true for external application', () async {
final UrlLauncherMacOS launcher = UrlLauncherMacOS(api: api);
expect(
await launcher
.supportsMode(PreferredLaunchMode.externalApplication),
true);
});

test('returns false for other modes', () async {
final UrlLauncherMacOS launcher = UrlLauncherMacOS(api: api);
expect(
await launcher.supportsMode(
PreferredLaunchMode.externalNonBrowserApplication),
false);
expect(
await launcher.supportsMode(PreferredLaunchMode.inAppBrowserView),
false);
expect(await launcher.supportsMode(PreferredLaunchMode.inAppWebView),
false);
});
});

test('supportsCloseForMode returns false', () async {
final UrlLauncherMacOS launcher = UrlLauncherMacOS(api: api);
expect(
await launcher
.supportsCloseForMode(PreferredLaunchMode.platformDefault),
false);
expect(
await launcher
.supportsCloseForMode(PreferredLaunchMode.externalApplication),
false);
});
});
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,4 +45,16 @@ class UrlLauncherWindows extends UrlLauncherPlatform {
// Failure is handled via a PlatformException from `launchUrl`.
return true;
}

@override
Future<bool> supportsMode(PreferredLaunchMode mode) async {
return mode == PreferredLaunchMode.platformDefault ||
mode == PreferredLaunchMode.externalApplication;
}

@override
Future<bool> supportsCloseForMode(PreferredLaunchMode mode) async {
// No supported mode is closeable.
return false;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,45 @@ void main() {
expect(api.argument, 'http://example.com/');
});
});

group('supportsMode', () {
test('returns true for platformDefault', () async {
final UrlLauncherWindows launcher = UrlLauncherWindows(api: api);
expect(await launcher.supportsMode(PreferredLaunchMode.platformDefault),
true);
});

test('returns true for external application', () async {
final UrlLauncherWindows launcher = UrlLauncherWindows(api: api);
expect(
await launcher.supportsMode(PreferredLaunchMode.externalApplication),
true);
});

test('returns false for other modes', () async {
final UrlLauncherWindows launcher = UrlLauncherWindows(api: api);
expect(
await launcher
.supportsMode(PreferredLaunchMode.externalNonBrowserApplication),
false);
expect(await launcher.supportsMode(PreferredLaunchMode.inAppBrowserView),
false);
expect(
await launcher.supportsMode(PreferredLaunchMode.inAppWebView), false);
});
});

test('supportsCloseForMode returns false', () async {
final UrlLauncherWindows launcher = UrlLauncherWindows(api: api);
expect(
await launcher
.supportsCloseForMode(PreferredLaunchMode.platformDefault),
false);
expect(
await launcher
.supportsCloseForMode(PreferredLaunchMode.externalApplication),
false);
});
}

class _FakeUrlLauncherApi implements UrlLauncherApi {
Expand Down