XCUIDeviceRotationTests.m 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. /**
  2. * Copyright (c) 2015-present, Facebook, Inc.
  3. * All rights reserved.
  4. *
  5. * This source code is licensed under the BSD-style license found in the
  6. * LICENSE file in the root directory of this source tree. An additional grant
  7. * of patent rights can be found in the PATENTS file in the same directory.
  8. */
  9. #import <XCTest/XCTest.h>
  10. #import <UIKit/UIKit.h>
  11. #import "FBIntegrationTestCase.h"
  12. #import "XCUIDevice+FBRotation.h"
  13. @interface XCUIDeviceRotationTests : FBIntegrationTestCase
  14. @end
  15. @implementation XCUIDeviceRotationTests
  16. - (void)setUp
  17. {
  18. [super setUp];
  19. [self launchApplication];
  20. }
  21. - (void)tearDown
  22. {
  23. [self resetOrientation];
  24. [super tearDown];
  25. }
  26. - (void)testLandscapeRightOrientation
  27. {
  28. BOOL success = [[XCUIDevice sharedDevice] fb_setDeviceInterfaceOrientation:UIDeviceOrientationLandscapeRight];
  29. XCTAssertTrue(success, @"Device should support LandscapeRight");
  30. // Device rotation gives opposite interface rotation
  31. XCTAssertTrue(self.testedApplication.staticTexts[@"LandscapeLeft"].exists);
  32. }
  33. - (void)testLandscapeLeftOrientation
  34. {
  35. BOOL success = [[XCUIDevice sharedDevice] fb_setDeviceInterfaceOrientation:UIDeviceOrientationLandscapeLeft];
  36. XCTAssertTrue(success, @"Device should support LandscapeLeft");
  37. // Device rotation gives opposite interface rotation
  38. XCTAssertTrue(self.testedApplication.staticTexts[@"LandscapeRight"].exists);
  39. }
  40. - (void)testLandscapeRightRotation
  41. {
  42. BOOL success = [[XCUIDevice sharedDevice] fb_setDeviceRotation:@{
  43. @"x" : @(0),
  44. @"y" : @(0),
  45. @"z" : @(90)
  46. }];
  47. XCTAssertTrue(success, @"Device should support LandscapeRight");
  48. // Device rotation gives opposite interface rotation
  49. XCTAssertTrue(self.testedApplication.staticTexts[@"LandscapeLeft"].exists);
  50. }
  51. - (void)testLandscapeLeftRotation
  52. {
  53. BOOL success = [[XCUIDevice sharedDevice] fb_setDeviceRotation:@{
  54. @"x" : @(0),
  55. @"y" : @(0),
  56. @"z" : @(270)
  57. }];
  58. XCTAssertTrue(success, @"Device should support LandscapeLeft");
  59. // Device rotation gives opposite interface rotation
  60. XCTAssertTrue(self.testedApplication.staticTexts[@"LandscapeRight"].exists);
  61. }
  62. - (void)testRotationTiltRotation
  63. {
  64. UIDeviceOrientation currentRotation = [XCUIDevice sharedDevice].orientation;
  65. BOOL success = [[XCUIDevice sharedDevice] fb_setDeviceRotation:@{
  66. @"x" : @(15),
  67. @"y" : @(0),
  68. @"z" : @(0)}
  69. ];
  70. XCTAssertFalse(success, @"Device should not support tilt");
  71. XCTAssertEqual(currentRotation, [XCUIDevice sharedDevice].orientation, @"Device doesnt support tilt, should be at previous orientation");
  72. }
  73. @end