Ticket #3149: test-domiterator.patch

File test-domiterator.patch, 4.6 KB (added by Garry Yao, 15 years ago)
  • _source/tests/plugins/domiterator/data5.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>Test Data Page</title>
     6        </head>
     7        <body id="iterContainer5"><br /></body>
     8</html>
  • _source/tests/plugins/domiterator/domiterator_5.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.getHtml() );
     61                assert.areSame( getTextAreaValue( textareaId ) , html );
     62        }
     63       
     64        /**
     65         *
     66         * @param {String|CKEDITOR.dom.range} containerId|range Either the id of html container which contents are treated as range, or a exisiting range object.
     67         * @param {Object} iteratorOption
     68         * @param {Array} expectedTagList block elements tagName list in iteration orders.
     69         */
     70        function assumeIterationSameAs( containerIdOrRange, iteratorOption, expectedTagList )
     71        {
     72                var range;
     73                if( typeof containerIdOrRange == 'string' )
     74                {
     75                        range = new CKEDITOR.dom.range( doc );
     76                        range.selectNodeContents( doc.getById( containerIdOrRange ) );
     77                }
     78                else
     79                        range = containerIdOrRange;
     80                       
     81                var iter = range.createIterator();
     82                CKEDITOR.tools.extend( iter, iteratorOption, true );
     83                var blockList = [], block;
     84                while (( block = iter.getNextParagraph() ) )
     85                {
     86                        blockList.push( block.getName() );
     87                }
     88                arrayAssert.itemsAreEqual( expectedTagList, blockList );
     89        }
     90       
     91        return {
     92               
     93                /**
     94                 * Test ignore BR break.
     95                 */
     96                test_iterator5 : function()
     97                {
     98                        var doc = new CKEDITOR.dom.document(
     99                                document.getElementById( 'innerFrame' ).
     100                                contentWindow.document ),
     101                                range = new CKEDITOR.dom.range( doc );
     102
     103                        range.setStartAt( doc.getById( 'iterContainer5' ), CKEDITOR.POSITION_AFTER_START );
     104                        range.setEndAt( doc.getById( 'iterContainer5' ), CKEDITOR.POSITION_BEFORE_END );
     105                        assumeIterationSameAs( range, null, [] );
     106                        assumeElementContentAreSame( doc.getById( 'iterContainer5' ), 'iterResult5' );
     107                },
     108       
     109                name : document.title
     110        };
     111})() );
     112
     113        //]]>
     114        </script>
     115</head>
     116<body>
     117<iframe id="innerFrame" src="data1.htm"></iframe>
     118<textarea id="iterResult5"><br /></textarea>
     119</body>
     120</html>
© 2003 – 2022, CKSource sp. z o.o. sp.k. All rights reserved. | Terms of use | Privacy policy