Android: Add a unit test for WindowAndroid destruction

Adds a unit test for https://crrev.com/c/1102823. Verified
that the test fails before, but passes after the CL.

Bug: b/78251221
Change-Id: Ib68ebe7675820ecea7b09061335aa9c821c99e95
Reviewed-on: https://chromium-review.googlesource.com/1112893
Commit-Queue: Jinsuk Kim <[email protected]>
Reviewed-by: Bo <[email protected]>
Cr-Commit-Position: refs/heads/master@{#570461}
diff --git a/ui/android/view_android_unittests.cc b/ui/android/view_android_unittests.cc
index 9a90bf51..71c758d 100644
--- a/ui/android/view_android_unittests.cc
+++ b/ui/android/view_android_unittests.cc
@@ -324,4 +324,27 @@
   EXPECT_FALSE(bottom_observer.attached_);
 }
 
+TEST(ViewAndroidTest, WindowAndroidDestructionDetachesAllViewAndroid) {
+  std::unique_ptr<WindowAndroid> window(WindowAndroid::CreateForTesting());
+  ViewAndroid top;
+  ViewAndroid bottom;
+
+  Observer top_observer;
+  Observer bottom_observer;
+
+  top.AddObserver(&top_observer);
+  bottom.AddObserver(&bottom_observer);
+
+  window->AddChild(&top);
+  top.AddChild(&bottom);
+
+  EXPECT_TRUE(top_observer.attached_);
+  EXPECT_TRUE(bottom_observer.attached_);
+
+  window.reset();
+
+  EXPECT_FALSE(top_observer.attached_);
+  EXPECT_FALSE(bottom_observer.attached_);
+}
+
 }  // namespace ui