| Index: content/public/android/javatests/src/org/chromium/content/browser/webcontents/AccessibilitySnapshotTest.java
|
| diff --git a/content/public/android/javatests/src/org/chromium/content/browser/webcontents/AccessibilitySnapshotTest.java b/content/public/android/javatests/src/org/chromium/content/browser/webcontents/AccessibilitySnapshotTest.java
|
| index 633470ae2b138029255bb192a9f2985699bd4401..ab54db8d68ed02fc3695ffe990f6ceaf859bc7f3 100644
|
| --- a/content/public/android/javatests/src/org/chromium/content/browser/webcontents/AccessibilitySnapshotTest.java
|
| +++ b/content/public/android/javatests/src/org/chromium/content/browser/webcontents/AccessibilitySnapshotTest.java
|
| @@ -1,4 +1,4 @@
|
| -// Copyright 2016 The Chromium Authors. All rights reserved.
|
| +// Copyright 2017 The Chromium Authors. All rights reserved.
|
| // Use of this source code is governed by a BSD-style license that can be
|
| // found in the LICENSE file.
|
|
|
| @@ -6,17 +6,29 @@ package org.chromium.content.browser.webcontents;
|
|
|
| import android.support.test.filters.SmallTest;
|
|
|
| +import org.junit.Assert;
|
| +import org.junit.Rule;
|
| +import org.junit.Test;
|
| +import org.junit.runner.RunWith;
|
| +
|
| +import org.chromium.base.test.BaseJUnit4ClassRunner;
|
| import org.chromium.base.test.util.CallbackHelper;
|
| import org.chromium.base.test.util.UrlUtils;
|
| import org.chromium.content.browser.test.util.JavaScriptUtils;
|
| import org.chromium.content_public.browser.AccessibilitySnapshotCallback;
|
| import org.chromium.content_public.browser.AccessibilitySnapshotNode;
|
| -import org.chromium.content_shell_apk.ContentShellTestBase;
|
| +import org.chromium.content_shell_apk.ContentShellActivityTestRule;
|
|
|
| /**
|
| * Accessibility snapshot tests for Assist feature.
|
| */
|
| -public class AccessibilitySnapshotTest extends ContentShellTestBase {
|
| +@RunWith(BaseJUnit4ClassRunner.class)
|
| +public class AccessibilitySnapshotTest {
|
| + private static final double ASSERTION_DELTA = 0.00000001;
|
| +
|
| + @Rule
|
| + public ContentShellActivityTestRule mActivityTestRule = new ContentShellActivityTestRule();
|
| +
|
| private static class AccessibilityCallbackHelper extends CallbackHelper {
|
| private AccessibilitySnapshotNode mRoot;
|
|
|
| @@ -32,10 +44,11 @@ public class AccessibilitySnapshotTest extends ContentShellTestBase {
|
|
|
| private AccessibilitySnapshotNode receiveAccessibilitySnapshot(String data, String js)
|
| throws Throwable {
|
| - launchContentShellWithUrl(UrlUtils.encodeHtmlDataUri(data));
|
| - waitForActiveShellToBeDoneLoading();
|
| + mActivityTestRule.launchContentShellWithUrl(UrlUtils.encodeHtmlDataUri(data));
|
| + mActivityTestRule.waitForActiveShellToBeDoneLoading();
|
| if (js != null) {
|
| - JavaScriptUtils.executeJavaScriptAndWaitForResult(getWebContents(), js);
|
| + JavaScriptUtils.executeJavaScriptAndWaitForResult(
|
| + mActivityTestRule.getWebContents(), js);
|
| }
|
|
|
| final AccessibilityCallbackHelper callbackHelper = new AccessibilityCallbackHelper();
|
| @@ -48,10 +61,10 @@ public class AccessibilitySnapshotTest extends ContentShellTestBase {
|
| // read the callbackcount before executing the call on UI thread, since it may
|
| // synchronously complete.
|
| final int callbackCount = callbackHelper.getCallCount();
|
| - runTestOnUiThread(new Runnable() {
|
| + mActivityTestRule.runOnUiThread(new Runnable() {
|
| @Override
|
| public void run() {
|
| - getWebContents().requestAccessibilitySnapshot(callback);
|
| + mActivityTestRule.getWebContents().requestAccessibilitySnapshot(callback);
|
| }
|
| });
|
| callbackHelper.waitForCallback(callbackCount);
|
| @@ -61,117 +74,125 @@ public class AccessibilitySnapshotTest extends ContentShellTestBase {
|
| /**
|
| * Verifies that AX tree is returned.
|
| */
|
| + @Test
|
| @SmallTest
|
| public void testRequestAccessibilitySnapshot() throws Throwable {
|
| final String data = "<button>Click</button>";
|
| AccessibilitySnapshotNode root = receiveAccessibilitySnapshot(data, null);
|
| - assertEquals(1, root.children.size());
|
| - assertEquals("", root.text);
|
| + Assert.assertEquals(1, root.children.size());
|
| + Assert.assertEquals("", root.text);
|
| AccessibilitySnapshotNode child = root.children.get(0);
|
| - assertEquals(1, child.children.size());
|
| - assertEquals("", child.text);
|
| + Assert.assertEquals(1, child.children.size());
|
| + Assert.assertEquals("", child.text);
|
| AccessibilitySnapshotNode grandChild = child.children.get(0);
|
| - assertEquals(0, grandChild.children.size());
|
| - assertEquals("Click", grandChild.text);
|
| + Assert.assertEquals(0, grandChild.children.size());
|
| + Assert.assertEquals("Click", grandChild.text);
|
| }
|
|
|
| + @Test
|
| @SmallTest
|
| public void testRequestAccessibilitySnapshotColors() throws Throwable {
|
| final String data = "<p style=\"color:#123456;background:#abcdef\">color</p>";
|
| AccessibilitySnapshotNode root = receiveAccessibilitySnapshot(data, null);
|
| - assertEquals(1, root.children.size());
|
| - assertEquals("", root.text);
|
| + Assert.assertEquals(1, root.children.size());
|
| + Assert.assertEquals("", root.text);
|
| AccessibilitySnapshotNode child = root.children.get(0);
|
| - assertEquals("color", child.text);
|
| - assertTrue(child.hasStyle);
|
| - assertEquals("ff123456", Integer.toHexString(child.color));
|
| - assertEquals("ffabcdef", Integer.toHexString(child.bgcolor));
|
| + Assert.assertEquals("color", child.text);
|
| + Assert.assertTrue(child.hasStyle);
|
| + Assert.assertEquals("ff123456", Integer.toHexString(child.color));
|
| + Assert.assertEquals("ffabcdef", Integer.toHexString(child.bgcolor));
|
| }
|
|
|
| + @Test
|
| @SmallTest
|
| public void testRequestAccessibilitySnapshotFontSize() throws Throwable {
|
| final String data = "<html><head><style> "
|
| + " p { font-size:16px; transform: scale(2); }"
|
| + " </style></head><body><p>foo</p></body></html>";
|
| AccessibilitySnapshotNode root = receiveAccessibilitySnapshot(data, null);
|
| - assertEquals(1, root.children.size());
|
| - assertEquals("", root.text);
|
| + Assert.assertEquals(1, root.children.size());
|
| + Assert.assertEquals("", root.text);
|
| AccessibilitySnapshotNode child = root.children.get(0);
|
| - assertTrue(child.hasStyle);
|
| - assertEquals("foo", child.text);
|
| + Assert.assertTrue(child.hasStyle);
|
| + Assert.assertEquals("foo", child.text);
|
|
|
| // The font size should take the scale into account.
|
| - assertEquals(32.0, child.textSize, 1.0);
|
| + Assert.assertEquals(32.0, child.textSize, 1.0);
|
| }
|
|
|
| + @Test
|
| @SmallTest
|
| public void testRequestAccessibilitySnapshotStyles() throws Throwable {
|
| final String data = "<html><head><style> "
|
| + " body { font: italic bold 12px Courier; }"
|
| + " </style></head><body><p>foo</p></body></html>";
|
| AccessibilitySnapshotNode root = receiveAccessibilitySnapshot(data, null);
|
| - assertEquals(1, root.children.size());
|
| - assertEquals("", root.text);
|
| + Assert.assertEquals(1, root.children.size());
|
| + Assert.assertEquals("", root.text);
|
| AccessibilitySnapshotNode child = root.children.get(0);
|
| - assertEquals("foo", child.text);
|
| - assertTrue(child.hasStyle);
|
| - assertTrue(child.bold);
|
| - assertTrue(child.italic);
|
| - assertFalse(child.lineThrough);
|
| - assertFalse(child.underline);
|
| + Assert.assertEquals("foo", child.text);
|
| + Assert.assertTrue(child.hasStyle);
|
| + Assert.assertTrue(child.bold);
|
| + Assert.assertTrue(child.italic);
|
| + Assert.assertFalse(child.lineThrough);
|
| + Assert.assertFalse(child.underline);
|
| }
|
|
|
| + @Test
|
| @SmallTest
|
| public void testRequestAccessibilitySnapshotStrongStyle() throws Throwable {
|
| final String data = "<html><body><p>foo</p><p><strong>bar</strong></p></body></html>";
|
| AccessibilitySnapshotNode root = receiveAccessibilitySnapshot(data, null);
|
| - assertEquals(2, root.children.size());
|
| - assertEquals("", root.text);
|
| + Assert.assertEquals(2, root.children.size());
|
| + Assert.assertEquals("", root.text);
|
| AccessibilitySnapshotNode child1 = root.children.get(0);
|
| - assertEquals("foo", child1.text);
|
| - assertTrue(child1.hasStyle);
|
| - assertFalse(child1.bold);
|
| + Assert.assertEquals("foo", child1.text);
|
| + Assert.assertTrue(child1.hasStyle);
|
| + Assert.assertFalse(child1.bold);
|
| AccessibilitySnapshotNode child2 = root.children.get(1);
|
| AccessibilitySnapshotNode child2child = child2.children.get(0);
|
| - assertEquals("bar", child2child.text);
|
| - assertEquals(child1.textSize, child2child.textSize);
|
| - assertTrue(child2child.bold);
|
| + Assert.assertEquals("bar", child2child.text);
|
| + Assert.assertEquals(child1.textSize, child2child.textSize, ASSERTION_DELTA);
|
| + Assert.assertTrue(child2child.bold);
|
| }
|
|
|
| + @Test
|
| @SmallTest
|
| public void testRequestAccessibilitySnapshotItalicStyle() throws Throwable {
|
| final String data = "<html><body><i>foo</i></body></html>";
|
| AccessibilitySnapshotNode root = receiveAccessibilitySnapshot(data, null);
|
| - assertEquals(1, root.children.size());
|
| - assertEquals("", root.text);
|
| + Assert.assertEquals(1, root.children.size());
|
| + Assert.assertEquals("", root.text);
|
| AccessibilitySnapshotNode child = root.children.get(0);
|
| AccessibilitySnapshotNode grandchild = child.children.get(0);
|
| - assertEquals("foo", grandchild.text);
|
| - assertTrue(grandchild.hasStyle);
|
| - assertTrue(grandchild.italic);
|
| + Assert.assertEquals("foo", grandchild.text);
|
| + Assert.assertTrue(grandchild.hasStyle);
|
| + Assert.assertTrue(grandchild.italic);
|
| }
|
|
|
| + @Test
|
| @SmallTest
|
| public void testRequestAccessibilitySnapshotBoldStyle() throws Throwable {
|
| final String data = "<html><body><b>foo</b></body></html>";
|
| AccessibilitySnapshotNode root = receiveAccessibilitySnapshot(data, null);
|
| - assertEquals(1, root.children.size());
|
| - assertEquals("", root.text);
|
| + Assert.assertEquals(1, root.children.size());
|
| + Assert.assertEquals("", root.text);
|
| AccessibilitySnapshotNode child = root.children.get(0);
|
| AccessibilitySnapshotNode grandchild = child.children.get(0);
|
| - assertEquals("foo", grandchild.text);
|
| - assertTrue(grandchild.hasStyle);
|
| - assertTrue(grandchild.bold);
|
| + Assert.assertEquals("foo", grandchild.text);
|
| + Assert.assertTrue(grandchild.hasStyle);
|
| + Assert.assertTrue(grandchild.bold);
|
| }
|
|
|
| + @Test
|
| @SmallTest
|
| public void testRequestAccessibilitySnapshotNoStyle() throws Throwable {
|
| final String data = "<table><thead></thead></table>";
|
| AccessibilitySnapshotNode root = receiveAccessibilitySnapshot(data, null);
|
| - assertEquals(1, root.children.size());
|
| - assertEquals("", root.text);
|
| + Assert.assertEquals(1, root.children.size());
|
| + Assert.assertEquals("", root.text);
|
| AccessibilitySnapshotNode grandChild = root.children.get(0).children.get(0);
|
| - assertFalse(grandChild.hasStyle);
|
| + Assert.assertFalse(grandChild.hasStyle);
|
| }
|
|
|
| private String getSelectionScript(String node1, int start, String node2, int end) {
|
| @@ -187,55 +208,60 @@ public class AccessibilitySnapshotTest extends ContentShellTestBase {
|
| + "selection.addRange(range);";
|
| }
|
|
|
| + @Test
|
| @SmallTest
|
| public void testRequestAccessibilitySnapshotOneCharacterSelection() throws Throwable {
|
| final String data = "<html><body><b id='node'>foo</b></body></html>";
|
|
|
| AccessibilitySnapshotNode root =
|
| receiveAccessibilitySnapshot(data, getSelectionScript("node", 0, "node", 1));
|
| - assertEquals(1, root.children.size());
|
| - assertEquals("", root.text);
|
| + Assert.assertEquals(1, root.children.size());
|
| + Assert.assertEquals("", root.text);
|
| AccessibilitySnapshotNode child = root.children.get(0);
|
| AccessibilitySnapshotNode grandchild = child.children.get(0);
|
| - assertEquals("foo", grandchild.text);
|
| - assertEquals(0, grandchild.startSelection);
|
| - assertEquals(1, grandchild.endSelection);
|
| + Assert.assertEquals("foo", grandchild.text);
|
| + Assert.assertEquals(0, grandchild.startSelection);
|
| + Assert.assertEquals(1, grandchild.endSelection);
|
| }
|
|
|
| + @Test
|
| +
|
| @SmallTest
|
| public void testRequestAccessibilitySnapshotOneNodeSelection() throws Throwable {
|
| final String data = "<html><body><b id='node'>foo</b></body></html>";
|
|
|
| AccessibilitySnapshotNode root =
|
| receiveAccessibilitySnapshot(data, getSelectionScript("node", 0, "node", 3));
|
| - assertEquals(1, root.children.size());
|
| - assertEquals("", root.text);
|
| + Assert.assertEquals(1, root.children.size());
|
| + Assert.assertEquals("", root.text);
|
| AccessibilitySnapshotNode child = root.children.get(0);
|
| AccessibilitySnapshotNode grandchild = child.children.get(0);
|
| - assertEquals("foo", grandchild.text);
|
| - assertEquals(0, grandchild.startSelection);
|
| - assertEquals(3, grandchild.endSelection);
|
| + Assert.assertEquals("foo", grandchild.text);
|
| + Assert.assertEquals(0, grandchild.startSelection);
|
| + Assert.assertEquals(3, grandchild.endSelection);
|
| }
|
|
|
| + @Test
|
| @SmallTest
|
| public void testRequestAccessibilitySnapshotSubsequentNodeSelection() throws Throwable {
|
| final String data = "<html><body><b id='node1'>foo</b><b id='node2'>bar</b></body></html>";
|
|
|
| AccessibilitySnapshotNode root =
|
| receiveAccessibilitySnapshot(data, getSelectionScript("node1", 1, "node2", 1));
|
| - assertEquals(1, root.children.size());
|
| - assertEquals("", root.text);
|
| + Assert.assertEquals(1, root.children.size());
|
| + Assert.assertEquals("", root.text);
|
| AccessibilitySnapshotNode child = root.children.get(0);
|
| AccessibilitySnapshotNode grandchild = child.children.get(0);
|
| - assertEquals("foo", grandchild.text);
|
| - assertEquals(1, grandchild.startSelection);
|
| - assertEquals(3, grandchild.endSelection);
|
| + Assert.assertEquals("foo", grandchild.text);
|
| + Assert.assertEquals(1, grandchild.startSelection);
|
| + Assert.assertEquals(3, grandchild.endSelection);
|
| grandchild = child.children.get(1);
|
| - assertEquals("bar", grandchild.text);
|
| - assertEquals(0, grandchild.startSelection);
|
| - assertEquals(1, grandchild.endSelection);
|
| + Assert.assertEquals("bar", grandchild.text);
|
| + Assert.assertEquals(0, grandchild.startSelection);
|
| + Assert.assertEquals(1, grandchild.endSelection);
|
| }
|
|
|
| + @Test
|
| @SmallTest
|
| public void testRequestAccessibilitySnapshotMultiNodeSelection() throws Throwable {
|
| final String data =
|
| @@ -243,23 +269,24 @@ public class AccessibilitySnapshotTest extends ContentShellTestBase {
|
|
|
| AccessibilitySnapshotNode root =
|
| receiveAccessibilitySnapshot(data, getSelectionScript("node1", 1, "node2", 1));
|
| - assertEquals(1, root.children.size());
|
| - assertEquals("", root.text);
|
| + Assert.assertEquals(1, root.children.size());
|
| + Assert.assertEquals("", root.text);
|
| AccessibilitySnapshotNode child = root.children.get(0);
|
| AccessibilitySnapshotNode grandchild = child.children.get(0);
|
| - assertEquals("foo", grandchild.text);
|
| - assertEquals(1, grandchild.startSelection);
|
| - assertEquals(3, grandchild.endSelection);
|
| + Assert.assertEquals("foo", grandchild.text);
|
| + Assert.assertEquals(1, grandchild.startSelection);
|
| + Assert.assertEquals(3, grandchild.endSelection);
|
| grandchild = child.children.get(1);
|
| - assertEquals("middle", grandchild.text);
|
| - assertEquals(0, grandchild.startSelection);
|
| - assertEquals(6, grandchild.endSelection);
|
| + Assert.assertEquals("middle", grandchild.text);
|
| + Assert.assertEquals(0, grandchild.startSelection);
|
| + Assert.assertEquals(6, grandchild.endSelection);
|
| grandchild = child.children.get(2);
|
| - assertEquals("bar", grandchild.text);
|
| - assertEquals(0, grandchild.startSelection);
|
| - assertEquals(1, grandchild.endSelection);
|
| + Assert.assertEquals("bar", grandchild.text);
|
| + Assert.assertEquals(0, grandchild.startSelection);
|
| + Assert.assertEquals(1, grandchild.endSelection);
|
| }
|
|
|
| + @Test
|
| @SmallTest
|
| public void testRequestAccessibilitySnapshotInputSelection() throws Throwable {
|
| final String data = "<html><body><input id='input' value='Hello, world'></body></html>";
|
| @@ -268,24 +295,25 @@ public class AccessibilitySnapshotTest extends ContentShellTestBase {
|
| + "input.selectionStart = 0;"
|
| + "input.selectionEnd = 5;";
|
| AccessibilitySnapshotNode root = receiveAccessibilitySnapshot(data, js);
|
| - assertEquals(1, root.children.size());
|
| - assertEquals("", root.text);
|
| + Assert.assertEquals(1, root.children.size());
|
| + Assert.assertEquals("", root.text);
|
| AccessibilitySnapshotNode child = root.children.get(0);
|
| AccessibilitySnapshotNode grandchild = child.children.get(0);
|
| - assertEquals("Hello, world", grandchild.text);
|
| - assertEquals(0, grandchild.startSelection);
|
| - assertEquals(5, grandchild.endSelection);
|
| + Assert.assertEquals("Hello, world", grandchild.text);
|
| + Assert.assertEquals(0, grandchild.startSelection);
|
| + Assert.assertEquals(5, grandchild.endSelection);
|
| }
|
|
|
| + @Test
|
| @SmallTest
|
| public void testRequestAccessibilitySnapshotPasswordField() throws Throwable {
|
| final String data =
|
| "<html><body><input id='input' type='password' value='foo'></body></html>";
|
| AccessibilitySnapshotNode root = receiveAccessibilitySnapshot(data, null);
|
| - assertEquals(1, root.children.size());
|
| - assertEquals("", root.text);
|
| + Assert.assertEquals(1, root.children.size());
|
| + Assert.assertEquals("", root.text);
|
| AccessibilitySnapshotNode child = root.children.get(0);
|
| AccessibilitySnapshotNode grandchild = child.children.get(0);
|
| - assertEquals("•••", grandchild.text);
|
| + Assert.assertEquals("•••", grandchild.text);
|
| }
|
| }
|
|
|