Skip to content

Commit 4faf194

Browse files
KazuCocoadpgraham
authored andcommitted
feat: add reduce motion (works only on simulator) (#202)
* add reduceMotion in WDA to apply the change immediately * tweak comment * fix reviews * add fbconfig tests * revert plist * replace header, assertion method * check by selector if the method is available * define as const
1 parent e5e7ef6 commit 4faf194

File tree

6 files changed

+116
-1
lines changed

6 files changed

+116
-1
lines changed
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
2+
/* Generated by RuntimeBrowser
3+
Image: /System/Library/PrivateFrameworks/AccessibilityUtilities.framework/AccessibilityUtilities
4+
*/
5+
6+
@interface AXSettings : NSObject
7+
8+
@property bool reduceMotionEnabled;
9+
10+
+ (id)sharedInstance;
11+
12+
- (void)setReduceMotionEnabled:(bool)arg1;
13+
- (bool)reduceMotionEnabled;
14+
15+
@end

WebDriverAgent.xcodeproj/project.pbxproj

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -298,10 +298,13 @@
298298
641EE70F2240CE4800173FCB /* FBTVNavigationTracker.m in Sources */ = {isa = PBXBuildFile; fileRef = 641EE70D2240CE4800173FCB /* FBTVNavigationTracker.m */; };
299299
641EE7172240DE8C00173FCB /* RoutingHTTPServer.framework in Copy frameworks */ = {isa = PBXBuildFile; fileRef = 641EE7122240DE5E00173FCB /* RoutingHTTPServer.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; };
300300
641EE7192240DFC100173FCB /* RoutingHTTPServer.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 641EE7122240DE5E00173FCB /* RoutingHTTPServer.framework */; };
301+
644D9CCE230E1F1A00C90459 /* FBConfigurationTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 644D9CCD230E1F1A00C90459 /* FBConfigurationTests.m */; };
301302
648C10AB22AAAD9C00B81B9A /* UIKeyboardImpl.h in Headers */ = {isa = PBXBuildFile; fileRef = 648C10AA22AAAD9C00B81B9A /* UIKeyboardImpl.h */; };
302303
648C10AC22AAAD9C00B81B9A /* UIKeyboardImpl.h in Headers */ = {isa = PBXBuildFile; fileRef = 648C10AA22AAAD9C00B81B9A /* UIKeyboardImpl.h */; };
303304
648C10AF22AAAE4000B81B9A /* TIPreferencesController.h in Headers */ = {isa = PBXBuildFile; fileRef = 648C10AE22AAAE4000B81B9A /* TIPreferencesController.h */; };
304305
648C10B022AAAE4000B81B9A /* TIPreferencesController.h in Headers */ = {isa = PBXBuildFile; fileRef = 648C10AE22AAAE4000B81B9A /* TIPreferencesController.h */; };
306+
6496A5D9230D6EB30087F8CB /* AXSettings.h in Headers */ = {isa = PBXBuildFile; fileRef = 6496A5D8230D6EB30087F8CB /* AXSettings.h */; };
307+
6496A5DA230D6EB30087F8CB /* AXSettings.h in Headers */ = {isa = PBXBuildFile; fileRef = 6496A5D8230D6EB30087F8CB /* AXSettings.h */; };
305308
64B264FE228C50E0002A5025 /* WebDriverAgentLib_tvOS.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 641EE6F82240C5CA00173FCB /* WebDriverAgentLib_tvOS.framework */; };
306309
64B26504228C5299002A5025 /* FBTVNavigationTrackerTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 64B264F3228C5098002A5025 /* FBTVNavigationTrackerTests.m */; };
307310
64B26508228C5514002A5025 /* XCUIElementDouble.m in Sources */ = {isa = PBXBuildFile; fileRef = 64B26507228C5514002A5025 /* XCUIElementDouble.m */; };
@@ -832,8 +835,10 @@
832835
641EE70D2240CE4800173FCB /* FBTVNavigationTracker.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = FBTVNavigationTracker.m; sourceTree = "<group>"; };
833836
641EE7122240DE5E00173FCB /* RoutingHTTPServer.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = RoutingHTTPServer.framework; path = Carthage/Build/tvOS/RoutingHTTPServer.framework; sourceTree = "<group>"; };
834837
641EE73A2240F49D00173FCB /* YYCache.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = YYCache.framework; path = Carthage/Build/tvOS/YYCache.framework; sourceTree = "<group>"; };
838+
644D9CCD230E1F1A00C90459 /* FBConfigurationTests.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = FBConfigurationTests.m; sourceTree = "<group>"; };
835839
648C10AA22AAAD9C00B81B9A /* UIKeyboardImpl.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = UIKeyboardImpl.h; sourceTree = "<group>"; };
836840
648C10AE22AAAE4000B81B9A /* TIPreferencesController.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = TIPreferencesController.h; sourceTree = "<group>"; };
841+
6496A5D8230D6EB30087F8CB /* AXSettings.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = AXSettings.h; sourceTree = "<group>"; };
837842
64B264EB228C4D54002A5025 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
838843
64B264F3228C5098002A5025 /* FBTVNavigationTrackerTests.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = FBTVNavigationTrackerTests.m; sourceTree = "<group>"; };
839844
64B264F9228C50E0002A5025 /* UnitTests_tvOS.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = UnitTests_tvOS.xctest; sourceTree = BUILT_PRODUCTS_DIR; };
@@ -1337,6 +1342,14 @@
13371342
path = TextInput;
13381343
sourceTree = "<group>";
13391344
};
1345+
6496A5D7230D6E9D0087F8CB /* AccessibilityUtilities */ = {
1346+
isa = PBXGroup;
1347+
children = (
1348+
6496A5D8230D6EB30087F8CB /* AXSettings.h */,
1349+
);
1350+
path = AccessibilityUtilities;
1351+
sourceTree = "<group>";
1352+
};
13401353
64B264E8228C4D54002A5025 /* UnitTests_tvOS */ = {
13411354
isa = PBXGroup;
13421355
children = (
@@ -1423,6 +1436,7 @@
14231436
91F9DB731B99DDD8001349B2 /* PrivateHeaders */ = {
14241437
isa = PBXGroup;
14251438
children = (
1439+
6496A5D7230D6E9D0087F8CB /* AccessibilityUtilities */,
14261440
C8FB547222D3948300B69954 /* MobileCoreServices */,
14271441
648C10AD22AAAE2400B81B9A /* TextInput */,
14281442
648C10A922AAAD7600B81B9A /* UIKitCore */,
@@ -1732,6 +1746,7 @@
17321746
EEBBD48D1D4785FC00656A81 /* XCUIElementFBFindTests.m */,
17331747
EE1E06E11D181CC9007CF043 /* XCUIElementHelperIntegrationTests.m */,
17341748
631B523421F6174300625362 /* FBImageIOScalerTests.m */,
1749+
644D9CCD230E1F1A00C90459 /* FBConfigurationTests.m */,
17351750
);
17361751
path = IntegrationTests;
17371752
sourceTree = "<group>";
@@ -2044,6 +2059,7 @@
20442059
641EE6792240C5CA00173FCB /* XCUIRecorderNodeFinder.h in Headers */,
20452060
641EE67A2240C5CA00173FCB /* XCUIElement+FBAccessibility.h in Headers */,
20462061
641EE67B2240C5CA00173FCB /* XCUIRecorderUtilities.h in Headers */,
2062+
6496A5DA230D6EB30087F8CB /* AXSettings.h in Headers */,
20472063
641EE67C2240C5CA00173FCB /* XCTestCaseRun.h in Headers */,
20482064
641EE67D2240C5CA00173FCB /* XCTestConfiguration.h in Headers */,
20492065
641EE67E2240C5CA00173FCB /* _XCTDarwinNotificationExpectationImplementation.h in Headers */,
@@ -2203,6 +2219,7 @@
22032219
71B155DF23080CA600646AFB /* FBProtocolHelpers.h in Headers */,
22042220
EE35AD4B1E3B77D600A02D78 /* XCTestExpectationWaiter.h in Headers */,
22052221
EE35AD1E1E3B77D600A02D78 /* UIGestureRecognizer-RecordingAdditions.h in Headers */,
2222+
6496A5D9230D6EB30087F8CB /* AXSettings.h in Headers */,
22062223
EE35AD301E3B77D600A02D78 /* XCKeyboardKeyMap.h in Headers */,
22072224
EE35AD5D1E3B77D600A02D78 /* XCTNSPredicateExpectationObject-Protocol.h in Headers */,
22082225
EE158B5F1CBD47A000A3E3F0 /* WebDriverAgentLib.h in Headers */,
@@ -2930,6 +2947,7 @@
29302947
EE5095EE1EBCC9090028E2FE /* FBXPathIntegrationTests.m in Sources */,
29312948
EE5095EF1EBCC9090028E2FE /* XCUIElementHelperIntegrationTests.m in Sources */,
29322949
EE5095F01EBCC9090028E2FE /* XCUIDeviceHelperTests.m in Sources */,
2950+
644D9CCE230E1F1A00C90459 /* FBConfigurationTests.m in Sources */,
29332951
EE5095F11EBCC9090028E2FE /* XCUIElementFBFindTests.m in Sources */,
29342952
EE5095F21EBCC9090028E2FE /* XCUIDeviceRotationTests.m in Sources */,
29352953
EE5095F41EBCC9090028E2FE /* XCUIDeviceHealthCheckTests.m in Sources */,

WebDriverAgentLib/Commands/FBSessionCommands.m

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
static NSString* const KEYBOARD_PREDICTION = @"keyboardPrediction";
3333
static NSString* const SNAPSHOT_TIMEOUT = @"snapshotTimeout";
3434
static NSString* const USE_FIRST_MATCH = @"useFirstMatch";
35+
static NSString* const REDUCE_MOTION = @"reduceMotion";
3536

3637
@implementation FBSessionCommands
3738

@@ -233,6 +234,7 @@ + (NSArray *)routes
233234
KEYBOARD_PREDICTION: @([FBConfiguration keyboardPrediction]),
234235
SNAPSHOT_TIMEOUT: @([FBConfiguration snapshotTimeout]),
235236
USE_FIRST_MATCH: @([FBConfiguration useFirstMatch]),
237+
REDUCE_MOTION: @([FBConfiguration reduceMotionEnabled]),
236238
}
237239
);
238240
}
@@ -273,6 +275,9 @@ + (NSArray *)routes
273275
if ([settings objectForKey:USE_FIRST_MATCH]) {
274276
[FBConfiguration setUseFirstMatch:[[settings objectForKey:USE_FIRST_MATCH] boolValue]];
275277
}
278+
if ([settings objectForKey:REDUCE_MOTION]) {
279+
[FBConfiguration setReduceMotionEnabled:[[settings objectForKey:REDUCE_MOTION] boolValue]];
280+
}
276281

277282
return [self handleGetSettings:request];
278283
}

WebDriverAgentLib/Utilities/FBConfiguration.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99

1010
#import <Foundation/Foundation.h>
1111

12+
#import "AXSettings.h"
1213
#import "UIKeyboardImpl.h"
1314
#import "TIPreferencesController.h"
1415

@@ -147,6 +148,16 @@ NS_ASSUME_NONNULL_BEGIN
147148
+ (void)setUseFirstMatch:(BOOL)enabled;
148149
+ (BOOL)useFirstMatch;
149150

151+
/**
152+
* Modify reduce motion configuration in accessibility.
153+
* It works only for Simulator since Real device has security model which allows chnaging preferences
154+
* only from settings app.
155+
*
156+
* @param isEnabled Turn the configuration on if the value is YES
157+
*/
158+
+ (void)setReduceMotionEnabled:(BOOL)isEnabled;
159+
+ (BOOL)reduceMotionEnabled;
160+
150161
@end
151162

152163
NS_ASSUME_NONNULL_END

WebDriverAgentLib/Utilities/FBConfiguration.m

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
static NSString *const controllerClassName = @"TIPreferencesController";
2626
static NSString *const FBKeyboardAutocorrectionKey = @"KeyboardAutocorrection";
2727
static NSString *const FBKeyboardPredictionKey = @"KeyboardPrediction";
28-
28+
static NSString *const axSettingsClassName = @"AXSettings";
2929

3030
static BOOL FBShouldUseTestManagerForVisibilityDetection = NO;
3131
static BOOL FBShouldUseSingletonTestManager = YES;
@@ -346,4 +346,27 @@ + (NSRange)bindingPortRangeFromArguments
346346
return NSMakeRange(port, 1);
347347
}
348348

349+
+ (void)setReduceMotionEnabled:(BOOL)isEnabled
350+
{
351+
Class settingsClass = NSClassFromString(axSettingsClassName);
352+
AXSettings *settings = [settingsClass sharedInstance];
353+
354+
// Below does not work on real devices because of iOS security model
355+
// (lldb) po settings.reduceMotionEnabled = isEnabled
356+
// 2019-08-21 22:58:19.776165+0900 WebDriverAgentRunner-Runner[322:13361] [User Defaults] Couldn't write value for key ReduceMotionEnabled in CFPrefsPlistSource<0x28111a700> (Domain: com.apple.Accessibility, User: kCFPreferencesCurrentUser, ByHost: No, Container: (null), Contents Need Refresh: No): setting preferences outside an application's container requires user-preference-write or file-write-data sandbox access
357+
if ([settings respondsToSelector:@selector(setReduceMotionEnabled:)]) {
358+
[settings setReduceMotionEnabled:isEnabled];
359+
}
360+
}
361+
362+
+ (BOOL)reduceMotionEnabled
363+
{
364+
Class settingsClass = NSClassFromString(axSettingsClassName);
365+
AXSettings *settings = [settingsClass sharedInstance];
366+
367+
if ([settings respondsToSelector:@selector(reduceMotionEnabled)]) {
368+
return settings.reduceMotionEnabled;
369+
}
370+
return NO;
371+
}
349372
@end
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
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+
#import "FBIntegrationTestCase.h"
12+
13+
#import "FBConfiguration.h"
14+
#import "FBRuntimeUtils.h"
15+
16+
@interface FBConfigurationTests : FBIntegrationTestCase
17+
18+
@end
19+
20+
@implementation FBConfigurationTests
21+
22+
- (void)setUp
23+
{
24+
[super setUp];
25+
[self launchApplication];
26+
}
27+
28+
- (void)testReduceMotion
29+
{
30+
BOOL defaultReduceMotionEnabled = [FBConfiguration reduceMotionEnabled];
31+
32+
[FBConfiguration setReduceMotionEnabled:YES];
33+
XCTAssertTrue([FBConfiguration reduceMotionEnabled]);
34+
35+
[FBConfiguration setReduceMotionEnabled:defaultReduceMotionEnabled];
36+
if (isSDKVersionLessThan(@"10.0")) {
37+
XCTAssertFalse([FBConfiguration reduceMotionEnabled]);
38+
} else {
39+
XCTAssertEqual([FBConfiguration reduceMotionEnabled], defaultReduceMotionEnabled);
40+
}
41+
}
42+
43+
@end

0 commit comments

Comments
 (0)