FBW3CMultiTouchActionsIntegrationTests.m 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  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 "FBIntegrationTestCase.h"
  11. #import "XCUIElement.h"
  12. #import "XCUIApplication+FBTouchAction.h"
  13. #import "FBTestMacros.h"
  14. #import "XCUIDevice+FBRotation.h"
  15. #import "FBRunLoopSpinner.h"
  16. @interface FBW3CMultiTouchActionsIntegrationTests : FBIntegrationTestCase
  17. @end
  18. @implementation FBW3CMultiTouchActionsIntegrationTests
  19. - (void)verifyGesture:(NSArray<NSDictionary<NSString *, id> *> *)gesture orientation:(UIDeviceOrientation)orientation
  20. {
  21. [[XCUIDevice sharedDevice] fb_setDeviceInterfaceOrientation:orientation];
  22. NSError *error;
  23. XCTAssertTrue([self.testedApplication fb_performW3CActions:gesture elementCache:nil error:&error]);
  24. FBAssertWaitTillBecomesTrue(self.testedApplication.alerts.count > 0);
  25. }
  26. - (void)setUp
  27. {
  28. [super setUp];
  29. static dispatch_once_t onceToken;
  30. dispatch_once(&onceToken, ^{
  31. [self launchApplication];
  32. [self goToAlertsPage];
  33. });
  34. [self clearAlert];
  35. }
  36. - (void)tearDown
  37. {
  38. [self clearAlert];
  39. [self resetOrientation];
  40. [super tearDown];
  41. }
  42. - (void)testErroneousGestures
  43. {
  44. NSArray<NSArray<NSDictionary<NSString *, id> *> *> *invalidGestures =
  45. @[
  46. // One of the chains has duplicated id
  47. @[
  48. @{
  49. @"type": @"pointer",
  50. @"id": @"finger1",
  51. @"parameters": @{@"pointerType": @"touch"},
  52. @"actions": @[
  53. @{@"type": @"pointerMove", @"duration": @0, @"x": @1, @"y": @1},
  54. @{@"type": @"pointerDown"},
  55. @{@"type": @"pause", @"duration": @100},
  56. @{@"type": @"pointerUp"},
  57. ],
  58. },
  59. @{
  60. @"type": @"pointer",
  61. @"id": @"finger1",
  62. @"parameters": @{@"pointerType": @"touch"},
  63. @"actions": @[
  64. @{@"type": @"pointerMove", @"duration": @0, @"x": @1, @"y": @1},
  65. @{@"type": @"pointerDown"},
  66. @{@"type": @"pause", @"duration": @100},
  67. @{@"type": @"pointerUp"},
  68. ],
  69. },
  70. ],
  71. ];
  72. for (NSArray<NSDictionary<NSString *, id> *> *invalidGesture in invalidGestures) {
  73. NSError *error;
  74. XCTAssertFalse([self.testedApplication fb_performW3CActions:invalidGesture elementCache:nil error:&error]);
  75. XCTAssertNotNil(error);
  76. }
  77. }
  78. - (void)testSymmetricTwoFingersTap
  79. {
  80. XCUIElement *element = self.testedApplication.buttons[FBShowAlertButtonName];
  81. NSArray<NSDictionary<NSString *, id> *> *gesture =
  82. @[
  83. @{
  84. @"type": @"pointer",
  85. @"id": @"finger1",
  86. @"parameters": @{@"pointerType": @"touch"},
  87. @"actions": @[
  88. @{@"type": @"pointerMove", @"duration": @0, @"origin": element, @"x": @0, @"y": @0},
  89. @{@"type": @"pointerDown"},
  90. @{@"type": @"pause", @"duration": @100},
  91. @{@"type": @"pointerUp"},
  92. ],
  93. },
  94. @{
  95. @"type": @"pointer",
  96. @"id": @"finger2",
  97. @"parameters": @{@"pointerType": @"touch"},
  98. @"actions": @[
  99. @{@"type": @"pointerMove", @"duration": @0, @"origin": element, @"x": @0, @"y": @0},
  100. @{@"type": @"pointerDown"},
  101. @{@"type": @"pause", @"duration": @100},
  102. @{@"type": @"pointerUp"},
  103. ],
  104. },
  105. ];
  106. [self verifyGesture:gesture orientation:UIDeviceOrientationPortrait];
  107. }
  108. @end