1 include(bbq.ajax.AJAXRequest);
  2 
  3 /**
  4  * For use while testing classes that make AJAX requests to a remote server.
  5  *
  6  * For example, if you are testing a bit of code that includes the following:
  7  *
  8  * <pre>
  9  * <code class="language-javascript">
 10  * new bbq.ajax.JSONRequest({
 11  *     url: "/foo/bar",
 12  *     args: {
 13  *          bar: "baz"
 14  *     },
 15  *     onSuccess: function(serverResponse, json) {
 16  *          alert("server said: " + json.baz);
 17  *     }
 18  * });
 19  * </code>
 20  * </pre>
 21  *
 22  * To handle this sort of request, you'd do the following before the AJAX
 23  * call is invoked:
 24  *
 25  * <pre>
 26  * <code class="language-javascript">
 27  * bbq.ajax.MockAJAXRequest["/foo/bar"] = function(args) {
 28  *      return new bbq.ajax.MockJSONResponse({response: {
 29  *          baz: "qux"
 30  *      }});
 31  * }
 32  * </code>
 33  * </pre>
 34  *
 35  * This will result in the onSuccess handler being called immediately.
 36  *
 37  * @class bbq.ajax.MockAJAXRequest
 38  */
 39 bbq.ajax.MockAJAXRequest = {
 40 
 41 };
 42 
 43 // Overwrite method that sends the AJAX request
 44 bbq.ajax.AJAXRequest.prototype._sendRequest = function() {
 45 	var result;
 46 
 47 	try {
 48 		if(bbq.ajax.MockAJAXRequest[this.options.url]) {
 49 			var handler = bbq.ajax.MockAJAXRequest[this.options.url];
 50 
 51 			result = handler(this.options.args);
 52 
 53 			this._onSuccess(result);
 54 
 55 			return;
 56 		}
 57 	} catch(e) {
 58 
 59 	}
 60 
 61 	this._onFailure(result);
 62 };
 63