summaryrefslogtreecommitdiff
path: root/platform/ios/Integration Tests
diff options
context:
space:
mode:
Diffstat (limited to 'platform/ios/Integration Tests')
-rw-r--r--platform/ios/Integration Tests/Annotation Tests/MGLAnnotationViewIntegrationTests.m26
-rw-r--r--platform/ios/Integration Tests/MGLMapViewIntegrationTest.h1
-rw-r--r--platform/ios/Integration Tests/MGLMapViewIntegrationTest.m7
-rw-r--r--platform/ios/Integration Tests/MGLTestLocationManager.h10
-rw-r--r--platform/ios/Integration Tests/MGLTestLocationManager.m44
5 files changed, 88 insertions, 0 deletions
diff --git a/platform/ios/Integration Tests/Annotation Tests/MGLAnnotationViewIntegrationTests.m b/platform/ios/Integration Tests/Annotation Tests/MGLAnnotationViewIntegrationTests.m
index ba63a9eff4..fefb938773 100644
--- a/platform/ios/Integration Tests/Annotation Tests/MGLAnnotationViewIntegrationTests.m
+++ b/platform/ios/Integration Tests/Annotation Tests/MGLAnnotationViewIntegrationTests.m
@@ -1,6 +1,7 @@
#import "MGLMapViewIntegrationTest.h"
#import "MGLTestUtility.h"
#import "MGLMapAccessibilityElement.h"
+#import "MGLTestLocationManager.h"
@interface MGLMapView (Tests)
- (MGLAnnotationTag)annotationTagAtPoint:(CGPoint)point persistingResults:(BOOL)persist;
@@ -91,6 +92,31 @@
}
}
+- (void)testUserLocationWithOffsetAnchorPoint {
+ [self.mapView setCenterCoordinate:CLLocationCoordinate2DMake(37.787357, -122.39899)];
+ MGLTestLocationManager *locationManager = [[MGLTestLocationManager alloc] init];
+ self.mapView.locationManager = locationManager;
+
+ [self.mapView setUserTrackingMode:MGLUserTrackingModeFollow animated:NO];
+ CGRect originalFrame = [self.mapView viewForAnnotation:self.mapView.userLocation].frame;
+
+ // Temporarily disable location tracking so we can save the value of
+ // the originalFrame in memory
+ [self.mapView setUserTrackingMode:MGLUserTrackingModeNone animated:NO];
+
+ CGPoint offset = CGPointMake(20, 20);
+
+ self.mapViewUserLocationAnchorPoint = ^CGPoint (MGLMapView *mapView) {
+ return offset;;
+ };
+
+ [self.mapView setUserTrackingMode:MGLUserTrackingModeFollow animated:NO];
+ CGRect offsetFrame = [self.mapView viewForAnnotation:self.mapView.userLocation].frame;
+
+ XCTAssertEqual(originalFrame.origin.x + offset.x, offsetFrame.origin.x);
+ XCTAssertEqual(originalFrame.origin.y + offset.y, offsetFrame.origin.y);
+}
+
- (void)waitForCollisionDetectionToRun {
XCTAssertNil(self.renderFinishedExpectation, @"Incorrect test setup");
diff --git a/platform/ios/Integration Tests/MGLMapViewIntegrationTest.h b/platform/ios/Integration Tests/MGLMapViewIntegrationTest.h
index f513df8b20..2f459a5f44 100644
--- a/platform/ios/Integration Tests/MGLMapViewIntegrationTest.h
+++ b/platform/ios/Integration Tests/MGLMapViewIntegrationTest.h
@@ -26,6 +26,7 @@
@property (nonatomic) void (^regionWillChange)(MGLMapView *mapView, BOOL animated);
@property (nonatomic) void (^regionIsChanging)(MGLMapView *mapView);
@property (nonatomic) void (^regionDidChange)(MGLMapView *mapView, MGLCameraChangeReason reason, BOOL animated);
+@property (nonatomic) CGPoint (^mapViewUserLocationAnchorPoint)(MGLMapView *mapView);
// Utility methods
- (NSString*)validAccessToken;
diff --git a/platform/ios/Integration Tests/MGLMapViewIntegrationTest.m b/platform/ios/Integration Tests/MGLMapViewIntegrationTest.m
index c427a7842f..7153257df5 100644
--- a/platform/ios/Integration Tests/MGLMapViewIntegrationTest.m
+++ b/platform/ios/Integration Tests/MGLMapViewIntegrationTest.m
@@ -101,6 +101,13 @@
}
}
+- (CGPoint)mapViewUserLocationAnchorPoint:(MGLMapView *)mapView {
+ if (self.mapViewUserLocationAnchorPoint) {
+ return self.mapViewUserLocationAnchorPoint(mapView);
+ }
+ return CGPointZero;
+}
+
#pragma mark - Utilities
- (void)waitForMapViewToFinishLoadingStyleWithTimeout:(NSTimeInterval)timeout {
diff --git a/platform/ios/Integration Tests/MGLTestLocationManager.h b/platform/ios/Integration Tests/MGLTestLocationManager.h
new file mode 100644
index 0000000000..e0e6f25bb2
--- /dev/null
+++ b/platform/ios/Integration Tests/MGLTestLocationManager.h
@@ -0,0 +1,10 @@
+#import <XCTest/XCTest.h>
+#import <Mapbox/Mapbox.h>
+#import "MGLTestUtility.h"
+
+@interface MGLTestLocationManager : NSObject<MGLLocationManager>
+@end
+
+@interface MGLTestLocationManager()
+
+@end
diff --git a/platform/ios/Integration Tests/MGLTestLocationManager.m b/platform/ios/Integration Tests/MGLTestLocationManager.m
new file mode 100644
index 0000000000..f9a5a8650f
--- /dev/null
+++ b/platform/ios/Integration Tests/MGLTestLocationManager.m
@@ -0,0 +1,44 @@
+#import "MGLTestLocationManager.h"
+
+// Used to supply integration tests with a simulated location manager.
+// Methods that are empty are not used within integration tests and are
+// therefore unimplemented.
+
+@implementation MGLTestLocationManager
+
+@synthesize delegate;
+
+- (CLAuthorizationStatus)authorizationStatus { return kCLAuthorizationStatusAuthorizedAlways; }
+
+- (void)setHeadingOrientation:(CLDeviceOrientation)headingOrientation { }
+
+- (CLDeviceOrientation)headingOrientation { return 90; }
+
+- (void)requestAlwaysAuthorization { }
+
+- (void)requestWhenInUseAuthorization { }
+
+- (void)startUpdatingHeading { }
+
+// Simulate one location update
+- (void)startUpdatingLocation
+{
+ if ([self.delegate respondsToSelector:@selector(locationManager:didUpdateLocations:)]) {
+ CLLocation *location = [[CLLocation alloc] initWithLatitude:37.787357 longitude:-122.39899];
+ [self.delegate locationManager:self didUpdateLocations:@[location]];
+ }
+}
+
+- (void)stopUpdatingHeading { }
+
+- (void)stopUpdatingLocation { }
+
+- (void)dismissHeadingCalibrationDisplay { }
+
+- (void)dealloc { self.delegate = nil; }
+
+- (void)locationManager:(CLLocationManager *)manager didUpdateHeading:(CLHeading *)newHeading { }
+
+- (BOOL)locationManagerShouldDisplayHeadingCalibration:(CLLocationManager *)manager { return NO; }
+
+@end