From 5e788a0315b937ebfaea47ee15103b093bd4edb3 Mon Sep 17 00:00:00 2001 From: gaye Date: Tue, 16 Apr 2013 15:50:24 -0700 Subject: Add an abort routine to Caldav.Xhr --- test/caldav/request/abstract_test.js | 7 +++++++ test/caldav/xhr_test.js | 36 ++++++++++++++++++++++++++++++++---- 2 files changed, 39 insertions(+), 4 deletions(-) (limited to 'test') diff --git a/test/caldav/request/abstract_test.js b/test/caldav/request/abstract_test.js index 21bde48..e2fb3d1 100644 --- a/test/caldav/request/abstract_test.js +++ b/test/caldav/request/abstract_test.js @@ -70,6 +70,13 @@ suite('caldav/request/abstract.js', function() { return FakeXhr.instances.pop(); } + test('should return a Caldav.Xhr object', function() { + var req = subject.send(function() {}); + assert.deepEqual(url, req.url) + assert.deepEqual(con.user, req.user); + assert.deepEqual(con.password, req.password); + }); + suite('error', function() { var calledWith; diff --git a/test/caldav/xhr_test.js b/test/caldav/xhr_test.js index 6130346..a3e6b66 100644 --- a/test/caldav/xhr_test.js +++ b/test/caldav/xhr_test.js @@ -76,10 +76,9 @@ suite('webacls/xhr', function() { }); suite('when xhr is a success and responds /w data', function() { - var response = '', cb; + var response = '', cb, xhr; setup(function(done) { - var xhr; request({ data: data, url: url, @@ -88,8 +87,8 @@ suite('webacls/xhr', function() { cb = callback.bind(this, done); xhr = subject.send(cb); - //should be waiting inbetween requests - assert.equal(subject.waiting, true); + // should be waiting inbetween requests + assert.deepEqual(subject.waiting, true); xhr.readyState = 4; xhr.responseText = response; @@ -101,6 +100,35 @@ suite('webacls/xhr', function() { }); }); + suite('when abort is called on the request', function() { + var aborted, xhr; + + setup(function() { + request({ + data: data, + url: url, + method: 'PUT' + }); + xhr = subject.send(callback); + + // should be waiting inbetween requests + assert.deepEqual(subject.waiting, true); + + aborted = false; + }); + + test('underlying request should be aborted', function(done) { + xhr.abort = function() { + aborted = true; + }; + + subject.abort(function() { + assert.deepEqual(true, aborted); + assert.deepEqual(false, subject.waiting); + done(); + }); + }); + }); }); suite('requests real files', function() { -- cgit