summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author Felipe Leme <felipeal@google.com> 2019-02-07 20:22:33 +0000
committer Android (Google) Code Review <android-gerrit@google.com> 2019-02-07 20:22:33 +0000
commit8f5ef4518f30a219538a3b055b0f22be4340d1f3 (patch)
treedd8e8b5b58fc9b7a3f252d5faa9196471881f80b
parent6f82297cb1c3fbb740ae91d2d5e59603f67b1e84 (diff)
parentf38d414e093f5a85c9f3800a739d7ba695771ee6 (diff)
Merge "Made moar ContentCapture APIs available for testing."
-rw-r--r--api/test-current.txt62
-rw-r--r--core/java/android/view/autofill/AutofillId.java2
-rw-r--r--core/java/android/view/contentcapture/ViewNode.java14
-rw-r--r--core/tests/coretests/src/android/view/contentcapture/UserDataRemovalRequestTest.java88
-rw-r--r--core/tests/coretests/src/android/view/contentcapture/ViewNodeTest.java376
5 files changed, 74 insertions, 468 deletions
diff --git a/api/test-current.txt b/api/test-current.txt
index f9d04eee3e56..1f351d566b84 100644
--- a/api/test-current.txt
+++ b/api/test-current.txt
@@ -2669,6 +2669,8 @@ package android.view.autofill {
public final class AutofillId implements android.os.Parcelable {
ctor public AutofillId(int);
ctor public AutofillId(@NonNull android.view.autofill.AutofillId, int);
+ ctor public AutofillId(int, int);
+ ctor public AutofillId(@NonNull android.view.autofill.AutofillId, long, int);
}
public final class AutofillManager {
@@ -2718,6 +2720,66 @@ package android.view.contentcapture {
public final class ViewNode extends android.app.assist.AssistStructure.ViewNode {
method @Nullable public android.view.autofill.AutofillId getParentAutofillId();
+ method @Nullable public static android.view.contentcapture.ViewNode readFromParcel(@NonNull android.os.Parcel);
+ method public static void writeToParcel(@NonNull android.os.Parcel, @Nullable android.view.contentcapture.ViewNode, int);
+ }
+
+ public static final class ViewNode.ViewStructureImpl extends android.view.ViewStructure {
+ ctor public ViewNode.ViewStructureImpl(@NonNull android.view.View);
+ ctor public ViewNode.ViewStructureImpl(@NonNull android.view.autofill.AutofillId, long, int);
+ method public int addChildCount(int);
+ method public void asyncCommit();
+ method public android.view.ViewStructure asyncNewChild(int);
+ method public android.view.autofill.AutofillId getAutofillId();
+ method public int getChildCount();
+ method public android.os.Bundle getExtras();
+ method public CharSequence getHint();
+ method public android.view.contentcapture.ViewNode getNode();
+ method public android.graphics.Rect getTempRect();
+ method public CharSequence getText();
+ method public int getTextSelectionEnd();
+ method public int getTextSelectionStart();
+ method public boolean hasExtras();
+ method public android.view.ViewStructure newChild(int);
+ method public android.view.ViewStructure.HtmlInfo.Builder newHtmlInfoBuilder(String);
+ method public void setAccessibilityFocused(boolean);
+ method public void setActivated(boolean);
+ method public void setAlpha(float);
+ method public void setAssistBlocked(boolean);
+ method public void setAutofillHints(String[]);
+ method public void setAutofillId(android.view.autofill.AutofillId);
+ method public void setAutofillId(android.view.autofill.AutofillId, int);
+ method public void setAutofillOptions(CharSequence[]);
+ method public void setAutofillType(int);
+ method public void setAutofillValue(android.view.autofill.AutofillValue);
+ method public void setCheckable(boolean);
+ method public void setChecked(boolean);
+ method public void setChildCount(int);
+ method public void setClassName(String);
+ method public void setClickable(boolean);
+ method public void setContentDescription(CharSequence);
+ method public void setContextClickable(boolean);
+ method public void setDataIsSensitive(boolean);
+ method public void setDimens(int, int, int, int, int, int);
+ method public void setElevation(float);
+ method public void setEnabled(boolean);
+ method public void setFocusable(boolean);
+ method public void setFocused(boolean);
+ method public void setHint(CharSequence);
+ method public void setHtmlInfo(android.view.ViewStructure.HtmlInfo);
+ method public void setId(int, String, String, String);
+ method public void setInputType(int);
+ method public void setLocaleList(android.os.LocaleList);
+ method public void setLongClickable(boolean);
+ method public void setOpaque(boolean);
+ method public void setSelected(boolean);
+ method public void setText(CharSequence);
+ method public void setText(CharSequence, int, int);
+ method public void setTextLines(int[], int[]);
+ method public void setTextStyle(float, int, int, int);
+ method public void setTransformation(android.graphics.Matrix);
+ method public void setVisibility(int);
+ method public void setWebDomain(String);
}
}
diff --git a/core/java/android/view/autofill/AutofillId.java b/core/java/android/view/autofill/AutofillId.java
index f1c7b695ce05..5608bb372701 100644
--- a/core/java/android/view/autofill/AutofillId.java
+++ b/core/java/android/view/autofill/AutofillId.java
@@ -52,11 +52,13 @@ public final class AutofillId implements Parcelable {
}
/** @hide */
+ @TestApi
public AutofillId(int parentId, int virtualChildId) {
this(FLAG_IS_VIRTUAL_INT, parentId, virtualChildId, NO_SESSION);
}
/** @hide */
+ @TestApi
public AutofillId(@NonNull AutofillId parent, long virtualChildId, int sessionId) {
this(FLAG_IS_VIRTUAL_LONG | FLAG_HAS_SESSION, parent.mViewId, virtualChildId, sessionId);
}
diff --git a/core/java/android/view/contentcapture/ViewNode.java b/core/java/android/view/contentcapture/ViewNode.java
index 924bb9a7d853..8d6245458d62 100644
--- a/core/java/android/view/contentcapture/ViewNode.java
+++ b/core/java/android/view/contentcapture/ViewNode.java
@@ -34,7 +34,6 @@ import android.view.ViewStructure.HtmlInfo.Builder;
import android.view.autofill.AutofillId;
import android.view.autofill.AutofillValue;
-import com.android.internal.annotations.VisibleForTesting;
import com.android.internal.util.Preconditions;
//TODO(b/122484602): add javadocs / implement Parcelable / implement
@@ -589,6 +588,7 @@ public final class ViewNode extends AssistStructure.ViewNode {
}
/** @hide */
+ @TestApi
public static void writeToParcel(@NonNull Parcel parcel, @Nullable ViewNode node, int flags) {
if (node == null) {
parcel.writeLong(0);
@@ -598,18 +598,20 @@ public final class ViewNode extends AssistStructure.ViewNode {
}
/** @hide */
+ @TestApi
public static @Nullable ViewNode readFromParcel(@NonNull Parcel parcel) {
final long nodeFlags = parcel.readLong();
return nodeFlags == 0 ? null : new ViewNode(nodeFlags, parcel);
}
/** @hide */
- @VisibleForTesting // Must be public to be accessed from FrameworkCoreTests' apk.
+ @TestApi
public static final class ViewStructureImpl extends ViewStructure {
final ViewNode mNode = new ViewNode();
- @VisibleForTesting // Must be public to be accessed from FrameworkCoreTests' apk.
+ /** @hide */
+ @TestApi
public ViewStructureImpl(@NonNull View view) {
mNode.mAutofillId = Preconditions.checkNotNull(view).getAutofillId();
final ViewParent parent = view.getParent();
@@ -618,13 +620,15 @@ public final class ViewNode extends AssistStructure.ViewNode {
}
}
- @VisibleForTesting // Must be public to be accessed from FrameworkCoreTests' apk.
+ /** @hide */
+ @TestApi
public ViewStructureImpl(@NonNull AutofillId parentId, long virtualId, int sessionId) {
mNode.mParentAutofillId = Preconditions.checkNotNull(parentId);
mNode.mAutofillId = new AutofillId(parentId, virtualId, sessionId);
}
- @VisibleForTesting // Must be public to be accessed from FrameworkCoreTests' apk.
+ /** @hide */
+ @TestApi
public ViewNode getNode() {
return mNode;
}
diff --git a/core/tests/coretests/src/android/view/contentcapture/UserDataRemovalRequestTest.java b/core/tests/coretests/src/android/view/contentcapture/UserDataRemovalRequestTest.java
deleted file mode 100644
index bebb2a89f480..000000000000
--- a/core/tests/coretests/src/android/view/contentcapture/UserDataRemovalRequestTest.java
+++ /dev/null
@@ -1,88 +0,0 @@
-/*
- * Copyright (C) 2019 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.view.contentcapture;
-
-import static com.google.common.truth.Truth.assertThat;
-
-import static org.testng.Assert.assertThrows;
-
-import android.net.Uri;
-
-import org.junit.Test;
-import org.junit.runner.RunWith;
-import org.mockito.Mock;
-import org.mockito.junit.MockitoJUnitRunner;
-
-/**
- * Unit test for {@link UserDataRemovalRequest}.
- *
- * <p>To run it:
- * {@code atest FrameworksCoreTests:android.view.contentcapture.UserDataRemovalRequestTest}
- */
-@RunWith(MockitoJUnitRunner.class)
-public class UserDataRemovalRequestTest {
-
- @Mock
- private final Uri mUri = Uri.parse("content://com.example/");
-
- private UserDataRemovalRequest.Builder mBuilder = new UserDataRemovalRequest.Builder();
-
- @Test
- public void testBuilder_addUri_invalid() {
- assertThrows(NullPointerException.class, () -> mBuilder.addUri(null, false));
- }
-
- @Test
- public void testBuilder_addUri_valid() {
- assertThat(mBuilder.addUri(mUri, false)).isNotNull();
- assertThat(mBuilder.addUri(Uri.parse("content://com.example2"), true)).isNotNull();
- }
-
- @Test
- public void testBuilder_addUriAfterForEverything() {
- assertThat(mBuilder.forEverything()).isNotNull();
- assertThrows(IllegalStateException.class, () -> mBuilder.addUri(mUri, false));
- }
-
- @Test
- public void testBuilder_forEverythingAfterAddingUri() {
- assertThat(mBuilder.addUri(mUri, false)).isNotNull();
- assertThrows(IllegalStateException.class, () -> mBuilder.forEverything());
- }
-
- @Test
- public void testBuild_invalid() {
- assertThrows(IllegalStateException.class, () -> mBuilder.build());
- }
-
- @Test
- public void testBuild_valid() {
- assertThat(new UserDataRemovalRequest.Builder().forEverything().build())
- .isNotNull();
- assertThat(new UserDataRemovalRequest.Builder().addUri(mUri, false).build())
- .isNotNull();
- }
-
- @Test
- public void testNoMoreInteractionsAfterBuild() {
- assertThat(mBuilder.forEverything().build()).isNotNull();
-
- assertThrows(IllegalStateException.class, () -> mBuilder.addUri(mUri, false));
- assertThrows(IllegalStateException.class, () -> mBuilder.forEverything());
- assertThrows(IllegalStateException.class, () -> mBuilder.build());
-
- }
-}
diff --git a/core/tests/coretests/src/android/view/contentcapture/ViewNodeTest.java b/core/tests/coretests/src/android/view/contentcapture/ViewNodeTest.java
index b84a098574c2..213cd405e903 100644
--- a/core/tests/coretests/src/android/view/contentcapture/ViewNodeTest.java
+++ b/core/tests/coretests/src/android/view/contentcapture/ViewNodeTest.java
@@ -18,29 +18,18 @@ package android.view.contentcapture;
import static com.google.common.truth.Truth.assertThat;
-import static org.testng.Assert.assertThrows;
-
import android.content.Context;
import android.graphics.Matrix;
-import android.os.Bundle;
-import android.os.LocaleList;
-import android.os.Parcel;
+import android.support.test.InstrumentationRegistry;
import android.view.View;
import android.view.ViewStructure.HtmlInfo;
-import android.view.autofill.AutofillId;
-import android.view.autofill.AutofillValue;
import android.view.contentcapture.ViewNode.ViewStructureImpl;
-import android.widget.FrameLayout;
-
-import androidx.test.InstrumentationRegistry;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.junit.MockitoJUnitRunner;
-import java.util.Locale;
-
/**
* Unit tests for {@link ViewNode}.
*
@@ -55,100 +44,6 @@ public class ViewNodeTest {
private HtmlInfo mHtmlInfoMock;
@Test
- public void testAutofillIdMethods_orphanView() {
- View view = new View(mContext);
- AutofillId initialId = new AutofillId(42);
- view.setAutofillId(initialId);
-
- ViewStructureImpl structure = new ViewStructureImpl(view);
- ViewNode node = structure.getNode();
-
- assertThat(node.getAutofillId()).isEqualTo(initialId);
- assertThat(node.getParentAutofillId()).isNull();
-
- AutofillId newId = new AutofillId(108);
- structure.setAutofillId(newId);
- assertThat(node.getAutofillId()).isEqualTo(newId);
- assertThat(node.getParentAutofillId()).isNull();
-
- structure.setAutofillId(new AutofillId(66), 6);
- assertThat(node.getAutofillId()).isEqualTo(new AutofillId(66, 6));
- assertThat(node.getParentAutofillId()).isEqualTo(new AutofillId(66));
- }
-
- @Test
- public void testAutofillIdMethods_parentedView() {
- FrameLayout parent = new FrameLayout(mContext);
- AutofillId initialParentId = new AutofillId(48);
- parent.setAutofillId(initialParentId);
-
- View child = new View(mContext);
- AutofillId initialChildId = new AutofillId(42);
- child.setAutofillId(initialChildId);
-
- parent.addView(child);
-
- ViewStructureImpl structure = new ViewStructureImpl(child);
- ViewNode node = structure.getNode();
-
- assertThat(node.getAutofillId()).isEqualTo(initialChildId);
- assertThat(node.getParentAutofillId()).isEqualTo(initialParentId);
-
- AutofillId newChildId = new AutofillId(108);
- structure.setAutofillId(newChildId);
- assertThat(node.getAutofillId()).isEqualTo(newChildId);
- assertThat(node.getParentAutofillId()).isEqualTo(initialParentId);
-
- AutofillId newParentId = new AutofillId(15162342);
- parent.setAutofillId(newParentId);
- assertThat(node.getAutofillId()).isEqualTo(newChildId);
- assertThat(node.getParentAutofillId()).isEqualTo(initialParentId);
-
- structure.setAutofillId(new AutofillId(66), 6);
- assertThat(node.getAutofillId()).isEqualTo(new AutofillId(66, 6));
- assertThat(node.getParentAutofillId()).isEqualTo(new AutofillId(66));
- }
-
- @Test
- public void testAutofillIdMethods_explicitIdsConstructor() {
- AutofillId initialParentId = new AutofillId(42);
- ViewStructureImpl structure = new ViewStructureImpl(initialParentId, 108, 666);
- ViewNode node = structure.getNode();
-
- assertThat(node.getAutofillId()).isEqualTo(new AutofillId(initialParentId, 108, 666));
- assertThat(node.getParentAutofillId()).isEqualTo(initialParentId);
-
- AutofillId newChildId = new AutofillId(108);
- structure.setAutofillId(newChildId);
- assertThat(node.getAutofillId()).isEqualTo(newChildId);
- assertThat(node.getParentAutofillId()).isEqualTo(initialParentId);
-
- structure.setAutofillId(new AutofillId(66), 6);
- assertThat(node.getAutofillId()).isEqualTo(new AutofillId(66, 6));
- assertThat(node.getParentAutofillId()).isEqualTo(new AutofillId(66));
- }
-
- @Test
- public void testInvalidSetters() {
- View view = new View(mContext);
- AutofillId initialId = new AutofillId(42);
- view.setAutofillId(initialId);
-
- ViewStructureImpl structure = new ViewStructureImpl(view);
- ViewNode node = structure.getNode();
- assertThat(node.getAutofillId()).isEqualTo(initialId); // sanity check
-
- assertThrows(NullPointerException.class, () -> structure.setAutofillId(null));
- assertThat(node.getAutofillId()).isEqualTo(initialId); // invariant
-
- assertThrows(NullPointerException.class, () -> structure.setAutofillId(null, 666));
- assertThat(node.getAutofillId()).isEqualTo(initialId); // invariant
-
- assertThrows(NullPointerException.class, () -> structure.setTextIdEntry(null));
- assertThat(node.getTextIdEntry()).isNull();
- }
-
- @Test
public void testUnsupportedProperties() {
View view = new View(mContext);
@@ -190,273 +85,4 @@ public class ViewNodeTest {
structure.setTransformation(Matrix.IDENTITY_MATRIX);
assertThat(node.getTransformation()).isNull();
}
-
- @Test
- public void testValidProperties_directly() {
- ViewStructureImpl structure = newSimpleStructure();
- assertSimpleStructure(structure);
- assertSimpleNode(structure.getNode());
- }
-
- @Test
- public void testValidProperties_throughParcel() {
- ViewStructureImpl structure = newSimpleStructure();
- final ViewNode node = structure.getNode();
- assertSimpleNode(node); // sanity check
-
- final ViewNode clone = cloneThroughParcel(node);
- assertSimpleNode(clone);
- }
-
- @Test
- public void testComplexText_directly() {
- ViewStructureImpl structure = newStructureWithComplexText();
- assertStructureWithComplexText(structure);
- assertNodeWithComplexText(structure.getNode());
- }
-
- @Test
- public void testComplexText_throughParcel() {
- ViewStructureImpl structure = newStructureWithComplexText();
- final ViewNode node = structure.getNode();
- assertNodeWithComplexText(node); // sanity check
-
- ViewNode clone = cloneThroughParcel(node);
- assertNodeWithComplexText(clone);
- }
-
- @Test
- public void testVisibility() {
- // Visibility is a special case becase it use flag masks, so we want to make sure it works
- // fine
- View view = new View(mContext);
- ViewStructureImpl structure = new ViewStructureImpl(view);
- ViewNode node = structure.getNode();
-
- structure.setVisibility(View.VISIBLE);
- assertThat(node.getVisibility()).isEqualTo(View.VISIBLE);
- assertThat(cloneThroughParcel(node).getVisibility()).isEqualTo(View.VISIBLE);
-
- structure.setVisibility(View.GONE);
- assertThat(node.getVisibility()).isEqualTo(View.GONE);
- assertThat(cloneThroughParcel(node).getVisibility()).isEqualTo(View.GONE);
-
- structure.setVisibility(View.VISIBLE);
- assertThat(node.getVisibility()).isEqualTo(View.VISIBLE);
- assertThat(cloneThroughParcel(node).getVisibility()).isEqualTo(View.VISIBLE);
-
- structure.setVisibility(View.INVISIBLE);
- assertThat(node.getVisibility()).isEqualTo(View.INVISIBLE);
- assertThat(cloneThroughParcel(node).getVisibility()).isEqualTo(View.INVISIBLE);
-
- structure.setVisibility(View.INVISIBLE | View.GONE);
- assertThat(node.getVisibility()).isEqualTo(View.INVISIBLE | View.GONE);
- assertThat(cloneThroughParcel(node).getVisibility()).isEqualTo(View.INVISIBLE | View.GONE);
-
-
- final int invalidValue = Math.max(Math.max(View.VISIBLE, View.INVISIBLE), View.GONE) * 2;
- structure.setVisibility(View.VISIBLE);
- structure.setVisibility(invalidValue); // should be ignored
- assertThat(node.getVisibility()).isEqualTo(View.VISIBLE);
- assertThat(cloneThroughParcel(node).getVisibility()).isEqualTo(View.VISIBLE);
-
- structure.setVisibility(View.GONE | invalidValue);
- assertThat(node.getVisibility()).isEqualTo(View.GONE);
- assertThat(cloneThroughParcel(node).getVisibility()).isEqualTo(View.GONE);
- }
-
- /**
- * Creates a {@link ViewStructureImpl} that can be asserted through
- * {@link #assertSimpleNode(ViewNode)}.
- */
- private ViewStructureImpl newSimpleStructure() {
- View view = new View(mContext);
- view.setAutofillId(new AutofillId(42));
-
- ViewStructureImpl structure = new ViewStructureImpl(view);
-
- // Basic properties
- structure.setText("Text is set!");
- structure.setClassName("Classy!");
- structure.setContentDescription("Described I am!");
- structure.setVisibility(View.INVISIBLE);
-
- // Autofill properties
- structure.setAutofillType(View.AUTOFILL_TYPE_TEXT);
- structure.setAutofillHints(new String[] { "Auto", "Man" });
- structure.setAutofillOptions(new String[] { "Maybe" });
- structure.setAutofillValue(AutofillValue.forText("Malkovich"));
-
- // Extra text properties
- structure.setMinTextEms(6);
- structure.setMaxTextLength(66);
- structure.setMaxTextEms(666);
- structure.setInputType(42);
- structure.setTextIdEntry("TEXT, Y U NO ENTRY?");
- structure.setLocaleList(new LocaleList(Locale.US, Locale.ENGLISH));
-
- // Resource id
- structure.setId(16, "package.name", "type.name", "entry.name");
-
- // Dimensions
- structure.setDimens(4, 8, 15, 16, 23, 42);
-
- // Boolean properties
- structure.setAssistBlocked(true);
- structure.setEnabled(true);
- structure.setClickable(true);
- structure.setLongClickable(true);
- structure.setContextClickable(true);
- structure.setFocusable(true);
- structure.setFocused(true);
- structure.setAccessibilityFocused(true);
- structure.setChecked(true);
- structure.setActivated(true);
- structure.setOpaque(true);
-
- // Bundle
- assertThat(structure.hasExtras()).isFalse();
- final Bundle bundle = structure.getExtras();
- assertThat(bundle).isNotNull();
- bundle.putString("Marlon", "Bundle");
- assertThat(structure.hasExtras()).isTrue();
- return structure;
- }
-
- /**
- * Asserts the properties of a {@link ViewNode} that was created by
- * {@link #newSimpleStructure()}.
- */
- private void assertSimpleNode(ViewNode node) {
-
- // Basic properties
- assertThat(node.getAutofillId()).isEqualTo(new AutofillId(42));
- assertThat(node.getParentAutofillId()).isNull();
- assertThat(node.getText()).isEqualTo("Text is set!");
- assertThat(node.getClassName()).isEqualTo("Classy!");
- assertThat(node.getContentDescription().toString()).isEqualTo("Described I am!");
- assertThat(node.getVisibility()).isEqualTo(View.INVISIBLE);
-
- // Autofill properties
- assertThat(node.getAutofillType()).isEqualTo(View.AUTOFILL_TYPE_TEXT);
- assertThat(node.getAutofillHints()).asList().containsExactly("Auto", "Man").inOrder();
- assertThat(node.getAutofillOptions()).asList().containsExactly("Maybe").inOrder();
- assertThat(node.getAutofillValue().getTextValue()).isEqualTo("Malkovich");
-
- // Extra text properties
- assertThat(node.getMinTextEms()).isEqualTo(6);
- assertThat(node.getMaxTextLength()).isEqualTo(66);
- assertThat(node.getMaxTextEms()).isEqualTo(666);
- assertThat(node.getInputType()).isEqualTo(42);
- assertThat(node.getTextIdEntry()).isEqualTo("TEXT, Y U NO ENTRY?");
- assertThat(node.getLocaleList()).isEqualTo(new LocaleList(Locale.US, Locale.ENGLISH));
-
- // Resource id
- assertThat(node.getId()).isEqualTo(16);
- assertThat(node.getIdPackage()).isEqualTo("package.name");
- assertThat(node.getIdType()).isEqualTo("type.name");
- assertThat(node.getIdEntry()).isEqualTo("entry.name");
-
- // Dimensions
- assertThat(node.getLeft()).isEqualTo(4);
- assertThat(node.getTop()).isEqualTo(8);
- assertThat(node.getScrollX()).isEqualTo(15);
- assertThat(node.getScrollY()).isEqualTo(16);
- assertThat(node.getWidth()).isEqualTo(23);
- assertThat(node.getHeight()).isEqualTo(42);
-
- // Boolean properties
- assertThat(node.isAssistBlocked()).isTrue();
- assertThat(node.isEnabled()).isTrue();
- assertThat(node.isClickable()).isTrue();
- assertThat(node.isLongClickable()).isTrue();
- assertThat(node.isContextClickable()).isTrue();
- assertThat(node.isFocusable()).isTrue();
- assertThat(node.isFocused()).isTrue();
- assertThat(node.isAccessibilityFocused()).isTrue();
- assertThat(node.isChecked()).isTrue();
- assertThat(node.isActivated()).isTrue();
- assertThat(node.isOpaque()).isTrue();
-
- // Bundle
- final Bundle bundle = node.getExtras();
- assertThat(bundle).isNotNull();
- assertThat(bundle.size()).isEqualTo(1);
- assertThat(bundle.getString("Marlon")).isEqualTo("Bundle");
- }
-
- /**
- * Asserts the properties of a {@link ViewStructureImpl} that was created by
- * {@link #newSimpleStructure()}.
- */
- private void assertSimpleStructure(ViewStructureImpl structure) {
- assertThat(structure.getAutofillId()).isEqualTo(new AutofillId(42));
- assertThat(structure.getText()).isEqualTo("Text is set!");
-
- // Bundle
- final Bundle bundle = structure.getExtras();
- assertThat(bundle.size()).isEqualTo(1);
- assertThat(bundle.getString("Marlon")).isEqualTo("Bundle");
- }
-
- /**
- * Creates a {@link ViewStructureImpl} with "complex" text properties (such as selection); it
- * can be asserted through {@link #assertNodeWithComplexText(ViewNode)}.
- */
- private ViewStructureImpl newStructureWithComplexText() {
- View view = new View(mContext);
- ViewStructureImpl structure = new ViewStructureImpl(view);
- structure.setText("IGNORE ME!");
- structure.setText("Now we're talking!", 4, 8);
- structure.setHint("Soylent Green is SPOILER ALERT");
- structure.setTextStyle(15.0f, 16, 23, 42);
- structure.setTextLines(new int[] {4, 8, 15} , new int[] {16, 23, 42});
- return structure;
- }
-
- /**
- * Asserts the properties of a {@link ViewNode} that was created by
- * {@link #newStructureWithComplexText()}.
- */
- private void assertNodeWithComplexText(ViewNode node) {
- assertThat(node.getText()).isEqualTo("Now we're talking!");
- assertThat(node.getTextSelectionStart()).isEqualTo(4);
- assertThat(node.getTextSelectionEnd()).isEqualTo(8);
- assertThat(node.getHint()).isEqualTo("Soylent Green is SPOILER ALERT");
- assertThat(node.getTextSize()).isWithin(1.0e-10f).of(15.0f);
- assertThat(node.getTextColor()).isEqualTo(16);
- assertThat(node.getTextBackgroundColor()).isEqualTo(23);
- assertThat(node.getTextStyle()).isEqualTo(42);
- assertThat(node.getTextLineCharOffsets()).asList().containsExactly(4, 8, 15).inOrder();
- assertThat(node.getTextLineBaselines()).asList().containsExactly(16, 23, 42).inOrder();
- }
-
- /**
- * Asserts the properties of a {@link ViewStructureImpl} that was created by
- * {@link #newStructureWithComplexText()}.
- */
- private void assertStructureWithComplexText(ViewStructureImpl structure) {
- assertThat(structure.getText()).isEqualTo("Now we're talking!");
- assertThat(structure.getTextSelectionStart()).isEqualTo(4);
- assertThat(structure.getTextSelectionEnd()).isEqualTo(8);
- assertThat(structure.getHint()).isEqualTo("Soylent Green is SPOILER ALERT");
- }
-
- private ViewNode cloneThroughParcel(ViewNode node) {
- Parcel parcel = Parcel.obtain();
-
- try {
- // Write to parcel
- parcel.setDataPosition(0); // Sanity / paranoid check
- ViewNode.writeToParcel(parcel, node, 0);
-
- // Read from parcel
- parcel.setDataPosition(0);
- ViewNode clone = ViewNode.readFromParcel(parcel);
- assertThat(clone).isNotNull();
- return clone;
- } finally {
- parcel.recycle();
- }
- }
}