Ticket #3009: 3009_3.patch

File 3009_3.patch, 3.9 KB (added by Garry Yao, 15 years ago)
  • _test/cktester/runners/yuitest/extension.js

     
    33For licensing, see LICENSE.html or http://ckeditor.com/license
    44*/
    55
    6 (function()
     6
     7// Extend YUI Lang to support function interception.
     8YAHOO.lang.intercept = function( originalFunction, functionBuilder )
     9{
     10        return functionBuilder( originalFunction );
     11};
     12
     13// Extend YUI TestRunner to support 'wait'/'resume' in during 'setUp' of TestSuite/TestCase.
     14( function()
    715{
     16        function getWaitInterceptor( continuation )
     17        {
     18                return function ( original )
     19                {
     20                        var fn = continuation;
     21                        return function()
     22                        {
     23                                var orgFn = original;
     24                                try
     25                                {
     26                                        orgFn.apply( this, arguments );
     27                                }catch( thrown )
     28                                {
     29                                        if ( thrown instanceof YAHOO.tool.TestCase.Wait )
     30                                        {
     31                                                this.continuation = fn;
     32                                        }
     33                                        else
     34                                                throw thrown;
     35                                }
     36                        };
     37                }
     38        }
     39
     40        var runner = YAHOO.tool.TestRunner;
     41
     42        // Borrow 'wait' from YAHOO.tool.TestCase.
     43        YAHOO.lang.augment( YAHOO.tool.TestSuite, YAHOO.tool.TestCase, 'wait' );
     44
     45        // Resume the continuation of setUp on 'resumeSetup()'.
     46        YAHOO.tool.TestSuite.prototype.resumeSetup = YAHOO.tool.TestCase.prototype.resumeSetup =
     47        function( )
     48        {
     49                runner.continuation.call( runner );
     50                delete runner.continuation;
     51        };
     52
     53        // Pause the test suite setup on any wait() and it's enough to continue by re-calling '_run'.
     54        runner._run = YAHOO.lang.intercept( runner._run , getWaitInterceptor( function()
     55        {
     56                runner._run();
     57        } ) );
     58
     59        // Pause the test case setup on any wait(), and continue with '_resumeTest( testFragment )'.
     60        runner._runTest = YAHOO.lang.intercept( runner._runTest , getWaitInterceptor( function()
     61        {
     62                var node = this._cur,
     63                        testName /*:String*/ = node.testObject,
     64                        testCase /*:YAHOO.tool.TestCase*/ = node.parent.testObject,
     65                        test /*:Function*/ = testCase[testName];
     66
     67                this._resumeTest( test );
     68        } ) );
     69} )();
     70
     71
     72(function()
     73{
    874        var createLogger = function()
    975        {
    1076                document.body.appendChild( document.createElement( 'div' ) ).id = 'testLogger';
  • _source/core/test.js

     
    182182         */
    183183        deferRunner : false
    184184};
     185
     186// Provide a set of default test suites/test cases.
     187CKEDITOR.test.suites = {};
     188CKEDITOR.test.cases = {};
     189/**
     190 *  All test cases in this suite share a fully interacted 'playground' editor instance.
     191 */
     192YAHOO.lang.extend( ( CKEDITOR.test.suites.editorTestSuite = function( template )
     193        {
     194                // The editor instance shared by all tests.
     195                this.editor = null;
     196                // The editor name to be used.
     197                this.editorName = '';
     198                // The editor instance config to be used.
     199                this.config = null;
     200                // The initial editor data loaded.
     201                this.startupData = null;
     202
     203                CKEDITOR.test.suites.editorTestSuite.superclass.constructor.call( this, template );
     204
     205        } ), YAHOO.tool.TestSuite,
     206        {
     207                setUp : function() {
     208
     209                        var editorName = this.editorName || 'test_editor';
     210                        var element = CKEDITOR.document.getById( editorName )
     211                                                  || CKEDITOR.document.getBody().append(
     212                                                                CKEDITOR.dom.element.createFromHtml(
     213                                                                '<div id="' + editorName + '"></div>') );
     214                        element.setValue( this.startupData );
     215                        CKEDITOR.on( 'instanceReady', function( evt )
     216                        {
     217                                if ( evt.editor.name == editorName )
     218                                {
     219                                        this.editor = evt.editor;
     220                                        this.editor.focus();
     221                                        this.resumeSetup();
     222                                }
     223                        }, this );
     224                        CKEDITOR.replace( element.getAttribute( 'id' ), this.config );
     225                        this.wait();
     226                },
     227
     228                tearDown : function()
     229                {
     230                        this.editor.destroy();
     231                }
     232        });
     233
© 2003 – 2022, CKSource sp. z o.o. sp.k. All rights reserved. | Terms of use | Privacy policy