diff options
Diffstat (limited to 'test')
-rw-r--r-- | test/caldav/xhr_test.js | 63 |
1 files changed, 46 insertions, 17 deletions
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(); + }); }); - }); + + }); }); }); |