PageRenderTime 42ms CodeModel.GetById 18ms RepoModel.GetById 0ms app.codeStats 0ms

/framework/source/class/qx/test/io/remote/AbstractRequest.js

http://github.com/qooxdoo/qooxdoo
JavaScript | 150 lines | 95 code | 31 blank | 24 comment | 4 complexity | f5e07c45e803cee655f9fe64531be144 MD5 | raw file
Possible License(s): CC-BY-SA-3.0, LGPL-3.0, MIT
  1. /* ************************************************************************
  2. qooxdoo - the new era of web development
  3. http://qooxdoo.org
  4. Copyright:
  5. 2007-2008 1&1 Internet AG, Germany, http://www.1und1.de
  6. License:
  7. MIT: https://opensource.org/licenses/MIT
  8. See the LICENSE file in the project's top-level directory for details.
  9. Authors:
  10. * Fabian Jakobs (fjakobs)
  11. * Tristan Koch (tristankoch)
  12. ************************************************************************ */
  13. /*
  14. */
  15. /**
  16. *
  17. * @asset(qx/test/*)
  18. */
  19. qx.Class.define("qx.test.io.remote.AbstractRequest",
  20. {
  21. type : "abstract",
  22. extend : qx.dev.unit.TestCase,
  23. include : qx.test.io.MRemoteTest,
  24. members :
  25. {
  26. _requests : null,
  27. setUp : function()
  28. {
  29. this._requests = [];
  30. for (var i = 0; i < 10 ; i++) {
  31. var request = this._createRequest();
  32. request.addListener("aborted", this.responseError, this);
  33. request.addListener("failed", this.responseError, this);
  34. request.addListener("timeout", this.responseError, this);
  35. this._requests[i] = request;
  36. }
  37. },
  38. _createRequest : function() {
  39. throw new Error("Abstract method call");
  40. },
  41. _getRequests: function() {
  42. return this._requests;
  43. },
  44. tearDown : function() {
  45. this._disposeArray("_requests");
  46. },
  47. responseError : function(e)
  48. {
  49. var request = e;
  50. var type = e.getType();
  51. qx.event.Timer.once(function()
  52. {
  53. this.resume(function()
  54. {
  55. this.fail("Response error: " + type + " " +
  56. request.getStatusCode()
  57. );
  58. }, this);
  59. }, this);
  60. },
  61. testAsynchronous : function()
  62. {
  63. if (this.isLocal()) {
  64. this.needsPHPWarning();
  65. return;
  66. }
  67. var completedCount = 0;
  68. for (var i = 0; i < this._requests.length; i++)
  69. {
  70. var request = this._requests[i];
  71. request.setParameter("test", "test" + i);
  72. request.addListener("completed", function(e)
  73. {
  74. completedCount++;
  75. var response = qx.lang.Json.parse(e.getContent());
  76. request = e.getTarget();
  77. this.assertEquals(request.getParameter("test"), response["test"]);
  78. }, this);
  79. request.send();
  80. }
  81. var that = this;
  82. this.wait(5000, function()
  83. {
  84. that.assertEquals(i, completedCount);
  85. });
  86. },
  87. testAbortedOnException : function()
  88. {
  89. if (this.isLocal()) {
  90. this.needsPHPWarning();
  91. return;
  92. }
  93. var url = this.getUrl("qx/test/xmlhttp/echo_get_request.php");
  94. var request = new qx.io.remote.Request(url, "GET", "text/plain");
  95. request.addListener("failed", this.responseError, this);
  96. request.addListener("timeout", this.responseError, this);
  97. request.addListener("completed", function(e)
  98. {
  99. throw new Error("Expected exception.");
  100. }, this);
  101. request.addListener("aborted", function(e)
  102. {
  103. this.resume(function()
  104. {
  105. this.assertEquals(request, e.getTarget());
  106. request.dispose();
  107. }, this);
  108. }, this);
  109. request.send();
  110. this.wait(2000);
  111. }
  112. }
  113. });