Ticket #3422: test_domiterator.patch

File test_domiterator.patch, 5.0 KB (added by Garry Yao, 15 years ago)

Unit Test Case

  • _source/tests/plugins/domiterator/domiterator_12_data.htm

     
     1<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
     2<html>
     3        <head>
     4                <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
     5                <title>Javascript  Test Page</title>
     6        </head>
     7        <body>
     8                text
     9                <br />
     10                text
     11                <br _moz_dirty="" />
     12        </body>
     13</html>
  • _source/tests/plugins/domiterator/domiterator_12.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
     27var tc;
     28CKEDITOR.test.addTestCase( tc = (function()
     29{
     30       
     31        // Local references.
     32        var assert = CKEDITOR.test.assert,
     33                arrayAssert = YAHOO.util.ArrayAssert;
     34       
     35        var doc = new CKEDITOR.dom.document( document );
     36
     37        // In these tests, we may "reset" the writer rules to avoid it formatting
     38        // the output, making the assertion easier to the done. We don't need to
     39        // test formatting features here, so this is ok.
     40        var getDataProcessor = function()
     41        {
     42                var dataProcessor = new CKEDITOR.htmlDataProcessor();
     43                dataProcessor.writer._.rules = [];
     44                return dataProcessor;
     45        };
     46
     47        /**
     48         * IE always returning CRLF for line-feed, so remove it when retrieving
     49         * pre-formated text from text area.
     50         */
     51        function getTextAreaValue( id )
     52        {
     53                return CKEDITOR.document.getById( id ).getValue().replace( /\r/gi, '' );
     54        }
     55
     56        function assumeElementContentAreSame( container, textareaId )
     57        {
     58                if( typeof container == 'string' )
     59                        container = doc.getById( container );
     60                //Assume result document content
     61                var html = getDataProcessor().toDataFormat( container.getHtml() );
     62                assert.areSame( getTextAreaValue( textareaId ) , html );
     63        }
     64       
     65        function assumeElementAreSame( element, textareaId )
     66        {
     67                if( typeof element == 'string' )
     68                        element = doc.getById( element );
     69                //Assume result document content
     70                var html = getDataProcessor().toDataFormat( element.getOuterHtml() );
     71                assert.areSame( getTextAreaValue( textareaId ) , html );
     72        }
     73       
     74        /**
     75         *
     76         * @param {String|CKEDITOR.dom.range} containerId|range Either the id of html container which contents are treated as range, or a exisiting range object.
     77         * @param {Object} iteratorOption
     78         * @param {Array} expectedTagList block elements tagName list in iteration orders.
     79         */
     80        function assumeIterationSameAs( containerIdOrRange, iteratorOption, expectedTagList )
     81        {
     82                var range;
     83                if( typeof containerIdOrRange == 'string' )
     84                {
     85                        range = new CKEDITOR.dom.range( doc );
     86                        range.selectNodeContents( doc.getById( containerIdOrRange ) );
     87                }
     88                else
     89                        range = containerIdOrRange;
     90                       
     91                var iter = range.createIterator();
     92                CKEDITOR.tools.extend( iter, iteratorOption, true );
     93                var blockList = [], block;
     94                while (( block = iter.getNextParagraph() ) )
     95                {
     96                        blockList.push( block.getName() );
     97                }
     98                arrayAssert.itemsAreEqual( expectedTagList, blockList );
     99        }
     100       
     101        return {
     102               
     103                /**
     104                 * Test respecting block padding BR when sweeping redundant BRs between newly established paragraphs.
     105                 */
     106                test_iterator_respect_block_padding_br : function()
     107                {
     108                       
     109                        var innerDoc = new CKEDITOR.dom.document(
     110                                document.getElementById( 'innerFrame' ).
     111                                contentWindow.document ),
     112                                range = new CKEDITOR.dom.range( innerDoc );
     113                        range.selectNodeContents( innerDoc.getBody() );
     114                        assumeIterationSameAs( range, null, [ 'p' ] );
     115                        assumeElementContentAreSame( innerDoc.getBody(), 'iteration_result' );
     116                },
     117
     118                name : document.title
     119        };
     120})() );
     121
     122        //]]>
     123        </script>
     124</head>
     125<body>
     126<iframe id="innerFrame" name="innerFrame" src="domiterator_12_data.htm"></iframe>
     127<textarea id="iteration_result"><p>text <br /> text </p><br _moz_dirty="" /></textarea>
     128</body>
     129</html>
© 2003 – 2022, CKSource sp. z o.o. sp.k. All rights reserved. | Terms of use | Privacy policy