File tree Expand file tree Collapse file tree 3 files changed +33
-1
lines changed Expand file tree Collapse file tree 3 files changed +33
-1
lines changed Original file line number Diff line number Diff line change 1313#import " CCDirector.h"
1414#import " AppDelegate.h"
1515#import " CCUnitTestAssertions.h"
16+ #import " CCPackage_private.h"
1617
1718@interface CCPackageDownloadManagerTestURLProtocol : NSURLProtocol @end
1819
@@ -175,6 +176,22 @@ - (void)testEnqueuePausedPackage
175176 [self assertPackagesDownloadedAndContentsAreAsExpected: @[package1]];
176177}
177178
179+ - (void )testResumeDownloadAfterLoadingPackages
180+ {
181+ // This test aims at the situation when coming back from persistency and
182+ // the package manager resume downloads.
183+
184+ CCPackage *package = [self completePackageWithName: @" package" ];
185+ package.status = CCPackageStatusDownloadPaused;
186+ package.localDownloadURL = [NSURL fileURLWithPath: [_downloadManager.downloadPath stringByAppendingPathComponent: @" foo.zip" ]];
187+
188+ [_downloadManager enqueuePackageForDownload: package];
189+
190+ [self waitUntilDelegateReturns ];
191+
192+ [self assertPackagesDownloadedAndContentsAreAsExpected: @[package]];
193+ }
194+
178195- (void )waitUntilDelegateReturns
179196{
180197 while (!_allDownloadsReturned)
Original file line number Diff line number Diff line change 4545- (void )enqueuePackageForDownload : (CCPackage *)package ;
4646
4747/* *
48- * Cancels a download of a given package. Downloaded file will be deleted.
48+ * Cancels a download of a given package. Downloaded data will be deleted.
49+ * Status of package is reset to CCPackageStatusInitial.
4950 *
5051 * @param package The package that should be cancelled
5152 */
Original file line number Diff line number Diff line change @@ -126,11 +126,25 @@ - (void)pauseDownloadOfPackage:(CCPackage *)package
126126
127127- (void )resumeDownloadOfPackage : (CCPackage *)package
128128{
129+ [self createDownloadIfNotExistForPackage: package];
130+
129131 CCLOGINFO (@" [PACKAGE/DOWNLOADS][INFO] Resuming download of package %@ ." , package);
130132 CCPackageDownload *packageDownload = [self packageDownloadForPackage: package];
131133 [packageDownload resume ];
132134}
133135
136+ - (void )createDownloadIfNotExistForPackage : (CCPackage *)package
137+ {
138+ if (![self packageDownloadForPackage: package])
139+ {
140+ CCPackageDownload *packageDownload = [[CCPackageDownload alloc ] initWithPackage: package
141+ localURL: package.localDownloadURL];
142+ packageDownload.delegate = self;
143+
144+ [_downloads addObject: packageDownload];
145+ }
146+ }
147+
134148- (void )pauseAllDownloads
135149{
136150 CCLOGINFO (@" [PACKAGE/DOWNLOADS][INFO] Pausing all downloads." );
You can’t perform that action at this time.
0 commit comments