| Index: components/ui_devtools/devtools/ui_devtools_unittest.cc
|
| diff --git a/ash/devtools/ash_devtools_unittest.cc b/components/ui_devtools/devtools/ui_devtools_unittest.cc
|
| similarity index 83%
|
| rename from ash/devtools/ash_devtools_unittest.cc
|
| rename to components/ui_devtools/devtools/ui_devtools_unittest.cc
|
| index 89de77da5ddfc314f1d14595ef6340f5c451c266..d78b329c185af30f9ebf6b9ec10e56dc391513c7 100644
|
| --- a/ash/devtools/ash_devtools_unittest.cc
|
| +++ b/components/ui_devtools/devtools/ui_devtools_unittest.cc
|
| @@ -2,23 +2,21 @@
|
| // 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/window_element.h"
|
| #include "ash/public/cpp/shell_window_ids.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/devtools/ui_devtools_css_agent.h"
|
| +#include "components/ui_devtools/devtools/ui_devtools_dom_agent.h"
|
| +#include "components/ui_devtools/devtools/ui_element.h"
|
| +#include "components/ui_devtools/devtools/window_element.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"
|
|
|
| -namespace ash {
|
| +namespace ui {
|
| namespace {
|
|
|
| using namespace ui::devtools::protocol;
|
| @@ -85,7 +83,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) &&
|
| @@ -140,7 +138,8 @@ int GetPropertyByName(const std::string& name,
|
|
|
| aura::Window* GetHighlightingWindow(aura::Window* root_window) {
|
| const aura::Window::Windows& overlay_windows =
|
| - root_window->GetChildById(kShellWindowId_OverlayContainer)->children();
|
| + root_window->GetChildById(ash::kShellWindowId_OverlayContainer)
|
| + ->children();
|
| for (aura::Window* window : overlay_windows) {
|
| if (window->GetName() == "HighlightingWidget")
|
| return window;
|
| @@ -171,18 +170,18 @@ 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());
|
| + views::Widget* widget =
|
| + views::Widget::GetWidgetForNativeView(highlighting_window);
|
| +
|
| + EXPECT_EQ(kBackgroundColor, widget->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;
|
| @@ -191,36 +190,73 @@ class AshDevToolsTest : public test::AshTestBase {
|
| params.parent = nullptr;
|
| if (!dom_agent()->root_windows().empty()) {
|
| params.parent = dom_agent()->root_windows()[0]->GetChildById(
|
| - kShellWindowId_DefaultContainer);
|
| + ash::kShellWindowId_DefaultContainer);
|
| }
|
| 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> CreateTestWidget(
|
| + const gfx::Rect& bounds,
|
| + aura::Window* parent = nullptr) {
|
| + 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 = parent;
|
| + if (!parent && !dom_agent()->root_windows().empty()) {
|
| + params.parent = dom_agent()->root_windows()[0]->GetChildById(
|
| + ash::kShellWindowId_Invalid);
|
| + }
|
| + widget->Init(params);
|
| + widget->Show();
|
| + return widget;
|
| + }
|
| +
|
| + std::unique_ptr<aura::Window> CreateChildWindow(
|
| + aura::Window* parent,
|
| + int id = ash::kShellWindowId_Invalid,
|
| + ui::wm::WindowType type = ui::wm::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());
|
| + window->set_id(id);
|
| + 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();
|
| - AshTestBase::SetUp();
|
| + views::ViewsTestBase::SetUp();
|
| + top_window = CreateChildWindow(dom_agent()->root_windows()[0]);
|
| + top_default_container_window = CreateChildWindow(
|
| + dom_agent()->root_windows()[0], ash::kShellWindowId_DefaultContainer);
|
| + top_overlay_window = CreateChildWindow(dom_agent()->root_windows()[0],
|
| + ash::kShellWindowId_OverlayContainer,
|
| + ui::wm::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) {
|
| @@ -292,19 +328,23 @@ class AshDevToolsTest : public test::AshTestBase {
|
| return fake_frontend_channel_.get();
|
| }
|
|
|
| - 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();
|
| @@ -332,7 +372,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();
|
| @@ -349,11 +389,13 @@ TEST_F(AshDevToolsTest, GetDocumentNativeWidgetOwnsWidget) {
|
| widget->CloseNow();
|
| }
|
|
|
| -TEST_F(AshDevToolsTest, WindowAddedChildNodeInserted) {
|
| +TEST_F(UIDevToolsTest, WindowAddedChildNodeInserted) {
|
| // Initialize DOMAgent
|
| + std::unique_ptr<aura::Window> top_invalid_window_child =
|
| + CreateChildWindow(top_window.get());
|
| +
|
| std::unique_ptr<ui::devtools::protocol::DOM::Node> root;
|
| dom_agent()->getDocument(&root);
|
| -
|
| aura::Window* root_window = dom_agent()->root_windows()[0];
|
| aura::Window* parent_window = root_window->children()[0];
|
| DOM::Node* parent_node = FindInRoot(parent_window, root.get());
|
| @@ -363,9 +405,13 @@ TEST_F(AshDevToolsTest, WindowAddedChildNodeInserted) {
|
|
|
| std::unique_ptr<aura::Window> child(CreateChildWindow(parent_window));
|
| ExpectChildNodeInserted(parent_node->getNodeId(), sibling_node->getNodeId());
|
| + top_invalid_window_child.reset();
|
| }
|
|
|
| -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);
|
| @@ -381,15 +427,19 @@ 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());
|
| + child_1.reset();
|
| }
|
|
|
| -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);
|
| -
|
| aura::Window* root_window = dom_agent()->root_windows()[0];
|
| aura::Window* rotation_window = root_window->children()[0];
|
| aura::Window* parent_window = rotation_window->children()[0];
|
| @@ -413,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 = dom_agent()->root_windows()[0];
|
| aura::Window* rotation_window = root_window->children()[0];
|
| aura::Window* parent_window = rotation_window->children()[0];
|
| @@ -443,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);
|
| @@ -467,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();
|
| @@ -491,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
|
| @@ -521,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();
|
| @@ -574,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();
|
| @@ -613,7 +672,10 @@ TEST_F(AshDevToolsTest, ViewRearrangedRemovedAndInserted) {
|
| ExpectChildNodeInserted(target_view_node->getNodeId(), 0);
|
| }
|
|
|
| -TEST_F(AshDevToolsTest, WindowWidgetViewHighlight) {
|
| +TEST_F(UIDevToolsTest, WindowWidgetViewHighlight) {
|
| + DCHECK_EQ(dom_agent()->root_windows()[0]->GetChildById(
|
| + ash::kShellWindowId_OverlayContainer),
|
| + top_overlay_window.get());
|
| std::unique_ptr<views::Widget> widget(
|
| CreateTestWidget(gfx::Rect(0, 0, 400, 400)));
|
| aura::Window* parent_window = widget->GetNativeWindow();
|
| @@ -672,31 +734,10 @@ int GetNodeIdFromWindow(devtools::UIElement* ui_element, aura::Window* window) {
|
| return 0;
|
| }
|
|
|
| -TEST_F(AshDevToolsTest, MultipleDisplayHighlight) {
|
| - UpdateDisplay("300x400,500x500");
|
| -
|
| - aura::Window::Windows root_windows = dom_agent()->root_windows();
|
| - std::unique_ptr<aura::Window> window(
|
| - CreateTestWindowInShellWithBounds(gfx::Rect(1, 2, 30, 40)));
|
| -
|
| - std::unique_ptr<ui::devtools::protocol::DOM::Node> root;
|
| - dom_agent()->getDocument(&root);
|
| -
|
| - EXPECT_EQ(root_windows[0], window->GetRootWindow());
|
| - HighlightNode(
|
| - GetNodeIdFromWindow(dom_agent()->window_element_root(), window.get()));
|
| - ExpectHighlighted(window->GetBoundsInScreen(),
|
| - dom_agent()->root_windows()[0]);
|
| -
|
| - window->SetBoundsInScreen(gfx::Rect(500, 0, 50, 50), GetSecondaryDisplay());
|
| - EXPECT_EQ(root_windows[1], window->GetRootWindow());
|
| - HighlightNode(
|
| - GetNodeIdFromWindow(dom_agent()->window_element_root(), window.get()));
|
| - ExpectHighlighted(window->GetBoundsInScreen(),
|
| - dom_agent()->root_windows()[1]);
|
| -}
|
| +// TODO(thanhph): Add UIDevToolsTest.MultipleDisplayHighlight back when multiple
|
| +// displays are available for ViewTestBase.
|
|
|
| -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();
|
| @@ -722,7 +763,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();
|
| @@ -746,14 +787,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();
|
| @@ -825,4 +865,4 @@ TEST_F(AshDevToolsTest, WindowWidgetViewSetStyleText) {
|
| EXPECT_TRUE(root_view->visible());
|
| }
|
|
|
| -} // namespace ash
|
| +} // namespace ui
|
|
|