[GTK] accessibility/placeholder.html is failing
https://bugs.webkit.org/show_bug.cgi?id=98373

Patch by Joanmarie Diggs <jdiggs@igalia.com> on 2012-12-09
Reviewed by Martin Robinson.

The test was failing because the placeholder text was not supported and
AccessibilityUIElement::stringAttributeValue() was not implemented.

Source/WebCore:

No new tests; instead the failing test was unskipped.

* accessibility/atk/WebKitAccessibleWrapperAtk.cpp:
(webkitAccessibleGetAttributes): Add the placeholder text as an AtkAttribute
of the AtkObject, as is done in Gtk+ 3.

Tools:

* DumpRenderTree/gtk/AccessibilityUIElementGtk.cpp:
(coreAttributeToAtkAttribute): New convenience method to convert WebCore attribute
names into AtkObject attribute names
(AccessibilityUIElement::stringAttributeValue): implemented

LayoutTests:

* platform/gtk/TestExpectations: Unskip the failing test

git-svn-id: http://svn.webkit.org/repository/webkit/trunk@137099 268f45cc-cd09-0410-ab3c-d52691b4dbfc
diff --git a/LayoutTests/ChangeLog b/LayoutTests/ChangeLog
index 5004566..d2d5769 100644
--- a/LayoutTests/ChangeLog
+++ b/LayoutTests/ChangeLog
@@ -1,3 +1,15 @@
+2012-12-09  Joanmarie Diggs  <jdiggs@igalia.com>
+
+        [GTK] accessibility/placeholder.html is failing
+        https://bugs.webkit.org/show_bug.cgi?id=98373
+
+        Reviewed by Martin Robinson.
+
+        The test was failing because the placeholder text was not supported and
+        AccessibilityUIElement::stringAttributeValue() was not implemented.
+
+        * platform/gtk/TestExpectations: Unskip the failing test
+
 2012-12-09  Zan Dobersek  <zandobersek@gmail.com>
 
         Unreviewed GTK gardening.
diff --git a/LayoutTests/platform/gtk/TestExpectations b/LayoutTests/platform/gtk/TestExpectations
index d5e6ee9..f02601c 100644
--- a/LayoutTests/platform/gtk/TestExpectations
+++ b/LayoutTests/platform/gtk/TestExpectations
@@ -750,7 +750,6 @@
 webkit.org/b/98370 accessibility/loading-iframe-sends-notification.html [ Failure ]
 webkit.org/b/98371 accessibility/loading-iframe-updates-axtree.html [ Failure ]
 webkit.org/b/98372 accessibility/onclick-handlers.html [ Failure ]
-webkit.org/b/98373 accessibility/placeholder.html [ Failure ]
 webkit.org/b/98375 accessibility/secure-textfield-title-ui.html [ Failure ]
 webkit.org/b/98376 accessibility/selection-states.html [ Failure ]
 webkit.org/b/101185 accessibility/svg-remote-element.html [ Failure ]
diff --git a/Source/WebCore/ChangeLog b/Source/WebCore/ChangeLog
index b455272..ff2232c 100644
--- a/Source/WebCore/ChangeLog
+++ b/Source/WebCore/ChangeLog
@@ -1,3 +1,19 @@
+2012-12-09  Joanmarie Diggs  <jdiggs@igalia.com>
+
+        [GTK] accessibility/placeholder.html is failing
+        https://bugs.webkit.org/show_bug.cgi?id=98373
+
+        Reviewed by Martin Robinson.
+
+        The test was failing because the placeholder text was not supported and
+        AccessibilityUIElement::stringAttributeValue() was not implemented.
+
+        No new tests; instead the failing test was unskipped.
+
+        * accessibility/atk/WebKitAccessibleWrapperAtk.cpp:
+        (webkitAccessibleGetAttributes): Add the placeholder text as an AtkAttribute
+        of the AtkObject, as is done in Gtk+ 3.
+
 2012-12-09  Kondapally Kalyan  <kalyan.kondapally@intel.com>
 
         [EFL] [WebGL] Path is not resized correctly.
diff --git a/Source/WebCore/accessibility/atk/WebKitAccessibleWrapperAtk.cpp b/Source/WebCore/accessibility/atk/WebKitAccessibleWrapperAtk.cpp
index defd9c5..613a9a2 100644
--- a/Source/WebCore/accessibility/atk/WebKitAccessibleWrapperAtk.cpp
+++ b/Source/WebCore/accessibility/atk/WebKitAccessibleWrapperAtk.cpp
@@ -455,6 +455,10 @@
     if (coreObject->isAccessibilityTable() && !coreObject->isDataTable())
         attributeSet = addToAtkAttributeSet(attributeSet, "layout-guess", "true");
 
+    String placeholder = coreObject->placeholderValue();
+    if (!placeholder.isEmpty())
+        attributeSet = addToAtkAttributeSet(attributeSet, "placeholder-text", placeholder.utf8().data());
+
     return attributeSet;
 }
 
diff --git a/Tools/ChangeLog b/Tools/ChangeLog
index 9cc11de..899fd81 100644
--- a/Tools/ChangeLog
+++ b/Tools/ChangeLog
@@ -1,3 +1,18 @@
+2012-12-09  Joanmarie Diggs  <jdiggs@igalia.com>
+
+        [GTK] accessibility/placeholder.html is failing
+        https://bugs.webkit.org/show_bug.cgi?id=98373
+
+        Reviewed by Martin Robinson.
+
+        The test was failing because the placeholder text was not supported and
+        AccessibilityUIElement::stringAttributeValue() was not implemented.
+
+        * DumpRenderTree/gtk/AccessibilityUIElementGtk.cpp:
+        (coreAttributeToAtkAttribute): New convenience method to convert WebCore attribute
+        names into AtkObject attribute names
+        (AccessibilityUIElement::stringAttributeValue): implemented
+
 2012-12-09  Dan Winship  <danw@gnome.org>
 
         [GTK] Bump libxml2 requirement in jhbuild.modules
diff --git a/Tools/DumpRenderTree/gtk/AccessibilityUIElementGtk.cpp b/Tools/DumpRenderTree/gtk/AccessibilityUIElementGtk.cpp
index fa8d35b..07b57d8 100644
--- a/Tools/DumpRenderTree/gtk/AccessibilityUIElementGtk.cpp
+++ b/Tools/DumpRenderTree/gtk/AccessibilityUIElementGtk.cpp
@@ -37,6 +37,19 @@
 #include <wtf/text/WTFString.h>
 #include <wtf/unicode/CharacterNames.h>
 
+static String coreAttributeToAtkAttribute(JSStringRef attribute)
+{
+    size_t bufferSize = JSStringGetMaximumUTF8CStringSize(attribute);
+    GOwnPtr<gchar> buffer(static_cast<gchar*>(g_malloc(bufferSize)));
+    JSStringGetUTF8CString(attribute, buffer.get(), bufferSize);
+
+    String attributeString = String::fromUTF8(buffer.get());
+    if (attributeString == "AXPlaceholderValue")
+        return "placeholder-text";
+
+    return "";
+}
+
 static inline String roleToString(AtkRole role)
 {
     switch (role) {
@@ -764,7 +777,19 @@
 
 JSStringRef AccessibilityUIElement::stringAttributeValue(JSStringRef attribute)
 {
-    // FIXME: implement
+    if (!m_element)
+        return JSStringCreateWithCharacters(0, 0);
+
+    String atkAttributeName = coreAttributeToAtkAttribute(attribute);
+    if (atkAttributeName.isEmpty())
+        return JSStringCreateWithCharacters(0, 0);
+
+    for (GSList* atkAttributes = atk_object_get_attributes(ATK_OBJECT(m_element)); atkAttributes; atkAttributes = atkAttributes->next) {
+        AtkAttribute* atkAttribute = static_cast<AtkAttribute*>(atkAttributes->data);
+        if (!strcmp(atkAttribute->name, atkAttributeName.utf8().data()))
+            return JSStringCreateWithUTF8CString(atkAttribute->value);
+    }
+
     return JSStringCreateWithCharacters(0, 0);
 }