Source/WebKit/chromium: Fix crash by handling case when AccessibilityObject::lineForP...
authordmazzoni@google.com <dmazzoni@google.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 9 Nov 2011 23:28:12 +0000 (23:28 +0000)
committerdmazzoni@google.com <dmazzoni@google.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 9 Nov 2011 23:28:12 +0000 (23:28 +0000)
returns -1.
https://bugs.webkit.org/show_bug.cgi?id=71561

Adds layout test: platform/chromium/accessibility/insertion-point-line-number-on-password-crashes.html

Reviewed by Dimitri Glazkov.

* src/WebAccessibilityObject.cpp:
(WebKit::WebAccessibilityObject::lineBreaks):

Tools: [Chromium] Implement AccessibilityUIElement::insertionPointLineNumberGetterCallback
https://bugs.webkit.org/show_bug.cgi?id=71561

Reviewed by Dimitri Glazkov.

* DumpRenderTree/chromium/AccessibilityUIElement.cpp:
(AccessibilityUIElement::insertionPointLineNumberGetterCallback):

LayoutTests: [Chromium] Add new test for crash in WebAccessibilityObject::lineBreaks
https://bugs.webkit.org/show_bug.cgi?id=71561

Reviewed by Dimitri Glazkov.

* platform/chromium/accessibility/insertion-point-line-number-on-password-crashes-expected.txt: Added.
* platform/chromium/accessibility/insertion-point-line-number-on-password-crashes.html: Added.

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

LayoutTests/ChangeLog
LayoutTests/platform/chromium/accessibility/insertion-point-line-number-on-password-crashes-expected.txt [new file with mode: 0644]
LayoutTests/platform/chromium/accessibility/insertion-point-line-number-on-password-crashes.html [new file with mode: 0644]
Source/WebKit/chromium/ChangeLog
Source/WebKit/chromium/src/WebAccessibilityObject.cpp
Tools/ChangeLog
Tools/DumpRenderTree/chromium/AccessibilityUIElement.cpp

index 0e61ded..2ee0521 100644 (file)
@@ -1,3 +1,13 @@
+2011-11-09  Dominic Mazzoni  <dmazzoni@google.com>
+
+        [Chromium] Add new test for crash in WebAccessibilityObject::lineBreaks
+        https://bugs.webkit.org/show_bug.cgi?id=71561
+
+        Reviewed by Dimitri Glazkov.
+
+        * platform/chromium/accessibility/insertion-point-line-number-on-password-crashes-expected.txt: Added.
+        * platform/chromium/accessibility/insertion-point-line-number-on-password-crashes.html: Added.
+
 2011-11-09  Benjamin Poulain  <bpoulain@apple.com>
 
         Implement dumpProgressFinishedCallback() for Mac layoutTestController
diff --git a/LayoutTests/platform/chromium/accessibility/insertion-point-line-number-on-password-crashes-expected.txt b/LayoutTests/platform/chromium/accessibility/insertion-point-line-number-on-password-crashes-expected.txt
new file mode 100644 (file)
index 0000000..7666613
--- /dev/null
@@ -0,0 +1,2 @@
+Line number for password element: 0
+
diff --git a/LayoutTests/platform/chromium/accessibility/insertion-point-line-number-on-password-crashes.html b/LayoutTests/platform/chromium/accessibility/insertion-point-line-number-on-password-crashes.html
new file mode 100644 (file)
index 0000000..6b7581c
--- /dev/null
@@ -0,0 +1,25 @@
+<html>
+<script>
+    if (window.layoutTestController)
+        layoutTestController.dumpAsText();
+</script>
+<body>
+
+    <div id="result"></div>
+
+    <input type="password" id="password">
+
+    <script>
+        if (window.accessibilityController) {
+            var result = document.getElementById("result");
+
+            var password = document.getElementById("password");
+            password.focus();
+
+            // Make sure this doesn't crash.
+            lineNumber = accessibilityController.focusedElement.insertionPointLineNumber;
+            result.innerText += "Line number for password element: " + lineNumber + "\n";
+        }
+    </script>
+</body>
+</html>
index a735e69..85f7d8d 100644 (file)
@@ -1,3 +1,16 @@
+2011-11-09  Dominic Mazzoni  <dmazzoni@google.com>
+
+        Fix crash by handling case when AccessibilityObject::lineForPosition
+        returns -1.
+        https://bugs.webkit.org/show_bug.cgi?id=71561
+
+        Adds layout test: platform/chromium/accessibility/insertion-point-line-number-on-password-crashes.html
+
+        Reviewed by Dimitri Glazkov.
+
+        * src/WebAccessibilityObject.cpp:
+        (WebKit::WebAccessibilityObject::lineBreaks):
+
 2011-11-09  Jay Civelli  <jcivelli@chromium.org>
 
         Fix MHTML generation to use the QuotedPrintable encoding for text resources.
index 417d2f9..8df900a 100644 (file)
@@ -771,7 +771,7 @@ bool WebAccessibilityObject::lineBreaks(WebVector<int>& result) const
 
     VisiblePosition pos = m_private->visiblePositionForIndex(textLength);
     int lineBreakCount = m_private->lineForPosition(pos);
-    if (!lineBreakCount)
+    if (lineBreakCount <= 0)
         return false;
 
     WebVector<int> lineBreaks(static_cast<size_t>(lineBreakCount));
index 3aefaa5..ca2bd90 100644 (file)
@@ -1,3 +1,13 @@
+2011-11-09  Dominic Mazzoni  <dmazzoni@google.com>
+
+        [Chromium] Implement AccessibilityUIElement::insertionPointLineNumberGetterCallback
+        https://bugs.webkit.org/show_bug.cgi?id=71561
+
+        Reviewed by Dimitri Glazkov.
+
+        * DumpRenderTree/chromium/AccessibilityUIElement.cpp:
+        (AccessibilityUIElement::insertionPointLineNumberGetterCallback):
+
 2011-11-09  Benjamin Poulain  <bpoulain@apple.com>
 
         Implement dumpProgressFinishedCallback() for Mac layoutTestController
index d7b95b1..f1332fb 100644 (file)
@@ -453,8 +453,13 @@ void AccessibilityUIElement::childrenCountGetterCallback(CppVariant* result)
 
 void AccessibilityUIElement::insertionPointLineNumberGetterCallback(CppVariant* result)
 {
-    // FIXME: Implement this.
-    result->set(0);
+    WebVector<int> lineBreaks;
+    accessibilityObject().lineBreaks(lineBreaks);
+    int cursor = accessibilityObject().selectionEnd();
+    int line = 0;
+    while (line < static_cast<int>(lineBreaks.size()) && lineBreaks[line] <= cursor)
+        line++;
+    result->set(line);
 }
 
 void AccessibilityUIElement::selectedTextRangeGetterCallback(CppVariant* result)