mirror of
https://github.com/flutter/flutter.git
synced 2026-02-20 02:29:02 +08:00
* Update project.pbxproj files to say Flutter rather than Chromium Also, the templates now have an empty organization so that we don't cause people to give their apps a Flutter copyright. * Update the copyright notice checker to require a standard notice on all files * Update copyrights on Dart files. (This was a mechanical commit.) * Fix weird license headers on Dart files that deviate from our conventions; relicense Shrine. Some were already marked "The Flutter Authors", not clear why. Their dates have been normalized. Some were missing the blank line after the license. Some were randomly different in trivial ways for no apparent reason (e.g. missing the trailing period). * Clean up the copyrights in non-Dart files. (Manual edits.) Also, make sure templates don't have copyrights. * Fix some more ORGANIZATIONNAMEs
213 lines
6.3 KiB
Dart
213 lines
6.3 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.
|
|
|
|
@TestOn('chrome')
|
|
|
|
import 'dart:async';
|
|
|
|
import 'package:flutter/rendering.dart';
|
|
import 'package:flutter/services.dart';
|
|
import 'package:flutter/widgets.dart';
|
|
import 'package:flutter_test/flutter_test.dart';
|
|
|
|
import '../services/fake_platform_views.dart';
|
|
|
|
void main() {
|
|
group('HtmlElementView', () {
|
|
testWidgets('Create HTML view', (WidgetTester tester) async {
|
|
final int currentViewId = platformViewsRegistry.getNextPlatformViewId();
|
|
final FakeHtmlPlatformViewsController viewsController = FakeHtmlPlatformViewsController();
|
|
viewsController.registerViewType('webview');
|
|
|
|
await tester.pumpWidget(
|
|
const Center(
|
|
child: SizedBox(
|
|
width: 200.0,
|
|
height: 100.0,
|
|
child: HtmlElementView(viewType: 'webview'),
|
|
),
|
|
),
|
|
);
|
|
|
|
expect(
|
|
viewsController.views,
|
|
unorderedEquals(<FakeHtmlPlatformView>[
|
|
FakeHtmlPlatformView(currentViewId + 1, 'webview'),
|
|
]),
|
|
);
|
|
});
|
|
|
|
testWidgets('Resize HTML view', (WidgetTester tester) async {
|
|
final int currentViewId = platformViewsRegistry.getNextPlatformViewId();
|
|
final FakeHtmlPlatformViewsController viewsController = FakeHtmlPlatformViewsController();
|
|
viewsController.registerViewType('webview');
|
|
await tester.pumpWidget(
|
|
const Center(
|
|
child: SizedBox(
|
|
width: 200.0,
|
|
height: 100.0,
|
|
child: HtmlElementView(viewType: 'webview'),
|
|
),
|
|
),
|
|
);
|
|
|
|
viewsController.resizeCompleter = Completer<void>();
|
|
|
|
await tester.pumpWidget(
|
|
const Center(
|
|
child: SizedBox(
|
|
width: 100.0,
|
|
height: 50.0,
|
|
child: HtmlElementView(viewType: 'webview'),
|
|
),
|
|
),
|
|
);
|
|
|
|
viewsController.resizeCompleter.complete();
|
|
await tester.pump();
|
|
|
|
expect(
|
|
viewsController.views,
|
|
unorderedEquals(<FakeHtmlPlatformView>[
|
|
FakeHtmlPlatformView(currentViewId + 1, 'webview'),
|
|
]),
|
|
);
|
|
});
|
|
|
|
testWidgets('Change HTML view type', (WidgetTester tester) async {
|
|
final int currentViewId = platformViewsRegistry.getNextPlatformViewId();
|
|
final FakeHtmlPlatformViewsController viewsController = FakeHtmlPlatformViewsController();
|
|
viewsController.registerViewType('webview');
|
|
viewsController.registerViewType('maps');
|
|
await tester.pumpWidget(
|
|
const Center(
|
|
child: SizedBox(
|
|
width: 200.0,
|
|
height: 100.0,
|
|
child: HtmlElementView(viewType: 'webview'),
|
|
),
|
|
),
|
|
);
|
|
|
|
await tester.pumpWidget(
|
|
const Center(
|
|
child: SizedBox(
|
|
width: 200.0,
|
|
height: 100.0,
|
|
child: HtmlElementView(viewType: 'maps'),
|
|
),
|
|
),
|
|
);
|
|
|
|
expect(
|
|
viewsController.views,
|
|
unorderedEquals(<FakeHtmlPlatformView>[
|
|
FakeHtmlPlatformView(currentViewId + 2, 'maps'),
|
|
]),
|
|
);
|
|
});
|
|
|
|
testWidgets('Dispose HTML view', (WidgetTester tester) async {
|
|
final FakeHtmlPlatformViewsController viewsController = FakeHtmlPlatformViewsController();
|
|
viewsController.registerViewType('webview');
|
|
await tester.pumpWidget(
|
|
const Center(
|
|
child: SizedBox(
|
|
width: 200.0,
|
|
height: 100.0,
|
|
child: HtmlElementView(viewType: 'webview'),
|
|
),
|
|
),
|
|
);
|
|
|
|
await tester.pumpWidget(
|
|
const Center(
|
|
child: SizedBox(
|
|
width: 200.0,
|
|
height: 100.0,
|
|
),
|
|
),
|
|
);
|
|
|
|
expect(
|
|
viewsController.views,
|
|
isEmpty,
|
|
);
|
|
});
|
|
|
|
testWidgets('HTML view survives widget tree change', (WidgetTester tester) async {
|
|
final int currentViewId = platformViewsRegistry.getNextPlatformViewId();
|
|
final FakeHtmlPlatformViewsController viewsController = FakeHtmlPlatformViewsController();
|
|
viewsController.registerViewType('webview');
|
|
final GlobalKey key = GlobalKey();
|
|
await tester.pumpWidget(
|
|
Center(
|
|
child: SizedBox(
|
|
width: 200.0,
|
|
height: 100.0,
|
|
child: HtmlElementView(viewType: 'webview', key: key),
|
|
),
|
|
),
|
|
);
|
|
|
|
await tester.pumpWidget(
|
|
Center(
|
|
child: Container(
|
|
child: SizedBox(
|
|
width: 200.0,
|
|
height: 100.0,
|
|
child: HtmlElementView(viewType: 'webview', key: key),
|
|
),
|
|
),
|
|
),
|
|
);
|
|
|
|
expect(
|
|
viewsController.views,
|
|
unorderedEquals(<FakeHtmlPlatformView>[
|
|
FakeHtmlPlatformView(currentViewId + 1, 'webview'),
|
|
]),
|
|
);
|
|
});
|
|
|
|
testWidgets('HtmlElementView has correct semantics', (WidgetTester tester) async {
|
|
final SemanticsHandle handle = tester.ensureSemantics();
|
|
final int currentViewId = platformViewsRegistry.getNextPlatformViewId();
|
|
expect(currentViewId, greaterThanOrEqualTo(0));
|
|
final FakeHtmlPlatformViewsController viewsController = FakeHtmlPlatformViewsController();
|
|
viewsController.registerViewType('webview');
|
|
|
|
await tester.pumpWidget(
|
|
Semantics(
|
|
container: true,
|
|
child: const Align(
|
|
alignment: Alignment.bottomRight,
|
|
child: SizedBox(
|
|
width: 200.0,
|
|
height: 100.0,
|
|
child: HtmlElementView(
|
|
viewType: 'webview',
|
|
),
|
|
),
|
|
),
|
|
),
|
|
);
|
|
// First frame is before the platform view was created so the render object
|
|
// is not yet in the tree.
|
|
await tester.pump();
|
|
|
|
// The platform view ID is set on the child of the HtmlElementView render object.
|
|
final SemanticsNode semantics = tester.getSemantics(find.byType(PlatformViewSurface));
|
|
|
|
expect(semantics.platformViewId, currentViewId + 1);
|
|
expect(semantics.rect, const Rect.fromLTWH(0, 0, 200, 100));
|
|
// A 200x100 rect positioned at bottom right of a 800x600 box.
|
|
expect(semantics.transform, Matrix4.translationValues(600, 500, 0));
|
|
expect(semantics.childrenCount, 0);
|
|
|
|
handle.dispose();
|
|
});
|
|
});
|
|
}
|