|  | 
|  | 1 | +// Copyright 2013 The Flutter Authors. All rights reserved. | 
|  | 2 | +// Use of this source code is governed by a BSD-style license that can be | 
|  | 3 | +// found in the LICENSE file. | 
|  | 4 | + | 
|  | 5 | +// @dart = 2.12 | 
|  | 6 | +import 'dart:async'; | 
|  | 7 | +import 'dart:html' as html; | 
|  | 8 | + | 
|  | 9 | +import 'package:ui/src/engine.dart'; | 
|  | 10 | +import 'package:ui/ui.dart' as ui; | 
|  | 11 | + | 
|  | 12 | +import 'package:test/bootstrap/browser.dart'; | 
|  | 13 | +import 'package:test/test.dart'; | 
|  | 14 | + | 
|  | 15 | +import 'common.dart'; | 
|  | 16 | + | 
|  | 17 | +const MethodCodec codec = StandardMethodCodec(); | 
|  | 18 | +final EngineSingletonFlutterWindow window = EngineSingletonFlutterWindow(0, EnginePlatformDispatcher.instance); | 
|  | 19 | + | 
|  | 20 | +void main() { | 
|  | 21 | +  internalBootstrapBrowserTest(() => testMain); | 
|  | 22 | +} | 
|  | 23 | + | 
|  | 24 | +void testMain() { | 
|  | 25 | +  group('HtmlViewEmbedder', () { | 
|  | 26 | +    setUpCanvasKitTest(); | 
|  | 27 | + | 
|  | 28 | +    test('embeds interactive platform views', () async { | 
|  | 29 | +      ui.platformViewRegistry.registerViewFactory( | 
|  | 30 | +        'test-platform-view', | 
|  | 31 | +        (viewId) => html.DivElement()..id = 'view-0', | 
|  | 32 | +      ); | 
|  | 33 | +      await _createPlatformView(0, 'test-platform-view'); | 
|  | 34 | + | 
|  | 35 | +      final EnginePlatformDispatcher dispatcher = ui.window.platformDispatcher as EnginePlatformDispatcher; | 
|  | 36 | +      final LayerSceneBuilder sb = LayerSceneBuilder(); | 
|  | 37 | +      sb.pushOffset(0, 0); | 
|  | 38 | +      sb.addPlatformView(0, width: 10, height: 10); | 
|  | 39 | +      dispatcher.rasterizer!.draw(sb.build().layerTree); | 
|  | 40 | +      expect( | 
|  | 41 | +        domRenderer.sceneElement!.querySelectorAll('#view-0').single.style.pointerEvents, | 
|  | 42 | +        'auto', | 
|  | 43 | +      ); | 
|  | 44 | +    }); | 
|  | 45 | +    // TODO: https://github.com/flutter/flutter/issues/60040 | 
|  | 46 | +  }, skip: isIosSafari); | 
|  | 47 | +} | 
|  | 48 | + | 
|  | 49 | +// Sends a platform message to create a Platform View with the given id and viewType. | 
|  | 50 | +Future<void> _createPlatformView(int id, String viewType) { | 
|  | 51 | +  final completer = Completer<void>(); | 
|  | 52 | +  window.sendPlatformMessage( | 
|  | 53 | +    'flutter/platform_views', | 
|  | 54 | +    codec.encodeMethodCall(MethodCall( | 
|  | 55 | +      'create', | 
|  | 56 | +      <String, dynamic>{ | 
|  | 57 | +        'id': id, | 
|  | 58 | +        'viewType': viewType, | 
|  | 59 | +      }, | 
|  | 60 | +    )), | 
|  | 61 | +    (dynamic _) => completer.complete(), | 
|  | 62 | +  ); | 
|  | 63 | +  return completer.future; | 
|  | 64 | +} | 
0 commit comments