Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

Commit d877b83

Browse files
author
nturgut
authored
[web] enable ios safari screenshot tests (#21226)
* enable ios safari screenshot tests * this is the value used for screenshots in the repo. * change revision * fix the error made in the gaps * do not try to fetch on LUCI * lunix luci migth break existing prs. only skip fetching for mac * add a placeholder tests for shadow golden test * try to use iPhone 11 Pro on LUCI * change the scale and the smoke test image * add unmerged goldens PR to tests all the screenshots. will be removed later * change the goldens lock back to flutter/goldens * change wrong comment on screenshot tests block * address reviewer comments * change the commit number for goldens file * skip canvas blend mode tests * debugging LUCI error * debugging LUCI error printing directory contents * skip one test, remove the debug logs * change the revision number to include the correct chrome files
1 parent fed0531 commit d877b83

File tree

8 files changed

+46
-12
lines changed

8 files changed

+46
-12
lines changed

lib/web_ui/dev/browser_lock.yaml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ ios-safari:
3434
# `heightOfHeader` is the number of pixels taken by the phone's header menu
3535
# and the browsers address bar.
3636
# TODO: https://github.com/flutter/flutter/issues/65672
37-
heightOfHeader: 282
37+
heightOfHeader: 189
3838
# `heightOfFooter` is the number of pixels taken by the phone's navigation
3939
# menu.
4040
heightOfFooter: 250
@@ -45,7 +45,8 @@ ios-safari:
4545
# phone screeen we enlarge or shrink the area by applying a linear
4646
# transformation by a scale_factor (a.k.a. we perform isotropic scaling).
4747
# This value will be differ depending on the phone.
48-
scaleFactor: 1.15
48+
# For iOS 13.0 iPhone 11 Pro, this number is 1.15.
49+
scaleFactor: 1.00
4950

5051
## geckodriver is used for testing Firefox Browser. It works with multiple
5152
## Firefox Browser versions.

lib/web_ui/dev/goldens_lock.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
repository: https://github.com/flutter/goldens.git
2-
revision: b6efc75885c23f0b5c485d8bd659ed339feec9ec
2+
revision: 1a4722227af42c3f51450266016b1a07ae459e73

lib/web_ui/dev/test_platform.dart

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,17 @@ class BrowserPlatform extends PlatformPlugin {
197197
'golden_files',
198198
);
199199
} else {
200-
await fetchGoldens();
200+
// On LUCI MacOS bots the goldens are fetched by the recipe code.
201+
// Fetch the goldens if:
202+
// - Tests are running on a local machine.
203+
// - Tests are running on an OS other than macOS.
204+
if (!isLuci || !Platform.isMacOS) {
205+
await fetchGoldens();
206+
} else {
207+
if (!env.environment.webUiGoldensRepositoryDirectory.existsSync()) {
208+
throw Exception('The goldens directory must have been copied');
209+
}
210+
}
201211
goldensDirectory = p.join(
202212
env.environment.webUiGoldensRepositoryDirectory.path,
203213
'engine',
@@ -212,7 +222,7 @@ class BrowserPlatform extends PlatformPlugin {
212222
));
213223
if (!file.existsSync() && !write) {
214224
return '''
215-
Golden file $filename does not exist.
225+
Golden file $filename does not exist on path ${file.absolute.path}
216226
217227
To automatically create this file call matchGoldenFile('$filename', write: true).
218228
''';

lib/web_ui/dev/test_runner.dart

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -397,12 +397,13 @@ class TestCommand extends Command<bool> with ArgUtils {
397397
'test',
398398
));
399399

400-
// Screenshot tests and smoke tests only run on: "Chrome/iOS Safari locally"
401-
// or "Chrome on a Linux bot". We can remove the Linux bot restriction
402-
// after solving the git issue faced on macOS and Windows bots:
400+
// Screenshot tests and smoke tests only run on: "Chrome/iOS Safari"
401+
// locally and on LUCI. They are not available on Windows bots:
403402
// TODO: https://github.com/flutter/flutter/issues/63710
404403
if ((isChrome && isLuci && io.Platform.isLinux) ||
405-
((isChrome || isSafariIOS) && !isLuci)) {
404+
((isChrome || isSafariIOS) && !isLuci) ||
405+
(isSafariIOS && isLuci)) {
406+
print('INFO: Also running the screenshot tests.');
406407
// Separate screenshot tests from unit-tests. Screenshot tests must run
407408
// one at a time. Otherwise, they will end up screenshotting each other.
408409
// This is not an issue for unit-tests.
-678 Bytes
Loading

lib/web_ui/test/golden_tests/engine/canvas_image_blend_mode_test.dart

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,9 @@ void testMain() async {
108108
rc.restore();
109109
await _checkScreenshot(rc, 'canvas_image_blend_group$blendGroup',
110110
maxDiffRatePercent: 8.0);
111-
});
111+
},
112+
skip: browserEngine == BrowserEngine.webkit &&
113+
operatingSystem == OperatingSystem.iOs);
112114
}
113115

114116
// Regression test for https://github.com/flutter/flutter/issues/56971

lib/web_ui/test/golden_tests/engine/shadow_golden_test.dart

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,8 @@ void testMain() async {
7575
builder.pop(); // offset
7676
}
7777

78-
void _paintBitmapCanvasShadow(double elevation, Offset offset, bool transparentOccluder) {
78+
void _paintBitmapCanvasShadow(
79+
double elevation, Offset offset, bool transparentOccluder) {
7980
final SurfacePath path = SurfacePath()
8081
..addRect(const Rect.fromLTRB(0, 0, 20, 20));
8182
builder.pushOffset(offset.dx, offset.dy);
@@ -168,4 +169,15 @@ void testMain() async {
168169
},
169170
testOn: 'chrome',
170171
);
172+
173+
/// For dart testing having `no tests ran` in a file is considered an error
174+
/// and result in exit code 1.
175+
/// See: https://github.com/dart-lang/test/pull/1173
176+
///
177+
/// Since screenshot tests run one by one and exit code is checked immediately
178+
/// after that a test file that only runs in chrome will break the other
179+
/// browsers. This method is added as a bandaid solution.
180+
test('dummy tests to pass on other browsers', () async {
181+
expect(2 + 2, 4);
182+
});
171183
}

lib/web_ui/test/golden_tests/engine/text_placeholders_test.dart

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,17 @@ void main() {
1515
internalBootstrapBrowserTest(() => testMain);
1616
}
1717

18+
/// Whether we are running on iOS Safari.
19+
// TODO: https://github.com/flutter/flutter/issues/66656
20+
bool get isIosSafari => browserEngine == BrowserEngine.webkit &&
21+
operatingSystem == OperatingSystem.iOs;
22+
1823
void testMain() async {
1924
final EngineScubaTester scuba = await EngineScubaTester.initialize(
2025
viewportSize: const Size(600, 600),
2126
);
2227

28+
2329
setUpStableTestFonts();
2430

2531
testEachCanvas('draws paragraphs with placeholders', (EngineCanvas canvas) {
@@ -40,7 +46,9 @@ void testMain() async {
4046
}
4147
recordingCanvas.endRecording();
4248
recordingCanvas.apply(canvas, screenRect);
43-
return scuba.diffCanvasScreenshot(canvas, 'text_with_placeholders');
49+
if (!isIosSafari) {
50+
return scuba.diffCanvasScreenshot(canvas, 'text_with_placeholders');
51+
}
4452
});
4553

4654
testEachCanvas('text alignment and placeholders', (EngineCanvas canvas) {

0 commit comments

Comments
 (0)