xhriopool_test.js 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  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. goog.provide('goog.net.XhrIoPoolTest');
  15. goog.setTestOnly('goog.net.XhrIoPoolTest');
  16. goog.require('goog.net.XhrIoPool');
  17. goog.require('goog.structs.Map');
  18. goog.require('goog.testing.jsunit');
  19. var headers = new goog.structs.Map();
  20. headers.set('X-Foo', 'Bar');
  21. function testSetHeadersForNewPoolObjects() {
  22. var xhrIoPool = new goog.net.XhrIoPool(headers, 0);
  23. var xhrIo = xhrIoPool.getObject();
  24. assertEquals('Request should contain 1 header', 1, xhrIo.headers.getCount());
  25. assertTrue(
  26. 'Request should contain right header key',
  27. xhrIo.headers.containsKey('X-Foo'));
  28. assertEquals(
  29. 'Request should contain right header value', xhrIo.headers.get('X-Foo'),
  30. 'Bar');
  31. xhrIoPool.releaseObject(xhrIo);
  32. goog.dispose(xhrIoPool);
  33. }
  34. function testSetHeadersForInitializedPoolObjects() {
  35. var xhrIoPool = new goog.net.XhrIoPool(headers, 1, 1);
  36. var xhrIo = xhrIoPool.getObject();
  37. assertEquals('Request should contain 1 header', 1, xhrIo.headers.getCount());
  38. assertTrue(
  39. 'Request should contain right header key',
  40. xhrIo.headers.containsKey('X-Foo'));
  41. assertEquals(
  42. 'Request should contain right header value', 'Bar',
  43. xhrIo.headers.get('X-Foo'));
  44. xhrIoPool.releaseObject(xhrIo);
  45. goog.dispose(xhrIoPool);
  46. }
  47. function testSetCredentials() {
  48. var xhrIoPool = new goog.net.XhrIoPool(
  49. undefined /* opt_headers */, undefined /* opt_minCount */,
  50. undefined /* opt_maxCount */, true /* opt_withCredentials */);
  51. var xhrIo = xhrIoPool.getObject();
  52. assertTrue(
  53. 'withCredentials should be set on a request object',
  54. xhrIo.getWithCredentials());
  55. xhrIoPool.releaseObject(xhrIo);
  56. goog.dispose(xhrIoPool);
  57. }