19
19
// compile this test case with Ming makeswf, and then
20
20
// execute it like this gnash -1 -r 0 -v out.swf
22
rcsid="$Id: TextField.as,v 1.45 2008/02/07 18:48:03 strk Exp $";
23
rcsid="$Id: TextField.as,v 1.56 2008/06/05 03:26:32 zoulunkai Exp $";
24
24
#include "check.as"
26
printBounds = function(b)
36
TextField.prototype.getBounds = MovieClip.prototype.getBounds;
26
38
#if OUTPUT_VERSION > 5
28
40
check_equals(typeof(TextField), 'function');
58
70
check( !TextField.prototype.hasOwnProperty('hscroll') );
59
71
xcheck( !TextField.prototype.hasOwnProperty('html') );
60
72
check( !TextField.prototype.hasOwnProperty('htmlText') );
61
check( !TextField.prototype.hasOwnProperty('length') );
73
xcheck( !TextField.prototype.hasOwnProperty('length') );
62
74
check( !TextField.prototype.hasOwnProperty('maxChars') );
63
75
check( !TextField.prototype.hasOwnProperty('maxhscroll') );
64
76
check( !TextField.prototype.hasOwnProperty('maxscroll') );
69
81
xcheck( !TextField.prototype.hasOwnProperty('selectable') );
70
82
check( !TextField.prototype.hasOwnProperty('text') );
71
83
xcheck( !TextField.prototype.hasOwnProperty('textColor') );
72
check( !TextField.prototype.hasOwnProperty('textHeight') );
73
check( !TextField.prototype.hasOwnProperty('textWidth') );
84
xcheck( !TextField.prototype.hasOwnProperty('textHeight') ); // should be available on first instantiation
85
xcheck( !TextField.prototype.hasOwnProperty('textWidth') ); // should be available on first instantiation
74
86
xcheck( !TextField.prototype.hasOwnProperty('type') ); // should be available on first instantiation
75
87
xcheck( !TextField.prototype.hasOwnProperty('variable') );
76
88
xcheck( !TextField.prototype.hasOwnProperty('wordWrap') );
101
113
check_equals(typeof(tfObj.replaceSel), 'function');
102
114
// this is a static method, it's available as TextField.getFontList
103
115
check_equals(typeof(tfObj.getFontList), 'undefined');
116
check_equals(typeof(tfObj._parent), 'undefined'); // no parent
105
118
//--------------------------------------------------
106
119
// Check textfield creation trough createTextField
133
146
xcheck( TextField.prototype.hasOwnProperty('hscroll') );
134
147
check( TextField.prototype.hasOwnProperty('html') );
135
148
xcheck( TextField.prototype.hasOwnProperty('htmlText') );
136
xcheck( TextField.prototype.hasOwnProperty('length') );
149
check( TextField.prototype.hasOwnProperty('length') );
137
150
xcheck( TextField.prototype.hasOwnProperty('maxChars') );
138
151
xcheck( TextField.prototype.hasOwnProperty('maxhscroll') );
139
152
xcheck( TextField.prototype.hasOwnProperty('maxscroll') );
144
157
check( TextField.prototype.hasOwnProperty('selectable') );
145
158
xcheck( TextField.prototype.hasOwnProperty('text') );
146
159
check( TextField.prototype.hasOwnProperty('textColor') );
147
xcheck( TextField.prototype.hasOwnProperty('textHeight') );
148
xcheck( TextField.prototype.hasOwnProperty('textWidth') );
160
check( TextField.prototype.hasOwnProperty('textHeight') );
161
check( TextField.prototype.hasOwnProperty('textWidth') );
149
162
check( TextField.prototype.hasOwnProperty('type') );
150
163
check( TextField.prototype.hasOwnProperty('variable') );
151
164
check( TextField.prototype.hasOwnProperty('wordWrap') );
165
check( TextField.prototype.hasOwnProperty('length') );
153
167
check( ! TextField.prototype.hasOwnProperty('valueOf') );
154
168
check( ! TextField.prototype.hasOwnProperty('toString') );
181
195
check_equals(tf.autoSize, 'center'); // toString is called for object args
182
196
tf.autoSize = 'lEft';
183
xcheck_equals(tf.autoSize, 'left'); // arg is not case sensitive
197
check_equals(tf.autoSize, 'left'); // arg is not case sensitive
184
198
tf.autoSize = new Boolean(true);
185
199
check_equals(tf.autoSize, 'none'); // a Boolean is the same as any other object
311
325
tf.text = "Hello world";
312
326
check_equals(tf.htmlText, 'Hello world');
328
//-------------------------------------------------------------------------
314
329
// Check TextField.length (number of characters in text)
330
//-------------------------------------------------------------------------
316
xcheck_equals(typeof(tf.length), 'number');
332
check_equals(typeof(tf.length), 'number');
317
333
check(!tf.hasOwnProperty('length'));
319
xcheck_equals(tf.length, 0);
335
check_equals(tf.length, 0);
320
336
tf.length = 10; // you don't change lenght like this, you assign to text instead
321
xcheck_equals(tf.length, 0);
337
check_equals(tf.length, 0);
322
338
tf.text = "Hello world";
323
xcheck_equals(tf.length, 11);
339
check_equals(tf.length, 11);
324
340
tf.htmlText = "Hello <b>world</b>";
325
xcheck_equals(tf.length, 18); // the tags are also counted
341
check_equals(tf.length, 18); // the tags are also counted
327
343
// Check TextField.maxChars
360
376
check_equals(tf.multiline, true);
361
377
tf.multiline = false;
379
//-------------------------------------------------------------------------
363
380
// Check TextField._name
381
//-------------------------------------------------------------------------
365
383
check_equals(typeof(tf._name), 'string');
366
384
check(!tf.hasOwnProperty('_name'));
377
395
check_equals(typeof(tfref), 'object');
378
396
// TODO: see effects of unloading the textfield ?
398
//-------------------------------------------------------------------------
380
399
// Check TextField._parent
400
//-------------------------------------------------------------------------
382
xcheck_equals(typeof(tf._parent), 'movieclip');
402
check_equals(typeof(tf._parent), 'movieclip');
383
403
check(!tf.hasOwnProperty('_parent'));
384
check(!tf.__proto__.hasOwnProperty('_parent'));
385
xcheck_equals(tf._parent, _root);
404
xcheck(!tf.__proto__.hasOwnProperty('_parent'));
405
check_equals(tf._parent, _root);
408
xcheck_equals(tf._parent, 23); // can be overridden !
409
check_equals(tf._target, "/tf"); // but won't change _target
410
r = delete tf._parent;
412
r = delete tf._parent;
414
TextField.prototype._parent = "from proto";
415
check_equals(tf._parent, _root); // still unchanged
416
delete TextField.prototype._parent;
419
//-------------------------------------------------------------------------
387
420
// Check TextField.password
421
//-------------------------------------------------------------------------
389
423
xcheck_equals(typeof(tf.password), 'boolean');
390
424
check(!tf.hasOwnProperty('password'));
477
511
check_equals(tf.tabIndex, 9);
478
512
delete(tf.tabIndex);
514
//-------------------------------------------------------------------------
480
515
// Check TextField._target
516
//-------------------------------------------------------------------------
482
518
check_equals(typeof(tf._target), 'string');
483
519
check( ! tf.hasOwnProperty('_target') );
494
530
check_equals(tf.text, 'Hello World');
495
531
tf.text = "hello world";
496
532
check_equals(tf.text, 'hello world');
497
xcheck_equals(tf.length, 11); // number of characters in "hello world"
533
check_equals(tf.length, 11); // number of characters in "hello world"
500
536
// Check TextField.textColor
509
545
// Check TextField.textHeight (height of the bounding box)
511
xcheck_equals(typeof(tf.textHeight), 'number');
547
check_equals(typeof(tf.textHeight), 'number');
512
548
check( ! tf.hasOwnProperty('textHeight') );
513
549
currentHeight = tf.textHeight; // WARNING: this might depend on the default font height
514
550
tf.textHeight = 1000;
515
xcheck_equals(tf.textHeight, currentHeight); // was read-only (I think)
551
check_equals(tf.textHeight, currentHeight); // was read-only (I think)
517
553
// Check TextField.textWidth (width of the bounding box)
656
692
check_equals(tf._width, 500); // as it was set by createTextField, see above
657
693
tf._width = 99999;
658
694
check_equals(tf._width, 99999);
695
b = tf.getBounds(_root); bs = printBounds(b);
696
check_equals(bs, 'xmin:10 ymin:10 xmax:100009 ymax:510');
698
tf.text = 'small'; // doesn't reset bounds (being autoSize false);
699
check_equals(tf._width, 99999);
700
b = tf.getBounds(_root); bs = printBounds(b);
701
check_equals(bs, 'xmin:10 ymin:10 xmax:100009 ymax:510');
703
tf.autoSize = true; // changes width !!
704
check(tf._width < 99999);
707
tf.autoSize = false; // doesn't reset to last manually set one
708
check_equals(tf._width, ow);
661
712
//-------------------------------------------------------------------------
682
733
// Check TextField._xmouse
683
734
//-------------------------------------------------------------------------
685
xcheck_equals(typeof(tf._xmouse), 'number');
736
check_equals(typeof(tf._xmouse), 'number');
686
737
check( ! tf.hasOwnProperty('_xmouse') );
687
check( ! tf.__proto__.hasOwnProperty('_xmouse') );
738
xcheck( ! tf.__proto__.hasOwnProperty('_xmouse') );
688
739
currXmouse = tf._xmouse; // unsafe, if user moves the mouse while running the test
689
740
tf._xmouse = "a string";
690
xcheck_equals(typeof(tf._xmouse), 'number');
691
xcheck_equals(tf._xmouse, currXmouse); // possibly unsafe, if user moves the mouse while running the test
741
check_equals(typeof(tf._xmouse), 'number');
742
check_equals(tf._xmouse, currXmouse); // possibly unsafe, if user moves the mouse while running the test
693
744
//-------------------------------------------------------------------------
694
745
// Check TextField._xscale
695
746
//-------------------------------------------------------------------------
697
xcheck_equals(typeof(tf._xscale), 'number');
748
check_equals(typeof(tf._xscale), 'number');
698
749
check( ! tf.hasOwnProperty('_xscale') );
699
check( ! tf.__proto__.hasOwnProperty('_xscale') );
700
xcheck_equals(tf._xscale, 100);
750
xcheck( ! tf.__proto__.hasOwnProperty('_xscale') );
751
check_equals(tf._xscale, 100);
701
752
// check how .textWidth and ._width change when changing _xscale
702
753
currTextWidth = tf.textWidth;
703
754
currWidth = tf._width;
722
773
// Check TextField._ymouse
723
774
//-------------------------------------------------------------------------
725
xcheck_equals(typeof(tf._ymouse), 'number');
776
check_equals(typeof(tf._ymouse), 'number');
726
777
check( ! tf.hasOwnProperty('_ymouse') );
727
check( ! tf.__proto__.hasOwnProperty('_ymouse') );
778
xcheck( ! tf.__proto__.hasOwnProperty('_ymouse') );
728
779
currYmouse = tf._ymouse;
729
780
tf._ymouse = "a string";
730
xcheck_equals(typeof(tf._ymouse), 'number');
731
xcheck_equals(tf._ymouse, currYmouse); // possibly unsafe, if user moves the mouse while running the test
781
check_equals(typeof(tf._ymouse), 'number');
782
check_equals(tf._ymouse, currYmouse); // possibly unsafe, if user moves the mouse while running the test
733
784
//-------------------------------------------------------------------------
734
785
// Check TextField._yscale
735
786
//-------------------------------------------------------------------------
737
xcheck_equals(typeof(tf._yscale), 'number');
788
check_equals(typeof(tf._yscale), 'number');
738
789
check( ! tf.hasOwnProperty('_yscale') );
739
check( ! tf.__proto__.hasOwnProperty('_yscale') );
740
xcheck_equals(tf._yscale, 100);
790
xcheck( ! tf.__proto__.hasOwnProperty('_yscale') );
791
check_equals(tf._yscale, 100);
741
792
// check how .textHeight and ._height change based on _yscale
742
793
currTextHeight = tf.textHeight;
743
794
currHeight = tf._height;
748
799
tf._yscale = 100;
750
801
//-------------------------------------------------------------------------
751
// Check interaction between autoSize and _width
802
// Check interaction between autoSize and _width and wordWrap
752
803
//-------------------------------------------------------------------------
754
805
tf._width = 10; // "hello world" text should overflow this
762
813
check_equals(tf.textWidth, origTextWidth); // textWidth isn't influenced by autoSize
763
814
tf.autoSize = 'none';
764
815
tf.wordWrap = true;
765
note("textWidth: "+tf.textWidth+" origTextWidth:"+origTextWidth);
816
note("After setting wordWrap flat: textWidth: "+tf.textWidth+" origTextWidth:"+origTextWidth);
766
817
check_equals(tf.textWidth, origTextWidth);
819
note("After reducing _width: textWidth: "+tf.textWidth+" origTextWidth:"+origTextWidth);
768
820
check_equals(tf._width, 10);
770
822
#if OUTPUT_VERSION < 8
771
xcheck_equals(origTextWidth, tf.textWidth); // textWidth isn't influenced by wordWrap
823
xcheck_equals(origTextWidth, tf.textWidth);
773
825
check(origTextWidth > tf.textWidth);
781
833
tf.text = "single line\n";
782
834
check_equals(tf._width, linewidth);
836
// Test that setting autoSize = none
837
// doesn't reset the bounding box.
840
oldwidth = tf._width;
841
note("width: "+oldwidth);
842
check(oldwidth>0); // or the test is invalid
843
tf.autoSize = 'none'; // tf was created with bounds 0,0
844
check_equals(tf._width, oldwidth); // but _width didn't change to that
846
// Test that when autoSize != none,
847
// and wordWrap is true, text box isn't
851
check_equals(tf._width, oldwidth); // text takes more width with wordWrap false
852
note("width on wordWrap="+tf.wordWrap+" autoSize="+tf.autoSize+": "+tf._width);
853
tf.autoSize = 'center';
854
note("width on wordWrap="+tf.wordWrap+" autoSize="+tf.autoSize+": "+tf._width);
855
check(tf._width > oldwidth);
856
oldwidth = tf._width;
858
note("width on wordWrap="+tf.wordWrap+" autoSize="+tf.autoSize+": "+tf._width);
859
check_equals(tf._width, oldwidth); // wordWrap change didn't reset the bbox
785
862
//------------------------------------------------------------
786
863
// Test insane calls
824
901
createTextField("tf6", 103, 10, 10, 160);
825
902
check_equals(typeof(tf6), 'undefined');
904
//------------------------------------------------------------
906
//------------------------------------------------------------
908
_root._visible = true; // just to be sure
909
_root._xscale = _root._yscale = 100;
910
_root.createTextField('htf',0,0,0,0,0);
911
check_equals(typeof(htf), 'object');
919
_parent='fake_parent';
924
check_equals(_root._x, 0);
925
check_equals(_root._y, 0);
926
check_equals(_root._visible, true);
927
check_equals(_root._xscale, 100);
928
check_equals(_root._yscale, 100);
929
check_equals(_root._target, '/');
930
xcheck_equals(_root._parent, 'fake_parent');
931
check_equals(_root._name, '');
933
check_equals(tf._x, 10);
934
check_equals(tf._y, 11);
935
check_equals(tf._visible, false);
936
check_equals(tf._xscale, 200);
937
check_equals(tf._yscale, 201);
938
check_equals(tf._target, '/fake_name');
939
check_equals(tf._parent, _level0);
940
check_equals(tf._name, 'fake_name');
942
_root._visible = true;
943
_root._x = _root._y = 0;
944
_root._xscale = _root._yscale = 100;
947
//------------------------------------------------------------
949
//------------------------------------------------------------
829
951
#if OUTPUT_VERSION < 8
835
957
#else // OUTPUT_VERSION <= 5