| Index: components/ui_devtools/views/ui_devtools_unittest.cc
|
| diff --git a/ash/devtools/ash_devtools_unittest.cc b/components/ui_devtools/views/ui_devtools_unittest.cc
|
| similarity index 86%
|
| rename from ash/devtools/ash_devtools_unittest.cc
|
| rename to components/ui_devtools/views/ui_devtools_unittest.cc
|
| index 90ed0be8d632503014ccd93efde1a2e52bf3ac8c..f21fe1b18fe80167b7a3ac353286db32e78dba62 100644
|
| --- a/ash/devtools/ash_devtools_unittest.cc
|
| +++ b/components/ui_devtools/views/ui_devtools_unittest.cc
|
| @@ -2,26 +2,24 @@
|
| // Use of this source code is governed by a BSD-style license that can be
|
| // found in the LICENSE file.
|
|
|
| -#include "ash/devtools/ash_devtools_css_agent.h"
|
| -#include "ash/devtools/ash_devtools_dom_agent.h"
|
| -#include "ash/devtools/ui_element.h"
|
| -#include "ash/devtools/view_element.h"
|
| -#include "ash/devtools/widget_element.h"
|
| -#include "ash/devtools/window_element.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 "components/ui_devtools/views/ui_devtools_css_agent.h"
|
| +#include "components/ui_devtools/views/ui_devtools_dom_agent.h"
|
| +#include "components/ui_devtools/views/ui_element.h"
|
| +#include "components/ui_devtools/views/view_element.h"
|
| +#include "components/ui_devtools/views/widget_element.h"
|
| +#include "components/ui_devtools/views/window_element.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/test/views_test_base.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 ui {
|
| namespace {
|
|
|
| using namespace ui::devtools::protocol;
|
| @@ -88,7 +86,7 @@ std::string GetAttributeValue(const std::string& attribute, DOM::Node* node) {
|
|
|
| bool Equals(aura::Window* window, DOM::Node* node) {
|
| int children_count = static_cast<int>(window->children().size());
|
| - if (GetInternalWidgetForWindow(window))
|
| + if (views::Widget::GetWidgetForNativeView(window))
|
| children_count++;
|
| return "Window" == node->getNodeName() &&
|
| window->GetName() == GetAttributeValue("name", node) &&
|
| @@ -173,53 +171,83 @@ 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)
|
| - ->GetRootView()
|
| - ->background()
|
| - ->get_color());
|
| + EXPECT_EQ(kBackgroundColor,
|
| + views::Widget::GetWidgetForNativeView(highlighting_window)
|
| + ->GetRootView()
|
| + ->background()
|
| + ->get_color());
|
| }
|
|
|
| } // namespace
|
|
|
| -class AshDevToolsTest : public test::AshTestBase {
|
| +class UIDevToolsTest : public views::ViewsTestBase {
|
| public:
|
| - AshDevToolsTest() {}
|
| - ~AshDevToolsTest() override {}
|
| + UIDevToolsTest() {}
|
| + ~UIDevToolsTest() override {}
|
|
|
| views::internal::NativeWidgetPrivate* CreateTestNativeWidget() {
|
| views::Widget* widget = new views::Widget;
|
| views::Widget::InitParams params;
|
| params.ownership = views::Widget::InitParams::NATIVE_WIDGET_OWNS_WIDGET;
|
| + 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;
|
| + }
|
| +
|
| + std::unique_ptr<aura::Window> CreateChildWindow(
|
| + aura::Window* parent,
|
| + aura::client::WindowType type = aura::client::WINDOW_TYPE_NORMAL) {
|
| + std::unique_ptr<aura::Window> window =
|
| + base::MakeUnique<aura::Window>(nullptr, type);
|
| + window->Init(ui::LAYER_NOT_DRAWN);
|
| + window->SetBounds(gfx::Rect());
|
| + parent->AddChild(window.get());
|
| + window->Show();
|
| + return window;
|
| }
|
|
|
| void SetUp() override {
|
| fake_frontend_channel_ = base::MakeUnique<FakeFrontendChannel>();
|
| uber_dispatcher_ =
|
| base::MakeUnique<UberDispatcher>(fake_frontend_channel_.get());
|
| - dom_agent_ = base::MakeUnique<devtools::AshDevToolsDOMAgent>();
|
| + dom_agent_ = base::MakeUnique<devtools::UIDevToolsDOMAgent>();
|
| dom_agent_->Init(uber_dispatcher_.get());
|
| css_agent_ =
|
| - base::MakeUnique<devtools::AshDevToolsCSSAgent>(dom_agent_.get());
|
| + base::MakeUnique<devtools::UIDevToolsCSSAgent>(dom_agent_.get());
|
| css_agent_->Init(uber_dispatcher_.get());
|
| css_agent_->enable();
|
| +
|
| // We need to create |dom_agent| first to observe creation of
|
| - // WindowTreeHosts in AshTestBase::SetUp().
|
| - AshTestBase::SetUp();
|
| + // WindowTreeHosts in ViewTestBase::SetUp().
|
| + views::ViewsTestBase::SetUp();
|
| +
|
| + top_window = CreateChildWindow(GetPrimaryRootWindow());
|
| + top_default_container_window = CreateChildWindow(GetPrimaryRootWindow());
|
| + top_overlay_window = CreateChildWindow(GetPrimaryRootWindow(),
|
| + aura::client::WINDOW_TYPE_UNKNOWN);
|
| }
|
|
|
| void TearDown() override {
|
| + top_overlay_window.reset();
|
| + top_default_container_window.reset();
|
| + top_window.reset();
|
| css_agent_.reset();
|
| dom_agent_.reset();
|
| uber_dispatcher_.reset();
|
| fake_frontend_channel_.reset();
|
| - AshTestBase::TearDown();
|
| + views::ViewsTestBase::TearDown();
|
| }
|
|
|
| void ExpectChildNodeInserted(int parent_id, int prev_sibling_id) {
|
| @@ -299,19 +327,23 @@ class AshDevToolsTest : public test::AshTestBase {
|
| return dom_agent()->root_windows()[0];
|
| }
|
|
|
| - devtools::AshDevToolsCSSAgent* css_agent() { return css_agent_.get(); }
|
| - devtools::AshDevToolsDOMAgent* dom_agent() { return dom_agent_.get(); }
|
| + devtools::UIDevToolsCSSAgent* css_agent() { return css_agent_.get(); }
|
| + devtools::UIDevToolsDOMAgent* dom_agent() { return dom_agent_.get(); }
|
| +
|
| + std::unique_ptr<aura::Window> top_overlay_window;
|
| + std::unique_ptr<aura::Window> top_window;
|
| + std::unique_ptr<aura::Window> top_default_container_window;
|
|
|
| private:
|
| std::unique_ptr<UberDispatcher> uber_dispatcher_;
|
| std::unique_ptr<FakeFrontendChannel> fake_frontend_channel_;
|
| - std::unique_ptr<devtools::AshDevToolsDOMAgent> dom_agent_;
|
| - std::unique_ptr<devtools::AshDevToolsCSSAgent> css_agent_;
|
| + std::unique_ptr<devtools::UIDevToolsDOMAgent> dom_agent_;
|
| + std::unique_ptr<devtools::UIDevToolsCSSAgent> css_agent_;
|
|
|
| - DISALLOW_COPY_AND_ASSIGN(AshDevToolsTest);
|
| + DISALLOW_COPY_AND_ASSIGN(UIDevToolsTest);
|
| };
|
|
|
| -TEST_F(AshDevToolsTest, GetDocumentWithWindowWidgetView) {
|
| +TEST_F(UIDevToolsTest, GetDocumentWithWindowWidgetView) {
|
| std::unique_ptr<views::Widget> widget(
|
| CreateTestWidget(gfx::Rect(1, 1, 1, 1)));
|
| aura::Window* parent_window = widget->GetNativeWindow();
|
| @@ -339,7 +371,7 @@ TEST_F(AshDevToolsTest, GetDocumentWithWindowWidgetView) {
|
| Compare(child_view, widget_children->get(0)->getChildren(nullptr)->get(1));
|
| }
|
|
|
| -TEST_F(AshDevToolsTest, GetDocumentNativeWidgetOwnsWidget) {
|
| +TEST_F(UIDevToolsTest, GetDocumentNativeWidgetOwnsWidget) {
|
| views::internal::NativeWidgetPrivate* native_widget_private =
|
| CreateTestNativeWidget();
|
| views::Widget* widget = native_widget_private->GetWidget();
|
| @@ -356,8 +388,11 @@ TEST_F(AshDevToolsTest, GetDocumentNativeWidgetOwnsWidget) {
|
| widget->CloseNow();
|
| }
|
|
|
| -TEST_F(AshDevToolsTest, WindowAddedChildNodeInserted) {
|
| +TEST_F(UIDevToolsTest, WindowAddedChildNodeInserted) {
|
| // Initialize DOMAgent
|
| + std::unique_ptr<aura::Window> window_child =
|
| + CreateChildWindow(top_window.get());
|
| +
|
| std::unique_ptr<ui::devtools::protocol::DOM::Node> root;
|
| dom_agent()->getDocument(&root);
|
|
|
| @@ -372,7 +407,10 @@ TEST_F(AshDevToolsTest, WindowAddedChildNodeInserted) {
|
| ExpectChildNodeInserted(parent_node->getNodeId(), sibling_node->getNodeId());
|
| }
|
|
|
| -TEST_F(AshDevToolsTest, WindowDestroyedChildNodeRemoved) {
|
| +TEST_F(UIDevToolsTest, WindowDestroyedChildNodeRemoved) {
|
| + std::unique_ptr<aura::Window> child_1 = CreateChildWindow(top_window.get());
|
| + std::unique_ptr<aura::Window> child_2 = CreateChildWindow(child_1.get());
|
| +
|
| // Initialize DOMAgent
|
| std::unique_ptr<ui::devtools::protocol::DOM::Node> root;
|
| dom_agent()->getDocument(&root);
|
| @@ -388,11 +426,16 @@ TEST_F(AshDevToolsTest, WindowDestroyedChildNodeRemoved) {
|
|
|
| Compare(parent_window, parent_node);
|
| Compare(child_window, child_node);
|
| - delete child_window;
|
| + child_2.reset();
|
| ExpectChildNodeRemoved(parent_node->getNodeId(), child_node->getNodeId());
|
| }
|
|
|
| -TEST_F(AshDevToolsTest, WindowReorganizedChildNodeRearranged) {
|
| +TEST_F(UIDevToolsTest, WindowReorganizedChildNodeRearranged) {
|
| + std::unique_ptr<aura::Window> child_1 = CreateChildWindow(top_window.get());
|
| + std::unique_ptr<aura::Window> child_2 = CreateChildWindow(top_window.get());
|
| + std::unique_ptr<aura::Window> child_11 = CreateChildWindow(child_1.get());
|
| + std::unique_ptr<aura::Window> child_21 = CreateChildWindow(child_2.get());
|
| +
|
| // Initialize DOMAgent
|
| std::unique_ptr<ui::devtools::protocol::DOM::Node> root;
|
| dom_agent()->getDocument(&root);
|
| @@ -420,7 +463,12 @@ TEST_F(AshDevToolsTest, WindowReorganizedChildNodeRearranged) {
|
| ExpectChildNodeInserted(target_node->getNodeId(), sibling_node->getNodeId());
|
| }
|
|
|
| -TEST_F(AshDevToolsTest, WindowReorganizedChildNodeRemovedAndInserted) {
|
| +TEST_F(UIDevToolsTest, WindowReorganizedChildNodeRemovedAndInserted) {
|
| + std::unique_ptr<aura::Window> child_1 = CreateChildWindow(top_window.get());
|
| + std::unique_ptr<aura::Window> child_2 = CreateChildWindow(top_window.get());
|
| + std::unique_ptr<aura::Window> child_21 = CreateChildWindow(child_2.get());
|
| + std::unique_ptr<aura::Window> child_22 = CreateChildWindow(child_2.get());
|
| +
|
| aura::Window* root_window = GetPrimaryRootWindow();
|
| aura::Window* rotation_window = root_window->children()[0];
|
| aura::Window* parent_window = rotation_window->children()[0];
|
| @@ -450,7 +498,11 @@ TEST_F(AshDevToolsTest, WindowReorganizedChildNodeRemovedAndInserted) {
|
| ExpectChildNodeInserted(target_node->getNodeId(), sibling_node->getNodeId());
|
| }
|
|
|
| -TEST_F(AshDevToolsTest, WindowStackingChangedChildNodeRemovedAndInserted) {
|
| +TEST_F(UIDevToolsTest, WindowStackingChangedChildNodeRemovedAndInserted) {
|
| + std::unique_ptr<aura::Window> child_11 = CreateChildWindow(top_window.get());
|
| + std::unique_ptr<aura::Window> child_12 = CreateChildWindow(top_window.get());
|
| + std::unique_ptr<aura::Window> child_13 = CreateChildWindow(top_window.get());
|
| +
|
| // Initialize DOMAgent
|
| std::unique_ptr<ui::devtools::protocol::DOM::Node> root;
|
| dom_agent()->getDocument(&root);
|
| @@ -474,7 +526,7 @@ TEST_F(AshDevToolsTest, WindowStackingChangedChildNodeRemovedAndInserted) {
|
| ExpectChildNodeInserted(parent_id, sibling_node->getNodeId());
|
| }
|
|
|
| -TEST_F(AshDevToolsTest, ViewInserted) {
|
| +TEST_F(UIDevToolsTest, ViewInserted) {
|
| std::unique_ptr<views::Widget> widget(
|
| CreateTestWidget(gfx::Rect(1, 1, 1, 1)));
|
| aura::Window* window = widget->GetNativeWindow();
|
| @@ -498,7 +550,7 @@ TEST_F(AshDevToolsTest, ViewInserted) {
|
| sibling_view_node->getNodeId());
|
| }
|
|
|
| -TEST_F(AshDevToolsTest, ViewRemoved) {
|
| +TEST_F(UIDevToolsTest, ViewRemoved) {
|
| std::unique_ptr<views::Widget> widget(
|
| CreateTestWidget(gfx::Rect(1, 1, 1, 1)));
|
| // Need to store |view| in unique_ptr because it is removed from the widget
|
| @@ -528,7 +580,7 @@ TEST_F(AshDevToolsTest, ViewRemoved) {
|
| child_view_node->getNodeId());
|
| }
|
|
|
| -TEST_F(AshDevToolsTest, ViewRearranged) {
|
| +TEST_F(UIDevToolsTest, ViewRearranged) {
|
| std::unique_ptr<views::Widget> widget(
|
| CreateTestWidget(gfx::Rect(1, 1, 1, 1)));
|
| aura::Window* window = widget->GetNativeWindow();
|
| @@ -581,7 +633,7 @@ TEST_F(AshDevToolsTest, ViewRearranged) {
|
| ExpectChildNodeInserted(target_view_node->getNodeId(), 0);
|
| }
|
|
|
| -TEST_F(AshDevToolsTest, ViewRearrangedRemovedAndInserted) {
|
| +TEST_F(UIDevToolsTest, ViewRearrangedRemovedAndInserted) {
|
| std::unique_ptr<views::Widget> widget(
|
| CreateTestWidget(gfx::Rect(1, 1, 1, 1)));
|
| aura::Window* window = widget->GetNativeWindow();
|
| @@ -620,7 +672,7 @@ TEST_F(AshDevToolsTest, ViewRearrangedRemovedAndInserted) {
|
| ExpectChildNodeInserted(target_view_node->getNodeId(), 0);
|
| }
|
|
|
| -TEST_F(AshDevToolsTest, WindowWidgetViewHighlight) {
|
| +TEST_F(UIDevToolsTest, WindowWidgetViewHighlight) {
|
| std::unique_ptr<views::Widget> widget(
|
| CreateTestWidget(gfx::Rect(0, 0, 400, 400)));
|
| aura::Window* parent_window = widget->GetNativeWindow();
|
| @@ -697,7 +749,7 @@ int GetNodeIdFromWindow(devtools::UIElement* ui_element, aura::Window* window) {
|
| // TODO(thanhph): Make test AshDevToolsTest.MultipleDisplayHighlight work with
|
| // multiple displays. https://crbug.com/726831.
|
|
|
| -TEST_F(AshDevToolsTest, WindowWidgetViewGetMatchedStylesForNode) {
|
| +TEST_F(UIDevToolsTest, WindowWidgetViewGetMatchedStylesForNode) {
|
| std::unique_ptr<views::Widget> widget(
|
| CreateTestWidget(gfx::Rect(1, 1, 1, 1)));
|
| aura::Window* parent_window = widget->GetNativeWindow();
|
| @@ -723,7 +775,7 @@ TEST_F(AshDevToolsTest, WindowWidgetViewGetMatchedStylesForNode) {
|
| view_bounds);
|
| }
|
|
|
| -TEST_F(AshDevToolsTest, WindowWidgetViewStyleSheetChanged) {
|
| +TEST_F(UIDevToolsTest, WindowWidgetViewStyleSheetChanged) {
|
| std::unique_ptr<views::Widget> widget(
|
| CreateTestWidget(gfx::Rect(1, 1, 1, 1)));
|
| aura::Window* widget_window = widget->GetNativeWindow();
|
| @@ -747,14 +799,13 @@ TEST_F(AshDevToolsTest, WindowWidgetViewStyleSheetChanged) {
|
| EXPECT_EQ(1, GetStyleSheetChangedCount(widget_node->getNodeId()));
|
| EXPECT_EQ(
|
| 1, GetStyleSheetChangedCount(widget_node_children->get(1)->getNodeId()));
|
| - EXPECT_EQ(2,
|
| - GetStyleSheetChangedCount(widget_node_children->get(0)
|
| - ->getChildren(nullptr)
|
| - ->get(0)
|
| - ->getNodeId()));
|
| + EXPECT_EQ(2, GetStyleSheetChangedCount(widget_node_children->get(0)
|
| + ->getChildren(nullptr)
|
| + ->get(0)
|
| + ->getNodeId()));
|
| }
|
|
|
| -TEST_F(AshDevToolsTest, WindowWidgetViewSetStyleText) {
|
| +TEST_F(UIDevToolsTest, WindowWidgetViewSetStyleText) {
|
| std::unique_ptr<views::Widget> widget(
|
| CreateTestWidget(gfx::Rect(0, 0, 400, 400)));
|
| aura::Window* parent_window = widget->GetNativeWindow();
|
| @@ -826,4 +877,4 @@ TEST_F(AshDevToolsTest, WindowWidgetViewSetStyleText) {
|
| EXPECT_TRUE(root_view->visible());
|
| }
|
|
|
| -} // namespace ash
|
| +} // namespace ui
|
|
|