Upstream version 9.38.198.0
[platform/framework/web/crosswalk.git] / src / third_party / WebKit / LayoutTests / inspector / editor / text-editor-home-button.html
1 <html>
2 <head>
3 <script src="../../http/tests/inspector/inspector-test.js"></script>
4 <script src="editor-test.js"></script>
5 <script>
6
7 function test()
8 {
9 function foo()
10 {
11     return 42;
12 }
13     var textEditor = InspectorTest.createTestEditor();
14     textEditor.setMimeType("text/javascript");
15     textEditor.setReadOnly(false);
16     textEditor.element.focus();
17
18     textEditor.setText(foo.toString());
19
20     InspectorTest.addResult(textEditor.text());
21
22     function homeButton(shift, callback)
23     {
24         var key = WebInspector.isMac() ? "leftArrow" : "home";
25         var modifiers = WebInspector.isMac() ? ["metaKey"] : [];
26         if (shift)
27             modifiers.push("shiftKey");
28         InspectorTest.fakeKeyEvent(textEditor, key, modifiers, callback);
29     }
30
31     function hitHomeButton(shift, times, callback)
32     {
33         function hitButtonCallback()
34         {
35             --times;
36             InspectorTest.dumpTextWithSelection(textEditor);
37             if (times > 0) {
38                 homeButton(shift, hitButtonCallback);
39                 return;
40             }
41             callback();
42         }
43         homeButton(shift, hitButtonCallback);
44     }
45
46     InspectorTest.runTestSuite([
47         function testFirstNonBlankCharacter(next)
48         {
49             var selection = WebInspector.TextRange.createFromLocation(2, 8);
50             textEditor.setSelection(selection);
51             InspectorTest.dumpTextWithSelection(textEditor);
52             hitHomeButton(false, 1, next);
53         },
54
55         function testFirstNonBlankCharacterFromWhitespace(next)
56         {
57             var selection = WebInspector.TextRange.createFromLocation(2, 2);
58             textEditor.setSelection(selection);
59             InspectorTest.dumpTextWithSelection(textEditor);
60             hitHomeButton(false, 1, next);
61         },
62
63         function testHomeButtonToggling(next)
64         {
65             var selection = WebInspector.TextRange.createFromLocation(2, 2);
66             textEditor.setSelection(selection);
67             InspectorTest.dumpTextWithSelection(textEditor);
68             hitHomeButton(false, 3, next);
69         },
70
71         function testHomeButtonDoesNotChangeCursor(next)
72         {
73             var selection = WebInspector.TextRange.createFromLocation(0, 2);
74             textEditor.setSelection(selection);
75             InspectorTest.dumpTextWithSelection(textEditor);
76             hitHomeButton(false, 2, next);
77         },
78
79         function testHomeButtonWithShift(next)
80         {
81             var selection = new WebInspector.TextRange(0, 0, 2, 8);
82             textEditor.setSelection(selection);
83             InspectorTest.dumpTextWithSelection(textEditor);
84             hitHomeButton(true, 3, next);
85         },
86
87         function testHomeButtonWithShiftInversed(next)
88         {
89             var selection = new WebInspector.TextRange(3, 1, 2, 8);
90             textEditor.setSelection(selection);
91             InspectorTest.dumpTextWithSelection(textEditor);
92             hitHomeButton(true, 3, next);
93         }
94     ]);
95 }
96
97 </script>
98 </head>
99
100 <body onload="runTest();">
101 <p>
102 This test verifies that home button triggers selection between first symbol of the line
103 and first non-blank symbol of the line.
104 </p>
105
106 </body>
107 </html>