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

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

Issue 2660813002: Add WidgetTest::GetAllWidgets() to find dialogs created by TestBrowserDialog. (Closed)
Patch Set: fix mac 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
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..c0995a6b6a51bce81e168f20fd165749b170b330
--- /dev/null
+++ b/ui/views/test/widget_test_unittest.cc
@@ -0,0 +1,77 @@
+// 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) {
+ Widget::Widgets expected;
+
+ EXPECT_EQ(expected, GetAllWidgets());
+
+ Widget* platform = CreateTopLevelPlatformWidget();
+ ExpectAdd(&expected, platform, "platform");
sky 2017/01/30 17:07:04 It seems like the order of WidgetTest::GetAllWidge
tapted 2017/01/30 23:36:31 Ah, it's coincidence here that |expected| is updat
+
+ 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
« chrome/browser/ui/test/test_browser_dialog.cc ('K') | « 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