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

Side by Side Diff: chrome/browser/ui/test/test_browser_dialog.cc

Issue 2660813002: Add WidgetTest::GetAllWidgets() to find dialogs created by TestBrowserDialog. (Closed)
Patch Set: fix mac Created 3 years, 10 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 unified diff | Download patch
OLDNEW
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"
11 #include "chrome/browser/platform_util.h" 11 #include "chrome/browser/platform_util.h"
12 #include "ui/base/material_design/material_design_controller.h" 12 #include "ui/base/material_design/material_design_controller.h"
13 #include "ui/base/test/material_design_controller_test_api.h" 13 #include "ui/base/test/material_design_controller_test_api.h"
14 #include "ui/base/test/user_interactive_test_case.h" 14 #include "ui/base/test/user_interactive_test_case.h"
15 #include "ui/base/ui_base_switches.h" 15 #include "ui/base/ui_base_switches.h"
16 #include "ui/views/test/widget_test.h"
16 #include "ui/views/widget/widget.h" 17 #include "ui/views/widget/widget.h"
17 #include "ui/views/widget/widget_observer.h" 18 #include "ui/views/widget/widget_observer.h"
18 19
20 #if defined(USE_ASH)
sky 2017/01/30 17:07:04 USE_ASH is going to become OS_CHROMEOS, so you may
tapted 2017/01/30 23:36:31 Done.
21 #include "ash/shell.h" // nogncheck
22 #endif
23
19 namespace { 24 namespace {
20 25
21 // An automatic action for WidgetCloser to post to the RunLoop. 26 // An automatic action for WidgetCloser to post to the RunLoop.
22 // TODO(tapted): Explore asynchronous Widget::Close() and DialogClientView:: 27 // TODO(tapted): Explore asynchronous Widget::Close() and DialogClientView::
23 // {Accept,Cancel}Window() approaches to test other dialog lifetimes. 28 // {Accept,Cancel}Window() approaches to test other dialog lifetimes.
24 enum class DialogAction { 29 enum class DialogAction {
25 INTERACTIVE, // Run interactively. 30 INTERACTIVE, // Run interactively.
26 CLOSE_NOW, // Call Widget::CloseNow(). 31 CLOSE_NOW, // Call Widget::CloseNow().
27 }; 32 };
28 33
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
79 // The rest of this method assumes the child dialog is toolkit-views. So, for 84 // The rest of this method assumes the child dialog is toolkit-views. So, for
80 // Mac, it will only work if --secondary-ui-md is passed. Without this, a 85 // Mac, it will only work if --secondary-ui-md is passed. Without this, a
81 // Cocoa dialog will be created, which TestBrowserDialog doesn't support. 86 // Cocoa dialog will be created, which TestBrowserDialog doesn't support.
82 // Force SecondaryUiMaterial() on Mac to get coverage on the bots. Leave it 87 // Force SecondaryUiMaterial() on Mac to get coverage on the bots. Leave it
83 // optional elsewhere so that the non-MD dialog can be invoked to compare. 88 // optional elsewhere so that the non-MD dialog can be invoked to compare.
84 ui::test::MaterialDesignControllerTestAPI md_test_api( 89 ui::test::MaterialDesignControllerTestAPI md_test_api(
85 ui::MaterialDesignController::GetMode()); 90 ui::MaterialDesignController::GetMode());
86 md_test_api.SetSecondaryUiMaterial(true); 91 md_test_api.SetSecondaryUiMaterial(true);
87 #endif 92 #endif
88 93
89 gfx::NativeView parent = platform_util::GetViewForWindow(DialogParent()); 94 views::Widget::Widgets widgets_before =
90 views::Widget::Widgets widgets_before; 95 views::test::WidgetTest::GetAllWidgets();
91 views::Widget::GetAllChildWidgets(parent, &widgets_before); 96 #if defined(USE_ASH)
97 // GetAllWidgets() uses AuraTestHelper to find the aura root window, but
98 // that's not used on browser_tests, so ask ash.
99 views::Widget::GetAllChildWidgets(ash::Shell::GetPrimaryRootWindow(),
sky 2017/01/30 17:07:04 I assume only the primary display is ok for tests,
tapted 2017/01/30 23:36:31 Yes, I think it should be correct for these tests.
100 &widgets_before);
101 #endif // USE_ASH
92 102
93 ShowDialog(NameFromTestCase()); 103 ShowDialog(NameFromTestCase());
94 views::Widget::Widgets widgets_after; 104 views::Widget::Widgets widgets_after =
95 views::Widget::GetAllChildWidgets(parent, &widgets_after); 105 views::test::WidgetTest::GetAllWidgets();
106 #if defined(USE_ASH)
107 views::Widget::GetAllChildWidgets(ash::Shell::GetPrimaryRootWindow(),
108 &widgets_after);
109 #endif // USE_ASH
96 110
97 auto added = base::STLSetDifference<std::vector<views::Widget*>>( 111 auto added = base::STLSetDifference<std::vector<views::Widget*>>(
98 widgets_after, widgets_before); 112 widgets_after, widgets_before);
99 113
100 // This can fail if no dialog was shown, if the dialog shown wasn't a toolkit- 114 // This can fail if no dialog was shown, if the dialog shown wasn't a toolkit-
101 // views dialog, or if more than one child dialog was shown. 115 // views dialog, or if more than one child dialog was shown.
102 ASSERT_EQ(1u, added.size()); 116 ASSERT_EQ(1u, added.size());
103 117
104 const DialogAction action = base::CommandLine::ForCurrentProcess()->HasSwitch( 118 const DialogAction action = base::CommandLine::ForCurrentProcess()->HasSwitch(
105 internal::kInteractiveSwitch) 119 internal::kInteractiveSwitch)
106 ? DialogAction::INTERACTIVE 120 ? DialogAction::INTERACTIVE
107 : DialogAction::CLOSE_NOW; 121 : DialogAction::CLOSE_NOW;
108 122
109 WidgetCloser closer(added[0], action); 123 WidgetCloser closer(added[0], action);
110 ::test::RunTestInteractively(); 124 ::test::RunTestInteractively();
111 } 125 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698