Skip to content
This repository has been archived by the owner on Feb 22, 2023. It is now read-only.

[multiple_web] Adapt web PlatformView widgets to work slotted. #3964

Merged
merged 8 commits into from
Jun 1, 2021
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .cirrus.yml
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ task:
env:
# Currently missing; see https://github.com/flutter/flutter/issues/81982
# and https://github.com/flutter/flutter/issues/82211
PLUGINS_TO_EXCLUDE_INTEGRATION_TESTS: "file_selector,image_picker_for_web,shared_preferences_web,video_player_web"
PLUGINS_TO_EXCLUDE_INTEGRATION_TESTS: "file_selector,image_picker_for_web,shared_preferences_web"
matrix:
CHANNEL: "master"
CHANNEL: "stable"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 0.3.0+1

* Change sizing code of `GoogleMap` widget's `HtmlElementView` so it works well when slotted.

## 0.3.0

* Migrate package to null-safety.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,10 @@ class GoogleMapController {
// Register the view factory that will hold the `_div` that holds the map in the DOM.
// The `_div` needs to be created outside of the ViewFactory (and cached!) so we can
// use it to create the [gmaps.GMap] in the `init()` method of this class.
_div = DivElement()..id = _getViewType(mapId);
_div = DivElement()
..id = _getViewType(mapId)
..style.width = '100%'
..style.height = '100%';

ui.platformViewRegistry.registerViewFactory(
_getViewType(mapId),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: google_maps_flutter_web
description: Web platform implementation of google_maps_flutter
repository: https://github.com/flutter/plugins/tree/master/packages/google_maps_flutter/google_maps_flutter_web
issue_tracker: https://github.com/flutter/flutter/issues?q=is%3Aissue+is%3Aopen+label%3A%22p%3A+maps%22
version: 0.3.0
version: 0.3.0+1

environment:
sdk: ">=2.12.0 <3.0.0"
Expand Down
3 changes: 2 additions & 1 deletion packages/url_launcher/url_launcher/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
## NEXT
## 6.0.5

* Add iOS unit and UI integration test targets.
* Add a `Link` widget to the example app.

## 6.0.4

Expand Down
14 changes: 14 additions & 0 deletions packages/url_launcher/url_launcher/example/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import 'dart:async';

import 'package:flutter/material.dart';
import 'package:url_launcher/link.dart';
import 'package:url_launcher/url_launcher.dart';

void main() {
Expand Down Expand Up @@ -196,6 +197,19 @@ class _MyHomePageState extends State<MyHomePage> {
child: const Text('Launch in app + close after 5 seconds'),
),
const Padding(padding: EdgeInsets.all(16.0)),
Link(
uri: Uri.parse(
'https://pub.dev/documentation/url_launcher/latest/link/link-library.html'),
target: LinkTarget.blank,
builder: (ctx, openLink) {
return TextButton.icon(
onPressed: openLink,
label: Text('Link Widget documentation'),
icon: Icon(Icons.read_more),
);
},
),
const Padding(padding: EdgeInsets.all(16.0)),
FutureBuilder<void>(future: _launched, builder: _launchStatus),
],
),
Expand Down
2 changes: 1 addition & 1 deletion packages/url_launcher/url_launcher/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ description: Flutter plugin for launching a URL. Supports
web, phone, SMS, and email schemes.
repository: https://github.com/flutter/plugins/tree/master/packages/url_launcher/url_launcher
issue_tracker: https://github.com/flutter/flutter/issues?q=is%3Aissue+is%3Aopen+label%3A%22p%3A+url_launcher%22
version: 6.0.4
version: 6.0.5

environment:
sdk: ">=2.12.0 <3.0.0"
Expand Down
4 changes: 4 additions & 0 deletions packages/url_launcher/url_launcher_web/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# 2.0.1

- Change sizing code of `Link` widget's `HtmlElementView` so it works well when slotted.

# 2.0.0

- Migrate to null safety.
Expand Down
2 changes: 2 additions & 0 deletions packages/url_launcher/url_launcher_web/lib/src/link.dart
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,8 @@ class LinkViewController extends PlatformViewController {
_element.style
..opacity = '0'
..display = 'block'
..width = '100%'
..height = '100%'
..cursor = 'unset';

// This is recommended on MDN:
Expand Down
2 changes: 1 addition & 1 deletion packages/url_launcher/url_launcher_web/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: url_launcher_web
description: Web platform implementation of url_launcher
repository: https://github.com/flutter/plugins/tree/master/packages/url_launcher/url_launcher_web
issue_tracker: https://github.com/flutter/flutter/issues?q=is%3Aissue+is%3Aopen+label%3A%22p%3A+url_launcher%22
version: 2.0.0
version: 2.0.1

environment:
sdk: ">=2.12.0 <3.0.0"
Expand Down
5 changes: 5 additions & 0 deletions packages/video_player/video_player_web/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
## 2.0.1

* Change sizing code of `Video` widget's `HtmlElementView` so it works well when slotted.
* Move tests to `example` directory, so they run as integration_tests with `flutter drive`.

## 2.0.0

* Migrate to null safety.
Expand Down
21 changes: 21 additions & 0 deletions packages/video_player/video_player_web/example/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Testing

This package utilizes the `integration_test` package to run its tests in a web browser.

See [flutter.dev > Integration testing](https://flutter.dev/docs/testing/integration-tests) for more info.

## Running the tests
ditman marked this conversation as resolved.
Show resolved Hide resolved

Make sure you have updated to the latest Flutter master.

1. Check what version of Chrome is running on the machine you're running tests on.

2. Download and install driver for that version from here:
* <https://chromedriver.chromium.org/downloads>

3. Start the driver using `chromedriver --port=4444`

4. Run tests: `flutter drive -d web-server --browser-name=chrome --driver=test_driver/integration_driver.dart --target=integration_test/TEST_NAME.dart`, or (in Linux):

* Single: `./run_test.sh integration_test/TEST_NAME.dart`
* All: `./run_test.sh`
Original file line number Diff line number Diff line change
Expand Up @@ -2,39 +2,39 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

@TestOn('browser')

import 'dart:async';

import 'package:flutter/services.dart';
import 'package:flutter/widgets.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:integration_test/integration_test.dart';
import 'package:video_player_platform_interface/video_player_platform_interface.dart';
import 'package:video_player_web/video_player_web.dart';

void main() {
IntegrationTestWidgetsFlutterBinding.ensureInitialized();

group('VideoPlayer for Web', () {
late int textureId;
late Future<int> textureId;

setUp(() async {
setUp(() {
VideoPlayerPlatform.instance = VideoPlayerPlugin();
textureId = (await VideoPlayerPlatform.instance.create(
DataSource(
sourceType: DataSourceType.network,
uri:
'https://flutter.github.io/assets-for-api-docs/assets/videos/bee.mp4'),
))!;
});

test('$VideoPlayerPlugin is the live instance', () {
expect(VideoPlayerPlatform.instance, isA<VideoPlayerPlugin>());
textureId = VideoPlayerPlatform.instance
.create(
DataSource(
sourceType: DataSourceType.network,
uri:
'https://flutter.github.io/assets-for-api-docs/assets/videos/bee.mp4',
),
)
.then((textureId) => textureId!);
});

test('can init', () {
testWidgets('can init', (WidgetTester tester) async {
expect(VideoPlayerPlatform.instance.init(), completes);
});

test('can create from network', () {
testWidgets('can create from network', (WidgetTester tester) async {
expect(
VideoPlayerPlatform.instance.create(
DataSource(
Expand All @@ -45,7 +45,7 @@ void main() {
completion(isNonZero));
});

test('can create from asset', () {
testWidgets('can create from asset', (WidgetTester tester) async {
expect(
VideoPlayerPlatform.instance.create(
DataSource(
Expand All @@ -57,7 +57,7 @@ void main() {
completion(isNonZero));
});

test('cannot create from file', () {
testWidgets('cannot create from file', (WidgetTester tester) async {
expect(
VideoPlayerPlatform.instance.create(
DataSource(
Expand All @@ -68,22 +68,25 @@ void main() {
throwsUnimplementedError);
});

test('can dispose', () {
expect(VideoPlayerPlatform.instance.dispose(textureId), completes);
testWidgets('can dispose', (WidgetTester tester) async {
expect(VideoPlayerPlatform.instance.dispose(await textureId), completes);
});

test('can set looping', () {
testWidgets('can set looping', (WidgetTester tester) async {
expect(
VideoPlayerPlatform.instance.setLooping(textureId, true), completes);
VideoPlayerPlatform.instance.setLooping(await textureId, true),
completes,
);
});

test('can play', () async {
testWidgets('can play', (WidgetTester tester) async {
// Mute video to allow autoplay (See https://goo.gl/xX8pDD)
await VideoPlayerPlatform.instance.setVolume(textureId, 0);
expect(VideoPlayerPlatform.instance.play(textureId), completes);
await VideoPlayerPlatform.instance.setVolume(await textureId, 0);
expect(VideoPlayerPlatform.instance.play(await textureId), completes);
});

test('throws PlatformException when playing bad media', () async {
testWidgets('throws PlatformException when playing bad media',
(WidgetTester tester) async {
int videoPlayerId = (await VideoPlayerPlatform.instance.create(
DataSource(
sourceType: DataSourceType.network,
Expand All @@ -103,43 +106,50 @@ void main() {
}, throwsA(isA<PlatformException>()));
});

test('can pause', () {
expect(VideoPlayerPlatform.instance.pause(textureId), completes);
testWidgets('can pause', (WidgetTester tester) async {
expect(VideoPlayerPlatform.instance.pause(await textureId), completes);
});

test('can set volume', () {
expect(VideoPlayerPlatform.instance.setVolume(textureId, 0.8), completes);
testWidgets('can set volume', (WidgetTester tester) async {
expect(
VideoPlayerPlatform.instance.setVolume(await textureId, 0.8),
completes,
);
});

test('can set playback speed', () {
testWidgets('can set playback speed', (WidgetTester tester) async {
expect(
VideoPlayerPlatform.instance.setPlaybackSpeed(textureId, 2.0),
VideoPlayerPlatform.instance.setPlaybackSpeed(await textureId, 2.0),
completes,
);
});

test('can seek to position', () {
testWidgets('can seek to position', (WidgetTester tester) async {
expect(
VideoPlayerPlatform.instance.seekTo(textureId, Duration(seconds: 1)),
completes);
VideoPlayerPlatform.instance.seekTo(
await textureId,
Duration(seconds: 1),
),
completes,
);
});

test('can get position', () {
expect(VideoPlayerPlatform.instance.getPosition(textureId),
testWidgets('can get position', (WidgetTester tester) async {
expect(VideoPlayerPlatform.instance.getPosition(await textureId),
completion(isInstanceOf<Duration>()));
});

test('can get video event stream', () {
expect(VideoPlayerPlatform.instance.videoEventsFor(textureId),
testWidgets('can get video event stream', (WidgetTester tester) async {
expect(VideoPlayerPlatform.instance.videoEventsFor(await textureId),
isInstanceOf<Stream<VideoEvent>>());
});

test('can build view', () {
expect(VideoPlayerPlatform.instance.buildView(textureId),
testWidgets('can build view', (WidgetTester tester) async {
expect(VideoPlayerPlatform.instance.buildView(await textureId),
isInstanceOf<Widget>());
});

test('ignores setting mixWithOthers', () {
testWidgets('ignores setting mixWithOthers', (WidgetTester tester) async {
expect(VideoPlayerPlatform.instance.setMixWithOthers(true), completes);
expect(VideoPlayerPlatform.instance.setMixWithOthers(false), completes);
});
Expand Down
25 changes: 25 additions & 0 deletions packages/video_player/video_player_web/example/lib/main.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
// 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 'package:flutter/material.dart';

void main() {
runApp(MyApp());
}

/// App for testing
class MyApp extends StatefulWidget {
@override
_MyAppState createState() => _MyAppState();
}

class _MyAppState extends State<MyApp> {
@override
Widget build(BuildContext context) {
return Directionality(
textDirection: TextDirection.ltr,
child: Text('Testing... Look at the console output for results!'),
);
}
}
20 changes: 20 additions & 0 deletions packages/video_player/video_player_web/example/pubspec.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
name: connectivity_for_web_integration_tests
publish_to: none

environment:
sdk: ">=2.12.0 <3.0.0"
flutter: ">=2.2.0"

dependencies:
video_player_web:
path: ../
flutter:
sdk: flutter

dev_dependencies:
flutter_test:
sdk: flutter
flutter_driver:
sdk: flutter
integration_test:
sdk: flutter
22 changes: 22 additions & 0 deletions packages/video_player/video_player_web/example/run_test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#!/usr/bin/bash
# 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.

if pgrep -lf chromedriver > /dev/null; then
echo "chromedriver is running."

if [ $# -eq 0 ]; then
echo "No target specified, running all tests..."
find integration_test/ -iname *_test.dart | xargs -n1 -i -t flutter drive -d web-server --web-port=7357 --browser-name=chrome --driver=test_driver/integration_test.dart --target='{}'
else
echo "Running test target: $1..."
set -x
flutter drive -d web-server --web-port=7357 --browser-name=chrome --driver=test_driver/integration_test.dart --target=$1
fi

else
echo "chromedriver is not running."
echo "Please, check the README.md for instructions on how to use run_test.sh"
fi

Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
// 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 'package:integration_test/integration_test_driver.dart';

Future<void> main() => integrationDriver();
Loading