Ticket #3064: test-domiterator.patch

File test-domiterator.patch, 4.1 KB (added by Garry Yao, 15 years ago)
  • _source/tests/plugins/domiterator/domiterator.html

     
     1<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
     2<html xmlns="http://www.w3.org/1999/xhtml">
     3<head>
     4        <title>Plugin: domiterator</title>
     5        <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
     6        <link rel="stylesheet" type="text/css" href="../../test.css" />
     7        <script type="text/javascript" src="../../../../ckeditor_source.js"></script>
     8        <script type="text/javascript" src="../../test.js"></script>
     9        <script type="text/javascript">
     10
     11CKEDITOR.plugins.load( [ 'htmldataprocessor', 'htmlwriter', 'domiterator'] );
     12
     13
     14        </script>
     15        <script type="text/javascript">
     16        //<![CDATA[
     17
     18/**
     19 * IE always returning CRLF for linefeed, so remove it when retrieve pre-formated text from text area.
     20 * @param {Object} id
     21 */     
     22function getTextAreaValue( id )
     23{
     24        return CKEDITOR.document.getById( id ).getValue().replace(/\r/gi,'');
     25}
     26
     27CKEDITOR.test.addTestCase( (function()
     28{
     29       
     30        // Local references.
     31        var assert = CKEDITOR.test.assert,
     32                arrayAssert = YAHOO.util.ArrayAssert;
     33       
     34        var doc = new CKEDITOR.dom.document( document );
     35
     36        // In these tests, we may "reset" the writer rules to avoid it formatting
     37        // the output, making the assertion easier to the done. We don't need to
     38        // test formatting features here, so this is ok.
     39        var getDataProcessor = function()
     40        {
     41                var dataProcessor = new CKEDITOR.htmlDataProcessor();
     42                dataProcessor.writer._.rules = [];
     43                return dataProcessor;
     44        };
     45
     46        /**
     47         * IE always returning CRLF for line-feed, so remove it when retrieving
     48         * pre-formated text from text area.
     49         */
     50        function getTextAreaValue( id )
     51        {
     52                return CKEDITOR.document.getById( id ).getValue().replace( /\r/gi, '' );
     53        }
     54
     55        function assumeElementContentAreSame( container, textareaId )
     56        {
     57                if( typeof container == 'string' )
     58                        container = doc.getById( container );
     59                //Assume result document content
     60                var html = getDataProcessor().toDataFormat( container );
     61                assert.areSame( getTextAreaValue( textareaId ) , html );
     62        }
     63       
     64        function assumeElementAreSame( element, textareaId )
     65        {
     66                if( typeof element == 'string' )
     67                        element = doc.getById( element );
     68                //Assume result document content
     69                var html = getDataProcessor().toDataFormat( element.getOuterHtml() );
     70                assert.areSame( getTextAreaValue( textareaId ) , html );
     71        }
     72       
     73        /**
     74         *
     75         * @param {String|CKEDITOR.dom.range} containerId|range Either the id of html container which contents are treated as range, or a exisiting range object.
     76         * @param {Object} iteratorOption
     77         * @param {Array} expectedTagList block elements tagName list in iteration orders.
     78         */
     79        function assumeIterationSameAs( containerIdOrRange, iteratorOption, expectedTagList )
     80        {
     81                var range;
     82                if( typeof containerIdOrRange == 'string' )
     83                {
     84                        range = new CKEDITOR.dom.range( doc );
     85                        range.selectNodeContents( doc.getById( containerIdOrRange ) );
     86                }
     87                else
     88                        range = containerIdOrRange;
     89                       
     90                var iter = range.createIterator();
     91                CKEDITOR.tools.extend( iter, iteratorOption, true );
     92                var blockList = [], block;
     93                while (( block = iter.getNextParagraph() ) )
     94                {
     95                        blockList.push( block.getName() );
     96                }
     97                arrayAssert.itemsAreEqual( expectedTagList, blockList );
     98        }
     99       
     100        return {
     101               
     102                /**
     103                 * Test collapsed range before paraghraph end.
     104                 */
     105                test_toDataFormat7 : function()
     106                {
     107                        var range = new CKEDITOR.dom.range( doc );
     108                        range.setStartAt( doc.getById( 'iterTarget7' ), CKEDITOR.POSITION_BEFORE_END );
     109                        assumeIterationSameAs( range, null, [ 'p' ]);
     110                        assumeElementContentAreSame( 'iterContainer7', 'iterResult7' );
     111                },
     112       
     113                name : document.title
     114        };
     115})() );
     116
     117        //]]>
     118        </script>
     119</head>
     120<body>
     121
     122<p id="iterTarget7">paragraph</p>
     123<textarea id="iterResult7"><p id="iterTarget7">paragraph</p></textarea>
     124
     125</body>
     126</html>
     127 No newline at end of file
© 2003 – 2022, CKSource sp. z o.o. sp.k. All rights reserved. | Terms of use | Privacy policy