/* Copyright (c) 2009, Yahoo! Inc. All rights reserved. Code licensed under the BSD License: http://developer.yahoo.net/yui/license.txt version: 3.0.0 build: 1549 */ YUI.add("test",function(B){B.namespace("Test");B.Test.Case=function(C){this._should={};for(var D in C){this[D]=C[D];}if(!B.Lang.isString(this.name)){this.name="testCase"+B.guid();}};B.Test.Case.prototype={resume:function(C){B.Test.Runner.resume(C);},wait:function(E,D){var C=arguments;if(B.Lang.isFunction(C[0])){throw new B.Test.Wait(C[0],C[1]);}else{throw new B.Test.Wait(function(){B.Assert.fail("Timeout: wait() called but resume() never called.");},(B.Lang.isNumber(C[0])?C[0]:10000));}},setUp:function(){},tearDown:function(){}};B.Test.Wait=function(D,C){this.segment=(B.Lang.isFunction(D)?D:null);this.delay=(B.Lang.isNumber(C)?C:0);};B.namespace("Test");B.Test.Suite=function(C){this.name="";this.items=[];if(B.Lang.isString(C)){this.name=C;}else{if(B.Lang.isObject(C)){B.mix(this,C,true);}}if(this.name===""){this.name="testSuite"+B.guid();}};B.Test.Suite.prototype={add:function(C){if(C instanceof B.Test.Suite||C instanceof B.Test.Case){this.items.push(C);}return this;},setUp:function(){},tearDown:function(){}};B.Test.Runner=(function(){function D(E){this.testObject=E;this.firstChild=null;this.lastChild=null;this.parent=null;this.next=null;this.results={passed:0,failed:0,total:0,ignored:0};if(E instanceof B.Test.Suite){this.results.type="testsuite";this.results.name=E.name;}else{if(E instanceof B.Test.Case){this.results.type="testcase";this.results.name=E.name;}}}D.prototype={appendChild:function(E){var F=new D(E);if(this.firstChild===null){this.firstChild=this.lastChild=F;}else{this.lastChild.next=F;this.lastChild=F;}F.parent=this;return F;}};function C(){C.superclass.constructor.apply(this,arguments);this.masterSuite=new B.Test.Suite("YUI Test Results");this._cur=null;this._root=null;this._log=true;this._waiting=false;var F=[this.TEST_CASE_BEGIN_EVENT,this.TEST_CASE_COMPLETE_EVENT,this.TEST_SUITE_BEGIN_EVENT,this.TEST_SUITE_COMPLETE_EVENT,this.TEST_PASS_EVENT,this.TEST_FAIL_EVENT,this.TEST_IGNORE_EVENT,this.COMPLETE_EVENT,this.BEGIN_EVENT];for(var E=0;E-1&&I.indexOf(" ")>-1))&&B.Lang.isFunction(G[I])){H.appendChild(I);}}},_addTestSuiteToTestTree:function(E,H){var G=E.appendChild(H);for(var F=0;F0){return B.Lang.substitute(D,{message:C});}else{return C;}},_getCount:function(){return this._asserts;},_increment:function(){this._asserts++;},_reset:function(){this._asserts=0;},fail:function(C){throw new B.Assert.Error(B.Assert._formatMessage(C,"Test force-failed."));},areEqual:function(D,E,C){B.Assert._increment();if(D!=E){throw new B.Assert.ComparisonFailure(B.Assert._formatMessage(C,"Values should be equal."),D,E);}},areNotEqual:function(C,E,D){B.Assert._increment();if(C==E){throw new B.Assert.UnexpectedValue(B.Assert._formatMessage(D,"Values should not be equal."),C);}},areNotSame:function(C,E,D){B.Assert._increment();if(C===E){throw new B.Assert.UnexpectedValue(B.Assert._formatMessage(D,"Values should not be the same."),C);}},areSame:function(D,E,C){B.Assert._increment();if(D!==E){throw new B.Assert.ComparisonFailure(B.Assert._formatMessage(C,"Values should be the same."),D,E);}},isFalse:function(D,C){B.Assert._increment();if(false!==D){throw new B.Assert.ComparisonFailure(B.Assert._formatMessage(C,"Value should be false."),false,D);}},isTrue:function(D,C){B.Assert._increment();if(true!==D){throw new B.Assert.ComparisonFailure(B.Assert._formatMessage(C,"Value should be true."),true,D);}},isNaN:function(D,C){B.Assert._increment();if(!isNaN(D)){throw new B.Assert.ComparisonFailure(B.Assert._formatMessage(C,"Value should be NaN."),NaN,D);}},isNotNaN:function(D,C){B.Assert._increment();if(isNaN(D)){throw new B.Assert.UnexpectedValue(B.Assert._formatMessage(C,"Values should not be NaN."),NaN);}},isNotNull:function(D,C){B.Assert._increment();if(B.Lang.isNull(D)){throw new B.Assert.UnexpectedValue(B.Assert._formatMessage(C,"Values should not be null."),null);}},isNotUndefined:function(D,C){B.Assert._increment();if(B.Lang.isUndefined(D)){throw new B.Assert.UnexpectedValue(B.Assert._formatMessage(C,"Value should not be undefined."),undefined);}},isNull:function(D,C){B.Assert._increment();if(!B.Lang.isNull(D)){throw new B.Assert.ComparisonFailure(B.Assert._formatMessage(C,"Value should be null."),null,D);}},isUndefined:function(D,C){B.Assert._increment();if(!B.Lang.isUndefined(D)){throw new B.Assert.ComparisonFailure(B.Assert._formatMessage(C,"Value should be undefined."),undefined,D);}},isArray:function(D,C){B.Assert._increment();if(!B.Lang.isArray(D)){throw new B.Assert.UnexpectedValue(B.Assert._formatMessage(C,"Value should be an array."),D);}},isBoolean:function(D,C){B.Assert._increment();if(!B.Lang.isBoolean(D)){throw new B.Assert.UnexpectedValue(B.Assert._formatMessage(C,"Value should be a Boolean."),D);}},isFunction:function(D,C){B.Assert._increment();if(!B.Lang.isFunction(D)){throw new B.Assert.UnexpectedValue(B.Assert._formatMessage(C,"Value should be a function."),D);}},isInstanceOf:function(D,E,C){B.Assert._increment();if(!(E instanceof D)){throw new B.Assert.ComparisonFailure(B.Assert._formatMessage(C,"Value isn't an instance of expected type."),D,E);}},isNumber:function(D,C){B.Assert._increment();if(!B.Lang.isNumber(D)){throw new B.Assert.UnexpectedValue(B.Assert._formatMessage(C,"Value should be a number."),D);}},isObject:function(D,C){B.Assert._increment();if(!B.Lang.isObject(D)){throw new B.Assert.UnexpectedValue(B.Assert._formatMessage(C,"Value should be an object."),D);}},isString:function(D,C){B.Assert._increment();if(!B.Lang.isString(D)){throw new B.Assert.UnexpectedValue(B.Assert._formatMessage(C,"Value should be a string."),D);}},isTypeOf:function(C,E,D){B.Assert._increment();if(typeof E!=C){throw new B.Assert.ComparisonFailure(B.Assert._formatMessage(D,"Value should be of type "+C+"."),expected,typeof E);}}};B.assert=function(D,C){B.Assert._increment();if(!D){throw new B.Assert.Error(B.Assert._formatMessage(C,"Assertion failed."));}};B.fail=B.Assert.fail;B.Assert.Error=function(C){arguments.callee.superclass.constructor.call(this,C);this.message=C;this.name="Assert Error";};B.extend(B.Assert.Error,Error,{getMessage:function(){return this.message;},toString:function(){return this.name+": "+this.getMessage();},valueOf:function(){return this.toString();}});B.Assert.ComparisonFailure=function(D,C,E){arguments.callee.superclass.constructor.call(this,D);this.expected=C;this.actual=E;this.name="ComparisonFailure";};B.extend(B.Assert.ComparisonFailure,B.Assert.Error,{getMessage:function(){return this.message+"\nExpected: "+this.expected+" ("+(typeof this.expected)+")"+"\nActual: "+this.actual+" ("+(typeof this.actual)+")";}});B.Assert.UnexpectedValue=function(D,C){arguments.callee.superclass.constructor.call(this,D);this.unexpected=C;this.name="UnexpectedValue";};B.extend(B.Assert.UnexpectedValue,B.Assert.Error,{getMessage:function(){return this.message+"\nUnexpected: "+this.unexpected+" ("+(typeof this.unexpected)+") ";}});B.Assert.ShouldFail=function(C){arguments.callee.superclass.constructor.call(this,C||"This test should fail but didn't.");this.name="ShouldFail";};B.extend(B.Assert.ShouldFail,B.Assert.Error);B.Assert.ShouldError=function(C){arguments.callee.superclass.constructor.call(this,C||"This test should have thrown an error but didn't.");this.name="ShouldError";};B.extend(B.Assert.ShouldError,B.Assert.Error);B.Assert.UnexpectedError=function(C){arguments.callee.superclass.constructor.call(this,"Unexpected error: "+C.message);this.cause=C;this.name="UnexpectedError";this.stack=C.stack;};B.extend(B.Assert.UnexpectedError,B.Assert.Error);B.ArrayAssert={contains:function(E,D,C){B.Assert._increment();if(B.Array.indexOf(D,E)==-1){B.Assert.fail(B.Assert._formatMessage(C,"Value "+E+" ("+(typeof E)+") not found in array ["+D+"]."));}},containsItems:function(E,F,D){B.Assert._increment();for(var C=0;C-1){B.Assert.fail(B.Assert._formatMessage(C,"Value found in array ["+D+"]."));}},doesNotContainItems:function(E,F,D){B.Assert._increment();for(var C=0;C-1){B.Assert.fail(B.Assert._formatMessage(D,"Value found in array ["+F+"]."));}}},doesNotContainMatch:function(E,D,C){B.Assert._increment();if(typeof E!="function"){throw new TypeError("ArrayAssert.doesNotContainMatch(): First argument must be a function.");}if(B.Array.some(D,E)){B.Assert.fail(B.Assert._formatMessage(C,"Value found in array ["+D+"]."));}},indexOf:function(G,F,C,E){B.Assert._increment();for(var D=0;D0){B.Assert.fail(B.Assert._formatMessage(C,"Array should be empty."));}},isNotEmpty:function(D,C){B.Assert._increment();if(D.length===0){B.Assert.fail(B.Assert._formatMessage(C,"Array should not be empty."));}},itemsAreSame:function(E,F,D){B.Assert._increment();if(E.length!=F.length){B.Assert.fail(B.Assert._formatMessage(D,"Array should have a length of "+E.length+" but has a length of "+F.length));}for(var C=0;C=0;D--){if(F[D]===G){if(C!=D){B.Assert.fail(B.Assert._formatMessage(E,"Value exists at index "+D+" but should be at index "+C+"."));}return;}}B.Assert.fail(B.Assert._formatMessage(E,"Value doesn't exist in array."));}};B.ObjectAssert={areEqual:function(D,E,C){B.Assert._increment();B.Object.each(D,function(G,F){if(D[F]!=E[F]){throw new B.Assert.ComparisonFailure(B.Assert._formatMessage(C,"Values should be equal for property "+F),D[F],E[F]);}});},hasKey:function(C,D,E){B.Assert._increment();if(!B.Object.hasKey(D,C)){B.fail(B.Assert._formatMessage(E,"Property '"+C+"' not found on object."));}},hasKeys:function(E,C,F){B.Assert._increment();for(var D=0;D0){B.fail(B.Assert._formatMessage(E,"Object owns "+D.length+" properties but should own none."));}}};B.DateAssert={datesAreEqual:function(D,F,C){B.Assert._increment();if(D instanceof Date&&F instanceof Date){var E="";if(D.getFullYear()!=F.getFullYear()){E="Years should be equal.";}if(D.getMonth()!=F.getMonth()){E="Months should be equal.";}if(D.getDate()!=F.getDate()){E="Days of month should be equal.";}if(E.length){throw new B.Assert.ComparisonFailure(B.Assert._formatMessage(C,E),D,F);}}else{throw new TypeError("Y.Assert.datesAreEqual(): Expected and actual values must be Date objects.");}},timesAreEqual:function(D,F,C){B.Assert._increment();if(D instanceof Date&&F instanceof Date){var E="";if(D.getHours()!=F.getHours()){E="Hours should be equal.";}if(D.getMinutes()!=F.getMinutes()){E="Minutes should be equal.";}if(D.getSeconds()!=F.getSeconds()){E="Seconds should be equal.";}if(E.length){throw new B.Assert.ComparisonFailure(B.Assert._formatMessage(C,E),D,F);}}else{throw new TypeError("DateY.AsserttimesAreEqual(): Expected and actual values must be Date objects.");}}};B.namespace("Test.Format");function A(C){return C.replace(/[<>"'&]/g,function(D){switch(D){case"<":return"<";case">":return">";case'"':return""";case"'":return"'";case"&":return"&";}});}B.Test.Format.JSON=function(C){return B.JSON.stringify(C);};B.Test.Format.XML=function(E){var C=B.Lang;var D="<"+E.type+' name="'+A(E.name)+'"';if(E.type=="test"){D+=' result="'+A(E.result)+'" message="'+A(E.message)+'">';}else{D+=' passed="'+E.passed+'" failed="'+E.failed+'" ignored="'+E.ignored+'" total="'+E.total+'">';B.Object.each(E,function(F,G){if(C.isObject(F)&&!C.isArray(F)){D+=arguments.callee(F);}});}D+="";return D;};B.Test.Format.XML=function(D){function C(G){var E=B.Lang,F="<"+G.type+' name="'+A(G.name)+'"';if(E.isNumber(G.duration)){F+=' duration="'+G.duration+'"';}if(G.type=="test"){F+=' result="'+G.result+'" message="'+A(G.message)+'">';}else{F+=' passed="'+G.passed+'" failed="'+G.failed+'" ignored="'+G.ignored+'" total="'+G.total+'">';B.Object.each(G,function(H,I){if(E.isObject(H)&&!E.isArray(H)){F+=C(H);}});}F+="";return F;}return''+C(D);};B.Test.Format.JUnitXML=function(C){function D(G){var E=B.Lang,F="",H;switch(G.type){case"test":if(G.result!="ignore"){F='';if(G.result=="fail"){F+='";}F+="";}break;case"testcase":F='';B.Object.each(G,function(I,J){if(E.isObject(I)&&!E.isArray(I)){F+=D(I);}});F+="";break;case"testsuite":B.Object.each(G,function(I,J){if(E.isObject(I)&&!E.isArray(I)){F+=D(I);}});break;case"report":F="";B.Object.each(G,function(I,J){if(E.isObject(I)&&!E.isArray(I)){F+=D(I);}});F+="";}return F;}return''+D(C);};B.namespace("Test");B.Test.Reporter=function(C,D){this.url=C;this.format=D||B.Test.Format.XML;this._fields=new Object();this._form=null;this._iframe=null;};B.Test.Reporter.prototype={constructor:B.Test.Reporter,addField:function(C,D){this._fields[C]=D;},clearFields:function(){this._fields=new Object();},destroy:function(){if(this._form){this._form.parentNode.removeChild(this._form);this._form=null;}if(this._iframe){this._iframe.parentNode.removeChild(this._iframe);this._iframe=null;}this._fields=null;},report:function(C){if(!this._form){this._form=document.createElement("form");this._form.method="post";this._form.style.visibility="hidden";this._form.style.position="absolute";this._form.style.top=0;document.body.appendChild(this._form);if(B.UA.ie){this._iframe=document.createElement('