Commit 8ce0e372 authored by Mike Wasserman's avatar Mike Wasserman Committed by Commit Bot

Chrome OS: Avoid GetAllWidgets in non-mash browser tests.

Avoid GetAllWidgets in classic ash and mus Chrome OS browser tests.
These configs cannot get a list of root windows at the Views layer.
Add a DCHECK to avoid using GetAllWidgets in those scenarios.

Win/Linux/Mac query their WMs directly for root windows; on Chrome OS:
1) Mash can use MusClient to get a list of root windows.
2) Unit tests can use AuraTestHelper to get the root window.
3) Non-mash browser tests must use ash::Shell to get root windows.

This should land after http://crrev.com/c/919922

Bug: 811940
Change-Id: I609531529ff5c4379f6c1de47ca878b30e7dd614
Reviewed-on: https://chromium-review.googlesource.com/922268Reviewed-by: default avatarScott Violet <sky@chromium.org>
Commit-Queue: Michael Wasserman <msw@chromium.org>
Cr-Commit-Position: refs/heads/master@{#537331}
parent c36c604e
......@@ -164,17 +164,19 @@ bool TestBrowserDialog::AlwaysCloseAsynchronously() {
}
void TestBrowserDialog::UpdateWidgets() {
#if defined(TOOLKIT_VIEWS)
widgets_ = views::test::WidgetTest::GetAllWidgets();
widgets_.clear();
#if defined(OS_CHROMEOS)
// GetAllWidgets() uses AuraTestHelper to find the aura root window, but
// that's not used on browser_tests, so ask ash. Under mash the MusClient
// provides the list of root windows, so this isn't needed.
if (chromeos::GetAshConfig() != ash::Config::MASH) {
views::Widget::GetAllChildWidgets(ash::Shell::GetPrimaryRootWindow(),
&widgets_);
// Under mash, GetAllWidgets() uses MusClient to get the list of root windows.
// Otherwise, GetAllWidgets() relies on AuraTestHelper to get the root window,
// but that is not available in browser_tests, so use ash::Shell directly.
if (chromeos::GetAshConfig() == ash::Config::MASH) {
widgets_ = views::test::WidgetTest::GetAllWidgets();
} else {
for (aura::Window* root_window : ash::Shell::GetAllRootWindows())
views::Widget::GetAllChildWidgets(root_window, &widgets_);
}
#endif // OS_CHROMEOS
#elif defined(TOOLKIT_VIEWS)
widgets_ = views::test::WidgetTest::GetAllWidgets();
#else
NOTIMPLEMENTED();
#endif
......
......@@ -17,9 +17,6 @@
#if defined(USE_X11)
#include "ui/gfx/x/x11.h" // nogncheck
#include "ui/gfx/x/x11_types.h" // nogncheck
#endif
#if defined(USE_X11)
#include "ui/views/widget/desktop_aura/desktop_window_tree_host_x11.h"
#endif
......@@ -75,22 +72,26 @@ std::vector<aura::Window*> GetAllTopLevelWindows() {
std::vector<aura::Window*> roots;
#if defined(USE_X11)
roots = DesktopWindowTreeHostX11::GetAllOpenWindows();
#endif
#if defined(OS_WIN)
#elif defined(OS_WIN)
{
FindAllWindowsData data = {&roots};
EnumThreadWindows(GetCurrentThreadId(), FindAllWindowsCallback,
reinterpret_cast<LPARAM>(&data));
}
#endif // OS_WIN
aura::test::AuraTestHelper* aura_test_helper =
aura::test::AuraTestHelper::GetInstance();
if (aura_test_helper)
roots.push_back(aura_test_helper->root_window());
#endif
if (MusClient::Get()) {
auto mus_roots = MusClient::Get()->window_tree_client()->GetRoots();
roots.insert(roots.end(), mus_roots.begin(), mus_roots.end());
} else {
aura::test::AuraTestHelper* aura_test_helper =
aura::test::AuraTestHelper::GetInstance();
#if defined(OS_CHROMEOS)
// Chrome OS non-mash unit tests use AuraTestHelper to get the root window.
// Chrome OS non-mash browser tests must use ash::Shell::GetAllRootWindows.
DCHECK(aura_test_helper) << "Can't find all widgets without a test helper";
#endif
if (aura_test_helper)
roots.push_back(aura_test_helper->root_window());
}
return roots;
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment