| 1 |
// Copyright 2015 The Closure Library Authors. All Rights Reserved. |
| 2 |
// |
| 3 |
// Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 |
// you may not use this file except in compliance with the License. |
| 5 |
// You may obtain a copy of the License at |
| 6 |
// |
| 7 |
// http://www.apache.org/licenses/LICENSE-2.0 |
| 8 |
// |
| 9 |
// Unless required by applicable law or agreed to in writing, software |
| 10 |
// distributed under the License is distributed on an "AS-IS" BASIS, |
| 11 |
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 |
// See the License for the specific language governing permissions and |
| 13 |
// limitations under the License. |
| 14 |
|
| 15 |
goog.provide('goog.net.XhrIoPoolTest'); |
| 16 |
goog.setTestOnly('goog.net.XhrIoPoolTest'); |
| 17 |
|
| 18 |
goog.require('goog.net.XhrIoPool'); |
| 19 |
goog.require('goog.structs.Map'); |
| 20 |
goog.require('goog.testing.jsunit'); |
| 21 |
|
| 22 |
|
| 23 |
var headers = new goog.structs.Map(); |
| 24 |
headers.set('X-Foo', 'Bar'); |
| 25 |
|
| 26 |
|
| 27 |
function testSetHeadersForNewPoolObjects() { |
| 28 |
var xhrIoPool = new goog.net.XhrIoPool(headers, 0); |
| 29 |
var xhrIo = xhrIoPool.getObject(); |
| 30 |
|
| 31 |
assertEquals('Request should contain 1 header', 1, xhrIo.headers.getCount()); |
| 32 |
assertTrue( |
| 33 |
'Request should contain right header key', |
| 34 |
xhrIo.headers.containsKey('X-Foo')); |
| 35 |
assertEquals( |
| 36 |
'Request should contain right header value', xhrIo.headers.get('X-Foo'), |
| 37 |
'Bar'); |
| 38 |
|
| 39 |
xhrIoPool.releaseObject(xhrIo); |
| 40 |
goog.dispose(xhrIoPool); |
| 41 |
} |
| 42 |
|
| 43 |
|
| 44 |
function testSetHeadersForInitializedPoolObjects() { |
| 45 |
var xhrIoPool = new goog.net.XhrIoPool(headers, 1, 1); |
| 46 |
var xhrIo = xhrIoPool.getObject(); |
| 47 |
|
| 48 |
assertEquals('Request should contain 1 header', 1, xhrIo.headers.getCount()); |
| 49 |
assertTrue( |
| 50 |
'Request should contain right header key', |
| 51 |
xhrIo.headers.containsKey('X-Foo')); |
| 52 |
assertEquals( |
| 53 |
'Request should contain right header value', 'Bar', |
| 54 |
xhrIo.headers.get('X-Foo')); |
| 55 |
|
| 56 |
xhrIoPool.releaseObject(xhrIo); |
| 57 |
goog.dispose(xhrIoPool); |
| 58 |
} |
| 59 |
|
| 60 |
|
| 61 |
function testSetCredentials() { |
| 62 |
var xhrIoPool = new goog.net.XhrIoPool( |
| 63 |
undefined /* opt_headers */, undefined /* opt_minCount */, |
| 64 |
undefined /* opt_maxCount */, true /* opt_withCredentials */); |
| 65 |
var xhrIo = xhrIoPool.getObject(); |
| 66 |
|
| 67 |
assertTrue( |
| 68 |
'withCredentials should be set on a request object', |
| 69 |
xhrIo.getWithCredentials()); |
| 70 |
|
| 71 |
xhrIoPool.releaseObject(xhrIo); |
| 72 |
goog.dispose(xhrIoPool); |
| 73 |
} |