Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(624)

Unified Diff: ui/views/test/widget_test_unittest.cc

Issue 2660813002: Add WidgetTest::GetAllWidgets() to find dialogs created by TestBrowserDialog. (Closed)
Patch Set: respond to comments Created 3 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « ui/views/test/widget_test_mac.mm ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ui/views/test/widget_test_unittest.cc
diff --git a/ui/views/test/widget_test_unittest.cc b/ui/views/test/widget_test_unittest.cc
new file mode 100644
index 0000000000000000000000000000000000000000..b4d8ea50364dcfb00e521e1fccc117cbaf0b1fdd
--- /dev/null
+++ b/ui/views/test/widget_test_unittest.cc
@@ -0,0 +1,79 @@
+// 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.
+
+#include "ui/views/test/widget_test.h"
+
+#include <algorithm>
+#include <vector>
+
+#include "testing/gtest/include/gtest/gtest.h"
+
+namespace views {
+namespace test {
+namespace {
+
+// Insert |widget| into |expected| and ensure it's reported by GetAllWidgets().
+void ExpectAdd(Widget::Widgets* expected, Widget* widget, const char* message) {
+ SCOPED_TRACE(message);
+ EXPECT_TRUE(expected->insert(widget).second);
+ Widget::Widgets actual = WidgetTest::GetAllWidgets();
+ EXPECT_EQ(expected->size(), actual.size());
+ EXPECT_TRUE(std::equal(expected->begin(), expected->end(), actual.begin()));
+}
+
+// Close |widgets[0]|, and expect all |widgets| to be removed.
+void ExpectClose(Widget::Widgets* expected,
+ std::vector<Widget*> widgets,
+ const char* message) {
+ SCOPED_TRACE(message);
+ for (Widget* widget : widgets)
+ EXPECT_EQ(1u, expected->erase(widget));
+ widgets[0]->CloseNow();
+ Widget::Widgets actual = WidgetTest::GetAllWidgets();
+ EXPECT_EQ(expected->size(), actual.size());
+ EXPECT_TRUE(std::equal(expected->begin(), expected->end(), actual.begin()));
+}
+
+} // namespace
+
+using WidgetTestTest = WidgetTest;
+
+// Ensure that Widgets with various root windows are correctly reported by
+// WidgetTest::GetAllWidgets().
+TEST_F(WidgetTestTest, GetAllWidgets) {
+ // Note Widget::Widgets is a std::set ordered by pointer value, so the order
+ // that |expected| is updated below is not important.
+ Widget::Widgets expected;
+
+ EXPECT_EQ(expected, GetAllWidgets());
+
+ Widget* platform = CreateTopLevelPlatformWidget();
+ ExpectAdd(&expected, platform, "platform");
+
+ Widget* platform_child = CreateChildPlatformWidget(platform->GetNativeView());
+ ExpectAdd(&expected, platform_child, "platform_child");
+
+ Widget* frameless = CreateTopLevelFramelessPlatformWidget();
+ ExpectAdd(&expected, frameless, "frameless");
+
+ Widget* native = CreateTopLevelNativeWidget();
+ ExpectAdd(&expected, native, "native");
+
+ Widget* native_child = CreateChildNativeWidgetWithParent(native);
+ ExpectAdd(&expected, native_child, "native_child");
+
+ Widget* desktop = CreateNativeDesktopWidget();
+ ExpectAdd(&expected, desktop, "desktop");
+
+ Widget* desktop_child = CreateChildNativeWidgetWithParent(desktop);
+ ExpectAdd(&expected, desktop_child, "desktop_child");
+
+ ExpectClose(&expected, {desktop, desktop_child}, "desktop");
+ ExpectClose(&expected, {native, native_child}, "native");
+ ExpectClose(&expected, {platform, platform_child}, "platform");
+ ExpectClose(&expected, {frameless}, "frameless");
+}
+
+} // namespace views
+} // namespace test
« no previous file with comments | « ui/views/test/widget_test_mac.mm ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698