Upstream version 9.38.198.0
[platform/framework/web/crosswalk.git] / src / third_party / WebKit / LayoutTests / inspector / editor / text-editor-home-button.html
index 0eb818c..69e0c4c 100644 (file)
@@ -19,18 +19,28 @@ function foo()
 
     InspectorTest.addResult(textEditor.text());
 
-    function dumpTextEditorWithSelection()
-    {
-        InspectorTest.addResult(InspectorTest.textWithSelection(textEditor.text(), textEditor.selection()));
-    }
-
-    function homeButton(shift)
+    function homeButton(shift, callback)
     {
         var key = WebInspector.isMac() ? "leftArrow" : "home";
         var modifiers = WebInspector.isMac() ? ["metaKey"] : [];
         if (shift)
             modifiers.push("shiftKey");
-        eventSender.keyDown(key, modifiers);
+        InspectorTest.fakeKeyEvent(textEditor, key, modifiers, callback);
+    }
+
+    function hitHomeButton(shift, times, callback)
+    {
+        function hitButtonCallback()
+        {
+            --times;
+            InspectorTest.dumpTextWithSelection(textEditor);
+            if (times > 0) {
+                homeButton(shift, hitButtonCallback);
+                return;
+            }
+            callback();
+        }
+        homeButton(shift, hitButtonCallback);
     }
 
     InspectorTest.runTestSuite([
@@ -38,74 +48,48 @@ function foo()
         {
             var selection = WebInspector.TextRange.createFromLocation(2, 8);
             textEditor.setSelection(selection);
-            dumpTextEditorWithSelection();
-            homeButton(false);
-            dumpTextEditorWithSelection();
-            next();
+            InspectorTest.dumpTextWithSelection(textEditor);
+            hitHomeButton(false, 1, next);
         },
 
         function testFirstNonBlankCharacterFromWhitespace(next)
         {
             var selection = WebInspector.TextRange.createFromLocation(2, 2);
             textEditor.setSelection(selection);
-            dumpTextEditorWithSelection();
-            homeButton(false);
-            dumpTextEditorWithSelection();
-            next();
+            InspectorTest.dumpTextWithSelection(textEditor);
+            hitHomeButton(false, 1, next);
         },
 
         function testHomeButtonToggling(next)
         {
             var selection = WebInspector.TextRange.createFromLocation(2, 2);
             textEditor.setSelection(selection);
-            dumpTextEditorWithSelection();
-            homeButton(false);
-            dumpTextEditorWithSelection();
-            homeButton(false);
-            dumpTextEditorWithSelection();
-            homeButton(false);
-            dumpTextEditorWithSelection();
-            next();
+            InspectorTest.dumpTextWithSelection(textEditor);
+            hitHomeButton(false, 3, next);
         },
 
         function testHomeButtonDoesNotChangeCursor(next)
         {
             var selection = WebInspector.TextRange.createFromLocation(0, 2);
             textEditor.setSelection(selection);
-            dumpTextEditorWithSelection();
-            homeButton(false);
-            dumpTextEditorWithSelection();
-            homeButton(false);
-            dumpTextEditorWithSelection();
-            next();
+            InspectorTest.dumpTextWithSelection(textEditor);
+            hitHomeButton(false, 2, next);
         },
 
         function testHomeButtonWithShift(next)
         {
             var selection = new WebInspector.TextRange(0, 0, 2, 8);
             textEditor.setSelection(selection);
-            dumpTextEditorWithSelection();
-            homeButton(true);
-            dumpTextEditorWithSelection();
-            homeButton(true);
-            dumpTextEditorWithSelection();
-            homeButton(true);
-            dumpTextEditorWithSelection();
-            next();
+            InspectorTest.dumpTextWithSelection(textEditor);
+            hitHomeButton(true, 3, next);
         },
 
         function testHomeButtonWithShiftInversed(next)
         {
             var selection = new WebInspector.TextRange(3, 1, 2, 8);
             textEditor.setSelection(selection);
-            dumpTextEditorWithSelection();
-            homeButton(true);
-            dumpTextEditorWithSelection();
-            homeButton(true);
-            dumpTextEditorWithSelection();
-            homeButton(true);
-            dumpTextEditorWithSelection();
-            next();
+            InspectorTest.dumpTextWithSelection(textEditor);
+            hitHomeButton(true, 3, next);
         }
     ]);
 }