2009-01-12 Eric Roman <eroman@chromium.org>
[WebKit-https.git] / LayoutTests / editing / selection / doubleclick-whitespace.html
index 0d4dcdc..a6ac152 100644 (file)
@@ -6,33 +6,109 @@ if (window.layoutTestController) {
      layoutTestController.setSmartInsertDeleteEnabled(false);
      layoutTestController.setSelectTrailingWhitespaceEnabled(true);
 }
+
+function getPositionOfNode(id)
+{
+    var n = document.getElementById(id);
+    var pos = {x: 0, y: 0};
+
+    while (n) {
+        pos.x += n.offsetLeft + n.clientLeft;
+        pos.y += n.offsetTop + n.clientTop;
+        n = n.offsetParent;
+    }
+    return pos;
+}
+
+function doubleClickNode(id)
+{
+    var pos = getPositionOfNode(id);
+    eventSender.mouseMoveTo(pos.x + 2, pos.y + 2);
+    eventSender.mouseDown();
+    eventSender.leapForward(1);
+    eventSender.mouseUp();
+    eventSender.leapForward(100);
+    eventSender.mouseDown();
+    eventSender.leapForward(1);
+    eventSender.mouseUp();
+}
+
+function doTest(testId, expectedText)
+{
+    // Simulate a double click.
+    doubleClickNode(testId);
+
+    // Get the text of the current selection.
+    var sel = window.getSelection();
+    var actualText = sel.getRangeAt(0).toString();
+
+    if (expectedText == actualText) {
+        log("Passed " + testId);
+    } else {
+        log("Failed " + testId);
+        log("  Expected: " + expectedText);
+        log("  Actual: " + actualText);
+    }
+
+}
+
+function runTests()
+{
+    if (window.layoutTestController) {
+        doTest("test1", "Doubleclickme \u00a0\u00a0\u00a0 ");
+        doTest("test2", "Doubleclickme");
+        doTest("test3", "Doubleclickme \u00a0\u00a0 ");
+        doTest("test4", "Doubleclickme");
+        doTest("test5", "Doubleclickme  \u00a0\u00a0");
+        doTest("test6", "Doubleclickme  \u00a0\t\t\t\u00a0");
+    }
+}
+
+function log(msg)
+{
+    var l = document.getElementById('log');
+    l.appendChild(document.createTextNode(msg));
+    l.appendChild(document.createElement('br'));
+}
+
 </script>
-<style>
-body { margin: 0; padding: 0 }
-</style>
 </head>
-<body>
-<pre>
-This tests that double-clicking a word on the Windows platform selects the whitespace after the word.  You should see the word "PASS" below.
+<body onload="runTests()">
 <p>
-<script type="text/javascript">
-    if (window.layoutTestController) {
-        eventSender.mouseMoveTo(20, 10);
-        eventSender.mouseDown();
-        eventSender.leapForward(1);
-        eventSender.mouseUp();
-        eventSender.leapForward(100);
-        eventSender.mouseDown();
-        eventSender.leapForward(1);
-        eventSender.mouseUp();
-        var sel = window.getSelection();
-        var range = sel.getRangeAt(0);
-        if (range.toString() != "This ")
-            document.write("FAIL");
-        else
-            document.write("PASS");
-    } else
-        document.write("This test is only expected to pass when run in automated mode, with access to LayoutTestController.");
-</script>
+This tests that double-clicking a word on the Windows platform selects the whitespace after the word.
+</p>
+
+<div>
+<span id=test1>Doubleclickme &nbsp;&nbsp;&nbsp; |END|</span>
+</div>
+
+<div>
+<span id=test2>Doubleclickme|END|</span>
+</div>
+
+<div>
+<span id=test3>Doubleclickme</span> &nbsp;&nbsp; 
+|END|</span>
+</div>
+
+<div>
+<div>
+<span id="test4">Doubleclickme</span>
+</div>
+&nbsp;&nbsp;&nbsp;|(Should not have been extended into this line)|
+</div>
+
+<div>
+<span id="test5">Doubleclickme </span> &nbsp;&nbsp;<img src="does-not-exist.png" />&nbsp; &nbsp;
+</div>
+
+<pre>
+<span id="test6">Doubleclickme </span> &nbsp;                  &nbsp;|END|
+</pre>
+
+<br/>
+<pre id=log>
+</pre>
+
 </body>
 </html>