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_web] migrate to pkg:web #5451

Merged
merged 8 commits into from Nov 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 5 additions & 0 deletions packages/url_launcher/url_launcher_web/CHANGELOG.md
@@ -1,3 +1,8 @@
## 2.2.1

* Supports Flutter Web + Wasm
* Updates minimum supported SDK version to Flutter 3.16.0/Dart 3.2.0.

## 2.2.0

* Implements `supportsMode` and `supportsCloseForMode`.
Expand Down
10 changes: 0 additions & 10 deletions packages/url_launcher/url_launcher_web/example/build.yaml

This file was deleted.

Expand Up @@ -2,7 +2,6 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

import 'dart:html' as html;
import 'dart:js_util';
import 'dart:ui_web' as ui_web;

Expand All @@ -11,6 +10,7 @@ import 'package:flutter_test/flutter_test.dart';
import 'package:integration_test/integration_test.dart';
import 'package:url_launcher_platform_interface/link.dart';
import 'package:url_launcher_web/src/link.dart';
import 'package:web/helpers.dart' as html;

void main() {
IntegrationTestWidgetsFlutterBinding.ensureInitialized();
Expand Down Expand Up @@ -174,7 +174,9 @@ void main() {

html.Element _findSingleAnchor() {
final List<html.Element> foundAnchors = <html.Element>[];
for (final html.Element anchor in html.document.querySelectorAll('a')) {
html.NodeList anchors = html.document.querySelectorAll('a');
for (int i = 0; i < anchors.length; i++) {
final html.Element anchor = anchors.item(i)! as html.Element;
if (hasProperty(anchor, linkViewIdProperty)) {
foundAnchors.add(anchor);
}
Expand All @@ -184,7 +186,9 @@ html.Element _findSingleAnchor() {
final html.ShadowRoot? shadowRoot =
html.document.querySelector('flt-glass-pane')?.shadowRoot;
if (shadowRoot != null) {
for (final html.Element anchor in shadowRoot.querySelectorAll('a')) {
anchors = shadowRoot.querySelectorAll('a');
for (int i = 0; i < anchors.length; i++) {
final html.Element anchor = anchors.item(i)! as html.Element;
if (hasProperty(anchor, linkViewIdProperty)) {
foundAnchors.add(anchor);
}
Expand Down
Expand Up @@ -2,18 +2,31 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

import 'dart:html' as html;
import 'dart:js_interop';
import 'dart:js_util';

import 'package:flutter_test/flutter_test.dart';
import 'package:integration_test/integration_test.dart';
import 'package:mockito/annotations.dart';
import 'package:mockito/mockito.dart';
import 'package:mockito/mockito.dart' show any, verify, when, Mock;
import 'package:url_launcher_platform_interface/url_launcher_platform_interface.dart';
import 'package:url_launcher_web/url_launcher_web.dart';
import 'package:web/helpers.dart' as html;

import 'url_launcher_web_test.mocks.dart';
abstract class MyWindow {
html.Window? open(Object? a, Object? b, Object? c);
html.Navigator? get navigator;
}

@JSExport()
class MockWindow extends Mock implements MyWindow {}

abstract class MyNavigator {
String? get userAgent;
}

@JSExport()
class MockNavigator extends Mock implements MyNavigator {}

@GenerateMocks(<Type>[html.Window, html.Navigator])
void main() {
IntegrationTestWidgetsFlutterBinding.ensureInitialized();

Expand All @@ -26,15 +39,21 @@ void main() {
setUp(() {
mockWindow = MockWindow();
mockNavigator = MockNavigator();
when(mockWindow.navigator).thenReturn(mockNavigator);

final html.Window jsMockWindow =
createDartExport(mockWindow) as html.Window;
final html.Navigator jsMockNavigator =
createDartExport(mockNavigator) as html.Navigator;

when(mockWindow.navigator).thenReturn(jsMockNavigator);

// Simulate that window.open does something.
when(mockWindow.open(any, any, any)).thenReturn(MockWindow());
when(mockWindow.open(any, any, any)).thenReturn(jsMockWindow);

when(mockNavigator.userAgent).thenReturn(
'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/114.0.0.0 Safari/537.36');

plugin = UrlLauncherPlugin(debugWindow: mockWindow);
plugin = UrlLauncherPlugin(debugWindow: mockWindow as html.Window);
});

group('canLaunch', () {
Expand All @@ -43,8 +62,7 @@ void main() {
});

testWidgets('"https" URLs -> true', (WidgetTester _) async {
expect(
plugin.canLaunch('https://go, (Widogle.com'), completion(isTrue));
expect(plugin.canLaunch('https://google.com'), completion(isTrue));
});

testWidgets('"mailto" URLs -> true', (WidgetTester _) async {
Expand Down Expand Up @@ -167,7 +185,7 @@ void main() {
when(mockNavigator.userAgent).thenReturn(
'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/16.5.1 Safari/605.1.15');
// Recreate the plugin, so it grabs the overrides from this group
plugin = UrlLauncherPlugin(debugWindow: mockWindow);
plugin = UrlLauncherPlugin(debugWindow: mockWindow as html.Window);
});

testWidgets('http urls should be launched in a new window',
Expand Down