Reporter.js revision d0199bcbfc68b65683c19c4e3e0c38e238142e7e
33d85edf47749fa345d7b636b9b4b9d0d0386f44Dav Glass * An object capable of sending test results to a server.
33d85edf47749fa345d7b636b9b4b9d0d0386f44Dav Glass * @param {String} url The URL to submit the results to.
33d85edf47749fa345d7b636b9b4b9d0d0386f44Dav Glass * @param {Function} format (Optiona) A function that outputs the results in a specific format.
33d85edf47749fa345d7b636b9b4b9d0d0386f44Dav Glass * @constructor
5aab19b8b78189ce79cf89283f2d505566d4e6a8Dav Glass * @namespace Test
33d85edf47749fa345d7b636b9b4b9d0d0386f44Dav Glass * @class Reporter
33d85edf47749fa345d7b636b9b4b9d0d0386f44Dav Glass * The URL to submit the data to.
33d85edf47749fa345d7b636b9b4b9d0d0386f44Dav Glass * @type String
33d85edf47749fa345d7b636b9b4b9d0d0386f44Dav Glass * @property url
33d85edf47749fa345d7b636b9b4b9d0d0386f44Dav Glass * The formatting function to call when submitting the data.
33d85edf47749fa345d7b636b9b4b9d0d0386f44Dav Glass * @type Function
33d85edf47749fa345d7b636b9b4b9d0d0386f44Dav Glass * @property format
33d85edf47749fa345d7b636b9b4b9d0d0386f44Dav Glass * Extra fields to submit with the request.
33d85edf47749fa345d7b636b9b4b9d0d0386f44Dav Glass * @type Object
33d85edf47749fa345d7b636b9b4b9d0d0386f44Dav Glass * @property _fields
33d85edf47749fa345d7b636b9b4b9d0d0386f44Dav Glass this._fields = new Object();
33d85edf47749fa345d7b636b9b4b9d0d0386f44Dav Glass * The form element used to submit the results.
33d85edf47749fa345d7b636b9b4b9d0d0386f44Dav Glass * @type HTMLFormElement
33d85edf47749fa345d7b636b9b4b9d0d0386f44Dav Glass * @property _form
33d85edf47749fa345d7b636b9b4b9d0d0386f44Dav Glass this._form = null;
33d85edf47749fa345d7b636b9b4b9d0d0386f44Dav Glass * Iframe used as a target for form submission.
33d85edf47749fa345d7b636b9b4b9d0d0386f44Dav Glass * @type HTMLIFrameElement
33d85edf47749fa345d7b636b9b4b9d0d0386f44Dav Glass * @property _iframe
33d85edf47749fa345d7b636b9b4b9d0d0386f44Dav Glass this._iframe = null;
33d85edf47749fa345d7b636b9b4b9d0d0386f44Dav Glass //restore missing constructor
33d85edf47749fa345d7b636b9b4b9d0d0386f44Dav Glass * Adds a field to the form that submits the results.
33d85edf47749fa345d7b636b9b4b9d0d0386f44Dav Glass * @param {String} name The name of the field.
33d85edf47749fa345d7b636b9b4b9d0d0386f44Dav Glass * @param {Variant} value The value of the field.
33d85edf47749fa345d7b636b9b4b9d0d0386f44Dav Glass * @return {Void}
33d85edf47749fa345d7b636b9b4b9d0d0386f44Dav Glass * @method addField
33d85edf47749fa345d7b636b9b4b9d0d0386f44Dav Glass * Removes all previous defined fields.
33d85edf47749fa345d7b636b9b4b9d0d0386f44Dav Glass * @return {Void}
33d85edf47749fa345d7b636b9b4b9d0d0386f44Dav Glass * @method addField
33d85edf47749fa345d7b636b9b4b9d0d0386f44Dav Glass clearFields : function(){
33d85edf47749fa345d7b636b9b4b9d0d0386f44Dav Glass this._fields = new Object();
33d85edf47749fa345d7b636b9b4b9d0d0386f44Dav Glass * Cleans up the memory associated with the TestReporter, removing DOM elements
33d85edf47749fa345d7b636b9b4b9d0d0386f44Dav Glass * that were created.
33d85edf47749fa345d7b636b9b4b9d0d0386f44Dav Glass * @return {Void}
33d85edf47749fa345d7b636b9b4b9d0d0386f44Dav Glass * @method destroy
33d85edf47749fa345d7b636b9b4b9d0d0386f44Dav Glass destroy : function() {
33d85edf47749fa345d7b636b9b4b9d0d0386f44Dav Glass this._form = null;
33d85edf47749fa345d7b636b9b4b9d0d0386f44Dav Glass this._iframe.parentNode.removeChild(this._iframe);
33d85edf47749fa345d7b636b9b4b9d0d0386f44Dav Glass this._iframe = null;
33d85edf47749fa345d7b636b9b4b9d0d0386f44Dav Glass this._fields = null;
33d85edf47749fa345d7b636b9b4b9d0d0386f44Dav Glass * Sends the report to the server.
33d85edf47749fa345d7b636b9b4b9d0d0386f44Dav Glass * @param {Object} results The results object created by TestRunner.
33d85edf47749fa345d7b636b9b4b9d0d0386f44Dav Glass * @return {Void}
33d85edf47749fa345d7b636b9b4b9d0d0386f44Dav Glass * @method report
33d85edf47749fa345d7b636b9b4b9d0d0386f44Dav Glass //if the form hasn't been created yet, create it
33d85edf47749fa345d7b636b9b4b9d0d0386f44Dav Glass //IE won't let you assign a name using the DOM, must do it the hacky way
33d85edf47749fa345d7b636b9b4b9d0d0386f44Dav Glass this._iframe = document.createElement("<iframe name=\"yuiTestTarget\" />");
33d85edf47749fa345d7b636b9b4b9d0d0386f44Dav Glass //set the form's action
33d85edf47749fa345d7b636b9b4b9d0d0386f44Dav Glass //remove any existing fields
33d85edf47749fa345d7b636b9b4b9d0d0386f44Dav Glass //create default fields
33d85edf47749fa345d7b636b9b4b9d0d0386f44Dav Glass this._fields.timestamp = (new Date()).toLocaleString();
33d85edf47749fa345d7b636b9b4b9d0d0386f44Dav Glass //add fields to the form
33d85edf47749fa345d7b636b9b4b9d0d0386f44Dav Glass if (this._fields.hasOwnProperty(prop) && (typeof value != "function")){
33d85edf47749fa345d7b636b9b4b9d0d0386f44Dav Glass //remove default fields