14
14
#import " AppDelegate.h"
15
15
16
16
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
-
75
17
@interface CCPackageTest : TestBase <CCPackageManagerDelegate>
76
18
77
19
@property (nonatomic , strong ) CCPackage *package;
@@ -83,8 +25,6 @@ @implementation CCPackageTest
83
25
84
26
- (void ) setupPackageTest
85
27
{
86
- [self setupLocalHTTPRequests ];
87
-
88
28
[self .contentNode removeAllChildren ];
89
29
90
30
[self removePersistedPackages ];
@@ -101,15 +41,10 @@ - (void) setupPackageTest
101
41
102
42
self.package = [[CCPackageManager sharedManager ] downloadPackageWithName: @" testpackage"
103
43
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 " ]
105
45
enableAfterDownload: YES ];
106
46
}
107
47
108
- - (void )setupLocalHTTPRequests
109
- {
110
- [NSURLProtocol registerClass: [CCPackageTestURLProtocol class ]];
111
- }
112
-
113
48
- (void )removePersistedPackages
114
49
{
115
50
[[NSUserDefaults standardUserDefaults ] removeObjectForKey: PACKAGE_STORAGE_USERDEFAULTS_KEY];
@@ -209,31 +144,26 @@ - (void)packageInstallationFinished:(CCPackage *)package
209
144
- (void )packageInstallationFailed : (CCPackage *)package error : (NSError *)error
210
145
{
211
146
self.subTitle = [NSString stringWithFormat: @" Test failed: installation failed." ];
212
- [NSURLProtocol unregisterClass: [CCPackageTestURLProtocol class ]];
213
147
}
214
148
215
149
- (void )packageDownloadFinished : (CCPackage *)package
216
150
{
217
151
self.subTitle = [NSString stringWithFormat: @" Download finished" ];
218
- [NSURLProtocol unregisterClass: [CCPackageTestURLProtocol class ]];
219
- }
152
+ }
220
153
221
154
- (void )packageDownloadFailed : (CCPackage *)package error : (NSError *)error
222
155
{
223
156
self.subTitle = [NSString stringWithFormat: @" Test failed: download failed." ];
224
- [NSURLProtocol unregisterClass: [CCPackageTestURLProtocol class ]];
225
157
}
226
158
227
159
- (void )packageUnzippingFinished : (CCPackage *)package
228
160
{
229
161
self.subTitle = [NSString stringWithFormat: @" Unzip finished" ];
230
- [NSURLProtocol unregisterClass: [CCPackageTestURLProtocol class ]];
231
162
}
232
163
233
164
- (void )packageUnzippingFailed : (CCPackage *)package error : (NSError *)error
234
165
{
235
166
self.subTitle = [NSString stringWithFormat: @" Test failed: unzipping failed." ];
236
- [NSURLProtocol unregisterClass: [CCPackageTestURLProtocol class ]];
237
167
}
238
168
239
169
- (void )packageDownloadProgress : (CCPackage *)package downloadedBytes : (NSUInteger )downloadedBytes totalBytes : (NSUInteger )totalBytes
0 commit comments