Skip to content

Commit f9869cc

Browse files
vashworthandroidseb
authored andcommitted
[webview_flutter] Fix macOS test issues and skip some legacy iOS tests (flutter#8895)
Tests on macOS were [failing](flutter/flutter#164632 (comment)) due to `videoTestBase64` not being initialized. This PR moved `videoTestBase64` initialization into each individual test. Tests on macOS were [failing](flutter/flutter#164632 (comment)) due matching failing because on some devices JavaScript turns a boolean as a string like `"false"` and sometimes as a number like `"0"`. This PR changes it to accept either regardless of device. Some legacy iOS tests are [flaking](flutter/flutter#164632 (comment)) with Xcode 16, so we're skipping them for now. ## Pre-Review Checklist [^1]: Regular contributors who have demonstrated familiarity with the repository guidelines only need to comment if the PR is not auto-exempted by repo tooling.
1 parent 8107316 commit f9869cc

File tree

4 files changed

+277
-264
lines changed

4 files changed

+277
-264
lines changed

packages/webview_flutter/webview_flutter/example/integration_test/webview_flutter_test.dart

Lines changed: 38 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -204,46 +204,8 @@ Future<void> main() async {
204204
});
205205

206206
group('Video playback policy', () {
207-
late String videoTestBase64;
208-
setUpAll(() async {
209-
final ByteData videoData =
210-
await rootBundle.load('assets/sample_video.mp4');
211-
final String base64VideoData =
212-
base64Encode(Uint8List.view(videoData.buffer));
213-
final String videoTest = '''
214-
<!DOCTYPE html><html>
215-
<head><title>Video auto play</title>
216-
<script type="text/javascript">
217-
function play() {
218-
var video = document.getElementById("video");
219-
video.play();
220-
video.addEventListener('timeupdate', videoTimeUpdateHandler, false);
221-
}
222-
function videoTimeUpdateHandler(e) {
223-
var video = document.getElementById("video");
224-
VideoTestTime.postMessage(video.currentTime);
225-
}
226-
function isPaused() {
227-
var video = document.getElementById("video");
228-
return video.paused;
229-
}
230-
function isFullScreen() {
231-
var video = document.getElementById("video");
232-
return video.webkitDisplayingFullscreen;
233-
}
234-
</script>
235-
</head>
236-
<body onload="play();">
237-
<video controls playsinline autoplay id="video">
238-
<source src="data:video/mp4;charset=utf-8;base64,$base64VideoData">
239-
</video>
240-
</body>
241-
</html>
242-
''';
243-
videoTestBase64 = base64Encode(const Utf8Encoder().convert(videoTest));
244-
});
245-
246207
testWidgets('Auto media playback', (WidgetTester tester) async {
208+
final String videoTestBase64 = await getTestVideoBase64();
247209
Completer<void> pageLoaded = Completer<void>();
248210

249211
late PlatformWebViewControllerCreationParams params;
@@ -306,6 +268,7 @@ Future<void> main() async {
306268
});
307269

308270
testWidgets('Video plays inline', (WidgetTester tester) async {
271+
final String videoTestBase64 = await getTestVideoBase64();
309272
final Completer<void> pageLoaded = Completer<void>();
310273
final Completer<void> videoPlaying = Completer<void>();
311274

@@ -1062,3 +1025,39 @@ class ResizableWebViewState extends State<ResizableWebView> {
10621025
);
10631026
}
10641027
}
1028+
1029+
Future<String> getTestVideoBase64() async {
1030+
final ByteData videoData = await rootBundle.load('assets/sample_video.mp4');
1031+
final String base64VideoData = base64Encode(Uint8List.view(videoData.buffer));
1032+
final String videoTest = '''
1033+
<!DOCTYPE html><html>
1034+
<head><title>Video auto play</title>
1035+
<script type="text/javascript">
1036+
function play() {
1037+
var video = document.getElementById("video");
1038+
video.play();
1039+
video.addEventListener('timeupdate', videoTimeUpdateHandler, false);
1040+
}
1041+
function videoTimeUpdateHandler(e) {
1042+
var video = document.getElementById("video");
1043+
VideoTestTime.postMessage(video.currentTime);
1044+
}
1045+
function isPaused() {
1046+
var video = document.getElementById("video");
1047+
return video.paused;
1048+
}
1049+
function isFullScreen() {
1050+
var video = document.getElementById("video");
1051+
return video.webkitDisplayingFullscreen;
1052+
}
1053+
</script>
1054+
</head>
1055+
<body onload="play();">
1056+
<video controls playsinline autoplay id="video">
1057+
<source src="data:video/mp4;charset=utf-8;base64,$base64VideoData">
1058+
</video>
1059+
</body>
1060+
</html>
1061+
''';
1062+
return base64Encode(const Utf8Encoder().convert(videoTest));
1063+
}

0 commit comments

Comments
 (0)