jsxmlhttpdatasource_test.js 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. // Copyright 2008 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.ds.JsXmlHttpDataSourceTest');
  15. goog.setTestOnly('goog.ds.JsXmlHttpDataSourceTest');
  16. goog.require('goog.ds.JsXmlHttpDataSource');
  17. goog.require('goog.testing.TestQueue');
  18. goog.require('goog.testing.jsunit');
  19. goog.require('goog.testing.net.XhrIo');
  20. var TEXT_PREFIX = null;
  21. var TEXT_POSTFIX = null;
  22. var INDEX_OF_URI_ENTRY = 1;
  23. var INDEX_OF_CONTENT_ENTRY = 3;
  24. function setUp() {}
  25. function tearDown() {}
  26. function testLoad_WithPostAndQueryDataSet() {
  27. var USE_POST = true;
  28. var dataSource = new goog.ds.JsXmlHttpDataSource(
  29. 'uri', 'namne', TEXT_PREFIX, TEXT_POSTFIX, USE_POST);
  30. var testQueue = new goog.testing.TestQueue();
  31. dataSource.xhr_ = new goog.testing.net.XhrIo(testQueue);
  32. var expectedContent = 'Some test content';
  33. dataSource.setQueryData(expectedContent);
  34. dataSource.load();
  35. assertFalse(testQueue.isEmpty());
  36. var actualRequest = testQueue.dequeue();
  37. assertEquals(expectedContent, actualRequest[INDEX_OF_CONTENT_ENTRY]);
  38. assertTrue(testQueue.isEmpty());
  39. }
  40. function testLoad_WithPostAndNoQueryDataSet() {
  41. var USE_POST = true;
  42. var dataSource = new goog.ds.JsXmlHttpDataSource(
  43. 'uri?a=1&b=2', 'namne', TEXT_PREFIX, TEXT_POSTFIX, USE_POST);
  44. var testQueue = new goog.testing.TestQueue();
  45. dataSource.xhr_ = new goog.testing.net.XhrIo(testQueue);
  46. dataSource.load();
  47. assertFalse(testQueue.isEmpty());
  48. var actualRequest = testQueue.dequeue();
  49. assertEquals('a=1&b=2', actualRequest[INDEX_OF_CONTENT_ENTRY].toString());
  50. assertTrue(testQueue.isEmpty());
  51. }
  52. function testLoad_WithGet() {
  53. var USE_GET = false;
  54. var expectedUri = 'uri?a=1&b=2';
  55. var dataSource = new goog.ds.JsXmlHttpDataSource(
  56. expectedUri, 'namne', TEXT_PREFIX, TEXT_POSTFIX, USE_GET);
  57. var testQueue = new goog.testing.TestQueue();
  58. dataSource.xhr_ = new goog.testing.net.XhrIo(testQueue);
  59. dataSource.load();
  60. assertFalse(testQueue.isEmpty());
  61. var actualRequest = testQueue.dequeue();
  62. assertEquals(expectedUri, actualRequest[INDEX_OF_URI_ENTRY].toString());
  63. assertTrue(testQueue.isEmpty());
  64. }