Skip to content

Commit d810bad

Browse files
authored
Remove WebGoldenComparator, which is no longer used by the tool. (flutter#169898)
I could see the argument in keeping this around longer for API compatibility, but we no longer use it, it's no longer tested, and only really existed for the HTML-backend, which was removed, so I'm saying remove it. Closes flutter#160261.
1 parent d20f8b0 commit d810bad

File tree

3 files changed

+0
-281
lines changed

3 files changed

+0
-281
lines changed

packages/flutter_test/lib/src/_goldens_io.dart

Lines changed: 0 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -285,42 +285,6 @@ ByteData _invert(ByteData imageBytes) {
285285
return bytes;
286286
}
287287

288-
/// An unsupported [WebGoldenComparator] that exists for API compatibility.
289-
@Deprecated(
290-
'Use GoldenFileComparator instead. '
291-
'This feature was deprecated after v3.28.0-0.1.pre.',
292-
)
293-
class DefaultWebGoldenComparator extends WebGoldenComparator {
294-
/// This is provided to prevent warnings from the analyzer.
295-
@Deprecated(
296-
'Use a GoldenFileComparator implementation instead. '
297-
'This feature was deprecated after v3.28.0-0.1.pre.',
298-
)
299-
DefaultWebGoldenComparator(Uri _) {
300-
throw UnsupportedError('DefaultWebGoldenComparator is only supported on the web.');
301-
}
302-
303-
@override
304-
Future<bool> compare(double width, double height, Uri golden) {
305-
throw UnsupportedError('DefaultWebGoldenComparator is only supported on the web.');
306-
}
307-
308-
@override
309-
Future<void> update(double width, double height, Uri golden) {
310-
throw UnsupportedError('DefaultWebGoldenComparator is only supported on the web.');
311-
}
312-
313-
@override
314-
Future<bool> compareBytes(Uint8List bytes, Uri golden) {
315-
throw UnsupportedError('DefaultWebGoldenComparator is only supported on the web.');
316-
}
317-
318-
@override
319-
Future<void> updateBytes(Uint8List bytes, Uri golden) {
320-
throw UnsupportedError('DefaultWebGoldenComparator is only supported on the web.');
321-
}
322-
}
323-
324288
/// Reads the red value out of a 32 bit rgba pixel.
325289
int _readRed(int pixel) => (pixel >> 24) & 0xff;
326290

packages/flutter_test/lib/src/_goldens_web.dart

Lines changed: 0 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -76,74 +76,3 @@ final class HttpProxyGoldenComparator extends GoldenFileComparator {
7676
await compare(bytes, golden);
7777
}
7878
}
79-
80-
/// The default [WebGoldenComparator] implementation for `flutter test`.
81-
///
82-
/// This comparator will send a request to the test server for golden comparison
83-
/// which will then defer the comparison to [goldenFileComparator].
84-
///
85-
/// See also:
86-
///
87-
/// * [matchesGoldenFile], the function that invokes the comparator.
88-
@Deprecated(
89-
'Use goldenFileComparator instead. '
90-
'This feature was deprecated after v3.28.0-0.1.pre.',
91-
)
92-
class DefaultWebGoldenComparator extends WebGoldenComparator {
93-
/// Creates a new [DefaultWebGoldenComparator] for the specified [testUri].
94-
///
95-
/// Golden file keys will be interpreted as file paths relative to the
96-
/// directory in which [testUri] resides.
97-
///
98-
/// The [testUri] must represent a file.
99-
@Deprecated(
100-
'Use an implementation of GoldenFileComparator instead. '
101-
'This feature was deprecated after v3.28.0-0.1.pre.',
102-
)
103-
DefaultWebGoldenComparator(Uri testUri) : _comparatorImpl = HttpProxyGoldenComparator(testUri);
104-
105-
// TODO(matanlurey): Refactor as part of https://github.com/flutter/flutter/issues/160261.
106-
final HttpProxyGoldenComparator _comparatorImpl;
107-
108-
@override
109-
Future<bool> compare(double width, double height, Uri golden) async {
110-
final String key = golden.toString();
111-
final web.Response response =
112-
await web.window
113-
.fetch(
114-
'flutter_goldens'.toJS,
115-
web.RequestInit(
116-
method: 'POST',
117-
body:
118-
json.encode(<String, Object>{
119-
'testUri': _comparatorImpl._testUri.toString(),
120-
'key': key,
121-
'width': width.round(),
122-
'height': height.round(),
123-
}).toJS,
124-
),
125-
)
126-
.toDart;
127-
final String responseText = (await response.text().toDart).toDart;
128-
if (responseText == 'true') {
129-
return true;
130-
}
131-
fail(responseText);
132-
}
133-
134-
@override
135-
Future<void> update(double width, double height, Uri golden) async {
136-
// Update is handled on the server side, just use the same logic here
137-
await compare(width, height, golden);
138-
}
139-
140-
@override
141-
Future<bool> compareBytes(Uint8List bytes, Uri golden) async {
142-
return _comparatorImpl.compare(bytes, golden);
143-
}
144-
145-
@override
146-
Future<void> updateBytes(Uint8List bytes, Uri golden) async {
147-
await _comparatorImpl.update(golden, bytes);
148-
}
149-
}

packages/flutter_test/lib/src/goldens.dart

Lines changed: 0 additions & 174 deletions
Original file line numberDiff line numberDiff line change
@@ -195,142 +195,6 @@ abstract class GoldenFileComparator {
195195
/// directory-level.
196196
GoldenFileComparator goldenFileComparator = const TrivialComparator._();
197197

198-
/// Compares image pixels against a golden image file.
199-
///
200-
/// Instances of this comparator will be used as the backend for
201-
/// [matchesGoldenFile] when tests are running on Flutter Web, and will usually
202-
/// implemented by deferring the screenshot taking and image comparison to a
203-
/// test server.
204-
///
205-
/// Instances of this comparator will be invoked by the test framework in the
206-
/// [TestWidgetsFlutterBinding.runAsync] zone and are thus not subject to the
207-
/// fake async constraints that are normally imposed on widget tests (i.e. the
208-
/// need or the ability to call [WidgetTester.pump] to advance the microtask
209-
/// queue). Prior to the invocation, the test framework will render only the
210-
/// [Element] to be compared on the screen.
211-
///
212-
/// See also:
213-
///
214-
/// * [GoldenFileComparator] for the comparator to be used when the test is
215-
/// not running in a web browser.
216-
/// * [DefaultWebGoldenComparator] for the default [WebGoldenComparator]
217-
/// implementation for `flutter test`.
218-
/// * [matchesGoldenFile], the function that invokes the comparator.
219-
@Deprecated(
220-
'Use GoldenFileComparator instead. '
221-
'This feature was deprecated after v3.28.0-0.1.pre.',
222-
)
223-
abstract class WebGoldenComparator {
224-
/// Compares the rendered pixels of size [width]x[height] that is being
225-
/// rendered on the top left of the screen against the golden file identified
226-
/// by [golden].
227-
///
228-
/// The returned future completes with a boolean value that indicates whether
229-
/// the pixels rendered on screen match the golden file's pixels.
230-
///
231-
/// In the case of comparison mismatch, the comparator may choose to throw a
232-
/// [TestFailure] if it wants to control the failure message, often in the
233-
/// form of a [ComparisonResult] that provides detailed information about the
234-
/// mismatch.
235-
///
236-
/// The method by which [golden] is located and by which its bytes are loaded
237-
/// is left up to the implementation class. For instance, some implementations
238-
/// may load files from the local file system, whereas others may load files
239-
/// over the network or from a remote repository.
240-
Future<bool> compare(double width, double height, Uri golden);
241-
242-
/// Updates the golden file identified by [golden] with rendered pixels of
243-
/// [width]x[height].
244-
///
245-
/// This will be invoked in lieu of [compare] when [autoUpdateGoldenFiles]
246-
/// is `true` (which gets set automatically by the test framework when the
247-
/// user runs `flutter test --update-goldens --platform=chrome`).
248-
///
249-
/// The method by which [golden] is located and by which its bytes are written
250-
/// is left up to the implementation class.
251-
Future<void> update(double width, double height, Uri golden);
252-
253-
/// Compares the pixels of decoded png [bytes] against the golden file
254-
/// identified by [golden].
255-
///
256-
/// The returned future completes with a boolean value that indicates whether
257-
/// the pixels rendered on screen match the golden file's pixels.
258-
///
259-
/// In the case of comparison mismatch, the comparator may choose to throw a
260-
/// [TestFailure] if it wants to control the failure message, often in the
261-
/// form of a [ComparisonResult] that provides detailed information about the
262-
/// mismatch.
263-
///
264-
/// The method by which [golden] is located and by which its bytes are loaded
265-
/// is left up to the implementation class. For instance, some implementations
266-
/// may load files from the local file system, whereas others may load files
267-
/// over the network or from a remote repository.
268-
Future<bool> compareBytes(Uint8List bytes, Uri golden);
269-
270-
/// Compares the pixels of decoded png [bytes] against the golden file
271-
/// identified by [golden].
272-
///
273-
/// This will be invoked in lieu of [compareBytes] when [autoUpdateGoldenFiles]
274-
/// is `true` (which gets set automatically by the test framework when the
275-
/// user runs `flutter test --update-goldens --platform=chrome`).
276-
///
277-
/// The method by which [golden] is located and by which its bytes are written
278-
/// is left up to the implementation class.
279-
Future<void> updateBytes(Uint8List bytes, Uri golden);
280-
281-
/// Returns a new golden file [Uri] to incorporate any [version] number with
282-
/// the [key].
283-
///
284-
/// The [version] is an optional int that can be used to differentiate
285-
/// historical golden files.
286-
///
287-
/// Version numbers are used in golden file tests for package:flutter. You can
288-
/// learn more about these tests [here](https://github.com/flutter/flutter/blob/main/docs/contributing/testing/Writing-a-golden-file-test-for-package-flutter.md).
289-
Uri getTestUri(Uri key, int? version) {
290-
if (version == null) {
291-
return key;
292-
}
293-
final String keyString = key.toString();
294-
final String extension = path.extension(keyString);
295-
return Uri.parse('${keyString.split(extension).join()}.$version$extension');
296-
}
297-
}
298-
299-
/// Compares pixels against those of a golden image file.
300-
///
301-
/// This comparator is used as the backend for [matchesGoldenFile] when tests
302-
/// are running in a web browser.
303-
///
304-
/// When using `flutter test --platform=chrome`, a comparator implemented by
305-
/// [DefaultWebGoldenComparator] is used if no other comparator is specified. It
306-
/// will send a request to the test server, which uses [goldenFileComparator]
307-
/// for golden file comparison.
308-
///
309-
/// When using `flutter test --update-goldens`, the [DefaultWebGoldenComparator]
310-
/// updates the files on disk to match the rendering.
311-
///
312-
/// When using `flutter run`, the default comparator
313-
/// (`_TrivialWebGoldenComparator`) is used. It prints a message to the console
314-
/// but otherwise does nothing. This allows tests to be developed visually on a
315-
/// web browser.
316-
///
317-
/// Callers may choose to override the default comparator by setting this to a
318-
/// custom comparator during test set-up (or using directory-level test
319-
/// configuration). For example, some projects may wish to install a comparator
320-
/// with tolerance levels for allowable differences.
321-
///
322-
/// See also:
323-
///
324-
/// * [flutter_test] for more information about how to configure tests at the
325-
/// directory-level.
326-
/// * [goldenFileComparator], the comparator used when tests are not running on
327-
/// a web browser.
328-
WebGoldenComparator get webGoldenComparator => _webGoldenComparator;
329-
WebGoldenComparator _webGoldenComparator = const _TrivialWebGoldenComparator._();
330-
set webGoldenComparator(WebGoldenComparator value) {
331-
_webGoldenComparator = value;
332-
}
333-
334198
/// Whether golden files should be automatically updated during tests rather
335199
/// than compared to the image bytes recorded by the tests.
336200
///
@@ -386,44 +250,6 @@ class TrivialComparator implements GoldenFileComparator {
386250
}
387251
}
388252

389-
class _TrivialWebGoldenComparator implements WebGoldenComparator {
390-
const _TrivialWebGoldenComparator._();
391-
392-
@override
393-
Future<bool> compare(double width, double height, Uri golden) {
394-
return _warnAboutSkipping(golden);
395-
}
396-
397-
@override
398-
Future<void> update(double width, double height, Uri golden) {
399-
throw StateError('webGoldenComparator has not been initialized');
400-
}
401-
402-
@override
403-
Uri getTestUri(Uri key, int? version) {
404-
return key;
405-
}
406-
407-
@override
408-
Future<bool> compareBytes(Uint8List bytes, Uri golden) {
409-
return _warnAboutSkipping(golden);
410-
}
411-
412-
@override
413-
Future<void> updateBytes(Uint8List bytes, Uri golden) {
414-
throw StateError('webGoldenComparator has not been initialized');
415-
}
416-
417-
Future<bool> _warnAboutSkipping(Uri golden) {
418-
// Ideally we would use markTestSkipped here but in some situations,
419-
// comparators are called outside of tests.
420-
// See also: https://github.com/flutter/flutter/issues/91285
421-
// ignore: avoid_print
422-
print('Golden comparison requested for "$golden"; skipping...');
423-
return Future<bool>.value(true);
424-
}
425-
}
426-
427253
/// The result of a pixel comparison test.
428254
///
429255
/// The [ComparisonResult] will always indicate if a test has [passed]. The

0 commit comments

Comments
 (0)