Revert "Add POST support to XHR as well as .status and statusText support" This reverts commit 5ef81d249b841f44c9593ffb0158d64c7e0febfc. This appeared to make 5 XHR tests timeout. Not sure why yet. TBR=esprehn@chromium.org Review URL: https://codereview.chromium.org/808663002
diff --git a/sky/framework/xmlhttprequest.sky b/sky/framework/xmlhttprequest.sky index ce68eaf..897ad97 100644 --- a/sky/framework/xmlhttprequest.sky +++ b/sky/framework/xmlhttprequest.sky
@@ -21,24 +21,11 @@ } } -// Somewhat hacky, but works. -function stringToUTF8Buffer(string) { - var string = unescape(encodeURIComponent(string)); - var charList = string.split(''); - var uintArray = []; - for (var i = 0; i < charList.length; i++) { - uintArray.push(charList[i].charCodeAt(0)); - } - return new Uint8Array(uintArray); -} - // https://xhr.spec.whatwg.org class XMLHttpRequest { constructor() { this[kPrivate] = new Private; this.responseType = ''; // Only text and arraybuffer support for now. - this.status = null; - this.statusText = null; } onload() { @@ -82,29 +69,8 @@ this[kPrivate].headers.set(header, value); } - send(body) { + send() { var priv = this[kPrivate]; - // Handle the body before the headers as it can affect Content-Type. - if (body) { - var bodyAsBufferView = null; - if (typeof(body) === "string") { - this.setRequestHeader("Content-Type", "text/plain;charset=UTF-8"); - bodyAsBufferView = stringToUTF8Buffer(body); - } else { - bodyAsBufferView = new Uint8Array(body); - } - var dataPipe = new core.createDataPipe(); - // FIXME: body is currently assumed to be an ArrayBuffer. - var writeResult = core.writeData(dataPipe.producerHandle, - bodyAsBufferView, core.WRITE_DATA_FLAG_ALL_OR_NONE); - core.close(dataPipe.producerHandle); - // FIXME: Much better error handling needed. - console.assert(writeResult.result === core.RESULT_OK); - console.assert(writeResult.numBytes === body.length); - // 'body' is actually an array of body segments. - priv.request.body = [dataPipe.consumerHandle]; - } - var requestHeaders = []; priv.headers.forEach(function(value, key) { requestHeaders.push(key + ': ' + value); @@ -119,21 +85,14 @@ var self = this; outstandingRequests.add(this); priv.loader.start(priv.request).then(function(result) { - self.status = result.response.status_code; - self.statusText = result.response.status_line; - if (result.response.error) - throw new Error(result.response.error.description); return core.drainData(result.response.body).then(function(result) { outstandingRequests.delete(self); priv.responseArrayBuffer = result.buffer; - // Use a setTimeout to avoid exceptions in onload tripping onerror. - window.setTimeout(function() { - self.onload(); - }); + // FIXME: Catch exceptions during onload so they don't trip onerror. + self.onload(); }); }).catch(function(error) { outstandingRequests.delete(self); - // Technically this should throw a ProgressEvent. self.onerror(error); }); }
diff --git a/sky/tests/framework/xmlhttprequest/empty-responseType.sky b/sky/tests/framework/xmlhttprequest/empty-responseType.sky index f97e254..19a132b 100644 --- a/sky/tests/framework/xmlhttprequest/empty-responseType.sky +++ b/sky/tests/framework/xmlhttprequest/empty-responseType.sky
@@ -4,7 +4,9 @@ <import src="/sky/framework/xmlhttprequest.sky" as="XMLHttpRequest" /> <script> describe("xmlhttprequest.responseType", function() { - it("should default to text when empty", function(done) { + this.enableTimeouts(false); + + it("should default to text when empty", function() { var xhr = new XMLHttpRequest(); assert.equal(xhr.responseType, ""); xhr.responseType = 'foo';
diff --git a/sky/tests/framework/xmlhttprequest/responseType.sky b/sky/tests/framework/xmlhttprequest/responseType.sky index f220009..5153093 100644 --- a/sky/tests/framework/xmlhttprequest/responseType.sky +++ b/sky/tests/framework/xmlhttprequest/responseType.sky
@@ -4,11 +4,12 @@ <import src="/sky/framework/xmlhttprequest.sky" as="XMLHttpRequest" /> <script> describe("xmlhttprequest.responseType", function() { - it("should support arraybuffer", function(done) { + this.enableTimeouts(false); + + it("should support arraybuffer", function() { var xhr = new XMLHttpRequest(); - xhr.responseType = 'arraybuffer'; xhr.onload = function() { - assert.instanceOf(xhr.response, ArrayBuffer, "Response is an ArrayBuffer\n"); + assert.typeOf(this.response, "arraybuffer", "Response is an arraybuffer\n"); done(); }; xhr.open("GET", "resources/pass.txt");
diff --git a/sky/tests/framework/xmlhttprequest/unicode-post-expected.txt b/sky/tests/framework/xmlhttprequest/unicode-post-expected.txt deleted file mode 100644 index 64c865d..0000000 --- a/sky/tests/framework/xmlhttprequest/unicode-post-expected.txt +++ /dev/null
@@ -1,5 +0,0 @@ -Running 1 tests -ok 1 XMLHttpRequest should be able to post non-ascii -1 tests -1 pass -0 fail
diff --git a/sky/tests/framework/xmlhttprequest/unicode-post.sky b/sky/tests/framework/xmlhttprequest/unicode-post.sky deleted file mode 100644 index e785741..0000000 --- a/sky/tests/framework/xmlhttprequest/unicode-post.sky +++ /dev/null
@@ -1,22 +0,0 @@ -<html> -<import src="/sky/tests/resources/chai.sky" /> -<import src="/sky/tests/resources/mocha.sky" /> -<import src="/sky/framework/xmlhttprequest.sky" as="XMLHttpRequest" /> -<script> -describe('XMLHttpRequest', function() { - it('should be able to post non-ascii', function(done) { - // example utf8, #114, "I can eat glass" in arabic. - // http://www.columbia.edu/~kermit/utf8.html - var utf8_text = "أنا قادر على أكل الزجاج و هذا لا يؤلمني."; - - var xhr = new XMLHttpRequest(); - xhr.onload = function() { - assert.equal(this.responseText, utf8_text); - done(); - }; - xhr.open("GET", "/echo_post"); - xhr.send(utf8_text); - }); -}); -</script> -</html>
diff --git a/sky/tests/framework/xmlhttprequest/xhr-does-not-exist-expected.txt b/sky/tests/framework/xmlhttprequest/xhr-does-not-exist-expected.txt deleted file mode 100644 index fd4506d..0000000 --- a/sky/tests/framework/xmlhttprequest/xhr-does-not-exist-expected.txt +++ /dev/null
@@ -1,5 +0,0 @@ -Running 1 tests -ok 1 xmlhttprequest should call onerror when endpoint does not exist -1 tests -1 pass -0 fail
diff --git a/sky/tests/framework/xmlhttprequest/xhr-does-not-exist.sky b/sky/tests/framework/xmlhttprequest/xhr-does-not-exist.sky deleted file mode 100644 index e88c4c9..0000000 --- a/sky/tests/framework/xmlhttprequest/xhr-does-not-exist.sky +++ /dev/null
@@ -1,26 +0,0 @@ -<sky> -<import src="/sky/tests/resources/chai.sky" /> -<import src="/sky/tests/resources/mocha.sky" /> -<import src="/sky/framework/xmlhttprequest.sky" as="XMLHttpRequest" /> -<script> -describe("xmlhttprequest", function() { - it("should call onerror when endpoint does not exist", function(done) { - var xhr = new XMLHttpRequest(); - xhr.open("GET", "does_not_exist.html"); - xhr.onerror = function() { - assert.fail("onload", "onerror", "onerror should not be called."); - done(); - } - xhr.onload = function() { - // Missing files are application-level errors, not network errors - // so onload fires, not onerror. - assert.equal(xhr.status, 404); - assert.equal(xhr.statusText, "HTTP/1.1 404 Not Found", - "status text should also be 404"); - done(); - } - xhr.send(); - }); -}); -</script> -</sky>
diff --git a/sky/tests/framework/xmlhttprequest/xhr-relative.sky b/sky/tests/framework/xmlhttprequest/xhr-relative.sky index 632810f..19a9034 100644 --- a/sky/tests/framework/xmlhttprequest/xhr-relative.sky +++ b/sky/tests/framework/xmlhttprequest/xhr-relative.sky
@@ -4,6 +4,8 @@ <import src="/sky/framework/xmlhttprequest.sky" as="XMLHttpRequest" /> <script> describe('XMLHttpRequest', function() { + this.enableTimeouts(false); + it('should be able to fetch relative urls', function(done) { var xhr = new XMLHttpRequest();
diff --git a/sky/tests/framework/xmlhttprequest/xhr.sky b/sky/tests/framework/xmlhttprequest/xhr.sky index d730963..c19f36d 100644 --- a/sky/tests/framework/xmlhttprequest/xhr.sky +++ b/sky/tests/framework/xmlhttprequest/xhr.sky
@@ -4,6 +4,8 @@ <import src="/sky/framework/xmlhttprequest.sky" as="XMLHttpRequest" /> <script> describe('XMLHttpRequest', function() { + this.enableTimeouts(false); + it('should be able to fetch text files', function(done) { var xhr = new XMLHttpRequest();
diff --git a/sky/tools/skygo/sky_server.go b/sky/tools/skygo/sky_server.go index e851487..c69fdd5 100644 --- a/sky/tools/skygo/sky_server.go +++ b/sky/tools/skygo/sky_server.go
@@ -6,7 +6,6 @@ import ( "flag" - "io/ioutil" "net/http" "path" "strings" @@ -39,11 +38,6 @@ genRoot := path.Join(root, "out", *configuration, "gen") http.Handle("/", skyHandler(root)) - http.HandleFunc("/echo_post", func(w http.ResponseWriter, r *http.Request) { - defer r.Body.Close() - body, _ := ioutil.ReadAll(r.Body) - w.Write(body) - }) http.Handle("/mojo/public/", http.StripPrefix("/mojo/public/", skyHandler(path.Join(genRoot, "mojo", "public")))) http.Handle("/mojo/services/", http.StripPrefix("/mojo/services/", skyHandler(path.Join(genRoot, "mojo", "services")))) http.Handle("/sky/services/", http.StripPrefix("/sky/services/", skyHandler(path.Join(genRoot, "sky", "services"))))
diff --git a/sky/tools/skygo/sky_server.sha1 b/sky/tools/skygo/sky_server.sha1 index 8b7306e..38a08c7 100644 --- a/sky/tools/skygo/sky_server.sha1 +++ b/sky/tools/skygo/sky_server.sha1
@@ -1 +1 @@ -f6b808791e8ab0290cb18bc8b444159074c395ae \ No newline at end of file +7b6d0d60949ad71a35a88430b2eb7d70fe7334b6 \ No newline at end of file