Skip to content
This repository was archived by the owner on Dec 26, 2019. It is now read-only.

Commit 762760d

Browse files
Marek Cirkosfacebook-github-bot
authored andcommitted
Handle infinitive numbers in elements rect
Summary: In case testmanagerd has problems in calculating frames it may return 'inf' instead which does not behave well with JSON encoding. Therfore checing for infs when formating JSON reponse Reviewed By: antiarchit Differential Revision: D7067158 fbshipit-source-id: 180400186af49f1353d93e9eb61d7306b8a1a0f6
1 parent eb9a584 commit 762760d

File tree

3 files changed

+67
-1
lines changed

3 files changed

+67
-1
lines changed

WebDriverAgent.xcodeproj/project.pbxproj

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -281,6 +281,7 @@
281281
EE7E271E1D06C69F001BEC7B /* FBXCTestCaseImplementationFailureHoldingProxy.h in Headers */ = {isa = PBXBuildFile; fileRef = EE7E271A1D06C69F001BEC7B /* FBXCTestCaseImplementationFailureHoldingProxy.h */; };
282282
EE7E271F1D06C69F001BEC7B /* FBXCTestCaseImplementationFailureHoldingProxy.m in Sources */ = {isa = PBXBuildFile; fileRef = EE7E271B1D06C69F001BEC7B /* FBXCTestCaseImplementationFailureHoldingProxy.m */; };
283283
EE8BA97A1DCCED9A00A9DEF8 /* FBNavigationController.m in Sources */ = {isa = PBXBuildFile; fileRef = EE8BA9791DCCED9A00A9DEF8 /* FBNavigationController.m */; };
284+
EE8DDD7920C565FB004D4925 /* XCUIApplicationFBHelpersTests.m in Sources */ = {isa = PBXBuildFile; fileRef = EE8DDD7820C565FB004D4925 /* XCUIApplicationFBHelpersTests.m */; };
284285
EE9AB8011CAEE048008C271F /* UITestingUITests.m in Sources */ = {isa = PBXBuildFile; fileRef = EE9AB7FD1CAEE048008C271F /* UITestingUITests.m */; };
285286
EE9B76591CF7987800275851 /* FBRouteTests.m in Sources */ = {isa = PBXBuildFile; fileRef = EE9B76571CF7987300275851 /* FBRouteTests.m */; };
286287
EE9B768E1CF7997600275851 /* AppDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = EE9B76831CF7997600275851 /* AppDelegate.m */; };
@@ -611,6 +612,7 @@
611612
EE836C021C0F118600D87246 /* UnitTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = UnitTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; };
612613
EE8BA9781DCCED9A00A9DEF8 /* FBNavigationController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = FBNavigationController.h; sourceTree = "<group>"; };
613614
EE8BA9791DCCED9A00A9DEF8 /* FBNavigationController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = FBNavigationController.m; sourceTree = "<group>"; };
615+
EE8DDD7820C565FB004D4925 /* XCUIApplicationFBHelpersTests.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = XCUIApplicationFBHelpersTests.m; sourceTree = "<group>"; };
614616
EE9AB7451CAEDF0C008C271F /* XCUIElement+FBAccessibility.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "XCUIElement+FBAccessibility.h"; sourceTree = "<group>"; };
615617
EE9AB7461CAEDF0C008C271F /* XCUIElement+FBAccessibility.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "XCUIElement+FBAccessibility.m"; sourceTree = "<group>"; };
616618
EE9AB7471CAEDF0C008C271F /* XCUIElement+FBIsVisible.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "XCUIElement+FBIsVisible.h"; sourceTree = "<group>"; };
@@ -1117,6 +1119,7 @@
11171119
EE9B76581CF7987300275851 /* Info.plist */,
11181120
7139145B1DF01A12005896C2 /* NSExpressionFBFormatTests.m */,
11191121
71A224E71DE326C500844D55 /* NSPredicateFBFormatTests.m */,
1122+
EE8DDD7820C565FB004D4925 /* XCUIApplicationFBHelpersTests.m */,
11201123
EEC9EED820077D8E00BC0D5B /* XCUICoordinateFix.m */,
11211124
713914591DF01989005896C2 /* XCUIElementHelpersTests.m */,
11221125
);
@@ -1849,6 +1852,7 @@
18491852
EE3F8D001D08B05F006F02CE /* FBElementTypeTransformerTests.m in Sources */,
18501853
EEE16E971D33A25500172525 /* FBConfigurationTests.m in Sources */,
18511854
ADBC39941D0782CD00327304 /* FBElementCacheTests.m in Sources */,
1855+
EE8DDD7920C565FB004D4925 /* XCUIApplicationFBHelpersTests.m in Sources */,
18521856
719FF5B91DAD21F5008E0099 /* FBElementUtilitiesTests.m in Sources */,
18531857
716E0BD11E917F260087A825 /* FBXMLSafeStringTests.m in Sources */,
18541858
ADEF63AD1D09DCCF0070A7E3 /* FBXPathCreatorTests.m in Sources */,

WebDriverAgentLib/Categories/XCUIApplication+FBHelpers.m

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ + (NSDictionary *)dictionaryForElement:(XCElementSnapshot *)snapshot
5959
info[@"name"] = FBValueOrNull(snapshot.wdName);
6060
info[@"value"] = FBValueOrNull(snapshot.wdValue);
6161
info[@"label"] = FBValueOrNull(snapshot.wdLabel);
62-
info[@"rect"] = snapshot.wdRect;
62+
info[@"rect"] = [XCUIApplication formattedRectWithFrame:snapshot.wdFrame];
6363
info[@"frame"] = NSStringFromCGRect(snapshot.wdFrame);
6464
info[@"isEnabled"] = [@([snapshot isWDEnabled]) stringValue];
6565
info[@"isVisible"] = [@([snapshot isWDVisible]) stringValue];
@@ -74,6 +74,16 @@ + (NSDictionary *)dictionaryForElement:(XCElementSnapshot *)snapshot
7474
return info;
7575
}
7676

77+
+ (NSDictionary *)formattedRectWithFrame:(CGRect)frame
78+
{
79+
return @{
80+
@"x": @(isinf(CGRectGetMinX(frame)) ? 0: CGRectGetMinX(frame)),
81+
@"y": @(isinf(CGRectGetMinY(frame)) ? 0: CGRectGetMinY(frame)),
82+
@"width": @(isinf(CGRectGetWidth(frame)) ? 0 : CGRectGetWidth(frame)),
83+
@"height": @(isinf(CGRectGetHeight(frame)) ? 0 : CGRectGetHeight(frame)),
84+
};
85+
}
86+
7787
+ (NSDictionary *)accessibilityInfoForElement:(XCElementSnapshot *)snapshot
7888
{
7989
BOOL isAccessible = [snapshot isWDAccessible];
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
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+
10+
#import <XCTest/XCTest.h>
11+
12+
#import "XCUIApplication+FBHelpers.h"
13+
14+
@interface XCUIApplication (FBHelpersTest)
15+
+ (NSDictionary *)formattedRectWithFrame:(CGRect)frame;
16+
@end
17+
18+
@interface XCUIApplicationFBHelpersTests : XCTestCase
19+
@end
20+
21+
@implementation XCUIApplicationFBHelpersTests
22+
23+
- (void)setUp
24+
{
25+
[super setUp];
26+
}
27+
28+
- (void)testRectWithFinitePositiveNumbers
29+
{
30+
NSDictionary *expected = @{@"x": @1, @"y": @2, @"width": @3, @"height": @4};
31+
NSDictionary *result = [XCUIApplication formattedRectWithFrame:CGRectMake(1, 2, 3, 4)];
32+
XCTAssertNoThrow([NSJSONSerialization dataWithJSONObject:result options:NSJSONWritingPrettyPrinted error:nil]);
33+
XCTAssertEqualObjects(result, expected);
34+
}
35+
36+
- (void)testRectWithFiniteNegativeNumbers
37+
{
38+
NSDictionary *expected = @{@"x": @(-4), @"y": @2, @"width": @3, @"height": @4};
39+
NSDictionary *result = [XCUIApplication formattedRectWithFrame:CGRectMake(-1, 2, -3, 4)];
40+
XCTAssertNoThrow([NSJSONSerialization dataWithJSONObject:result options:NSJSONWritingPrettyPrinted error:nil]);
41+
XCTAssertEqualObjects(result, expected);
42+
}
43+
44+
- (void)testInfinitives
45+
{
46+
NSDictionary *expected = @{@"x": @(0), @"y": @0, @"width": @(3), @"height": @0};
47+
NSDictionary *result = [XCUIApplication formattedRectWithFrame:CGRectMake(INFINITY, INFINITY, 3, INFINITY)];
48+
XCTAssertNoThrow([NSJSONSerialization dataWithJSONObject:result options:NSJSONWritingPrettyPrinted error:nil]);
49+
XCTAssertEqualObjects(result, expected);
50+
}
51+
52+
@end

0 commit comments

Comments
 (0)