diff options
author | Svetoslav Ganov <svetoslavganov@google.com> | 2011-02-10 17:51:14 -0800 |
---|---|---|
committer | Svetoslav Ganov <svetoslavganov@google.com> | 2011-02-14 09:53:23 -0800 |
commit | 2cfed9eb0e1316f9906eacf25b51231c1ed8b331 (patch) | |
tree | 257896fd3370acda220e6922e92be5cb7206907b /core/tests | |
parent | b1d884d58994fe5ed74aa8d9bbe223c872cabe74 (diff) | |
download | frameworks_base-2cfed9eb0e1316f9906eacf25b51231c1ed8b331.zip frameworks_base-2cfed9eb0e1316f9906eacf25b51231c1ed8b331.tar.gz frameworks_base-2cfed9eb0e1316f9906eacf25b51231c1ed8b331.tar.bz2 |
Accessibility events generated by WebView contain non well formed markup.
bug:3444147
1. Now that the spans with CSS data are included in the accessibility
events, such that a client can parse them, the tests are doing so.
Change-Id: I574c68d27a95cd8226dd7634b00a7d404ae387fe
Diffstat (limited to 'core/tests')
-rw-r--r-- | core/tests/coretests/src/android/webkit/AccessibilityInjectorTest.java | 33 |
1 files changed, 32 insertions, 1 deletions
diff --git a/core/tests/coretests/src/android/webkit/AccessibilityInjectorTest.java b/core/tests/coretests/src/android/webkit/AccessibilityInjectorTest.java index 242e578..aedfbad 100644 --- a/core/tests/coretests/src/android/webkit/AccessibilityInjectorTest.java +++ b/core/tests/coretests/src/android/webkit/AccessibilityInjectorTest.java @@ -56,6 +56,12 @@ public class AccessibilityInjectorTest private static final int META_STATE_ALT_LEFT_ON = KeyEvent.META_ALT_ON | KeyEvent.META_ALT_LEFT_ON; + /** Prefix for the CSS style span appended by WebKit. */ + private static final String APPLE_SPAN_PREFIX = "<span class=\"Apple-style-span\""; + + /** Suffix for the CSS style span appended by WebKit. */ + private static final String APPLE_SPAN_SUFFIX = "</span>"; + /** The value for not specified selection string since null is a valid value. */ private static final String SELECTION_STRING_UNKNOWN = "Unknown"; @@ -1578,6 +1584,27 @@ public class AccessibilityInjectorTest } /** + * Strips the apple span appended by WebKit while generating + * the selection markup. + * + * @param markup The markup. + * @return Stripped from apple spans markup. + */ + private static String stripAppleSpanFromMarkup(String markup) { + StringBuilder stripped = new StringBuilder(markup); + int prefixBegIdx = stripped.indexOf(APPLE_SPAN_PREFIX); + while (prefixBegIdx >= 0) { + int prefixEndIdx = stripped.indexOf(">", prefixBegIdx) + 1; + stripped.replace(prefixBegIdx, prefixEndIdx, ""); + int suffixBegIdx = stripped.lastIndexOf(APPLE_SPAN_SUFFIX); + int suffixEndIdx = suffixBegIdx + APPLE_SPAN_SUFFIX.length(); + stripped.replace(suffixBegIdx, suffixEndIdx, ""); + prefixBegIdx = stripped.indexOf(APPLE_SPAN_PREFIX); + } + return stripped.toString(); + } + + /** * Disables accessibility and the mock accessibility service. */ private void disableAccessibilityAndMockAccessibilityService() { @@ -1757,7 +1784,11 @@ public class AccessibilityInjectorTest } if (!event.getText().isEmpty()) { CharSequence text = event.getText().get(0); - sReceivedSelectionString = (text != null) ? text.toString() : null; + if (text != null) { + sReceivedSelectionString = stripAppleSpanFromMarkup(text.toString()); + } else { + sReceivedSelectionString = null; + } } synchronized (sTestLock) { sTestLock.notifyAll(); |