rob@77: var sys = require("util") rob@77: , assert = require("assert") rob@77: , http = require("http") rob@77: , XMLHttpRequest = require("../lib/XMLHttpRequest").XMLHttpRequest rob@77: , xhr; rob@77: rob@77: // Test server rob@77: var server = http.createServer(function (req, res) { rob@77: var body = (req.method != "HEAD" ? "Hello World" : ""); rob@77: rob@77: res.writeHead(200, { rob@77: "Content-Type": "text/plain", rob@77: "Content-Length": Buffer.byteLength(body) rob@77: }); rob@77: // HEAD has no body rob@77: if (req.method != "HEAD") { rob@77: res.write(body); rob@77: } rob@77: res.end(); rob@77: assert.equal(onreadystatechange, true); rob@77: assert.equal(readystatechange, true); rob@77: assert.equal(removed, true); rob@77: sys.puts("done"); rob@77: this.close(); rob@77: }).listen(8000); rob@77: rob@77: xhr = new XMLHttpRequest(); rob@77: rob@77: // Track event calls rob@77: var onreadystatechange = false; rob@77: var readystatechange = false; rob@77: var removed = true; rob@77: var removedEvent = function() { rob@77: removed = false; rob@77: }; rob@77: rob@77: xhr.onreadystatechange = function() { rob@77: onreadystatechange = true; rob@77: }; rob@77: rob@77: xhr.addEventListener("readystatechange", function() { rob@77: readystatechange = true; rob@77: }); rob@77: rob@77: // This isn't perfect, won't guarantee it was added in the first place rob@77: xhr.addEventListener("readystatechange", removedEvent); rob@77: xhr.removeEventListener("readystatechange", removedEvent); rob@77: rob@77: xhr.open("GET", "http://localhost:8000"); rob@77: xhr.send();