| OLD | NEW |
| (Empty) | |
| 1 // Copyright 2017 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "ui/views/test/widget_test.h" |
| 6 |
| 7 #include <algorithm> |
| 8 #include <vector> |
| 9 |
| 10 #include "testing/gtest/include/gtest/gtest.h" |
| 11 |
| 12 namespace views { |
| 13 namespace test { |
| 14 namespace { |
| 15 |
| 16 // Insert |widget| into |expected| and ensure it's reported by GetAllWidgets(). |
| 17 void ExpectAdd(Widget::Widgets* expected, Widget* widget, const char* message) { |
| 18 SCOPED_TRACE(message); |
| 19 EXPECT_TRUE(expected->insert(widget).second); |
| 20 Widget::Widgets actual = WidgetTest::GetAllWidgets(); |
| 21 EXPECT_EQ(expected->size(), actual.size()); |
| 22 EXPECT_TRUE(std::equal(expected->begin(), expected->end(), actual.begin())); |
| 23 } |
| 24 |
| 25 // Close |widgets[0]|, and expect all |widgets| to be removed. |
| 26 void ExpectClose(Widget::Widgets* expected, |
| 27 std::vector<Widget*> widgets, |
| 28 const char* message) { |
| 29 SCOPED_TRACE(message); |
| 30 for (Widget* widget : widgets) |
| 31 EXPECT_EQ(1u, expected->erase(widget)); |
| 32 widgets[0]->CloseNow(); |
| 33 Widget::Widgets actual = WidgetTest::GetAllWidgets(); |
| 34 EXPECT_EQ(expected->size(), actual.size()); |
| 35 EXPECT_TRUE(std::equal(expected->begin(), expected->end(), actual.begin())); |
| 36 } |
| 37 |
| 38 } // namespace |
| 39 |
| 40 using WidgetTestTest = WidgetTest; |
| 41 |
| 42 // Ensure that Widgets with various root windows are correctly reported by |
| 43 // WidgetTest::GetAllWidgets(). |
| 44 TEST_F(WidgetTestTest, GetAllWidgets) { |
| 45 // Note Widget::Widgets is a std::set ordered by pointer value, so the order |
| 46 // that |expected| is updated below is not important. |
| 47 Widget::Widgets expected; |
| 48 |
| 49 EXPECT_EQ(expected, GetAllWidgets()); |
| 50 |
| 51 Widget* platform = CreateTopLevelPlatformWidget(); |
| 52 ExpectAdd(&expected, platform, "platform"); |
| 53 |
| 54 Widget* platform_child = CreateChildPlatformWidget(platform->GetNativeView()); |
| 55 ExpectAdd(&expected, platform_child, "platform_child"); |
| 56 |
| 57 Widget* frameless = CreateTopLevelFramelessPlatformWidget(); |
| 58 ExpectAdd(&expected, frameless, "frameless"); |
| 59 |
| 60 Widget* native = CreateTopLevelNativeWidget(); |
| 61 ExpectAdd(&expected, native, "native"); |
| 62 |
| 63 Widget* native_child = CreateChildNativeWidgetWithParent(native); |
| 64 ExpectAdd(&expected, native_child, "native_child"); |
| 65 |
| 66 Widget* desktop = CreateNativeDesktopWidget(); |
| 67 ExpectAdd(&expected, desktop, "desktop"); |
| 68 |
| 69 Widget* desktop_child = CreateChildNativeWidgetWithParent(desktop); |
| 70 ExpectAdd(&expected, desktop_child, "desktop_child"); |
| 71 |
| 72 ExpectClose(&expected, {desktop, desktop_child}, "desktop"); |
| 73 ExpectClose(&expected, {native, native_child}, "native"); |
| 74 ExpectClose(&expected, {platform, platform_child}, "platform"); |
| 75 ExpectClose(&expected, {frameless}, "frameless"); |
| 76 } |
| 77 |
| 78 } // namespace views |
| 79 } // namespace test |
| OLD | NEW |