Skip to content

Commit b6787ef

Browse files
Test for 2 bytes, 3 bytes and 4 bytes characters.
1 parent c896f15 commit b6787ef

File tree

4 files changed

+65
-2
lines changed

4 files changed

+65
-2
lines changed

Gruntfile.js

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,17 @@ module.exports = function (grunt) {
7373
base: ['.', 'test'],
7474
open: 'http://127.0.0.1:10000',
7575
keepalive: true,
76-
livereload: true
76+
livereload: true,
77+
middleware: function(connect, options, middlewares) {
78+
// Log the information when cookies are sent to the server
79+
middlewares.unshift(function(request, response, next) {
80+
if ( request.headers.cookie ) {
81+
console.log('Cookie: ' + request.headers.cookie);
82+
}
83+
return next();
84+
});
85+
return middlewares;
86+
}
7787
}
7888
}
7989
},

post_iframe.html

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<!DOCTYPE html>
2+
<html>
3+
<head>
4+
<meta charset="utf-8">
5+
<title>JavaScript Cookie Test Suite</title>
6+
<script src="../src/js.cookie.js"></script>
7+
</head>
8+
</html>

test/index.html

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@
1111
</head>
1212
<body>
1313
<div id="qunit"></div>
14-
<div id="qunit-fixture"></div>
14+
<div id="qunit-fixture">
15+
<form id="post_form" action="" target="post_iframe"></form>
16+
<iframe id='post_iframe' name="post_iframe"></iframe>
17+
</div>
1518
</body>
1619
</html>

test/tests.js

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,22 @@
3333
});
3434
}());
3535

36+
window.submitToServer = function () {
37+
stop();
38+
return {
39+
then: function (afterLoading) {
40+
var iframe = document.getElementById('post_iframe');
41+
var form = document.getElementById('post_form');
42+
iframe.onload = function () {
43+
start();
44+
afterLoading.call(null, iframe.contentWindow.Cookies);
45+
};
46+
form.action = 'post_iframe.html?bust='.concat(+new Date);
47+
form.submit();
48+
}
49+
}
50+
}
51+
3652
var lifecycle = {
3753
teardown: function () {
3854
Cookies.defaults = {};
@@ -210,6 +226,8 @@ test('defaults', function () {
210226
ok(Cookies.set('c', 'v', { path: '/bar' }).match(/path=\/bar/), 'options argument has precedence');
211227
});
212228

229+
module('encoding', lifecycle);
230+
213231
test('Handling quotes in the cookie value for read and write', function () {
214232
expect(3);
215233

@@ -306,6 +324,30 @@ test('RFC 6265 - disallowed characters in cookie-name', function () {
306324
strictEqual(Cookies.get(' '), 'v', 'should handle the horizontal tab character');
307325
});
308326

327+
test('server processing for 2 bytes characters', function () {
328+
expect(1);
329+
Cookies.set('ã', 'ã');
330+
submitToServer().then(function (Cookies) {
331+
strictEqual(Cookies.get('ã'), 'ã', 'should handle ã character');
332+
});
333+
});
334+
335+
test('server processing for 3 bytes characters', function () {
336+
expect(1);
337+
Cookies.set('₯', '₯');
338+
submitToServer().then(function (Cookies) {
339+
strictEqual(Cookies.get('₯'), '₯', 'should handle ₯ character');
340+
});
341+
});
342+
343+
test('server processing for 4 bytes characters', function () {
344+
expect(1);
345+
Cookies.set('𩸽', '𩸽');
346+
submitToServer().then(function (Cookies) {
347+
strictEqual(Cookies.get('𩸽'), '𩸽', 'should handle 𩸽 character');
348+
});
349+
});
350+
309351
module('removeCookie', lifecycle);
310352

311353
test('deletion', function () {

0 commit comments

Comments
 (0)