Added test scenarios around nested clusters

Nested cluster behavior is now defined as "pretend nested
clusters are not clusters". This adds some testing for that.

Bug: 32804858
Test: ViewGroupTest#{testAddKeyboardNavigationClusters,
      testRestoreFocusInCluster, testTouchscreenBlocksFocus}
Change-Id: I2f7082659f7eec9f2f0e7e6d9c04a8230bcc6295
diff --git a/tests/tests/view/src/android/view/cts/ViewGroupTest.java b/tests/tests/view/src/android/view/cts/ViewGroupTest.java
index 17c6843..95b8491 100644
--- a/tests/tests/view/src/android/view/cts/ViewGroupTest.java
+++ b/tests/tests/view/src/android/view/cts/ViewGroupTest.java
@@ -208,6 +208,19 @@
         mMockViewGroup.setVisibility(View.GONE);
         parent.addKeyboardNavigationClusters(list, 0);
         assertEquals(0, list.size());
+        list.clear();
+
+        // Nested clusters are ignored
+        TestClusterHier h = new TestClusterHier();
+        h.nestedGroup.setKeyboardNavigationCluster(true);
+        h.cluster2.setKeyboardNavigationCluster(false);
+        h.top.addKeyboardNavigationClusters(list, View.FOCUS_FORWARD);
+        assertTrue(list.contains(h.nestedGroup));
+        list.clear();
+        h.cluster2.setKeyboardNavigationCluster(true);
+        h.top.addKeyboardNavigationClusters(list, View.FOCUS_FORWARD);
+        assertFalse(list.contains(h.nestedGroup));
+        list.clear();
     }
 
     @UiThreadTest
@@ -1562,6 +1575,14 @@
         h.c2view1.setVisibility(View.INVISIBLE);
         h.cluster2.restoreFocusInCluster(View.FOCUS_DOWN);
         assertSame(h.c2view2, h.top.findFocus());
+
+        // Nested clusters should be ignored.
+        h = new TestClusterHier();
+        h.c1view1.setFocusedInCluster();
+        h.nestedGroup.setKeyboardNavigationCluster(true);
+        h.c2view2.setFocusedInCluster();
+        h.cluster2.restoreFocusInCluster(View.FOCUS_DOWN);
+        assertSame(h.c2view2, h.top.findFocus());
     }
 
     @UiThreadTest
@@ -1781,6 +1802,7 @@
         // can normal-navigate around once inside
         h.top.addFocusables(views, View.FOCUS_DOWN);
         assertTrue(views.contains(h.c1view1));
+        views.clear();
         h.c1view1.requestFocus();
         assertSame(h.c1view1, h.top.findFocus());
         // focus loops within cluster (doesn't leave)
@@ -1791,6 +1813,17 @@
         h.c2view2.requestFocus();
         h.c1view1.requestFocus();
         assertSame(h.c2view2, h.top.findFocus());
+
+        h = new TestClusterHier(false);
+        h.c1view1.requestFocus();
+        h.nestedGroup.setKeyboardNavigationCluster(true);
+        h.nestedGroup.setTouchscreenBlocksFocus(true);
+        // since cluster is nested, it should ignore its touchscreenBlocksFocus behavior.
+        h.c2view2.requestFocus();
+        assertSame(h.c2view2, h.top.findFocus());
+        h.top.addFocusables(views, View.FOCUS_DOWN);
+        assertTrue(views.contains(h.c2view2));
+        views.clear();
     }
 
     @UiThreadTest