Skip to content

Commit

Permalink
use percent for golden diff rates; tighten the values (#16430)
Browse files Browse the repository at this point in the history
  • Loading branch information
yjbanov committed Feb 5, 2020
1 parent 8f89bac commit f34bc65
Show file tree
Hide file tree
Showing 10 changed files with 33 additions and 19 deletions.
Expand Up @@ -28,7 +28,7 @@ void main() async {
try {
sceneElement.append(engineCanvas.rootElement);
html.document.body.append(sceneElement);
await matchGoldenFile('$fileName.png', region: region, maxDiffRate: 0.03);
await matchGoldenFile('$fileName.png', region: region, maxDiffRatePercent: 0.0);
} finally {
// The page is reused across tests, so remove the element after taking the
// Scuba screenshot.
Expand Down
Expand Up @@ -28,7 +28,7 @@ void main() async {
try {
sceneElement.append(engineCanvas.rootElement);
html.document.body.append(sceneElement);
await matchGoldenFile('$fileName.png', region: region, maxDiffRate: 0.2);
await matchGoldenFile('$fileName.png', region: region, maxDiffRatePercent: 0.0);
} finally {
// The page is reused across tests, so remove the element after taking the
// Scuba screenshot.
Expand Down
Expand Up @@ -31,7 +31,7 @@ void main() async {
try {
sceneElement.append(engineCanvas.rootElement);
html.document.body.append(sceneElement);
await matchGoldenFile('$fileName.png', region: region, maxDiffRate: 0.2);
await matchGoldenFile('$fileName.png', region: region, maxDiffRatePercent: 0.0);
} finally {
// The page is reused across tests, so remove the element after taking the
// Scuba screenshot.
Expand Down
Expand Up @@ -166,7 +166,7 @@ void main() async {
await matchGoldenFile(
'bitmap_canvas_draws_high_quality_text.png',
region: canvasSize,
maxDiffRate: 0.0,
maxDiffRatePercent: 0.0,
pixelComparison: PixelComparison.precise,
);
}, timeout: const Timeout(Duration(seconds: 10)), testOn: 'chrome');
Expand Down
Expand Up @@ -592,7 +592,7 @@ void _testCullRectComputation() {
await matchGoldenFile(
'compositing_draw_high_quality_text.png',
region: canvasSize,
maxDiffRate: 0.0,
maxDiffRatePercent: 0.0,
pixelComparison: PixelComparison.precise,
);
},
Expand Down
Expand Up @@ -28,9 +28,12 @@ void main() async {
try {
sceneElement.append(engineCanvas.rootElement);
html.document.body.append(sceneElement);
// Set rate to 0.66% for webGL difference across platforms.
await matchGoldenFile('$fileName.png', region: region, write: write,
maxDiffRate: 1.5 / 100.0);
await matchGoldenFile(
'$fileName.png',
region: region,
write: write,
maxDiffRatePercent: 0.0,
);
} finally {
// The page is reused across tests, so remove the element after taking the
// golden screenshot.
Expand Down
8 changes: 4 additions & 4 deletions lib/web_ui/test/golden_tests/engine/scuba.dart
Expand Up @@ -45,12 +45,12 @@ class EngineScubaTester {
Future<void> diffScreenshot(
String fileName, {
ui.Rect region,
double maxDiffRate,
double maxDiffRatePercent,
}) async {
await matchGoldenFile(
'$fileName.png',
region: region ?? viewportRegion,
maxDiffRate: maxDiffRate,
maxDiffRatePercent: maxDiffRatePercent,
);
}

Expand All @@ -62,7 +62,7 @@ class EngineScubaTester {
EngineCanvas canvas,
String fileName, {
ui.Rect region,
double maxDiffRate,
double maxDiffRatePercent,
}) async {
// Wrap in <flt-scene> so that our CSS selectors kick in.
final html.Element sceneElement = html.Element.tag('flt-scene');
Expand All @@ -76,7 +76,7 @@ class EngineScubaTester {
await diffScreenshot(
screenshotName,
region: region,
maxDiffRate: maxDiffRate,
maxDiffRatePercent: maxDiffRatePercent,
);
} finally {
// The page is reused across tests, so remove the element after taking the
Expand Down
Expand Up @@ -219,7 +219,7 @@ void main() async {

testEachCanvas('draws text with a shadow', (EngineCanvas canvas) {
drawTextWithShadow(canvas);
return scuba.diffCanvasScreenshot(canvas, 'text_shadow', maxDiffRate: 0.2);
return scuba.diffCanvasScreenshot(canvas, 'text_shadow', maxDiffRatePercent: 0.2);
}, bSkipHoudini: true);

testEachCanvas('Handles disabled strut style', (EngineCanvas canvas) {
Expand All @@ -238,7 +238,7 @@ void main() async {
canvas,
'text_strut_style_disabled',
region: Rect.fromLTRB(0, 0, 100, 100),
maxDiffRate: 0.9 / 100, // 0.9%
maxDiffRatePercent: 0.0,
);
});
}
19 changes: 14 additions & 5 deletions web_sdk/web_engine_tester/lib/golden_tester.dart
Expand Up @@ -6,6 +6,7 @@ import 'dart:async';
import 'dart:convert';
import 'dart:html' as html;

import 'package:ui/src/engine.dart';
import 'package:ui/ui.dart';

import 'package:test/test.dart';
Expand Down Expand Up @@ -49,24 +50,32 @@ enum PixelComparison {
/// [pixelComparison] determines the algorithm used to compare pixels. Uses
/// fuzzy comparison by default.
Future<void> matchGoldenFile(String filename,
{bool write = false, Rect region = null, double maxDiffRate = null, PixelComparison pixelComparison = PixelComparison.fuzzy}) async {
{bool write = false, Rect region = null, double maxDiffRatePercent = null, PixelComparison pixelComparison = PixelComparison.fuzzy}) async {
Map<String, dynamic> serverParams = <String, dynamic>{
'filename': filename,
'write': write,
'region': region == null
? null
: {
: <String, dynamic>{
'x': region.left,
'y': region.top,
'width': region.width,
'height': region.height
},
'pixelComparison': pixelComparison.toString(),
};
if (maxDiffRate != null) {
serverParams['maxdiffrate'] = maxDiffRate;

// Chrome on macOS renders slighly differently from Linux, so allow it an
// extra 1% to deviate from the golden files.
if (maxDiffRatePercent != null) {
if (operatingSystem == OperatingSystem.macOs) {
maxDiffRatePercent += 1.0;
}
serverParams['maxdiffrate'] = maxDiffRatePercent / 100;
} else if (operatingSystem == OperatingSystem.macOs) {
serverParams['maxdiffrate'] = 0.01;
}
final String response = await _callScreenshotServer(serverParams);
final String response = await _callScreenshotServer(serverParams) as String;
if (response == 'OK') {
// Pass
return;
Expand Down
2 changes: 2 additions & 0 deletions web_sdk/web_engine_tester/pubspec.yaml
Expand Up @@ -8,3 +8,5 @@ dependencies:
stream_channel: 2.0.0
test: 1.6.5
webkit_inspection_protocol: 0.5.0
ui:
path: ../../lib/web_ui

0 comments on commit f34bc65

Please sign in to comment.