Add check for idPackage to AutofillCtsTestHelper.
This CL adds a check for idPackage when counting ViewNodes in a
structure so that irrelevant nodes (such as Views in a caption bar) are
not counted by Autofill tests.
Test: atest CtsAutoFillServiceTestCases
Bug: 220215536
Change-Id: I1a1dfc078cf9c12e13de6aeb7c9954ce6af8bc05
diff --git a/tests/autofillservice/src/android/autofillservice/cts/testcore/Helper.java b/tests/autofillservice/src/android/autofillservice/cts/testcore/Helper.java
index 21befa5..1d519d7 100644
--- a/tests/autofillservice/src/android/autofillservice/cts/testcore/Helper.java
+++ b/tests/autofillservice/src/android/autofillservice/cts/testcore/Helper.java
@@ -771,6 +771,7 @@
/**
* Gets the total number of nodes in an structure.
+ * A node that has a non-null IdPackage which does not match the test package is not counted.
*/
public static int getNumberNodes(AssistStructure structure,
CharSequence windowTitle) {
@@ -798,14 +799,18 @@
/**
* Gets the total number of nodes in an node, including all descendants and the node itself.
+ * A node that has a non-null IdPackage which does not match the test package is not counted.
*/
public static int getNumberNodes(ViewNode node) {
+ if (node.getIdPackage() != null && !node.getIdPackage().equals(MY_PACKAGE)) {
+ Log.w(TAG, "ViewNode ignored in getNumberNodes because of mismatched package: "
+ + node.getIdPackage());
+ return 0;
+ }
int count = 1;
final int childrenSize = node.getChildCount();
- if (childrenSize > 0) {
- for (int i = 0; i < childrenSize; i++) {
- count += getNumberNodes(node.getChildAt(i));
- }
+ for (int i = 0; i < childrenSize; i++) {
+ count += getNumberNodes(node.getChildAt(i));
}
return count;
}