[CSS Regions] Helper functions for selection layout tests
authorrego@igalia.com <rego@igalia.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 2 Oct 2013 23:29:12 +0000 (23:29 +0000)
committerrego@igalia.com <rego@igalia.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 2 Oct 2013 23:29:12 +0000 (23:29 +0000)
https://bugs.webkit.org/show_bug.cgi?id=122128

Reviewed by Alexandru Chiculita.

Create new common JavaScript methods for CSS Regions layout tests
related to selection. Refactored tests in order to use them.

* fast/regions/resources/helper.js: Added new functions.
(selectContentByRange): Select from start to end position.
(selectContentByIds): Select from the beginning of the first element to the end
of the second one.
(selectBaseAndExtent): Select from start to end with given offsets using
Selection.setBaseAndExtent() method.
(mouseClick): Clicks in a given position.
* fast/regions/selection/selecting-text-in-empty-region.html: Refactored
test in order to use the new functions.
* fast/regions/selection/selecting-text-through-different-region-flows-2-expected.html:
Ditto.
* fast/regions/selection/selecting-text-through-different-region-flows-2.html:
Ditto.
* fast/regions/selection/selecting-text-through-different-region-flows.html:
Ditto.
* fast/regions/selection/selection-direction-expected.html: Ditto.
* fast/regions/selection/selection-direction.html: Ditto.

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@156807 268f45cc-cd09-0410-ab3c-d52691b4dbfc

LayoutTests/ChangeLog
LayoutTests/fast/regions/resources/helper.js
LayoutTests/fast/regions/selection/selecting-text-in-empty-region.html
LayoutTests/fast/regions/selection/selecting-text-through-different-region-flows-2-expected.html
LayoutTests/fast/regions/selection/selecting-text-through-different-region-flows-2.html
LayoutTests/fast/regions/selection/selecting-text-through-different-region-flows.html
LayoutTests/fast/regions/selection/selection-direction-expected.html
LayoutTests/fast/regions/selection/selection-direction.html

index 2a33dce..abf3d41 100644 (file)
@@ -1,3 +1,31 @@
+2013-10-02  Manuel Rego Casasnovas  <rego@igalia.com>
+
+        [CSS Regions] Helper functions for selection layout tests
+        https://bugs.webkit.org/show_bug.cgi?id=122128
+
+        Reviewed by Alexandru Chiculita.
+
+        Create new common JavaScript methods for CSS Regions layout tests
+        related to selection. Refactored tests in order to use them.
+
+        * fast/regions/resources/helper.js: Added new functions.
+        (selectContentByRange): Select from start to end position.
+        (selectContentByIds): Select from the beginning of the first element to the end
+        of the second one.
+        (selectBaseAndExtent): Select from start to end with given offsets using
+        Selection.setBaseAndExtent() method.
+        (mouseClick): Clicks in a given position.
+        * fast/regions/selection/selecting-text-in-empty-region.html: Refactored
+        test in order to use the new functions.
+        * fast/regions/selection/selecting-text-through-different-region-flows-2-expected.html:
+        Ditto.
+        * fast/regions/selection/selecting-text-through-different-region-flows-2.html:
+        Ditto.
+        * fast/regions/selection/selecting-text-through-different-region-flows.html:
+        Ditto.
+        * fast/regions/selection/selection-direction-expected.html: Ditto.
+        * fast/regions/selection/selection-direction.html: Ditto.
+
 2013-10-02  Bem Jones-Bey  <bjonesbe@adobe.com>
 
         [css-shapes] shape-outside does not properly handle the container and the float having different writing modes
index 4c290a8..6cf7d3f 100644 (file)
@@ -202,3 +202,41 @@ function compareArrays(current, expected) {
     }
     testPassed("Array ["  + expected.toString() + "] is equal to [" + current.toString() + "]");
 }
+
+function selectContentByRange(fromX, fromY, toX, toY) {
+    if (!window.testRunner)
+        return;
+
+    eventSender.mouseMoveTo(fromX, fromY);
+    eventSender.mouseDown();
+
+    eventSender.mouseMoveTo(toX, toY);
+    eventSender.mouseUp();
+}
+
+function selectContentByIds(fromId, toId) {
+    var fromRect = document.getElementById(fromId).getBoundingClientRect();
+    var toRect = document.getElementById(toId).getBoundingClientRect();
+
+    var fromRectVerticalCenter = fromRect.top + fromRect.height / 2;
+    var toRectVerticalCenter = toRect.top + toRect.height / 2;
+
+    selectContentByRange(fromRect.left, fromRectVerticalCenter, toRect.right, toRectVerticalCenter);
+}
+
+function selectBaseAndExtent(fromId, fromOffset, toId, toOffset) {
+    var from = document.getElementById(fromId);
+    var to = document.getElementById(toId);
+
+    var selection = window.getSelection();
+    selection.setBaseAndExtent(from, fromOffset, to, toOffset);
+}
+
+function mouseClick(positionX, positionY) {
+    if (!window.testRunner)
+        return;
+
+    eventSender.mouseMoveTo(positionX, positionY);
+    eventSender.mouseDown();
+    eventSender.mouseUp();
+}
index 760fc1a..675b47b 100644 (file)
@@ -1,6 +1,7 @@
 <!doctype html>
 <html>
     <head>
+        <script src="../resources/helper.js"></script>
         <style>
             body { font: 20px/1 monospace; margin: 20px; }
             #region { -webkit-flow-from: undefined; width: 100px; height: 100px; border: 10px solid blue; }
                 var endPositionX = startPositionX + 100;
                 var endPositionY = startPositionY + 100;
 
-                eventSender.mouseMoveTo(startPositionX, startPositionY);
-                eventSender.mouseDown();
-                eventSender.mouseMoveTo(endPositionX, endPositionY);
-                eventSender.mouseUp();
+                selectContentByRange(startPositionX, startPositionY, endPositionX, endPositionY);
 
                 document.getElementById("result").innerHTML = (selection.toString().length == 0) ? "PASS" : "FAIL";
             }
index b2aeb5e..700ac24 100644 (file)
@@ -1,23 +1,13 @@
 <!DOCTYPE html>
 <html>
 <head>
+<script src="../resources/helper.js"></script>
 <style>
 body { width: 600px; }
 #footNote { font-size: 13px; }
 </style>
-<script>
-function selectText()
-{
-  var selection = window.getSelection();
-
-  var start = document.getElementById("start");
-  var end = document.getElementById("end");
-
-  selection.setBaseAndExtent(start, 0, end, 0);
-}
-</script>
 </head>
-<body onload="selectText()">
+<body onload="selectBaseAndExtent('start', 0, 'end', 1)">
 <div id="content">
     <h1 style="margin-top: 0px">Selecting text through different CSS-Region flows</h1>
     <div>
index e283e02..9b083b2 100644 (file)
@@ -1,6 +1,7 @@
 <!DOCTYPE html>
 <html>
 <head>
+<script src="../resources/helper.js"></script>
 <style>
 body { width: 600px; }
 
@@ -30,21 +31,7 @@ body { width: 600px; }
 </div>
 
 <script>
-if (window.testRunner) {
-    // We are positioning the mouse to the center of the contentText and start holding the mouse down
-    var start = document.getElementById("start");
-    var xStartPosition = start.offsetLeft + 0;
-    var yStartPosition = start.offsetTop + start.offsetHeight / 2;
-    eventSender.mouseMoveTo(xStartPosition, yStartPosition);
-    eventSender.mouseDown();
-
-    // We are positioning the mouse to the center of the footNote (what is a different region flow) and release the button
-    var end = document.getElementById("end");
-    var xEndPosition = end.offsetLeft + 0;
-    var yEndPosition = end.offsetTop + end.offsetHeight / 2;
-    eventSender.mouseMoveTo(xEndPosition, yEndPosition);
-    eventSender.mouseUp();
-}
+selectContentByIds("start", "end");
 </script>
 </body>
 </html>
index 65f9a04..edb624d 100644 (file)
@@ -1,6 +1,7 @@
 <!DOCTYPE html>
 <html>
 <head>
+<script src="../resources/helper.js"></script>
 <style>
 body { width: 600px; }
 
@@ -46,9 +47,7 @@ if (window.testRunner) {
     eventSender.mouseUp();
 
     // We are moving the mouse somewhere else and click to clear the selection
-    eventSender.mouseMoveTo(1, 1);
-    eventSender.mouseDown();
-    eventSender.mouseUp();
+    mouseClick(1, 1);
 }
 </script>
 </body>
index 6375089..b18d682 100644 (file)
@@ -1,5 +1,6 @@
 <html>
 <head>
+    <script src="../resources/helper.js"></script>
     <style>
         #region {
             height: 100px;
             top: 200px;
         }
     </style>
-    <script>
-        function selectText() {
-            if (window.testRunner) {
-                eventSender.mouseMoveTo(100, 10);
-                eventSender.mouseDown();
-
-                eventSender.mouseMoveTo(100, 110);
-                eventSender.mouseUp();
-            }
-        }
-    </script>
 </head>
-<body onload="selectText();">
+<body onload="selectContentByRange(100, 10, 100, 110);">
     <div id="region">inside region inside region inside region inside region</div>
     <div id="outside">outside region outside region outside region outside region</div>
     <div id="description">
index e85b8fe..5c702d1 100644 (file)
@@ -1,5 +1,6 @@
 <html>
 <head>
+    <script src="../resources/helper.js"></script>
     <style>
         #source {
             -webkit-flow-into: content;
             width: 600px;
         }
     </style>
-    <script>
-        function selectText() {
-            if (window.testRunner) {
-                eventSender.mouseMoveTo(100, 10);
-                eventSender.mouseDown();
-
-                eventSender.mouseMoveTo(100, 110);
-                eventSender.mouseUp();
-            }
-        }
-    </script>
 </head>
-<body onload="selectText();">
+<body onload="selectContentByRange(100, 10, 100, 110);">
     <div id="source">inside region inside region inside region inside region</div>
     <div id="outside">outside region outside region outside region outside region</div>
     <div id="region"></div>