poltergeistFork 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (43) hide show
  1. checksums.yaml +7 -0
  2. data/LICENSE +22 -0
  3. data/README.md +425 -0
  4. data/lib/capybara/poltergeist/browser.rb +426 -0
  5. data/lib/capybara/poltergeist/client.rb +151 -0
  6. data/lib/capybara/poltergeist/client/agent.coffee +423 -0
  7. data/lib/capybara/poltergeist/client/browser.coffee +497 -0
  8. data/lib/capybara/poltergeist/client/cmd.coffee +17 -0
  9. data/lib/capybara/poltergeist/client/compiled/agent.js +587 -0
  10. data/lib/capybara/poltergeist/client/compiled/browser.js +687 -0
  11. data/lib/capybara/poltergeist/client/compiled/cmd.js +31 -0
  12. data/lib/capybara/poltergeist/client/compiled/connection.js +25 -0
  13. data/lib/capybara/poltergeist/client/compiled/main.js +228 -0
  14. data/lib/capybara/poltergeist/client/compiled/node.js +88 -0
  15. data/lib/capybara/poltergeist/client/compiled/web_page.js +539 -0
  16. data/lib/capybara/poltergeist/client/connection.coffee +11 -0
  17. data/lib/capybara/poltergeist/client/main.coffee +99 -0
  18. data/lib/capybara/poltergeist/client/node.coffee +70 -0
  19. data/lib/capybara/poltergeist/client/pre/agent.js +587 -0
  20. data/lib/capybara/poltergeist/client/pre/browser.js +688 -0
  21. data/lib/capybara/poltergeist/client/pre/cmd.js +31 -0
  22. data/lib/capybara/poltergeist/client/pre/connection.js +25 -0
  23. data/lib/capybara/poltergeist/client/pre/main.js +228 -0
  24. data/lib/capybara/poltergeist/client/pre/node.js +88 -0
  25. data/lib/capybara/poltergeist/client/pre/web_page.js +540 -0
  26. data/lib/capybara/poltergeist/client/web_page.coffee +372 -0
  27. data/lib/capybara/poltergeist/command.rb +17 -0
  28. data/lib/capybara/poltergeist/cookie.rb +35 -0
  29. data/lib/capybara/poltergeist/driver.rb +394 -0
  30. data/lib/capybara/poltergeist/errors.rb +183 -0
  31. data/lib/capybara/poltergeist/inspector.rb +46 -0
  32. data/lib/capybara/poltergeist/json.rb +25 -0
  33. data/lib/capybara/poltergeist/network_traffic.rb +7 -0
  34. data/lib/capybara/poltergeist/network_traffic/error.rb +19 -0
  35. data/lib/capybara/poltergeist/network_traffic/request.rb +27 -0
  36. data/lib/capybara/poltergeist/network_traffic/response.rb +40 -0
  37. data/lib/capybara/poltergeist/node.rb +177 -0
  38. data/lib/capybara/poltergeist/server.rb +36 -0
  39. data/lib/capybara/poltergeist/utility.rb +9 -0
  40. data/lib/capybara/poltergeist/version.rb +5 -0
  41. data/lib/capybara/poltergeist/web_socket_server.rb +107 -0
  42. data/lib/capybara/poltergeistFork.rb +27 -0
  43. metadata +268 -0
@@ -0,0 +1,687 @@
1
+ var indexOf = [].indexOf || function(item) { for (var i = 0, l = this.length; i < l; i++) { if (i in this && this[i] === item) return i; } return -1; };
2
+
3
+ Poltergeist.Browser = (function() {
4
+ function Browser(width, height) {
5
+ this.width = width || 1024;
6
+ this.height = height || 768;
7
+ this.pages = [];
8
+ this.js_errors = true;
9
+ this._debug = false;
10
+ this._counter = 0;
11
+ this.processed_modal_messages = [];
12
+ this.confirm_processes = [];
13
+ this.prompt_responses = [];
14
+ this.s_width = 1280;
15
+ this.s_height = 800;
16
+ this.resetPage();
17
+ }
18
+
19
+ Browser.prototype.resetPage = function() {
20
+ var ref;
21
+ ref = [0, []], this._counter = ref[0], this.pages = ref[1];
22
+ if (this.page != null) {
23
+ if (!this.page.closed) {
24
+ if (this.page.currentUrl() !== 'about:blank') {
25
+ this.page.clearLocalStorage();
26
+ }
27
+ this.page.release();
28
+ }
29
+ phantom.clearCookies();
30
+ }
31
+ this.page = this.currentPage = new Poltergeist.WebPage;
32
+ this.page.setViewportSize({
33
+ width: this.width,
34
+ height: this.height
35
+ });
36
+ this.page.handle = "" + (this._counter++);
37
+ this.pages.push(this.page);
38
+ this.processed_modal_messages = [];
39
+ this.confirm_processes = [];
40
+ this.prompt_responses = [];
41
+ this.page["native"]().onAlert = (function(_this) {
42
+ return function(msg) {
43
+ _this.setModalMessage(msg);
44
+ };
45
+ })(this);
46
+ this.page["native"]().onConfirm = (function(_this) {
47
+ return function(msg) {
48
+ var process;
49
+ process = _this.confirm_processes.pop();
50
+ if (process === void 0) {
51
+ process = true;
52
+ }
53
+ _this.setModalMessage(msg);
54
+ return process;
55
+ };
56
+ })(this);
57
+ this.page["native"]().onPrompt = (function(_this) {
58
+ return function(msg, defaultVal) {
59
+ var response;
60
+ response = _this.prompt_responses.pop();
61
+ if (response === void 0 || response === false) {
62
+ response = defaultVal;
63
+ }
64
+ _this.setModalMessage(msg);
65
+ return response;
66
+ };
67
+ })(this);
68
+ this.page.onPageCreated = (function(_this) {
69
+ return function(newPage) {
70
+ var page;
71
+ page = new Poltergeist.WebPage(newPage);
72
+ page.handle = "" + (_this._counter++);
73
+ return _this.pages.push(page);
74
+ };
75
+ })(this);
76
+ };
77
+
78
+ Browser.prototype.getPageByHandle = function(handle) {
79
+ return this.pages.filter(function(p) {
80
+ return !p.closed && p.handle === handle;
81
+ })[0];
82
+ };
83
+
84
+ Browser.prototype.runCommand = function(command) {
85
+ this.current_command = command;
86
+ this.currentPage.state = 'default';
87
+ return this[command.name].apply(this, command.args);
88
+ };
89
+
90
+ Browser.prototype.debug = function(message) {
91
+ if (this._debug) {
92
+ return console.log("poltergeist [" + (new Date().getTime()) + "] " + message);
93
+ }
94
+ };
95
+
96
+ Browser.prototype.setModalMessage = function(msg) {
97
+ this.processed_modal_messages.push(msg);
98
+ };
99
+
100
+ Browser.prototype.add_extension = function(extension) {
101
+ this.currentPage.injectExtension(extension);
102
+ return this.current_command.sendResponse('success');
103
+ };
104
+
105
+ Browser.prototype.node = function(page_id, id) {
106
+ if (this.currentPage.id === page_id) {
107
+ return this.currentPage.get(id);
108
+ } else {
109
+ throw new Poltergeist.ObsoleteNode;
110
+ }
111
+ };
112
+
113
+ Browser.prototype.visit = function(url) {
114
+ var command, prevUrl;
115
+ this.currentPage.state = 'loading';
116
+ this.processed_modal_messages = [];
117
+ this.confirm_processes = [];
118
+ this.prompt_responses = [];
119
+ prevUrl = this.currentPage.source === null ? 'about:blank' : this.currentPage.currentUrl();
120
+ this.currentPage.open(url);
121
+ if (/#/.test(url) && prevUrl.split('#')[0] === url.split('#')[0]) {
122
+ this.currentPage.state = 'default';
123
+ return this.current_command.sendResponse({
124
+ status: 'success'
125
+ });
126
+ } else {
127
+ command = this.current_command;
128
+ this.currentPage.waitState('default', (function(_this) {
129
+ return function() {
130
+ if (_this.currentPage.statusCode === null && _this.currentPage.status === 'fail') {
131
+ return command.sendError(new Poltergeist.StatusFailError(url));
132
+ } else {
133
+ return command.sendResponse({
134
+ status: _this.currentPage.status
135
+ });
136
+ }
137
+ };
138
+ })(this));
139
+ }
140
+ };
141
+
142
+ Browser.prototype.current_url = function() {
143
+ return this.current_command.sendResponse(this.currentPage.currentUrl());
144
+ };
145
+
146
+ Browser.prototype.status_code = function() {
147
+ return this.current_command.sendResponse(this.currentPage.statusCode);
148
+ };
149
+
150
+ Browser.prototype.body = function() {
151
+ return this.current_command.sendResponse(this.currentPage.content());
152
+ };
153
+
154
+ Browser.prototype.source = function() {
155
+ return this.current_command.sendResponse(this.currentPage.source);
156
+ };
157
+
158
+ Browser.prototype.title = function() {
159
+ return this.current_command.sendResponse(this.currentPage.title());
160
+ };
161
+
162
+ Browser.prototype.find = function(method, selector) {
163
+ return this.current_command.sendResponse({
164
+ page_id: this.currentPage.id,
165
+ ids: this.currentPage.find(method, selector)
166
+ });
167
+ };
168
+
169
+ Browser.prototype.find_within = function(page_id, id, method, selector) {
170
+ return this.current_command.sendResponse(this.node(page_id, id).find(method, selector));
171
+ };
172
+
173
+ Browser.prototype.all_text = function(page_id, id) {
174
+ return this.current_command.sendResponse(this.node(page_id, id).allText());
175
+ };
176
+
177
+ Browser.prototype.visible_text = function(page_id, id) {
178
+ return this.current_command.sendResponse(this.node(page_id, id).visibleText());
179
+ };
180
+
181
+ Browser.prototype.delete_text = function(page_id, id) {
182
+ return this.current_command.sendResponse(this.node(page_id, id).deleteText());
183
+ };
184
+
185
+ Browser.prototype.property = function(page_id, id, name) {
186
+ return this.current_command.sendResponse(this.node(page_id, id).getProperty(name));
187
+ };
188
+
189
+ Browser.prototype.attribute = function(page_id, id, name) {
190
+ return this.current_command.sendResponse(this.node(page_id, id).getAttribute(name));
191
+ };
192
+
193
+ Browser.prototype.attributes = function(page_id, id, name) {
194
+ return this.current_command.sendResponse(this.node(page_id, id).getAttributes());
195
+ };
196
+
197
+ Browser.prototype.parents = function(page_id, id) {
198
+ return this.current_command.sendResponse(this.node(page_id, id).parentIds());
199
+ };
200
+
201
+ Browser.prototype.value = function(page_id, id) {
202
+ return this.current_command.sendResponse(this.node(page_id, id).value());
203
+ };
204
+
205
+ Browser.prototype.set = function(page_id, id, value) {
206
+ this.node(page_id, id).set(value);
207
+ return this.current_command.sendResponse(true);
208
+ };
209
+
210
+ Browser.prototype.select_file = function(page_id, id, value) {
211
+ var node;
212
+ node = this.node(page_id, id);
213
+ this.currentPage.beforeUpload(node.id);
214
+ this.currentPage.uploadFile('[_poltergeist_selected]', value);
215
+ this.currentPage.afterUpload(node.id);
216
+ if (phantom.version.major === 2) {
217
+ return this.click(page_id, id);
218
+ } else {
219
+ return this.current_command.sendResponse(true);
220
+ }
221
+ };
222
+
223
+ Browser.prototype.select = function(page_id, id, value) {
224
+ return this.current_command.sendResponse(this.node(page_id, id).select(value));
225
+ };
226
+
227
+ Browser.prototype.tag_name = function(page_id, id) {
228
+ return this.current_command.sendResponse(this.node(page_id, id).tagName());
229
+ };
230
+
231
+ Browser.prototype.visible = function(page_id, id) {
232
+ return this.current_command.sendResponse(this.node(page_id, id).isVisible());
233
+ };
234
+
235
+ Browser.prototype.disabled = function(page_id, id) {
236
+ return this.current_command.sendResponse(this.node(page_id, id).isDisabled());
237
+ };
238
+
239
+ Browser.prototype.path = function(page_id, id) {
240
+ return this.current_command.sendResponse(this.node(page_id, id).path());
241
+ };
242
+
243
+ Browser.prototype.evaluate = function(script) {
244
+ return this.current_command.sendResponse(this.currentPage.evaluate("function() { return " + script + " }"));
245
+ };
246
+
247
+ Browser.prototype.execute = function(script) {
248
+ this.currentPage.execute("function() { " + script + " }");
249
+ return this.current_command.sendResponse(true);
250
+ };
251
+
252
+ Browser.prototype.frameUrl = function(frame_name) {
253
+ return this.currentPage.frameUrl(frame_name);
254
+ };
255
+
256
+ Browser.prototype.pushFrame = function(command, name, timeout) {
257
+ var frame, ref;
258
+ if (Array.isArray(name)) {
259
+ frame = this.node.apply(this, name);
260
+ name = frame.getAttribute('name') || frame.getAttribute('id');
261
+ if (!name) {
262
+ frame.setAttribute('name', "_random_name_" + (new Date().getTime()));
263
+ name = frame.getAttribute('name');
264
+ }
265
+ }
266
+ if (ref = this.frameUrl(name), indexOf.call(this.currentPage.blockedUrls(), ref) >= 0) {
267
+ return command.sendResponse(true);
268
+ } else if (this.currentPage.pushFrame(name)) {
269
+ if (this.currentPage.currentUrl() === 'about:blank') {
270
+ this.currentPage.state = 'awaiting_frame_load';
271
+ return this.currentPage.waitState('default', (function(_this) {
272
+ return function() {
273
+ return command.sendResponse(true);
274
+ };
275
+ })(this));
276
+ } else {
277
+ return command.sendResponse(true);
278
+ }
279
+ } else {
280
+ if (new Date().getTime() < timeout) {
281
+ return setTimeout(((function(_this) {
282
+ return function() {
283
+ return _this.pushFrame(command, name, timeout);
284
+ };
285
+ })(this)), 50);
286
+ } else {
287
+ return command.sendError(new Poltergeist.FrameNotFound(name));
288
+ }
289
+ }
290
+ };
291
+
292
+ Browser.prototype.push_frame = function(name, timeout) {
293
+ if (timeout == null) {
294
+ timeout = (new Date().getTime()) + 2000;
295
+ }
296
+ return this.pushFrame(this.current_command, name, timeout);
297
+ };
298
+
299
+ Browser.prototype.pop_frame = function() {
300
+ return this.current_command.sendResponse(this.currentPage.popFrame());
301
+ };
302
+
303
+ Browser.prototype.window_handles = function() {
304
+ var handles;
305
+ handles = this.pages.filter(function(p) {
306
+ return !p.closed;
307
+ }).map(function(p) {
308
+ return p.handle;
309
+ });
310
+ return this.current_command.sendResponse(handles);
311
+ };
312
+
313
+ Browser.prototype.window_handle = function(name) {
314
+ var handle, page;
315
+ if (name == null) {
316
+ name = null;
317
+ }
318
+ handle = name ? (page = this.pages.filter(function(p) {
319
+ return !p.closed && p.windowName() === name;
320
+ })[0], page ? page.handle : null) : this.currentPage.handle;
321
+ return this.current_command.sendResponse(handle);
322
+ };
323
+
324
+ Browser.prototype.switch_to_window = function(handle) {
325
+ var command, page;
326
+ command = this.current_command;
327
+ page = this.getPageByHandle(handle);
328
+ if (page) {
329
+ if (page !== this.currentPage) {
330
+ return page.waitState('default', (function(_this) {
331
+ return function() {
332
+ _this.currentPage = page;
333
+ return command.sendResponse(true);
334
+ };
335
+ })(this));
336
+ } else {
337
+ return command.sendResponse(true);
338
+ }
339
+ } else {
340
+ throw new Poltergeist.NoSuchWindowError;
341
+ }
342
+ };
343
+
344
+ Browser.prototype.open_new_window = function() {
345
+ this.execute('window.open()');
346
+ return this.current_command.sendResponse(true);
347
+ };
348
+
349
+ Browser.prototype.close_window = function(handle) {
350
+ var page;
351
+ page = this.getPageByHandle(handle);
352
+ if (page) {
353
+ page.release();
354
+ return this.current_command.sendResponse(true);
355
+ } else {
356
+ return this.current_command.sendResponse(false);
357
+ }
358
+ };
359
+
360
+ Browser.prototype.mouse_event = function(page_id, id, name) {
361
+ var command, node;
362
+ node = this.node(page_id, id);
363
+ this.currentPage.state = 'mouse_event';
364
+ this.last_mouse_event = node.mouseEvent(name);
365
+ command = this.current_command;
366
+ return setTimeout((function(_this) {
367
+ return function() {
368
+ if (_this.currentPage.state === 'mouse_event') {
369
+ _this.currentPage.state = 'default';
370
+ return command.sendResponse({
371
+ position: _this.last_mouse_event
372
+ });
373
+ } else {
374
+ return _this.currentPage.waitState('default', function() {
375
+ return command.sendResponse({
376
+ position: _this.last_mouse_event
377
+ });
378
+ });
379
+ }
380
+ };
381
+ })(this), 5);
382
+ };
383
+
384
+ Browser.prototype.click = function(page_id, id) {
385
+ return this.mouse_event(page_id, id, 'click');
386
+ };
387
+
388
+ Browser.prototype.right_click = function(page_id, id) {
389
+ return this.mouse_event(page_id, id, 'rightclick');
390
+ };
391
+
392
+ Browser.prototype.double_click = function(page_id, id) {
393
+ return this.mouse_event(page_id, id, 'doubleclick');
394
+ };
395
+
396
+ Browser.prototype.hover = function(page_id, id) {
397
+ return this.mouse_event(page_id, id, 'mousemove');
398
+ };
399
+
400
+ Browser.prototype.click_coordinates = function(x, y) {
401
+ this.currentPage.sendEvent('click', x, y);
402
+ return this.current_command.sendResponse({
403
+ click: {
404
+ x: x,
405
+ y: y
406
+ }
407
+ });
408
+ };
409
+
410
+ Browser.prototype.drag = function(page_id, id, other_id) {
411
+ this.node(page_id, id).dragTo(this.node(page_id, other_id));
412
+ return this.current_command.sendResponse(true);
413
+ };
414
+
415
+ Browser.prototype.drag_by = function(page_id, id, x, y) {
416
+ this.node(page_id, id).dragBy(x, y);
417
+ return this.current_command.sendResponse(true);
418
+ };
419
+
420
+ Browser.prototype.trigger = function(page_id, id, event) {
421
+ this.node(page_id, id).trigger(event);
422
+ return this.current_command.sendResponse(event);
423
+ };
424
+
425
+ Browser.prototype.equals = function(page_id, id, other_id) {
426
+ return this.current_command.sendResponse(this.node(page_id, id).isEqual(this.node(page_id, other_id)));
427
+ };
428
+
429
+ Browser.prototype.reset = function() {
430
+ this.resetPage();
431
+ return this.current_command.sendResponse(true);
432
+ };
433
+
434
+ Browser.prototype.scroll_to = function(left, top) {
435
+ this.currentPage.setScrollPosition({
436
+ left: left,
437
+ top: top
438
+ });
439
+ return this.current_command.sendResponse(true);
440
+ };
441
+
442
+ Browser.prototype.send_keys = function(page_id, id, keys) {
443
+ var i, j, k, key, len, len1, len2, modifier_code, modifier_key, modifier_keys, sequence, target;
444
+ target = this.node(page_id, id);
445
+ if (!target.containsSelection()) {
446
+ target.mouseEvent('click');
447
+ }
448
+ for (i = 0, len = keys.length; i < len; i++) {
449
+ sequence = keys[i];
450
+ key = sequence.key != null ? this.currentPage.keyCode(sequence.key) : sequence;
451
+ if (sequence.modifier != null) {
452
+ modifier_keys = this.currentPage.keyModifierKeys(sequence.modifier);
453
+ modifier_code = this.currentPage.keyModifierCode(sequence.modifier);
454
+ for (j = 0, len1 = modifier_keys.length; j < len1; j++) {
455
+ modifier_key = modifier_keys[j];
456
+ this.currentPage.sendEvent('keydown', modifier_key);
457
+ }
458
+ this.currentPage.sendEvent('keypress', key, null, null, modifier_code);
459
+ for (k = 0, len2 = modifier_keys.length; k < len2; k++) {
460
+ modifier_key = modifier_keys[k];
461
+ this.currentPage.sendEvent('keyup', modifier_key);
462
+ }
463
+ } else {
464
+ this.currentPage.sendEvent('keypress', key);
465
+ }
466
+ }
467
+ return this.current_command.sendResponse(true);
468
+ };
469
+
470
+ Browser.prototype.render_base64 = function(format, full, selector) {
471
+ var encoded_image;
472
+ if (selector == null) {
473
+ selector = null;
474
+ }
475
+ this.set_clip_rect(full, selector);
476
+ encoded_image = this.currentPage.renderBase64(format);
477
+ return this.current_command.sendResponse(encoded_image);
478
+ };
479
+
480
+ Browser.prototype.render = function(path, full, selector) {
481
+ var dimensions;
482
+ if (selector == null) {
483
+ selector = null;
484
+ }
485
+ dimensions = this.set_clip_rect(full, selector);
486
+ this.currentPage.setScrollPosition({
487
+ left: 0,
488
+ top: 0
489
+ });
490
+ this.currentPage.render(path);
491
+ this.currentPage.setScrollPosition({
492
+ left: dimensions.left,
493
+ top: dimensions.top
494
+ });
495
+ return this.current_command.sendResponse(true);
496
+ };
497
+
498
+ Browser.prototype.set_clip_rect = function(full, selector) {
499
+ var dimensions, document, rect, ref, viewport;
500
+ dimensions = this.currentPage.validatedDimensions();
501
+ ref = [dimensions.document, dimensions.viewport], document = ref[0], viewport = ref[1];
502
+ rect = full ? {
503
+ left: 0,
504
+ top: 0,
505
+ width: document.width,
506
+ height: document.height
507
+ } : selector != null ? this.currentPage.elementBounds(selector) : {
508
+ left: 0,
509
+ top: 0,
510
+ width: viewport.width,
511
+ height: viewport.height
512
+ };
513
+ this.currentPage.setClipRect(rect);
514
+ return dimensions;
515
+ };
516
+
517
+ Browser.prototype.set_paper_size = function(size) {
518
+ this.currentPage.setPaperSize(size);
519
+ return this.current_command.sendResponse(true);
520
+ };
521
+
522
+ Browser.prototype.set_zoom_factor = function(zoom_factor) {
523
+ this.currentPage.setZoomFactor(zoom_factor);
524
+ return this.current_command.sendResponse(true);
525
+ };
526
+
527
+ Browser.prototype.set_screen_size = function(s_width, s_height) {
528
+ this.currentPage.setScreenSize({
529
+ s_width: s_width,
530
+ s_height: s_height
531
+ });
532
+ return this.current_command.sendResponse(true);
533
+ };
534
+
535
+ Browser.prototype.resize = function(width, height) {
536
+ this.currentPage.setViewportSize({
537
+ width: width,
538
+ height: height
539
+ });
540
+ return this.current_command.sendResponse(true);
541
+ };
542
+
543
+ Browser.prototype.network_traffic = function() {
544
+ return this.current_command.sendResponse(this.currentPage.networkTraffic());
545
+ };
546
+
547
+ Browser.prototype.clear_network_traffic = function() {
548
+ this.currentPage.clearNetworkTraffic();
549
+ return this.current_command.sendResponse(true);
550
+ };
551
+
552
+ Browser.prototype.get_headers = function() {
553
+ return this.current_command.sendResponse(this.currentPage.getCustomHeaders());
554
+ };
555
+
556
+ Browser.prototype.set_headers = function(headers) {
557
+ if (headers['User-Agent']) {
558
+ this.currentPage.setUserAgent(headers['User-Agent']);
559
+ }
560
+ this.currentPage.setCustomHeaders(headers);
561
+ return this.current_command.sendResponse(true);
562
+ };
563
+
564
+ Browser.prototype.add_headers = function(headers) {
565
+ var allHeaders, name, value;
566
+ allHeaders = this.currentPage.getCustomHeaders();
567
+ for (name in headers) {
568
+ value = headers[name];
569
+ allHeaders[name] = value;
570
+ }
571
+ return this.set_headers(allHeaders);
572
+ };
573
+
574
+ Browser.prototype.add_header = function(header, permanent) {
575
+ if (!permanent) {
576
+ this.currentPage.addTempHeader(header);
577
+ }
578
+ return this.add_headers(header);
579
+ };
580
+
581
+ Browser.prototype.response_headers = function() {
582
+ return this.current_command.sendResponse(this.currentPage.responseHeaders());
583
+ };
584
+
585
+ Browser.prototype.cookies = function() {
586
+ return this.current_command.sendResponse(this.currentPage.cookies());
587
+ };
588
+
589
+ Browser.prototype.set_cookie = function(cookie) {
590
+ phantom.addCookie(cookie);
591
+ return this.current_command.sendResponse(true);
592
+ };
593
+
594
+ Browser.prototype.remove_cookie = function(name) {
595
+ this.currentPage.deleteCookie(name);
596
+ return this.current_command.sendResponse(true);
597
+ };
598
+
599
+ Browser.prototype.clear_cookies = function() {
600
+ phantom.clearCookies();
601
+ return this.current_command.sendResponse(true);
602
+ };
603
+
604
+ Browser.prototype.cookies_enabled = function(flag) {
605
+ phantom.cookiesEnabled = flag;
606
+ return this.current_command.sendResponse(true);
607
+ };
608
+
609
+ Browser.prototype.set_http_auth = function(user, password) {
610
+ this.currentPage.setHttpAuth(user, password);
611
+ return this.current_command.sendResponse(true);
612
+ };
613
+
614
+ Browser.prototype.set_js_errors = function(value) {
615
+ this.js_errors = value;
616
+ return this.current_command.sendResponse(true);
617
+ };
618
+
619
+ Browser.prototype.set_debug = function(value) {
620
+ this._debug = value;
621
+ return this.current_command.sendResponse(true);
622
+ };
623
+
624
+ Browser.prototype.exit = function() {
625
+ return phantom.exit();
626
+ };
627
+
628
+ Browser.prototype.noop = function() {};
629
+
630
+ Browser.prototype.browser_error = function() {
631
+ throw new Error('zomg');
632
+ };
633
+
634
+ Browser.prototype.go_back = function() {
635
+ var command;
636
+ command = this.current_command;
637
+ if (this.currentPage.canGoBack) {
638
+ this.currentPage.state = 'loading';
639
+ this.currentPage.goBack();
640
+ return this.currentPage.waitState('default', (function(_this) {
641
+ return function() {
642
+ return command.sendResponse(true);
643
+ };
644
+ })(this));
645
+ } else {
646
+ return command.sendResponse(false);
647
+ }
648
+ };
649
+
650
+ Browser.prototype.go_forward = function() {
651
+ var command;
652
+ command = this.current_command;
653
+ if (this.currentPage.canGoForward) {
654
+ this.currentPage.state = 'loading';
655
+ this.currentPage.goForward();
656
+ return this.currentPage.waitState('default', (function(_this) {
657
+ return function() {
658
+ return command.sendResponse(true);
659
+ };
660
+ })(this));
661
+ } else {
662
+ return command.sendResponse(false);
663
+ }
664
+ };
665
+
666
+ Browser.prototype.set_url_blacklist = function() {
667
+ this.currentPage.urlBlacklist = Array.prototype.slice.call(arguments);
668
+ return this.current_command.sendResponse(true);
669
+ };
670
+
671
+ Browser.prototype.set_confirm_process = function(process) {
672
+ this.confirm_processes.push(process);
673
+ return this.current_command.sendResponse(true);
674
+ };
675
+
676
+ Browser.prototype.set_prompt_response = function(response) {
677
+ this.prompt_responses.push(response);
678
+ return this.current_command.sendResponse(true);
679
+ };
680
+
681
+ Browser.prototype.modal_message = function() {
682
+ return this.current_command.sendResponse(this.processed_modal_messages.shift());
683
+ };
684
+
685
+ return Browser;
686
+
687
+ })();