Skip to content
This repository was archived by the owner on Feb 2, 2023. It is now read-only.

Commit 901a8fb

Browse files
committed
fixed video tests
1 parent 42efde3 commit 901a8fb

2 files changed

Lines changed: 22 additions & 38 deletions

File tree

AsyncDisplayKit/ASVideoNode.mm

Lines changed: 5 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -139,31 +139,6 @@ - (void)fetchData
139139
}
140140
}
141141

142-
//- (void)fetchData
143-
//{
144-
// [super fetchData];
145-
//
146-
// @try {
147-
// [_currentItem removeObserver:self forKeyPath:NSStringFromSelector(@selector(status))];
148-
// }
149-
// @catch (NSException * __unused exception) {
150-
// NSLog(@"unnecessary removal in fetch data");
151-
// }
152-
//
153-
// {
154-
// ASDN::MutexLocker l(_lock);
155-
//
156-
// _currentItem = [[AVPlayerItem alloc] initWithAsset:_asset];
157-
// [_currentItem addObserver:self forKeyPath:NSStringFromSelector(@selector(status)) options:NSKeyValueObservingOptionInitial | NSKeyValueObservingOptionNew context:NULL];
158-
//
159-
// [((AVPlayerLayer *)_playerNode.layer).player replaceCurrentItemWithPlayerItem:_currentItem];
160-
// }
161-
//
162-
// if (_shouldAutoPlay) {
163-
// [self play];
164-
// }
165-
//}
166-
167142
- (void)clearFetchedData
168143
{
169144
[super clearFetchedData];
@@ -281,6 +256,11 @@ - (void)pause;
281256
_playButton.alpha = 1.0;
282257
}
283258

259+
- (AVPlayerItem *)currentItem
260+
{
261+
return _currentItem;
262+
}
263+
284264
- (void)dealloc
285265
{
286266
[[NSNotificationCenter defaultCenter] removeObserver:self];

AsyncDisplayKitTests/ASVideoNodeTests.m

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -11,35 +11,39 @@
1111
#import "ASVideoNode.h"
1212

1313
@interface ASVideoNodeTests : XCTestCase
14+
@end
1415

16+
@interface ASVideoNode ()
17+
@property (atomic, readonly) AVPlayerItem *currentItem;
18+
@property (atomic) ASInterfaceState interfaceState;
1519
@end
1620

1721
@implementation ASVideoNodeTests
1822

19-
- (void)testVideoNodeReplacesAVPlayerWhenNewURLIsSet {
23+
- (void)testVideoNodeReplacesAVPlayerItemWhenNewURLIsSet {
2024
ASVideoNode *videoNode = [[ASVideoNode alloc] init];
25+
videoNode.interfaceState = ASInterfaceStateFetchData;
2126
videoNode.asset = [AVAsset assetWithURL:[NSURL URLWithString:@"firstURL"]];
22-
[videoNode fetchData];
23-
AVPlayer *player = ((AVPlayerLayer *)videoNode.layer).player;
27+
28+
AVPlayerItem *item = [videoNode currentItem];
2429

2530
videoNode.asset = [AVAsset assetWithURL:[NSURL URLWithString:@"secondURL"]];
26-
[videoNode fetchData];
27-
AVPlayer *secondPlayer = ((AVPlayerLayer *)videoNode.layer).player;
28-
29-
XCTAssertNotEqualObjects(player, secondPlayer);
31+
AVPlayerItem *secondItem = [videoNode currentItem];
32+
33+
XCTAssertNotEqualObjects(item, secondItem);
3034
}
3135

32-
- (void)testVideoNodeDoesNotMakeNewPlayerWhenURLIsTheSame {
36+
- (void)testVideoNodeDoesNotReplaceAVPlayerItemWhenSameURLIsSet {
3337
ASVideoNode *videoNode = [[ASVideoNode alloc] init];
38+
videoNode.interfaceState = ASInterfaceStateFetchData;
39+
3440
videoNode.asset = [AVAsset assetWithURL:[NSURL URLWithString:@"firstURL"]];
35-
[videoNode fetchData];
41+
AVPlayerItem *item = [videoNode currentItem];
3642

37-
AVPlayer *firstPlayer = ((AVPlayerLayer *)videoNode.layer).player;
3843
videoNode.asset = [AVAsset assetWithURL:[NSURL URLWithString:@"firstURL"]];
39-
40-
AVPlayer *secondPlayer = ((AVPlayerLayer *)videoNode.layer).player;
44+
AVPlayerItem *secondItem = [videoNode currentItem];
4145

42-
XCTAssertEqualObjects(firstPlayer, secondPlayer);
46+
XCTAssertEqualObjects(item, secondItem);
4347
}
4448

4549
@end

0 commit comments

Comments
 (0)