OLD | NEW |
---|---|
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "chrome/browser/ui/test/test_browser_dialog.h" | 5 #include "chrome/browser/ui/test/test_browser_dialog.h" |
6 | 6 |
7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
8 #include "base/message_loop/message_loop.h" | 8 #include "base/message_loop/message_loop.h" |
9 #include "base/stl_util.h" | |
9 #include "base/test/gtest_util.h" | 10 #include "base/test/gtest_util.h" |
10 #include "base/threading/thread_task_runner_handle.h" | 11 #include "base/threading/thread_task_runner_handle.h" |
11 #include "chrome/browser/platform_util.h" | 12 #include "chrome/browser/platform_util.h" |
12 #include "ui/base/material_design/material_design_controller.h" | 13 #include "ui/base/material_design/material_design_controller.h" |
13 #include "ui/base/test/material_design_controller_test_api.h" | 14 #include "ui/base/test/material_design_controller_test_api.h" |
14 #include "ui/base/test/user_interactive_test_case.h" | 15 #include "ui/base/test/user_interactive_test_case.h" |
15 #include "ui/base/ui_base_switches.h" | 16 #include "ui/base/ui_base_switches.h" |
16 #include "ui/views/test/widget_test.h" | 17 #include "ui/views/test/widget_test.h" |
17 #include "ui/views/widget/widget.h" | 18 #include "ui/views/widget/widget.h" |
18 #include "ui/views/widget/widget_observer.h" | 19 #include "ui/views/widget/widget_observer.h" |
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
104 views::Widget::Widgets widgets_after = | 105 views::Widget::Widgets widgets_after = |
105 views::test::WidgetTest::GetAllWidgets(); | 106 views::test::WidgetTest::GetAllWidgets(); |
106 #if defined(OS_CHROMEOS) | 107 #if defined(OS_CHROMEOS) |
107 views::Widget::GetAllChildWidgets(ash::Shell::GetPrimaryRootWindow(), | 108 views::Widget::GetAllChildWidgets(ash::Shell::GetPrimaryRootWindow(), |
108 &widgets_after); | 109 &widgets_after); |
109 #endif // OS_CHROMEOS | 110 #endif // OS_CHROMEOS |
110 | 111 |
111 auto added = base::STLSetDifference<std::vector<views::Widget*>>( | 112 auto added = base::STLSetDifference<std::vector<views::Widget*>>( |
112 widgets_after, widgets_before); | 113 widgets_after, widgets_before); |
113 | 114 |
115 if (added.size() > 1) { | |
116 // Some tests create a standalone window to anchor a dialog. In those cases, | |
117 // ignore added Widgets that are not dialogs. | |
118 base::EraseIf(added, [](views::Widget* widget) { | |
Peter Kasting
2017/03/10 08:29:54
Nice use of this API that just went in! I think y
| |
119 return !widget->widget_delegate()->AsDialogDelegate(); | |
120 }); | |
121 } | |
122 | |
114 // This can fail if no dialog was shown, if the dialog shown wasn't a toolkit- | 123 // This can fail if no dialog was shown, if the dialog shown wasn't a toolkit- |
115 // views dialog, or if more than one child dialog was shown. | 124 // views dialog, or if more than one child dialog was shown. |
116 ASSERT_EQ(1u, added.size()); | 125 ASSERT_EQ(1u, added.size()); |
117 | 126 |
118 const DialogAction action = base::CommandLine::ForCurrentProcess()->HasSwitch( | 127 const DialogAction action = base::CommandLine::ForCurrentProcess()->HasSwitch( |
119 internal::kInteractiveSwitch) | 128 internal::kInteractiveSwitch) |
120 ? DialogAction::INTERACTIVE | 129 ? DialogAction::INTERACTIVE |
121 : DialogAction::CLOSE_NOW; | 130 : DialogAction::CLOSE_NOW; |
122 | 131 |
123 WidgetCloser closer(added[0], action); | 132 WidgetCloser closer(added[0], action); |
124 ::test::RunTestInteractively(); | 133 ::test::RunTestInteractively(); |
125 } | 134 } |
OLD | NEW |