Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ - (void)testFontRenderingWhenSuppliedWithBogusFont {
XCTAssertTrue([addTextField waitForExistenceWithTimeout:30]);

GoldenTestManager* manager = [[GoldenTestManager alloc] initWithLaunchArg:@"--bogus-font-text"];
[manager checkGoldenForTest:self];
[manager checkGoldenForTest:self rmesThreshold:kDefaultRmseThreshold];
}

@end
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ NS_ASSUME_NONNULL_BEGIN
// Compare this GoldenImage to `image`.
//
// Return YES if the `image` of this GoldenImage have the same pixels of provided `image`.
- (BOOL)compareGoldenToImage:(UIImage*)image;
- (BOOL)compareGoldenToImage:(UIImage*)image rmesThreshold:(double)rmesThreshold;

@end

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@
#import <os/log.h>
#include <sys/sysctl.h>

static const double kRmseThreshold = 0.5;

@interface GoldenImage ()

@end
Expand All @@ -28,7 +26,7 @@ - (instancetype)initWithGoldenNamePrefix:(NSString*)prefix {
return self;
}

- (BOOL)compareGoldenToImage:(UIImage*)image {
- (BOOL)compareGoldenToImage:(UIImage*)image rmesThreshold:(double)rmesThreshold {
if (!self.image || !image) {
os_log_error(OS_LOG_DEFAULT, "GOLDEN DIFF FAILED: image does not exists.");
return NO;
Expand Down Expand Up @@ -91,11 +89,11 @@ - (BOOL)compareGoldenToImage:(UIImage*)image {
}
}
double rmse = sqrt(sum / size);
if (rmse > kRmseThreshold) {
if (rmse > rmesThreshold) {
os_log_error(
OS_LOG_DEFAULT,
"GOLDEN DIFF FAILED: image diff greater than threshold. Current diff: %@, threshold: %@",
@(rmse), @(kRmseThreshold));
@(rmse), @(rmesThreshold));
return NO;
}
return YES;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ NS_ASSUME_NONNULL_BEGIN
@interface GoldenPlatformViewTests : XCTestCase

@property(nonatomic, strong) XCUIApplication* application;
@property(nonatomic, assign) double rmseThreadhold;

// Initialize with a `GoldenTestManager`.
- (instancetype)initWithManager:(GoldenTestManager*)manager invocation:(NSInvocation*)invocation;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ @implementation GoldenPlatformViewTests
- (instancetype)initWithManager:(GoldenTestManager*)manager invocation:(NSInvocation*)invocation {
self = [super initWithInvocation:invocation];
_manager = manager;
_rmseThreadhold = kDefaultRmseThreshold;
return self;
}

Expand All @@ -45,6 +46,6 @@ - (void)checkPlatformViewGolden {
@(kSecondsToWaitForPlatformView));
}

[self.manager checkGoldenForTest:self];
[self.manager checkGoldenForTest:self rmesThreshold:self.rmseThreadhold];
}
@end
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
NS_ASSUME_NONNULL_BEGIN

extern NSDictionary* launchArgsMap;
const extern double kDefaultRmseThreshold;

// Manages a `GoldenPlatformViewTests`.
//
Expand All @@ -27,7 +28,7 @@ extern NSDictionary* launchArgsMap;

// Take a sceenshot of the test app and check it has the same pixels with
// goldenImage inside the `GoldenTestManager`.
- (void)checkGoldenForTest:(XCTestCase*)test;
- (void)checkGoldenForTest:(XCTestCase*)test rmesThreshold:(double)rmesThreshold;

@end

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ @interface GoldenTestManager ()
@implementation GoldenTestManager

NSDictionary* launchArgsMap;
const double kDefaultRmseThreshold = 0.5;

- (instancetype)initWithLaunchArg:(NSString*)launchArg {
self = [super init];
Expand Down Expand Up @@ -73,7 +74,7 @@ - (instancetype)initWithLaunchArg:(NSString*)launchArg {
return self;
}

- (void)checkGoldenForTest:(XCTestCase*)test {
- (void)checkGoldenForTest:(XCTestCase*)test rmesThreshold:(double)rmesThreshold {
XCUIScreenshot* screenshot = [[XCUIScreen mainScreen] screenshot];
if (!_goldenImage.image) {
XCTAttachment* attachment = [XCTAttachment attachmentWithScreenshot:screenshot];
Expand All @@ -88,7 +89,7 @@ - (void)checkGoldenForTest:(XCTestCase*)test {
_goldenImage.goldenName);
}

if (![_goldenImage compareGoldenToImage:screenshot.image]) {
if (![_goldenImage compareGoldenToImage:screenshot.image rmesThreshold:rmesThreshold]) {
XCTAttachment* screenshotAttachment = [XCTAttachment attachmentWithImage:screenshot.image];
screenshotAttachment.name = [_goldenImage.goldenName stringByAppendingString:@"_actual.png"];
screenshotAttachment.lifetime = XCTAttachmentLifetimeKeepAlways;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -375,6 +375,11 @@ - (instancetype)initWithInvocation:(NSInvocation*)invocation {
}

- (void)testPlatformView {
// (TODO)cyanglaz: remove the threshold adjustment after all the ci migrates to macOS13.
// https://github.com/flutter/flutter/issues/133207
if ([NSProcessInfo processInfo].operatingSystemVersion.majorVersion >= 13) {
self.rmseThreadhold = 0.7;
}
[self checkPlatformViewGolden];
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ - (void)testSpawnEngineWorks {

GoldenTestManager* manager =
[[GoldenTestManager alloc] initWithLaunchArg:@"--spawn-engine-works"];
[manager checkGoldenForTest:self];
[manager checkGoldenForTest:self rmesThreshold:kDefaultRmseThreshold];
}

@end