run_loop 2.0.1 → 2.0.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,150 +1,4 @@
1
- if (typeof JSON !== 'object') {
2
- JSON = {};
3
- }
4
- (function () {
5
- 'use strict';
6
- function f(n) {
7
- return n < 10 ? '0' + n : n;
8
- }
9
-
10
- if (typeof Date.prototype.toJSON !== 'function') {
11
- Date.prototype.toJSON = function (key) {
12
- return isFinite(this.valueOf()) ? this.getUTCFullYear() + '-' +
13
- f(this.getUTCMonth() + 1) + '-' +
14
- f(this.getUTCDate()) + 'T' +
15
- f(this.getUTCHours()) + ':' +
16
- f(this.getUTCMinutes()) + ':' +
17
- f(this.getUTCSeconds()) + 'Z' : null;
18
- };
19
- String.prototype.toJSON = Number.prototype.toJSON = Boolean.prototype.toJSON = function (key) {
20
- return this.valueOf();
21
- };
22
- }
23
- var cx = /[\u0000\u00ad\u0600-\u0604\u070f\u17b4\u17b5\u200c-\u200f\u2028-\u202f\u2060-\u206f\ufeff\ufff0-\uffff]/g, escapable = /[\\\"\x00-\x1f\x7f-\x9f\u00ad\u0600-\u0604\u070f\u17b4\u17b5\u200c-\u200f\u2028-\u202f\u2060-\u206f\ufeff\ufff0-\uffff]/g, gap, indent, meta = {'\b': '\\b', '\t': '\\t', '\n': '\\n', '\f': '\\f', '\r': '\\r', '"': '\\"', '\\': '\\\\'}, rep;
24
-
25
- function quote(string) {
26
- escapable.lastIndex = 0;
27
- return escapable.test(string) ? '"' + string.replace(escapable, function (a) {
28
- var c = meta[a];
29
- return typeof c === 'string' ? c : '\\u' + ('0000' + a.charCodeAt(0).toString(16)).slice(-4);
30
- }) + '"' : '"' + string + '"';
31
- }
32
-
33
- function str(key, holder) {
34
- var i, k, v, length, mind = gap, partial, value = holder[key];
35
- if (value && typeof value === 'object' && typeof value.toJSON === 'function') {
36
- value = value.toJSON(key);
37
- }
38
- if (typeof rep === 'function') {
39
- value = rep.call(holder, key, value);
40
- }
41
- switch (typeof value) {
42
- case'string':
43
- return quote(value);
44
- case'number':
45
- return isFinite(value) ? String(value) : 'null';
46
- case'boolean':
47
- case'null':
48
- return String(value);
49
- case'object':
50
- if (!value) {
51
- return'null';
52
- }
53
- gap += indent;
54
- partial = [];
55
- if (Object.prototype.toString.apply(value) === '[object Array]') {
56
- length = value.length;
57
- for (i = 0; i < length; i += 1) {
58
- partial[i] = str(i, value) || 'null';
59
- }
60
- v = partial.length === 0 ? '[]' : gap ? '[\n' + gap + partial.join(',\n' + gap) + '\n' + mind + ']' : '[' + partial.join(',') + ']';
61
- gap = mind;
62
- return v;
63
- }
64
- if (rep && typeof rep === 'object') {
65
- length = rep.length;
66
- for (i = 0; i < length; i += 1) {
67
- if (typeof rep[i] === 'string') {
68
- k = rep[i];
69
- v = str(k, value);
70
- if (v) {
71
- partial.push(quote(k) + (gap ? ': ' : ':') + v);
72
- }
73
- }
74
- }
75
- } else {
76
- for (k in value) {
77
- if (Object.prototype.hasOwnProperty.call(value, k)) {
78
- v = str(k, value);
79
- if (v) {
80
- partial.push(quote(k) + (gap ? ': ' : ':') + v);
81
- }
82
- }
83
- }
84
- }
85
- v = partial.length === 0 ? '{}' : gap ? '{\n' + gap + partial.join(',\n' + gap) + '\n' + mind + '}' : '{' + partial.join(',') + '}';
86
- gap = mind;
87
- return v;
88
- }
89
- }
90
-
91
- if (typeof JSON.stringify !== 'function') {
92
- JSON.stringify = function (value, replacer, space) {
93
- var i;
94
- gap = '';
95
- indent = '';
96
- if (typeof space === 'number') {
97
- for (i = 0; i < space; i += 1) {
98
- indent += ' ';
99
- }
100
- } else if (typeof space === 'string') {
101
- indent = space;
102
- }
103
- rep = replacer;
104
- if (replacer && typeof replacer !== 'function' && (typeof replacer !== 'object' || typeof replacer.length !== 'number')) {
105
- throw new Error('JSON.stringify');
106
- }
107
- return str('', {'': value});
108
- };
109
- }
110
- if (typeof JSON.parse !== 'function') {
111
- JSON.parse = function (text, reviver) {
112
- var j;
113
-
114
- function walk(holder, key) {
115
- var k, v, value = holder[key];
116
- if (value && typeof value === 'object') {
117
- for (k in value) {
118
- if (Object.prototype.hasOwnProperty.call(value, k)) {
119
- v = walk(value, k);
120
- if (v !== undefined) {
121
- value[k] = v;
122
- } else {
123
- delete value[k];
124
- }
125
- }
126
- }
127
- }
128
- return reviver.call(holder, key, value);
129
- }
130
-
131
- text = String(text);
132
- cx.lastIndex = 0;
133
- if (cx.test(text)) {
134
- text = text.replace(cx, function (a) {
135
- return'\\u' +
136
- ('0000' + a.charCodeAt(0).toString(16)).slice(-4);
137
- });
138
- }
139
- if (/^[\],:{}\s]*$/.test(text.replace(/\\(?:["\\\/bfnrt]|u[0-9a-fA-F]{4})/g, '@').replace(/"[^"\\\n\r]*"|true|false|null|-?\d+(?:\.\d*)?(?:[eE][+\-]?\d+)?/g, ']').replace(/(?:^|:|,)(?:\s*\[)+/g, ''))) {
140
- j = eval('(' + text + ')');
141
- return typeof reviver === 'function' ? walk({'': j}, '') : j;
142
- }
143
- throw new SyntaxError('JSON.parse');
144
- };
145
- }
146
- }());
147
-
1
+ <% render_template("lib/json2.min.js") %>
148
2
 
149
3
  _RUN_LOOP_MAX_RETRY_AFTER_HANDLER = 10;
150
4
  var _expectedIndex = 0,//expected index of next command
@@ -153,91 +7,8 @@ var _expectedIndex = 0,//expected index of next command
153
7
  _result,
154
8
  _lastResponse=null;
155
9
 
156
- var Log = (function () {
157
- var forceFlush = [],
158
- N = 16384,
159
- i = N;
160
- while (i--) {
161
- forceFlush[i] = "*";
162
- }
163
- forceFlush = forceFlush.join('');
164
-
165
- function log_json(object, flush)
166
- {
167
- UIALogger.logMessage("OUTPUT_JSON:\n"+JSON.stringify(object)+"\nEND_OUTPUT");
168
- if (flush) {
169
- UIALogger.logMessage(forceFlush);
170
- }
171
- }
172
-
173
- return {
174
- result: function (status, data, flush) {
175
- log_json({"status": status, "value": data, "index":_actualIndex}, flush)
176
- },
177
- output: function (msg, flush) {
178
- log_json({"output": msg,"last_index":_actualIndex}, flush);
179
- }
180
- };
181
- })();
182
-
183
-
184
- function findAlertViewText(alert) {
185
- if (!alert) {
186
- return false;
187
- }
188
- var txt = alert.name(),
189
- txts;
190
- if (txt == null) {
191
- txts = alert.staticTexts();
192
- if (txts != null && txts.length > 0) {
193
- txt = txts[0].name();
194
- }
195
- }
196
- return txt;
197
- }
198
-
199
- function isLocationPrompt(alert) {
200
- var exps = [
201
-
202
- ["Tillad", /bruge din lokalitet, når du bruger appen/],
203
- ["Tillad", /også når du ikke bruger appen/],
204
- ["OK", /vil bruge din aktuelle placering/],
205
- ["OK", /Would Like to Use Your Current Location/],
206
- ["Ja", /Darf (?:.)+ Ihren aktuellen Ort verwenden/],
207
- ["Allow", /access your location/],
208
- ["OK", /Would Like to Access Your Photos/],
209
- ["OK", /Would Like to Access Your Contacts/],
210
- ["OK", /Location Accuracy/],
211
- ["OK", /запрашивает разрешение на использование Ващей текущей пгеопозиции/],
212
- ["OK", /Access the Microphone/],
213
- ["OK", /Would Like to Access Your Calendar/],
214
- ["OK", /Would Like to Access Your Reminders/],
215
- ["OK", /Would Like to Access Your Motion Activity/],
216
- ["OK", /Would Like to Access the Camera/],
217
- ["OK", /Would Like to Access Your Motion & Fitness Activity/],
218
- ["OK", /Would Like Access to Twitter Accounts/],
219
- ["OK", /data available to nearby bluetooth devices/],
220
-
221
- // APNS
222
- ["OK", /enviarle notificaiones/],
223
- ["OK", /wil u berichten stuern/],
224
- ["OK", /Would Like to Send You Notifications/],
225
- ["OK", /would like to send you Push Notifications/]
226
- ],
227
- ans, exp,
228
- txt;
229
-
230
- txt = findAlertViewText(alert);
231
- Log.output({"output":"alert: "+txt}, true);
232
- for (var i = 0; i < exps.length; i++) {
233
- ans = exps[i][0];
234
- exp = exps[i][1];
235
- if (exp.test(txt)) {
236
- return ans;
237
- }
238
- }
239
- return false;
240
- }
10
+ <%= render_template("lib/log.js"); %>
11
+ <%= render_template("lib/on_alert.js"); %>
241
12
 
242
13
  UIATarget.onAlert = function (alert) {
243
14
  var target = UIATarget.localTarget(),
@@ -246,29 +17,29 @@ UIATarget.onAlert = function (alert) {
246
17
  rsp = null,
247
18
  actualIndex = null;
248
19
  target.pushTimeout(10);
249
- function attemptTouchOKOnLocation(retry_count) {
20
+ function dismissPrivacyAlert(retry_count) {
250
21
  retry_count = retry_count || 0;
251
22
  if (retry_count >= 5) {
252
- Log.output("Maxed out retry (5) - unable to dismiss location dialog.");
23
+ Log.output("Maxed out retry (5) - unable to dismiss privacy alert.");
253
24
  return;
254
25
  }
255
26
  try {
256
- var answer = isLocationPrompt(alert);
27
+ var answer = isPrivacyAlert(alert);
257
28
  if (answer) {
258
29
  alert.buttons()[answer].tap();
259
30
  }
260
31
  }
261
32
  catch (e) {
262
- Log.output("Exception while trying to touch alert dialog. Retrying...");
33
+ Log.output("Exception while trying to touch privacy alert. Retrying...");
263
34
  if (e && typeof e.toString == 'function') {
264
35
  Log.output(e.toString());
265
36
  }
266
37
  target.delay(1);
267
- attemptTouchOKOnLocation(retry_count + 1);
38
+ dismissPrivacyAlert(retry_count + 1);
268
39
  }
269
40
  }
270
41
 
271
- attemptTouchOKOnLocation(0);
42
+ dismissPrivacyAlert(0);
272
43
  target.popTimeout();
273
44
  for (var i=0;i<_RUN_LOOP_MAX_RETRY_AFTER_HANDLER;i++) {
274
45
  req = app.preferencesValueForKey(__calabashRequest);
@@ -1,151 +1,6 @@
1
1
  //#import "calabash_script_uia.js"
2
2
 
3
- if (typeof JSON !== 'object') {
4
- JSON = {};
5
- }
6
- (function () {
7
- 'use strict';
8
- function f(n) {
9
- return n < 10 ? '0' + n : n;
10
- }
11
-
12
- if (typeof Date.prototype.toJSON !== 'function') {
13
- Date.prototype.toJSON = function (key) {
14
- return isFinite(this.valueOf()) ? this.getUTCFullYear() + '-' +
15
- f(this.getUTCMonth() + 1) + '-' +
16
- f(this.getUTCDate()) + 'T' +
17
- f(this.getUTCHours()) + ':' +
18
- f(this.getUTCMinutes()) + ':' +
19
- f(this.getUTCSeconds()) + 'Z' : null;
20
- };
21
- String.prototype.toJSON = Number.prototype.toJSON = Boolean.prototype.toJSON = function (key) {
22
- return this.valueOf();
23
- };
24
- }
25
- var cx = /[\u0000\u00ad\u0600-\u0604\u070f\u17b4\u17b5\u200c-\u200f\u2028-\u202f\u2060-\u206f\ufeff\ufff0-\uffff]/g, escapable = /[\\\"\x00-\x1f\x7f-\x9f\u00ad\u0600-\u0604\u070f\u17b4\u17b5\u200c-\u200f\u2028-\u202f\u2060-\u206f\ufeff\ufff0-\uffff]/g, gap, indent, meta = {'\b': '\\b', '\t': '\\t', '\n': '\\n', '\f': '\\f', '\r': '\\r', '"': '\\"', '\\': '\\\\'}, rep;
26
-
27
- function quote(string) {
28
- escapable.lastIndex = 0;
29
- return escapable.test(string) ? '"' + string.replace(escapable, function (a) {
30
- var c = meta[a];
31
- return typeof c === 'string' ? c : '\\u' + ('0000' + a.charCodeAt(0).toString(16)).slice(-4);
32
- }) + '"' : '"' + string + '"';
33
- }
34
-
35
- function str(key, holder) {
36
- var i, k, v, length, mind = gap, partial, value = holder[key];
37
- if (value && typeof value === 'object' && typeof value.toJSON === 'function') {
38
- value = value.toJSON(key);
39
- }
40
- if (typeof rep === 'function') {
41
- value = rep.call(holder, key, value);
42
- }
43
- switch (typeof value) {
44
- case'string':
45
- return quote(value);
46
- case'number':
47
- return isFinite(value) ? String(value) : 'null';
48
- case'boolean':
49
- case'null':
50
- return String(value);
51
- case'object':
52
- if (!value) {
53
- return'null';
54
- }
55
- gap += indent;
56
- partial = [];
57
- if (Object.prototype.toString.apply(value) === '[object Array]') {
58
- length = value.length;
59
- for (i = 0; i < length; i += 1) {
60
- partial[i] = str(i, value) || 'null';
61
- }
62
- v = partial.length === 0 ? '[]' : gap ? '[\n' + gap + partial.join(',\n' + gap) + '\n' + mind + ']' : '[' + partial.join(',') + ']';
63
- gap = mind;
64
- return v;
65
- }
66
- if (rep && typeof rep === 'object') {
67
- length = rep.length;
68
- for (i = 0; i < length; i += 1) {
69
- if (typeof rep[i] === 'string') {
70
- k = rep[i];
71
- v = str(k, value);
72
- if (v) {
73
- partial.push(quote(k) + (gap ? ': ' : ':') + v);
74
- }
75
- }
76
- }
77
- } else {
78
- for (k in value) {
79
- if (Object.prototype.hasOwnProperty.call(value, k)) {
80
- v = str(k, value);
81
- if (v) {
82
- partial.push(quote(k) + (gap ? ': ' : ':') + v);
83
- }
84
- }
85
- }
86
- }
87
- v = partial.length === 0 ? '{}' : gap ? '{\n' + gap + partial.join(',\n' + gap) + '\n' + mind + '}' : '{' + partial.join(',') + '}';
88
- gap = mind;
89
- return v;
90
- }
91
- }
92
-
93
- if (typeof JSON.stringify !== 'function') {
94
- JSON.stringify = function (value, replacer, space) {
95
- var i;
96
- gap = '';
97
- indent = '';
98
- if (typeof space === 'number') {
99
- for (i = 0; i < space; i += 1) {
100
- indent += ' ';
101
- }
102
- } else if (typeof space === 'string') {
103
- indent = space;
104
- }
105
- rep = replacer;
106
- if (replacer && typeof replacer !== 'function' && (typeof replacer !== 'object' || typeof replacer.length !== 'number')) {
107
- throw new Error('JSON.stringify');
108
- }
109
- return str('', {'': value});
110
- };
111
- }
112
- if (typeof JSON.parse !== 'function') {
113
- JSON.parse = function (text, reviver) {
114
- var j;
115
-
116
- function walk(holder, key) {
117
- var k, v, value = holder[key];
118
- if (value && typeof value === 'object') {
119
- for (k in value) {
120
- if (Object.prototype.hasOwnProperty.call(value, k)) {
121
- v = walk(value, k);
122
- if (v !== undefined) {
123
- value[k] = v;
124
- } else {
125
- delete value[k];
126
- }
127
- }
128
- }
129
- }
130
- return reviver.call(holder, key, value);
131
- }
132
-
133
- text = String(text);
134
- cx.lastIndex = 0;
135
- if (cx.test(text)) {
136
- text = text.replace(cx, function (a) {
137
- return'\\u' +
138
- ('0000' + a.charCodeAt(0).toString(16)).slice(-4);
139
- });
140
- }
141
- if (/^[\],:{}\s]*$/.test(text.replace(/\\(?:["\\\/bfnrt]|u[0-9a-fA-F]{4})/g, '@').replace(/"[^"\\\n\r]*"|true|false|null|-?\d+(?:\.\d*)?(?:[eE][+\-]?\d+)?/g, ']').replace(/(?:^|:|,)(?:\s*\[)+/g, ''))) {
142
- j = eval('(' + text + ')');
143
- return typeof reviver === 'function' ? walk({'': j}, '') : j;
144
- }
145
- throw new SyntaxError('JSON.parse');
146
- };
147
- }
148
- }());
3
+ <%= render_template("lib/json2.min.js") %>
149
4
 
150
5
  var commandPath = "$PATH";
151
6
  if (!/\/$/.test(commandPath)) {
@@ -156,10 +11,6 @@ commandPath += "repl-cmd.pipe";
156
11
  var timeoutScriptPath = "$TIMEOUT_SCRIPT_PATH",
157
12
  readPipeScriptPath = "$READ_SCRIPT_PATH";
158
13
 
159
-
160
-
161
-
162
-
163
14
  var _expectedIndex = 0,//expected index of next command
164
15
  _actualIndex,//actual index of next command by reading commandPath
165
16
  _index,//index of ':' char in command
@@ -168,107 +19,21 @@ var _expectedIndex = 0,//expected index of next command
168
19
  _input,//command
169
20
  _process;//host command process
170
21
 
171
- var Log = (function () {
172
- var forceFlush = [],
173
- N = "$MODE" == "FLUSH" ? 16384 : 0,
174
- i = N;
175
- while (i--) {
176
- forceFlush[i] = "*";
177
- }
178
- forceFlush = forceFlush.join('');
179
-
180
- function log_json(object)
181
- {
182
- UIALogger.logMessage("OUTPUT_JSON:\n"+JSON.stringify(object)+"\nEND_OUTPUT");
183
- }
184
-
185
- return {
186
- result: function (status, data) {
187
- log_json({"status": status, "value": data, "index":_actualIndex})
188
- if (forceFlush.length > 0) {
189
- UIALogger.logMessage(forceFlush);
190
- }
191
- },
192
- output: function (msg) {
193
- log_json({"output": msg,"last_index":_actualIndex});
194
- if (forceFlush.length > 0) {
195
- UIALogger.logMessage(forceFlush);
196
- }
197
- }
198
- };
199
- })();
200
-
201
-
202
- function findAlertViewText(alert) {
203
- if (!alert) {
204
- return false;
205
- }
206
- var txt = alert.name(),
207
- txts;
208
- if (txt == null) {
209
- txts = alert.staticTexts();
210
- if (txts != null && txts.length > 0) {
211
- txt = txts[0].name();
212
- }
213
- }
214
- return txt;
215
- }
216
-
217
- function isLocationPrompt(alert) {
218
- var exps = [
219
-
220
- ["Tillad", /bruge din lokalitet, når du bruger appen/],
221
- ["Tillad", /også når du ikke bruger appen/],
222
- ["OK", /vil bruge din aktuelle placering/],
223
- ["OK", /Would Like to Use Your Current Location/],
224
- ["Ja", /Darf (?:.)+ Ihren aktuellen Ort verwenden/],
225
- ["Allow", /access your location/],
226
- ["OK", /Would Like to Access Your Photos/],
227
- ["OK", /Would Like to Access Your Contacts/],
228
- ["OK", /Location Accuracy/],
229
- ["OK", /запрашивает разрешение на использование Ващей текущей пгеопозиции/],
230
- ["OK", /Access the Microphone/],
231
- ["OK", /Would Like to Access Your Calendar/],
232
- ["OK", /Would Like to Access Your Reminders/],
233
- ["OK", /Would Like to Access Your Motion Activity/],
234
- ["OK", /Would Like to Access the Camera/],
235
- ["OK", /Would Like to Access Your Motion & Fitness Activity/],
236
- ["OK", /Would Like Access to Twitter Accounts/],
237
- ["OK", /data available to nearby bluetooth devices/],
238
-
239
- // APNS
240
- ["OK", /enviarle notificaiones/],
241
- ["OK", /wil u berichten stuern/],
242
- ["OK", /Would Like to Send You Notifications/],
243
- ["OK", /would like to send you Push Notifications/]
244
- ],
245
- ans, exp,
246
- txt;
247
-
248
- txt = findAlertViewText(alert);
249
- Log.output({"output":"alert: "+txt}, true);
250
- for (var i = 0; i < exps.length; i++) {
251
- ans = exps[i][0];
252
- exp = exps[i][1];
253
- if (exp.test(txt)) {
254
- return ans;
255
- }
256
- }
257
- return false;
258
- }
22
+ <%= render_template("lib/log.js"); %>
23
+ <%= render_template("lib/on_alert.js"); %>
259
24
 
260
25
  UIATarget.onAlert = function (alert) {
261
26
  Log.output({"output":"on alert"}, true);
262
27
  var target = UIATarget.localTarget();
263
28
  target.pushTimeout(10);
264
- function attemptTouchOKOnLocation(retry_count) {
29
+ function dismissPrivacyAlert(retry_count) {
265
30
  retry_count = retry_count || 0;
266
31
  if (retry_count >= 5) {
267
32
  Log.output("Maxed out retry (5) - unable to dismiss location dialog.");
268
33
  return;
269
34
  }
270
35
  try {
271
- var answer = isLocationPrompt(alert);
36
+ var answer = isPrivacyAlert(alert);
272
37
  if (answer) {
273
38
  alert.buttons()[answer].tap();
274
39
  }
@@ -279,11 +44,11 @@ UIATarget.onAlert = function (alert) {
279
44
  Log.output(e.toString());
280
45
  }
281
46
  target.delay(1);
282
- attemptTouchOKOnLocation(retry_count + 1);
47
+ dismissPrivacyAlert(retry_count + 1);
283
48
  }
284
49
  }
285
50
 
286
- attemptTouchOKOnLocation(0);
51
+ dismissPrivacyAlert(0);
287
52
  target.popTimeout();
288
53
  return true;
289
54
  };