tizen beta release
[framework/web/webkit-efl.git] / LayoutTests / fast / html / set-text-direction.html
1 <!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN">
2 <html>
3 <head>
4 <script src="../../fast/js/resources/js-test-pre.js"></script>
5 </head>
6 <body>
7 <script language="javascript" type="text/javascript">
8 description('Test that WebKit changes the dir attribute and sends an input event when we change the text direction.');
9
10 // The string used for storing the expected text direction when we receive an input event.
11 var expected = '';
12 var sentInputEvent = false;
13
14 function removeChildAndForceGC(child) {
15     document.body.removeChild(child);
16     gc();
17 }
18
19 // Create a textarea element and an input element. These elements are used for
20 // changing their text direction with Editor::setBaseWritingDirection() calls.
21 var textarea = document.createElement('textarea');
22 textarea.rows = 10;
23 textarea.cols = 10;
24 textarea.oninput = function() {
25     shouldBe('expected', 'textarea.dir');
26     sentInputEvent = true;
27
28     // When we change the direction to ltr, we remove this element to verify WebKit
29     // continue running without crashes.
30     if (expected == 'ltr')
31         removeChildAndForceGC(textarea);
32 }
33 document.body.appendChild(textarea);
34
35 var input = document.createElement('input');
36 input.type = 'text';
37 input.oninput = function() {
38     shouldBe('expected', 'input.dir');
39     sentInputEvent = true;
40
41     // When we change the direction to ltr, we remove this element to verify WebKit
42     // continue running without crashes.
43     if (expected == 'ltr')
44         removeChildAndForceGC(input);
45 }
46 document.body.appendChild(input);
47
48 // Change the text direction of the textarea element to RTL.
49 expected = 'rtl';
50 sentInputEvent = false;
51 textarea.focus();
52 layoutTestController.setTextDirection('rtl');
53 shouldBeTrue('sentInputEvent');
54
55 // Change the text direction of the textarea element to LTR.
56 // This also removes the element to verify WebKit works without crashes.
57 expected = 'ltr';
58 sentInputEvent = false;
59 textarea.focus();
60 layoutTestController.setTextDirection('ltr');
61 shouldBeTrue('sentInputEvent');
62
63 // Change the text direction of the input element to RTL.
64 expected = 'rtl';
65 sentInputEvent = false;
66 input.focus();
67 layoutTestController.setTextDirection('rtl');
68 shouldBeTrue('sentInputEvent');
69
70 // Change the text direction of the input element to LTR.
71 // This also removes the element to verify WebKit works without crashes.
72 expected = 'ltr';
73 sentInputEvent = false;
74 input.focus();
75 layoutTestController.setTextDirection('ltr');
76 shouldBeTrue('sentInputEvent');
77 </script>
78 <script src="../../fast/js/resources/js-test-post.js"></script>
79 </body>
80 </html>