[GTK] Test /webkit/atk/getTextInParagraphAndBodyModerate fails
authormario@webkit.org <mario@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 10 Sep 2013 08:52:07 +0000 (08:52 +0000)
committermario@webkit.org <mario@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 10 Sep 2013 08:52:07 +0000 (08:52 +0000)
https://bugs.webkit.org/show_bug.cgi?id=105538

Reviewed by Chris Fleizach.

Source/WebCore:

Expose '\n' for linebreaks when they were explicitly set by the
author of the web content with a <br> tag.

Tests: accessibility/paragraph-with-linebreaks.html

* accessibility/AccessibilityNodeObject.cpp:
(WebCore::shouldAddSpaceBeforeAppendingNextElement): Helper
function to decide when to append spaces when building the text
under an element, considering line breaks.
(WebCore::AccessibilityNodeObject::textUnderElement): Use the
shouldAddSpaceBeforeAppendingNextElement() function here.
* accessibility/AccessibilityRenderObject.cpp:
(WebCore::AccessibilityRenderObject::textUnderElement): Return the
renderer's text for accessibility objects exposing <br> elements.
* html/parser/HTMLParserIdioms.h:
(WebCore::isHTMLSpaceButNotLineBreak): New helper function, useful
to be passed to other functions like simplifyWhiteSpace().

Tools:

Unskip passing test getTextInParagraphAndBodyModerate.

* Scripts/run-gtk-tests:
(TestRunner): Unskip pasing test.

LayoutTests:

Added new Layout test and platform specific expectations.

* platform/efl/accessibility/paragraph-with-linebreaks-expected.txt: Added.
* platform/gtk/accessibility/paragraph-with-linebreaks-expected.txt: Added.
* accessibility/paragraph-with-linebreaks.html: Added.

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

LayoutTests/ChangeLog
LayoutTests/accessibility/paragraph-with-linebreaks.html [new file with mode: 0644]
LayoutTests/platform/efl/accessibility/paragraph-with-linebreaks-expected.txt [new file with mode: 0644]
LayoutTests/platform/gtk/accessibility/paragraph-with-linebreaks-expected.txt [new file with mode: 0644]
Source/WebCore/ChangeLog
Source/WebCore/accessibility/AccessibilityNodeObject.cpp
Source/WebCore/accessibility/AccessibilityRenderObject.cpp
Source/WebCore/html/parser/HTMLParserIdioms.h
Tools/ChangeLog
Tools/Scripts/run-gtk-tests

index bd7c19a..19c6023 100644 (file)
@@ -1,3 +1,16 @@
+2013-09-10  Mario Sanchez Prada  <mario.prada@samsung.com>
+
+        [GTK] Test /webkit/atk/getTextInParagraphAndBodyModerate fails
+        https://bugs.webkit.org/show_bug.cgi?id=105538
+
+        Reviewed by Chris Fleizach.
+
+        Added new Layout test and platform specific expectations.
+
+        * platform/efl/accessibility/paragraph-with-linebreaks-expected.txt: Added.
+        * platform/gtk/accessibility/paragraph-with-linebreaks-expected.txt: Added.
+        * accessibility/paragraph-with-linebreaks.html: Added.
+
 2013-09-10  Arpita Bahuguna  <a.bah@samsung.com>
 
         When deleting editable content, typing style should be reset when moving into another node.
diff --git a/LayoutTests/accessibility/paragraph-with-linebreaks.html b/LayoutTests/accessibility/paragraph-with-linebreaks.html
new file mode 100644 (file)
index 0000000..78d740d
--- /dev/null
@@ -0,0 +1,48 @@
+<html>
+<head>
+<script src="../fast/js/resources/js-test-pre.js"></script>
+</head>
+<body>
+
+<p>
+  Lorem ipsum dolor sit amet,<br>
+  consectetur adipiscing elit.<br>
+  Aliquam faucibus diam sit amet nunc vestibulum auctor.
+</p>
+
+<p style="max-width:150px;">
+  Lorem ipsum dolor sit amet, consectetur adipiscing elit. Aliquam faucibus diam sit amet nunc vestibulum auctor.
+</p>
+
+<p id="description"></p>
+<div id="console"></div>
+
+<script>
+
+description("This test checks that linebreaks explicitly set by the author are properly exposed to ATs.");
+
+if (window.testRunner) {
+  testRunner.dumpAsText();
+
+  if (window.accessibilityController) {
+
+    document.body.focus();
+    var webArea = accessibilityController.focusedElement;
+
+    var brokenParagraph = webArea.childAtIndex(0);
+    debug("Role of the paragraph with break lines: " + brokenParagraph.role);
+    debug("Value of the paragraph with break lines: " + brokenParagraph.stringValue);
+    debug("<br>");
+
+    var wrappedParagraph = webArea.childAtIndex(1);
+    debug("Role of the paragraph with wrapped lines: " + wrappedParagraph.role);
+    debug("Value of the paragraph with wrapped lines: " + wrappedParagraph.stringValue);
+    debug("<br>");
+  }
+}
+</script>
+
+<script src="../fast/js/resources/js-test-post.js"></script>
+
+</body>
+</html>
diff --git a/LayoutTests/platform/efl/accessibility/paragraph-with-linebreaks-expected.txt b/LayoutTests/platform/efl/accessibility/paragraph-with-linebreaks-expected.txt
new file mode 100644 (file)
index 0000000..216b0bb
--- /dev/null
@@ -0,0 +1,23 @@
+Lorem ipsum dolor sit amet,
+consectetur adipiscing elit.
+Aliquam faucibus diam sit amet nunc vestibulum auctor.
+
+Lorem ipsum dolor sit amet, consectetur adipiscing elit. Aliquam faucibus diam sit amet nunc vestibulum auctor.
+
+This test checks that linebreaks explicitly set by the author are properly exposed to ATs.
+
+On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
+
+
+Role of the paragraph with break lines: AXRole: AXParagraph
+Value of the paragraph with break lines: AXValue: Lorem ipsum dolor sit amet,<\n>consectetur adipiscing elit.<\n>Aliquam faucibus diam sit amet nunc vestibulum auctor.
+
+
+Role of the paragraph with wrapped lines: AXRole: AXParagraph
+Value of the paragraph with wrapped lines: AXValue: Lorem ipsum dolor sit amet, consectetur adipiscing elit. Aliquam faucibus diam sit amet nunc vestibulum auctor.
+
+
+PASS successfullyParsed is true
+
+TEST COMPLETE
+
diff --git a/LayoutTests/platform/gtk/accessibility/paragraph-with-linebreaks-expected.txt b/LayoutTests/platform/gtk/accessibility/paragraph-with-linebreaks-expected.txt
new file mode 100644 (file)
index 0000000..216b0bb
--- /dev/null
@@ -0,0 +1,23 @@
+Lorem ipsum dolor sit amet,
+consectetur adipiscing elit.
+Aliquam faucibus diam sit amet nunc vestibulum auctor.
+
+Lorem ipsum dolor sit amet, consectetur adipiscing elit. Aliquam faucibus diam sit amet nunc vestibulum auctor.
+
+This test checks that linebreaks explicitly set by the author are properly exposed to ATs.
+
+On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
+
+
+Role of the paragraph with break lines: AXRole: AXParagraph
+Value of the paragraph with break lines: AXValue: Lorem ipsum dolor sit amet,<\n>consectetur adipiscing elit.<\n>Aliquam faucibus diam sit amet nunc vestibulum auctor.
+
+
+Role of the paragraph with wrapped lines: AXRole: AXParagraph
+Value of the paragraph with wrapped lines: AXValue: Lorem ipsum dolor sit amet, consectetur adipiscing elit. Aliquam faucibus diam sit amet nunc vestibulum auctor.
+
+
+PASS successfullyParsed is true
+
+TEST COMPLETE
+
index d83df6d..d142189 100644 (file)
@@ -1,3 +1,28 @@
+2013-09-10  Mario Sanchez Prada  <mario.prada@samsung.com>
+
+        [GTK] Test /webkit/atk/getTextInParagraphAndBodyModerate fails
+        https://bugs.webkit.org/show_bug.cgi?id=105538
+
+        Reviewed by Chris Fleizach.
+
+        Expose '\n' for linebreaks when they were explicitly set by the
+        author of the web content with a <br> tag.
+
+        Tests: accessibility/paragraph-with-linebreaks.html
+
+        * accessibility/AccessibilityNodeObject.cpp:
+        (WebCore::shouldAddSpaceBeforeAppendingNextElement): Helper
+        function to decide when to append spaces when building the text
+        under an element, considering line breaks.
+        (WebCore::AccessibilityNodeObject::textUnderElement): Use the
+        shouldAddSpaceBeforeAppendingNextElement() function here.
+        * accessibility/AccessibilityRenderObject.cpp:
+        (WebCore::AccessibilityRenderObject::textUnderElement): Return the
+        renderer's text for accessibility objects exposing <br> elements.
+        * html/parser/HTMLParserIdioms.h:
+        (WebCore::isHTMLSpaceButNotLineBreak): New helper function, useful
+        to be passed to other functions like simplifyWhiteSpace().
+
 2013-09-10  Arpita Bahuguna  <a.bah@samsung.com>
 
         When deleting editable content, typing style should be reset when moving into another node.
index 50c910f..96248d0 100644 (file)
@@ -54,6 +54,7 @@
 #include "HTMLOptGroupElement.h"
 #include "HTMLOptionElement.h"
 #include "HTMLOptionsCollection.h"
+#include "HTMLParserIdioms.h"
 #include "HTMLPlugInImageElement.h"
 #include "HTMLSelectElement.h"
 #include "HTMLTextAreaElement.h"
@@ -1542,6 +1543,15 @@ static bool shouldUseAccessiblityObjectInnerText(AccessibilityObject* obj, Acces
     return true;
 }
 
+static bool shouldAddSpaceBeforeAppendingNextElement(StringBuilder& builder, String& childText)
+{
+    if (!builder.length() || !childText.length())
+        return false;
+
+    // We don't need to add an additional space before or after a line break.
+    return !(isHTMLLineBreak(childText[0]) || isHTMLLineBreak(builder[builder.length() - 1]));
+}
+
 String AccessibilityNodeObject::textUnderElement(AccessibilityTextUnderElementMode mode) const
 {
     Node* node = this->node();
@@ -1557,7 +1567,7 @@ String AccessibilityNodeObject::textUnderElement(AccessibilityTextUnderElementMo
             Vector<AccessibilityText> textOrder;
             toAccessibilityNodeObject(child)->alternativeText(textOrder);
             if (textOrder.size() > 0 && textOrder[0].text.length()) {
-                if (builder.length())
+                if (shouldAddSpaceBeforeAppendingNextElement(builder, textOrder[0].text))
                     builder.append(' ');
                 builder.append(textOrder[0].text);
                 continue;
@@ -1566,13 +1576,13 @@ String AccessibilityNodeObject::textUnderElement(AccessibilityTextUnderElementMo
 
         String childText = child->textUnderElement(mode);
         if (childText.length()) {
-            if (builder.length())
+            if (shouldAddSpaceBeforeAppendingNextElement(builder, childText))
                 builder.append(' ');
             builder.append(childText);
         }
     }
 
-    return builder.toString().stripWhiteSpace().simplifyWhiteSpace();
+    return builder.toString().stripWhiteSpace().simplifyWhiteSpace(isHTMLSpaceButNotLineBreak);
 }
 
 String AccessibilityNodeObject::title() const
index a1848d1..757a50f 100644 (file)
@@ -65,6 +65,7 @@
 #include "NodeList.h"
 #include "Page.h"
 #include "ProgressTracker.h"
+#include "RenderBR.h"
 #include "RenderButton.h"
 #include "RenderFieldset.h"
 #include "RenderFileUploadControl.h"
@@ -630,6 +631,10 @@ String AccessibilityRenderObject::textUnderElement(AccessibilityTextUnderElement
     if (m_renderer->isFileUploadControl())
         return toRenderFileUploadControl(m_renderer)->buttonValue();
     
+    // Reflect when a content author has explicitly marked a line break.
+    if (m_renderer->isBR())
+        return toRenderBR(*m_renderer).text();
+
 #if ENABLE(MATHML)
     // Math operators create RenderText nodes on the fly that are not tied into the DOM in a reasonable way,
     // so rangeOfContents does not work for them (nor does regular text selection).
index 07af76c..8d9e43f 100644 (file)
@@ -38,6 +38,7 @@ class Decimal;
 bool isHTMLSpace(UChar);
 bool isHTMLLineBreak(UChar);
 bool isNotHTMLSpace(UChar);
+bool isHTMLSpaceButNotLineBreak(UChar character);
 
 // Strip leading and trailing whitespace as defined by the HTML specification. 
 String stripLeadingAndTrailingHTMLSpaces(const String&);
@@ -92,6 +93,11 @@ inline bool isNotHTMLSpace(UChar character)
     return !isHTMLSpace(character);
 }
 
+inline bool isHTMLSpaceButNotLineBreak(UChar character)
+{
+    return isHTMLSpace(character) && !isHTMLLineBreak(character);
+}
+
 bool threadSafeMatch(const QualifiedName&, const QualifiedName&);
 #if ENABLE(THREADED_HTML_PARSER)
 bool threadSafeMatch(const HTMLIdentifier&, const QualifiedName&);
index eaac4d9..2f641c8 100644 (file)
@@ -1,3 +1,15 @@
+2013-09-10  Mario Sanchez Prada  <mario.prada@samsung.com>
+
+        [GTK] Test /webkit/atk/getTextInParagraphAndBodyModerate fails
+        https://bugs.webkit.org/show_bug.cgi?id=105538
+
+        Reviewed by Chris Fleizach.
+
+        Unskip passing test getTextInParagraphAndBodyModerate.
+
+        * Scripts/run-gtk-tests:
+        (TestRunner): Unskip pasing test.
+
 2013-09-09  Mark Lam  <mark.lam@apple.com>
 
         Remove more references to the deleted js-test-style.css.
index 92184fd..e845c72 100755 (executable)
@@ -66,7 +66,6 @@ class TestRunner:
         SkippedTest("unittests/testwebresource", "/webkit/webresource/loading", "Test fails", 104689),
         SkippedTest("unittests/testwebresource", "/webkit/webresource/sub_resource_loading", "Test fails in GTK Linux 64-bit Release bot", 82330),
         SkippedTest("unittests/testwebview", "/webkit/webview/icon-uri", "Test times out in GTK Linux 64-bit Release bot", 82328),
-        SkippedTest("unittests/testatk", "/webkit/atk/getTextInParagraphAndBodyModerate", "Test fails", 105538),
         SkippedTest("WebKit2APITests/TestResources", "/webkit2/WebKitWebView/resources", "Test is flaky in GTK Linux 32-bit Release bot", 82868),
         SkippedTest("WebKit2APITests/TestWebKitWebView", SkippedTest.ENTIRE_SUITE, "Test times out after r150890", 117689),
         SkippedTest("WebKit2APITests/TestContextMenu", SkippedTest.ENTIRE_SUITE, "Test times out after r150890", 117689),