From 93141ac0f0b7f6ce42d8ab68c7f70bb86689644d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Minh=20Nguye=CC=82=CC=83n?= Date: Thu, 30 Apr 2020 17:53:07 -0700 Subject: [PATCH] [ios, macos] Hard-code Null Island for runtime styling test MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Relying on the stylesheet to jump from an invalid camera to Null Island seems to introduce a race condition where the tiles don’t render by the time the snapshot takes place. --- platform/darwin/test/MGLMapSnapshotterTests.m | 24 ++++++++++++------- platform/darwin/test/one-liner.json | 2 +- 2 files changed, 16 insertions(+), 10 deletions(-) diff --git a/platform/darwin/test/MGLMapSnapshotterTests.m b/platform/darwin/test/MGLMapSnapshotterTests.m index 829694080..c885fd665 100644 --- a/platform/darwin/test/MGLMapSnapshotterTests.m +++ b/platform/darwin/test/MGLMapSnapshotterTests.m @@ -141,7 +141,7 @@ MGLImage *MGLImageFromCurrentContext() { } - (void)testRuntimeStyling { - [self testStyleURL:nil applyingRuntimeStylingActions:^(MGLStyle *style) { + [self testStyleURL:nil camera:[MGLMapCamera camera] applyingRuntimeStylingActions:^(MGLStyle *style) { MGLBackgroundStyleLayer *backgroundLayer = [[MGLBackgroundStyleLayer alloc] initWithIdentifier:@"background"]; backgroundLayer.backgroundColor = [NSExpression expressionForConstantValue:[MGLColor orangeColor]]; [style addLayer:backgroundLayer]; @@ -151,16 +151,17 @@ MGLImage *MGLImageFromCurrentContext() { - (void)testLocalGlyphRendering { [[NSUserDefaults standardUserDefaults] setObject:@[@"PingFang TC"] forKey:@"MGLIdeographicFontFamilyName"]; NSURL *styleURL = [[NSBundle bundleForClass:[self class]] URLForResource:@"mixed" withExtension:@"json"]; - [self testStyleURL:styleURL applyingRuntimeStylingActions:^(MGLStyle *style) {} expectedImageName:@"Fixtures/MGLMapSnapshotterTests/PingFang"]; + [self testStyleURL:styleURL camera:nil applyingRuntimeStylingActions:^(MGLStyle *style) {} expectedImageName:@"Fixtures/MGLMapSnapshotterTests/PingFang"]; } /** Tests that applying the given runtime styling actions on a blank style results in a snapshot image that matches the image with the given name in the asset catalog. @param actions Runtime styling actions to apply to the blank style. + @param camera The camera to show, or `nil` to show the style’s default camera. @param expectedImageName Name of the test fixture image in Media.xcassets. */ -- (void)testStyleURL:(nullable NSURL *)styleURL applyingRuntimeStylingActions:(void (^)(MGLStyle *style))actions expectedImageName:(NSString *)expectedImageName { +- (void)testStyleURL:(nullable NSURL *)styleURL camera:(nullable MGLMapCamera *)camera applyingRuntimeStylingActions:(void (^)(MGLStyle *style))actions expectedImageName:(NSString *)expectedImageName { self.styleLoadingExpectation = [self expectationWithDescription:@"Style should finish loading."]; XCTestExpectation *overlayExpectation = [self expectationWithDescription:@"Overlay handler should get called."]; XCTestExpectation *completionExpectation = [self expectationWithDescription:@"Completion handler should get called."]; @@ -175,12 +176,17 @@ MGLImage *MGLImageFromCurrentContext() { if (!styleURL) { styleURL = [[NSBundle bundleForClass:[self class]] URLForResource:@"one-liner" withExtension:@"json"]; } - MGLMapCamera *camera = [MGLMapCamera camera]; - camera.centerCoordinate = kCLLocationCoordinate2DInvalid; - camera.heading = -1; - camera.pitch = -1; - MGLMapSnapshotOptions *options = [[MGLMapSnapshotOptions alloc] initWithStyleURL:styleURL camera:camera size:expectedImage.size]; - options.zoomLevel = -1; + + MGLMapCamera *defaultCamera = camera ?: [MGLMapCamera camera]; + if (!camera) { + defaultCamera.centerCoordinate = kCLLocationCoordinate2DInvalid; + defaultCamera.heading = -1; + defaultCamera.pitch = -1; + } + MGLMapSnapshotOptions *options = [[MGLMapSnapshotOptions alloc] initWithStyleURL:styleURL camera:defaultCamera size:expectedImage.size]; + if (!camera) { + options.zoomLevel = -1; + } MGLMapSnapshotter *snapshotter = [[MGLMapSnapshotter alloc] initWithOptions:options]; snapshotter.delegate = self; diff --git a/platform/darwin/test/one-liner.json b/platform/darwin/test/one-liner.json index 7888811e9..398641258 100644 --- a/platform/darwin/test/one-liner.json +++ b/platform/darwin/test/one-liner.json @@ -1 +1 @@ -{"version":8,"sources":{},"layers":[],"center":[0,0],"zoom":0} +{"version":8,"sources":{},"layers":[]}