diff --git a/XCDYouTubeKit Tests/XCDYouTubeClientTestCase.m b/XCDYouTubeKit Tests/XCDYouTubeClientTestCase.m index 2f46546a..dd0b9a99 100644 --- a/XCDYouTubeKit Tests/XCDYouTubeClientTestCase.m +++ b/XCDYouTubeKit Tests/XCDYouTubeClientTestCase.m @@ -9,6 +9,8 @@ #import #import +NSTimeInterval kDefaultNetworkTimeout = 5; + @interface XCDYouTubeClientTestCase : XCDYouTubeKitTestCase @end @@ -23,7 +25,7 @@ - (void) testThatVideoIsAvailalbeOnDetailPageEventLabel XCTAssertNotNil(video); [expectation fulfill]; }]; - [self waitForExpectationsWithTimeout:5 handler:nil]; + [self waitForExpectationsWithTimeout:kDefaultNetworkTimeout handler:nil]; } - (void) testThatVideoHasMetadata @@ -42,7 +44,7 @@ - (void) testThatVideoHasMetadata XCTAssertTrue(video.duration > 0); [expectation fulfill]; }]; - [self waitForExpectationsWithTimeout:5 handler:nil]; + [self waitForExpectationsWithTimeout:kDefaultNetworkTimeout handler:nil]; } #if TARGET_OS_OSX - (void) testThatThumbnailsAreOrderedCorrectly @@ -70,7 +72,7 @@ - (void) testThatThumbnailsAreOrderedCorrectly [expectation fulfill]; }]; - [self waitForExpectationsWithTimeout:5 handler:nil]; + [self waitForExpectationsWithTimeout:kDefaultNetworkTimeout handler:nil]; } #endif - (void) testThatVideoHasOtherStreams @@ -105,7 +107,7 @@ - (void) testThatVideoHasOtherStreams [expectation fulfill]; }]; - [self waitForExpectationsWithTimeout:5 handler:nil]; + [self waitForExpectationsWithTimeout:kDefaultNetworkTimeout handler:nil]; } - (void) testVideoThatHasCaptions @@ -120,7 +122,7 @@ - (void) testVideoThatHasCaptions XCTAssertNotEqual(video.autoGeneratedCaptionURLs[@"en"], video.captionURLs[@"en"]); [expectation fulfill]; }]; - [self waitForExpectationsWithTimeout:5 handler:nil]; + [self waitForExpectationsWithTimeout:kDefaultNetworkTimeout handler:nil]; } @@ -133,7 +135,7 @@ - (void)testVideoWithDashManifest XCTAssertNotNil(video.streamURLs[@299], @"Could not find Dash video 299 in `streamURLs`"); //itag=299: {'ext': 'mp4', 'height': 1080, 'format_note': 'DASH video', 'vcodec': 'h264', 'fps': 60} [expectation fulfill]; }]; - [self waitForExpectationsWithTimeout:5 handler:nil]; + [self waitForExpectationsWithTimeout:kDefaultNetworkTimeout handler:nil]; } //See -[XCDYouTubeVideoOperation handleConnectionError:requestType] @@ -147,7 +149,7 @@ - (void)testConnectionErrorWithDashManifest [expectation fulfill]; }]; - [self waitForExpectationsWithTimeout:5 handler:nil]; + [self waitForExpectationsWithTimeout:kDefaultNetworkTimeout handler:nil]; } - (void) testVideoWithUndeterminedCaptionLanguageCode @@ -161,7 +163,7 @@ - (void) testVideoWithUndeterminedCaptionLanguageCode XCTAssertNotNil(video.captionURLs); [expectation fulfill]; }]; - [self waitForExpectationsWithTimeout:5 handler:nil]; + [self waitForExpectationsWithTimeout:kDefaultNetworkTimeout handler:nil]; } @@ -182,7 +184,7 @@ - (void) testMobileRestrictedVideo }]; [expectation fulfill]; }]; - [self waitForExpectationsWithTimeout:5 handler:nil]; + [self waitForExpectationsWithTimeout:kDefaultNetworkTimeout handler:nil]; } - (void) testLiveVideo @@ -197,7 +199,7 @@ - (void) testLiveVideo XCTAssertNotNil(video.streamURLs[XCDYouTubeVideoQualityHTTPLiveStreaming]); [expectation fulfill]; }]; - [self waitForExpectationsWithTimeout:5 handler:nil]; + [self waitForExpectationsWithTimeout:kDefaultNetworkTimeout handler:nil]; } // Test for https://github.com/0xced/XCDYouTubeKit/issues/420 @@ -218,7 +220,7 @@ - (void) testVideo1 }]; [expectation fulfill]; }]; - [self waitForExpectationsWithTimeout:5 handler:nil]; + [self waitForExpectationsWithTimeout:kDefaultNetworkTimeout handler:nil]; } - (void) testVideo2 @@ -264,7 +266,7 @@ - (void) testVideo1IsPlayable }]; [dataTask resume]; }]; - [self waitForExpectationsWithTimeout:5 handler:nil]; + [self waitForExpectationsWithTimeout:kDefaultNetworkTimeout handler:nil]; } - (void) testVideo1ReturnsSomePlayableStreams @@ -303,7 +305,7 @@ - (void) testVideo1ReturnsSomePlayableStreams }]; }]; - [self waitForExpectationsWithTimeout:5 handler:nil]; + [self waitForExpectationsWithTimeout:kDefaultNetworkTimeout handler:nil]; } // Disable internet connection before running to allow some queries to fail @@ -339,7 +341,7 @@ - (void) testVideo1ReturnsSomePlayableStreamsEvenIfSomeFailDueToConnectionError_ }]; }]; - [self waitForExpectationsWithTimeout:5 handler:nil]; + [self waitForExpectationsWithTimeout:kDefaultNetworkTimeout handler:nil]; } // Disable internet connection before running to allow all queries to fail @@ -369,7 +371,7 @@ - (void) testVideo1ReturnsNoPlayableStreamsBecauseConnectionError_offline }]; }]; - [self waitForExpectationsWithTimeout:5 handler:nil]; + [self waitForExpectationsWithTimeout:kDefaultNetworkTimeout handler:nil]; } - (void) testVideo2ReturnsAllPlayableStreams @@ -398,7 +400,7 @@ - (void) testVideo2ReturnsAllPlayableStreams }]; }]; - [self waitForExpectationsWithTimeout:5 handler:nil]; + [self waitForExpectationsWithTimeout:kDefaultNetworkTimeout handler:nil]; } - (void) testVideo3ReturnsSomePlayableStreams @@ -439,7 +441,7 @@ - (void) testVideo3ReturnsSomePlayableStreams }]; }]; - [self waitForExpectationsWithTimeout:5 handler:nil]; + [self waitForExpectationsWithTimeout:kDefaultNetworkTimeout handler:nil]; } - (void) testThatQueryingLiveVideoReturnsPlayableStreams @@ -471,7 +473,7 @@ - (void) testThatQueryingLiveVideoReturnsPlayableStreams }]; }]; - [self waitForExpectationsWithTimeout:5 handler:nil]; + [self waitForExpectationsWithTimeout:kDefaultNetworkTimeout handler:nil]; } - (void) testQueryingWithSpecifiedStreamURLs @@ -515,7 +517,7 @@ - (void) testQueryingWithSpecifiedStreamURLs }]; }]; - [self waitForExpectationsWithTimeout:5 handler:nil]; + [self waitForExpectationsWithTimeout:kDefaultNetworkTimeout handler:nil]; } - (void) testQueryingWithSpecifiedStreamURLsSomeNotBeingInVideoObject @@ -564,7 +566,7 @@ - (void) testQueryingWithSpecifiedStreamURLsSomeNotBeingInVideoObject }]; }]; - [self waitForExpectationsWithTimeout:5 handler:nil]; + [self waitForExpectationsWithTimeout:kDefaultNetworkTimeout handler:nil]; } - (void) testQueryingWhenNoSpecifiedURLsAreInVideoObject @@ -600,7 +602,7 @@ - (void) testQueryingWhenNoSpecifiedURLsAreInVideoObject }]; }]; - [self waitForExpectationsWithTimeout:5 handler:nil]; + [self waitForExpectationsWithTimeout:kDefaultNetworkTimeout handler:nil]; } -(void) testQueryingWhenSpecifiedURLsAreEmpty @@ -629,7 +631,7 @@ -(void) testQueryingWhenSpecifiedURLsAreEmpty }]; }]; - [self waitForExpectationsWithTimeout:5 handler:nil]; + [self waitForExpectationsWithTimeout:kDefaultNetworkTimeout handler:nil]; } - (void) testExpiredLiveVideo @@ -642,7 +644,7 @@ - (void) testExpiredLiveVideo XCTAssertEqualObjects(error.localizedDescription, @"This live stream recording is not available."); [expectation fulfill]; }]; - [self waitForExpectationsWithTimeout:5 handler:nil]; + [self waitForExpectationsWithTimeout:kDefaultNetworkTimeout handler:nil]; } - (void) testRestrictedVideo @@ -658,7 +660,7 @@ - (void) testRestrictedVideo XCTAssertEqualObjects(error.localizedDescription, @"This video is no longer available because the YouTube account associated with this video has been terminated."); [expectation fulfill]; }]; - [self waitForExpectationsWithTimeout:5 handler:nil]; + [self waitForExpectationsWithTimeout:kDefaultNetworkTimeout handler:nil]; if (logLevel) setenv("XCDYouTubeKitLogLevel", logLevel, 1); @@ -680,7 +682,7 @@ - (void) testTooManyRequestsError XCTAssertEqualObjects(error.localizedDescription, @"The operation couldn’t be completed because too many requests were sent."); [expectation fulfill]; }]; - [self waitForExpectationsWithTimeout:5 handler:nil]; + [self waitForExpectationsWithTimeout:kDefaultNetworkTimeout handler:nil]; } - (void) testRemovedVideo @@ -694,7 +696,7 @@ - (void) testRemovedVideo XCTAssertEqualObjects(error.localizedDescription, @"This video is no longer available due to a copyright claim by Digital Rights Group Ltd."); [expectation fulfill]; }]; - [self waitForExpectationsWithTimeout:5 handler:nil]; + [self waitForExpectationsWithTimeout:kDefaultNetworkTimeout handler:nil]; } - (void) testGeoblockedVideo @@ -708,7 +710,7 @@ - (void) testGeoblockedVideo XCTAssertEqualObjects(error.localizedDescription, @"The uploader has not made this video available in your country."); [expectation fulfill]; }]; - [self waitForExpectationsWithTimeout:5 handler:nil]; + [self waitForExpectationsWithTimeout:kDefaultNetworkTimeout handler:nil]; } - (void) testInvalidVideoIdentifier @@ -722,7 +724,7 @@ - (void) testInvalidVideoIdentifier XCTAssertEqualObjects(error.localizedDescription, @"Invalid parameters."); [expectation fulfill]; }]; - [self waitForExpectationsWithTimeout:5 handler:nil]; + [self waitForExpectationsWithTimeout:kDefaultNetworkTimeout handler:nil]; } - (void) testEmptyResponse_offline @@ -735,21 +737,24 @@ - (void) testEmptyResponse_offline XCTAssertEqual(error.code, XCDYouTubeErrorEmptyResponse); [expectation fulfill]; }]; - [self waitForExpectationsWithTimeout:5 handler:nil]; + [self waitForExpectationsWithTimeout:kDefaultNetworkTimeout handler:nil]; } - (void) testNonExistentVideoIdentifier { __weak XCTestExpectation *expectation = [self expectationWithDescription:@""]; + NSDate* date = [NSDate date]; [[XCDYouTubeClient defaultClient] getVideoWithIdentifier:@"xxxxxxxxxxx" completionHandler:^(XCDYouTubeVideo *video, NSError *error) { + NSTimeInterval timeInterval = [date timeIntervalSinceNow]; + NSLog(@"time interval %@", @(timeInterval)); XCTAssertNil(video); XCTAssertEqualObjects(error.domain, XCDYouTubeVideoErrorDomain); XCTAssertEqual(error.code, XCDYouTubeErrorNoStreamAvailable); XCTAssertEqualObjects(error.localizedDescription, @"Video unavailable"); [expectation fulfill]; }]; - [self waitForExpectationsWithTimeout:5 handler:nil]; + [self waitForExpectationsWithTimeout:10 handler:nil]; } - (void) testFrenchClient @@ -763,7 +768,7 @@ - (void) testFrenchClient XCTAssertEqualObjects(error.localizedDescription, @"Vidéo non disponible"); [expectation fulfill]; }]; - [self waitForExpectationsWithTimeout:5 handler:nil]; + [self waitForExpectationsWithTimeout:kDefaultNetworkTimeout handler:nil]; } - (void) testNilVideoIdentifier @@ -777,7 +782,7 @@ - (void) testNilVideoIdentifier XCTAssertEqualObjects(error.localizedDescription, @"Invalid parameters."); [expectation fulfill]; }]; - [self waitForExpectationsWithTimeout:5 handler:nil]; + [self waitForExpectationsWithTimeout:kDefaultNetworkTimeout handler:nil]; } - (void) testSpaceVideoIdentifier @@ -791,7 +796,7 @@ - (void) testSpaceVideoIdentifier XCTAssertEqualObjects(error.localizedDescription, @"Invalid parameters."); [expectation fulfill]; }]; - [self waitForExpectationsWithTimeout:5 handler:nil]; + [self waitForExpectationsWithTimeout:kDefaultNetworkTimeout handler:nil]; } // Disable internet connection before running @@ -809,12 +814,12 @@ - (void) testConnectionError_offline XCTAssertEqual(underlyingError.code, NSURLErrorNotConnectedToInternet); [expectation fulfill]; }]; - [self waitForExpectationsWithTimeout:5 handler:nil]; + [self waitForExpectationsWithTimeout:kDefaultNetworkTimeout handler:nil]; } - (void) testUsingClientOnNonMainThread { - __weak XCTestExpectation *expectation = [self expectationWithDescription:@""]; + __weak XCTestExpectation *expectation = [self expectationWithDescription:@"It should call back on main thread"]; dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{ XCTAssertFalse([NSThread isMainThread]); [[XCDYouTubeClient defaultClient] getVideoWithIdentifier:@"EdeVaT-zZt4" completionHandler:^(XCDYouTubeVideo *video, NSError *error) @@ -823,7 +828,20 @@ - (void) testUsingClientOnNonMainThread [expectation fulfill]; }]; }); - [self waitForExpectationsWithTimeout:5 handler:nil]; + + __weak XCTestExpectation *expectation2 = [self expectationWithDescription:@"It should call back on calling operation queue"]; + NSOperationQueue *queue = [[NSOperationQueue alloc] init]; + [queue addOperationWithBlock:^{ + XCTAssertFalse([NSThread isMainThread]); + [[XCDYouTubeClient defaultClient] getVideoWithIdentifier:@"EdeVaT-zZt4" completionHandler:^(XCDYouTubeVideo *video, NSError *error) + { + XCTAssertFalse([NSThread isMainThread]); + XCTAssertEqual(queue, [NSOperationQueue currentQueue]); + [expectation2 fulfill]; + }]; + }]; + + [self waitForExpectationsWithTimeout:kDefaultNetworkTimeout handler:nil]; } - (void) testCancelingOperation @@ -855,7 +873,7 @@ - (void) testCancelingOperationQueryOperation [expectation fulfill]; }]; - [self waitForExpectationsWithTimeout:5 handler:nil]; + [self waitForExpectationsWithTimeout:kDefaultNetworkTimeout handler:nil]; } - (void) testNilCompletionHandler diff --git a/XCDYouTubeKit Tests/XCDYouTubeKitTestCase.h b/XCDYouTubeKit Tests/XCDYouTubeKitTestCase.h index 532b8e31..6577b425 100644 --- a/XCDYouTubeKit Tests/XCDYouTubeKitTestCase.h +++ b/XCDYouTubeKit Tests/XCDYouTubeKitTestCase.h @@ -7,6 +7,8 @@ #import "VCR.h" #import "VCRCassetteManager.h" +extern NSTimeInterval kDefaultNetworkTimeout; + @interface XCDYouTubeKitTestCase : XCTestCase - (void) setUpTestWithSelector:(SEL)selector; @property NSArray*cookies; diff --git a/XCDYouTubeKit Tests/XCDYouTubeProtectedVideosTestCase.m b/XCDYouTubeKit Tests/XCDYouTubeProtectedVideosTestCase.m index ec2668af..1dae1e3b 100644 --- a/XCDYouTubeKit Tests/XCDYouTubeProtectedVideosTestCase.m +++ b/XCDYouTubeKit Tests/XCDYouTubeProtectedVideosTestCase.m @@ -62,7 +62,7 @@ - (void) testAgeRestrictedVideoThatRequiresCookiesWithUserCookies [expectation fulfill]; }]; - [self waitForExpectationsWithTimeout:5 handler:nil]; + [self waitForExpectationsWithTimeout:kDefaultNetworkTimeout handler:nil]; } - (void) testAgeRestrictedVideoThatRequiresCookiesWithUserCookiesIsPlayable @@ -88,7 +88,7 @@ - (void) testAgeRestrictedVideoThatRequiresCookiesWithUserCookiesIsPlayable [dataTask resume]; }]; - [self waitForExpectationsWithTimeout:5 handler:nil]; + [self waitForExpectationsWithTimeout:kDefaultNetworkTimeout handler:nil]; } - (void) testAgeRestrictedVideoThatRequiresCookiesWithoutCookies @@ -101,7 +101,7 @@ - (void) testAgeRestrictedVideoThatRequiresCookiesWithoutCookies [expectation fulfill]; }]; - [self waitForExpectationsWithTimeout:5 handler:nil]; + [self waitForExpectationsWithTimeout:kDefaultNetworkTimeout handler:nil]; } - (void) testAgeRestrictedVideo @@ -122,7 +122,7 @@ - (void) testAgeRestrictedVideo }]; [expectation fulfill]; }]; - [self waitForExpectationsWithTimeout:5 handler:nil]; + [self waitForExpectationsWithTimeout:kDefaultNetworkTimeout handler:nil]; } - (void) testAgeRestrictedUnratedVideo @@ -143,7 +143,7 @@ - (void) testAgeRestrictedUnratedVideo }]; [expectation fulfill]; }]; - [self waitForExpectationsWithTimeout:5 handler:nil]; + [self waitForExpectationsWithTimeout:kDefaultNetworkTimeout handler:nil]; } - (void) testProtectedVEVOVideoWithInvalidCustomPattern @@ -156,7 +156,7 @@ - (void) testProtectedVEVOVideoWithInvalidCustomPattern XCTAssertNil(video); [expectation fulfill]; }]; - [self waitForExpectationsWithTimeout:5 handler:nil]; + [self waitForExpectationsWithTimeout:kDefaultNetworkTimeout handler:nil]; } - (void) testProtectedVEVOVideoWithNilCustomPatternIsPlayable @@ -182,7 +182,7 @@ - (void) testProtectedVEVOVideoWithNilCustomPatternIsPlayable }]; [dataTask resume]; }]; - [self waitForExpectationsWithTimeout:5 handler:nil]; + [self waitForExpectationsWithTimeout:kDefaultNetworkTimeout handler:nil]; } - (void) testProtectedVEVOVideoWithEmptyCustomPatternIsPlayable @@ -208,7 +208,7 @@ - (void) testProtectedVEVOVideoWithEmptyCustomPatternIsPlayable }]; [dataTask resume]; }]; - [self waitForExpectationsWithTimeout:5 handler:nil]; + [self waitForExpectationsWithTimeout:kDefaultNetworkTimeout handler:nil]; } - (void) testProtectedVEVOVideoWithInvalidCustomPatternIsPlayable @@ -234,7 +234,7 @@ - (void) testProtectedVEVOVideoWithInvalidCustomPatternIsPlayable }]; [dataTask resume]; }]; - [self waitForExpectationsWithTimeout:5 handler:nil]; + [self waitForExpectationsWithTimeout:kDefaultNetworkTimeout handler:nil]; } - (void) testProtectedVEVOVideoWithValidCustomPatternIsPlayable @@ -260,7 +260,7 @@ - (void) testProtectedVEVOVideoWithValidCustomPatternIsPlayable }]; [dataTask resume]; }]; - [self waitForExpectationsWithTimeout:5 handler:nil]; + [self waitForExpectationsWithTimeout:kDefaultNetworkTimeout handler:nil]; } - (void) testProtectedVEVOVideo1 @@ -281,7 +281,7 @@ - (void) testProtectedVEVOVideo1 }]; [expectation fulfill]; }]; - [self waitForExpectationsWithTimeout:5 handler:nil]; + [self waitForExpectationsWithTimeout:kDefaultNetworkTimeout handler:nil]; } - (void) testProtectedVEVOVideo2 @@ -302,7 +302,7 @@ - (void) testProtectedVEVOVideo2 }]; [expectation fulfill]; }]; - [self waitForExpectationsWithTimeout:5 handler:nil]; + [self waitForExpectationsWithTimeout:kDefaultNetworkTimeout handler:nil]; } - (void) testProtectedVEVOVideo3 @@ -323,7 +323,7 @@ - (void) testProtectedVEVOVideo3 }]; [expectation fulfill]; }]; - [self waitForExpectationsWithTimeout:5 handler:nil]; + [self waitForExpectationsWithTimeout:kDefaultNetworkTimeout handler:nil]; } // See testAlternativeSignatureValue.xml for Charles Proxy Setting @@ -346,7 +346,7 @@ - (void) testAlternativeSignatureValue_offline }]; [expectation fulfill]; }]; - [self waitForExpectationsWithTimeout:5 handler:nil]; + [self waitForExpectationsWithTimeout:kDefaultNetworkTimeout handler:nil]; } - (void) testProtectedVEVOIsPlayable @@ -370,7 +370,7 @@ - (void) testProtectedVEVOIsPlayable }]; [dataTask resume]; }]; - [self waitForExpectationsWithTimeout:5 handler:nil]; + [self waitForExpectationsWithTimeout:kDefaultNetworkTimeout handler:nil]; } - (void) testDASHAudioWithRateBypassIsPlayable @@ -389,7 +389,7 @@ - (void) testDASHAudioWithRateBypassIsPlayable }]; [dataTask resume]; }]; - [self waitForExpectationsWithTimeout:5 handler:nil]; + [self waitForExpectationsWithTimeout:kDefaultNetworkTimeout handler:nil]; } - (void) testAgeRestrictedVEVOVideoWithUserCookies @@ -411,7 +411,7 @@ - (void) testAgeRestrictedVEVOVideoWithUserCookies [expectation fulfill]; }]; - [self waitForExpectationsWithTimeout:5 handler:nil]; + [self waitForExpectationsWithTimeout:kDefaultNetworkTimeout handler:nil]; } - (void) testAgeRestrictedVEVOVideoWithUserCookiesIsPlayable @@ -437,7 +437,7 @@ - (void) testAgeRestrictedVEVOVideoWithUserCookiesIsPlayable [dataTask resume]; }]; - [self waitForExpectationsWithTimeout:5 handler:nil]; + [self waitForExpectationsWithTimeout:kDefaultNetworkTimeout handler:nil]; } @@ -455,7 +455,7 @@ - (void) testProtectedVideoWithWebPageConnectionError_offline XCTAssertEqualObjects(error.localizedDescription, @"Video unavailable"); [expectation fulfill]; }]; - [self waitForExpectationsWithTimeout:5 handler:nil]; + [self waitForExpectationsWithTimeout:kDefaultNetworkTimeout handler:nil]; } // With Charles: Tools -> Black List... -> Add host:www.youtube.com and path:s/player/* to simulate connection error on the player script @@ -470,7 +470,7 @@ - (void) testProtectedVideoWithPlayerScriptConnectionError_offline XCTAssertEqualObjects(error.localizedDescription, @"Video unavailable"); [expectation fulfill]; }]; - [self waitForExpectationsWithTimeout:5 handler:nil]; + [self waitForExpectationsWithTimeout:kDefaultNetworkTimeout handler:nil]; } // Edit testProtectedVideoWithoutSignatureFunction.json by removing entire body for javascript URL and adding "XXXX" @@ -485,7 +485,7 @@ - (void) testProtectedVideoWithoutSignatureFunction_offline XCTAssertEqualObjects(error.localizedDescription, @"Video unavailable"); [expectation fulfill]; }]; - [self waitForExpectationsWithTimeout:5 handler:nil]; + [self waitForExpectationsWithTimeout:kDefaultNetworkTimeout handler:nil]; } // Disable (when replacing mutiple values the other values revert back to the original) @@ -500,7 +500,7 @@ - (void) _testProtectedVideoWithoutJavaScriptPlayerURL_offline XCTAssertEqualObjects(error.localizedDescription, @"Video unavailable"); [expectation fulfill]; }]; - [self waitForExpectationsWithTimeout:5 handler:nil]; + [self waitForExpectationsWithTimeout:kDefaultNetworkTimeout handler:nil]; } // Edit testProtectedVideoWithNonAnonymousJavaScriptPlayerFunction.json by replacing all `(function` with `(Xfunction` @@ -517,7 +517,7 @@ - (void) testProtectedVideoWithNonAnonymousJavaScriptPlayerFunction_offline XCTAssertEqualObjects(error.localizedDescription, @"Video unavailable"); [expectation fulfill]; }]; - [self waitForExpectationsWithTimeout:5 handler:nil]; + [self waitForExpectationsWithTimeout:kDefaultNetworkTimeout handler:nil]; } // With Charles: Tools -> Black List... -> Add host:www.youtube.com and path:embed/* to simulate connection error on the web page and replace and `jsUrl` with `jsXUrl` and ` 0 || alternativeAdaptiveFormats.count > 0)) - { - streamQueries = [NSMutableArray new]; - [streamQueries addObjectsFromArray:alternativeStreamMap]; - [streamQueries addObjectsFromArray:alternativeAdaptiveFormats]; - } - - NSString *title = info[@"title"] == nil? videoDetails[@"title"] : info[@"title"]; - if (title == nil) - title = @""; - _title = title; - - NSString *author = info[@"author"] == nil? videoDetails[@"author"] : info[@"author"]; - if (author == nil) - author = @""; - _author = author; - - NSString *channelIdentifier = info[@"ucid"] == nil? videoDetails[@"channelId"] : info[@"ucid"]; - if (channelIdentifier == nil) - channelIdentifier = @""; - _channelIdentifier = channelIdentifier; - - NSString *description = videoDetails[@"shortDescription"]; - if (description == nil) - description = @""; - _videoDescription = description; - - _viewCount = info[@"viewCount"] == nil? [(NSString *)videoDetails[@"viewCount"] integerValue] : [(NSString *)info[@"viewCount"] integerValue]; - - _duration = info[@"length_seconds"] == nil? [(NSString *)videoDetails[@"lengthSeconds"] doubleValue] : [(NSString *)info[@"length_seconds"] doubleValue]; + if (streamQueries == nil && (alternativeStreamMap.count > 0 || alternativeAdaptiveFormats.count > 0)) + { + streamQueries = [NSMutableArray new]; + [streamQueries addObjectsFromArray:alternativeStreamMap]; + [streamQueries addObjectsFromArray:alternativeAdaptiveFormats]; + } + + NSString *title = info[@"title"] ?: videoDetails[@"title"] ?: @""; + NSString *author = info[@"author"] ?: videoDetails[@"author"] ?: @""; + NSString *keywords = info[@"keywords"] ?: videoDetails[@"keywords"] ?: @""; + NSString *channelIdentifier = info[@"ucid"] ?: videoDetails[@"channelId"] ?: @""; + NSString *description = videoDetails[@"shortDescription"] ?: @""; + + if([keywords isKindOfClass:[NSArray class]]) { + keywords = [(NSArray*)keywords componentsJoinedByString:@","]; + } + _title = title; + _author = author; + _keywords = keywords; + _channelIdentifier = channelIdentifier; + _videoDescription = description; + + NSString* viewCount = (NSString *)info[@"viewCount"] ?: (NSString *)videoDetails[@"viewCount"]; + _viewCount = [viewCount integerValue] ?: [viewCount integerValue]; + + NSString* lengthSeconds = (NSString *)info[@"length_seconds"] ?: (NSString *)videoDetails[@"lengthSeconds"]; + _duration = [lengthSeconds doubleValue]; NSString *thumbnail = info[@"thumbnail_url"] ?: info[@"iurl"]; NSURL *thumbnailURL = thumbnail ? [NSURL URLWithString:thumbnail] : nil;