Index: _test/cktester/runners/yuitest/extension.js =================================================================== --- _test/cktester/runners/yuitest/extension.js (revision 4088) +++ _test/cktester/runners/yuitest/extension.js Thu Aug 13 19:01:06 CST 2009 @@ -3,8 +3,74 @@ For licensing, see LICENSE.html or http://ckeditor.com/license */ + +// Extend YUI Lang to support function interception. +YAHOO.lang.intercept = function( originalFunction, functionBuilder ) +{ + return functionBuilder( originalFunction ); +}; + +// Extend YUI TestRunner to support 'wait'/'resume' in during 'setUp' of TestSuite/TestCase. -(function() +( function() { + function getWaitInterceptor( continuation ) + { + return function ( original ) + { + var fn = continuation; + return function() + { + var orgFn = original; + try + { + orgFn.apply( this, arguments ); + }catch( thrown ) + { + if ( thrown instanceof YAHOO.tool.TestCase.Wait ) + { + this.continuation = fn; + } + else + throw thrown; + } + }; + } + } + + var runner = YAHOO.tool.TestRunner; + + // Borrow 'wait' from YAHOO.tool.TestCase. + YAHOO.lang.augment( YAHOO.tool.TestSuite, YAHOO.tool.TestCase, 'wait' ); + + // Resume the continuation of setUp on 'resumeSetup()'. + YAHOO.tool.TestSuite.prototype.resumeSetup = YAHOO.tool.TestCase.prototype.resumeSetup = + function( ) + { + runner.continuation.call( runner ); + delete runner.continuation; + }; + + // Pause the test suite setup on any wait() and it's enough to continue by re-calling '_run'. + runner._run = YAHOO.lang.intercept( runner._run , getWaitInterceptor( function() + { + runner._run(); + } ) ); + + // Pause the test case setup on any wait(), and continue with '_resumeTest( testFragment )'. + runner._runTest = YAHOO.lang.intercept( runner._runTest , getWaitInterceptor( function() + { + var node = this._cur, + testName /*:String*/ = node.testObject, + testCase /*:YAHOO.tool.TestCase*/ = node.parent.testObject, + test /*:Function*/ = testCase[testName]; + + this._resumeTest( test ); + } ) ); +} )(); + + +(function() +{ var createLogger = function() { document.body.appendChild( document.createElement( 'div' ) ).id = 'testLogger'; Index: _source/core/test.js =================================================================== --- _source/core/test.js (revision 4037) +++ _source/core/test.js Thu Aug 13 18:40:50 CST 2009 @@ -182,3 +182,52 @@ */ deferRunner : false }; + +// Provide a set of default test suites/test cases. +CKEDITOR.test.suites = {}; +CKEDITOR.test.cases = {}; +/** + * All test cases in this suite share a fully interacted 'playground' editor instance. + */ +YAHOO.lang.extend( ( CKEDITOR.test.suites.editorTestSuite = function( template ) + { + // The editor instance shared by all tests. + this.editor = null; + // The editor name to be used. + this.editorName = ''; + // The editor instance config to be used. + this.config = null; + // The initial editor data loaded. + this.startupData = null; + + CKEDITOR.test.suites.editorTestSuite.superclass.constructor.call( this, template ); + + } ), YAHOO.tool.TestSuite, + { + setUp : function() { + + var editorName = this.editorName || 'test_editor'; + var element = CKEDITOR.document.getById( editorName ) + || CKEDITOR.document.getBody().append( + CKEDITOR.dom.element.createFromHtml( + '
') ); + element.setValue( this.startupData ); + CKEDITOR.on( 'instanceReady', function( evt ) + { + if ( evt.editor.name == editorName ) + { + this.editor = evt.editor; + this.editor.focus(); + this.resumeSetup(); + } + }, this ); + CKEDITOR.replace( element.getAttribute( 'id' ), this.config ); + this.wait(); + }, + + tearDown : function() + { + this.editor.destroy(); + } + }); +