This repository was archived by the owner on Feb 25, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 6k
iOS platform view mutation XCUITests #11652
Merged
cyanglaz
merged 11 commits into
flutter:master
from
cyanglaz:ios_platform_view_mutation_uitest
Sep 15, 2019
Merged
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
7418e7e
wait for platform view appear
4d13348
add uitest for all the available mutations
4edf7cd
remove uncessary code
df45e14
remove unnecssary golden
97f736a
formatting
5be3a9e
review fixes
a2dafee
formatting
4ed4a6c
review fixes(dart)
285ffc2
review fixes
b4dbcc0
review fixes
f8c2a8e
merge master
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
23 changes: 23 additions & 0 deletions
23
.../scenario_app/android/app/src/main/java/io/flutter/plugins/GeneratedPluginRegistrant.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,23 @@ | ||
| package io.flutter.plugins; | ||
|
|
||
| import io.flutter.plugin.common.PluginRegistry; | ||
|
|
||
| /** | ||
| * Generated file. Do not edit. | ||
| */ | ||
| public final class GeneratedPluginRegistrant { | ||
| public static void registerWith(PluginRegistry registry) { | ||
| if (alreadyRegisteredWith(registry)) { | ||
| return; | ||
| } | ||
| } | ||
|
|
||
| private static boolean alreadyRegisteredWith(PluginRegistry registry) { | ||
| final String key = GeneratedPluginRegistrant.class.getCanonicalName(); | ||
| if (registry.hasPlugin(key)) { | ||
| return true; | ||
| } | ||
| registry.registrarFor(key); | ||
| return false; | ||
| } | ||
| } |
14 changes: 14 additions & 0 deletions
14
testing/scenario_app/ios/Runner/GeneratedPluginRegistrant.h
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| // | ||
| // Generated file. Do not edit. | ||
| // | ||
|
|
||
| #ifndef GeneratedPluginRegistrant_h | ||
| #define GeneratedPluginRegistrant_h | ||
|
|
||
| #import <Flutter/Flutter.h> | ||
|
|
||
| @interface GeneratedPluginRegistrant : NSObject | ||
| + (void)registerWithRegistry:(NSObject<FlutterPluginRegistry>*)registry; | ||
| @end | ||
|
|
||
| #endif /* GeneratedPluginRegistrant_h */ |
12 changes: 12 additions & 0 deletions
12
testing/scenario_app/ios/Runner/GeneratedPluginRegistrant.m
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| // | ||
| // Generated file. Do not edit. | ||
| // | ||
|
|
||
| #import "GeneratedPluginRegistrant.h" | ||
|
|
||
| @implementation GeneratedPluginRegistrant | ||
|
|
||
| + (void)registerWithRegistry:(NSObject<FlutterPluginRegistry>*)registry { | ||
| } | ||
|
|
||
| @end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
26 changes: 26 additions & 0 deletions
26
testing/scenario_app/ios/Scenarios/ScenariosUITests/GoldenImage.h
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,26 @@ | ||
| // 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. | ||
|
|
||
| #import <UIKit/UIKit.h> | ||
|
|
||
| NS_ASSUME_NONNULL_BEGIN | ||
|
|
||
| @interface GoldenImage : NSObject | ||
|
|
||
| @property(readonly, copy, nonatomic) NSString* goldenName; | ||
| @property(readonly, strong, nonatomic) UIImage* image; | ||
|
|
||
| // Initilize with the golden file's prefix. | ||
| // | ||
| // Create an image from a golden file named prefix+devicemodel. | ||
| - (instancetype)initWithGoldenNamePrefix:(NSString*)prefix; | ||
|
|
||
| // Compare this GoldenImage to `image`. | ||
| // | ||
| // Return YES if the `image` of this GoldenImage have the same pixels of provided `image`. | ||
| - (BOOL)compareGoldenToImage:(UIImage*)image; | ||
|
|
||
| @end | ||
|
|
||
| NS_ASSUME_NONNULL_END |
94 changes: 94 additions & 0 deletions
94
testing/scenario_app/ios/Scenarios/ScenariosUITests/GoldenImage.m
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,94 @@ | ||
| // 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. | ||
|
|
||
| #import "GoldenImage.h" | ||
| #import <XCTest/XCTest.h> | ||
| #include <sys/sysctl.h> | ||
|
|
||
| @interface GoldenImage () | ||
|
|
||
| @end | ||
|
|
||
| @implementation GoldenImage | ||
|
|
||
| - (instancetype)initWithGoldenNamePrefix:(NSString*)prefix { | ||
| self = [super init]; | ||
| if (self) { | ||
| _goldenName = [prefix stringByAppendingString:_platformName()]; | ||
| NSBundle* bundle = [NSBundle bundleForClass:[self class]]; | ||
| NSURL* goldenURL = [bundle URLForResource:_goldenName withExtension:@"png"]; | ||
| NSData* data = [NSData dataWithContentsOfURL:goldenURL]; | ||
| _image = [[UIImage alloc] initWithData:data]; | ||
| } | ||
| return self; | ||
| } | ||
|
|
||
| - (BOOL)compareGoldenToImage:(UIImage*)image { | ||
| if (!self.image || !image) { | ||
| return NO; | ||
| } | ||
| CGImageRef imageRefA = [self.image CGImage]; | ||
| CGImageRef imageRefB = [image CGImage]; | ||
|
|
||
| NSUInteger widthA = CGImageGetWidth(imageRefA); | ||
| NSUInteger heightA = CGImageGetHeight(imageRefA); | ||
| NSUInteger widthB = CGImageGetWidth(imageRefB); | ||
| NSUInteger heightB = CGImageGetHeight(imageRefB); | ||
|
|
||
| if (widthA != widthB || heightA != heightB) { | ||
| return NO; | ||
| } | ||
| NSUInteger bytesPerPixel = 4; | ||
| NSUInteger size = widthA * heightA * bytesPerPixel; | ||
| NSMutableData* rawA = [NSMutableData dataWithLength:size]; | ||
| NSMutableData* rawB = [NSMutableData dataWithLength:size]; | ||
|
|
||
| if (!rawA || !rawB) { | ||
| return NO; | ||
| } | ||
|
|
||
| CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB(); | ||
|
|
||
| NSUInteger bytesPerRow = bytesPerPixel * widthA; | ||
| NSUInteger bitsPerComponent = 8; | ||
| CGContextRef contextA = | ||
| CGBitmapContextCreate(rawA.mutableBytes, widthA, heightA, bitsPerComponent, bytesPerRow, | ||
| colorSpace, kCGImageAlphaPremultipliedLast | kCGBitmapByteOrder32Big); | ||
|
|
||
| CGContextDrawImage(contextA, CGRectMake(0, 0, widthA, heightA), imageRefA); | ||
| CGContextRelease(contextA); | ||
|
|
||
| CGContextRef contextB = | ||
| CGBitmapContextCreate(rawB.mutableBytes, widthA, heightA, bitsPerComponent, bytesPerRow, | ||
| colorSpace, kCGImageAlphaPremultipliedLast | kCGBitmapByteOrder32Big); | ||
| CGColorSpaceRelease(colorSpace); | ||
|
|
||
| CGContextDrawImage(contextB, CGRectMake(0, 0, widthA, heightA), imageRefB); | ||
| CGContextRelease(contextB); | ||
|
|
||
| if (memcmp(rawA.mutableBytes, rawB.mutableBytes, size)) { | ||
| return NO; | ||
| } | ||
|
|
||
| return YES; | ||
| } | ||
|
|
||
| NS_INLINE NSString* _platformName() { | ||
| NSString* simulatorName = | ||
| [[NSProcessInfo processInfo].environment objectForKey:@"SIMULATOR_DEVICE_NAME"]; | ||
| if (simulatorName) { | ||
| return [NSString stringWithFormat:@"%@_simulator", simulatorName]; | ||
| } | ||
|
|
||
| size_t size; | ||
| sysctlbyname("hw.model", NULL, &size, NULL, 0); | ||
| char* answer = malloc(size); | ||
| sysctlbyname("hw.model", answer, &size, NULL, 0); | ||
|
|
||
| NSString* results = [NSString stringWithCString:answer encoding:NSUTF8StringEncoding]; | ||
| free(answer); | ||
| return results; | ||
| } | ||
|
|
||
| @end | ||
30 changes: 30 additions & 0 deletions
30
testing/scenario_app/ios/Scenarios/ScenariosUITests/GoldenPlatformViewTests.h
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,30 @@ | ||
| // 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. | ||
|
|
||
| #import <XCTest/XCTest.h> | ||
| #import "PlatformViewGoldenTestManager.h" | ||
|
|
||
| NS_ASSUME_NONNULL_BEGIN | ||
|
|
||
| // The base class of all the PlatformView golden tests. | ||
| // | ||
| // A new PlatformView golden tests can subclass this and override the `-initiWithInvocation:` | ||
| // method, which then retun the `-initWithManager:invocation:` | ||
| // | ||
| // Then in any test method, call `checkGolden` to perform the golden test. | ||
| // | ||
| // This base class doesn't run any test case on its own. | ||
| @interface GoldenPlatformViewTests : XCTestCase | ||
|
|
||
| // Initialize with a `PlatformViewGoldenTestManager`. | ||
| - (instancetype)initWithManager:(PlatformViewGoldenTestManager*)manager | ||
| invocation:(NSInvocation*)invocation; | ||
|
|
||
| // Take a sceenshot of the test app and check it has the same pixels with goldenImage inside the | ||
| // `PlatformViewGoldenTestManager`. | ||
| - (void)checkGolden; | ||
|
|
||
| @end | ||
|
|
||
| NS_ASSUME_NONNULL_END |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Override
-isEqual: and-hashinstead.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh actually never mind, that would require you to make a GoldenImage out of the screen shot. This is fine.