forked from 0xced/XCDYouTubeKit
-
Notifications
You must be signed in to change notification settings - Fork 0
/
XCDYouTubeVideoPlayerViewControllerTestCase.m
106 lines (93 loc) · 5.02 KB
/
XCDYouTubeVideoPlayerViewControllerTestCase.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
//
// Copyright (c) 2013-2016 Cédric Luthi. All rights reserved.
//
#import "XCDYouTubeKitTestCase.h"
#import <XCDYouTubeKit/XCDYouTubeClient.h>
#import <XCDYouTubeKit/XCDYouTubeVideoPlayerViewController.h>
#import <XCDYouTubeKit/XCDYouTubeError.h>
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
@interface XCDYouTubeVideoPlayerViewControllerTestCase : XCDYouTubeKitTestCase
@end
@implementation XCDYouTubeVideoPlayerViewControllerTestCase
- (void) testWrongInitializer
{
XCTAssertThrowsSpecificNamed([[XCDYouTubeVideoPlayerViewController alloc] initWithContentURL:nil], NSException, NSGenericException);
}
- (void) testAPIMisuseException
{
#if defined(DEBUG) && DEBUG
__weak XCTestExpectation *expectation = [self expectationWithDescription:@""];
[[XCDYouTubeClient defaultClient] getVideoWithIdentifier:@"6v2L2UGZJAM" completionHandler:^(XCDYouTubeVideo *video, NSError *error) {
XCTAssertThrowsSpecificNamed([[XCDYouTubeVideoPlayerViewController alloc] initWithVideoIdentifier:@"6v2L2UGZJAM"], NSException, NSGenericException);
[expectation fulfill];
}];
[self waitForExpectationsWithTimeout:5 handler:nil];
#endif
}
- (void) testVideoNotification
{
__weak XCTestExpectation *expectation = [self expectationWithDescription:@""];
XCDYouTubeVideoPlayerViewController *videoPlayerViewController = [[XCDYouTubeVideoPlayerViewController alloc] initWithVideoIdentifier:@"6v2L2UGZJAM"];
[[NSNotificationCenter defaultCenter] addObserverForName:XCDYouTubeVideoPlayerViewControllerDidReceiveVideoNotification object:videoPlayerViewController queue:nil usingBlock:^(NSNotification *notification)
{
XCTAssertNotNil(notification.userInfo[XCDYouTubeVideoUserInfoKey]);
[expectation fulfill];
}];
[self waitForExpectationsWithTimeout:5 handler:nil];
}
- (void) testAsynchronousVideoNotification
{
__weak XCTestExpectation *expectation = [self expectationWithDescription:@""];
XCDYouTubeVideoPlayerViewController *videoPlayerViewController = [XCDYouTubeVideoPlayerViewController new];
[[NSOperationQueue mainQueue] addOperationWithBlock:^{
videoPlayerViewController.videoIdentifier = @"6v2L2UGZJAM";
}];
[[NSNotificationCenter defaultCenter] addObserverForName:XCDYouTubeVideoPlayerViewControllerDidReceiveVideoNotification object:videoPlayerViewController queue:nil usingBlock:^(NSNotification *notification)
{
XCTAssertNotNil(notification.userInfo[XCDYouTubeVideoUserInfoKey]);
[expectation fulfill];
}];
[self waitForExpectationsWithTimeout:5 handler:nil];
}
- (void) testNoStreamAvailableErrorNotification
{
__weak XCTestExpectation *expectation = [self expectationWithDescription:@""];
XCDYouTubeVideoPlayerViewController *videoPlayerViewController = [[XCDYouTubeVideoPlayerViewController alloc] initWithVideoIdentifier:@"6v2L2UGZJAM"];
videoPlayerViewController.preferredVideoQualities = @[];
[[NSNotificationCenter defaultCenter] addObserverForName:MPMoviePlayerPlaybackDidFinishNotification object:videoPlayerViewController.moviePlayer queue:nil usingBlock:^(NSNotification *notification)
{
NSError *error = notification.userInfo[XCDMoviePlayerPlaybackDidFinishErrorUserInfoKey];
MPMovieFinishReason finishReason = [notification.userInfo[MPMoviePlayerPlaybackDidFinishReasonUserInfoKey] integerValue];
XCTAssertEqual(finishReason, MPMovieFinishReasonPlaybackError);
XCTAssertEqualObjects(error.domain, XCDYouTubeVideoErrorDomain);
XCTAssertEqual(error.code, XCDYouTubeErrorNoStreamAvailable);
[expectation fulfill];
}];
[self waitForExpectationsWithTimeout:5 handler:nil];
}
- (void) testRestrictedPlaybackErrorNotification
{
__weak XCTestExpectation *expectation = [self expectationWithDescription:@""];
XCDYouTubeVideoPlayerViewController *videoPlayerViewController = [[XCDYouTubeVideoPlayerViewController alloc] initWithVideoIdentifier:@"1kIsylLeHHU"];
[[NSNotificationCenter defaultCenter] addObserverForName:MPMoviePlayerPlaybackDidFinishNotification object:videoPlayerViewController.moviePlayer queue:nil usingBlock:^(NSNotification *notification)
{
NSError *error = notification.userInfo[XCDMoviePlayerPlaybackDidFinishErrorUserInfoKey];
MPMovieFinishReason finishReason = [notification.userInfo[MPMoviePlayerPlaybackDidFinishReasonUserInfoKey] integerValue];
XCTAssertEqual(finishReason, MPMovieFinishReasonPlaybackError);
XCTAssertEqualObjects(error.domain, XCDYouTubeVideoErrorDomain);
XCTAssertEqual(error.code, XCDYouTubeErrorNoStreamAvailable);
[expectation fulfill];
}];
[self waitForExpectationsWithTimeout:5 handler:nil];
}
- (void) testPresentInView
{
UIView *view = [UIView new];
XCDYouTubeVideoPlayerViewController *videoPlayerViewController = [[XCDYouTubeVideoPlayerViewController alloc] initWithVideoIdentifier:@"EdeVaT-zZt4"];
XCTAssertNil(videoPlayerViewController.moviePlayer.view.superview);
[videoPlayerViewController presentInView:view];
XCTAssertEqualObjects(videoPlayerViewController.moviePlayer.view.superview, view);
XCTAssertEqual(videoPlayerViewController.moviePlayer.controlStyle, MPMovieControlStyleEmbedded);
XCTAssertFalse(videoPlayerViewController.moviePlayer.currentPlaybackRate > 0.0f);
}
@end