| Index: ash/devtools/ash_devtools_unittest.cc
|
| diff --git a/ash/devtools/ash_devtools_unittest.cc b/ash/devtools/ash_devtools_unittest.cc
|
| index a1ecc40126c8b139172f36b413355bd1f2e49b9a..924f7b99fefb1c4fdc47636db51293f0a5048ff4 100644
|
| --- a/ash/devtools/ash_devtools_unittest.cc
|
| +++ b/ash/devtools/ash_devtools_unittest.cc
|
| @@ -6,17 +6,18 @@
|
| #include "ash/devtools/ash_devtools_dom_agent.h"
|
| #include "ash/devtools/ui_element.h"
|
| #include "ash/devtools/window_element.h"
|
| -#include "ash/public/cpp/shell_window_ids.h"
|
| -#include "ash/root_window_controller.h"
|
| #include "ash/shell.h"
|
| #include "ash/test/ash_test_base.h"
|
| #include "ash/wm/widget_finder.h"
|
| #include "base/memory/ptr_util.h"
|
| #include "base/strings/stringprintf.h"
|
| +#include "ui/aura/client/window_parenting_client.h"
|
| +#include "ui/aura/window_tree_host.h"
|
| #include "ui/display/display.h"
|
| #include "ui/views/background.h"
|
| #include "ui/views/widget/native_widget_private.h"
|
| #include "ui/views/widget/widget.h"
|
| +#include "ui/wm/core/coordinate_conversion.h"
|
|
|
| namespace ash {
|
| namespace {
|
| @@ -138,11 +139,10 @@ int GetPropertyByName(const std::string& name,
|
| return -1;
|
| }
|
|
|
| -aura::Window* GetHighlightingWindow(int root_window_index) {
|
| - const aura::Window::Windows& overlay_windows =
|
| - Shell::GetAllRootWindows()[root_window_index]
|
| - ->GetChildById(kShellWindowId_OverlayContainer)
|
| - ->children();
|
| +aura::Window* GetHighlightingWindow(aura::Window* root_window) {
|
| + // const aura::Window::Windows& overlay_windows =
|
| + // root_window->GetChildById(kShellWindowId_OverlayContainer)->children();
|
| + const aura::Window::Windows& overlay_windows = root_window->children();
|
| for (aura::Window* window : overlay_windows) {
|
| if (window->GetName() == "HighlightingWidget")
|
| return window;
|
| @@ -169,8 +169,8 @@ std::unique_ptr<DOM::HighlightConfig> CreateHighlightConfig(
|
| .build();
|
| }
|
|
|
| -void ExpectHighlighted(const gfx::Rect& bounds, int root_window_index) {
|
| - aura::Window* highlighting_window = GetHighlightingWindow(root_window_index);
|
| +void ExpectHighlighted(const gfx::Rect& bounds, aura::Window* root_window) {
|
| + aura::Window* highlighting_window = GetHighlightingWindow(root_window);
|
| EXPECT_TRUE(highlighting_window->IsVisible());
|
| EXPECT_EQ(bounds, highlighting_window->GetBoundsInScreen());
|
| EXPECT_EQ(kBackgroundColor, GetInternalWidgetForWindow(highlighting_window)
|
| @@ -179,10 +179,6 @@ void ExpectHighlighted(const gfx::Rect& bounds, int root_window_index) {
|
| ->get_color());
|
| }
|
|
|
| -aura::Window* GetPrimaryRootWindow() {
|
| - return Shell::Get()->GetPrimaryRootWindow();
|
| -}
|
| -
|
| } // namespace
|
|
|
| class AshDevToolsTest : public test::AshTestBase {
|
| @@ -194,20 +190,38 @@ class AshDevToolsTest : public test::AshTestBase {
|
| views::Widget* widget = new views::Widget;
|
| views::Widget::InitParams params;
|
| params.ownership = views::Widget::InitParams::NATIVE_WIDGET_OWNS_WIDGET;
|
| - Shell::GetPrimaryRootWindowController()
|
| - ->ConfigureWidgetInitParamsForContainer(
|
| - widget, kShellWindowId_DefaultContainer, ¶ms);
|
| + DCHECK(dom_agent()->root_windows().size());
|
| + params.parent = GetPrimaryRootWindow();
|
| widget->Init(params);
|
| return widget->native_widget_private();
|
| }
|
|
|
| std::unique_ptr<views::Widget> CreateTestWidget(const gfx::Rect& bounds) {
|
| - return AshTestBase::CreateTestWidget(nullptr, kShellWindowId_Invalid,
|
| - bounds);
|
| + std::unique_ptr<views::Widget> widget(new views::Widget);
|
| + views::Widget::InitParams params;
|
| + params.delegate = nullptr;
|
| + params.ownership = views::Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET;
|
| + params.bounds = bounds;
|
| + params.parent = GetPrimaryRootWindow();
|
| + widget->Init(params);
|
| + widget->Show();
|
| + return widget;
|
| + }
|
| +
|
| + aura::Window* CreateTestWindow(const gfx::Rect& bounds) {
|
| + aura::Window* window = new aura::Window(nullptr);
|
| + window->set_id(0);
|
| + window->Init(ui::LAYER_TEXTURED);
|
| + window->Show();
|
| + aura::Window* root = dom_agent()->root_windows()[0];
|
| + gfx::Point origin = bounds.origin();
|
| + ::wm::ConvertPointFromScreen(root, &origin);
|
| + window->SetBounds(gfx::Rect(origin, bounds.size()));
|
| + aura::client::ParentWindowWithContext(window, root, bounds);
|
| + return window;
|
| }
|
|
|
| void SetUp() override {
|
| - AshTestBase::SetUp();
|
| fake_frontend_channel_ = base::MakeUnique<FakeFrontendChannel>();
|
| uber_dispatcher_ =
|
| base::MakeUnique<UberDispatcher>(fake_frontend_channel_.get());
|
| @@ -217,6 +231,7 @@ class AshDevToolsTest : public test::AshTestBase {
|
| base::MakeUnique<devtools::AshDevToolsCSSAgent>(dom_agent_.get());
|
| css_agent_->Init(uber_dispatcher_.get());
|
| css_agent_->enable();
|
| + AshTestBase::SetUp();
|
| }
|
|
|
| void TearDown() override {
|
| @@ -287,13 +302,23 @@ class AshDevToolsTest : public test::AshTestBase {
|
|
|
| void HideHighlight(int root_window_index) {
|
| dom_agent_->hideHighlight();
|
| - ASSERT_FALSE(GetHighlightingWindow(root_window_index)->IsVisible());
|
| + DCHECK_GE(root_window_index, 0);
|
| + DCHECK_LE(root_window_index,
|
| + static_cast<int>(dom_agent()->root_windows().size()));
|
| + ASSERT_FALSE(
|
| + GetHighlightingWindow(dom_agent()->root_windows()[root_window_index])
|
| + ->IsVisible());
|
| }
|
|
|
| FakeFrontendChannel* frontend_channel() {
|
| return fake_frontend_channel_.get();
|
| }
|
|
|
| + aura::Window* GetPrimaryRootWindow() {
|
| + DCHECK(dom_agent()->root_windows().size());
|
| + return dom_agent()->root_windows()[0];
|
| + }
|
| +
|
| devtools::AshDevToolsCSSAgent* css_agent() { return css_agent_.get(); }
|
| devtools::AshDevToolsDOMAgent* dom_agent() { return dom_agent_.get(); }
|
|
|
| @@ -634,23 +659,23 @@ TEST_F(AshDevToolsTest, WindowWidgetViewHighlight) {
|
| DOM::Node* root_view_node = widget_node->getChildren(nullptr)->get(0);
|
|
|
| HighlightNode(window_node->getNodeId());
|
| - ExpectHighlighted(window->GetBoundsInScreen(), 0);
|
| + ExpectHighlighted(window->GetBoundsInScreen(), GetPrimaryRootWindow());
|
|
|
| HideHighlight(0);
|
|
|
| HighlightNode(widget_node->getNodeId());
|
| - ExpectHighlighted(widget->GetWindowBoundsInScreen(), 0);
|
| + ExpectHighlighted(widget->GetWindowBoundsInScreen(), GetPrimaryRootWindow());
|
|
|
| HideHighlight(0);
|
|
|
| HighlightNode(root_view_node->getNodeId());
|
| - ExpectHighlighted(root_view->GetBoundsInScreen(), 0);
|
| + ExpectHighlighted(root_view->GetBoundsInScreen(), GetPrimaryRootWindow());
|
|
|
| HideHighlight(0);
|
|
|
| // Highlight non-existent node
|
| HighlightNode(10000);
|
| - EXPECT_FALSE(GetHighlightingWindow(0)->IsVisible());
|
| + EXPECT_FALSE(GetHighlightingWindow(GetPrimaryRootWindow())->IsVisible());
|
| }
|
|
|
| int GetNodeIdFromWindow(devtools::UIElement* ui_element, aura::Window* window) {
|
| @@ -670,10 +695,21 @@ int GetNodeIdFromWindow(devtools::UIElement* ui_element, aura::Window* window) {
|
| return 0;
|
| }
|
|
|
| +// TODO(thanhph): Make test AshDevToolsTest.MultipleDisplayHighlight work with
|
| +// multiple displays by updating params.parent in
|
| +// InitializeHighlightingWidget().
|
| +
|
| TEST_F(AshDevToolsTest, MultipleDisplayHighlight) {
|
| + LOG(ERROR) << "1.";
|
| UpdateDisplay("300x400,500x500");
|
| + LOG(ERROR) << "2.";
|
| +
|
| + aura::Window::Windows root_windows = dom_agent()->root_windows();
|
| + LOG(ERROR) << "root_windows[0]->GetBoundsInScreen().ToString(): "
|
| + << root_windows[0]->GetBoundsInScreen().ToString();
|
| + LOG(ERROR) << "root_windows[1]->GetBoundsInScreen().ToString(): "
|
| + << root_windows[1]->GetBoundsInScreen().ToString();
|
|
|
| - aura::Window::Windows root_windows = Shell::GetAllRootWindows();
|
| std::unique_ptr<aura::Window> window(
|
| CreateTestWindowInShellWithBounds(gfx::Rect(1, 2, 30, 40)));
|
|
|
| @@ -681,15 +717,24 @@ TEST_F(AshDevToolsTest, MultipleDisplayHighlight) {
|
| dom_agent()->getDocument(&root);
|
|
|
| EXPECT_EQ(root_windows[0], window->GetRootWindow());
|
| + LOG(ERROR) << "4.";
|
| HighlightNode(
|
| GetNodeIdFromWindow(dom_agent()->window_element_root(), window.get()));
|
| - ExpectHighlighted(window->GetBoundsInScreen(), 0);
|
| + LOG(ERROR) << "5.";
|
| + ExpectHighlighted(window->GetBoundsInScreen(),
|
| + dom_agent()->root_windows()[0]);
|
| + LOG(ERROR) << "6.";
|
|
|
| window->SetBoundsInScreen(gfx::Rect(500, 0, 50, 50), GetSecondaryDisplay());
|
| + LOG(ERROR) << "7.";
|
| EXPECT_EQ(root_windows[1], window->GetRootWindow());
|
| + LOG(ERROR) << "8.";
|
| HighlightNode(
|
| GetNodeIdFromWindow(dom_agent()->window_element_root(), window.get()));
|
| - ExpectHighlighted(window->GetBoundsInScreen(), 1);
|
| + LOG(ERROR) << "9.";
|
| + ExpectHighlighted(window->GetBoundsInScreen(),
|
| + dom_agent()->root_windows()[2]);
|
| + LOG(ERROR) << "10.";
|
| }
|
|
|
| TEST_F(AshDevToolsTest, WindowWidgetViewGetMatchedStylesForNode) {
|
|
|