Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(268)

Side by Side Diff: remoting/webapp/crd/js/xhr_unittest.js

Issue 1017613002: Migrate Remoting Webapp Unittests to use QUnit 2.0 syntax. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Reviewer's feedback Created 5 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 /** 5 /**
6 * @fileoverview 6 * @fileoverview
7 * @suppress {checkTypes|checkVars|reportUnknownTypes} 7 * @suppress {checkTypes|checkVars|reportUnknownTypes}
8 */ 8 */
9 9
10 (function() { 10 (function() {
11 11
12 'use strict'; 12 'use strict';
13 13
14 module('xhr', { 14 QUnit.test('urlencodeParamHash', function() {
John Williams 2015/03/17 19:22:37 A call to QUnit module is still needed here to set
15 setup: function() {
16 },
17 teardown: function() {
18 }
19 });
20
21 test('urlencodeParamHash', function() {
22 QUnit.equal( 15 QUnit.equal(
23 remoting.xhr.urlencodeParamHash({}), 16 remoting.xhr.urlencodeParamHash({}),
24 ''); 17 '');
25 QUnit.equal( 18 QUnit.equal(
26 remoting.xhr.urlencodeParamHash({'key': 'value'}), 19 remoting.xhr.urlencodeParamHash({'key': 'value'}),
27 'key=value'); 20 'key=value');
28 QUnit.equal( 21 QUnit.equal(
29 remoting.xhr.urlencodeParamHash({'key /?=&': 'value /?=&'}), 22 remoting.xhr.urlencodeParamHash({'key /?=&': 'value /?=&'}),
30 'key%20%2F%3F%3D%26=value%20%2F%3F%3D%26'); 23 'key%20%2F%3F%3D%26=value%20%2F%3F%3D%26');
31 QUnit.equal( 24 QUnit.equal(
32 remoting.xhr.urlencodeParamHash({'k1': 'v1', 'k2': 'v2'}), 25 remoting.xhr.urlencodeParamHash({'k1': 'v1', 'k2': 'v2'}),
33 'k1=v1&k2=v2'); 26 'k1=v1&k2=v2');
34 }); 27 });
35 28
36 asyncTest('basic GET', function() { 29 QUnit.test('basic GET', function(assert) {
37 sinon.useFakeXMLHttpRequest(); 30 sinon.useFakeXMLHttpRequest();
31 var done = assert.async();
38 var request = remoting.xhr.start({ 32 var request = remoting.xhr.start({
39 method: 'GET', 33 method: 'GET',
40 url: 'http://foo.com', 34 url: 'http://foo.com',
41 onDone: function(xhr) { 35 onDone: function(xhr) {
42 QUnit.ok(xhr === request); 36 QUnit.ok(xhr === request);
43 QUnit.equal(xhr.status, 200); 37 QUnit.equal(xhr.status, 200);
44 QUnit.equal(xhr.responseText, 'body'); 38 QUnit.equal(xhr.responseText, 'body');
45 QUnit.start(); 39 done();
46 } 40 }
47 }); 41 });
48 QUnit.equal(request.method, 'GET'); 42 QUnit.equal(request.method, 'GET');
49 QUnit.equal(request.url, 'http://foo.com'); 43 QUnit.equal(request.url, 'http://foo.com');
50 QUnit.equal(request.withCredentials, false); 44 QUnit.equal(request.withCredentials, false);
51 QUnit.equal(request.requestBody, null); 45 QUnit.equal(request.requestBody, null);
52 QUnit.ok(!('Content-type' in request.requestHeaders)); 46 QUnit.ok(!('Content-type' in request.requestHeaders));
53 request.respond(200, {}, 'body'); 47 request.respond(200, {}, 'body');
54 }); 48 });
55 49
56 asyncTest('GET with param string', function() { 50 QUnit.test('GET with param string', function(assert) {
51 var done = assert.async();
57 sinon.useFakeXMLHttpRequest(); 52 sinon.useFakeXMLHttpRequest();
58 var request = remoting.xhr.start({ 53 var request = remoting.xhr.start({
59 method: 'GET', 54 method: 'GET',
60 url: 'http://foo.com', 55 url: 'http://foo.com',
61 onDone: function(xhr) { 56 onDone: function(xhr) {
62 QUnit.ok(xhr === request); 57 QUnit.ok(xhr === request);
63 QUnit.equal(xhr.status, 200); 58 QUnit.equal(xhr.status, 200);
64 QUnit.equal(xhr.responseText, 'body'); 59 QUnit.equal(xhr.responseText, 'body');
65 QUnit.start(); 60 done();
66 }, 61 },
67 urlParams: 'the_param_string' 62 urlParams: 'the_param_string'
68 }); 63 });
69 QUnit.equal(request.method, 'GET'); 64 QUnit.equal(request.method, 'GET');
70 QUnit.equal(request.url, 'http://foo.com?the_param_string'); 65 QUnit.equal(request.url, 'http://foo.com?the_param_string');
71 QUnit.equal(request.withCredentials, false); 66 QUnit.equal(request.withCredentials, false);
72 QUnit.equal(request.requestBody, null); 67 QUnit.equal(request.requestBody, null);
73 QUnit.ok(!('Content-type' in request.requestHeaders)); 68 QUnit.ok(!('Content-type' in request.requestHeaders));
74 request.respond(200, {}, 'body'); 69 request.respond(200, {}, 'body');
75 }); 70 });
76 71
77 asyncTest('GET with param object', function() { 72 QUnit.test('GET with param object', function(assert) {
73 var done = assert.async();
78 sinon.useFakeXMLHttpRequest(); 74 sinon.useFakeXMLHttpRequest();
79 var request = remoting.xhr.start({ 75 var request = remoting.xhr.start({
80 method: 'GET', 76 method: 'GET',
81 url: 'http://foo.com', 77 url: 'http://foo.com',
82 onDone: function(xhr) { 78 onDone: function(xhr) {
83 QUnit.ok(xhr === request); 79 QUnit.ok(xhr === request);
84 QUnit.equal(xhr.status, 200); 80 QUnit.equal(xhr.status, 200);
85 QUnit.equal(xhr.responseText, 'body'); 81 QUnit.equal(xhr.responseText, 'body');
86 QUnit.start(); 82 done();
87 }, 83 },
88 urlParams: {'a': 'b', 'c': 'd'} 84 urlParams: {'a': 'b', 'c': 'd'}
89 }); 85 });
90 QUnit.equal(request.method, 'GET'); 86 QUnit.equal(request.method, 'GET');
91 QUnit.equal(request.url, 'http://foo.com?a=b&c=d'); 87 QUnit.equal(request.url, 'http://foo.com?a=b&c=d');
92 QUnit.equal(request.withCredentials, false); 88 QUnit.equal(request.withCredentials, false);
93 QUnit.equal(request.requestBody, null); 89 QUnit.equal(request.requestBody, null);
94 QUnit.ok(!('Content-type' in request.requestHeaders)); 90 QUnit.ok(!('Content-type' in request.requestHeaders));
95 request.respond(200, {}, 'body'); 91 request.respond(200, {}, 'body');
96 }); 92 });
97 93
98 asyncTest('GET with headers', function() { 94 QUnit.test('GET with headers', function(assert) {
99 sinon.useFakeXMLHttpRequest(); 95 sinon.useFakeXMLHttpRequest();
96 var done = assert.async();
100 var request = remoting.xhr.start({ 97 var request = remoting.xhr.start({
101 method: 'GET', 98 method: 'GET',
102 url: 'http://foo.com', 99 url: 'http://foo.com',
103 onDone: function(xhr) { 100 onDone: function(xhr) {
104 QUnit.ok(xhr === request); 101 QUnit.ok(xhr === request);
105 QUnit.equal(xhr.status, 200); 102 QUnit.equal(xhr.status, 200);
106 QUnit.equal(xhr.responseText, 'body'); 103 QUnit.equal(xhr.responseText, 'body');
107 QUnit.start(); 104 done();
108 }, 105 },
109 headers: {'Header1': 'headerValue1', 'Header2': 'headerValue2'} 106 headers: {'Header1': 'headerValue1', 'Header2': 'headerValue2'}
110 }); 107 });
111 QUnit.equal(request.method, 'GET'); 108 QUnit.equal(request.method, 'GET');
112 QUnit.equal(request.url, 'http://foo.com'); 109 QUnit.equal(request.url, 'http://foo.com');
113 QUnit.equal(request.withCredentials, false); 110 QUnit.equal(request.withCredentials, false);
114 QUnit.equal(request.requestBody, null); 111 QUnit.equal(request.requestBody, null);
115 QUnit.equal( 112 QUnit.equal(
116 request.requestHeaders['Header1'], 113 request.requestHeaders['Header1'],
117 'headerValue1'); 114 'headerValue1');
118 QUnit.equal( 115 QUnit.equal(
119 request.requestHeaders['Header2'], 116 request.requestHeaders['Header2'],
120 'headerValue2'); 117 'headerValue2');
121 QUnit.ok(!('Content-type' in request.requestHeaders)); 118 QUnit.ok(!('Content-type' in request.requestHeaders));
122 request.respond(200, {}, 'body'); 119 request.respond(200, {}, 'body');
123 }); 120 });
124 121
125 122
126 asyncTest('GET with credentials', function() { 123 QUnit.test('GET with credentials', function(assert) {
127 sinon.useFakeXMLHttpRequest(); 124 sinon.useFakeXMLHttpRequest();
125 var done = assert.async();
128 var request = remoting.xhr.start({ 126 var request = remoting.xhr.start({
129 method: 'GET', 127 method: 'GET',
130 url: 'http://foo.com', 128 url: 'http://foo.com',
131 onDone: function(xhr) { 129 onDone: function(xhr) {
132 QUnit.ok(xhr === request); 130 QUnit.ok(xhr === request);
133 QUnit.equal(xhr.status, 200); 131 QUnit.equal(xhr.status, 200);
134 QUnit.equal(xhr.responseText, 'body'); 132 QUnit.equal(xhr.responseText, 'body');
135 QUnit.start(); 133 done();
136 }, 134 },
137 withCredentials: true 135 withCredentials: true
138 }); 136 });
139 QUnit.equal(request.method, 'GET'); 137 QUnit.equal(request.method, 'GET');
140 QUnit.equal(request.url, 'http://foo.com'); 138 QUnit.equal(request.url, 'http://foo.com');
141 QUnit.equal(request.withCredentials, true); 139 QUnit.equal(request.withCredentials, true);
142 QUnit.equal(request.requestBody, null); 140 QUnit.equal(request.requestBody, null);
143 QUnit.ok(!('Content-type' in request.requestHeaders)); 141 QUnit.ok(!('Content-type' in request.requestHeaders));
144 request.respond(200, {}, 'body'); 142 request.respond(200, {}, 'body');
145 }); 143 });
146 144
147 asyncTest('POST with text content', function() { 145 QUnit.test('POST with text content', function(assert) {
148 sinon.useFakeXMLHttpRequest(); 146 sinon.useFakeXMLHttpRequest();
147 var done = assert.async();
149 var request = remoting.xhr.start({ 148 var request = remoting.xhr.start({
150 method: 'POST', 149 method: 'POST',
151 url: 'http://foo.com', 150 url: 'http://foo.com',
152 onDone: function(xhr) { 151 onDone: function(xhr) {
153 QUnit.ok(xhr === request); 152 QUnit.ok(xhr === request);
154 QUnit.equal(xhr.status, 200); 153 QUnit.equal(xhr.status, 200);
155 QUnit.equal(xhr.responseText, 'body'); 154 QUnit.equal(xhr.responseText, 'body');
156 QUnit.start(); 155 done();
157 }, 156 },
158 textContent: 'the_content_string' 157 textContent: 'the_content_string'
159 }); 158 });
160 QUnit.equal(request.method, 'POST'); 159 QUnit.equal(request.method, 'POST');
161 QUnit.equal(request.url, 'http://foo.com'); 160 QUnit.equal(request.url, 'http://foo.com');
162 QUnit.equal(request.withCredentials, false); 161 QUnit.equal(request.withCredentials, false);
163 QUnit.equal(request.requestBody, 'the_content_string'); 162 QUnit.equal(request.requestBody, 'the_content_string');
164 QUnit.ok(!('Content-type' in request.requestHeaders)); 163 QUnit.ok(!('Content-type' in request.requestHeaders));
165 request.respond(200, {}, 'body'); 164 request.respond(200, {}, 'body');
166 }); 165 });
167 166
168 asyncTest('POST with form content', function() { 167 QUnit.test('POST with form content', function(assert) {
169 sinon.useFakeXMLHttpRequest(); 168 sinon.useFakeXMLHttpRequest();
169 var done = assert.async();
170 var request = remoting.xhr.start({ 170 var request = remoting.xhr.start({
171 method: 'POST', 171 method: 'POST',
172 url: 'http://foo.com', 172 url: 'http://foo.com',
173 onDone: function(xhr) { 173 onDone: function(xhr) {
174 QUnit.ok(xhr === request); 174 QUnit.ok(xhr === request);
175 QUnit.equal(xhr.status, 200); 175 QUnit.equal(xhr.status, 200);
176 QUnit.equal(xhr.responseText, 'body'); 176 QUnit.equal(xhr.responseText, 'body');
177 QUnit.start(); 177 done();
178 }, 178 },
179 formContent: {'a': 'b', 'c': 'd'} 179 formContent: {'a': 'b', 'c': 'd'}
180 }); 180 });
181 QUnit.equal(request.method, 'POST'); 181 QUnit.equal(request.method, 'POST');
182 QUnit.equal(request.url, 'http://foo.com'); 182 QUnit.equal(request.url, 'http://foo.com');
183 QUnit.equal(request.withCredentials, false); 183 QUnit.equal(request.withCredentials, false);
184 QUnit.equal(request.requestBody, 'a=b&c=d'); 184 QUnit.equal(request.requestBody, 'a=b&c=d');
185 QUnit.equal( 185 QUnit.equal(
186 request.requestHeaders['Content-type'], 186 request.requestHeaders['Content-type'],
187 'application/x-www-form-urlencoded'); 187 'application/x-www-form-urlencoded');
188 request.respond(200, {}, 'body'); 188 request.respond(200, {}, 'body');
189 }); 189 });
190 190
191 asyncTest('defaultResponse 200', function() { 191 QUnit.test('defaultResponse 200', function(assert) {
192 sinon.useFakeXMLHttpRequest(); 192 sinon.useFakeXMLHttpRequest();
193 var done = assert.async();
193 194
194 var onDone = function() { 195 var onDone = function() {
195 QUnit.ok(true); 196 QUnit.ok(true);
196 QUnit.start(); 197 done();
197 }; 198 };
198 199
199 var onError = function(error) { 200 var onError = function(error) {
200 QUnit.ok(false); 201 QUnit.ok(false);
201 QUnit.start(); 202 done();
202 }; 203 };
203 204
204 var request = remoting.xhr.start({ 205 var request = remoting.xhr.start({
205 method: 'POST', 206 method: 'POST',
206 url: 'http://foo.com', 207 url: 'http://foo.com',
207 onDone: remoting.xhr.defaultResponse(onDone, onError) 208 onDone: remoting.xhr.defaultResponse(onDone, onError)
208 }); 209 });
209 request.respond(200); 210 request.respond(200);
210 }); 211 });
211 212
212 213
213 asyncTest('defaultResponse 404', function() { 214 QUnit.test('defaultResponse 404', function(assert) {
214 sinon.useFakeXMLHttpRequest(); 215 sinon.useFakeXMLHttpRequest();
215 216 var done = assert.async();
216 var onDone = function() { 217 var onDone = function() {
217 QUnit.ok(false); 218 QUnit.ok(false);
218 QUnit.start(); 219 done();
219 }; 220 };
220 221
221 var onError = function(error) { 222 var onError = function(error) {
222 QUnit.ok(true); 223 QUnit.ok(true);
223 QUnit.start(); 224 done();
224 }; 225 };
225 226
226 var request = remoting.xhr.start({ 227 var request = remoting.xhr.start({
227 method: 'POST', 228 method: 'POST',
228 url: 'http://foo.com', 229 url: 'http://foo.com',
229 onDone: remoting.xhr.defaultResponse(onDone, onError) 230 onDone: remoting.xhr.defaultResponse(onDone, onError)
230 }); 231 });
231 request.respond(404); 232 request.respond(404);
232 }); 233 });
233 234
234 })(); 235 })();
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698