diff options
author | Minh Nguyễn <mxn@1ec5.org> | 2016-04-26 00:58:23 -0700 |
---|---|---|
committer | Minh Nguyễn <mxn@1ec5.org> | 2016-05-05 01:07:29 -0700 |
commit | dc0432bf8775a1c65920b24f471fbd66d177ecee (patch) | |
tree | 5732cdf7c9bf53237bb00c1f3bc33c21cf0cd0a1 | |
parent | 261b9a5811948141541e2da4d6535c157b980831 (diff) | |
download | qtlocation-mapboxgl-dc0432bf8775a1c65920b24f471fbd66d177ecee.tar.gz |
[ios] Test rotation, compass; bypass access token prompt
Test the rotation gesture and the compass. Bypass the access token prompt by filling in a bogus access token.
-rw-r--r-- | platform/ios/ios.xcodeproj/project.pbxproj | 11 | ||||
-rw-r--r-- | platform/ios/ios.xcodeproj/xcshareddata/xcschemes/iosapp.xcscheme | 10 | ||||
-rw-r--r-- | platform/ios/uitest/MGLAnnotationTests.m | 15 | ||||
-rw-r--r-- | platform/ios/uitest/MGLGestureTests.m | 62 | ||||
-rw-r--r-- | platform/ios/uitest/MGLUITests.h | 3 |
5 files changed, 97 insertions, 4 deletions
diff --git a/platform/ios/ios.xcodeproj/project.pbxproj b/platform/ios/ios.xcodeproj/project.pbxproj index 20024c8749..617443fa27 100644 --- a/platform/ios/ios.xcodeproj/project.pbxproj +++ b/platform/ios/ios.xcodeproj/project.pbxproj @@ -50,6 +50,7 @@ DA35A2CB1CCAAAD200E826B2 /* NSValue+MGLAdditions.m in Sources */ = {isa = PBXBuildFile; fileRef = DA35A2C81CCAAAD200E826B2 /* NSValue+MGLAdditions.m */; }; DA35A2CC1CCAAAD200E826B2 /* NSValue+MGLAdditions.m in Sources */ = {isa = PBXBuildFile; fileRef = DA35A2C81CCAAAD200E826B2 /* NSValue+MGLAdditions.m */; }; DA4A0DF01CCE82500045352A /* MGLAnnotationTests.m in Sources */ = {isa = PBXBuildFile; fileRef = DA4A0DEF1CCE82500045352A /* MGLAnnotationTests.m */; }; + DA6A65971CCF429800F21F6B /* MGLGestureTests.m in Sources */ = {isa = PBXBuildFile; fileRef = DA6A65961CCF429800F21F6B /* MGLGestureTests.m */; }; DA821D061CCC6D59007508D4 /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = DA821D041CCC6D59007508D4 /* LaunchScreen.storyboard */; }; DA821D071CCC6D59007508D4 /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = DA821D051CCC6D59007508D4 /* Main.storyboard */; }; DA8847D91CBAF91600AB86E3 /* Mapbox.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = DA8847D21CBAF91600AB86E3 /* Mapbox.framework */; }; @@ -356,6 +357,8 @@ DA4A0DEF1CCE82500045352A /* MGLAnnotationTests.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = MGLAnnotationTests.m; sourceTree = "<group>"; }; DA4A0DF11CCE82500045352A /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; }; DA4A26961CB6E795000B7809 /* Mapbox.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; path = Mapbox.framework; sourceTree = BUILT_PRODUCTS_DIR; }; + DA6A65961CCF429800F21F6B /* MGLGestureTests.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MGLGestureTests.m; sourceTree = "<group>"; }; + DA6A65981CCF42FE00F21F6B /* MGLUITests.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MGLUITests.h; sourceTree = "<group>"; }; DA821D041CCC6D59007508D4 /* LaunchScreen.storyboard */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.storyboard; path = LaunchScreen.storyboard; sourceTree = "<group>"; }; DA821D051CCC6D59007508D4 /* Main.storyboard */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.storyboard; path = Main.storyboard; sourceTree = "<group>"; }; DA8847D21CBAF91600AB86E3 /* Mapbox.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Mapbox.framework; sourceTree = BUILT_PRODUCTS_DIR; }; @@ -536,7 +539,7 @@ DABCABA91CB80692000A7C39 /* Benchmarking App */, DA8847D31CBAF91600AB86E3 /* SDK */, DA2E88521CC036F400F24E7B /* SDK Tests */, - DA4A0DEE1CCE82500045352A /* uitest */, + DA4A0DEE1CCE82500045352A /* UI Tests */, DA1DC9921CB6DF24006E619F /* Frameworks */, DAC07C951CBB2CAD000CB309 /* Configuration */, DA1DC94B1CB6C1C2006E619F /* Products */, @@ -632,12 +635,15 @@ path = test; sourceTree = "<group>"; }; - DA4A0DEE1CCE82500045352A /* uitest */ = { + DA4A0DEE1CCE82500045352A /* UI Tests */ = { isa = PBXGroup; children = ( + DA6A65981CCF42FE00F21F6B /* MGLUITests.h */, DA4A0DEF1CCE82500045352A /* MGLAnnotationTests.m */, + DA6A65961CCF429800F21F6B /* MGLGestureTests.m */, DA4A0DF11CCE82500045352A /* Info.plist */, ); + name = "UI Tests"; path = uitest; sourceTree = "<group>"; }; @@ -1298,6 +1304,7 @@ isa = PBXSourcesBuildPhase; buildActionMask = 2147483647; files = ( + DA6A65971CCF429800F21F6B /* MGLGestureTests.m in Sources */, DA4A0DF01CCE82500045352A /* MGLAnnotationTests.m in Sources */, ); runOnlyForDeploymentPostprocessing = 0; diff --git a/platform/ios/ios.xcodeproj/xcshareddata/xcschemes/iosapp.xcscheme b/platform/ios/ios.xcodeproj/xcshareddata/xcschemes/iosapp.xcscheme index 9f5e2355c3..ac2e4a93a7 100644 --- a/platform/ios/ios.xcodeproj/xcshareddata/xcschemes/iosapp.xcscheme +++ b/platform/ios/ios.xcodeproj/xcshareddata/xcschemes/iosapp.xcscheme @@ -33,6 +33,16 @@ skipped = "NO"> <BuildableReference BuildableIdentifier = "primary" + BlueprintIdentifier = "DA2E88501CC036F400F24E7B" + BuildableName = "test.xctest" + BlueprintName = "test" + ReferencedContainer = "container:ios.xcodeproj"> + </BuildableReference> + </TestableReference> + <TestableReference + skipped = "NO"> + <BuildableReference + BuildableIdentifier = "primary" BlueprintIdentifier = "DA4A0DEC1CCE82500045352A" BuildableName = "uitest.xctest" BlueprintName = "uitest" diff --git a/platform/ios/uitest/MGLAnnotationTests.m b/platform/ios/uitest/MGLAnnotationTests.m index a719bc5638..9798647204 100644 --- a/platform/ios/uitest/MGLAnnotationTests.m +++ b/platform/ios/uitest/MGLAnnotationTests.m @@ -1,4 +1,4 @@ -#import <XCTest/XCTest.h> +#import "MGLUITests.h" @interface MGLAnnotationTests : XCTestCase @@ -12,7 +12,18 @@ self.continueAfterFailure = NO; [XCUIDevice sharedDevice].orientation = UIDeviceOrientationPortrait; - [[[XCUIApplication alloc] init] launch]; + XCUIApplication *app = [[XCUIApplication alloc] init]; + + // Bypass the access token prompt. + NSMutableDictionary <NSString *, NSString *> *environment = app.launchEnvironment.mutableCopy; + environment[@"MAPBOX_ACCESS_TOKEN"] = MGLUITestsBogusAccessToken; + app.launchEnvironment = environment; + + [app launch]; + + // Reset the viewport. + [app.navigationBars[@"MBXNavigationBar"].buttons[@"MBXSettingsButton"] tap]; + [app.sheets[@"Map Settings"].collectionViews.buttons[@"Reset Position"] tap]; } - (void)testDropPin { diff --git a/platform/ios/uitest/MGLGestureTests.m b/platform/ios/uitest/MGLGestureTests.m new file mode 100644 index 0000000000..42199dc20d --- /dev/null +++ b/platform/ios/uitest/MGLGestureTests.m @@ -0,0 +1,62 @@ +#import "MGLUITests.h" + +@interface MGLGestureTests : XCTestCase + +@end + +@implementation MGLGestureTests + +- (void)setUp { + [super setUp]; + + self.continueAfterFailure = NO; + [XCUIDevice sharedDevice].orientation = UIDeviceOrientationPortrait; + XCUIApplication *app = [[XCUIApplication alloc] init]; + + // Bypass the access token prompt. + NSMutableDictionary <NSString *, NSString *> *environment = app.launchEnvironment.mutableCopy; + environment[@"MAPBOX_ACCESS_TOKEN"] = MGLUITestsBogusAccessToken; + app.launchEnvironment = environment; + + [app launch]; + + // Reset the viewport. + [app.navigationBars[@"MBXNavigationBar"].buttons[@"MBXSettingsButton"] tap]; + [app.sheets[@"Map Settings"].collectionViews.buttons[@"Reset Position"] tap]; +} + +- (void)testRotate { + XCUIElement *mapElement = [[XCUIApplication alloc] init].otherElements[@"MGLMapView"]; + XCUIElement *compassElement = mapElement.buttons[@"MGLMapViewCompass"]; + NSPredicate *unhittable = [NSPredicate predicateWithFormat:@"hittable == NO"]; + + XCTAssertFalse(compassElement.hittable, @"Compass should be absent when the map is unrotated."); + + // Attempt to rotate the map 90° counterclockwise. The map should unrotate itself. + [mapElement rotate:M_PI_2 withVelocity:M_PI]; + XCTAssertTrue(compassElement.hittable, @"Compass should be present when the map is rotated."); + XCTAssertNotEqualWithAccuracy([compassElement.value rangeOfString:@"west"].location, NSNotFound, 1, @"Map should point west or thereabouts after rotating 90° counterclockwise. Instead, it points %@.", compassElement.value); + [self expectationForPredicate:unhittable evaluatedWithObject:compassElement handler:nil]; + [self waitForExpectationsWithTimeout:3 handler:nil]; + + // Zoom in until rotation is allowed. + [mapElement doubleTap]; + [mapElement doubleTap]; + [mapElement doubleTap]; + + // Rotate the map 90° counterclockwise. + [mapElement rotate:M_PI_2 withVelocity:M_PI]; + XCTAssertTrue(compassElement.hittable, @"Compass should be present when the map is rotated."); + XCTAssertNotEqualWithAccuracy([compassElement.value rangeOfString:@"west"].location, NSNotFound, 1, @"Map should point west or thereabouts after rotating 90° counterclockwise. Instead, it points %@.", compassElement.value); + + // Keep interacting with the map to make sure it doesn’t unrotate. + [mapElement swipeLeft]; + [mapElement swipeRight]; + + // Unrotate the map. + [compassElement tap]; + [self expectationForPredicate:unhittable evaluatedWithObject:compassElement handler:nil]; + [self waitForExpectationsWithTimeout:3 handler:nil]; +} + +@end diff --git a/platform/ios/uitest/MGLUITests.h b/platform/ios/uitest/MGLUITests.h new file mode 100644 index 0000000000..181b535688 --- /dev/null +++ b/platform/ios/uitest/MGLUITests.h @@ -0,0 +1,3 @@ +#import <XCTest/XCTest.h> + +static NSString * const MGLUITestsBogusAccessToken = @"sk.feedCafeDeadBeef.BadeBede"; |