1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
12 teardown: function() {
16 test('urlencodeParamHash', function() {
18 remoting
.xhr
.urlencodeParamHash({}),
21 remoting
.xhr
.urlencodeParamHash({'key': 'value'}),
24 remoting
.xhr
.urlencodeParamHash({'key /?=&': 'value /?=&'}),
25 'key%20%2F%3F%3D%26=value%20%2F%3F%3D%26');
27 remoting
.xhr
.urlencodeParamHash({'k1': 'v1', 'k2': 'v2'}),
31 asyncTest('basic GET', function() {
32 sinon
.useFakeXMLHttpRequest();
33 var request
= remoting
.xhr
.start({
35 url
: 'http://foo.com',
36 onDone: function(xhr
) {
37 QUnit
.ok(xhr
=== request
);
38 QUnit
.equal(xhr
.status
, 200);
39 QUnit
.equal(xhr
.responseText
, 'body');
43 QUnit
.equal(request
.method
, 'GET');
44 QUnit
.equal(request
.url
, 'http://foo.com');
45 QUnit
.equal(request
.withCredentials
, false);
46 QUnit
.equal(request
.requestBody
, null);
47 QUnit
.ok(!('Content-type' in request
.requestHeaders
));
48 request
.respond(200, {}, 'body');
51 asyncTest('GET with param string', function() {
52 sinon
.useFakeXMLHttpRequest();
53 var request
= remoting
.xhr
.start({
55 url
: 'http://foo.com',
56 onDone: function(xhr
) {
57 QUnit
.ok(xhr
=== request
);
58 QUnit
.equal(xhr
.status
, 200);
59 QUnit
.equal(xhr
.responseText
, 'body');
62 urlParams
: 'the_param_string'
64 QUnit
.equal(request
.method
, 'GET');
65 QUnit
.equal(request
.url
, 'http://foo.com?the_param_string');
66 QUnit
.equal(request
.withCredentials
, false);
67 QUnit
.equal(request
.requestBody
, null);
68 QUnit
.ok(!('Content-type' in request
.requestHeaders
));
69 request
.respond(200, {}, 'body');
72 asyncTest('GET with param object', function() {
73 sinon
.useFakeXMLHttpRequest();
74 var request
= remoting
.xhr
.start({
76 url
: 'http://foo.com',
77 onDone: function(xhr
) {
78 QUnit
.ok(xhr
=== request
);
79 QUnit
.equal(xhr
.status
, 200);
80 QUnit
.equal(xhr
.responseText
, 'body');
83 urlParams
: {'a': 'b', 'c': 'd'}
85 QUnit
.equal(request
.method
, 'GET');
86 QUnit
.equal(request
.url
, 'http://foo.com?a=b&c=d');
87 QUnit
.equal(request
.withCredentials
, false);
88 QUnit
.equal(request
.requestBody
, null);
89 QUnit
.ok(!('Content-type' in request
.requestHeaders
));
90 request
.respond(200, {}, 'body');
93 asyncTest('GET with headers', function() {
94 sinon
.useFakeXMLHttpRequest();
95 var request
= remoting
.xhr
.start({
97 url
: 'http://foo.com',
98 onDone: function(xhr
) {
99 QUnit
.ok(xhr
=== request
);
100 QUnit
.equal(xhr
.status
, 200);
101 QUnit
.equal(xhr
.responseText
, 'body');
104 headers
: {'Header1': 'headerValue1', 'Header2': 'headerValue2'}
106 QUnit
.equal(request
.method
, 'GET');
107 QUnit
.equal(request
.url
, 'http://foo.com');
108 QUnit
.equal(request
.withCredentials
, false);
109 QUnit
.equal(request
.requestBody
, null);
111 request
.requestHeaders
['Header1'],
114 request
.requestHeaders
['Header2'],
116 QUnit
.ok(!('Content-type' in request
.requestHeaders
));
117 request
.respond(200, {}, 'body');
121 asyncTest('GET with credentials', function() {
122 sinon
.useFakeXMLHttpRequest();
123 var request
= remoting
.xhr
.start({
125 url
: 'http://foo.com',
126 onDone: function(xhr
) {
127 QUnit
.ok(xhr
=== request
);
128 QUnit
.equal(xhr
.status
, 200);
129 QUnit
.equal(xhr
.responseText
, 'body');
132 withCredentials
: true
134 QUnit
.equal(request
.method
, 'GET');
135 QUnit
.equal(request
.url
, 'http://foo.com');
136 QUnit
.equal(request
.withCredentials
, true);
137 QUnit
.equal(request
.requestBody
, null);
138 QUnit
.ok(!('Content-type' in request
.requestHeaders
));
139 request
.respond(200, {}, 'body');
142 asyncTest('POST with text content', function() {
143 sinon
.useFakeXMLHttpRequest();
144 var request
= remoting
.xhr
.start({
146 url
: 'http://foo.com',
147 onDone: function(xhr
) {
148 QUnit
.ok(xhr
=== request
);
149 QUnit
.equal(xhr
.status
, 200);
150 QUnit
.equal(xhr
.responseText
, 'body');
153 textContent
: 'the_content_string'
155 QUnit
.equal(request
.method
, 'POST');
156 QUnit
.equal(request
.url
, 'http://foo.com');
157 QUnit
.equal(request
.withCredentials
, false);
158 QUnit
.equal(request
.requestBody
, 'the_content_string');
159 QUnit
.ok(!('Content-type' in request
.requestHeaders
));
160 request
.respond(200, {}, 'body');
163 asyncTest('POST with form content', function() {
164 sinon
.useFakeXMLHttpRequest();
165 var request
= remoting
.xhr
.start({
167 url
: 'http://foo.com',
168 onDone: function(xhr
) {
169 QUnit
.ok(xhr
=== request
);
170 QUnit
.equal(xhr
.status
, 200);
171 QUnit
.equal(xhr
.responseText
, 'body');
174 formContent
: {'a': 'b', 'c': 'd'}
176 QUnit
.equal(request
.method
, 'POST');
177 QUnit
.equal(request
.url
, 'http://foo.com');
178 QUnit
.equal(request
.withCredentials
, false);
179 QUnit
.equal(request
.requestBody
, 'a=b&c=d');
181 request
.requestHeaders
['Content-type'],
182 'application/x-www-form-urlencoded');
183 request
.respond(200, {}, 'body');
186 asyncTest('defaultResponse 200', function() {
187 sinon
.useFakeXMLHttpRequest();
189 var onDone = function() {
194 var onError = function(error
) {
199 var request
= remoting
.xhr
.start({
201 url
: 'http://foo.com',
202 onDone
: remoting
.xhr
.defaultResponse(onDone
, onError
)
204 request
.respond(200);
208 asyncTest('defaultResponse 404', function() {
209 sinon
.useFakeXMLHttpRequest();
211 var onDone = function() {
216 var onError = function(error
) {
221 var request
= remoting
.xhr
.start({
223 url
: 'http://foo.com',
224 onDone
: remoting
.xhr
.defaultResponse(onDone
, onError
)
226 request
.respond(404);