Loading core/tests/coretests/AndroidManifest.xml +7 −0 Original line number Diff line number Diff line Loading @@ -1210,6 +1210,13 @@ android:authorities="android.app.SuggestionProvider"> </provider> <activity android:name="android.webkit.AccessibilityInjectorTestActivity"> <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.FRAMEWORK_INSTRUMENTATION_TEST" /> </intent-filter> </activity> </application> <instrumentation android:name="android.test.InstrumentationTestRunner" Loading core/tests/coretests/res/layout/accessibility_injector_test.xml 0 → 100644 +20 −0 Original line number Diff line number Diff line <?xml version="1.0" encoding="utf-8"?> <!-- Copyright (C) 2011 The Android Open Source Project Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. --> <WebView xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/webview" android:layout_width="match_parent" android:layout_height="match_parent" /> core/tests/coretests/src/android/webkit/AccessibilityInjectorTest.java +289 −51 Original line number Diff line number Diff line Loading @@ -25,13 +25,11 @@ import android.os.Handler; import android.os.Looper; import android.os.SystemClock; import android.provider.Settings; import android.test.AndroidTestCase; import android.test.ActivityInstrumentationTestCase2; import android.test.suitebuilder.annotation.LargeTest; import android.view.KeyEvent; import android.view.accessibility.AccessibilityEvent; import android.view.accessibility.AccessibilityManager; import android.webkit.WebView; import android.webkit.WebViewClient; /** * This is a test for the behavior of the {@link AccessibilityInjector} Loading @@ -42,7 +40,8 @@ import android.webkit.WebViewClient; * to so it also checks if the test for announcing navigation axis and * status messages as appropriate. */ public class AccessibilityInjectorTest extends AndroidTestCase { public class AccessibilityInjectorTest extends ActivityInstrumentationTestCase2<AccessibilityInjectorTestActivity> { /** The timeout to wait for the expected selection. */ private static final long TIMEOUT_WAIT_FOR_SELECTION_STRING = 1000; Loading @@ -51,7 +50,7 @@ public class AccessibilityInjectorTest extends AndroidTestCase { private static final long TIMEOUT_ENABLE_ACCESSIBILITY_AND_MOCK_SERVICE = 1000; /** The count of tests to detect when to shut down the service. */ private static final int TEST_CASE_COUNT = 16; private static final int TEST_CASE_COUNT = 19; /** The meta state for pressed left ALT. */ private static final int META_STATE_ALT_LEFT_ON = KeyEvent.META_ALT_ON Loading Loading @@ -95,6 +94,10 @@ public class AccessibilityInjectorTest extends AndroidTestCase { /** The received selection string for assertion checking. */ private static String sReceivedSelectionString = SELECTION_STRING_UNKNOWN; public AccessibilityInjectorTest() { super(AccessibilityInjectorTestActivity.class); } @Override protected void setUp() throws Exception { super.setUp(); Loading Loading @@ -142,11 +145,10 @@ public class AccessibilityInjectorTest extends AndroidTestCase { "d" + "<p/>" + "e" + "</p>" + "</body>" + "</html>"; WebView webView = createWebVewWithHtml(html); WebView webView = loadHTML(html); // change navigation axis to word sendKeyEvent(webView, KeyEvent.KEYCODE_DPAD_DOWN, META_STATE_ALT_LEFT_ON); Loading Loading @@ -241,7 +243,7 @@ public class AccessibilityInjectorTest extends AndroidTestCase { "</body>" + "</html>"; WebView webView = createWebVewWithHtml(html); WebView webView = loadHTML(html); // change navigation axis to word sendKeyEvent(webView, KeyEvent.KEYCODE_DPAD_DOWN, META_STATE_ALT_LEFT_ON); Loading Loading @@ -368,7 +370,7 @@ public class AccessibilityInjectorTest extends AndroidTestCase { "</body>" + "</html>"; WebView webView = createWebVewWithHtml(html); WebView webView = loadHTML(html); // Sentence axis is the default Loading Loading @@ -471,7 +473,7 @@ public class AccessibilityInjectorTest extends AndroidTestCase { "</body>" + "</html>"; WebView webView = createWebVewWithHtml(html); WebView webView = loadHTML(html); // change navigation axis to heading sendKeyEvent(webView, KeyEvent.KEYCODE_DPAD_RIGHT, META_STATE_ALT_LEFT_ON); Loading Loading @@ -559,7 +561,7 @@ public class AccessibilityInjectorTest extends AndroidTestCase { "</body>" + "</html>"; WebView webView = createWebVewWithHtml(html); WebView webView = loadHTML(html); // change navigation axis to heading sendKeyEvent(webView, KeyEvent.KEYCODE_DPAD_RIGHT, META_STATE_ALT_LEFT_ON); Loading Loading @@ -631,7 +633,7 @@ public class AccessibilityInjectorTest extends AndroidTestCase { "</body>" + "</html>"; WebView webView = createWebVewWithHtml(html); WebView webView = loadHTML(html); // change navigation axis to document sendKeyEvent(webView, KeyEvent.KEYCODE_DPAD_LEFT, META_STATE_ALT_LEFT_ON); Loading Loading @@ -689,7 +691,7 @@ public class AccessibilityInjectorTest extends AndroidTestCase { "</body>" + "</html>"; WebView webView = createWebVewWithHtml(html); WebView webView = loadHTML(html); // change navigation axis to document sendKeyEvent(webView, KeyEvent.KEYCODE_DPAD_LEFT, META_STATE_ALT_LEFT_ON); Loading Loading @@ -733,7 +735,7 @@ public class AccessibilityInjectorTest extends AndroidTestCase { "</body>" + "</html>"; WebView webView = createWebVewWithHtml(html); WebView webView = loadHTML(html); // change navigation axis to word sendKeyEvent(webView, KeyEvent.KEYCODE_DPAD_DOWN, META_STATE_ALT_LEFT_ON); Loading Loading @@ -792,11 +794,11 @@ public class AccessibilityInjectorTest extends AndroidTestCase { "</body>" + "</html>"; WebView webView = createWebVewWithHtml(html); WebView webView = loadHTML(html); // go to the first sentence sendKeyEvent(webView, KeyEvent.KEYCODE_DPAD_DOWN, 0); assertSelectionString("First"); assertSelectionString("<div>First</div>"); // go to the second sentence sendKeyEvent(webView, KeyEvent.KEYCODE_DPAD_DOWN, 0); Loading Loading @@ -828,7 +830,7 @@ public class AccessibilityInjectorTest extends AndroidTestCase { // go to the first sentence sendKeyEvent(webView, KeyEvent.KEYCODE_DPAD_DOWN, 0); assertSelectionString("First"); assertSelectionString("<div>First</div>"); } /** Loading @@ -855,7 +857,7 @@ public class AccessibilityInjectorTest extends AndroidTestCase { "</body>" + "</html>"; WebView webView = createWebVewWithHtml(html); WebView webView = loadHTML(html); // go to the first sentence sendKeyEvent(webView, KeyEvent.KEYCODE_DPAD_DOWN, 0); Loading Loading @@ -931,7 +933,7 @@ public class AccessibilityInjectorTest extends AndroidTestCase { "</body>" + "</html>"; WebView webView = createWebVewWithHtml(html); WebView webView = loadHTML(html); // go to the first sentence sendKeyEvent(webView, KeyEvent.KEYCODE_DPAD_DOWN, 0); Loading Loading @@ -991,7 +993,7 @@ public class AccessibilityInjectorTest extends AndroidTestCase { "</body>" + "</html>"; WebView webView = createWebVewWithHtml(html); WebView webView = loadHTML(html); // change navigation axis to word sendKeyEvent(webView, KeyEvent.KEYCODE_DPAD_DOWN, META_STATE_ALT_LEFT_ON); Loading Loading @@ -1047,7 +1049,7 @@ public class AccessibilityInjectorTest extends AndroidTestCase { "</body>" + "</html>"; WebView webView = createWebVewWithHtml(html); WebView webView = loadHTML(html); // change navigation axis to word sendKeyEvent(webView, KeyEvent.KEYCODE_DPAD_DOWN, META_STATE_ALT_LEFT_ON); Loading Loading @@ -1107,7 +1109,7 @@ public class AccessibilityInjectorTest extends AndroidTestCase { "</body>" + "</html>"; WebView webView = createWebVewWithHtml(html); WebView webView = loadHTML(html); // go to the first sentence sendKeyEvent(webView, KeyEvent.KEYCODE_DPAD_DOWN, 0); Loading Loading @@ -1179,7 +1181,7 @@ public class AccessibilityInjectorTest extends AndroidTestCase { "</body>" + "</html>"; WebView webView = createWebVewWithHtml(html); WebView webView = loadHTML(html); // go to the first sentence sendKeyEvent(webView, KeyEvent.KEYCODE_DPAD_DOWN, 0); Loading Loading @@ -1250,7 +1252,7 @@ public class AccessibilityInjectorTest extends AndroidTestCase { "</body>" + "</html>"; WebView webView = createWebVewWithHtml(html); WebView webView = loadHTML(html); // go to the first sentence sendKeyEvent(webView, KeyEvent.KEYCODE_DPAD_DOWN, 0); Loading Loading @@ -1296,9 +1298,243 @@ public class AccessibilityInjectorTest extends AndroidTestCase { sendKeyEvent(webView, KeyEvent.KEYCODE_DPAD_UP, 0); assertSelectionString("<input type=\"text\">"); // go to the second sentence sendKeyEvent(webView, KeyEvent.KEYCODE_DPAD_UP, 0); assertSelectionString("<input type=\"text\">"); // go to the first sentence sendKeyEvent(webView, KeyEvent.KEYCODE_DPAD_UP, 0); assertSelectionString("First"); } /** * Tests traversing of input controls. */ @LargeTest public void testSelectionOfInputElements3() throws Exception { // a bit ugly but helps detect beginning and end of all tests so accessibility // and the mock service are not toggled on every test (expensive) sExecutedTestCount++; String html = "<!DOCTYPE html>" + "<html>" + "<head>" + "</head>" + "<body>" + "<input type=\"text\"/>" + "<button type=\"button\">Click Me!</button>" + "<select>" + "<option value=\"volvo\">Volvo</option>" + "<option value=\"saab\">Saab</option>" + "</select>" + "</body>" + "</html>"; WebView webView = loadHTML(html); // go to the first sentence sendKeyEvent(webView, KeyEvent.KEYCODE_DPAD_DOWN, 0); assertSelectionString("<input type=\"text\">"); // go to the second sentence sendKeyEvent(webView, KeyEvent.KEYCODE_DPAD_DOWN, 0); assertSelectionString("<button type=\"button\">Click Me!</button>"); // go to the third sentence sendKeyEvent(webView, KeyEvent.KEYCODE_DPAD_DOWN, 0); assertSelectionString("<select><option value=\"volvo\">Volvo</option>" + "<option value=\"saab\">Saab</option></select>"); // go to past the last sentence sendKeyEvent(webView, KeyEvent.KEYCODE_DPAD_DOWN, 0); assertSelectionString(null); // go to the third sentence sendKeyEvent(webView, KeyEvent.KEYCODE_DPAD_UP, 0); assertSelectionString("<select><option value=\"volvo\">Volvo</option>" + "<option value=\"saab\">Saab</option></select>"); // go to the second sentence sendKeyEvent(webView, KeyEvent.KEYCODE_DPAD_UP, 0); assertSelectionString("<button type=\"button\">Click Me!</button>"); // go to the first sentence sendKeyEvent(webView, KeyEvent.KEYCODE_DPAD_UP, 0); assertSelectionString("<input type=\"text\">"); // go to before the first sentence sendKeyEvent(webView, KeyEvent.KEYCODE_DPAD_UP, 0); assertSelectionString(null); // go to the first sentence sendKeyEvent(webView, KeyEvent.KEYCODE_DPAD_DOWN, 0); assertSelectionString("<input type=\"text\">"); } /** * Tests traversing of input controls. */ @LargeTest public void testSelectionOfInputElements4() throws Exception { // a bit ugly but helps detect beginning and end of all tests so accessibility // and the mock service are not toggled on every test (expensive) sExecutedTestCount++; String html = "<!DOCTYPE html>" + "<html>" + "<head>" + "</head>" + "<body>" + "Start" + "<span>" + "<span>" + "<input type=\"submit\">" + "</span>" + "</span>" + "<input type=\"text\" size=\"30\">" + "<span>" + "<span>" + "<input type=\"submit\" size=\"30\">" + "</span>" + "</span>" + "End" + "</body>" + "</html>"; WebView webView = loadHTML(html); // go to the first sentence sendKeyEvent(webView, KeyEvent.KEYCODE_DPAD_DOWN, 0); assertSelectionString("Start"); // go to the second sentence sendKeyEvent(webView, KeyEvent.KEYCODE_DPAD_DOWN, 0); assertSelectionString("<input type=\"submit\">"); // go to the third sentence sendKeyEvent(webView, KeyEvent.KEYCODE_DPAD_DOWN, 0); assertSelectionString("<input type=\"text\" size=\"30\">"); // go to the fourth sentence sendKeyEvent(webView, KeyEvent.KEYCODE_DPAD_DOWN, 0); assertSelectionString("<input type=\"submit\" size=\"30\">"); // go to the fifth sentence sendKeyEvent(webView, KeyEvent.KEYCODE_DPAD_DOWN, 0); assertSelectionString("End"); // go to past the last sentence sendKeyEvent(webView, KeyEvent.KEYCODE_DPAD_DOWN, 0); assertSelectionString(null); // go to the fifth sentence sendKeyEvent(webView, KeyEvent.KEYCODE_DPAD_UP, 0); assertSelectionString("End"); // go to the fourth sentence sendKeyEvent(webView, KeyEvent.KEYCODE_DPAD_UP, 0); assertSelectionString("<input type=\"submit\" size=\"30\">"); // go to the third sentence sendKeyEvent(webView, KeyEvent.KEYCODE_DPAD_UP, 0); assertSelectionString("<input type=\"text\" size=\"30\">"); // go to the second sentence sendKeyEvent(webView, KeyEvent.KEYCODE_DPAD_UP, 0); assertSelectionString("<input type=\"submit\">"); // go to the first sentence sendKeyEvent(webView, KeyEvent.KEYCODE_DPAD_UP, 0); assertSelectionString("Start"); // go to before the first sentence sendKeyEvent(webView, KeyEvent.KEYCODE_DPAD_UP, 0); assertSelectionString(null); // go to the first sentence sendKeyEvent(webView, KeyEvent.KEYCODE_DPAD_DOWN, 0); assertSelectionString("Start"); } /** * Tests traversing of input controls. */ @LargeTest public void testSelectionOfInputElements5() throws Exception { // a bit ugly but helps detect beginning and end of all tests so accessibility // and the mock service are not toggled on every test (expensive) sExecutedTestCount++; String html = "<!DOCTYPE html>" + "<html>" + "<head>" + "</head>" + "<body>" + "<div>" + "First" + "<input type=\"hidden\">" + "<input type=\"hidden\">" + "<input type=\"hidden\">" + "<input type=\"hidden\">" + "<input type=\"text\">" + "<span>" + "<span>" + "<input type=\"submit\">" + "</span>" + "</span>" + "</div>" + "</body>" + "Second" + "</html>"; WebView webView = loadHTML(html); // go to the first sentence sendKeyEvent(webView, KeyEvent.KEYCODE_DPAD_DOWN, 0); assertSelectionString("First"); // go to the second sentence sendKeyEvent(webView, KeyEvent.KEYCODE_DPAD_DOWN, 0); assertSelectionString("<input type=\"text\">"); // go to the third sentence sendKeyEvent(webView, KeyEvent.KEYCODE_DPAD_DOWN, 0); assertSelectionString("<input type=\"submit\">"); // go to the fourth sentence sendKeyEvent(webView, KeyEvent.KEYCODE_DPAD_DOWN, 0); assertSelectionString("Second"); // go to past the last sentence sendKeyEvent(webView, KeyEvent.KEYCODE_DPAD_DOWN, 0); assertSelectionString(null); // go to the fourth sentence sendKeyEvent(webView, KeyEvent.KEYCODE_DPAD_UP, 0); assertSelectionString("Second"); // go to the third sentence sendKeyEvent(webView, KeyEvent.KEYCODE_DPAD_UP, 0); assertSelectionString("<input type=\"submit\">"); // go to the second sentence sendKeyEvent(webView, KeyEvent.KEYCODE_DPAD_UP, 0); assertSelectionString("<input type=\"text\">"); // go to the first sentence sendKeyEvent(webView, KeyEvent.KEYCODE_DPAD_UP, 0); assertSelectionString("First"); // go to before the first sentence sendKeyEvent(webView, KeyEvent.KEYCODE_DPAD_UP, 0); assertSelectionString(null); // go to the first sentence sendKeyEvent(webView, KeyEvent.KEYCODE_DPAD_DOWN, 0); assertSelectionString("First"); } /** Loading @@ -1306,14 +1542,14 @@ public class AccessibilityInjectorTest extends AndroidTestCase { */ private void enableAccessibilityAndMockAccessibilityService() { // make sure the manager is instantiated so the system initializes it AccessibilityManager.getInstance(getContext()); AccessibilityManager.getInstance(getActivity()); // enable accessibility and the mock accessibility service Settings.Secure.putInt(getContext().getContentResolver(), Settings.Secure.putInt(getActivity().getContentResolver(), Settings.Secure.ACCESSIBILITY_ENABLED, 1); String enabledServices = new ComponentName(getContext().getPackageName(), String enabledServices = new ComponentName(getActivity().getPackageName(), MockAccessibilityService.class.getName()).flattenToShortString(); Settings.Secure.putString(getContext().getContentResolver(), Settings.Secure.putString(getActivity().getContentResolver(), Settings.Secure.ENABLED_ACCESSIBILITY_SERVICES, enabledServices); // poll within a timeout and let be interrupted in case of success Loading Loading @@ -1346,9 +1582,9 @@ public class AccessibilityInjectorTest extends AndroidTestCase { */ private void disableAccessibilityAndMockAccessibilityService() { // disable accessibility and the mock accessibility service Settings.Secure.putInt(getContext().getContentResolver(), Settings.Secure.putInt(getActivity().getContentResolver(), Settings.Secure.ACCESSIBILITY_ENABLED, 0); Settings.Secure.putString(getContext().getContentResolver(), Settings.Secure.putString(getActivity().getContentResolver(), Settings.Secure.ENABLED_ACCESSIBILITY_SERVICES, ""); } Loading Loading @@ -1391,16 +1627,16 @@ public class AccessibilityInjectorTest extends AndroidTestCase { } /** * Creates a {@link WebView} with with a given HTML content. * Loads HTML content in a {@link WebView}. * * @param html The HTML content; * @return The created view. * @return The {@link WebView} view. */ private WebView createWebVewWithHtml(final String html) { private WebView loadHTML(final String html) { mWorker.getHandler().post(new Runnable() { public void run() { mWebView = new WebView(getContext()); mWebView.loadData(html, "text/html", "utf-8"); if (mWebView == null) { mWebView = getActivity().getWebView(); mWebView.setWebViewClient(new WebViewClient() { @Override public void onPageFinished(WebView view, String url) { Loading @@ -1414,6 +1650,8 @@ public class AccessibilityInjectorTest extends AndroidTestCase { } }); } mWebView.loadData(html, "text/html", "utf-8"); } }); synchronized (sTestLock) { try { Loading @@ -1430,7 +1668,7 @@ public class AccessibilityInjectorTest extends AndroidTestCase { * to ensure that this test will be agnostic to changes of the bindings. */ private void injectTestWebContentKeyBindings() { ContentResolver contentResolver = getContext().getContentResolver(); ContentResolver contentResolver = getActivity().getContentResolver(); mDefaultKeyBindings = Settings.Secure.getString(contentResolver, Settings.Secure.ACCESSIBILITY_WEB_CONTENT_KEY_BINDINGS); Settings.Secure.putString(contentResolver, Loading @@ -1441,7 +1679,7 @@ public class AccessibilityInjectorTest extends AndroidTestCase { * Restores the default web content key bindings. */ private void restoreDefaultWebContentKeyBindings() { Settings.Secure.putString(getContext().getContentResolver(), Settings.Secure.putString(getActivity().getContentResolver(), Settings.Secure.ACCESSIBILITY_WEB_CONTENT_KEY_BINDINGS, mDefaultKeyBindings); } Loading core/tests/coretests/src/android/webkit/AccessibilityInjectorTestActivity.java 0 → 100644 +38 −0 Original line number Diff line number Diff line /* * Copyright (C) 2011 The Android Open Source Project * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package android.webkit; import com.android.frameworks.coretests.R; import android.app.Activity; import android.os.Bundle; public class AccessibilityInjectorTestActivity extends Activity { private WebView mWebView; @Override public void onCreate(Bundle icicle) { super.onCreate(icicle); setContentView(R.layout.accessibility_injector_test); mWebView = (WebView) findViewById(R.id.webview); } public WebView getWebView() { return mWebView; } } Loading
core/tests/coretests/AndroidManifest.xml +7 −0 Original line number Diff line number Diff line Loading @@ -1210,6 +1210,13 @@ android:authorities="android.app.SuggestionProvider"> </provider> <activity android:name="android.webkit.AccessibilityInjectorTestActivity"> <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.FRAMEWORK_INSTRUMENTATION_TEST" /> </intent-filter> </activity> </application> <instrumentation android:name="android.test.InstrumentationTestRunner" Loading
core/tests/coretests/res/layout/accessibility_injector_test.xml 0 → 100644 +20 −0 Original line number Diff line number Diff line <?xml version="1.0" encoding="utf-8"?> <!-- Copyright (C) 2011 The Android Open Source Project Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. --> <WebView xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/webview" android:layout_width="match_parent" android:layout_height="match_parent" />
core/tests/coretests/src/android/webkit/AccessibilityInjectorTest.java +289 −51 Original line number Diff line number Diff line Loading @@ -25,13 +25,11 @@ import android.os.Handler; import android.os.Looper; import android.os.SystemClock; import android.provider.Settings; import android.test.AndroidTestCase; import android.test.ActivityInstrumentationTestCase2; import android.test.suitebuilder.annotation.LargeTest; import android.view.KeyEvent; import android.view.accessibility.AccessibilityEvent; import android.view.accessibility.AccessibilityManager; import android.webkit.WebView; import android.webkit.WebViewClient; /** * This is a test for the behavior of the {@link AccessibilityInjector} Loading @@ -42,7 +40,8 @@ import android.webkit.WebViewClient; * to so it also checks if the test for announcing navigation axis and * status messages as appropriate. */ public class AccessibilityInjectorTest extends AndroidTestCase { public class AccessibilityInjectorTest extends ActivityInstrumentationTestCase2<AccessibilityInjectorTestActivity> { /** The timeout to wait for the expected selection. */ private static final long TIMEOUT_WAIT_FOR_SELECTION_STRING = 1000; Loading @@ -51,7 +50,7 @@ public class AccessibilityInjectorTest extends AndroidTestCase { private static final long TIMEOUT_ENABLE_ACCESSIBILITY_AND_MOCK_SERVICE = 1000; /** The count of tests to detect when to shut down the service. */ private static final int TEST_CASE_COUNT = 16; private static final int TEST_CASE_COUNT = 19; /** The meta state for pressed left ALT. */ private static final int META_STATE_ALT_LEFT_ON = KeyEvent.META_ALT_ON Loading Loading @@ -95,6 +94,10 @@ public class AccessibilityInjectorTest extends AndroidTestCase { /** The received selection string for assertion checking. */ private static String sReceivedSelectionString = SELECTION_STRING_UNKNOWN; public AccessibilityInjectorTest() { super(AccessibilityInjectorTestActivity.class); } @Override protected void setUp() throws Exception { super.setUp(); Loading Loading @@ -142,11 +145,10 @@ public class AccessibilityInjectorTest extends AndroidTestCase { "d" + "<p/>" + "e" + "</p>" + "</body>" + "</html>"; WebView webView = createWebVewWithHtml(html); WebView webView = loadHTML(html); // change navigation axis to word sendKeyEvent(webView, KeyEvent.KEYCODE_DPAD_DOWN, META_STATE_ALT_LEFT_ON); Loading Loading @@ -241,7 +243,7 @@ public class AccessibilityInjectorTest extends AndroidTestCase { "</body>" + "</html>"; WebView webView = createWebVewWithHtml(html); WebView webView = loadHTML(html); // change navigation axis to word sendKeyEvent(webView, KeyEvent.KEYCODE_DPAD_DOWN, META_STATE_ALT_LEFT_ON); Loading Loading @@ -368,7 +370,7 @@ public class AccessibilityInjectorTest extends AndroidTestCase { "</body>" + "</html>"; WebView webView = createWebVewWithHtml(html); WebView webView = loadHTML(html); // Sentence axis is the default Loading Loading @@ -471,7 +473,7 @@ public class AccessibilityInjectorTest extends AndroidTestCase { "</body>" + "</html>"; WebView webView = createWebVewWithHtml(html); WebView webView = loadHTML(html); // change navigation axis to heading sendKeyEvent(webView, KeyEvent.KEYCODE_DPAD_RIGHT, META_STATE_ALT_LEFT_ON); Loading Loading @@ -559,7 +561,7 @@ public class AccessibilityInjectorTest extends AndroidTestCase { "</body>" + "</html>"; WebView webView = createWebVewWithHtml(html); WebView webView = loadHTML(html); // change navigation axis to heading sendKeyEvent(webView, KeyEvent.KEYCODE_DPAD_RIGHT, META_STATE_ALT_LEFT_ON); Loading Loading @@ -631,7 +633,7 @@ public class AccessibilityInjectorTest extends AndroidTestCase { "</body>" + "</html>"; WebView webView = createWebVewWithHtml(html); WebView webView = loadHTML(html); // change navigation axis to document sendKeyEvent(webView, KeyEvent.KEYCODE_DPAD_LEFT, META_STATE_ALT_LEFT_ON); Loading Loading @@ -689,7 +691,7 @@ public class AccessibilityInjectorTest extends AndroidTestCase { "</body>" + "</html>"; WebView webView = createWebVewWithHtml(html); WebView webView = loadHTML(html); // change navigation axis to document sendKeyEvent(webView, KeyEvent.KEYCODE_DPAD_LEFT, META_STATE_ALT_LEFT_ON); Loading Loading @@ -733,7 +735,7 @@ public class AccessibilityInjectorTest extends AndroidTestCase { "</body>" + "</html>"; WebView webView = createWebVewWithHtml(html); WebView webView = loadHTML(html); // change navigation axis to word sendKeyEvent(webView, KeyEvent.KEYCODE_DPAD_DOWN, META_STATE_ALT_LEFT_ON); Loading Loading @@ -792,11 +794,11 @@ public class AccessibilityInjectorTest extends AndroidTestCase { "</body>" + "</html>"; WebView webView = createWebVewWithHtml(html); WebView webView = loadHTML(html); // go to the first sentence sendKeyEvent(webView, KeyEvent.KEYCODE_DPAD_DOWN, 0); assertSelectionString("First"); assertSelectionString("<div>First</div>"); // go to the second sentence sendKeyEvent(webView, KeyEvent.KEYCODE_DPAD_DOWN, 0); Loading Loading @@ -828,7 +830,7 @@ public class AccessibilityInjectorTest extends AndroidTestCase { // go to the first sentence sendKeyEvent(webView, KeyEvent.KEYCODE_DPAD_DOWN, 0); assertSelectionString("First"); assertSelectionString("<div>First</div>"); } /** Loading @@ -855,7 +857,7 @@ public class AccessibilityInjectorTest extends AndroidTestCase { "</body>" + "</html>"; WebView webView = createWebVewWithHtml(html); WebView webView = loadHTML(html); // go to the first sentence sendKeyEvent(webView, KeyEvent.KEYCODE_DPAD_DOWN, 0); Loading Loading @@ -931,7 +933,7 @@ public class AccessibilityInjectorTest extends AndroidTestCase { "</body>" + "</html>"; WebView webView = createWebVewWithHtml(html); WebView webView = loadHTML(html); // go to the first sentence sendKeyEvent(webView, KeyEvent.KEYCODE_DPAD_DOWN, 0); Loading Loading @@ -991,7 +993,7 @@ public class AccessibilityInjectorTest extends AndroidTestCase { "</body>" + "</html>"; WebView webView = createWebVewWithHtml(html); WebView webView = loadHTML(html); // change navigation axis to word sendKeyEvent(webView, KeyEvent.KEYCODE_DPAD_DOWN, META_STATE_ALT_LEFT_ON); Loading Loading @@ -1047,7 +1049,7 @@ public class AccessibilityInjectorTest extends AndroidTestCase { "</body>" + "</html>"; WebView webView = createWebVewWithHtml(html); WebView webView = loadHTML(html); // change navigation axis to word sendKeyEvent(webView, KeyEvent.KEYCODE_DPAD_DOWN, META_STATE_ALT_LEFT_ON); Loading Loading @@ -1107,7 +1109,7 @@ public class AccessibilityInjectorTest extends AndroidTestCase { "</body>" + "</html>"; WebView webView = createWebVewWithHtml(html); WebView webView = loadHTML(html); // go to the first sentence sendKeyEvent(webView, KeyEvent.KEYCODE_DPAD_DOWN, 0); Loading Loading @@ -1179,7 +1181,7 @@ public class AccessibilityInjectorTest extends AndroidTestCase { "</body>" + "</html>"; WebView webView = createWebVewWithHtml(html); WebView webView = loadHTML(html); // go to the first sentence sendKeyEvent(webView, KeyEvent.KEYCODE_DPAD_DOWN, 0); Loading Loading @@ -1250,7 +1252,7 @@ public class AccessibilityInjectorTest extends AndroidTestCase { "</body>" + "</html>"; WebView webView = createWebVewWithHtml(html); WebView webView = loadHTML(html); // go to the first sentence sendKeyEvent(webView, KeyEvent.KEYCODE_DPAD_DOWN, 0); Loading Loading @@ -1296,9 +1298,243 @@ public class AccessibilityInjectorTest extends AndroidTestCase { sendKeyEvent(webView, KeyEvent.KEYCODE_DPAD_UP, 0); assertSelectionString("<input type=\"text\">"); // go to the second sentence sendKeyEvent(webView, KeyEvent.KEYCODE_DPAD_UP, 0); assertSelectionString("<input type=\"text\">"); // go to the first sentence sendKeyEvent(webView, KeyEvent.KEYCODE_DPAD_UP, 0); assertSelectionString("First"); } /** * Tests traversing of input controls. */ @LargeTest public void testSelectionOfInputElements3() throws Exception { // a bit ugly but helps detect beginning and end of all tests so accessibility // and the mock service are not toggled on every test (expensive) sExecutedTestCount++; String html = "<!DOCTYPE html>" + "<html>" + "<head>" + "</head>" + "<body>" + "<input type=\"text\"/>" + "<button type=\"button\">Click Me!</button>" + "<select>" + "<option value=\"volvo\">Volvo</option>" + "<option value=\"saab\">Saab</option>" + "</select>" + "</body>" + "</html>"; WebView webView = loadHTML(html); // go to the first sentence sendKeyEvent(webView, KeyEvent.KEYCODE_DPAD_DOWN, 0); assertSelectionString("<input type=\"text\">"); // go to the second sentence sendKeyEvent(webView, KeyEvent.KEYCODE_DPAD_DOWN, 0); assertSelectionString("<button type=\"button\">Click Me!</button>"); // go to the third sentence sendKeyEvent(webView, KeyEvent.KEYCODE_DPAD_DOWN, 0); assertSelectionString("<select><option value=\"volvo\">Volvo</option>" + "<option value=\"saab\">Saab</option></select>"); // go to past the last sentence sendKeyEvent(webView, KeyEvent.KEYCODE_DPAD_DOWN, 0); assertSelectionString(null); // go to the third sentence sendKeyEvent(webView, KeyEvent.KEYCODE_DPAD_UP, 0); assertSelectionString("<select><option value=\"volvo\">Volvo</option>" + "<option value=\"saab\">Saab</option></select>"); // go to the second sentence sendKeyEvent(webView, KeyEvent.KEYCODE_DPAD_UP, 0); assertSelectionString("<button type=\"button\">Click Me!</button>"); // go to the first sentence sendKeyEvent(webView, KeyEvent.KEYCODE_DPAD_UP, 0); assertSelectionString("<input type=\"text\">"); // go to before the first sentence sendKeyEvent(webView, KeyEvent.KEYCODE_DPAD_UP, 0); assertSelectionString(null); // go to the first sentence sendKeyEvent(webView, KeyEvent.KEYCODE_DPAD_DOWN, 0); assertSelectionString("<input type=\"text\">"); } /** * Tests traversing of input controls. */ @LargeTest public void testSelectionOfInputElements4() throws Exception { // a bit ugly but helps detect beginning and end of all tests so accessibility // and the mock service are not toggled on every test (expensive) sExecutedTestCount++; String html = "<!DOCTYPE html>" + "<html>" + "<head>" + "</head>" + "<body>" + "Start" + "<span>" + "<span>" + "<input type=\"submit\">" + "</span>" + "</span>" + "<input type=\"text\" size=\"30\">" + "<span>" + "<span>" + "<input type=\"submit\" size=\"30\">" + "</span>" + "</span>" + "End" + "</body>" + "</html>"; WebView webView = loadHTML(html); // go to the first sentence sendKeyEvent(webView, KeyEvent.KEYCODE_DPAD_DOWN, 0); assertSelectionString("Start"); // go to the second sentence sendKeyEvent(webView, KeyEvent.KEYCODE_DPAD_DOWN, 0); assertSelectionString("<input type=\"submit\">"); // go to the third sentence sendKeyEvent(webView, KeyEvent.KEYCODE_DPAD_DOWN, 0); assertSelectionString("<input type=\"text\" size=\"30\">"); // go to the fourth sentence sendKeyEvent(webView, KeyEvent.KEYCODE_DPAD_DOWN, 0); assertSelectionString("<input type=\"submit\" size=\"30\">"); // go to the fifth sentence sendKeyEvent(webView, KeyEvent.KEYCODE_DPAD_DOWN, 0); assertSelectionString("End"); // go to past the last sentence sendKeyEvent(webView, KeyEvent.KEYCODE_DPAD_DOWN, 0); assertSelectionString(null); // go to the fifth sentence sendKeyEvent(webView, KeyEvent.KEYCODE_DPAD_UP, 0); assertSelectionString("End"); // go to the fourth sentence sendKeyEvent(webView, KeyEvent.KEYCODE_DPAD_UP, 0); assertSelectionString("<input type=\"submit\" size=\"30\">"); // go to the third sentence sendKeyEvent(webView, KeyEvent.KEYCODE_DPAD_UP, 0); assertSelectionString("<input type=\"text\" size=\"30\">"); // go to the second sentence sendKeyEvent(webView, KeyEvent.KEYCODE_DPAD_UP, 0); assertSelectionString("<input type=\"submit\">"); // go to the first sentence sendKeyEvent(webView, KeyEvent.KEYCODE_DPAD_UP, 0); assertSelectionString("Start"); // go to before the first sentence sendKeyEvent(webView, KeyEvent.KEYCODE_DPAD_UP, 0); assertSelectionString(null); // go to the first sentence sendKeyEvent(webView, KeyEvent.KEYCODE_DPAD_DOWN, 0); assertSelectionString("Start"); } /** * Tests traversing of input controls. */ @LargeTest public void testSelectionOfInputElements5() throws Exception { // a bit ugly but helps detect beginning and end of all tests so accessibility // and the mock service are not toggled on every test (expensive) sExecutedTestCount++; String html = "<!DOCTYPE html>" + "<html>" + "<head>" + "</head>" + "<body>" + "<div>" + "First" + "<input type=\"hidden\">" + "<input type=\"hidden\">" + "<input type=\"hidden\">" + "<input type=\"hidden\">" + "<input type=\"text\">" + "<span>" + "<span>" + "<input type=\"submit\">" + "</span>" + "</span>" + "</div>" + "</body>" + "Second" + "</html>"; WebView webView = loadHTML(html); // go to the first sentence sendKeyEvent(webView, KeyEvent.KEYCODE_DPAD_DOWN, 0); assertSelectionString("First"); // go to the second sentence sendKeyEvent(webView, KeyEvent.KEYCODE_DPAD_DOWN, 0); assertSelectionString("<input type=\"text\">"); // go to the third sentence sendKeyEvent(webView, KeyEvent.KEYCODE_DPAD_DOWN, 0); assertSelectionString("<input type=\"submit\">"); // go to the fourth sentence sendKeyEvent(webView, KeyEvent.KEYCODE_DPAD_DOWN, 0); assertSelectionString("Second"); // go to past the last sentence sendKeyEvent(webView, KeyEvent.KEYCODE_DPAD_DOWN, 0); assertSelectionString(null); // go to the fourth sentence sendKeyEvent(webView, KeyEvent.KEYCODE_DPAD_UP, 0); assertSelectionString("Second"); // go to the third sentence sendKeyEvent(webView, KeyEvent.KEYCODE_DPAD_UP, 0); assertSelectionString("<input type=\"submit\">"); // go to the second sentence sendKeyEvent(webView, KeyEvent.KEYCODE_DPAD_UP, 0); assertSelectionString("<input type=\"text\">"); // go to the first sentence sendKeyEvent(webView, KeyEvent.KEYCODE_DPAD_UP, 0); assertSelectionString("First"); // go to before the first sentence sendKeyEvent(webView, KeyEvent.KEYCODE_DPAD_UP, 0); assertSelectionString(null); // go to the first sentence sendKeyEvent(webView, KeyEvent.KEYCODE_DPAD_DOWN, 0); assertSelectionString("First"); } /** Loading @@ -1306,14 +1542,14 @@ public class AccessibilityInjectorTest extends AndroidTestCase { */ private void enableAccessibilityAndMockAccessibilityService() { // make sure the manager is instantiated so the system initializes it AccessibilityManager.getInstance(getContext()); AccessibilityManager.getInstance(getActivity()); // enable accessibility and the mock accessibility service Settings.Secure.putInt(getContext().getContentResolver(), Settings.Secure.putInt(getActivity().getContentResolver(), Settings.Secure.ACCESSIBILITY_ENABLED, 1); String enabledServices = new ComponentName(getContext().getPackageName(), String enabledServices = new ComponentName(getActivity().getPackageName(), MockAccessibilityService.class.getName()).flattenToShortString(); Settings.Secure.putString(getContext().getContentResolver(), Settings.Secure.putString(getActivity().getContentResolver(), Settings.Secure.ENABLED_ACCESSIBILITY_SERVICES, enabledServices); // poll within a timeout and let be interrupted in case of success Loading Loading @@ -1346,9 +1582,9 @@ public class AccessibilityInjectorTest extends AndroidTestCase { */ private void disableAccessibilityAndMockAccessibilityService() { // disable accessibility and the mock accessibility service Settings.Secure.putInt(getContext().getContentResolver(), Settings.Secure.putInt(getActivity().getContentResolver(), Settings.Secure.ACCESSIBILITY_ENABLED, 0); Settings.Secure.putString(getContext().getContentResolver(), Settings.Secure.putString(getActivity().getContentResolver(), Settings.Secure.ENABLED_ACCESSIBILITY_SERVICES, ""); } Loading Loading @@ -1391,16 +1627,16 @@ public class AccessibilityInjectorTest extends AndroidTestCase { } /** * Creates a {@link WebView} with with a given HTML content. * Loads HTML content in a {@link WebView}. * * @param html The HTML content; * @return The created view. * @return The {@link WebView} view. */ private WebView createWebVewWithHtml(final String html) { private WebView loadHTML(final String html) { mWorker.getHandler().post(new Runnable() { public void run() { mWebView = new WebView(getContext()); mWebView.loadData(html, "text/html", "utf-8"); if (mWebView == null) { mWebView = getActivity().getWebView(); mWebView.setWebViewClient(new WebViewClient() { @Override public void onPageFinished(WebView view, String url) { Loading @@ -1414,6 +1650,8 @@ public class AccessibilityInjectorTest extends AndroidTestCase { } }); } mWebView.loadData(html, "text/html", "utf-8"); } }); synchronized (sTestLock) { try { Loading @@ -1430,7 +1668,7 @@ public class AccessibilityInjectorTest extends AndroidTestCase { * to ensure that this test will be agnostic to changes of the bindings. */ private void injectTestWebContentKeyBindings() { ContentResolver contentResolver = getContext().getContentResolver(); ContentResolver contentResolver = getActivity().getContentResolver(); mDefaultKeyBindings = Settings.Secure.getString(contentResolver, Settings.Secure.ACCESSIBILITY_WEB_CONTENT_KEY_BINDINGS); Settings.Secure.putString(contentResolver, Loading @@ -1441,7 +1679,7 @@ public class AccessibilityInjectorTest extends AndroidTestCase { * Restores the default web content key bindings. */ private void restoreDefaultWebContentKeyBindings() { Settings.Secure.putString(getContext().getContentResolver(), Settings.Secure.putString(getActivity().getContentResolver(), Settings.Secure.ACCESSIBILITY_WEB_CONTENT_KEY_BINDINGS, mDefaultKeyBindings); } Loading
core/tests/coretests/src/android/webkit/AccessibilityInjectorTestActivity.java 0 → 100644 +38 −0 Original line number Diff line number Diff line /* * Copyright (C) 2011 The Android Open Source Project * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package android.webkit; import com.android.frameworks.coretests.R; import android.app.Activity; import android.os.Bundle; public class AccessibilityInjectorTestActivity extends Activity { private WebView mWebView; @Override public void onCreate(Bundle icicle) { super.onCreate(icicle); setContentView(R.layout.accessibility_injector_test); mWebView = (WebView) findViewById(R.id.webview); } public WebView getWebView() { return mWebView; } }