From ff00ab9fcaf0f791b1873ca1cd4d80e8a6dd6cda Mon Sep 17 00:00:00 2001 From: James Lal Date: Wed, 9 Jan 2013 11:21:04 +0100 Subject: utilize moz-chunked-text when given the option --- test/caldav/xhr_test.js | 63 ++++++++++++++++++++++++++++++++++++------------- 1 file changed, 46 insertions(+), 17 deletions(-) (limited to 'test') diff --git a/test/caldav/xhr_test.js b/test/caldav/xhr_test.js index aa9b4f2..6130346 100644 --- a/test/caldav/xhr_test.js +++ b/test/caldav/xhr_test.js @@ -104,7 +104,7 @@ suite('webacls/xhr', function() { }); suite('requests real files', function() { - function request(path) { + function request(path, globalOptions) { path = 'fixtures/' + path; if (typeof(__dirname) !== 'undefined') { @@ -113,7 +113,7 @@ suite('webacls/xhr', function() { path = '/test/caldav/' + path; } - return new Xhr({ url: path }); + return new Xhr({ url: path, globalXhrOptions: globalOptions }); } test('get', function(done) { @@ -125,27 +125,56 @@ suite('webacls/xhr', function() { }); }); - test('.ondata', function(done) { - var subject = request('long.txt'); - var gotData = ''; + suite('.ondata', function() { + var expected; + var file = 'long.txt'; - subject.ondata = function(chunk) { - gotData += chunk; - }; + setup(function(done) { + if (expected) { + done(); + } + + var req = request(file); + req.send(function(err, xhr) { + expected = xhr.responseText; + done(); + }); + }); - subject.send(function(err, xhr) { - var data = xhr.responseText; + if (this.navigator && navigator.userAgent.indexOf('Mozilla') !== -1) { + test('.ondata with chunked', function(done) { + var subject = request('long.txt', { useMozChunkedText: true }); + var gotData = ''; + + subject.ondata = function(chunk) { + gotData += chunk; + }; + + var xhr = subject.send(function(err, xhr) { + assert.ok(!xhr.responseText); + assert.equal(xhr.responseType, 'moz-chunked-text'); + assert.equal(expected, gotData); + done(); + }); + }); + } - assert.equal( - data.trim(), - gotData.trim(), - 'sends ondata' - ); + test('.ondata', function(done) { + var subject = request(file); + var gotData = ''; - done(); + subject.ondata = function(chunk) { + gotData += chunk; + }; + + subject.send(function(err, xhr) { + assert.equal(expected, gotData); + done(); + }); }); - }); + + }); }); }); -- cgit