forked from parse-community/Parse-SDK-iOS-OSX
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathExtensionDataSharingTests.m
218 lines (162 loc) · 8.17 KB
/
ExtensionDataSharingTests.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
/**
* Copyright (c) 2015-present, Parse, LLC.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*/
@import Bolts.BFTask;
#import "PFExtensionDataSharingTestHelper.h"
#import "PFFileManager.h"
#import "PFInternalUtils.h"
#import "PFMultiProcessFileLock.h"
#import "PFTestCase.h"
#import "Parse_Private.h"
//TODO: (nlutsenko,richardross) These tests are extremely flaky, we should update and re-enable them.
@interface ExtensionDataSharingTests : PFTestCase {
PFExtensionDataSharingTestHelper *_testHelper;
}
@end
@implementation ExtensionDataSharingTests
///--------------------------------------
#pragma mark - XCTestCase
///--------------------------------------
- (void)setUp {
[super setUp];
_testHelper = [[PFExtensionDataSharingTestHelper alloc] init];
}
- (void)tearDown {
[[Parse _currentManager] clearEventuallyQueue];
NSString *path = [[Parse _currentManager].fileManager parseLocalSandboxDataDirectoryPath];
[Parse _clearCurrentManager];
[Parse _resetDataSharingIdentifiers];
// This allows us to delete files while respecting file locks.
NSArray *removalTasks = @[
#if TARGET_OS_IPHONE
// Doing this on OSX is BAD, as this returns ~/Library/Application Support. Trust me, you don't want to delete this.
[PFFileManager removeItemAtPathAsync:[PFExtensionDataSharingTestHelper sharedTestDirectoryPath]],
#endif
[PFFileManager removeItemAtPathAsync:path]
];
[[BFTask taskForCompletionOfAllTasks:removalTasks] waitUntilFinished];
_testHelper = nil;
[super tearDown];
}
///--------------------------------------
#pragma mark - Tests
///--------------------------------------
- (void)testEnablingDataSharingFromMainApp {
_testHelper.swizzledGroupContainerDirectoryPath = YES;
_testHelper.runningInExtensionEnvironment = NO;
[Parse enableDataSharingWithApplicationGroupIdentifier:@"yolo"];
[Parse _resetDataSharingIdentifiers];
_testHelper.runningInExtensionEnvironment = YES;
XCTAssertThrows([Parse enableDataSharingWithApplicationGroupIdentifier:@"yolo"]);
// Just to make sure that initialization runs smoothly
[Parse setApplicationId:[[NSUUID UUID] UUIDString] clientKey:[[NSUUID UUID] UUIDString]];
}
- (void)testEnablingDataSharingFromExtensions {
_testHelper.swizzledGroupContainerDirectoryPath = YES;
_testHelper.runningInExtensionEnvironment = YES;
[Parse enableDataSharingWithApplicationGroupIdentifier:@"yolo"
containingApplication:@"parentYolo"];
[Parse _resetDataSharingIdentifiers];
_testHelper.runningInExtensionEnvironment = NO;
XCTAssertThrows([Parse enableDataSharingWithApplicationGroupIdentifier:@"yolo"
containingApplication:@"parentYolo"]);
// Just to make sure that initialization runs smoothly
[Parse setApplicationId:[[NSUUID UUID] UUIDString] clientKey:[[NSUUID UUID] UUIDString]];
}
- (void)testMainAppUsesSharedContainer {
_testHelper.swizzledGroupContainerDirectoryPath = YES;
_testHelper.runningInExtensionEnvironment = NO;
[Parse enableDataSharingWithApplicationGroupIdentifier:@"yolo"];
[Parse setApplicationId:[[NSUUID UUID] UUIDString] clientKey:@"b"];
// Paths are different on iOS and OSX.
NSString *containerPath = [PFExtensionDataSharingTestHelper sharedTestDirectoryPathForGroupIdentifier:@"yolo"];
[self assertDirectory:containerPath hasContents:@{ @"Parse" : @{ [Parse applicationId] : @{ @"applicationId" : [NSNull null] } } } only:NO];
}
- (void)testExtensionUsesSharedContainer {
_testHelper.swizzledGroupContainerDirectoryPath = YES;
_testHelper.runningInExtensionEnvironment = YES;
[Parse enableDataSharingWithApplicationGroupIdentifier:@"yolo"
containingApplication:@"parentYolo"];
[Parse setApplicationId:[[NSUUID UUID] UUIDString] clientKey:@"b"];
// Paths are different on iOS and OSX.
NSString *containerPath = [PFExtensionDataSharingTestHelper sharedTestDirectoryPathForGroupIdentifier:@"yolo"];
[self assertDirectory:containerPath hasContents:@{ @"Parse" : @{ [Parse applicationId] : @{ @"applicationId" : [NSNull null] } } } only:NO];
}
- (void)testMigratingDataFromMainSandbox {
NSString *containerPath = [PFExtensionDataSharingTestHelper sharedTestDirectoryPathForGroupIdentifier:@"yolo"];
NSString *applicationId = [[NSUUID UUID] UUIDString];
[Parse enableLocalDatastore];
[Parse setApplicationId:applicationId clientKey:@"b"];
PFObject *object = [PFObject objectWithClassName:@"TestObject"];
object[@"yolo"] = @"yarr";
XCTAssertTrue([object pin]);
// We are using the same directory on OSX, so this check is irrelevant
#if TARGET_OS_IPHONE
[self assertDirectoryDoesntExist:[containerPath stringByAppendingPathComponent:@"Parse"]];
#endif
[[Parse _currentManager] clearEventuallyQueue];
[Parse _clearCurrentManager];
[Parse _resetDataSharingIdentifiers];
_testHelper.swizzledGroupContainerDirectoryPath = YES;
_testHelper.runningInExtensionEnvironment = NO;
[Parse enableLocalDatastore];
[Parse enableDataSharingWithApplicationGroupIdentifier:@"yolo"];
[Parse setApplicationId:applicationId clientKey:@"b"];
PFQuery *query = [[PFQuery queryWithClassName:@"TestObject"] fromLocalDatastore];
NSError *error = nil;
NSInteger count = [query countObjects:&error];
XCTAssertNil(error, @"%@", error);
XCTAssertEqual(1, count);
[self assertDirectory:containerPath hasContents:@{ @"Parse" :
@{ applicationId :
@{ @"applicationId" : [NSNull null],
@"ParseOfflineStore" : [NSNull null]
}
}
} only:NO];
}
- (void)testMigratingDataFromExtensionsSandbox {
NSString *containerPath = [PFExtensionDataSharingTestHelper sharedTestDirectoryPathForGroupIdentifier:@"yolo"];
NSString *applicationId = [[NSUUID UUID] UUIDString];
[Parse enableLocalDatastore];
[Parse setApplicationId:applicationId clientKey:@"b"];
PFObject *object = [PFObject objectWithClassName:@"TestObject"];
object[@"yolo"] = @"yarr";
XCTAssertTrue([object pin]);
// We are using the same directory on OSX, so this check is irrelevant
#if TARGET_OS_IPHONE
[self assertDirectoryDoesntExist:[containerPath stringByAppendingPathComponent:@"Parse"]];
#endif
[[Parse _currentManager] clearEventuallyQueue];
[Parse _clearCurrentManager];
[Parse _resetDataSharingIdentifiers];
_testHelper.swizzledGroupContainerDirectoryPath = YES;
_testHelper.runningInExtensionEnvironment = YES;
[Parse enableLocalDatastore];
[Parse enableDataSharingWithApplicationGroupIdentifier:@"yolo"
containingApplication:@"parentYolo"];
[Parse setApplicationId:applicationId clientKey:@"b"];
PFQuery *query = [[PFQuery queryWithClassName:@"TestObject"] fromLocalDatastore];
// We are using the same directory on OSX, but different folders on iOS.
NSError *error = nil;
NSInteger count = [query countObjects:&error];
XCTAssertNil(error, @"%@", error);
#if TARGET_OS_IPHONE
XCTAssertEqual(0, count);
#else
XCTAssertEqual(1, count);
#endif
[self assertDirectory:containerPath hasContents:@{ @"Parse" :
@{ applicationId :
@{ @"applicationId" : [NSNull null],
@"ParseOfflineStore" : [NSNull null]
}
}
} only:NO];
}
@end