-
Notifications
You must be signed in to change notification settings - Fork 110
/
SDLLockScreenManagerSpec.m
465 lines (364 loc) 路 22.7 KB
/
SDLLockScreenManagerSpec.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
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
#import <Quick/Quick.h>
#import <Nimble/Nimble.h>
#import <OCMock/OCMock.h>
#import "SDLFakeViewControllerPresenter.h"
#import "SDLLockScreenConfiguration.h"
#import "SDLLockScreenManager.h"
#import "SDLLockScreenStatus.h"
#import "SDLLockScreenViewController.h"
#import "SDLNotificationConstants.h"
#import "SDLNotificationDispatcher.h"
#import "SDLOnLockScreenStatus.h"
#import "SDLOnDriverDistraction.h"
#import "SDLRPCNotificationNotification.h"
@interface SDLLockScreenManager ()
@property (assign, nonatomic) BOOL canPresent;
@property (strong, nonatomic, readwrite) SDLLockScreenConfiguration *config;
@property (strong, nonatomic) id<SDLViewControllerPresentable> presenter;
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
@property (strong, nonatomic, nullable) SDLOnLockScreenStatus *lastLockNotification;
#pragma clang diagnostic pop
@property (strong, nonatomic, nullable) SDLOnDriverDistraction *lastDriverDistractionNotification;
@property (assign, nonatomic, readwrite, getter=isLockScreenDismissable) BOOL lockScreenDismissable;
@property (assign, nonatomic) BOOL lockScreenDismissedByUser;
@end
QuickSpecBegin(SDLLockScreenManagerSpec)
describe(@"a lock screen manager", ^{
__block SDLLockScreenManager *testManager = nil;
__block SDLFakeViewControllerPresenter *fakePresenter = nil;
__block SDLNotificationDispatcher *testNotificationDispatcher = nil;
beforeEach(^{
fakePresenter = [[SDLFakeViewControllerPresenter alloc] init];
});
context(@"with a disabled configuration", ^{
beforeEach(^{
testManager = [[SDLLockScreenManager alloc] initWithConfiguration:[SDLLockScreenConfiguration disabledConfiguration] notificationDispatcher:nil presenter:fakePresenter];
});
it(@"should set properties correctly", ^{
// Note: We can't check the "lockScreenPresented" flag on the Lock Screen Manager because it's a computer property checking the window
expect(fakePresenter.shouldShowLockScreen).toEventually(beFalse());
expect(testManager.lockScreenViewController).to(beNil());
});
describe(@"after it is started", ^{
beforeEach(^{
[testManager start];
});
it(@"should not have a lock screen controller", ^{
expect(fakePresenter.shouldShowLockScreen).toEventually(beFalse());
expect(testManager.lockScreenViewController).to(beNil());
});
describe(@"when the lock screen status becomes REQUIRED", ^{
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
__block SDLOnLockScreenStatus *testRequiredStatus = nil;
beforeEach(^{
testRequiredStatus = [[SDLOnLockScreenStatus alloc] init];
testRequiredStatus.lockScreenStatus = SDLLockScreenStatusRequired;
[testNotificationDispatcher postNotificationName:SDLDidChangeLockScreenStatusNotification infoObject:testRequiredStatus];
#pragma clang diagnostic pop
});
it(@"should not have presented the lock screen", ^{
expect(fakePresenter.shouldShowLockScreen).toEventually(beFalse());
});
});
});
});
context(@"with an enabled configuration", ^{
beforeEach(^{
testManager = [[SDLLockScreenManager alloc] initWithConfiguration:[SDLLockScreenConfiguration enabledConfiguration] notificationDispatcher:nil presenter:fakePresenter];
});
it(@"should set properties correctly", ^{
expect(fakePresenter.shouldShowLockScreen).toEventually(beFalse());
expect(testManager.lockScreenViewController).to(beNil());
});
describe(@"after it's started", ^{
beforeEach(^{
[testManager start];
});
it(@"should set up the view controller correctly", ^{
expect(fakePresenter.shouldShowLockScreen).toEventually(beFalse());
expect(testManager.lockScreenViewController).toNot(beNil());
expect(testManager.lockScreenViewController).to(beAnInstanceOf([SDLLockScreenViewController class]));
});
describe(@"when the lock screen status becomes REQUIRED", ^{
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
__block SDLOnLockScreenStatus *testRequiredStatus = nil;
#pragma clang diagnostic pop
__block SDLOnDriverDistraction *testDriverDistraction = nil;
beforeEach(^{
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
testRequiredStatus = [[SDLOnLockScreenStatus alloc] init];
testRequiredStatus.lockScreenStatus = SDLLockScreenStatusRequired;
SDLRPCNotificationNotification *testLockStatusNotification = [[SDLRPCNotificationNotification alloc] initWithName:SDLDidChangeLockScreenStatusNotification object:nil rpcNotification:testRequiredStatus];
#pragma clang diagnostic pop
[[NSNotificationCenter defaultCenter] postNotification:testLockStatusNotification];
});
it(@"should have presented the lock screen", ^{
expect(fakePresenter.shouldShowLockScreen).toEventually(beTrue());
});
it(@"should not have a vehicle icon", ^{
expect(((SDLLockScreenViewController *)testManager.lockScreenViewController).vehicleIcon).to(beNil());
});
describe(@"when a vehicle icon is received", ^{
__block UIImage *testIcon = nil;
beforeEach(^{
testIcon = [UIImage imageNamed:@"testImagePNG" inBundle:[NSBundle bundleForClass:self.class] compatibleWithTraitCollection:nil];
[[NSNotificationCenter defaultCenter] postNotificationName:SDLDidReceiveLockScreenIcon object:nil userInfo:@{ SDLNotificationUserInfoObject: testIcon }];
});
it(@"should have a vehicle icon", ^{
expect(((SDLLockScreenViewController *)testManager.lockScreenViewController).vehicleIcon).toNot(beNil());
expect(((SDLLockScreenViewController *)testManager.lockScreenViewController).vehicleIcon).to(equal(testIcon));
});
});
describe(@"when a driver distraction notification is posted with lockScreenDismissableEnabled as true", ^{
__block SDLRPCNotificationNotification *testDriverDistractionNotification = nil;
beforeEach(^{
testDriverDistraction = [[SDLOnDriverDistraction alloc] init];
testDriverDistraction.lockScreenDismissalEnabled = @YES;
testDriverDistractionNotification = [[SDLRPCNotificationNotification alloc] initWithName:SDLDidChangeDriverDistractionStateNotification object:nil rpcNotification:testDriverDistraction];
[[NSNotificationCenter defaultCenter] postNotification:testDriverDistractionNotification];
});
it(@"should be able to be dismissed", ^{
expect(testManager.isLockScreenDismissable).toEventually(equal(YES));
});
});
describe(@"when a driver distraction notification is posted with lockScreenDismissableEnabled as false", ^{
__block SDLRPCNotificationNotification *testDriverDistractionNotification = nil;
beforeEach(^{
testDriverDistraction = [[SDLOnDriverDistraction alloc] init];
testDriverDistraction.lockScreenDismissalEnabled = @0;
testDriverDistractionNotification = [[SDLRPCNotificationNotification alloc] initWithName:SDLDidChangeDriverDistractionStateNotification object:nil rpcNotification:testDriverDistraction];
[[NSNotificationCenter defaultCenter] postNotification:testDriverDistractionNotification];
});
it(@"should not be able to be dismissed", ^{
expect(testManager.isLockScreenDismissable).toEventually(equal(NO));
});
});
describe(@"when a driver distraction notification is posted with lockScreenDismissableEnabled nil bit", ^{
__block SDLRPCNotificationNotification *testDriverDistractionNotification = nil;
beforeEach(^{
testDriverDistraction = [[SDLOnDriverDistraction alloc] init];
testDriverDistractionNotification = [[SDLRPCNotificationNotification alloc] initWithName:SDLDidChangeDriverDistractionStateNotification object:nil rpcNotification:testDriverDistraction];
[[NSNotificationCenter defaultCenter] postNotification:testDriverDistractionNotification];
});
it(@"should not be able to be dismissed", ^{
expect(testManager.isLockScreenDismissable).toEventually(equal(NO));
});
});
describe(@"then the manager is stopped", ^{
beforeEach(^{
[testManager stop];
});
it(@"should have dismissed the lock screen", ^{
expect(fakePresenter.shouldShowLockScreen).toEventually(beFalse());
});
});
describe(@"then the status becomes OFF", ^{
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
__block SDLOnLockScreenStatus *testOffStatus = nil;
beforeEach(^{
testOffStatus = [[SDLOnLockScreenStatus alloc] init];
testOffStatus.lockScreenStatus = SDLLockScreenStatusOff;
SDLRPCNotificationNotification *testLockStatusNotification = [[SDLRPCNotificationNotification alloc] initWithName:SDLDidChangeLockScreenStatusNotification object:nil rpcNotification:testOffStatus];
#pragma clang diagnostic pop
[[NSNotificationCenter defaultCenter] postNotification:testLockStatusNotification];
});
it(@"should have dismissed the lock screen", ^{
expect(fakePresenter.shouldShowLockScreen).toEventually(beFalse());
});
});
});
});
});
context(@"with showDeviceLogo as NO", ^{
beforeEach(^{
SDLLockScreenConfiguration *config = [SDLLockScreenConfiguration enabledConfiguration];
config.showDeviceLogo = NO;
testManager = [[SDLLockScreenManager alloc] initWithConfiguration:config notificationDispatcher:nil presenter:fakePresenter];
[testManager start];
});
describe(@"when a vehicle icon is received", ^{
__block UIImage *testIcon = nil;
beforeEach(^{
testIcon = [UIImage imageNamed:@"testImagePNG" inBundle:[NSBundle bundleForClass:self.class] compatibleWithTraitCollection:nil];
[[NSNotificationCenter defaultCenter] postNotificationName:SDLDidReceiveLockScreenIcon object:nil userInfo:@{ SDLNotificationUserInfoObject: testIcon }];
});
it(@"should not have a vehicle icon if showDeviceLogo is set to NO", ^{
expect(((SDLLockScreenViewController *)testManager.lockScreenViewController).vehicleIcon).to(beNil());
});
});
});
context(@"with a custom color configuration", ^{
__block UIColor *testColor = nil;
__block UIImage *testImage = nil;
beforeEach(^{
testColor = [UIColor blueColor];
testImage = [UIImage imageNamed:@"testImagePNG" inBundle:[NSBundle bundleForClass:self.class] compatibleWithTraitCollection:nil];
testManager = [[SDLLockScreenManager alloc] initWithConfiguration:[SDLLockScreenConfiguration enabledConfigurationWithAppIcon:testImage backgroundColor:testColor] notificationDispatcher:nil presenter:fakePresenter];
});
it(@"should set properties correctly", ^{
expect(fakePresenter.shouldShowLockScreen).toEventually(beFalse());
expect(testManager.lockScreenViewController).to(beNil());
});
describe(@"after it's started", ^{
beforeEach(^{
[testManager start];
});
it(@"should set up the view controller correctly", ^{
expect(fakePresenter.shouldShowLockScreen).toEventually(beFalse());
expect(testManager.lockScreenViewController).toNot(beNil());
expect(testManager.lockScreenViewController).to(beAnInstanceOf([SDLLockScreenViewController class]));
expect(((SDLLockScreenViewController *)testManager.lockScreenViewController).backgroundColor).to(equal(testColor));
expect(((SDLLockScreenViewController *)testManager.lockScreenViewController).appIcon).to(equal(testImage));
});
});
});
context(@"with a custom view controller configuration", ^{
__block UIViewController *testViewController = nil;
beforeEach(^{
testViewController = [[UIViewController alloc] init];
testManager = [[SDLLockScreenManager alloc] initWithConfiguration:[SDLLockScreenConfiguration enabledConfigurationWithViewController:testViewController] notificationDispatcher:nil presenter:fakePresenter];
});
it(@"should set properties correctly", ^{
expect(fakePresenter.shouldShowLockScreen).toEventually(beFalse());
expect(testManager.lockScreenViewController).to(beNil());
});
describe(@"after it's started", ^{
beforeEach(^{
[testManager start];
});
it(@"should set up the view controller correctly", ^{
expect(fakePresenter.shouldShowLockScreen).toEventually(beFalse());
expect(testManager.lockScreenViewController).toNot(beNil());
expect(testManager.lockScreenViewController).toNot(beAnInstanceOf([SDLLockScreenViewController class]));
expect(testManager.lockScreenViewController).to(equal(testViewController));
});
});
});
context(@"with a dismissable false configuration", ^{
beforeEach(^{
SDLLockScreenConfiguration *config = [SDLLockScreenConfiguration enabledConfiguration];
config.enableDismissGesture = NO;
testManager = [[SDLLockScreenManager alloc] initWithConfiguration:config notificationDispatcher:nil presenter:fakePresenter];
[testManager start];
});
describe(@"when a driver distraction notification is posted with lockScreenDismissableEnabled as true", ^{
__block SDLRPCNotificationNotification *testDriverDistractionNotification = nil;
beforeEach(^{
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
SDLOnLockScreenStatus *status = [[SDLOnLockScreenStatus alloc] init];
status.lockScreenStatus = SDLLockScreenStatusRequired;
#pragma clang diagnostic pop
testManager.lastLockNotification = status;
SDLOnDriverDistraction *testDriverDistraction = [[SDLOnDriverDistraction alloc] init];
testDriverDistraction.lockScreenDismissalEnabled = @YES;
testDriverDistractionNotification = [[SDLRPCNotificationNotification alloc] initWithName:SDLDidChangeDriverDistractionStateNotification object:nil rpcNotification:testDriverDistraction];
[[NSNotificationCenter defaultCenter] postNotification:testDriverDistractionNotification];
});
it(@"should not be able to be dismissed", ^{
expect(testManager.isLockScreenDismissable).toEventually(equal(NO));
});
});
});
describe(@"with an always enabled configuration", ^{
__block SDLFakeViewControllerPresenter *fakePresenter = nil;
__block SDLRPCNotificationNotification *testLockStatusNotification = nil;
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
__block SDLOnLockScreenStatus *testStatus = nil;
#pragma clang diagnostic pop
beforeEach(^{
fakePresenter = [[SDLFakeViewControllerPresenter alloc] init];
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
testStatus = [[SDLOnLockScreenStatus alloc] init];
#pragma clang diagnostic pop
SDLLockScreenConfiguration *config = [SDLLockScreenConfiguration enabledConfiguration];
config.displayMode = SDLLockScreenConfigurationDisplayModeAlways;
testManager = [[SDLLockScreenManager alloc] initWithConfiguration:config notificationDispatcher:nil presenter:fakePresenter];
[testManager start];
});
context(@"receiving a lock screen status of required", ^{
beforeEach(^{
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
testStatus.lockScreenStatus = SDLLockScreenStatusRequired;
testLockStatusNotification = [[SDLRPCNotificationNotification alloc] initWithName:SDLDidChangeLockScreenStatusNotification object:nil rpcNotification:testStatus];
#pragma clang diagnostic pop
[[NSNotificationCenter defaultCenter] postNotification:testLockStatusNotification];
});
it(@"should present the lock screen if not already presented", ^{
expect(fakePresenter.shouldShowLockScreen).toEventually(beTrue());
});
});
context(@"receiving a lock screen status of off", ^{
beforeEach(^{
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
testStatus.lockScreenStatus = SDLLockScreenStatusOff;
testLockStatusNotification = [[SDLRPCNotificationNotification alloc] initWithName:SDLDidChangeLockScreenStatusNotification object:nil rpcNotification:testStatus];
#pragma clang diagnostic pop
[[NSNotificationCenter defaultCenter] postNotification:testLockStatusNotification];
});
it(@"should present the lock screen if not already presented", ^{
expect(fakePresenter.shouldShowLockScreen).toEventually(beTrue());
});
});
});
describe(@"A lock screen status of OPTIONAL", ^{
__block SDLLockScreenManager *testLockScreenManager = nil;
__block SDLLockScreenConfiguration *testLockScreenConfig = nil;
__block id mockViewControllerPresenter = nil;
__block SDLRPCNotificationNotification *testLockStatusNotification = nil;
beforeEach(^{
mockViewControllerPresenter = OCMClassMock([SDLFakeViewControllerPresenter class]);
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
SDLOnLockScreenStatus *testOptionalStatus = [[SDLOnLockScreenStatus alloc] init];
testOptionalStatus.lockScreenStatus = SDLLockScreenStatusOptional;
testLockStatusNotification = [[SDLRPCNotificationNotification alloc] initWithName:SDLDidChangeLockScreenStatusNotification object:nil rpcNotification:testOptionalStatus];
#pragma clang diagnostic pop
testLockScreenConfig = [SDLLockScreenConfiguration enabledConfiguration];
});
context(@"showInOptionalState is true", ^{
beforeEach(^{
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
testLockScreenConfig.showInOptionalState = true;
#pragma clang diagnostic pop
testLockScreenManager = [[SDLLockScreenManager alloc] initWithConfiguration:testLockScreenConfig notificationDispatcher:nil presenter:mockViewControllerPresenter];
[testLockScreenManager start]; // Sets `canPresent` to `true`
});
it(@"should present the lock screen if not already presented", ^{
OCMStub([mockViewControllerPresenter lockViewController]).andReturn([OCMArg any]);
[[NSNotificationCenter defaultCenter] postNotification:testLockStatusNotification];
// Since lock screen must be presented/dismissed on the main thread, force the test to execute manually on the main thread. If this is not done, the test case may fail.
[[NSRunLoop mainRunLoop] runUntilDate:[NSDate dateWithTimeIntervalSinceNow:0.01]];
OCMVerify([mockViewControllerPresenter updateLockScreenToShow:YES withCompletionHandler:nil]);
});
});
context(@"showInOptionalState is false", ^{
beforeEach(^{
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
testLockScreenConfig.showInOptionalState = false;
#pragma clang diagnostic pop
testLockScreenManager = [[SDLLockScreenManager alloc] initWithConfiguration:testLockScreenConfig notificationDispatcher:nil presenter:mockViewControllerPresenter];
[testLockScreenManager start]; // Sets `canPresent` to `true`
});
it(@"should dismiss the lock screen if already presented", ^{
OCMStub([mockViewControllerPresenter lockViewController]).andReturn([OCMArg any]);
[[NSNotificationCenter defaultCenter] postNotification:testLockStatusNotification];
// Since lock screen must be presented/dismissed on the main thread, force the test to execute manually on the main thread. If this is not done, the test case may fail.
[[NSRunLoop mainRunLoop] runUntilDate:[NSDate dateWithTimeIntervalSinceNow:0.01]];
OCMVerify([mockViewControllerPresenter updateLockScreenToShow:NO withCompletionHandler:nil]);
});
});
});
});
QuickSpecEnd