| OLD | NEW |
| 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 "ash/devtools/ash_devtools_css_agent.h" | 5 #include "ash/devtools/ash_devtools_css_agent.h" |
| 6 #include "ash/devtools/ash_devtools_dom_agent.h" | 6 #include "ash/devtools/ash_devtools_dom_agent.h" |
| 7 #include "ash/devtools/ui_element.h" |
| 8 #include "ash/devtools/window_element.h" |
| 7 #include "ash/public/cpp/shell_window_ids.h" | 9 #include "ash/public/cpp/shell_window_ids.h" |
| 8 #include "ash/root_window_controller.h" | 10 #include "ash/root_window_controller.h" |
| 9 #include "ash/shell.h" | 11 #include "ash/shell.h" |
| 10 #include "ash/test/ash_test_base.h" | 12 #include "ash/test/ash_test_base.h" |
| 11 #include "ash/wm/widget_finder.h" | 13 #include "ash/wm/widget_finder.h" |
| 12 #include "base/memory/ptr_util.h" | 14 #include "base/memory/ptr_util.h" |
| 13 #include "base/strings/stringprintf.h" | 15 #include "base/strings/stringprintf.h" |
| 14 #include "ui/display/display.h" | 16 #include "ui/display/display.h" |
| 15 #include "ui/views/background.h" | 17 #include "ui/views/background.h" |
| 16 #include "ui/views/widget/native_widget_private.h" | 18 #include "ui/views/widget/native_widget_private.h" |
| 17 #include "ui/views/widget/widget.h" | 19 #include "ui/views/widget/widget.h" |
| 18 | 20 |
| 19 namespace ash { | 21 namespace ash { |
| 20 namespace { | 22 namespace { |
| 21 using namespace ui::devtools::protocol; | 23 using namespace ui::devtools::protocol; |
| 24 |
| 22 const int kDefaultChildNodeCount = -1; | 25 const int kDefaultChildNodeCount = -1; |
| 23 const SkColor kBackgroundColor = SK_ColorRED; | 26 const SkColor kBackgroundColor = SK_ColorRED; |
| 24 const SkColor kBorderColor = SK_ColorBLUE; | 27 const SkColor kBorderColor = SK_ColorBLUE; |
| 25 | 28 |
| 26 class TestView : public views::View { | 29 class TestView : public views::View { |
| 27 public: | 30 public: |
| 28 TestView(const char* name) : views::View(), name_(name) {} | 31 TestView(const char* name) : views::View(), name_(name) {} |
| 29 | 32 |
| 30 const char* GetClassName() const override { return name_; } | 33 const char* GetClassName() const override { return name_; } |
| 31 | 34 |
| (...skipping 595 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 627 HighlightNode(root_view_node->getNodeId()); | 630 HighlightNode(root_view_node->getNodeId()); |
| 628 ExpectHighlighted(root_view->GetBoundsInScreen(), 0); | 631 ExpectHighlighted(root_view->GetBoundsInScreen(), 0); |
| 629 | 632 |
| 630 HideHighlight(0); | 633 HideHighlight(0); |
| 631 | 634 |
| 632 // Highlight non-existent node | 635 // Highlight non-existent node |
| 633 HighlightNode(10000); | 636 HighlightNode(10000); |
| 634 EXPECT_FALSE(GetHighlightingWindow(0)->IsVisible()); | 637 EXPECT_FALSE(GetHighlightingWindow(0)->IsVisible()); |
| 635 } | 638 } |
| 636 | 639 |
| 640 int GetNodeIdFromWindow(devtools::UIElement* ui_element, aura::Window* window) { |
| 641 for (auto* child : ui_element->GetChildren()) { |
| 642 if (child->GetType() == devtools::UIElementType::WINDOW && |
| 643 static_cast<devtools::WindowElement*>(child)->window() == window) { |
| 644 return child->GetNodeId(); |
| 645 } |
| 646 } |
| 647 for (auto* child : ui_element->GetChildren()) { |
| 648 if (child->GetType() == devtools::UIElementType::WINDOW) { |
| 649 int node_id = GetNodeIdFromWindow(child, window); |
| 650 if (node_id > 0) |
| 651 return node_id; |
| 652 } |
| 653 } |
| 654 return 0; |
| 655 } |
| 656 |
| 637 TEST_F(AshDevToolsTest, MultipleDisplayHighlight) { | 657 TEST_F(AshDevToolsTest, MultipleDisplayHighlight) { |
| 638 UpdateDisplay("300x400,500x500"); | 658 UpdateDisplay("300x400,500x500"); |
| 639 | 659 |
| 640 aura::Window::Windows root_windows = Shell::GetAllRootWindows(); | 660 aura::Window::Windows root_windows = Shell::GetAllRootWindows(); |
| 641 std::unique_ptr<aura::Window> window( | 661 std::unique_ptr<aura::Window> window( |
| 642 CreateTestWindowInShellWithBounds(gfx::Rect(1, 2, 30, 40))); | 662 CreateTestWindowInShellWithBounds(gfx::Rect(1, 2, 30, 40))); |
| 643 | 663 |
| 644 std::unique_ptr<ui::devtools::protocol::DOM::Node> root; | 664 std::unique_ptr<ui::devtools::protocol::DOM::Node> root; |
| 645 dom_agent()->getDocument(&root); | 665 dom_agent()->getDocument(&root); |
| 646 | 666 |
| 647 EXPECT_EQ(root_windows[0], window->GetRootWindow()); | 667 EXPECT_EQ(root_windows[0], window->GetRootWindow()); |
| 648 HighlightNode(dom_agent()->GetNodeIdFromWindow(window.get())); | 668 HighlightNode( |
| 669 GetNodeIdFromWindow(dom_agent()->GetWindowElementRoot(), window.get())); |
| 649 ExpectHighlighted(window->GetBoundsInScreen(), 0); | 670 ExpectHighlighted(window->GetBoundsInScreen(), 0); |
| 650 | 671 |
| 651 window->SetBoundsInScreen(gfx::Rect(500, 0, 50, 50), GetSecondaryDisplay()); | 672 window->SetBoundsInScreen(gfx::Rect(500, 0, 50, 50), GetSecondaryDisplay()); |
| 652 EXPECT_EQ(root_windows[1], window->GetRootWindow()); | 673 EXPECT_EQ(root_windows[1], window->GetRootWindow()); |
| 653 HighlightNode(dom_agent()->GetNodeIdFromWindow(window.get())); | 674 HighlightNode( |
| 675 GetNodeIdFromWindow(dom_agent()->GetWindowElementRoot(), window.get())); |
| 654 ExpectHighlighted(window->GetBoundsInScreen(), 1); | 676 ExpectHighlighted(window->GetBoundsInScreen(), 1); |
| 655 } | 677 } |
| 656 | 678 |
| 657 TEST_F(AshDevToolsTest, WindowWidgetViewGetMatchedStylesForNode) { | 679 TEST_F(AshDevToolsTest, WindowWidgetViewGetMatchedStylesForNode) { |
| 658 std::unique_ptr<views::Widget> widget( | 680 std::unique_ptr<views::Widget> widget( |
| 659 CreateTestWidget(gfx::Rect(1, 1, 1, 1))); | 681 CreateTestWidget(gfx::Rect(1, 1, 1, 1))); |
| 660 aura::Window* parent_window = widget->GetNativeWindow(); | 682 aura::Window* parent_window = widget->GetNativeWindow(); |
| 661 std::unique_ptr<aura::Window> window(CreateChildWindow(parent_window)); | 683 std::unique_ptr<aura::Window> window(CreateChildWindow(parent_window)); |
| 662 gfx::Rect window_bounds(2, 2, 3, 3); | 684 gfx::Rect window_bounds(2, 2, 3, 3); |
| 663 gfx::Rect widget_bounds(50, 50, 100, 75); | 685 gfx::Rect widget_bounds(50, 50, 100, 75); |
| (...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 777 SetStyleTexts(root_view_node, "\nheight: 73;\n ", true); | 799 SetStyleTexts(root_view_node, "\nheight: 73;\n ", true); |
| 778 EXPECT_EQ(gfx::Rect(25, 35, 45, 73), root_view->bounds()); | 800 EXPECT_EQ(gfx::Rect(25, 35, 45, 73), root_view->bounds()); |
| 779 | 801 |
| 780 SetStyleTexts(root_view_node, "\nx: 10; y: 23; width: 52;\nvisibility: 1;\n", | 802 SetStyleTexts(root_view_node, "\nx: 10; y: 23; width: 52;\nvisibility: 1;\n", |
| 781 true); | 803 true); |
| 782 EXPECT_EQ(gfx::Rect(10, 23, 52, 73), root_view->bounds()); | 804 EXPECT_EQ(gfx::Rect(10, 23, 52, 73), root_view->bounds()); |
| 783 EXPECT_TRUE(root_view->visible()); | 805 EXPECT_TRUE(root_view->visible()); |
| 784 } | 806 } |
| 785 | 807 |
| 786 } // namespace ash | 808 } // namespace ash |
| OLD | NEW |