cronapp-cordova-plugin-contentsync 4.4.0-RC7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +201 -0
- package/NOTICE +11 -0
- package/README.md +372 -0
- package/package-lock.json +1545 -0
- package/package.json +58 -0
- package/plugin.xml +93 -0
- package/sample/css/index.css +128 -0
- package/sample/img/logo.png +0 -0
- package/sample/index.html +47 -0
- package/sample/js/index.js +152 -0
- package/spec/helper/cordova.js +83 -0
- package/spec/index.spec.js +334 -0
- package/src/android/Sync.java +1102 -0
- package/src/browser/Sync.js +20 -0
- package/src/ios/ContentSync.h +74 -0
- package/src/ios/ContentSync.m +1002 -0
- package/src/ios/SSZipArchive.h +52 -0
- package/src/ios/SSZipArchive.m +540 -0
- package/src/ios/minizip/crypt.h +131 -0
- package/src/ios/minizip/ioapi.c +239 -0
- package/src/ios/minizip/ioapi.h +201 -0
- package/src/ios/minizip/mztools.c +284 -0
- package/src/ios/minizip/mztools.h +31 -0
- package/src/ios/minizip/unzip.c +2153 -0
- package/src/ios/minizip/unzip.h +437 -0
- package/src/ios/minizip/zip.c +2022 -0
- package/src/ios/minizip/zip.h +362 -0
- package/src/windows/SyncProxy.js +279 -0
- package/src/windows/ZipWinProj/PGZipInflate.cs +94 -0
- package/src/windows/ZipWinProj/Properties/AssemblyInfo.cs +30 -0
- package/src/windows/ZipWinProj/ZipWinProj.csproj +57 -0
- package/src/wp8/Sync.cs +746 -0
- package/src/wp8/Unzip.cs +481 -0
- package/tests/anyfile.txt +1 -0
- package/tests/archives/www1.zip +0 -0
- package/tests/archives/www2.zip +0 -0
- package/tests/package.json +11 -0
- package/tests/plugin.xml +22 -0
- package/tests/scripts/start-server.sh +2 -0
- package/tests/scripts/stop-server.sh +1 -0
- package/tests/tests.js +255 -0
- package/www/index.js +285 -0
|
@@ -0,0 +1,334 @@
|
|
|
1
|
+
/*!
|
|
2
|
+
* Module dependencies.
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
var cordova = require('./helper/cordova'),
|
|
6
|
+
contentSync = require('../www'),
|
|
7
|
+
execSpy,
|
|
8
|
+
execWin,
|
|
9
|
+
options;
|
|
10
|
+
|
|
11
|
+
/*!
|
|
12
|
+
* Specification.
|
|
13
|
+
*/
|
|
14
|
+
|
|
15
|
+
describe('CronApp/cronapp-cordova-plugin-contentsync', function() {
|
|
16
|
+
beforeEach(function() {
|
|
17
|
+
options = { src: 'http://path/to/src.zip', id: 'app-1' };
|
|
18
|
+
execWin = jasmine.createSpy();
|
|
19
|
+
execSpy = spyOn(cordova.required, 'cordova/exec').andCallFake(execWin);
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
describe('.sync', function() {
|
|
23
|
+
it('should require the options parameter', function() {
|
|
24
|
+
expect(function() {
|
|
25
|
+
options = undefined;
|
|
26
|
+
contentSync.sync(options);
|
|
27
|
+
}).toThrow();
|
|
28
|
+
expect(execSpy).not.toHaveBeenCalled();
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
it('should require the options.src parameter for merge/replace', function() {
|
|
32
|
+
expect(function() {
|
|
33
|
+
options.src = undefined;
|
|
34
|
+
contentSync.sync(options);
|
|
35
|
+
}).toThrow();
|
|
36
|
+
expect(execSpy).not.toHaveBeenCalled();
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
it('should not require the options.src parameter for local', function() {
|
|
40
|
+
expect(function() {
|
|
41
|
+
options.src = undefined;
|
|
42
|
+
options.src = "local";
|
|
43
|
+
contentSync.sync(options);
|
|
44
|
+
}).not.toThrow();
|
|
45
|
+
expect(execSpy).not.toHaveBeenCalled();
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
it('should require the options.id parameter', function() {
|
|
49
|
+
expect(function() {
|
|
50
|
+
options.id = undefined;
|
|
51
|
+
contentSync.sync(options);
|
|
52
|
+
}).toThrow();
|
|
53
|
+
expect(execSpy).not.toHaveBeenCalled();
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
it('should return an instance of ContentSync', function() {
|
|
57
|
+
var sync = contentSync.sync(options);
|
|
58
|
+
expect(sync).toEqual(jasmine.any(contentSync.ContentSync));
|
|
59
|
+
});
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
describe('.loadUrl', function() {
|
|
63
|
+
it('should raise an error if url is not provided', function() {
|
|
64
|
+
expect(function() {
|
|
65
|
+
contentSync.loadUrl(null);
|
|
66
|
+
}).toThrow();
|
|
67
|
+
});
|
|
68
|
+
|
|
69
|
+
});
|
|
70
|
+
|
|
71
|
+
describe('ContentSync instance', function() {
|
|
72
|
+
describe('cordova.exec', function() {
|
|
73
|
+
it('should call cordova.exec on next process tick', function(done) {
|
|
74
|
+
contentSync.sync(options);
|
|
75
|
+
setTimeout(function() {
|
|
76
|
+
expect(execSpy).toHaveBeenCalledWith(
|
|
77
|
+
jasmine.any(Function),
|
|
78
|
+
jasmine.any(Function),
|
|
79
|
+
'Sync',
|
|
80
|
+
'sync',
|
|
81
|
+
jasmine.any(Object)
|
|
82
|
+
);
|
|
83
|
+
done();
|
|
84
|
+
}, 100);
|
|
85
|
+
});
|
|
86
|
+
|
|
87
|
+
describe('options.src', function() {
|
|
88
|
+
it('should be passed to exec', function(done) {
|
|
89
|
+
execSpy.andCallFake(function(win, fail, service, id, args) {
|
|
90
|
+
expect(args[0]).toEqual(options.src);
|
|
91
|
+
done();
|
|
92
|
+
});
|
|
93
|
+
contentSync.sync(options);
|
|
94
|
+
});
|
|
95
|
+
});
|
|
96
|
+
|
|
97
|
+
describe('options.id', function() {
|
|
98
|
+
it('should be passed to exec', function(done) {
|
|
99
|
+
options.id = '1234567890';
|
|
100
|
+
execSpy.andCallFake(function(win, fail, service, id, args) {
|
|
101
|
+
expect(args[1]).toEqual(options.id);
|
|
102
|
+
done();
|
|
103
|
+
});
|
|
104
|
+
contentSync.sync(options);
|
|
105
|
+
});
|
|
106
|
+
});
|
|
107
|
+
|
|
108
|
+
describe('options.type', function() {
|
|
109
|
+
it('should default to "replace"', function(done) {
|
|
110
|
+
execSpy.andCallFake(function(win, fail, service, id, args) {
|
|
111
|
+
expect(args[2]).toEqual('replace');
|
|
112
|
+
done();
|
|
113
|
+
});
|
|
114
|
+
contentSync.sync(options);
|
|
115
|
+
});
|
|
116
|
+
|
|
117
|
+
it('should be passed as whatever we specify', function(done) {
|
|
118
|
+
options.type = 'superduper';
|
|
119
|
+
execSpy.andCallFake(function(win, fail, service, id, args) {
|
|
120
|
+
expect(args[2]).toEqual(options.type);
|
|
121
|
+
done();
|
|
122
|
+
});
|
|
123
|
+
contentSync.sync(options);
|
|
124
|
+
});
|
|
125
|
+
});
|
|
126
|
+
|
|
127
|
+
describe('options.headers', function() {
|
|
128
|
+
it('should default to null', function(done) {
|
|
129
|
+
execSpy.andCallFake(function(win, fail, service, id, args) {
|
|
130
|
+
expect(args[3]).toEqual(null);
|
|
131
|
+
done();
|
|
132
|
+
});
|
|
133
|
+
contentSync.sync(options);
|
|
134
|
+
});
|
|
135
|
+
|
|
136
|
+
it('should be passed as whatever we specify', function(done) {
|
|
137
|
+
options.headers = { 'Authorization': 'SECRET_PASSWORD' };
|
|
138
|
+
execSpy.andCallFake(function(win, fail, service, id, args) {
|
|
139
|
+
expect(args[3]).toEqual(options.headers);
|
|
140
|
+
done();
|
|
141
|
+
});
|
|
142
|
+
contentSync.sync(options);
|
|
143
|
+
});
|
|
144
|
+
});
|
|
145
|
+
|
|
146
|
+
describe('options.copyCordovaAssets', function() {
|
|
147
|
+
it('should default to false', function(done) {
|
|
148
|
+
execSpy.andCallFake(function(win, fail, service, id, args) {
|
|
149
|
+
expect(args[4]).toEqual(false);
|
|
150
|
+
done();
|
|
151
|
+
});
|
|
152
|
+
contentSync.sync(options);
|
|
153
|
+
});
|
|
154
|
+
it('should be passed as whatever we specify', function(done) {
|
|
155
|
+
options.copyCordovaAssets = true;
|
|
156
|
+
execSpy.andCallFake(function(win, fail, service, id, args) {
|
|
157
|
+
expect(args[4]).toEqual(options.copyCordovaAssets);
|
|
158
|
+
done();
|
|
159
|
+
});
|
|
160
|
+
contentSync.sync(options);
|
|
161
|
+
});
|
|
162
|
+
});
|
|
163
|
+
|
|
164
|
+
describe('options.copyRootApp', function() {
|
|
165
|
+
it('should default to false', function(done) {
|
|
166
|
+
execSpy.andCallFake(function(win, fail, service, id, args) {
|
|
167
|
+
expect(args[5]).toEqual(false);
|
|
168
|
+
done();
|
|
169
|
+
});
|
|
170
|
+
contentSync.sync(options);
|
|
171
|
+
});
|
|
172
|
+
it('should be passed as whatever we specify', function(done) {
|
|
173
|
+
options.copyRootApp = true;
|
|
174
|
+
execSpy.andCallFake(function(win, fail, service, id, args) {
|
|
175
|
+
expect(args[5]).toEqual(options.copyRootApp);
|
|
176
|
+
done();
|
|
177
|
+
});
|
|
178
|
+
contentSync.sync(options);
|
|
179
|
+
});
|
|
180
|
+
});
|
|
181
|
+
describe('options.timeout', function() {
|
|
182
|
+
it('should default to 15.0', function(done) {
|
|
183
|
+
execSpy.andCallFake(function(win, fail, service, id, args) {
|
|
184
|
+
expect(args[6]).toEqual(15.0);
|
|
185
|
+
done();
|
|
186
|
+
});
|
|
187
|
+
contentSync.sync(options);
|
|
188
|
+
});
|
|
189
|
+
it('should be passed as whatever we specify', function(done) {
|
|
190
|
+
options.timeout = 30.0;
|
|
191
|
+
execSpy.andCallFake(function(win, fail, service, id, args) {
|
|
192
|
+
expect(args[6]).toEqual(options.timeout);
|
|
193
|
+
done();
|
|
194
|
+
});
|
|
195
|
+
contentSync.sync(options);
|
|
196
|
+
});
|
|
197
|
+
});
|
|
198
|
+
describe('options.trustHost', function() {
|
|
199
|
+
it('should default to false', function(done) {
|
|
200
|
+
execSpy.andCallFake(function(win, fail, service, id, args) {
|
|
201
|
+
expect(args[7]).toEqual(false);
|
|
202
|
+
done();
|
|
203
|
+
});
|
|
204
|
+
contentSync.sync(options);
|
|
205
|
+
});
|
|
206
|
+
it('should be passed as whatever we specify', function(done) {
|
|
207
|
+
options.trustHost = true;
|
|
208
|
+
execSpy.andCallFake(function(win, fail, service, id, args) {
|
|
209
|
+
expect(args[7]).toEqual(options.trustHost);
|
|
210
|
+
done();
|
|
211
|
+
});
|
|
212
|
+
contentSync.sync(options);
|
|
213
|
+
});
|
|
214
|
+
});
|
|
215
|
+
describe('options.manifest', function() {
|
|
216
|
+
it('should default to the empty string', function(done) {
|
|
217
|
+
execSpy.andCallFake(function(win, fail, service, id, args) {
|
|
218
|
+
expect(args[8]).toEqual("");
|
|
219
|
+
done();
|
|
220
|
+
});
|
|
221
|
+
contentSync.sync(options);
|
|
222
|
+
});
|
|
223
|
+
it('should be passed as whatever we specify', function(done) {
|
|
224
|
+
options.manifest = "manifest.json";
|
|
225
|
+
execSpy.andCallFake(function(win, fail, service, id, args) {
|
|
226
|
+
expect(args[8]).toEqual(options.manifest);
|
|
227
|
+
done();
|
|
228
|
+
});
|
|
229
|
+
contentSync.sync(options);
|
|
230
|
+
});
|
|
231
|
+
});
|
|
232
|
+
});
|
|
233
|
+
|
|
234
|
+
describe('on "progress" event', function() {
|
|
235
|
+
it('should be emitted with an argument', function(done) {
|
|
236
|
+
execSpy.andCallFake(function(win, fail, service, id, args) {
|
|
237
|
+
win({ 'progress': 1 });
|
|
238
|
+
});
|
|
239
|
+
var sync = contentSync.sync(options);
|
|
240
|
+
sync.on('progress', function(data) {
|
|
241
|
+
expect(data.progress).toEqual(1);
|
|
242
|
+
done();
|
|
243
|
+
});
|
|
244
|
+
});
|
|
245
|
+
});
|
|
246
|
+
|
|
247
|
+
describe('on "complete" event', function() {
|
|
248
|
+
beforeEach(function() {
|
|
249
|
+
execSpy.andCallFake(function(win, fail, service, id, args) {
|
|
250
|
+
win({
|
|
251
|
+
localPath: 'file:///path/to/content'
|
|
252
|
+
});
|
|
253
|
+
});
|
|
254
|
+
});
|
|
255
|
+
|
|
256
|
+
it('should be emitted on success', function(done) {
|
|
257
|
+
var sync = contentSync.sync(options);
|
|
258
|
+
sync.on('complete', function(data) {
|
|
259
|
+
done();
|
|
260
|
+
});
|
|
261
|
+
});
|
|
262
|
+
|
|
263
|
+
it('should provide the data.localPath argument', function(done) {
|
|
264
|
+
var sync = contentSync.sync(options);
|
|
265
|
+
sync.on('complete', function(data) {
|
|
266
|
+
expect(data.localPath).toEqual('file:///path/to/content');
|
|
267
|
+
done();
|
|
268
|
+
});
|
|
269
|
+
});
|
|
270
|
+
});
|
|
271
|
+
|
|
272
|
+
describe('on "error" event', function() {
|
|
273
|
+
it('should be emitted with an Error', function(done) {
|
|
274
|
+
execSpy.andCallFake(function(win, fail, service, id, args) {
|
|
275
|
+
fail('something went wrong');
|
|
276
|
+
});
|
|
277
|
+
var sync = contentSync.sync(options);
|
|
278
|
+
sync.on('error', function(e) {
|
|
279
|
+
expect(e).toEqual(jasmine.any(Error));
|
|
280
|
+
expect(e.message).toEqual('something went wrong');
|
|
281
|
+
done();
|
|
282
|
+
});
|
|
283
|
+
});
|
|
284
|
+
});
|
|
285
|
+
|
|
286
|
+
describe('.cancel()', function() {
|
|
287
|
+
it('should delegate to exec', function(done) {
|
|
288
|
+
var sync = contentSync.sync(options);
|
|
289
|
+
sync.cancel();
|
|
290
|
+
setTimeout(function() {
|
|
291
|
+
expect(execSpy).toHaveBeenCalled();
|
|
292
|
+
expect(execSpy.callCount).toEqual(2); // 1) sync, 2) cancel
|
|
293
|
+
expect(execSpy.mostRecentCall.args).toEqual([
|
|
294
|
+
jasmine.any(Function),
|
|
295
|
+
jasmine.any(Function),
|
|
296
|
+
'Sync',
|
|
297
|
+
'cancel',
|
|
298
|
+
[ options.id ]
|
|
299
|
+
]);
|
|
300
|
+
done();
|
|
301
|
+
}, 100);
|
|
302
|
+
});
|
|
303
|
+
|
|
304
|
+
it('should emit the "cancel" event', function(done) {
|
|
305
|
+
execSpy.andCallFake(function(win, fail, service, id, args) {
|
|
306
|
+
win();
|
|
307
|
+
});
|
|
308
|
+
var sync = contentSync.sync(options);
|
|
309
|
+
sync.on('cancel', function() {
|
|
310
|
+
done();
|
|
311
|
+
});
|
|
312
|
+
sync.cancel();
|
|
313
|
+
});
|
|
314
|
+
});
|
|
315
|
+
});
|
|
316
|
+
|
|
317
|
+
describe('PROGRESS_STATE enumeration', function() {
|
|
318
|
+
it('should defined 0 as STOPPED', function() {
|
|
319
|
+
expect(contentSync.PROGRESS_STATE[0]).toEqual('STOPPED');
|
|
320
|
+
});
|
|
321
|
+
|
|
322
|
+
it('should defined 1 as DOWNLOADING', function() {
|
|
323
|
+
expect(contentSync.PROGRESS_STATE[1]).toEqual('DOWNLOADING');
|
|
324
|
+
});
|
|
325
|
+
|
|
326
|
+
it('should defined 2 as EXTRACTING', function() {
|
|
327
|
+
expect(contentSync.PROGRESS_STATE[2]).toEqual('EXTRACTING');
|
|
328
|
+
});
|
|
329
|
+
|
|
330
|
+
it('should defined 3 as COMPLETE', function() {
|
|
331
|
+
expect(contentSync.PROGRESS_STATE[3]).toEqual('COMPLETE');
|
|
332
|
+
});
|
|
333
|
+
});
|
|
334
|
+
});
|