Chromium Code Reviews| 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 Widget::Widgets expected; | |
| 46 | |
| 47 EXPECT_EQ(expected, GetAllWidgets()); | |
| 48 | |
| 49 Widget* platform = CreateTopLevelPlatformWidget(); | |
| 50 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
| |
| 51 | |
| 52 Widget* platform_child = CreateChildPlatformWidget(platform->GetNativeView()); | |
| 53 ExpectAdd(&expected, platform_child, "platform_child"); | |
| 54 | |
| 55 Widget* frameless = CreateTopLevelFramelessPlatformWidget(); | |
| 56 ExpectAdd(&expected, frameless, "frameless"); | |
| 57 | |
| 58 Widget* native = CreateTopLevelNativeWidget(); | |
| 59 ExpectAdd(&expected, native, "native"); | |
| 60 | |
| 61 Widget* native_child = CreateChildNativeWidgetWithParent(native); | |
| 62 ExpectAdd(&expected, native_child, "native_child"); | |
| 63 | |
| 64 Widget* desktop = CreateNativeDesktopWidget(); | |
| 65 ExpectAdd(&expected, desktop, "desktop"); | |
| 66 | |
| 67 Widget* desktop_child = CreateChildNativeWidgetWithParent(desktop); | |
| 68 ExpectAdd(&expected, desktop_child, "desktop_child"); | |
| 69 | |
| 70 ExpectClose(&expected, {desktop, desktop_child}, "desktop"); | |
| 71 ExpectClose(&expected, {native, native_child}, "native"); | |
| 72 ExpectClose(&expected, {platform, platform_child}, "platform"); | |
| 73 ExpectClose(&expected, {frameless}, "frameless"); | |
| 74 } | |
| 75 | |
| 76 } // namespace views | |
| 77 } // namespace test | |
| OLD | NEW |