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/shell_port.h" | 12 #include "ash/shell_port.h" |
11 #include "ash/test/ash_test.h" | 13 #include "ash/test/ash_test.h" |
12 #include "ash/wm/widget_finder.h" | 14 #include "ash/wm/widget_finder.h" |
13 #include "ash/wm_window.h" | 15 #include "ash/wm_window.h" |
14 #include "base/memory/ptr_util.h" | 16 #include "base/memory/ptr_util.h" |
15 #include "base/strings/stringprintf.h" | 17 #include "base/strings/stringprintf.h" |
16 #include "ui/display/display.h" | 18 #include "ui/display/display.h" |
(...skipping 611 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
628 HighlightNode(root_view_node->getNodeId()); | 630 HighlightNode(root_view_node->getNodeId()); |
629 ExpectHighlighted(root_view->GetBoundsInScreen(), 0); | 631 ExpectHighlighted(root_view->GetBoundsInScreen(), 0); |
630 | 632 |
631 HideHighlight(0); | 633 HideHighlight(0); |
632 | 634 |
633 // Highlight non-existent node | 635 // Highlight non-existent node |
634 HighlightNode(10000); | 636 HighlightNode(10000); |
635 EXPECT_FALSE(GetHighlightingWindow(0)->IsVisible()); | 637 EXPECT_FALSE(GetHighlightingWindow(0)->IsVisible()); |
636 } | 638 } |
637 | 639 |
| 640 int GetNodeIdFromWindow(devtools::UIElement* ui_element, WmWindow* 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 |
638 TEST_F(AshDevToolsTest, MultipleDisplayHighlight) { | 657 TEST_F(AshDevToolsTest, MultipleDisplayHighlight) { |
639 UpdateDisplay("300x400,500x500"); | 658 UpdateDisplay("300x400,500x500"); |
640 | 659 |
641 WmWindow::Windows root_windows = ShellPort::Get()->GetAllRootWindows(); | 660 WmWindow::Windows root_windows = ShellPort::Get()->GetAllRootWindows(); |
642 std::unique_ptr<WindowOwner> window_owner( | 661 std::unique_ptr<WindowOwner> window_owner( |
643 CreateTestWindow(gfx::Rect(1, 2, 30, 40))); | 662 CreateTestWindow(gfx::Rect(1, 2, 30, 40))); |
644 WmWindow* window = window_owner->window(); | 663 WmWindow* window = window_owner->window(); |
645 | 664 |
646 std::unique_ptr<ui::devtools::protocol::DOM::Node> root; | 665 std::unique_ptr<ui::devtools::protocol::DOM::Node> root; |
647 dom_agent()->getDocument(&root); | 666 dom_agent()->getDocument(&root); |
648 | 667 |
649 EXPECT_EQ(root_windows[0], window->GetRootWindow()); | 668 EXPECT_EQ(root_windows[0], window->GetRootWindow()); |
650 HighlightNode(dom_agent()->GetNodeIdFromWindow(window)); | 669 HighlightNode( |
| 670 GetNodeIdFromWindow(dom_agent()->GetWindowElementRoot(), window)); |
651 ExpectHighlighted(window->GetBoundsInScreen(), 0); | 671 ExpectHighlighted(window->GetBoundsInScreen(), 0); |
652 | 672 |
653 window->SetBoundsInScreen(gfx::Rect(500, 0, 50, 50), GetSecondaryDisplay()); | 673 window->SetBoundsInScreen(gfx::Rect(500, 0, 50, 50), GetSecondaryDisplay()); |
654 EXPECT_EQ(root_windows[1], window->GetRootWindow()); | 674 EXPECT_EQ(root_windows[1], window->GetRootWindow()); |
655 HighlightNode(dom_agent()->GetNodeIdFromWindow(window)); | 675 HighlightNode( |
| 676 GetNodeIdFromWindow(dom_agent()->GetWindowElementRoot(), window)); |
656 ExpectHighlighted(window->GetBoundsInScreen(), 1); | 677 ExpectHighlighted(window->GetBoundsInScreen(), 1); |
657 } | 678 } |
658 | 679 |
659 TEST_F(AshDevToolsTest, WindowWidgetViewGetMatchedStylesForNode) { | 680 TEST_F(AshDevToolsTest, WindowWidgetViewGetMatchedStylesForNode) { |
660 std::unique_ptr<views::Widget> widget( | 681 std::unique_ptr<views::Widget> widget( |
661 CreateTestWidget(gfx::Rect(1, 1, 1, 1))); | 682 CreateTestWidget(gfx::Rect(1, 1, 1, 1))); |
662 WmWindow* parent_window = WmWindow::Get(widget->GetNativeWindow()); | 683 WmWindow* parent_window = WmWindow::Get(widget->GetNativeWindow()); |
663 std::unique_ptr<WindowOwner> child_owner(CreateChildWindow(parent_window)); | 684 std::unique_ptr<WindowOwner> child_owner(CreateChildWindow(parent_window)); |
664 WmWindow* window = child_owner->window(); | 685 WmWindow* window = child_owner->window(); |
665 gfx::Rect window_bounds(2, 2, 3, 3); | 686 gfx::Rect window_bounds(2, 2, 3, 3); |
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
782 SetStyleTexts(root_view_node, "\nheight: 73;\n ", true); | 803 SetStyleTexts(root_view_node, "\nheight: 73;\n ", true); |
783 EXPECT_EQ(gfx::Rect(25, 35, 45, 73), root_view->bounds()); | 804 EXPECT_EQ(gfx::Rect(25, 35, 45, 73), root_view->bounds()); |
784 | 805 |
785 SetStyleTexts(root_view_node, "\nx: 10; y: 23; width: 52;\nvisibility: 1;\n", | 806 SetStyleTexts(root_view_node, "\nx: 10; y: 23; width: 52;\nvisibility: 1;\n", |
786 true); | 807 true); |
787 EXPECT_EQ(gfx::Rect(10, 23, 52, 73), root_view->bounds()); | 808 EXPECT_EQ(gfx::Rect(10, 23, 52, 73), root_view->bounds()); |
788 EXPECT_TRUE(root_view->visible()); | 809 EXPECT_TRUE(root_view->visible()); |
789 } | 810 } |
790 | 811 |
791 } // namespace ash | 812 } // namespace ash |
OLD | NEW |