Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
jio
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Hamza
jio
Commits
d6408551
Commit
d6408551
authored
Mar 18, 2019
by
Romain Courteaud
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[test] Check ajax FormData and Blob handling
parent
489c41d3
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
205 additions
and
5 deletions
+205
-5
Makefile
Makefile
+1
-0
src/node/jio.js
src/node/jio.js
+8
-5
test/node.js
test/node.js
+1
-0
test/node/ajax.tests.js
test/node/ajax.tests.js
+195
-0
No files found.
Makefile
View file @
d6408551
...
@@ -108,6 +108,7 @@ lint: $(patsubst ${TESTDIR}/jio.storage/%.js, ${LINTDIR}/${TESTDIR}/jio.storage/
...
@@ -108,6 +108,7 @@ lint: $(patsubst ${TESTDIR}/jio.storage/%.js, ${LINTDIR}/${TESTDIR}/jio.storage/
${LINTDIR}/node/jio.js
\
${LINTDIR}/node/jio.js
\
${LINTDIR}/${TESTDIR}/node.js
\
${LINTDIR}/${TESTDIR}/node.js
\
${LINTDIR}/${TESTDIR}/node/node-require.js
\
${LINTDIR}/${TESTDIR}/node/node-require.js
\
${LINTDIR}/${TESTDIR}/node/ajax.tests.js
\
$(patsubst ${SRCDIR}/jio.storage/%.js
,
${LINTDIR}/jio.storage/%.js
,
$(wildcard ${SRCDIR}/jio.storage/*.js))
$(patsubst ${SRCDIR}/jio.storage/%.js
,
${LINTDIR}/jio.storage/%.js
,
$(wildcard ${SRCDIR}/jio.storage/*.js))
#############################################
#############################################
...
...
src/node/jio.js
View file @
d6408551
...
@@ -19,7 +19,7 @@
...
@@ -19,7 +19,7 @@
*/
*/
/*global window */
/*global window */
(
function
(
window
,
jIO
,
Blob
)
{
(
function
(
window
,
jIO
,
Blob
,
RSVP
)
{
"
use strict
"
;
"
use strict
"
;
var
FormData
,
var
FormData
,
...
@@ -48,9 +48,12 @@
...
@@ -48,9 +48,12 @@
// allow tests to check them
// allow tests to check them
param
=
Object
.
assign
({},
param
);
param
=
Object
.
assign
({},
param
);
// Blob is not supported by xhr2, so convert to ArrayBuffer instead
// Blob is not supported by xhr2, so convert to ArrayBuffer instead
return
jIO
.
util
.
readBlobAsArrayBuffer
(
param
.
data
)
return
new
RSVP
.
Queue
()
.
then
(
function
(
data
)
{
.
push
(
function
()
{
param
.
data
=
data
.
target
.
result
;
return
jIO
.
util
.
readBlobAsArrayBuffer
(
param
.
data
);
})
.
push
(
function
(
evt
)
{
param
.
data
=
evt
.
target
.
result
;
return
originalAjax
(
param
);
return
originalAjax
(
param
);
});
});
}
}
...
@@ -77,7 +80,7 @@
...
@@ -77,7 +80,7 @@
return
originalAjax
(
param
);
return
originalAjax
(
param
);
};
};
}(
window
,
window
.
jIO
,
window
.
Blob
));
}(
window
,
window
.
jIO
,
window
.
Blob
,
window
.
RSVP
));
// Define a global variable to allow storages to access jIO
// Define a global variable to allow storages to access jIO
var
jIO
=
window
.
jIO
,
var
jIO
=
window
.
jIO
,
...
...
test/node.js
View file @
d6408551
...
@@ -48,6 +48,7 @@
...
@@ -48,6 +48,7 @@
testrunner
.
run
({
testrunner
.
run
({
code
:
'
test/node/node-require.js
'
,
code
:
'
test/node/node-require.js
'
,
tests
:
[
tests
:
[
'
test/node/ajax.tests.js
'
,
'
test/jio/util.js
'
,
'
test/jio/util.js
'
,
'
test/queries/key.tests.js
'
,
'
test/queries/key.tests.js
'
,
'
test/queries/key-schema.tests.js
'
,
'
test/queries/key-schema.tests.js
'
,
...
...
test/node/ajax.tests.js
0 → 100644
View file @
d6408551
/*
* Copyright 2019, Nexedi SA
*
* This program is free software: you can Use, Study, Modify and Redistribute
* it under the terms of the GNU General Public License version 3, or (at your
* option) any later version, as published by the Free Software Foundation.
*
* You can also Link and Combine this program with other software covered by
* the terms of any of the Free Software licenses or any of the Open Source
* Initiative approved licenses and Convey the resulting work. Corresponding
* source of such a combination shall include the source code for all other
* software used.
*
* This program is distributed WITHOUT ANY WARRANTY; without even the implied
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
*
* See COPYING file for full licensing terms.
* See https://www.nexedi.com/licensing for rationale and options.
*/
/*global FormData, sinon, RSVP, jIO, QUnit, XMLHttpRequest, Blob, ArrayBuffer*/
(
function
(
jIO
,
QUnit
,
FormData
,
Blob
,
ArrayBuffer
)
{
"
use strict
"
;
var
test
=
QUnit
.
test
,
equal
=
QUnit
.
equal
,
stop
=
QUnit
.
stop
,
start
=
QUnit
.
start
,
expect
=
QUnit
.
expect
,
ok
=
QUnit
.
ok
,
module
=
QUnit
.
module
;
/////////////////////////////////////////////////////////////////
// util.ajax
/////////////////////////////////////////////////////////////////
module
(
"
node.ajax
"
,
{
setup
:
function
()
{
this
.
server
=
sinon
.
fakeServer
.
create
();
this
.
server
.
autoRespond
=
true
;
this
.
server
.
autoRespondAfter
=
5
;
this
.
spySetRequestHeader
=
sinon
.
spy
(
XMLHttpRequest
.
prototype
,
"
setRequestHeader
"
);
},
teardown
:
function
()
{
this
.
spySetRequestHeader
.
restore
();
delete
this
.
spySetRequestHeader
;
this
.
server
.
restore
();
delete
this
.
server
;
}
});
test
(
"
Blob data handling
"
,
function
()
{
stop
();
expect
(
5
);
var
url
=
"
https://www.example.org/com/bar
"
,
server
=
this
.
server
,
blob
=
new
Blob
([
'
abc
'
]);
this
.
server
.
respondWith
(
"
POST
"
,
url
,
[
200
,
{},
'
OK
'
]);
return
new
RSVP
.
Queue
()
.
then
(
function
()
{
return
jIO
.
util
.
ajax
({
type
:
'
POST
'
,
url
:
url
,
data
:
blob
});
})
.
then
(
function
()
{
equal
(
server
.
requests
.
length
,
1
);
equal
(
server
.
requests
[
0
].
method
,
"
POST
"
);
equal
(
server
.
requests
[
0
].
url
,
url
);
ok
(
server
.
requests
[
0
].
requestBody
instanceof
ArrayBuffer
);
return
jIO
.
util
.
readBlobAsText
(
new
Blob
([
server
.
requests
[
0
].
requestBody
])
);
})
.
then
(
function
(
evt
)
{
equal
(
evt
.
target
.
result
,
'
abc
'
);
})
.
always
(
function
()
{
start
();
});
});
test
(
"
FormData handling without headers
"
,
function
()
{
stop
();
expect
(
7
);
var
url
=
"
https://www.example.org/com/bar
"
,
server
=
this
.
server
,
context
=
this
;
this
.
server
.
respondWith
(
"
POST
"
,
url
,
[
200
,
{},
'
OK
'
]);
return
new
RSVP
.
Queue
()
.
then
(
function
()
{
var
form_data
=
new
FormData
();
form_data
.
append
(
"
foo
"
,
"
bar
"
);
form_data
.
append
(
"
foo2
"
,
"
bar2
"
,
"
barfilename2
"
);
return
jIO
.
util
.
ajax
({
type
:
'
POST
'
,
url
:
url
,
data
:
form_data
});
})
.
then
(
function
()
{
var
content_type
=
"
multipart/form-data; boundary=----------------------------
"
,
boundary
;
equal
(
context
.
spySetRequestHeader
.
callCount
,
1
);
equal
(
context
.
spySetRequestHeader
.
firstCall
.
args
[
0
],
"
Content-Type
"
);
equal
(
context
.
spySetRequestHeader
.
firstCall
.
args
[
1
].
length
,
content_type
.
length
+
10
);
boundary
=
context
.
spySetRequestHeader
.
firstCall
.
args
[
1
].
slice
(
"
multipart/form-data; boundary=
"
.
length
);
equal
(
server
.
requests
.
length
,
1
);
equal
(
server
.
requests
[
0
].
method
,
"
POST
"
);
equal
(
server
.
requests
[
0
].
url
,
url
);
equal
(
server
.
requests
[
0
].
requestBody
,
'
--
'
+
boundary
+
'
\r\n
Content-Disposition: form-data; name="foo"
\r\n\r\n
bar
\r\n
'
+
'
--
'
+
boundary
+
'
\r\n
Content-Disposition: form-data; name="foo2";
'
+
'
filename="barfilename2"
\r\n\r\n
bar2
\r\n
'
+
'
--
'
+
boundary
+
'
--
\r\n
'
);
})
.
always
(
function
()
{
start
();
});
});
test
(
"
FormData handling with headers
"
,
function
()
{
stop
();
expect
(
9
);
var
url
=
"
https://www.example.org/com/bar
"
,
server
=
this
.
server
,
context
=
this
;
this
.
server
.
respondWith
(
"
POST
"
,
url
,
[
200
,
{},
'
OK
'
]);
return
new
RSVP
.
Queue
()
.
then
(
function
()
{
var
form_data
=
new
FormData
();
form_data
.
append
(
"
foo
"
,
"
bar
"
);
form_data
.
append
(
"
foo2
"
,
"
bar2
"
,
"
barfilename2
"
);
return
jIO
.
util
.
ajax
({
type
:
'
POST
'
,
url
:
url
,
data
:
form_data
,
headers
:
{
"
bar
"
:
"
foo
"
}
});
})
.
then
(
function
()
{
var
content_type
=
"
multipart/form-data; boundary=----------------------------
"
,
boundary
;
equal
(
context
.
spySetRequestHeader
.
callCount
,
2
);
equal
(
context
.
spySetRequestHeader
.
firstCall
.
args
[
0
],
"
bar
"
);
equal
(
context
.
spySetRequestHeader
.
firstCall
.
args
[
1
],
"
foo
"
);
equal
(
context
.
spySetRequestHeader
.
secondCall
.
args
[
0
],
"
Content-Type
"
);
equal
(
context
.
spySetRequestHeader
.
secondCall
.
args
[
1
].
length
,
content_type
.
length
+
10
);
boundary
=
context
.
spySetRequestHeader
.
secondCall
.
args
[
1
].
slice
(
"
multipart/form-data; boundary=
"
.
length
);
equal
(
server
.
requests
.
length
,
1
);
equal
(
server
.
requests
[
0
].
method
,
"
POST
"
);
equal
(
server
.
requests
[
0
].
url
,
url
);
equal
(
server
.
requests
[
0
].
requestBody
,
'
--
'
+
boundary
+
'
\r\n
Content-Disposition: form-data; name="foo"
\r\n\r\n
bar
\r\n
'
+
'
--
'
+
boundary
+
'
\r\n
Content-Disposition: form-data; name="foo2";
'
+
'
filename="barfilename2"
\r\n\r\n
bar2
\r\n
'
+
'
--
'
+
boundary
+
'
--
\r\n
'
);
})
.
always
(
function
()
{
start
();
});
});
}(
jIO
,
QUnit
,
FormData
,
Blob
,
ArrayBuffer
));
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment