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/test/gtest_util.h" | 9 #include "base/test/gtest_util.h" |
10 #include "base/threading/thread_task_runner_handle.h" | 10 #include "base/threading/thread_task_runner_handle.h" |
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
104 views::Widget::Widgets widgets_after = | 104 views::Widget::Widgets widgets_after = |
105 views::test::WidgetTest::GetAllWidgets(); | 105 views::test::WidgetTest::GetAllWidgets(); |
106 #if defined(OS_CHROMEOS) | 106 #if defined(OS_CHROMEOS) |
107 views::Widget::GetAllChildWidgets(ash::Shell::GetPrimaryRootWindow(), | 107 views::Widget::GetAllChildWidgets(ash::Shell::GetPrimaryRootWindow(), |
108 &widgets_after); | 108 &widgets_after); |
109 #endif // OS_CHROMEOS | 109 #endif // OS_CHROMEOS |
110 | 110 |
111 auto added = base::STLSetDifference<std::vector<views::Widget*>>( | 111 auto added = base::STLSetDifference<std::vector<views::Widget*>>( |
112 widgets_after, widgets_before); | 112 widgets_after, widgets_before); |
113 | 113 |
| 114 if (added.size() > 1) { |
| 115 // Some tests create a standalone window to anchor a dialog. In those cases, |
| 116 // ignore added Widgets that are not dialogs. |
| 117 for (auto it = added.begin(); it != added.end();) { |
| 118 if (!(*it)->widget_delegate()->AsDialogDelegate()) |
| 119 it = added.erase(it); |
| 120 else |
| 121 ++it; |
| 122 } |
| 123 } |
| 124 |
114 // This can fail if no dialog was shown, if the dialog shown wasn't a toolkit- | 125 // 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. | 126 // views dialog, or if more than one child dialog was shown. |
116 ASSERT_EQ(1u, added.size()); | 127 ASSERT_EQ(1u, added.size()); |
117 | 128 |
118 const DialogAction action = base::CommandLine::ForCurrentProcess()->HasSwitch( | 129 const DialogAction action = base::CommandLine::ForCurrentProcess()->HasSwitch( |
119 internal::kInteractiveSwitch) | 130 internal::kInteractiveSwitch) |
120 ? DialogAction::INTERACTIVE | 131 ? DialogAction::INTERACTIVE |
121 : DialogAction::CLOSE_NOW; | 132 : DialogAction::CLOSE_NOW; |
122 | 133 |
123 WidgetCloser closer(added[0], action); | 134 WidgetCloser closer(added[0], action); |
124 ::test::RunTestInteractively(); | 135 ::test::RunTestInteractively(); |
125 } | 136 } |
OLD | NEW |