This repository has been archived by the owner on Nov 3, 2021. It is now read-only.
/
push-to-device.test.js
254 lines (240 loc) · 8.06 KB
/
push-to-device.test.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
'use strict';
var assert = require('chai').assert;
var proxyquire = require('proxyquire');
var mockUtils =
require('./mock_utils.js');
suite('push-to-device.js', function() {
var app;
setup(function() {
app = proxyquire.noCallThru().load(
'../../push-to-device', {
'./utils': mockUtils
});
mockUtils.getFileContent = function(file) {
return file;
};
});
suite('pushToDevice, getPid and installSvoperapps', function() {
var profileFolder = 'testProfileFolder';
var remotePath = 'testRemotePath';
test('pushToDevice without indexedDbFile', function(done) {
mockUtils.getFile = function() {
var args = Array.prototype.slice.call(arguments);
var path = args.join('/');
var indexDbFileExists = (path === profileFolder + '/indexedDB');
return {
exists: function() {
return !indexDbFileExists;
},
isDirectory: function() {
return !indexDbFileExists;
},
path: profileFolder + '/indexedDB'
};
};
var queue = app.pushToDevice(profileFolder, remotePath, 'adb');
queue.done(function() {
assert.deepEqual(
mockUtils.hasRunCommands,
{ sh: [
'-c adb shell rm -r /' + remotePath + '/webapps',
'-c adb shell rm //data/local/user.js',
'-c adb push "' + profileFolder + '/webapps" /' + remotePath +
'/webapps',
'-c adb push "' + profileFolder +
'/user.js" //data/local/user.js']
}
);
done();
});
});
test('pushToDevice with indexedDbFile', function(done) {
mockUtils.getFile = function() {
var args = Array.prototype.slice.call(arguments);
var path = args.join('/');
var indexDbFileExists = (path === profileFolder + '/indexedDB');
return {
exists: function() {
return indexDbFileExists;
},
isDirectory: function() {
return indexDbFileExists;
},
path: profileFolder + '/indexedDB'
};
};
var queue = app.pushToDevice(profileFolder, remotePath, 'adb');
queue.done(function() {
assert.deepEqual(
mockUtils.hasRunCommands,
{ sh: [
'-c adb shell rm -r /' + remotePath + '/webapps',
'-c adb shell rm //data/local/user.js',
'-c adb push "' + profileFolder + '/webapps" /' + remotePath +
'/webapps',
'-c adb push "' + profileFolder +
'/user.js" //data/local/user.js',
'-c adb push "' + profileFolder +
'/indexedDB" //data/local/indexedDB']
}
);
done();
});
});
test('installSvoperapps', function(done) {
var queue = app.installSvoperapps(profileFolder, 'adb');
queue.done(function() {
assert.deepEqual(mockUtils.hasRunCommands, {
sh: [
'-c adb shell rm -r //data/local/svoperapps',
'-c adb push "' + profileFolder +
'/svoperapps" //data/local/svoperapps'
]
});
done();
});
});
});
suite('execute', function() {
var options;
var appID;
setup(function() {
options = {
ADB: 'adb',
GAIA_DIR: 'testGaia',
PROFILE_DIR: 'testProfileFolder',
GAIA_INSTALL_PARENT: '/system/b2g',
GAIA_DOMAIN: 'testDomain'
};
appID = '999';
mockUtils.getFile = function() {
var args = Array.prototype.slice.call(arguments);
var path = args.join('/');
var profileExists = (path === options.PROFILE_DIR);
return {
exists: function() {
return profileExists;
},
isDirectory: function() {
return profileExists;
},
path: options.PROFILE_DIR
};
};
mockUtils.readZipManifest = function() {
return {
name: options.BUILD_APP_NAME
};
};
});
test('execute, test it without assigning app name', function(done) {
options.BUILD_APP_NAME = '*';
var queue = app.execute(options);
queue.done(function() {
assert.deepEqual(mockUtils.hasRunCommands, {
sh: [
'-c adb start-server',
'-c adb wait-for-device',
'-c adb shell stop b2g',
'-c adb shell rm -r //cache/*',
'-c adb remount',
'-c adb shell rm -r /' + options.GAIA_INSTALL_PARENT +
'/webapps',
'-c adb shell rm //data/local/user.js',
'-c adb push "' + options.PROFILE_DIR + '/webapps"' +
' //system/b2g/webapps',
'-c adb push "' + options.PROFILE_DIR + '/user.js"' +
' //data/local/user.js',
'-c adb shell start b2g']});
done();
});
});
test('execute, test it with testApp as an app name', function(done) {
options.BUILD_APP_NAME = 'testApp';
mockUtils.psParser = function() {
var pidMap = {};
pidMap[options.BUILD_APP_NAME] = {
PID: appID
};
return pidMap;
};
mockUtils.getPid = function(appName, gaiaDir) {
return appID;
};
var queue = app.execute(options);
queue.done(function() {
assert.deepEqual(mockUtils.hasRunCommands, {
sh: [
'-c adb start-server',
'-c adb wait-for-device',
'-c adb shell rm -r //cache/*',
'-c adb remount',
'-c adb push "' + options.PROFILE_DIR + '/webapps/' +
options.BUILD_APP_NAME + '.' + options.GAIA_DOMAIN +
'/manifest.webapp" /' + options.GAIA_INSTALL_PARENT +
'/webapps/' + options.BUILD_APP_NAME + '.' +
options.GAIA_DOMAIN + '/manifest.webapp',
'-c adb push "' + options.PROFILE_DIR + '/webapps/' +
options.BUILD_APP_NAME + '.' + options.GAIA_DOMAIN +
'/application.zip" /' + options.GAIA_INSTALL_PARENT +
'/webapps/' + options.BUILD_APP_NAME + '.' +
options.GAIA_DOMAIN + '/application.zip',
'-c adb shell kill ' + appID]});
done();
});
});
});
suite('getRemoteInstallPath', function() {
test('Return /system/b2g if no profile on device', function() {
var realGetJSON = mockUtils.getJSON;
mockUtils.getJSON = function(file) {
// getJSON should throw in this case because the content of the
// tempFile will be an adb error message.
return JSON.parse(
'remote object \'' + file.path + '\' does not exist');
};
var path = app.getRemoteInstallPath('adb');
assert.equal(path, '/system/b2g');
mockUtils.getJSON = realGetJSON;
});
test('Return /data/local if no app was installed on /system/b2g',
function() {
var realGetJSON = mockUtils.getJSON;
mockUtils.getJSON = function(file) {
return {
'app1.gaiamobile.org': {
'basePath': '/data/local/webapps'
},
'app2.gaiamobile.org': {
'basePath': '/data/local/webapps'
},
'app3.gaiamobile.org': {
'basePath': '/data/local/webapps'
}
};
};
var path = app.getRemoteInstallPath('adb');
assert.equal(path, '/data/local');
mockUtils.getJSON = realGetJSON;
});
test('Return /system/b2g if any app was installed there', function() {
var realGetJSON = mockUtils.getJSON;
mockUtils.getJSON = function(file) {
return {
'app1.gaiamobile.org': {
'basePath': '/data/local/webapps'
},
'app2.gaiamobile.org': {
'basePath': '/system/b2g/webapps'
},
'app3.gaiamobile.org': {
'basePath': '/system/b2g/webapps'
}
};
};
var path = app.getRemoteInstallPath('adb');
assert.equal(path, '/system/b2g');
mockUtils.getJSON = realGetJSON;
});
});
});