mirror of
https://github.com/flutter/flutter.git
synced 2026-02-20 02:29:02 +08:00
* change from build_runner to dart2js * add internalBootstrapBrowserTest to some of the tests * add internalBootstrapBrowserTest to all remaining tests * make tests build in paralel. Total time dropped from 586 to 177 seconds for 8 core MacBook * change isolates with pool * fixing analysis errors * skipping canvaskit tests for ios-safari * copy image files to the build directory * adding internalBootstrapBrowserTest to newly added tests * add internalBootstrapBrowserTest to faling path iterator test * necessary changes to make chrome windows work * in windows test in chrome instead of edge. our edge code was for legacy edge * do not run golden unit tests on Windows LUCI bots for now * addressing reviewer comments. Adding a method for deciding when to run integration tests. * remove lines that I forgot to remove * fixing analysis error. add issue for todo * add bootstap to a test file * adding bootstrap to another test * add internalBootstrapBrowserTest to a golden test * return test result in bat file. use archieve package to unzip * fixing logs for chrome_installer * use archieve and archieve entity instead of dynamic * adding comments for windows platform archieve part * addressing reviewer comments * change readme file
124 lines
4.7 KiB
Dart
124 lines
4.7 KiB
Dart
// 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.
|
|
|
|
// @dart = 2.6
|
|
import 'dart:async';
|
|
import 'dart:convert';
|
|
import 'dart:html' as html;
|
|
import 'dart:typed_data';
|
|
|
|
import 'package:test/bootstrap/browser.dart';
|
|
import 'package:test/test.dart';
|
|
import 'package:ui/ui.dart' as ui;
|
|
import 'package:ui/src/engine.dart';
|
|
|
|
void main() {
|
|
internalBootstrapBrowserTest(() => testMain);
|
|
}
|
|
|
|
void testMain() async {
|
|
await ui.webOnlyInitializeTestDomRenderer();
|
|
group('loadFontFromList', () {
|
|
const String _testFontUrl = 'packages/ui/assets/ahem.ttf';
|
|
|
|
tearDown(() {
|
|
html.document.fonts.clear();
|
|
});
|
|
|
|
test('surfaces error from invalid font buffer', () async {
|
|
await expectLater(
|
|
ui.loadFontFromList(Uint8List(0), fontFamily: 'test-font'),
|
|
throwsA(TypeMatcher<Exception>()));
|
|
},
|
|
// TODO(nurhan): https://github.com/flutter/flutter/issues/56702
|
|
// TODO(nurhan): https://github.com/flutter/flutter/issues/50770
|
|
skip: (browserEngine == BrowserEngine.edge ||
|
|
browserEngine == BrowserEngine.webkit));
|
|
|
|
test('loads Blehm font from buffer', () async {
|
|
expect(_containsFontFamily('Blehm'), false);
|
|
|
|
final html.HttpRequest response = await html.HttpRequest.request(
|
|
_testFontUrl,
|
|
responseType: 'arraybuffer');
|
|
await ui.loadFontFromList(Uint8List.view(response.response),
|
|
fontFamily: 'Blehm');
|
|
|
|
expect(_containsFontFamily('Blehm'), true);
|
|
},
|
|
// TODO(nurhan): https://github.com/flutter/flutter/issues/56702
|
|
// TODO(nurhan): https://github.com/flutter/flutter/issues/50770
|
|
skip: (browserEngine == BrowserEngine.edge ||
|
|
browserEngine == BrowserEngine.webkit));
|
|
|
|
test('loading font should clear measurement caches', () async {
|
|
final ui.ParagraphStyle style = ui.ParagraphStyle();
|
|
final ui.ParagraphBuilder builder = ui.ParagraphBuilder(style);
|
|
final ui.ParagraphConstraints constraints =
|
|
ui.ParagraphConstraints(width: 30.0);
|
|
builder.addText('test');
|
|
final ui.Paragraph paragraph = builder.build();
|
|
// Triggers the measuring and verifies the result has been cached.
|
|
paragraph.layout(constraints);
|
|
expect(TextMeasurementService.rulerManager.rulers.length, 1);
|
|
|
|
// Now, loads a new font using loadFontFromList. This should clear the
|
|
// cache
|
|
final html.HttpRequest response = await html.HttpRequest.request(
|
|
_testFontUrl,
|
|
responseType: 'arraybuffer');
|
|
await ui.loadFontFromList(Uint8List.view(response.response),
|
|
fontFamily: 'Blehm');
|
|
|
|
// Verifies the font is loaded, and the cache is cleaned.
|
|
expect(_containsFontFamily('Blehm'), true);
|
|
expect(TextMeasurementService.rulerManager.rulers.length, 0);
|
|
},
|
|
// TODO(nurhan): https://github.com/flutter/flutter/issues/56702
|
|
// TODO(nurhan): https://github.com/flutter/flutter/issues/50770
|
|
skip: (browserEngine == BrowserEngine.edge ||
|
|
browserEngine == BrowserEngine.webkit));
|
|
|
|
test('loading font should send font change message', () async {
|
|
final ui.PlatformMessageCallback oldHandler = ui.window.onPlatformMessage;
|
|
String actualName;
|
|
String message;
|
|
window.onPlatformMessage = (String name, ByteData data,
|
|
ui.PlatformMessageResponseCallback callback) {
|
|
actualName = name;
|
|
final buffer = data.buffer;
|
|
final Uint8List list =
|
|
buffer.asUint8List(data.offsetInBytes, data.lengthInBytes);
|
|
message = utf8.decode(list);
|
|
};
|
|
final html.HttpRequest response = await html.HttpRequest.request(
|
|
_testFontUrl,
|
|
responseType: 'arraybuffer');
|
|
await ui.loadFontFromList(Uint8List.view(response.response),
|
|
fontFamily: 'Blehm');
|
|
final Completer<void> completer = Completer();
|
|
html.window.requestAnimationFrame( (_) { completer.complete(true); } );
|
|
await(completer.future);
|
|
window.onPlatformMessage = oldHandler;
|
|
expect(actualName, 'flutter/system');
|
|
expect(message, '{"type":"fontsChange"}');
|
|
},
|
|
// TODO(nurhan): https://github.com/flutter/flutter/issues/56702
|
|
// TODO(nurhan): https://github.com/flutter/flutter/issues/50770
|
|
skip: (browserEngine == BrowserEngine.edge ||
|
|
browserEngine == BrowserEngine.webkit));
|
|
});
|
|
}
|
|
|
|
bool _containsFontFamily(String family) {
|
|
bool found = false;
|
|
html.document.fonts.forEach((html.FontFace fontFace,
|
|
html.FontFace fontFaceAgain, html.FontFaceSet fontFaceSet) {
|
|
if (fontFace.family == family) {
|
|
found = true;
|
|
}
|
|
});
|
|
return found;
|
|
}
|