mirror of
https://github.com/flutter/flutter.git
synced 2026-02-20 02:29:02 +08:00
Registering the service worker immediately after the documented has loaded may cause SW initialization to compete with framework initialization. It was recommended to us that we defer the service worker setup until after the framework is done with setup, which should be sometime after the first frame. To implement this, I augmented the binding setup to dispatch an event on the document after the binding has initialized. I don't see any obvious risks with this setup. Fixes #66066
39 lines
1.2 KiB
Dart
39 lines
1.2 KiB
Dart
// Copyright 2014 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.
|
|
|
|
// @dart = 2.8
|
|
|
|
import 'dart:async';
|
|
|
|
import 'package:flutter/foundation.dart';
|
|
import 'package:flutter/gestures.dart';
|
|
import 'package:flutter/rendering.dart';
|
|
import 'package:flutter/scheduler.dart';
|
|
import 'package:flutter/services.dart';
|
|
|
|
import '../flutter_test_alternative.dart';
|
|
|
|
void main() {
|
|
test('Flutter dispatches first frame event on the web only', () async {
|
|
final Completer<void> completer = Completer<void>();
|
|
final TestRenderBinding binding = TestRenderBinding();
|
|
const MethodChannel firstFrameChannel = MethodChannel('flutter/service_worker');
|
|
firstFrameChannel.setMockMethodCallHandler((MethodCall methodCall) async {
|
|
completer.complete();
|
|
});
|
|
|
|
binding.handleBeginFrame(Duration.zero);
|
|
binding.handleDrawFrame();
|
|
|
|
await expectLater(completer.future, completes);
|
|
}, skip: !kIsWeb);
|
|
}
|
|
|
|
class TestRenderBinding extends BindingBase with SchedulerBinding, ServicesBinding, GestureBinding, SemanticsBinding, RendererBinding {
|
|
@override
|
|
void initInstances() {
|
|
super.initInstances();
|
|
}
|
|
}
|