Coverage

87%
2438
2139
299

zombie/index.js

58%
31
18
13
LineHitsSource
1// Generated by CoffeeScript 1.3.3
21var Browser, Path, Util, contextify, listen, visit;
3
41Browser = require("./browser");
5
61Path = require("path");
7
81Util = require("util");
9
101try {
111 contextify = Path.resolve(require.resolve("jsdom"), "../../node_modules/contextify");
121 require(contextify);
13} catch (ex) {
140 throw new Error("Zombie will not run correctly without the Contextify module");
15}
16
171visit = function(url, options, callback) {
1818 return new Browser(options).visit(url, options, callback);
19};
20
211listen = function(port, callback) {
220 return require("./zombie/protocol").listen(port, callback);
23};
24
251console.depth = 0;
26
271console.showHidden = false;
28
291console.log = function() {
300 var arg, formatted;
310 formatted = (function() {
320 var _i, _len, _results;
330 _results = [];
340 for (_i = 0, _len = arguments.length; _i < _len; _i++) {
350 arg = arguments[_i];
360 _results.push(typeof arg === "string" ? arg : Util.inspect(arg, console.showHidden, console.depth));
37 }
380 return _results;
39 }).apply(this, arguments);
400 if (typeof Util.format === 'function') {
410 return process.stdout.write(Util.format.apply(this, formatted) + "\n");
42 } else {
430 return process.stdout.write(formatted.join(" ") + "\n");
44 }
45};
46
471Browser.listen = listen;
48
491Browser.visit = visit;
50
511Browser.debug = !!process.env.DEBUG;
52
531Browser.Browser = Browser;
54
551module.exports = Browser;

zombie/browser.js

86%
537
463
74
LineHitsSource
1// Generated by CoffeeScript 1.3.3
21var BROWSER_OPTIONS, Browser, Cache, Cookies, Credentials, EventEmitter, EventLoop, FS, GLOBAL_OPTIONS, HTML, HTML5, Interact, JSDOM, MOUSE_EVENT_NAMES, Mime, PACKAGE, Path, Q, Resources, Storages, URL, VERSION, Windows, XHR, deprecated,
3 __hasProp = {}.hasOwnProperty,
47 __extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; },
50 __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; };
6
71require("./jsdom_patches");
8
91require("./forms");
10
111require("./xpath");
12
131deprecated = require("./helpers").deprecated;
14
151Cache = require("./cache");
16
171Cookies = require("./cookies");
18
191EventEmitter = require("events").EventEmitter;
20
211EventLoop = require("./eventloop");
22
231FS = require("fs");
24
251HTML5 = require("html5").HTML5;
26
271Interact = require("./interact");
28
291JSDOM = require("jsdom");
30
311Mime = require("mime");
32
331Q = require("q");
34
351Path = require("path");
36
371Resources = require("./resources");
38
391Storages = require("./storage");
40
411URL = require("url");
42
431Windows = require("./windows");
44
451XHR = require("./xhr");
46
471BROWSER_OPTIONS = ["debug", "headers", "htmlParser", "loadCSS", "maxWait", "proxy", "referer", "runScripts", "silent", "site", "userAgent", "waitFor", "name"];
48
491GLOBAL_OPTIONS = ["debug", "headers", "htmlParser", "loadCSS", "maxWait", "proxy", "runScripts", "silent", "site", "userAgent", "waitFor"];
50
511PACKAGE = JSON.parse(require("fs").readFileSync(__dirname + "/../../package.json"));
52
531VERSION = PACKAGE.version;
54
551HTML = JSDOM.dom.level3.html;
56
571MOUSE_EVENT_NAMES = ["mousedown", "mousemove", "mouseup"];
58
591Browser = (function(_super) {
60
611 __extends(Browser, _super);
62
631 function Browser(options) {
64195 var name, _i, _len,
65 _this = this;
66195 if (options == null) {
67175 options = {};
68 }
69195 this._cache = new Cache();
70195 this._cookies = new Cookies();
71195 this._eventloop = new EventLoop(this);
72195 this._storages = new Storages();
73195 this._interact = Interact.use(this);
74195 this._xhr = XHR.use(this._cache);
75195 this.on("error", function(error) {
7615 _this.errors.push(error);
7715 return _this.log(error.message, error.stack);
78 });
79195 this.referer = void 0;
80195 this.name = "nodejs";
81195 for (_i = 0, _len = BROWSER_OPTIONS.length; _i < _len; _i++) {
822535 name = BROWSER_OPTIONS[_i];
832535 if (options.hasOwnProperty(name)) {
8420 this[name] = options[name];
852515 } else if (~GLOBAL_OPTIONS.indexOf(name)) {
862144 this[name] = Browser[name];
87 }
88 }
89195 this._setCredentials(options.credentials || Browser.credentials);
90195 this.errors = [];
91195 this.resources = new Resources(this);
92195 this.windows = new Windows(this);
93 }
94
951 Browser.debug = false;
96
971 Browser.htmlParser = HTML5;
98
991 Browser.loadCSS = true;
100
1011 Browser.maxWait = "5s";
102
1031 Browser.proxy = null;
104
1051 Browser.runScripts = true;
106
1071 Browser.silent = false;
108
1091 Browser.userAgent = "Mozilla/5.0 Chrome/10.0.613.0 Safari/534.15 Zombie.js/" + VERSION;
110
1111 Browser.site = void 0;
112
1131 Browser.waitFor = "0.5s";
114
1151 Browser.headers = {};
116
1171 Browser.prototype.withOptions = function(options, fn) {
118191 var k, restore, v, _ref,
119 _this = this;
120191 if (options) {
1214 restore = {};
1224 for (k in options) {
1234 v = options[k];
1244 if (~BROWSER_OPTIONS.indexOf(k)) {
1253 _ref = [this[k], v], restore[k] = _ref[0], this[k] = _ref[1];
126 }
127 }
1284 this._setCredentials(options.credentials);
1294 return function() {
1304 var _results;
1314 _results = [];
1324 for (k in restore) {
1333 v = restore[k];
1343 _results.push(_this[k] = v);
135 }
1364 return _results;
137 };
138 } else {
139187 return function() {};
140 }
141 };
142
1431 Browser.prototype.fork = function() {
1441 var forked, name, _i, _len;
1451 forked = new Browser();
1461 forked.loadCookies(this.saveCookies());
1471 forked.loadStorage(this.saveStorage());
1481 forked.loadHistory(this.saveHistory());
1491 forked.location = this.location;
1501 for (_i = 0, _len = BROWSER_OPTIONS.length; _i < _len; _i++) {
15113 name = BROWSER_OPTIONS[_i];
15213 forked[name] = this[name];
153 }
1541 return forked;
155 };
156
1571 Browser.prototype.__defineGetter__("window", function() {
1581572 return this.windows.current;
159 });
160
1611 Browser.prototype.open = function(options) {
16224 this._eventloop.reset();
16324 this.errors = [];
16424 this.resources.clear();
16524 return this.windows.open(options || {});
166 };
167
1681 Browser.prototype.__defineGetter__("error", function() {
1692 return this.errors[this.errors.length - 1];
170 });
171
1721 Browser.prototype.wait = function(duration, callback) {
173329 var deferred, last, _ref,
174 _this = this;
175329 if (arguments.length < 2 && typeof duration === "function") {
17637 _ref = [duration, null], callback = _ref[0], duration = _ref[1];
177 }
178329 deferred = Q.defer();
179329 last = this.errors[this.errors.length - 1];
180329 this._eventloop.wait(this.window, duration, function(error) {
181329 var newest;
182329 newest = _this.errors[_this.errors.length - 1];
183329 if (!(error || last === newest)) {
18414 error = newest;
185 }
186329 if (error) {
18714 deferred.reject(error);
188 } else {
189315 deferred.resolve();
190 }
191329 if (callback) {
192231 return callback(error);
193 }
194 });
195329 if (!callback) {
19698 return deferred.promise;
197 }
198 };
199
2001 Browser.prototype.fire = function(name, target, callback) {
201105 var event, type;
202105 type = __indexOf.call(MOUSE_EVENT_NAMES, name) >= 0 ? "MouseEvents" : "HTMLEvents";
203105 event = this.window.document.createEvent(type);
204105 event.initEvent(name, true, true);
205105 this.dispatchEvent(target, event);
206105 return this.wait(callback);
207 };
208
2091 Browser.prototype.dispatchEvent = function(target, event) {
210226 return this._eventloop.dispatch(target, event);
211 };
212
2131 Browser.prototype.queryAll = function(selector, context) {
21497 var ret;
21597 if (selector) {
21688 context || (context = this.document);
21788 ret = context.querySelectorAll(selector);
21888 return Array.prototype.slice.call(ret, 0);
219 } else {
2209 context || (context = this.document.documentElement);
2219 return [context];
222 }
223 };
224
2251 Browser.prototype.query = function(selector, context) {
22655 context || (context = this.document);
22755 if (selector) {
22855 return context.querySelector(selector);
229 } else {
2300 return context;
231 }
232 };
233
2341 Browser.prototype.$$ = function(selector, context) {
2352 return this.query(selector, context);
236 };
237
2381 Browser.prototype.querySelector = function(selector) {
239263 var _ref;
240263 return (_ref = this.window.document) != null ? _ref.querySelector(selector) : void 0;
241 };
242
2431 Browser.prototype.querySelectorAll = function(selector) {
24472 var _ref;
24572 return (_ref = this.window.document) != null ? _ref.querySelectorAll(selector) : void 0;
246 };
247
2481 Browser.prototype.text = function(selector, context) {
24982 if (this.document.documentElement) {
25082 return this.queryAll(selector, context).map(function(e) {
25182 return e.textContent;
252 }).join("").trim().replace(/\s+/g, " ");
253 }
2540 return this.source;
255 };
256
2571 Browser.prototype.html = function(selector, context) {
25814 if (this.document.documentElement) {
25914 return this.queryAll(selector, context).map(function(e) {
26014 return e.outerHTML.trim();
261 }).join("");
262 }
2630 return this.source;
264 };
265
2661 Browser.prototype.css = function(selector, context) {
2670 deprecated("Browser.css is deprecated, please use browser.query and browser.queryAll instead.");
2680 return this.queryAll(selector, context);
269 };
270
2711 Browser.prototype.xpath = function(expression, context) {
27230 return this.document.evaluate(expression, context || this.document.documentElement);
273 };
274
2751 Browser.prototype.__defineGetter__("document", function() {
276356 var _ref;
277356 return (_ref = this.window) != null ? _ref.document : void 0;
278 });
279
2801 Browser.prototype.__defineGetter__("body", function() {
2812 var _ref;
2822 return (_ref = this.window.document) != null ? _ref.querySelector("body") : void 0;
283 });
284
2851 Browser.prototype.__defineGetter__("statusCode", function() {
286145 var _ref;
287145 return (_ref = this.response) != null ? _ref[0] : void 0;
288 });
289
2901 Browser.prototype.__defineGetter__("success", function() {
2916 return this.statusCode >= 200 && this.statusCode < 300;
292 });
293
2941 Browser.prototype.__defineGetter__("redirected", function() {
2953 var _ref, _ref1;
2963 return !!((_ref = this.resources.last) != null ? (_ref1 = _ref.response) != null ? _ref1.redirected : void 0 : void 0);
297 });
298
2991 Browser.prototype.__defineGetter__("source", function() {
3002 var _ref;
3012 return (_ref = this.response) != null ? _ref[2] : void 0;
302 });
303
3041 Browser.prototype.close = function() {
3051 var _results;
3061 _results = [];
3071 while (this.windows.current) {
3081 _results.push(this.windows.close());
309 }
3101 return _results;
311 };
312
3131 Browser.prototype.visit = function(url, options, callback) {
314191 var deferred, duration, reset_options, site, _ref, _ref1,
315 _this = this;
316191 if (typeof options === "function" && !callback) {
317122 _ref = [options, null], callback = _ref[0], options = _ref[1];
318 }
319191 if (typeof options !== "object") {
32065 _ref1 = [options, null], duration = _ref1[0], options = _ref1[1];
321 }
322191 deferred = Q.defer();
323191 reset_options = this.withOptions(options);
324191 if (site = this.site) {
325191 if (!/^(https?:|file:)/i.test(site)) {
326191 site = "http://" + site;
327 }
328191 url = URL.resolve(site, URL.parse(URL.format(url)));
329 }
330191 this.window.history._assign(url);
331191 this.wait(duration, function(error) {
332191 reset_options();
333191 if (error) {
33411 deferred.reject(error);
335 } else {
336180 deferred.resolve();
337 }
338191 if (callback) {
339126 return callback(error, _this, _this.statusCode, _this.errors);
340 }
341 });
342191 if (!callback) {
34365 return deferred.promise;
344 }
345 };
346
3471 Browser.prototype.load = function(html, callback) {
3481 var deferred, first;
3491 try {
3501 this.errors = [];
3511 this.document.open();
3521 this.document.write(html);
3531 this.document.close();
354 } catch (error) {
3550 this.emit("error", error);
356 }
3571 first = this.errors[0];
3581 if (first) {
3590 if (callback) {
3600 process.nextTick(function() {
3610 return callback(first);
362 });
363 } else {
3640 deferred = Q.defer();
3650 deferred.reject(first);
3660 return deferred.promise;
367 }
368 } else {
3691 return this.wait(callback);
370 }
371 };
372
3731 Browser.prototype.__defineGetter__("location", function() {
37470 return this.window.location;
375 });
376
3771 Browser.prototype.__defineSetter__("location", function(url) {
3781 return this.window.location = url;
379 });
380
3811 Browser.prototype.link = function(selector) {
38215 var link, _i, _len, _ref;
38315 if (selector instanceof HTML.Element) {
3841 return selector;
385 }
38614 if (link = this.querySelector(selector)) {
3871 if (link.tagName === "A") {
3881 return link;
389 }
390 }
39113 _ref = this.querySelectorAll("body a");
39213 for (_i = 0, _len = _ref.length; _i < _len; _i++) {
39321 link = _ref[_i];
39421 if (link.textContent.trim() === selector) {
39513 return link;
396 }
397 }
398 };
399
4001 Browser.prototype.clickLink = function(selector, callback) {
40114 var link;
40214 if (!(link = this.link(selector))) {
4030 throw new Error("No link matching '" + selector + "'");
404 }
40514 return this.fire("click", link, callback);
406 };
407
4081 Browser.prototype.__defineGetter__("history", function() {
40919 return this.window.history;
410 });
411
4121 Browser.prototype.back = function(callback) {
4131 this.window.history.back();
4141 return this.wait(callback);
415 };
416
4171 Browser.prototype.reload = function(callback) {
4181 this.window.location.reload();
4191 return this.wait(callback);
420 };
421
4221 Browser.prototype.authenticate = function(host, create) {
423696 var credentials, _ref;
424696 if (create == null) {
425348 create = true;
426 }
427696 host || (host = "*");
428696 credentials = (_ref = this._credentials) != null ? _ref[host] : void 0;
429696 if (!credentials) {
430521 if (create) {
431179 credentials = new Credentials();
432179 this._credentials || (this._credentials = {});
433179 this._credentials[host] = credentials;
434 } else {
435342 credentials = this.authenticate();
436 }
437 }
438696 return credentials;
439 };
440
4411 Browser.prototype._setCredentials = function(credentials) {
442199 if (!credentials) {
443198 return;
444 }
4451 deprecated("This credentials option is deprecated, please use browser.authenticate(host) instead.");
4461 switch (credentials.scheme.toLowerCase()) {
447 case "basic":
4481 return this.authenticate().basic(credentials.user || credentials.username, credentials.password);
449 case "bearer":
4500 return this.authenticate().bearer(credentials.token);
451 case "oauth":
4520 return this.authenticate().oauth(credentials.token);
453 }
454 };
455
4561 Browser.prototype.saveHistory = function() {
4571 return this.window.history.save();
458 };
459
4601 Browser.prototype.loadHistory = function(serialized) {
4611 return this.window.history.load(serialized);
462 };
463
4641 Browser.prototype.field = function(selector) {
465104 var field, for_attr, label, _i, _len, _ref;
466104 if (selector instanceof HTML.Element) {
46724 return selector;
468 }
46980 if (field = this.querySelector(selector)) {
47025 if (field.tagName === "INPUT" || field.tagName === "TEXTAREA" || field.tagName === "SELECT") {
47125 return field;
472 }
473 }
47455 if (field = this.querySelector(":input[name='" + selector + "']")) {
47525 return field;
476 }
47730 _ref = this.querySelectorAll("label");
47830 for (_i = 0, _len = _ref.length; _i < _len; _i++) {
479186 label = _ref[_i];
480186 if (label.textContent.trim() === selector) {
48129 if (for_attr = label.getAttribute("for")) {
4826 return this.document.getElementById(for_attr);
483 } else {
48423 return label.querySelector(":input");
485 }
486 }
487 }
488 };
489
4901 Browser.prototype.fill = function(selector, value, callback) {
49140 var field;
49240 field = this.field(selector);
49340 if (!(field && (field.tagName === "TEXTAREA" || (field.tagName === "INPUT")))) {
4940 throw new Error("No INPUT matching '" + selector + "'");
495 }
49640 if (field.getAttribute("disabled")) {
4970 throw new Error("This INPUT field is disabled");
498 }
49940 if (field.getAttribute("readonly")) {
5000 throw new Error("This INPUT field is readonly");
501 }
50240 field.focus();
50340 field.value = value;
50440 this.fire("change", field, callback);
50540 return this;
506 };
507
5081 Browser.prototype._setCheckbox = function(selector, value, callback) {
50921 var field;
51021 field = this.field(selector);
51121 if (!(field && field.tagName === "INPUT" && field.type === "checkbox")) {
5120 throw new Error("No checkbox INPUT matching '" + selector + "'");
513 }
51421 if (field.getAttribute("disabled")) {
5150 throw new Error("This INPUT field is disabled");
516 }
51721 if (field.getAttribute("readonly")) {
5180 throw new Error("This INPUT field is readonly");
519 }
52021 if (field.checked ^ value) {
52119 field.click();
522 }
52321 if (callback) {
5244 this.wait(callback);
525 }
52621 return this;
527 };
528
5291 Browser.prototype.check = function(selector, callback) {
53016 return this._setCheckbox(selector, true, callback);
531 };
532
5331 Browser.prototype.uncheck = function(selector, callback) {
5345 return this._setCheckbox(selector, false, callback);
535 };
536
5371 Browser.prototype.choose = function(selector, callback) {
53811 var field;
53911 field = this.field(selector) || this.field("input[type=radio][value=\"" + (escape(selector)) + "\"]");
54011 if (!(field && field.tagName === "INPUT" && field.type === "radio")) {
5410 throw new Error("No radio INPUT matching '" + selector + "'");
542 }
54311 field.click();
54411 if (callback) {
5452 this.wait(callback);
546 }
54711 return this;
548 };
549
5501 Browser.prototype._findOption = function(selector, value) {
55126 var field, option, _i, _j, _k, _len, _len1, _len2, _ref, _ref1, _ref2;
55226 field = this.field(selector);
55326 if (!(field && field.tagName === "SELECT")) {
5540 throw new Error("No SELECT matching '" + selector + "'");
555 }
55626 if (field.getAttribute("disabled")) {
5570 throw new Error("This SELECT field is disabled");
558 }
55926 if (field.getAttribute("readonly")) {
5600 throw new Error("This SELECT field is readonly");
561 }
56226 _ref = field.options;
56326 for (_i = 0, _len = _ref.length; _i < _len; _i++) {
56454 option = _ref[_i];
56554 if (option.value === value) {
56622 return option;
567 }
568 }
5694 _ref1 = field.options;
5704 for (_j = 0, _len1 = _ref1.length; _j < _len1; _j++) {
57110 option = _ref1[_j];
57210 if (option.label === value) {
5733 return option;
574 }
575 }
5761 _ref2 = field.options;
5771 for (_k = 0, _len2 = _ref2.length; _k < _len2; _k++) {
5782 option = _ref2[_k];
5792 if (option.textContent.trim() === value) {
5801 return option;
581 }
582 }
5830 throw new Error("No OPTION '" + value + "'");
584 };
585
5861 Browser.prototype.select = function(selector, value, callback) {
58723 var option;
58823 option = this._findOption(selector, value);
58923 return this.selectOption(option, callback);
590 };
591
5921 Browser.prototype.selectOption = function(option, callback) {
59325 var select;
59425 if (option && !option.getAttribute("selected")) {
59524 select = this.xpath("./ancestor::select", option).value[0];
59624 option.setAttribute("selected", "selected");
59724 select.focus();
59824 this.fire("change", select, callback);
5991 } else if (callback) {
6000 process.nextTick(function() {
6010 return callback(null, false);
602 });
603 }
60425 return this;
605 };
606
6071 Browser.prototype.unselect = function(selector, value, callback) {
6083 var option;
6093 option = this._findOption(selector, value);
6103 return this.unselectOption(option, callback);
611 };
612
6131 Browser.prototype.unselectOption = function(option, callback) {
6143 var select;
6153 if (option && option.getAttribute("selected")) {
6161 select = this.xpath("./ancestor::select", option).value[0];
6171 if (!select.multiple) {
6180 throw new Error("Cannot unselect in single select");
619 }
6201 option.removeAttribute("selected");
6211 select.focus();
6221 this.fire("change", select, callback);
6232 } else if (callback) {
6240 process.nextTick(function() {
6250 return callback(null, false);
626 });
627 }
6283 return this;
629 };
630
6311 Browser.prototype.attach = function(selector, filename, callback) {
6324 var field, file, stat;
6334 field = this.field(selector);
6344 if (!(field && field.tagName === "INPUT" && field.type === "file")) {
6350 throw new Error("No file INPUT matching '" + selector + "'");
636 }
6374 if (filename) {
6383 stat = FS.statSync(filename);
6393 file = new this.window.File();
6403 file.name = Path.basename(filename);
6413 file.type = Mime.lookup(filename);
6423 file.size = stat.size;
6433 field.files || (field.files = []);
6443 field.files.push(file);
6453 field.value = filename;
646 }
6474 field.focus();
6484 this.fire("change", field, callback);
6494 return this;
650 };
651
6521 Browser.prototype.button = function(selector) {
65324 var button, input, inputs, _i, _j, _k, _len, _len1, _len2, _ref;
65424 if (selector instanceof HTML.Element) {
6551 return selector;
656 }
65723 if (button = this.querySelector(selector)) {
6581 if (button.tagName === "BUTTON" || button.tagName === "INPUT") {
6591 return button;
660 }
661 }
66222 _ref = this.querySelectorAll("button");
66322 for (_i = 0, _len = _ref.length; _i < _len; _i++) {
66417 button = _ref[_i];
66517 if (button.textContent.trim() === selector) {
66616 return button;
667 }
668 }
6696 inputs = this.querySelectorAll(":submit, :reset, :button");
6706 for (_j = 0, _len1 = inputs.length; _j < _len1; _j++) {
6719 input = inputs[_j];
6729 if (input.name === selector) {
6732 return input;
674 }
675 }
6764 for (_k = 0, _len2 = inputs.length; _k < _len2; _k++) {
6775 input = inputs[_k];
6785 if (input.value === selector) {
6794 return input;
680 }
681 }
682 };
683
6841 Browser.prototype.pressButton = function(selector, callback) {
68522 var button;
68622 if (!(button = this.button(selector))) {
6870 throw new Error("No BUTTON '" + selector + "'");
688 }
68922 if (button.getAttribute("disabled")) {
6900 throw new Error("This button is disabled");
691 }
69222 button.focus();
69322 return this.fire("click", button, callback);
694 };
695
6961 Browser.prototype.focused = function() {
6970 return this.window._focused;
698 };
699
7001 Browser.prototype.cookies = function(domain, path) {
701391 return this._cookies.access(domain || this.location.hostname, path || this.location.pathname);
702 };
703
7041 Browser.prototype.saveCookies = function() {
7051 return this._cookies.save();
706 };
707
7081 Browser.prototype.loadCookies = function(serialized) {
7091 return this._cookies.load(serialized);
710 };
711
7121 Browser.prototype.localStorage = function(host) {
7134 return this._storages.local(host);
714 };
715
7161 Browser.prototype.sessionStorage = function(host) {
7174 return this._storages.session(host);
718 };
719
7201 Browser.prototype.saveStorage = function() {
7211 return this._storages.save();
722 };
723
7241 Browser.prototype.loadStorage = function(serialized) {
7251 return this._storages.load(serialized);
726 };
727
7281 Browser.prototype.evaluate = function(code, filename) {
72914 return this.window._evaluate(code, filename);
730 };
731
7321 Browser.prototype.onalert = function(fn) {
7334 return this._interact.onalert(fn);
734 };
735
7361 Browser.prototype.onconfirm = function(question, response) {
7372 return this._interact.onconfirm(question, response);
738 };
739
7401 Browser.prototype.onprompt = function(message, response) {
7413 return this._interact.onprompt(message, response);
742 };
743
7441 Browser.prototype.prompted = function(message) {
74511 return this._interact.prompted(message);
746 };
747
7481 Browser.prototype.viewInBrowser = function(browser) {
7490 return require("./bcat").bcat(this.html());
750 };
751
7521 Browser.prototype.__defineGetter__("lastRequest", function() {
7534 var _ref;
7544 return (_ref = this.resources.last) != null ? _ref.request : void 0;
755 });
756
7571 Browser.prototype.__defineGetter__("lastResponse", function() {
7580 var _ref;
7590 return (_ref = this.resources.last) != null ? _ref.response : void 0;
760 });
761
7621 Browser.prototype.__defineGetter__("lastError", function() {
7630 var _ref;
7640 return (_ref = this.resources.last) != null ? _ref.error : void 0;
765 });
766
7671 Browser.prototype.log = function() {
768600 var arg, values, _i, _len;
769600 if (this.debug) {
7700 values = ["Zombie:"];
7710 if (typeof arguments[0] === "function") {
7720 try {
7730 values.push(arguments[0]());
774 } catch (ex) {
7750 values.push(ex);
776 }
777 } else {
7780 for (_i = 0, _len = arguments.length; _i < _len; _i++) {
7790 arg = arguments[_i];
7800 values.push(arg);
781 }
782 }
7830 return console.log.apply(null, values);
784 }
785 };
786
7871 Browser.prototype.dump = function() {
7880 var html, indent;
7890 indent = function(lines) {
7900 return lines.map(function(l) {
7910 return " " + l + "\n";
792 }).join("");
793 };
7940 process.stdout.write("Zombie: " + VERSION + "\n\n");
7950 process.stdout.write("URL: " + this.window.location.href + "\n");
7960 process.stdout.write("History:\n" + (indent(this.window.history.dump())) + "\n");
7970 process.stdout.write("Cookies:\n" + (indent(this._cookies.dump())) + "\n");
7980 process.stdout.write("Storage:\n" + (indent(this._storages.dump())) + "\n");
7990 process.stdout.write("Eventloop:\n" + (indent(this._eventloop.dump())) + "\n");
8000 if (this.document) {
8010 html = this.document.outerHTML;
8020 if (html.length > 497) {
8030 html = html.slice(0, 497) + "...";
804 }
8050 return process.stdout.write("Document:\n" + (indent(html.split("\n"))) + "\n");
806 } else {
8070 if (!this.document) {
8080 return process.stdout.write("No document\n");
809 }
810 }
811 };
812
8131 return Browser;
814
815})(EventEmitter);
816
8171Credentials = (function() {
818
8191 function Credentials() {}
820
8211 Credentials.prototype.apply = function(headers) {
822348 var base64;
823348 switch (this.scheme) {
824 case "basic":
8255 base64 = new Buffer(this.user + ":" + this.password).toString("base64");
8265 return headers["authorization"] = "Basic " + base64;
827 case "bearer":
8282 return headers["authorization"] = "Bearer " + this.token;
829 case "oauth":
8300 return headers["authorization"] = "OAuth " + this.token;
831 }
832 };
833
8341 Credentials.prototype.basic = function(user, password) {
8354 this.user = user;
8364 this.password = password;
8374 return this.scheme = "basic";
838 };
839
8401 Credentials.prototype.bearer = function(token) {
8412 this.token = token;
8422 return this.scheme = "bearer";
843 };
844
8451 Credentials.prototype.oauth = function(token) {
8460 this.token = token;
8470 return this.scheme = "oauth";
848 };
849
8501 Credentials.prototype.reset = function() {
8510 delete this.scheme;
8520 delete this.token;
8530 delete this.user;
8540 return delete this.password;
855 };
856
8571 return Credentials;
858
859})();
860
8611Browser.VERSION = VERSION;
862
8631module.exports = Browser;

zombie/jsdom_patches.js

94%
185
174
11
LineHitsSource
1// Generated by CoffeeScript 1.3.3
21var HTML, Path, URL, createSizzle, descendantOf, descendants, element, original, sizzle, _i, _j, _len, _len1, _ref, _ref1;
3
41Path = require("path");
5
61sizzle = Path.resolve(require.resolve("jsdom"), "../jsdom/selectors/sizzle");
7
81createSizzle = require(sizzle);
9
101HTML = require("jsdom").dom.level3.html;
11
121URL = require("url");
13
141HTML.HTMLElement.prototype.__defineGetter__("offsetLeft", function() {
152 return 0;
16});
17
181HTML.HTMLElement.prototype.__defineGetter__("offsetTop", function() {
19131 return 0;
20});
21
221original = HTML.Element.prototype.setAttribute;
23
241HTML.Element.prototype.setAttribute = function(name, value) {
257994 var attr, wrapped;
267994 if (/^on.+/.test(name)) {
2714 wrapped = "if ((function() { " + value + " }).call(this,event) === false) event.preventDefault();";
2814 this[name] = function(event) {
294 var window;
304 window = this.run ? this : this._ownerDocument.parentWindow;
314 try {
324 window.event = event;
334 return window.run(wrapped);
34 } finally {
354 window.event = null;
36 }
37 };
3814 if (this._ownerDocument) {
3914 attr = this._ownerDocument.createAttribute(name);
4014 attr.value = value;
4114 return this._attributes.setNamedItem(attr);
42 }
43 } else {
447980 return original.apply(this, arguments);
45 }
46};
47
481HTML.Element.prototype.getAttribute = function(name) {
4947055 var attribute;
5047055 attribute = this._attributes.getNamedItem(name);
5147055 return (attribute != null ? attribute.value : void 0) || null;
52};
53
541HTML.HTMLAnchorElement.prototype.__defineGetter__("href", function() {
5519 return HTML.resourceLoader.resolve(this._ownerDocument, this.getAttribute('href') || "");
56});
57
581HTML.HTMLLinkElement.prototype.__defineGetter__("href", function() {
5926 return HTML.resourceLoader.resolve(this._ownerDocument, this.getAttribute('href') || "");
60});
61
621HTML.HTMLElement.prototype.__defineGetter__("id", function() {
638762 return this.getAttribute("id") || "";
64});
65
661_ref = [HTML.HTMLFormElement, HTML.HTMLMenuElement, HTML.HTMLSelectElement, HTML.HTMLInputElement, HTML.HTMLTextAreaElement, HTML.HTMLButtonElement, HTML.HTMLAnchorElement, HTML.HTMLImageElement, HTML.HTMLObjectElement, HTML.HTMLParamElement, HTML.HTMLAppletElement, HTML.HTMLMapElement, HTML.HTMLFrameElement, HTML.HTMLIFrameElement];
671for (_i = 0, _len = _ref.length; _i < _len; _i++) {
6814 element = _ref[_i];
6914 element.prototype.__defineGetter__("name", function() {
7027107 return this.getAttribute("name") || "";
71 });
72}
73
741_ref1 = [HTML.HTMLInputElement, HTML.HTMLButtonElement, HTML.HTMLParamElement];
751for (_j = 0, _len1 = _ref1.length; _j < _len1; _j++) {
763 element = _ref1[_j];
773 element.prototype.__defineGetter__("value", function() {
78260 return this.getAttribute("value") || "";
79 });
80}
81
821HTML.HTMLAnchorElement.prototype._eventDefaults = {
83 click: function(event) {
848 var anchor, browser, window;
858 anchor = event.target;
868 if (!anchor.href) {
870 return;
88 }
898 window = anchor.ownerDocument.parentWindow;
908 browser = window.browser;
918 switch (anchor.target || "_self") {
92 case "_self":
932 window = window;
942 break;
95 case "_parent":
961 window = window.parent;
971 break;
98 case "_top":
991 window = window.top;
1001 break;
101 default:
1024 window = browser.windows.get(anchor.target) || browser.open({
103 name: anchor.target
104 });
105 }
1068 browser.windows.select(window);
1078 return window.location = anchor.href;
108 }
109};
110
1111HTML.resourceLoader.load = function(element, href, callback) {
11268 var document, loaded, ownerImplementation, tagName, url, window;
11368 document = element.ownerDocument;
11468 window = document.parentWindow;
11568 ownerImplementation = document.implementation;
11668 tagName = element.tagName.toLowerCase();
11768 if (ownerImplementation.hasFeature('FetchExternalResources', tagName)) {
11855 switch (tagName) {
119 case "iframe":
1200 if (/^javascript:/.test(href)) {
1210 return url = URL.parse(href);
122 } else {
1230 window = element.contentWindow;
1240 url = this.resolve(window.parent.location, href);
1250 loaded = function(response, filename) {
1260 return callback(response.body, URL.parse(response.url).pathname);
127 };
1280 return window.browser.resources.get(url, this.enqueue(element, loaded, url.pathname));
129 }
1300 break;
131 default:
13255 url = URL.parse(this.resolve(document, href));
13355 loaded = function(response, filename) {
13453 return callback.call(this, response.body, URL.parse(response.url).pathname);
135 };
13655 return window.browser.resources.get(url, this.enqueue(element, loaded, url.pathname));
137 }
138 }
139};
140
1411HTML.Document.prototype._elementBuilders["iframe"] = function(doc, tag) {
14219 var iframe, parent, window;
14319 parent = doc.window;
14419 iframe = new HTML.HTMLIFrameElement(doc, tag);
14519 window = null;
14619 Object.defineProperty(iframe, "contentWindow", {
147 get: function() {
14871 if (!window) {
14919 window = parent.browser.open({
150 name: iframe.name,
151 parent: parent
152 });
153 }
15471 return window;
155 }
156 });
15719 Object.defineProperty(iframe, "contentDocument", {
158 get: function() {
15920 return window.document;
160 }
161 });
16219 iframe.setAttribute = function(name, value) {
16347 if (name === "src" && value) {
16422 iframe.contentWindow.location = URL.resolve(parent.location, value);
16522 iframe.contentWindow.addEventListener("load", function(event) {
16621 var onload;
16721 onload = parent.document.createEvent("HTMLEvents");
16821 onload.initEvent("load", false, false);
16921 return parent.browser._eventloop.dispatch(iframe, onload);
170 });
17122 return HTML.HTMLElement.prototype.setAttribute.call(this, name, value);
172 } else {
17325 return HTML.HTMLFrameElement.prototype.setAttribute.call(this, name, value);
174 }
175 };
17619 return iframe;
177};
178
1791Object.defineProperty(HTML.CSSStyleDeclaration.prototype, "opacity", {
180 get: function() {
181241 return this._opacity || "";
182 },
183 set: function(opacity) {
18465 if (opacity) {
18563 opacity = parseFloat(opacity);
18663 if (!isNaN(opacity)) {
18762 return this._opacity = opacity.toString();
188 }
189 } else {
1902 return delete this._opacity;
191 }
192 }
193});
194
1951["height", "width"].forEach(function(prop) {
1962 var client, internal, offset;
1972 internal = "_" + prop;
1982 client = "client" + (prop[0].toUpperCase()) + (prop.slice(1));
1992 offset = "offset" + (prop[0].toUpperCase()) + (prop.slice(1));
2002 Object.defineProperty(HTML.CSSStyleDeclaration.prototype, prop, {
201 get: function() {
202904 return this[internal] || "";
203 },
204 set: function(value) {
205575 if (/^\d+px$/.test(value)) {
206428 return this[internal] = value;
207147 } else if (!value) {
20855 return delete this[internal];
209 }
210 }
211 });
2122 Object.defineProperty(HTML.HTMLElement.prototype, client, {
213 get: function() {
2140 return parseInt(this[internal] || 100);
215 }
216 });
2172 return Object.defineProperty(HTML.HTMLElement.prototype, offset, {
218 get: function() {
219116 return parseInt(this[internal] || 100);
220 }
221 });
222});
223
2241HTML.Node.prototype.__defineGetter__("textContent", function() {
2251303 if (this.nodeType === HTML.Node.TEXT_NODE || this.nodeType === HTML.Node.COMMENT_NODE || this.nodeType === HTML.Node.ATTRIBUTE_NODE || this.nodeType === HTML.Node.CDATA_SECTION_NODE) {
226596 return this.nodeValue;
227707 } else if (this.nodeType === HTML.Node.ELEMENT_NODE || this.nodeType === HTML.Node.DOCUMENT_FRAGMENT_NODE) {
228707 return this.childNodes.filter(function(node) {
229757 return node.nodeType === HTML.Node.TEXT_NODE || node.nodeType === HTML.Node.ELEMENT_NODE || node.nodeType === HTML.Node.CDATA_SECTION_NODE;
230 }).map(function(node) {
231756 return node.textContent;
232 }).join("");
233 } else {
2340 return null;
235 }
236});
237
2381HTML.NodeList.prototype.update = function() {
23910097 var i, name, node, nodes, _k, _l, _len2, _ref2, _ref3;
24010097 if (this._element && this._version < this._element._version) {
2415948 for (i = _k = 0, _ref2 = this._length; 0 <= _ref2 ? _k <= _ref2 : _k >= _ref2; i = 0 <= _ref2 ? ++_k : --_k) {
2425968 delete this[i];
243 }
2445948 if (this._names) {
2456 _ref3 = this._names;
2466 for (_l = 0, _len2 = _ref3.length; _l < _len2; _l++) {
24710 name = _ref3[_l];
24810 delete this[name];
249 }
250 }
2515948 nodes = this._snapshot = this._query();
2525948 this._length = nodes.length;
2535948 this._names = [];
2545948 for (i in nodes) {
25519412 node = nodes[i];
25619412 this[i] = node;
25719412 if (name = node.name) {
25818160 this._names.push(name);
25918160 this[node.name] = node;
260 }
261 }
2625948 this._version = this._element._version;
263 }
26410097 return this._snapshot;
265};
266
2671HTML.Node.prototype.contains = function(otherNode) {
2684 return !!(this.compareDocumentPosition(otherNode) & 16);
269};
270
2711HTML.HTMLDocument.prototype.querySelector = function(selector) {
272323 this._sizzle || (this._sizzle = createSizzle(this));
273323 return this._sizzle(selector, this)[0];
274};
275
2761HTML.HTMLDocument.prototype.querySelectorAll = function(selector) {
277202 this._sizzle || (this._sizzle = createSizzle(this));
278202 return new HTML.NodeList(this._sizzle(selector, this));
279};
280
2811descendantOf = function(element, context) {
2823360 var parent;
2833360 parent = element.parentNode;
2843360 if (parent) {
2852726 return parent === context || descendantOf(parent, context);
286 } else {
287634 return false;
288 }
289};
290
2911descendants = function(element, selector) {
29296 var document, parent;
29396 document = element.ownerDocument;
29496 document._sizzle || (document._sizzle = createSizzle(document));
29596 if (!element.parentNode) {
29630 parent = element.ownerDocument.createElement("div");
29730 parent.appendChild(element);
29830 element = parent;
299 }
30096 return document._sizzle(selector, element.parentNode || element).filter(function(node) {
301687 return descendantOf(node, element);
302 });
303};
304
3051HTML.Element.prototype.querySelector = function(selector) {
30623 return descendants(this, selector)[0];
307};
308
3091HTML.Element.prototype.querySelectorAll = function(selector) {
31073 return new HTML.NodeList(descendants(this, selector));
311};

zombie/forms.js

97%
171
166
5
LineHitsSource
1// Generated by CoffeeScript 1.3.3
21var File, HTML, Mime, Path, UploadedFile, element, focus, _i, _len, _ref;
3
41HTML = require("jsdom").dom.level3.html;
5
61Path = require("path");
7
81File = require("fs");
9
101Mime = require("mime");
11
121UploadedFile = function(filename) {
133 var file;
143 file = new String(Path.basename(filename));
153 file.filename = filename;
163 file.mime = Mime.lookup(filename);
173 file.read = function() {
183 return File.readFileSync(filename);
19 };
203 return file;
21};
22
231HTML.HTMLFormElement.prototype.submit = function(button) {
2418 var document, params, process,
25 _this = this;
2618 document = this.ownerDocument;
2718 params = [];
2818 process = function(index) {
29295 var field, history, name, option, selected, value, _i, _len, _ref, _ref1;
30295 if (field = _this.elements.item(index)) {
31277 value = null;
32277 if (!field.getAttribute("disabled") && (name = field.getAttribute("name"))) {
33250 if (field.nodeName === "SELECT") {
3437 selected = [];
3537 _ref = field.options;
3637 for (_i = 0, _len = _ref.length; _i < _len; _i++) {
37118 option = _ref[_i];
38118 if (option.selected) {
395 selected.push(option.value);
40 }
41 }
4237 if (field.multiple) {
436 params.push([name, selected]);
44 } else {
4531 if (selected.length > 0) {
463 value = selected[0];
47 } else {
4828 value = (_ref1 = field.options[0]) != null ? _ref1.value : void 0;
49 }
5031 params.push([name, value]);
51 }
52213 } else if (field.nodeName === "INPUT" && (field.type === "checkbox" || field.type === "radio")) {
5355 if (field.checked) {
5427 params.push([name, field.value || "1"]);
55 }
56158 } else if (field.nodeName === "INPUT" && field.type === "file") {
579 if (field.value) {
583 params.push([name, UploadedFile(field.value)]);
59 }
60149 } else if (field.nodeName === "TEXTAREA" || field.nodeName === "INPUT") {
61143 if (field.type !== "submit" && field.type !== "image") {
62127 params.push([name, field.value || ""]);
63 }
64 }
65 }
66277 return process(index + 1);
67 } else {
6818 if (button && button.name) {
698 params.push([button.name, button.value]);
70 }
7118 history = document.parentWindow.history;
7218 return history._submit(_this.getAttribute("action"), _this.getAttribute("method"), params, _this.getAttribute("enctype"));
73 }
74 };
7518 return process(0);
76};
77
781HTML.HTMLFormElement.prototype.reset = function() {
793 var field, option, _i, _len, _ref, _results;
803 _ref = this.elements;
813 _results = [];
823 for (_i = 0, _len = _ref.length; _i < _len; _i++) {
83108 field = _ref[_i];
84108 if (field.nodeName === "SELECT") {
8518 _results.push((function() {
8618 var _j, _len1, _ref1, _results1;
8718 _ref1 = field.options;
8818 _results1 = [];
8918 for (_j = 0, _len1 = _ref1.length; _j < _len1; _j++) {
9054 option = _ref1[_j];
9154 _results1.push(option.selected = option._defaultSelected);
92 }
9318 return _results1;
94 })());
9590 } else if (field.nodeName === "INPUT" && field.type === "check" || field.type === "radio") {
969 _results.push(field.checked = field._defaultChecked);
9781 } else if (field.nodeName === "INPUT" || field.nodeName === "TEXTAREA") {
9878 _results.push(field.value = field._defaultValue);
99 } else {
1003 _results.push(void 0);
101 }
102 }
1033 return _results;
104};
105
1061HTML.HTMLFormElement.prototype._dispatchSubmitEvent = function(button) {
10720 var event;
10820 event = this.ownerDocument.createEvent("HTMLEvents");
10920 event.initEvent("submit", true, true);
11020 event._button = button;
11120 return this.ownerDocument.parentWindow.browser.dispatchEvent(this, event);
112};
113
1141HTML.HTMLFormElement.prototype._eventDefaults["submit"] = function(event) {
11517 return event.target.submit(event._button);
116};
117
1181HTML.HTMLInputElement.prototype._eventDefaults = {
119 click: function(event) {
12037 var change, form, input;
12137 input = event.target;
12237 change = function() {
12328 event = input.ownerDocument.createEvent("HTMLEvents");
12428 event.initEvent("change", true, true);
12528 return input.ownerDocument.parentWindow.browser.dispatchEvent(input, event);
126 };
12737 switch (input.type) {
128 case "reset":
1292 if (form = input.form) {
1302 return form.reset();
131 }
1320 break;
133 case "submit":
134 case "image":
1357 if (form = input.form) {
1367 return form._dispatchSubmitEvent(input);
137 }
1380 break;
139 case "checkbox":
14018 return change();
141 case "radio":
14210 if (!input.getAttribute("readonly")) {
14310 input.checked = true;
14410 return change();
145 }
146 }
147 }
148};
149
1501HTML.HTMLInputElement.prototype.click = function() {
15133 var change, checked, click, original, radio, radios, _i, _j, _len, _len1,
152 _this = this;
15333 focus(this.ownerDocument, this);
15433 click = function() {
15533 var cancelled, event;
15633 event = _this.ownerDocument.createEvent("HTMLEvents");
15733 event.initEvent("click", true, true);
15833 cancelled = _this.ownerDocument.parentWindow.browser.dispatchEvent(_this, event);
15933 return !cancelled;
160 };
16133 change = function() {
16227 var event;
16327 event = _this.ownerDocument.createEvent("HTMLEvents");
16427 event.initEvent("change", true, true);
16527 return _this.ownerDocument.parentWindow.browser.dispatchEvent(_this, event);
166 };
16733 switch (this.type) {
168 case "checkbox":
16919 if (!this.getAttribute("readonly")) {
17019 original = this.checked;
17119 this.checked = !this.checked;
17219 if (click()) {
17318 change();
174 } else {
1751 this.checked = original;
176 }
177 }
17819 break;
179 case "radio":
18011 if (!this.getAttribute("readonly")) {
18111 if (this.checked) {
1821 click();
183 } else {
18410 radios = this.ownerDocument.querySelectorAll(":radio[name='" + (this.getAttribute("name")) + "']", this.form);
18510 checked = null;
18610 for (_i = 0, _len = radios.length; _i < _len; _i++) {
18718 radio = radios[_i];
18818 if (radio.checked) {
1899 checked = radio;
1909 radio.checked = false;
191 }
192 }
19310 this.checked = true;
19410 if (click()) {
1959 change();
196 } else {
1971 this.checked = false;
1981 for (_j = 0, _len1 = radios.length; _j < _len1; _j++) {
1990 radio = radios[_j];
2000 radio.checked = radio === checked;
201 }
202 }
203 }
204 }
20511 break;
206 default:
2073 click();
208 }
209};
210
2111HTML.HTMLButtonElement.prototype._eventDefaults = {
212 click: function(event) {
21313 var button, form;
21413 button = event.target;
21513 if (button.getAttribute("disabled")) {
216
217 } else {
21813 form = button.form;
21913 if (form) {
22013 return form._dispatchSubmitEvent(button);
221 }
222 }
223 }
224};
225
2261HTML.Document.prototype._elementBuilders["button"] = function(doc, s) {
22751 var button;
22851 button = new HTML.HTMLButtonElement(doc, s);
22951 button.type || (button.type = "submit");
23051 return button;
231};
232
2331HTML.HTMLDocument.prototype.__defineGetter__("activeElement", function() {
234226 return document._focused;
235});
236
2371focus = function(document, element) {
238125 var onblur, onfocus;
239125 if (element !== document._focused) {
240117 if (document._focused) {
24166 onblur = document.createEvent("HTMLEvents");
24266 onblur.initEvent("blur", false, false);
24366 document._focused.dispatchEvent(onblur);
244 }
245117 if (element) {
246117 onfocus = document.createEvent("HTMLEvents");
247117 onfocus.initEvent("focus", false, false);
248117 element.dispatchEvent(onfocus);
249 }
250117 return document._focused = element;
251 }
252};
253
2541_ref = [HTML.HTMLInputElement, HTML.HTMLSelectElement, HTML.HTMLTextAreaElement, HTML.HTMLButtonElement, HTML.HTMLAnchorElement];
2551for (_i = 0, _len = _ref.length; _i < _len; _i++) {
2565 element = _ref[_i];
2575 element.prototype.focus = function() {
25892 return focus(this.ownerDocument, this);
259 };
2605 element.prototype.blur = function() {
2610 return focus(this.ownerDocument, null);
262 };
263}

zombie/xpath.js

100%
27
27
0
LineHitsSource
1// Generated by CoffeeScript 1.3.3
21var engine, fs, html, vm, xpath;
3
41vm = require("vm");
5
61fs = require("fs");
7
81html = require("jsdom").dom.level3.html;
9
101engine = null;
11
121xpath = function() {
1330 if (!engine) {
141 engine = vm.Script.createContext();
151 engine.navigator = {
16 appVersion: "Zombie.js"
17 };
181 new vm.Script(fs.readFileSync(__dirname + "/../../xpath/util.js")).runInContext(engine);
191 new vm.Script(fs.readFileSync(__dirname + "/../../xpath/xmltoken.js")).runInContext(engine);
201 new vm.Script(fs.readFileSync(__dirname + "/../../xpath/xpath.js")).runInContext(engine);
21 }
2230 return engine;
23};
24
251html.HTMLDocument.prototype.evaluate = function(expr, node, nsResolver, type, result) {
2630 var context;
2730 engine = xpath();
2830 context = new engine.ExprContext(node || this);
2930 context.setCaseInsensitive(true);
3030 result = engine.xpathParse(expr).evaluate(context);
3130 if (result.type === 'node-set') {
3227 result.value = result.value.sort(function(a, b) {
3322 var value;
3422 value = a.compareDocumentPosition(b);
3522 if (value === 2 || value === 8 || value === 10) {
368 return 1;
37 } else {
3814 return -1;
39 }
40 });
41 }
4230 return result;
43};

zombie/helpers.js

100%
7
7
0
LineHitsSource
1// Generated by CoffeeScript 1.3.3
21var deprecated;
3
41deprecated = function(message) {
51 this.shown || (this.shown = {});
61 if (!this.shown[message]) {
71 this.shown[message] = true;
81 return process.stderr.write(message);
9 }
10};
11
121module.exports = {
13 deprecated: deprecated.bind(deprecated)
14};

zombie/cache.js

100%
5
5
0
LineHitsSource
1// Generated by CoffeeScript 1.3.3
21var Cache;
3
41Cache = (function() {
5
61 function Cache() {}
7
81 return Cache;
9
10})();
11
121module.exports = Cache;

zombie/cookies.js

76%
154
118
36
LineHitsSource
1// Generated by CoffeeScript 1.3.3
21var Access, Cookie, Cookies, HTML, Tough;
3
41HTML = require("jsdom").dom.level3.html;
5
61Tough = require("tough-cookie");
7
81Cookie = Tough.Cookie;
9
101Access = (function() {
11
121 function Access(_cookies, domain, path) {
13391 this._cookies = _cookies;
14391 this.domain = Tough.canonicalDomain(domain);
15391 this.path = path || "/";
16 }
17
181 Access.prototype.all = function() {
19383 var _this = this;
20383 return this._cookies.all().filter(function(cookie) {
21373 return Tough.domainMatch(_this.domain, cookie.domain) && Tough.pathMatch(_this.path, cookie.path) && cookie.TTL() > 0;
22 }).sort(Tough.cookieCompare);
23 };
24
251 Access.prototype.get = function(name) {
2624 var cookie, sorted, _i, _len;
2724 sorted = this.all();
2824 for (_i = 0, _len = sorted.length; _i < _len; _i++) {
29115 cookie = sorted[_i];
30115 if (cookie.key === name) {
3117 return cookie.value;
32 }
33 }
34 };
35
361 Access.prototype.set = function(name, value, options) {
3712 var cookie,
38 _this = this;
3912 if (options == null) {
407 options = {};
41 }
4212 cookie = new Cookie({
43 key: name,
44 value: value,
45 domain: options.domain || this.domain,
46 path: options.path || this.path
47 });
4812 if (options.expires) {
490 cookie.setExpires(options.expirs);
5012 } else if (options.hasOwnProperty("max-age")) {
512 cookie.setMaxAge(options["max-age"]);
52 }
5312 cookie.secure = !!options.secure;
5412 cookie.httpOnly = !!options.httpOnly;
5512 this._cookies.filter(function(c) {
5657 return !(cookie.key === c.key && cookie.domain === c.domain && cookie.path === c.path);
57 });
5812 if (Tough.domainMatch(cookie.domain, this.domain) && Tough.pathMatch(cookie.path, this.path) && cookie.TTL() > 0) {
5911 return this._cookies.push(cookie);
60 }
61 };
62
631 Access.prototype.remove = function(name) {
640 var _this = this;
650 return this._cookies.filter(function(cookie) {
660 return !(cookie.key === name && cookie.domain === _this.domain && cookie.path === _this.path);
67 });
68 };
69
701 Access.prototype.clear = function() {
710 var _this = this;
720 return this._cookies.filter(function(cookie) {
730 return !(cookie.domain === _this.domain && cookie.path === _this.path);
74 });
75 };
76
771 Access.prototype.update = function(serialized) {
78113 var cookie, _i, _len, _ref, _results;
79113 if (!serialized) {
800 return;
81 }
82113 if (serialized.constructor === Array) {
830 serialized = serialized.join(",");
84 }
85113 _ref = serialized.split(/,(?=[^;,]*=)|,$/);
86113 _results = [];
87113 for (_i = 0, _len = _ref.length; _i < _len; _i++) {
88113 cookie = _ref[_i];
89113 cookie = Cookie.parse(cookie);
90113 cookie.domain || (cookie.domain = this.domain);
91113 cookie.path || (cookie.path = this.path);
92113 this._cookies.filter(function(c) {
93630 return !(cookie.key === c.key && cookie.domain === c.domain && cookie.path === c.path);
94 });
95113 if (Tough.domainMatch(this.domain, cookie.domain) && Tough.pathMatch(this.path, cookie.path) && cookie.TTL() > 0) {
9676 _results.push(this._cookies.push(cookie));
97 } else {
9837 _results.push(void 0);
99 }
100 }
101113 return _results;
102 };
103
1041 Access.prototype.addHeader = function(headers) {
105349 var cookie, header;
106349 header = ((function() {
107349 var _i, _len, _ref, _results;
108349 _ref = this.all();
109349 _results = [];
110349 for (_i = 0, _len = _ref.length; _i < _len; _i++) {
11199 cookie = _ref[_i];
11299 _results.push(cookie.cookieString());
113 }
114349 return _results;
115 }).call(this)).join("; ");
116349 if (header.length > 0) {
11716 return headers.cookie = header;
118 }
119 };
120
1211 Access.prototype.dump = function(separator) {
1220 var cookie;
1230 if (separator == null) {
1240 separator = "\n";
125 }
1260 return ((function() {
1270 var _i, _len, _ref, _results;
1280 _ref = this.all();
1290 _results = [];
1300 for (_i = 0, _len = _ref.length; _i < _len; _i++) {
1310 cookie = _ref[_i];
1320 _results.push(cookie.toString());
133 }
1340 return _results;
135 }).call(this)).join(separator);
136 };
137
1381 Access.prototype.toString = function() {
1390 var cookie;
1400 return ((function() {
1410 var _i, _len, _ref, _results;
1420 _ref = this.all();
1430 _results = [];
1440 for (_i = 0, _len = _ref.length; _i < _len; _i++) {
1450 cookie = _ref[_i];
1460 _results.push(cookie.toString());
147 }
1480 return _results;
149 }).call(this)).join("\n");
150 };
151
1521 return Access;
153
154})();
155
1561Cookies = (function() {
157
1581 function Cookies() {
159195 this._cookies = [];
160 }
161
1621 Cookies.prototype.access = function(hostname, pathname) {
163391 return new Access(this, hostname, pathname);
164 };
165
1661 Cookies.prototype.extend = function(window) {
167223 return Object.defineProperty(window, "cookies", {
168 get: function() {
16914 return this.browser.cookies(this.location.hostname, this.location.pathname);
170 }
171 });
172 };
173
1741 Cookies.prototype.dump = function() {
1750 var cookie, _i, _len, _ref, _results;
1760 _ref = this._cookies.sort(Tough.cookieCompare);
1770 _results = [];
1780 for (_i = 0, _len = _ref.length; _i < _len; _i++) {
1790 cookie = _ref[_i];
1800 _results.push(process.stdout.write(cookie.toString() + "\n"));
181 }
1820 return _results;
183 };
184
1851 Cookies.prototype.save = function() {
1861 var cookie, serialized, _i, _len, _ref;
1871 serialized = ["# Saved on " + (new Date().toISOString())];
1881 _ref = this._cookies.sort(Tough.cookieCompare);
1891 for (_i = 0, _len = _ref.length; _i < _len; _i++) {
1901 cookie = _ref[_i];
1911 serialized.push(cookie.toString());
192 }
1931 return serialized.join("\n") + "\n";
194 };
195
1961 Cookies.prototype.load = function(serialized) {
1971 var line, _i, _len, _ref, _results;
1981 _ref = serialized.split(/\n+/);
1991 _results = [];
2001 for (_i = 0, _len = _ref.length; _i < _len; _i++) {
2013 line = _ref[_i];
2023 line = line.trim();
2033 if (line[0] === "#" || line === "") {
2042 continue;
205 }
2061 _results.push(this._cookies.push(Cookie.parse(line)));
207 }
2081 return _results;
209 };
210
2111 Cookies.prototype.filter = function(fn) {
212125 return this._cookies = this._cookies.filter(fn);
213 };
214
2151 Cookies.prototype.push = function(cookie) {
21687 return this._cookies.push(cookie);
217 };
218
2191 Cookies.prototype.all = function() {
220383 return this._cookies.slice();
221 };
222
2231 return Cookies;
224
225})();
226
2271HTML.HTMLDocument.prototype.__defineGetter__("cookie", function() {
2289 var cookie, cookies;
2299 cookies = (function() {
2309 var _i, _len, _ref, _results;
2319 _ref = this.parentWindow.cookies.all();
2329 _results = [];
2339 for (_i = 0, _len = _ref.length; _i < _len; _i++) {
23430 cookie = _ref[_i];
23530 if (!cookie.httpOnly) {
23626 _results.push("" + cookie.key + "=" + cookie.value);
237 }
238 }
2399 return _results;
240 }).call(this);
2419 return cookies.join("; ");
242});
243
2441HTML.HTMLDocument.prototype.__defineSetter__("cookie", function(cookie) {
2455 return this.parentWindow.cookies.update(cookie);
246});
247
2481module.exports = Cookies;

zombie/eventloop.js

96%
182
175
7
LineHitsSource
1// Generated by CoffeeScript 1.3.3
21var EventLoop, URL, ms, raise;
3
41ms = require("ms");
5
61URL = require("url");
7
81raise = require("./scripts").raise;
9
101EventLoop = (function() {
11
121 function EventLoop(_browser) {
13195 this._browser = _browser;
14195 this._processing = 0;
15195 this._waiting = [];
16195 this._timers = [];
17 }
18
191 EventLoop.prototype.reset = function() {
2024 var timer, _i, _len, _ref;
2124 if (this._timers) {
2224 _ref = this._timers;
2324 for (_i = 0, _len = _ref.length; _i < _len; _i++) {
241 timer = _ref[_i];
251 global.clearTimeout(timer.handle);
26 }
27 }
2824 return this._timers = [];
29 };
30
311 EventLoop.prototype.apply = function(window) {
32223 var remove,
33 _this = this;
34223 remove = function(timer) {
3567 var index;
3667 index = _this._timers.indexOf(timer);
3767 if (~index) {
3859 return _this._timers.splice(index, 1);
39 }
40 };
41223 window.setTimeout = function(fn, delay) {
4280 var timer;
4380 if (!fn) {
440 return;
45 }
4680 timer = {
47 handle: null,
48 timeout: true,
49 resume: function() {
5094 if (timer.handle) {
518 return;
52 }
5386 timer.next = Date.now() + Math.max(delay || 0, 0);
5486 if (delay <= 0) {
5524 remove(timer);
5624 return _this.perform(function(done) {
5724 return process.nextTick(function() {
5824 _this._browser.log("Firing timeout after " + delay + "ms delay");
5924 window._evaluate(fn);
6024 return done();
61 });
62 });
63 } else {
6462 return timer.handle = global.setTimeout(function() {
6531 return _this.perform(function(done) {
6631 remove(timer);
6731 _this._browser.log("Firing timeout after " + delay + "ms delay");
6831 window._evaluate(fn);
6931 return done();
70 });
71 }, delay);
72 }
73 },
74 pause: function() {
7528 global.clearTimeout(timer.handle);
7628 timer.handle = null;
7728 return delay = timer.next - Date.now();
78 },
79 stop: function() {
8010 global.clearTimeout(timer.handle);
8110 return remove(timer);
82 }
83 };
8480 _this._timers.push(timer);
8580 timer.resume();
8680 return timer;
87 };
88223 window.setInterval = function(fn, interval) {
8912 var timer;
9012 if (interval == null) {
910 interval = 0;
92 }
9312 if (!fn) {
940 return;
95 }
9612 timer = {
97 handle: null,
98 interval: true,
99 resume: function() {
10023 if (timer.handle) {
1016 return;
102 }
10317 timer.next = Date.now() + interval;
10417 return timer.handle = global.setInterval(function() {
105178 return _this.perform(function(done) {
106178 timer.next = Date.now() + interval;
107178 _this._browser.log("Firing interval every " + interval + "ms");
108178 window._evaluate(fn);
109178 return done();
110 });
111 }, interval);
112 },
113 pause: function() {
11416 global.clearInterval(timer.handle);
11516 return timer.handle = null;
116 },
117 stop: function() {
1182 global.clearInterval(timer.handle);
1192 return remove(timer);
120 }
121 };
12212 _this._timers.push(timer);
12312 timer.resume();
12412 return timer;
125 };
126223 window.clearTimeout = function(timer) {
12711 if (timer && timer.timeout && timer.stop) {
12810 return timer.stop();
129 }
130 };
131223 return window.clearInterval = function(timer) {
1323 if (timer && timer.interval && timer.stop) {
1332 return timer.stop();
134 }
135 };
136 };
137
1381 EventLoop.prototype.perform = function(fn) {
139828 var _this = this;
140828 ++this._processing;
141828 fn(function() {
142828 --_this._processing;
143828 if (_this._processing === 0) {
144682 return _this._next();
145 }
146 });
147 };
148
1491 EventLoop.prototype.dispatch = function(target, event) {
150254 var preventDefault;
151254 preventDefault = false;
152254 this.perform(function(done) {
153254 var window;
154254 if (target._evaluate) {
15520 window = target;
156 } else {
157234 window = (target.ownerDocument || target.document).window;
158 }
159254 window._evaluate(function() {
160254 return preventDefault = target.dispatchEvent(event);
161 });
162254 return done();
163 });
164254 return preventDefault;
165 };
166
1671 EventLoop.prototype.wait = function(window, duration, callback) {
168329 var done, done_at, is_done, terminate, waiting,
169 _this = this;
170329 if (typeof duration === "function") {
1712 is_done = duration;
1722 done_at = Infinity;
173 } else {
174327 if (!(duration && duration !== 0)) {
175317 duration = this._browser.waitFor;
176 }
177327 done_at = Date.now() + ms(duration || 0);
178 }
179329 done = function(error) {
180329 var fn;
181329 done = null;
182329 _this._waiting = (function() {
183329 var _i, _len, _ref, _results;
184329 _ref = this._waiting;
185329 _results = [];
186329 for (_i = 0, _len = _ref.length; _i < _len; _i++) {
187419 fn = _ref[_i];
188419 if (fn !== waiting) {
18990 _results.push(fn);
190 }
191 }
192329 return _results;
193 }).call(_this);
194329 if (_this._waiting.length === 0) {
195292 _this._pause();
196 }
197329 if (terminate) {
198329 clearTimeout(terminate);
199 }
200329 if (callback) {
201329 process.nextTick(function() {
202329 return callback(error, window);
203 });
204 }
205329 if (error) {
2060 return _this._browser.emit("error", error);
207 } else {
208329 return _this._browser.emit("done");
209 }
210 };
211329 terminate = setTimeout(done, ms(this._browser.maxWait));
212329 waiting = function() {
213993 var next, timer, timers;
214993 if (!done) {
21545 return;
216 }
217948 if (_this._processing > 0) {
218481 return;
219 }
220467 try {
221467 if (is_done && is_done(window)) {
2222 done();
2232 return;
224 }
225 } catch (error) {
2260 done(error);
2270 return;
228 }
229465 timers = (function() {
230465 var _i, _len, _ref, _results;
231465 _ref = this._timers;
232465 _results = [];
233465 for (_i = 0, _len = _ref.length; _i < _len; _i++) {
234253 timer = _ref[_i];
235253 _results.push(timer.next);
236 }
237465 return _results;
238 }).call(_this);
239465 next = Math.min.apply(Math, timers);
240465 if (next > done_at) {
241327 return done();
242 }
243 };
244329 if (this._waiting.length === 0) {
245292 this._resume();
246 }
247329 this._waiting.push(waiting);
248329 this._next();
249 };
250
2511 EventLoop.prototype._next = function() {
2521011 var waiting, _i, _len, _ref;
2531011 _ref = this._waiting;
2541011 for (_i = 0, _len = _ref.length; _i < _len; _i++) {
255993 waiting = _ref[_i];
256993 process.nextTick(waiting);
257 }
258 };
259
2601 EventLoop.prototype._pause = function() {
261292 var timer, _i, _len, _ref;
262292 _ref = this._timers;
263292 for (_i = 0, _len = _ref.length; _i < _len; _i++) {
26444 timer = _ref[_i];
26544 timer.pause();
266 }
267 };
268
2691 EventLoop.prototype._resume = function() {
270292 var timer, _i, _len, _ref;
271292 _ref = this._timers.slice();
272292 for (_i = 0, _len = _ref.length; _i < _len; _i++) {
27325 timer = _ref[_i];
27425 timer.resume();
275 }
276 };
277
2781 EventLoop.prototype.dump = function() {
2790 return ["The time: " + (new Date), "Timers: " + this._timers.length, "Processing: " + this._processing, "Waiting: " + this._waiting.length];
280 };
281
2821 return EventLoop;
283
284})();
285
2861module.exports = EventLoop;

zombie/scripts.js

98%
54
53
1
LineHitsSource
1// Generated by CoffeeScript 1.3.3
21var CoffeeScript, HTML, addInlineScriptSupport, raise;
3
41HTML = require("jsdom").dom.level3.html;
5
61try {
71 CoffeeScript = require("coffee-script");
81 HTML.languageProcessors.coffeescript = function(element, code, filename) {
90 return this.javascript(element, CoffeeScript.compile(code), filename);
10 };
11} catch (ex) {
12
13}
14
151HTML.languageProcessors.javascript = function(element, code, filename) {
16234 var cast, doc, window;
17234 if (doc = element.ownerDocument) {
18234 window = doc.parentWindow;
19234 try {
20234 return window._evaluate(code, filename);
21 } catch (error) {
225 if (!(error instanceof Error)) {
235 cast = new Error(error.message);
245 cast.stack = error.stack;
255 error = cast;
26 }
275 return raise({
28 element: element,
29 location: filename,
30 from: __filename,
31 error: error
32 });
33 }
34 }
35};
36
371addInlineScriptSupport = function(document) {
38469 return document.addEventListener("DOMNodeInserted", function(event) {
3910379 var node;
4010379 node = event.target;
4110379 if (node.tagName !== "SCRIPT") {
4210228 return;
43 }
44151 if (node.src) {
4555 return;
46 }
4796 HTML.resourceLoader.enqueue(node, function() {
4896 var code, language;
4996 code = node.text;
5096 language = HTML.languageProcessors[node.language];
5196 if (code && language) {
5290 return language(this, code, document.location.href);
53 }
54 })();
55 });
56};
57
581raise = function(_arg) {
595 var document, element, error, event, from, line, location, message, partial, scope, window, _i, _len, _ref;
605 element = _arg.element, location = _arg.location, from = _arg.from, scope = _arg.scope, error = _arg.error;
615 document = element.ownerDocument || element;
625 window = document.parentWindow;
635 message = scope ? "" + scope + ": " + error.message : error.message;
645 location || (location = document.location.href);
655 partial = [];
665 if (error.stack) {
675 _ref = error.stack.split("\n");
685 for (_i = 0, _len = _ref.length; _i < _len; _i++) {
6917 line = _ref[_i];
7017 if (~line.indexOf("contextify/lib/contextify.js")) {
715 break;
72 }
7312 partial.push(line);
74 }
75 }
765 partial.push(" in " + location);
775 error.stack = partial.join("\n");
785 event = document.createEvent("Event");
795 event.initEvent("error", false, false);
805 event.message = error.message;
815 event.error = error;
825 window.dispatchEvent(event);
83};
84
851module.exports = {
86 raise: raise,
87 addInlineScriptSupport: addInlineScriptSupport
88};

zombie/interact.js

100%
58
58
0
LineHitsSource
1// Generated by CoffeeScript 1.3.3
21var Interaction;
3
41Interaction = (function() {
5
61 function Interaction(browser) {
7195 var alertFns, confirmCanned, confirmFns, promptCanned, promptFns, prompts;
8195 prompts = [];
9195 alertFns = [];
10195 this.onalert = function(fn) {
114 return alertFns.push(fn);
12 };
13195 confirmFns = [];
14195 confirmCanned = {};
15195 this.onconfirm = function(question, response) {
162 if (typeof question === "function") {
171 return confirmFns.push(question);
18 } else {
191 return confirmCanned[question] = !!response;
20 }
21 };
22195 promptFns = [];
23195 promptCanned = {};
24195 this.onprompt = function(message, response) {
253 if (typeof message === "function") {
261 return promptFns.push(message);
27 } else {
282 return promptCanned[message] = response;
29 }
30 };
31195 this.prompted = function(message) {
3211 return prompts.indexOf(message) >= 0;
33 };
34195 this.extend = function(window) {
35223 window.alert = function(message) {
365 var fn, _i, _len;
375 prompts.push(message);
385 for (_i = 0, _len = alertFns.length; _i < _len; _i++) {
395 fn = alertFns[_i];
405 fn(message);
41 }
42 };
43223 window.confirm = function(question) {
443 var fn, response, _i, _len;
453 prompts.push(question);
463 response = confirmCanned[question];
473 if (!(response || response === false)) {
482 for (_i = 0, _len = confirmFns.length; _i < _len; _i++) {
492 fn = confirmFns[_i];
502 response = fn(question);
512 if (response || response === false) {
522 break;
53 }
54 }
55 }
563 return !!response;
57 };
58223 return window.prompt = function(message, def) {
594 var fn, response, _i, _len;
604 prompts.push(message);
614 response = promptCanned[message];
624 if (!(response || response === false)) {
632 for (_i = 0, _len = promptFns.length; _i < _len; _i++) {
642 fn = promptFns[_i];
652 response = fn(message, def);
662 if (response || response === false) {
671 break;
68 }
69 }
70 }
714 if (response) {
722 return response.toString();
73 }
742 if (response === false) {
751 return null;
76 }
771 return def || "";
78 };
79 };
80 }
81
821 return Interaction;
83
84})();
85
861exports.use = function(browser) {
87195 return new Interaction(browser);
88};

zombie/resources.js

89%
221
198
23
LineHitsSource
1// Generated by CoffeeScript 1.3.3
21var Cache, FS, HTTP, HTTPRequest, HTTPResponse, HTTPS, Path, QS, Request, Resource, Resources, STATUS, URL, indent, inspect, partial,
3 __hasProp = {}.hasOwnProperty,
47 __extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; };
5
61inspect = require("util").inspect;
7
81HTTP = require("http");
9
101HTTPS = require("https");
11
121FS = require("fs");
13
141Path = require("path");
15
161QS = require("querystring");
17
181Request = require("request");
19
201URL = require("url");
21
221partial = function(text, length) {
234 if (length == null) {
244 length = 250;
25 }
264 if (!text) {
272 return "";
28 }
292 if (text.length <= length) {
300 return text;
31 }
322 return text.substring(0, length - 3) + "...";
33};
34
351indent = function(text) {
364 return text.toString().split("\n").map(function(l) {
3743 return " " + l;
38 }).join("\n");
39};
40
411Resource = (function() {
42
431 function Resource(request) {
44314 this.request = request;
45314 this.request.resource = this;
46314 this.redirects = 0;
47314 this.start = new Date().getTime();
48314 this.time = 0;
49 }
50
511 Resource.prototype.__defineGetter__("size", function() {
522 var _ref;
532 return ((_ref = this.response) != null ? _ref.body.length : void 0) || 0;
54 });
55
561 Resource.prototype.__defineGetter__("url", function() {
574 var _ref;
584 return ((_ref = this.response) != null ? _ref.url : void 0) || this.request.url;
59 });
60
611 Resource.prototype.__defineGetter__("response", function() {
62323 return this._response;
63 });
64
651 Resource.prototype.__defineSetter__("response", function(response) {
66312 this.time = new Date().getTime() - this.start;
67312 response.resource = this;
68312 return this._response = response;
69 });
70
711 Resource.prototype.toString = function() {
722 return "URL: " + this.url + "\nTime: " + this.time + "ms\nSize: " + (this.size / 1024) + "kb\nRequest:\n" + (indent(this.request)) + "\nResponse:\n" + (indent(this.response)) + "\n";
73 };
74
751 return Resource;
76
77})();
78
791HTTPRequest = (function() {
80
811 function HTTPRequest(method, url, headers, body) {
82314 this.method = method;
83314 this.headers = headers;
84314 this.body = body;
85314 this.url = URL.format(url);
86 }
87
881 HTTPRequest.prototype.toString = function() {
892 return "" + (inspect(this.headers)) + "\n" + (partial(this.body));
90 };
91
921 return HTTPRequest;
93
94})();
95
961HTTPResponse = (function() {
97
981 function HTTPResponse(url, statusCode, headers, body) {
99315 this.statusCode = statusCode;
100315 this.headers = headers;
101315 this.body = body;
102315 this.url = URL.format(url);
103 }
104
1051 HTTPResponse.prototype.__defineGetter__("statusText", function() {
10611 return STATUS[this.statusCode];
107 });
108
1091 HTTPResponse.prototype.__defineGetter__("redirected", function() {
1103 return !!this.resource.redirects;
111 });
112
1131 HTTPResponse.prototype.toString = function() {
1142 return "" + this.statusCode + " " + this.statusText + "\n" + (inspect(this.headers)) + "\n" + (partial(this.body));
115 };
116
1171 return HTTPResponse;
118
119})();
120
1211Resources = (function(_super) {
1221 var stringify, stringifyPrimitive, typeOf;
123
1241 __extends(Resources, _super);
125
1261 function Resources(_browser) {
127195 this._browser = _browser;
128 }
129
1301 Resources.prototype.__defineGetter__("first", function() {
1310 return this[0];
132 });
133
1341 Resources.prototype.__defineGetter__("last", function() {
1357 return this[this.length - 1];
136 });
137
1381 Resources.prototype.get = function(url, callback) {
13955 return this.request("GET", url, null, null, callback);
140 };
141
1421 Resources.prototype.request = function(method, url, data, headers, callback) {
143317 var _this = this;
144317 return this._browser._eventloop.perform(function(done) {
145317 return _this._makeRequest(method, url, data, headers, null, function(error, response) {
146317 done();
147317 return callback(error, response);
148 });
149 });
150 };
151
1521 Resources.prototype.clear = function() {
15324 return this.length = 0;
154 };
155
1561 Resources.prototype.dump = function() {
1570 process.stdout.write(this.toString());
1580 return process.stdout.write("\n");
159 };
160
1611 Resources.prototype.toString = function() {
1621 return this.map(function(resource) {
1632 return resource.toString();
164 }).join("\n");
165 };
166
1671 Resources.prototype._makeRequest = function(method, url, data, headers, resource, callback) {
168351 var binary, body, boundary, browser, content, cookies, credentials, disp, field, jar, multipart, name, params, value, _i, _len, _ref,
169 _this = this;
170351 browser = this._browser;
171351 url = URL.parse(url);
172351 method = (method || "GET").toUpperCase();
173351 if (url.protocol === "file:") {
1743 browser.log(function() {
1750 return "" + method + " " + url.pathname;
176 });
1773 if (method === "GET") {
1783 FS.readFile(Path.normalize(url.pathname), function(err, data) {
1793 var response;
1803 if (err) {
1810 browser.log(function() {
1820 return "Error loading " + (URL.format(url)) + ": " + err.message;
183 });
1840 callback(err);
185 }
1863 response = new HTTPResponse(url, 200, {}, String(data));
1873 return callback(null, response);
188 });
189 } else {
1900 callback(new Error("Cannot " + method + " a file: URL"));
191 }
1923 return;
193 }
194348 headers = headers ? JSON.parse(JSON.stringify(headers)) : {};
195348 headers["User-Agent"] = browser.userAgent;
196348 headers["Accept-Encoding"] = "identity";
197348 if (method === "GET" || method === "HEAD") {
198326 if (data) {
1992 url.search = "?" + stringify(data);
200 }
201 } else {
20222 switch (headers["content-type"]) {
203 case "multipart/form-data":
2045 if (Object.keys(data).length > 0) {
2053 boundary = "" + (new Date().getTime()) + (Math.random());
2063 headers["content-type"] += "; boundary=" + boundary;
207 } else {
2082 headers["content-type"] = "text/plain;charset=UTF-8";
209 }
2105 break;
211 case "application/x-www-form-urlencoded":
21215 data = stringify(data);
21315 if (!headers["transfer-encoding"]) {
21415 headers["content-length"] || (headers["content-length"] = data.length);
215 }
21615 break;
217 default:
2182 headers["content-type"] || (headers["content-type"] = "text/plain;charset=UTF-8");
219 }
220 }
221348 headers["Host"] = url.host;
222348 credentials = this._browser.authenticate(url.host, false);
223348 if (credentials) {
224348 credentials.apply(headers);
225 }
226348 if (!(url.pathname && url.pathname[0] === "/")) {
2270 url.pathname = "/" + (url.pathname || "");
228 }
229348 if (!resource) {
230314 resource = new Resource(new HTTPRequest(method, url, headers, null));
231314 this.push(resource);
232 }
233348 if (method === "PUT" || method === "POST") {
23422 switch (headers["content-type"].split(";")[0]) {
235 case "application/x-www-form-urlencoded":
23616 body = data;
23716 break;
238 case "multipart/form-data":
2393 multipart = [];
2403 for (_i = 0, _len = data.length; _i < _len; _i++) {
2414 field = data[_i];
2424 name = field[0], content = field[1];
2434 disp = "form-data; name=\"" + name + "\"";
2444 if (content.read) {
2453 binary = content.read();
2463 multipart.push({
247 "Content-Disposition": "" + disp + "; filename=\"" + content + "\"",
248 "Content-Type": content.mime || "application/octet-stream",
249 "Content-Length": binary.length,
250 body: binary
251 });
252 } else {
2531 multipart.push({
254 "Content-Disposition": disp,
255 "Content-Type": "text/plain",
256 "Content-Transfer-Encoding": "utf8",
257 "Content-Length": content.length,
258 body: content
259 });
260 }
261 }
2623 break;
263 default:
2643 body = (data || "").toString();
265 }
266 } else {
267326 delete headers["content-type"];
268326 delete headers["content-length"];
269326 delete headers["content-transfer-encoding"];
270 }
271348 cookies = browser.cookies(url.hostname, url.pathname);
272348 cookies.addHeader(headers);
273348 jar = Request.jar();
274348 if (browser.headers) {
275348 _ref = browser.headers;
276348 for (name in _ref) {
2771 value = _ref[name];
2781 headers[name] = value;
279 }
280 }
281348 params = {
282 method: method,
283 url: url,
284 headers: headers,
285 body: body,
286 multipart: multipart,
287 proxy: browser.proxy,
288 jar: jar,
289 followRedirect: false
290 };
291348 return Request(params, function(error, response) {
292348 var cookie, redirect, _j, _len1, _ref1;
293348 if (error) {
2942 browser.log(function() {
2950 return "" + method + " " + (URL.format(url).slice("#")[0]) + " => " + error.message;
296 });
2972 callback(error);
2982 return;
299 }
300346 _ref1 = jar.cookies;
301346 for (_j = 0, _len1 = _ref1.length; _j < _len1; _j++) {
302104 cookie = _ref1[_j];
303104 cookies.update(cookie.str);
304 }
305346 switch (response.statusCode) {
306 case 301:
307 case 307:
3080 if (method === "GET" || method === "HEAD") {
3090 redirect = URL.resolve(url, response.headers['location']);
310 }
3110 break;
312 case 302:
313 case 303:
31434 redirect = URL.resolve(url, response.headers['location']);
31534 if (!(method === "GET" || method === "HEAD")) {
3162 method = "GET";
317 }
318 }
319346 if (redirect) {
32034 ++resource.redirects;
32134 if (resource.redirects > 5) {
3220 callback(new Error("More than five redirects, giving up"));
3230 return;
324 }
32534 headers['referer'] = URL.format(url);
32634 browser.log(function() {
3270 return "" + response.statusCode + " => " + redirect;
328 });
32934 return _this._makeRequest(method, redirect, null, headers, resource, callback);
330 } else {
331312 resource.response = new HTTPResponse(url, response.statusCode, response.headers, response.body);
332312 browser.log(function() {
3330 return "" + method + " " + (URL.format(url)) + " => " + response.statusCode;
334 });
335312 return callback(null, resource.response);
336 }
337 });
338 };
339
3401 typeOf = function(object) {
341388 return Object.prototype.toString.call(object);
342 };
343
3441 stringifyPrimitive = function(v) {
345388 var _ref;
346388 switch (typeOf(v)) {
347 case '[object Boolean]':
3480 return v != null ? v : {
349 'true': 'false'
350 };
351 case '[object Number]':
3520 return (_ref = isFinite(v)) != null ? _ref : {
353 v: ''
354 };
355 case '[object String]':
356381 return v;
357 default:
3587 return '';
359 }
360 };
361
3621 stringify = function(object) {
36317 if (!object.map) {
3644 return object.toString();
365 }
36613 return object.map(function(k) {
367198 if (Array.isArray(k[1])) {
3686 return k[1].map(function(v) {
3692 return QS.escape(stringifyPrimitive(k[0])) + "=" + QS.escape(stringifyPrimitive(v));
370 }).join("&");
371 } else {
372192 return QS.escape(stringifyPrimitive(k[0])) + "=" + QS.escape(stringifyPrimitive(k[1]));
373 }
374 }).join("&");
375 };
376
3771 return Resources;
378
379})(Array);
380
3811Cache = (function() {
382
3831 function Cache(browser) {
3840 this.resources = browser.resources;
385 }
386
3871 Cache.prototype.get = function(url, callback) {
3880 return this.request("GET", url, null, null, callback);
389 };
390
3911 Cache.prototype.request = function(method, url, data, headers, callback) {
3920 return this.resources.request(method, url, data, headers, callback);
393 };
394
3951 return Cache;
396
397})();
398
3991STATUS = {
400 100: "Continue",
401 101: "Switching Protocols",
402 200: "OK",
403 201: "Created",
404 202: "Accepted",
405 203: "Non-Authoritative",
406 204: "No Content",
407 205: "Reset Content",
408 206: "Partial Content",
409 300: "Multiple Choices",
410 301: "Moved Permanently",
411 302: "Found",
412 303: "See Other",
413 304: "Not Modified",
414 305: "Use Proxy",
415 307: "Temporary Redirect",
416 400: "Bad Request",
417 401: "Unauthorized",
418 402: "Payment Required",
419 403: "Forbidden",
420 404: "Not Found",
421 405: "Method Not Allowed",
422 406: "Not Acceptable",
423 407: "Proxy Authentication Required",
424 408: "Request Timeout",
425 409: "Conflict",
426 410: "Gone",
427 411: "Length Required",
428 412: "Precondition Failed",
429 413: "Request Entity Too Large",
430 414: "Request-URI Too Long",
431 415: "Unsupported Media Type",
432 416: "Requested Range Not Satisfiable",
433 417: "Expectation Failed",
434 500: "Internal Server Error",
435 501: "Not Implemented",
436 502: "Bad Gateway",
437 503: "Service Unavailable",
438 504: "Gateway Timeout",
439 505: "HTTP Version Not Supported"
440};
441
4421module.exports = Resources;

zombie/storage.js

74%
188
140
48
LineHitsSource
1// Generated by CoffeeScript 1.3.3
21var Event, HTML, Storage, StorageArea, StorageEvent, Storages;
3
41HTML = require("jsdom").dom.level3.html;
5
61Event = require("jsdom").dom.level3.events.Event;
7
81StorageArea = (function() {
9
101 function StorageArea() {
1116 this._items = [];
1216 this._storages = [];
13 }
14
151 StorageArea.prototype._fire = function(source, key, oldValue, newValue) {
1634 var event, storage, window, _i, _len, _ref, _ref1, _results;
1734 _ref = this._storages;
1834 _results = [];
1934 for (_i = 0, _len = _ref.length; _i < _len; _i++) {
200 _ref1 = _ref[_i], storage = _ref1[0], window = _ref1[1];
210 if (storage === source) {
220 continue;
23 }
240 event = new StorageEvent(storage, window.location.href, key, oldValue, newValue);
250 _results.push(window.browser.dispatchEvent(window, event));
26 }
2734 return _results;
28 };
29
301 StorageArea.prototype.__defineGetter__("length", function() {
3112 var i, k;
3212 i = 0;
3312 for (k in this._items) {
3412 ++i;
35 }
3612 return i;
37 });
38
391 StorageArea.prototype.key = function(index) {
4020 var i, k;
4120 i = 0;
4220 for (k in this._items) {
4322 if (i === index) {
4414 return k;
45 }
468 ++i;
47 }
48 };
49
501 StorageArea.prototype.get = function(key) {
5124 return this._items[key];
52 };
53
541 StorageArea.prototype.set = function(source, key, value) {
5526 var oldValue;
5626 oldValue = this._items[key];
5726 this._items[key] = value;
5826 return this._fire(source, key, oldValue, value);
59 };
60
611 StorageArea.prototype.remove = function(source, key) {
624 var oldValue;
634 oldValue = this._items[key];
644 delete this._items[key];
654 return this._fire(source, key, oldValue);
66 };
67
681 StorageArea.prototype.clear = function(source) {
694 this._items = [];
704 return this._fire(source);
71 };
72
731 StorageArea.prototype.associate = function(storage, window) {
740 return this._storages.push([storage, window]);
75 };
76
771 StorageArea.prototype.__defineGetter__("pairs", function() {
782 var k, v;
792 return (function() {
802 var _ref, _results;
812 _ref = this._items;
822 _results = [];
832 for (k in _ref) {
842 v = _ref[k];
852 _results.push([k, v]);
86 }
872 return _results;
88 }).call(this);
89 });
90
911 StorageArea.prototype.toString = function() {
920 var k, v;
930 return ((function() {
940 var _ref, _results;
950 _ref = this._items;
960 _results = [];
970 for (k in _ref) {
980 v = _ref[k];
990 _results.push("" + k + " = " + v);
100 }
1010 return _results;
102 }).call(this)).join("\n");
103 };
104
1051 return StorageArea;
106
107})();
108
1091Storage = (function() {
110
1111 function Storage(_area) {
11222 this._area = _area;
113 }
114
1151 Storage.prototype.__defineGetter__("length", function() {
11612 return this._area.length;
117 });
118
1191 Storage.prototype.key = function(index) {
12020 return this._area.key(index);
121 };
122
1231 Storage.prototype.getItem = function(key) {
12424 return this._area.get(key.toString());
125 };
126
1271 Storage.prototype.setItem = function(key, value) {
12826 return this._area.set(this, key.toString(), value);
129 };
130
1311 Storage.prototype.removeItem = function(key) {
1324 return this._area.remove(this, key.toString());
133 };
134
1351 Storage.prototype.clear = function() {
1364 return this._area.clear(this);
137 };
138
1391 Storage.prototype.dump = function() {
1400 return this._area.dump();
141 };
142
1431 return Storage;
144
145})();
146
1471StorageEvent = function(storage, url, key, oldValue, newValue) {
1480 Event.call(this, "storage");
1490 this.__defineGetter__("url", function() {
1500 return url;
151 });
1520 this.__defineGetter__("storageArea", function() {
1530 return storage;
154 });
1550 this.__defineGetter__("key", function() {
1560 return key;
157 });
1580 this.__defineGetter__("oldValue", function() {
1590 return oldValue;
160 });
1610 return this.__defineGetter__("newValue", function() {
1620 return newValue;
163 });
164};
165
1661StorageEvent.prototype.__proto__ = Event.prototype;
167
1681HTML.SECURITY_ERR = 18;
169
1701Storages = (function() {
171
1721 function Storages() {
173195 this._locals = {};
174195 this._sessions = {};
175 }
176
1771 Storages.prototype.local = function(host) {
17811 var area, _base, _ref;
17911 area = (_ref = (_base = this._locals)[host]) != null ? _ref : _base[host] = new StorageArea();
18011 return new Storage(area);
181 };
182
1831 Storages.prototype.session = function(host) {
18411 var area, _base, _ref;
18511 area = (_ref = (_base = this._sessions)[host]) != null ? _ref : _base[host] = new StorageArea();
18611 return new Storage(area);
187 };
188
1891 Storages.prototype.extend = function(window) {
190223 var storages;
191223 storages = this;
192223 window.StorageEvent = StorageEvent;
193223 Object.defineProperty(window, "localStorage", {
194 get: function() {
1956 var _ref;
1966 return (_ref = this.document) != null ? _ref._localStorage || (_ref._localStorage = storages.local(this.location.host)) : void 0;
197 }
198 });
199223 return Object.defineProperty(window, "sessionStorage", {
200 get: function() {
2016 var _ref;
2026 return (_ref = this.document) != null ? _ref._sessionStorage || (_ref._sessionStorage = storages.session(this.location.host)) : void 0;
203 }
204 });
205 };
206
2071 Storages.prototype.dump = function() {
2080 var area, domain, pair, pairs, serialized, _i, _j, _len, _len1, _ref, _ref1;
2090 serialized = [];
2100 _ref = this._locals;
2110 for (domain in _ref) {
2120 area = _ref[domain];
2130 pairs = area.pairs;
2140 serialized.push("" + domain + " local:");
2150 for (_i = 0, _len = pairs.length; _i < _len; _i++) {
2160 pair = pairs[_i];
2170 serialized.push(" " + pair[0] + " = " + pair[1]);
218 }
219 }
2200 _ref1 = this._sessions;
2210 for (domain in _ref1) {
2220 area = _ref1[domain];
2230 pairs = area.pairs;
2240 serialized.push("" + domain + " session:");
2250 for (_j = 0, _len1 = pairs.length; _j < _len1; _j++) {
2260 pair = pairs[_j];
2270 serialized.push(" " + pair[0] + " = " + pair[1]);
228 }
229 }
2300 return serialized;
231 };
232
2331 Storages.prototype.save = function() {
2341 var area, domain, pair, pairs, serialized, _i, _j, _len, _len1, _ref, _ref1;
2351 serialized = ["# Saved on " + (new Date().toISOString())];
2361 _ref = this._locals;
2371 for (domain in _ref) {
2381 area = _ref[domain];
2391 pairs = area.pairs;
2401 if (pairs.length > 0) {
2411 serialized.push("" + domain + " local:");
2421 for (_i = 0, _len = pairs.length; _i < _len; _i++) {
2431 pair = pairs[_i];
2441 serialized.push(" " + (escape(pair[0])) + " = " + (escape(pair[1])));
245 }
246 }
247 }
2481 _ref1 = this._sessions;
2491 for (domain in _ref1) {
2501 area = _ref1[domain];
2511 pairs = area.pairs;
2521 if (pairs.length > 0) {
2531 serialized.push("" + domain + " session:");
2541 for (_j = 0, _len1 = pairs.length; _j < _len1; _j++) {
2551 pair = pairs[_j];
2561 serialized.push(" " + (escape(pair[0])) + " = " + (escape(pair[1])));
257 }
258 }
259 }
2601 return serialized.join("\n") + "\n";
261 };
262
2631 Storages.prototype.load = function(serialized) {
2641 var domain, item, key, storage, type, value, _i, _len, _ref, _ref1, _ref2, _results;
2651 storage = null;
2661 _ref = serialized.split(/\n+/);
2671 _results = [];
2681 for (_i = 0, _len = _ref.length; _i < _len; _i++) {
2696 item = _ref[_i];
2706 if (item[0] === "#" || item === "") {
2712 continue;
272 }
2734 if (item[0] === " ") {
2742 _ref1 = item.split("="), key = _ref1[0], value = _ref1[1];
2752 if (storage) {
2762 _results.push(storage.setItem(unescape(key.trim()), unescape(value.trim())));
277 } else {
2780 throw "Must specify storage type using local: or session:";
279 }
280 } else {
2812 _ref2 = item.split(" "), domain = _ref2[0], type = _ref2[1];
2822 if (type === "local:") {
2831 _results.push(storage = this.local(domain));
2841 } else if (type === "session:") {
2851 _results.push(storage = this.session(domain));
286 } else {
2870 throw "Unkown storage type " + type;
288 }
289 }
290 }
2911 return _results;
292 };
293
2941 return Storages;
295
296})();
297
2981module.exports = Storages;

zombie/windows.js

95%
193
184
9
LineHitsSource
1// Generated by CoffeeScript 1.3.3
21var Console, EventSource, Events, File, HTML, History, JSDOM, Screen, URL, WebSocket, Windows;
3
41Console = require("./console");
5
61History = require("./history");
7
81JSDOM = require("jsdom");
9
101HTML = JSDOM.dom.level3.html;
11
121URL = require("url");
13
141EventSource = require("eventsource");
15
161WebSocket = require("ws");
17
181Events = JSDOM.dom.level3.events;
19
201Windows = (function() {
21
221 function Windows(browser) {
23195 this._browser = browser;
24195 this._named = {};
25195 this._stack = [];
26195 this.open({});
27 }
28
291 Windows.prototype.open = function(options) {
30224 var name, window, _base;
31224 if (options == null) {
320 options = {};
33 }
34224 name = options.name || this._browser.name || "";
35224 if (options.parent) {
3619 window = this._create(name, options);
37 } else {
38205 if (name === "_blank") {
391 window = this._create(name, options);
40 } else {
41204 window = (_base = this._named)[name] || (_base[name] = this._create(name, options));
42 }
43205 this._stack.push(window);
44 }
45224 if (options.url) {
463 window.location = options.url;
47221 } else if (!window.document) {
48220 window.location = "about:blank";
49 }
50224 if (!options.parent) {
51205 this.select(window);
52 }
53224 return window;
54 };
55
561 Windows.prototype.get = function(name_or_index) {
5717 return this._named[name_or_index] || this._stack[name_or_index];
58 };
59
601 Windows.prototype.all = function() {
617 return this._stack.slice();
62 };
63
641 Windows.prototype.__defineGetter__("count", function() {
659 return this._stack.length;
66 });
67
681 Windows.prototype.close = function(window) {
695 var index;
705 window = this._named[window] || this._stack[window] || window || this._current;
715 index = this._stack.indexOf(window);
725 if (!(index >= 0)) {
730 return;
74 }
755 if (!window.closed) {
765 window.closed = true;
775 window._close();
78 }
795 delete this._named[window.name];
805 this._stack.splice(index, 1);
815 if (window === this._current) {
824 this._current = null;
834 if (index > 0) {
842 this.select(this._stack[index - 1]);
85 } else {
862 this.select(this._stack[0]);
87 }
88 }
89 };
90
911 Windows.prototype.select = function(window) {
92225 var onblur, onfocus, previous, _ref;
93225 window = this._named[window] || this._stack[window] || window;
94225 if (!~this._stack.indexOf(window)) {
955 return;
96 }
97220 _ref = [this._current, window], previous = _ref[0], this._current = _ref[1];
98220 if (window.document && previous !== window) {
99212 onfocus = window.document.createEvent("HTMLEvents");
100212 onfocus.initEvent("focus", false, false);
101212 window.dispatchEvent(onfocus);
102212 if (previous) {
10314 onblur = window.document.createEvent("HTMLEvents");
10414 onblur.initEvent("blur", false, false);
10514 previous.dispatchEvent(onblur);
106 }
107 }
108 };
109
1101 Windows.prototype.__defineGetter__("current", function() {
1111574 return this._current;
112 });
113
1141 Windows.prototype._create = function(name, _arg) {
115223 var eventloop, global, opener, parent, window,
116 _this = this;
117223 parent = _arg.parent, opener = _arg.opener;
118223 window = JSDOM.createWindow(HTML);
119223 global = window.getGlobal();
120223 Object.defineProperty(window, "browser", {
121 value: this._browser
122 });
123223 eventloop = this._browser._eventloop;
124223 eventloop.apply(window);
125223 Object.defineProperty(window, "name", {
126 value: name || ""
127 });
128223 if (parent) {
12919 Object.defineProperty(window, "parent", {
130 value: parent.getGlobal()
131 });
13219 Object.defineProperty(window, "top", {
133 value: parent.top.getGlobal()
134 });
135 } else {
136204 Object.defineProperty(window, "parent", {
137 value: window.getGlobal()
138 });
139204 Object.defineProperty(window, "top", {
140 value: window.getGlobal()
141 });
142 }
143223 Object.defineProperty(window, "history", {
144 value: new History(window)
145 });
146223 Object.defineProperty(window, "opener", {
147 value: opener != null ? opener.getGlobal() : void 0
148 });
149223 Object.defineProperty(window, "title", {
150 get: function() {
1513 return this.document.title;
152 },
153 set: function(title) {
1541 return this.document.title = title;
155 }
156 });
157223 window.closed = false;
158223 Object.defineProperties(window.navigator, {
159 cookieEnabled: {
160 value: true
161 },
162 javaEnabled: {
163 value: function() {
1641 return false;
165 }
166 },
167 plugins: {
168 value: []
169 },
170 vendor: {
171 value: "Zombie Industries"
172 }
173 });
174223 this._browser._cookies.extend(window);
175223 this._browser._storages.extend(window);
176223 this._browser._interact.extend(window);
177223 this._browser._xhr.extend(window);
178223 Object.defineProperties(window, {
179 File: {
180 value: File
181 },
182 Event: {
183 value: Events.Event
184 },
185 screen: {
186 value: new Screen()
187 },
188 MouseEvent: {
189 value: Events.MouseEvent
190 },
191 MutationEvent: {
192 value: Events.MutationEvent
193 },
194 UIEvent: {
195 value: Events.UIEvent
196 }
197 });
198223 window.atob = function(string) {
1991 return new Buffer(string, "base64").toString("utf8");
200 };
201223 window.btoa = function(string) {
2021 return new Buffer(string, "utf8").toString("base64");
203 };
204223 window.EventSource = function(url) {
2051 url = URL.resolve(window.location, url);
2061 window.setInterval((function() {}), 100);
2071 return new EventSource(url);
208 };
209223 window.WebSocket = function(url, protocol) {
2104 var origin;
2114 origin = "" + window.location.protocol + "//" + window.location.host;
2124 return new WebSocket(url, {
213 origin: origin,
214 protocol: protocol
215 });
216 };
217223 window.Image = function(width, height) {
21812 var img;
21912 img = new HTML.HTMLImageElement(window.document);
22012 img.width = width;
22112 img.height = height;
22212 return img;
223 };
224223 window.console = new Console(this._browser.silent);
225223 window.resizeTo = function(width, height) {
2261 window.outerWidth = window.innerWidth = width;
2271 return window.outerHeight = window.innerHeight = height;
228 };
229223 window.resizeBy = function(width, height) {
2301 return window.resizeTo(window.outerWidth + width, window.outerHeight + height);
231 };
232223 window.postMessage = function(data, targetOrigin) {
2337 var document, event, origin;
2347 document = window.document;
2357 if (!document) {
2360 return;
237 }
2387 event = document.createEvent("MessageEvent");
2397 event.initEvent("message", false, false);
2407 event.data = data;
2417 event.source = Windows.inContext;
2427 origin = event.source.location;
2437 event.origin = URL.format({
244 protocol: origin.protocol,
245 host: origin.host
246 });
2477 return process.nextTick(function() {
2487 return eventloop.dispatch(window, event);
249 });
250 };
251223 window.addEventListener("focus", function(event) {
252212 var onfocus;
253212 if (window.document.activeElement) {
2540 onfocus = window.document.createEvent("HTMLEvents");
2550 onfocus.initEvent("focus", false, false);
2560 return window.document.activeElement.dispatchEvent(onfocus);
257 }
258 });
259223 window.addEventListener("blur", function(event) {
26014 var onblur;
26114 if (window.document.activeElement) {
2620 onblur = window.document.createEvent("HTMLEvents");
2630 onblur.initEvent("blur", false, false);
2640 return window.document.activeElement.dispatchEvent(onblur);
265 }
266 });
267223 window._evaluate = function(code, filename) {
268739 try {
269739 Windows.inContext = window;
270739 if (typeof code === "string" || code instanceof String) {
271252 return global.run(code, filename);
272487 } else if (code) {
273487 return code.call(global);
274 }
275 } finally {
276739 Windows.inContext = null;
277 }
278 };
279223 window.onerror = function(event) {
2804 var error;
2814 error = event.error || new Error("Error loading script");
2824 return _this._browser.emit("error", error);
283 };
284223 window.open = function(url, name, features) {
2855 if (url) {
2863 url = URL.resolve(window.location, url);
287 }
2885 return _this.open({
289 url: url,
290 name: name,
291 opener: window
292 });
293 };
294223 window._close = window.close;
295223 window.close = function() {
2962 if (opener) {
2971 _this.close(window);
298 } else {
2991 _this._browser.log("Scripts may not close windows that were not opened by script");
300 }
301 };
302223 return window;
303 };
304
3051 return Windows;
306
307})();
308
3091Screen = (function() {
310
3111 function Screen() {
312223 this.width = 1280;
313223 this.height = 800;
314223 this.left = 0;
315223 this.top = 0;
316 }
317
3181 Screen.prototype.__defineGetter__("availLeft", function() {
3191 return 0;
320 });
321
3221 Screen.prototype.__defineGetter__("availTop", function() {
3231 return 0;
324 });
325
3261 Screen.prototype.__defineGetter__("availWidth", function() {
3271 return this.width;
328 });
329
3301 Screen.prototype.__defineGetter__("availHeight", function() {
3311 return this.height;
332 });
333
3341 Screen.prototype.__defineGetter__("colorDepth", function() {
3351 return 24;
336 });
337
3381 Screen.prototype.__defineGetter__("pixelDepth", function() {
3391 return 24;
340 });
341
3421 return Screen;
343
344})();
345
3461File = (function() {
347
3481 function File() {}
349
3501 return File;
351
352})();
353
3541module.exports = Windows;

zombie/console.js

56%
60
34
26
LineHitsSource
1// Generated by CoffeeScript 1.3.3
21var Console, Util;
3
41Util = require("util");
5
61Console = (function() {
7
81 function Console(_silent) {
9223 this._silent = _silent;
10 }
11
121 Console.prototype.assert = console.assert.bind(console);
13
141 Console.prototype.count = function(name) {
150 var _base;
160 this._counters || (this._counters = {});
170 (_base = this._counters)[name] || (_base[name] = 0);
180 this._counters[name]++;
190 return this.log("" + name + ": " + this._counters[name]);
20 };
21
221 Console.prototype.debug = function() {
230 return this.log.apply(this, arguments);
24 };
25
261 Console.prototype.error = function() {
270 return this.log.apply(this, arguments);
28 };
29
301 Console.prototype.group = function() {};
31
321 Console.prototype.groupCollapsed = function() {};
33
341 Console.prototype.groupEnd = function() {};
35
361 Console.prototype.info = function() {
370 return this.log.apply(this, arguments);
38 };
39
401 Console.prototype.log = function() {
418 var arg, formatted, output;
428 formatted = (function() {
438 var _i, _len, _results;
448 _results = [];
458 for (_i = 0, _len = arguments.length; _i < _len; _i++) {
4625 arg = arguments[_i];
4725 _results.push(typeof arg === "string" ? arg : Util.inspect(arg, console.showHidden, console.depth));
48 }
498 return _results;
50 }).apply(this, arguments);
518 if (typeof Util.format === "function") {
528 output = Util.format.apply(this, formatted) + "\n";
53 } else {
540 output = formatted.join(" ") + "\n";
55 }
568 this._output || (this._output = []);
578 this._output.push(output);
588 if (!this._silent) {
590 return process.stdout.write(output);
60 }
61 };
62
631 Console.prototype.warn = function() {
640 return this.log.apply(this, arguments);
65 };
66
671 Console.prototype.time = function(name) {
680 this._timers || (this._timers = {});
690 return this._timers[name] = Date.now();
70 };
71
721 Console.prototype.timeEnd = function(name) {
730 var start;
740 if (!this._timers) {
750 return;
76 }
770 start = this._timers[name];
780 if (!start) {
790 return;
80 }
810 delete this._timers[name];
820 return this.log("" + name + ": " + (Date.now() - start) + "ms");
83 };
84
851 Console.prototype.trace = function() {
860 var stack;
870 stack = (new Error).stack.split("\n");
880 stack[0] = "console.trace()";
890 return this.log(stack.join("\n"));
90 };
91
921 Console.prototype.__defineGetter__("output", function() {
930 return (this._output ? this._output.join("\n") : "");
94 });
95
961 return Console;
97
98})();
99
1001module.exports = Console;

zombie/history.js

89%
259
233
26
LineHitsSource
1// Generated by CoffeeScript 1.3.3
21var ABOUT_BLANK, Entry, HTML, History, JSDOM, Location, Scripts, URL, util;
3
41util = require("util");
5
61JSDOM = require("jsdom");
7
81HTML = JSDOM.dom.level3.html;
9
101Scripts = require("./scripts");
11
121URL = require("url");
13
141ABOUT_BLANK = URL.parse("about:blank");
15
161Entry = (function() {
17
181 function Entry(url, options) {
19486 if (options) {
208 this.state = options.state;
218 this.title = options.title;
228 this.pop = !!options.pop;
23 }
24486 this.update(url);
25 }
26
271 Entry.prototype.update = function(url) {
28956 if (/^file:/i.test(url)) {
292 return this.url = {
30 protocol: "file:",
31 hostname: "",
32 pathname: url.slice(6),
33 href: url
34 };
35 } else {
36954 return this.url = URL.parse(URL.format(url));
37 }
38 };
39
401 return Entry;
41
42})();
43
441History = (function() {
45
461 function History(window) {
47223 var _this = this;
48223 this._use(window);
49223 this._stack = [];
50223 this._index = 0;
51223 this._location = new Location(this);
52223 Object.defineProperty(this, "current", {
53 get: function() {
54590 var _ref;
55590 return ((_ref = _this._stack[_this._index]) != null ? _ref.url : void 0) || ABOUT_BLANK;
56 }
57 });
58 }
59
601 History.prototype._use = function(window) {
61223 var _this = this;
62223 this._window = window;
63223 this._browser = this._window.browser;
64223 return Object.defineProperty(this._window, "location", {
65 get: function() {
66428 return _this._location;
67 },
68 set: function(url) {
69263 return _this._assign(_this._resolve(url));
70 }
71 });
72 };
73
741 History.prototype._pageChanged = function(was) {
75461 var evt, url, _ref;
76461 url = (_ref = this._stack[this._index]) != null ? _ref.url : void 0;
77461 if (!was || was.host !== url.host || was.pathname !== url.pathname || was.query !== url.query) {
78451 return this._resource(url);
7910 } else if (was.hash !== url.hash) {
806 evt = this._window.document.createEvent("HTMLEvents");
816 evt.initEvent("hashchange", true, false);
826 return this._browser.dispatchEvent(this._window, evt);
83 } else {
844 return this._resource(url);
85 }
86 };
87
881 History.prototype._resource = function(url, method, data, headers) {
89474 var referer, _ref, _ref1,
90 _this = this;
91474 switch (url.protocol) {
92 case "about:":
93220 this._createDocument(this._window, ABOUT_BLANK);
94220 this._stack[this._index].update(url);
95220 return this._browser.emit("loaded", this._browser);
96 case "javascript:":
974 this._createDocument(this._window, ABOUT_BLANK);
984 if (!this._stack[this._index]) {
990 this._stack[this._index].update(ABOUT_BLANK);
100 }
1014 try {
1024 this._window._evaluate(url.pathname, "javascript:");
1034 return this._browser.emit("loaded", this._browser);
104 } catch (error) {
1050 return this._browser.emit("error", error);
106 }
1070 break;
108 case "http:":
109 case "https:":
110 case "file:":
111250 headers = headers ? JSON.parse(JSON.stringify(headers)) : {};
112250 referer = ((_ref = this._stack[this._index - 1]) != null ? (_ref1 = _ref.url) != null ? _ref1.href : void 0 : void 0) || this._browser.referer;
113250 if (referer) {
11444 headers["referer"] = referer;
115 }
116250 method = (method || "GET").toUpperCase();
117250 return this._browser.resources.request(method, url, data, headers, function(error, response) {
118250 var document, evt;
119250 if (error) {
1200 document = _this._createDocument(_this._window, url);
1210 document.open();
1220 document.write(error.message);
1230 document.close();
1240 return _this._browser.emit("error", error);
125 } else {
126250 document = _this._createDocument(_this._window, response.url);
127250 _this._browser.response = [response.statusCode, response.headers, response.body];
128250 url = URL.parse(response.url);
129250 _this._stack[_this._index].update(url);
130250 if (response.body) {
131228 document.open();
132228 document.write(response.body);
133228 document.close();
134 }
135250 if (url.hash) {
1364 evt = _this._window.document.createEvent("HTMLEvents");
1374 evt.initEvent("hashchange", true, false);
1384 _this._browser.dispatchEvent(_this._window, evt);
139 }
140250 if (response.statusCode >= 400) {
14111 return _this._browser.emit("error", new Error("Server returned status code " + response.statusCode));
142239 } else if (document.documentElement) {
143239 return _this._browser.emit("loaded", _this._browser);
144 } else {
1450 return _this._browser.emit("error", new Error("Could not parse document at " + (URL.format(url))));
146 }
147 }
148 });
149 default:
1500 throw new Error("Cannot load resource: " + (URL.format(url)));
151 }
152 };
153
1541 History.prototype._createDocument = function(window, url) {
155474 var document, jsdom_opts,
156 _this = this;
157474 jsdom_opts = {
158 deferClose: true,
159 features: {
160 MutationEvents: "2.0",
161 ProcessExternalResources: [],
162 FetchExternalResources: ["iframe"]
163 },
164 parser: this._browser.htmlParser,
165 url: URL.format(url)
166 };
167474 if (this._browser.runScripts) {
168469 jsdom_opts.features.ProcessExternalResources.push("script");
169469 jsdom_opts.features.FetchExternalResources.push("script");
170 }
171474 if (this._browser.loadCSS) {
172474 jsdom_opts.features.FetchExternalResources.push("css");
173 }
174474 document = JSDOM.jsdom(null, HTML, jsdom_opts);
175474 if (this._browser.runScripts) {
176469 Scripts.addInlineScriptSupport(document);
177 }
178474 window.document = document;
179474 document.window = document.parentWindow = window;
180474 window.navigator.userAgent = this._browser.userAgent;
181474 document.addEventListener("DOMContentLoaded", function(event) {
182229 var onload;
183229 onload = document.createEvent("HTMLEvents");
184229 onload.initEvent("load", false, false);
185229 return window.dispatchEvent(onload);
186 });
187474 return document;
188 };
189
1901 History.prototype.forward = function() {
1912 return this.go(1);
192 };
193
1941 History.prototype.back = function() {
1955 return this.go(-1);
196 };
197
1981 History.prototype.go = function(amount) {
1997 var entry, new_index, popstate, was, _ref, _ref1, _ref2;
2007 was = (_ref = this._stack[this._index]) != null ? _ref.url : void 0;
2017 new_index = this._index + amount;
2027 if (new_index < 0) {
2031 new_index = 0;
204 }
2057 if (this._stack.length > 0 && new_index >= this._stack.length) {
2061 new_index = this._stack.length - 1;
207 }
2087 if (new_index !== this._index && (entry = this._stack[new_index])) {
2095 this._index = new_index;
2105 if (entry.pop) {
2113 if (was.host !== ((_ref1 = this._stack[this._index]) != null ? (_ref2 = _ref1.url) != null ? _ref2.host : void 0 : void 0)) {
2120 this._resource(this._stack[this._index].url);
213 } else {
2143 popstate = this._window.document.createEvent("HTMLEvents");
2153 popstate.initEvent("popstate", false, false);
2163 popstate.state = entry.state;
2173 this._browser.dispatchEvent(this._window, popstate);
218 }
219 } else {
2202 this._pageChanged(was);
221 }
222 }
223 };
224
2251 History.prototype.__defineGetter__("length", function() {
22621 return this._stack.length;
227 });
228
2291 History.prototype.pushState = function(state, title, url) {
2306 url = this._resolve(url);
2316 this._advance();
2326 return this._stack[this._index] = new Entry(url, {
233 state: state,
234 title: title,
235 pop: true
236 });
237 };
238
2391 History.prototype.replaceState = function(state, title, url) {
2402 if (this._index < 0) {
2410 this._index = 0;
242 }
2432 url = this._resolve(url);
2442 return this._stack[this._index] = new Entry(url, {
245 state: state,
246 title: title,
247 pop: true
248 });
249 };
250
2511 History.prototype._resolve = function(url) {
252748 var _ref, _ref1;
253748 if (url) {
254741 if (/^\w+:/i.test(url)) {
255721 return url;
256 } else {
25720 return URL.resolve((_ref = this._stack[this._index]) != null ? _ref.url : void 0, url);
258 }
259 } else {
2607 return (_ref1 = this._stack[this._index]) != null ? _ref1.url : void 0;
261 }
262 };
263
2641 History.prototype._assign = function(url) {
265458 var was, _ref;
266458 url = this._resolve(url);
267458 was = (_ref = this._stack[this._index]) != null ? _ref.url : void 0;
268458 this._stack = this._stack.slice(0, this._index + 1 || 9e9);
269458 this._advance();
270458 this._stack[this._index] = new Entry(url);
271458 return this._pageChanged(was);
272 };
273
2741 History.prototype._replace = function(url) {
2751 var was, _ref;
2761 url = this._resolve(url);
2771 was = (_ref = this._stack[this._index]) != null ? _ref.url : void 0;
2781 if (this._index < 0) {
2790 this._index = 0;
280 }
2811 this._stack[this._index] = new Entry(url);
2821 return this._pageChanged(was);
283 };
284
2851 History.prototype._loadPage = function(force) {
2861 if (this._stack[this._index]) {
2871 return this._resource(this._stack[this._index].url);
288 }
289 };
290
2911 History.prototype._submit = function(url, method, data, enctype) {
29218 var headers;
29318 headers = {
294 "content-type": enctype || "application/x-www-form-urlencoded"
295 };
29618 this._stack = this._stack.slice(0, this._index + 1 || 9e9);
29718 url = this._resolve(url);
29818 this._advance();
29918 this._stack[this._index] = new Entry(url);
30018 return this._resource(this._stack[this._index].url, method, data, headers);
301 };
302
3031 History.prototype.dump = function() {
3040 var dump, entry, i, line, _ref;
3050 dump = [];
3060 _ref = this._stack;
3070 for (i in _ref) {
3080 entry = _ref[i];
3090 i = Number(i);
3100 line = i === this._index ? "" + (i + 1) + ": " : "" + (i + 1) + ". ";
3110 line += URL.format(entry.url);
3120 if (entry.state) {
3130 line += " state: " + util.inspect(entry.state);
314 }
3150 dump.push(line);
316 }
3170 return dump;
318 };
319
3201 History.prototype.save = function() {
3211 var entry, i, line, serialized, _ref;
3221 serialized = [];
3231 _ref = this._stack;
3241 for (i in _ref) {
3251 entry = _ref[i];
3261 line = URL.format(entry.url);
3271 if (entry.pop) {
3280 line += " " + (JSON.stringify(entry.state));
329 }
3301 serialized.push(line);
331 }
3321 return serialized.join("\n") + "\n";
333 };
334
3351 History.prototype.load = function(serialized) {
3361 var line, options, state, url, _i, _len, _ref, _ref1, _results;
3371 _ref = serialized.split(/\n+/);
3381 _results = [];
3391 for (_i = 0, _len = _ref.length; _i < _len; _i++) {
3402 line = _ref[_i];
3412 line = line.trim();
3422 if (line[0] === "#" || line === "") {
3431 continue;
344 }
3451 _ref1 = line.split(/\s/), url = _ref1[0], state = _ref1[1];
3461 options = state && {
347 state: JSON.parse(state),
348 title: null,
349 pop: true
350 };
3511 this._advance();
3521 _results.push(this._stack[this._index] = new Entry(url, state));
353 }
3541 return _results;
355 };
356
3571 History.prototype._advance = function() {
358483 var current;
359483 current = this._stack[this._index];
360483 if (current && ~["http:", "https:", "file:"].indexOf(current.url.protocol)) {
36155 return ++this._index;
362 }
363 };
364
3651 return History;
366
367})();
368
3691Location = (function() {
3701 var prop, _fn, _i, _len, _ref,
371 _this = this;
372
3731 function Location(_history) {
374223 this._history = _history;
375 }
376
3771 Location.prototype.assign = function(newUrl) {
3781 return this._history._assign(newUrl);
379 };
380
3811 Location.prototype.replace = function(newUrl) {
3821 return this._history._replace(newUrl);
383 };
384
3851 Location.prototype.reload = function(force) {
3861 return this._history._loadPage(force);
387 };
388
3891 Location.prototype.toString = function() {
39088 return URL.format(this._history.current);
391 };
392
3931 Location.prototype.__defineGetter__("href", function() {
394186 var _ref;
395186 return (_ref = this._history.current) != null ? _ref.href : void 0;
396 });
397
3981 Location.prototype.__defineSetter__("href", function(new_url) {
3991 return this._history._assign(new_url);
400 });
401
4021 _ref = ["hash", "host", "hostname", "pathname", "port", "protocol", "search"];
4031 _fn = function(prop) {
4047 Location.prototype.__defineGetter__(prop, function() {
405314 var _ref1;
406314 return ((_ref1 = this._history.current) != null ? _ref1[prop] : void 0) || "";
407 });
4087 return Location.prototype.__defineSetter__(prop, function(value) {
4092 var newUrl, _ref1;
4102 newUrl = URL.parse((_ref1 = this._history.current) != null ? _ref1.href : void 0);
4112 newUrl[prop] = value;
4122 return this._history._assign(URL.format(newUrl));
413 });
414 };
4151 for (_i = 0, _len = _ref.length; _i < _len; _i++) {
4167 prop = _ref[_i];
4177 _fn(prop);
418 }
419
4201 return Location;
421
422}).call(this);
423
4241HTML.HTMLDocument.prototype.__defineGetter__("location", function() {
42598 return this.parentWindow.location;
426});
427
4281HTML.HTMLDocument.prototype.__defineSetter__("location", function(url) {
4291 if (this._parentWindow) {
4301 return this.parentWindow.location = url;
431 }
432});
433
4341module.exports = History;

zombie/xhr.js

81%
106
86
20
LineHitsSource
1// Generated by CoffeeScript 1.3.3
21var URL, XMLHttpRequest, html, http, raise;
3
41html = require("jsdom").dom.level3.html;
5
61http = require("http");
7
81URL = require("url");
9
101raise = require("./scripts").raise;
11
121html.SECURITY_ERR = 18;
13
141html.NETWORK_ERR = 19;
15
161html.ABORT_ERR = 20;
17
181XMLHttpRequest = function(window) {
1939 var reset, stateChanged,
20 _this = this;
2139 stateChanged = function(state) {
2236 _this.__defineGetter__("readyState", function() {
2324 return state;
24 });
2536 if (_this.onreadystatechange) {
2624 return window.browser._eventloop.perform(function(done) {
2724 return process.nextTick(function() {
2824 try {
2924 return _this.onreadystatechange.call(_this);
30 } catch (error) {
310 return raise({
32 element: window.document,
33 from: __filename,
34 scope: "XHR",
35 error: error
36 });
37 } finally {
3824 done();
39 }
40 });
41 });
42 }
43 };
4439 reset = function() {
4539 _this.__defineGetter__("readyState", function() {
460 return 0;
47 });
4839 _this.__defineGetter__("status", function() {
490 return 0;
50 });
5139 _this.__defineGetter__("statusText", function() {});
5239 _this.abort = function() {};
5339 _this.setRequestHeader = _this.send = function() {
540 throw new html.DOMException(html.INVALID_STATE_ERR, "Invalid state");
55 };
5639 _this.getResponseHeader = _this.getAllResponseHeaders = function() {};
5739 return _this.open = function(method, url, async, user, password) {
5812 var aborted, headers, _ref, _ref1;
5912 method = method.toUpperCase();
6012 if (/^(CONNECT|TRACE|TRACK)$/.test(method)) {
610 throw new html.DOMException(html.SECURITY_ERR, "Unsupported HTTP method");
62 }
6312 if (!/^(DELETE|GET|HEAD|OPTIONS|POST|PUT)$/.test(method)) {
640 throw new html.DOMException(html.SYNTAX_ERR, "Unsupported HTTP method");
65 }
6612 url = URL.parse(URL.resolve(window.location.href, url));
6712 url.hostname || (url.hostname = window.location.hostname);
6812 url.host = url.port ? "" + url.hostname + ":" + url.port : url.hostname;
6912 url.hash = null;
7012 if (url.host !== window.location.host) {
710 throw new html.DOMException(html.SECURITY_ERR, "Cannot make request to different domain");
72 }
7312 if ((_ref = url.protocol) !== "http:" && _ref !== "https:") {
740 throw new html.DOMException(html.NOT_SUPPORTED_ERR, "Only HTTP/S protocol supported");
75 }
7612 if (url.auth) {
770 _ref1 = url.auth.split(":"), user = _ref1[0], password = _ref1[1];
78 }
7912 this._error = null;
8012 aborted = false;
8112 this.abort = function() {
820 aborted = true;
830 return reset();
84 };
8512 headers = {};
8612 this.setRequestHeader = function(header, value) {
8729 return headers[header.toString().toLowerCase()] = value.toString();
88 };
8912 this.send = function(data) {
9012 var _this = this;
9112 this.abort = function() {
920 aborted = true;
930 this._error = new html.DOMException(html.ABORT_ERR, "Request aborted");
940 stateChanged(4);
950 return reset();
96 };
9712 return window.browser.resources.request(method, url, data, headers, function(error, response) {
9812 if (error) {
990 _this._error = new html.DOMException(html.NETWORK_ERR, error.message);
1000 stateChanged(4);
1010 return reset();
102 } else {
10312 _this.getResponseHeader = function(header) {
1041 return response.headers[header.toLowerCase()];
105 };
10612 _this.getAllResponseHeaders = function() {
10713 var header, headerStrings, value;
10813 headerStrings = (function() {
10913 var _ref2, _results;
11013 _ref2 = response.headers;
11113 _results = [];
11213 for (header in _ref2) {
11369 value = _ref2[header];
11469 _results.push("" + header + ": " + value);
115 }
11613 return _results;
117 })();
11813 return headerStrings.join("\n");
119 };
12012 _this.__defineGetter__("status", function() {
12116 return response.statusCode;
122 });
12312 _this.__defineGetter__("statusText", function() {
1249 return response.statusText;
125 });
12612 stateChanged(2);
12712 if (!aborted) {
12812 _this.__defineGetter__("responseText", function() {
12914 return response.body;
130 });
13112 _this.__defineGetter__("responseXML", function() {});
13212 return stateChanged(4);
133 }
134 }
135 });
136 };
13712 this.open = function(method, url, async, user, password) {
1380 this.abort();
1390 return this.open(method, url, async, user, password);
140 };
14112 return stateChanged(1);
142 };
143 };
14439 reset();
145};
146
1471XMLHttpRequest.UNSENT = 0;
148
1491XMLHttpRequest.OPENED = 1;
150
1511XMLHttpRequest.HEADERS_RECEIVED = 2;
152
1531XMLHttpRequest.LOADING = 3;
154
1551XMLHttpRequest.DONE = 4;
156
1571exports.use = function() {
158195 var extend;
159195 extend = function(window) {
160223 return window.XMLHttpRequest = function() {
16139 return XMLHttpRequest.call(this, window);
162 };
163 };
164195 return {
165 extend: extend
166 };
167};