Skip to content

Commit ff214a2

Browse files
committed
CCPackageTest: NSURLProtocol removed and turned download into a real http request.
1 parent 33dc17b commit ff214a2

File tree

1 file changed

+2
-72
lines changed

1 file changed

+2
-72
lines changed

cocos2d-ui-tests/tests/CCPackageTest.m

Lines changed: 2 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -14,64 +14,6 @@
1414
#import "AppDelegate.h"
1515

1616

17-
18-
@interface CCPackageTestURLProtocol : NSURLProtocol
19-
20-
@end
21-
22-
23-
@implementation CCPackageTestURLProtocol
24-
25-
+ (BOOL)canInitWithRequest:(NSURLRequest*)theRequest
26-
{
27-
return [theRequest.URL.scheme caseInsensitiveCompare:@"http"] == NSOrderedSame;
28-
}
29-
30-
+ (NSURLRequest *)canonicalRequestForRequest:(NSURLRequest *)theRequest
31-
{
32-
return theRequest;
33-
}
34-
35-
- (void)startLoading
36-
{
37-
NSString *fileName = [self.request.URL lastPathComponent];
38-
39-
NSString *pathToPackage = [[NSBundle mainBundle] pathForResource:[NSString stringWithFormat:@"Resources-shared/Packages/%@", fileName] ofType:nil];
40-
NSData *data = [NSData dataWithContentsOfFile:pathToPackage];
41-
42-
NSHTTPURLResponse *response;
43-
if (pathToPackage)
44-
{
45-
response = [[NSHTTPURLResponse alloc] initWithURL:self.request.URL
46-
statusCode:200
47-
HTTPVersion:@"HTTP/1.1"
48-
headerFields:nil];
49-
}
50-
else
51-
{
52-
response = [[NSHTTPURLResponse alloc] initWithURL:self.request.URL
53-
statusCode:404
54-
HTTPVersion:@"HTTP/1.1"
55-
headerFields:nil];
56-
}
57-
58-
59-
id<NSURLProtocolClient> client = [self client];
60-
[client URLProtocol:self didReceiveResponse:response cacheStoragePolicy:NSURLCacheStorageNotAllowed];
61-
[client URLProtocol:self didLoadData:data];
62-
[client URLProtocolDidFinishLoading:self];
63-
}
64-
65-
- (void)stopLoading
66-
{
67-
// Nothing to do
68-
}
69-
70-
@end
71-
72-
73-
#pragma mark - Test class
74-
7517
@interface CCPackageTest : TestBase <CCPackageManagerDelegate>
7618

7719
@property (nonatomic, strong) CCPackage *package;
@@ -83,8 +25,6 @@ @implementation CCPackageTest
8325

8426
- (void) setupPackageTest
8527
{
86-
[self setupLocalHTTPRequests];
87-
8828
[self.contentNode removeAllChildren];
8929

9030
[self removePersistedPackages];
@@ -101,15 +41,10 @@ - (void) setupPackageTest
10141

10242
self.package = [[CCPackageManager sharedManager] downloadPackageWithName:@"testpackage"
10343
resolution:@"phonehd"
104-
remoteURL:[NSURL URLWithString:@"http://package.request.fake/testpackage-iOS-phonehd.zip"]
44+
remoteURL:[NSURL URLWithString:@"https://github.com/NickyWeber/cocos2d_test_resources/blob/master/testpackage-iOS-phonehd.zip?raw=true"]
10545
enableAfterDownload:YES];
10646
}
10747

108-
- (void)setupLocalHTTPRequests
109-
{
110-
[NSURLProtocol registerClass:[CCPackageTestURLProtocol class]];
111-
}
112-
11348
- (void)removePersistedPackages
11449
{
11550
[[NSUserDefaults standardUserDefaults] removeObjectForKey:PACKAGE_STORAGE_USERDEFAULTS_KEY];
@@ -209,31 +144,26 @@ - (void)packageInstallationFinished:(CCPackage *)package
209144
- (void)packageInstallationFailed:(CCPackage *)package error:(NSError *)error
210145
{
211146
self.subTitle = [NSString stringWithFormat:@"Test failed: installation failed."];
212-
[NSURLProtocol unregisterClass:[CCPackageTestURLProtocol class]];
213147
}
214148

215149
- (void)packageDownloadFinished:(CCPackage *)package
216150
{
217151
self.subTitle = [NSString stringWithFormat:@"Download finished"];
218-
[NSURLProtocol unregisterClass:[CCPackageTestURLProtocol class]];
219-
}
152+
}
220153

221154
- (void)packageDownloadFailed:(CCPackage *)package error:(NSError *)error
222155
{
223156
self.subTitle = [NSString stringWithFormat:@"Test failed: download failed."];
224-
[NSURLProtocol unregisterClass:[CCPackageTestURLProtocol class]];
225157
}
226158

227159
- (void)packageUnzippingFinished:(CCPackage *)package
228160
{
229161
self.subTitle = [NSString stringWithFormat:@"Unzip finished"];
230-
[NSURLProtocol unregisterClass:[CCPackageTestURLProtocol class]];
231162
}
232163

233164
- (void)packageUnzippingFailed:(CCPackage *)package error:(NSError *)error
234165
{
235166
self.subTitle = [NSString stringWithFormat:@"Test failed: unzipping failed."];
236-
[NSURLProtocol unregisterClass:[CCPackageTestURLProtocol class]];
237167
}
238168

239169
- (void)packageDownloadProgress:(CCPackage *)package downloadedBytes:(NSUInteger)downloadedBytes totalBytes:(NSUInteger)totalBytes

0 commit comments

Comments
 (0)