| 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" | |
| 9 #include "ash/public/cpp/shell_window_ids.h" | 7 #include "ash/public/cpp/shell_window_ids.h" |
| 10 #include "ash/root_window_controller.h" | 8 #include "ash/root_window_controller.h" |
| 11 #include "ash/shell.h" | 9 #include "ash/shell.h" |
| 12 #include "ash/test/ash_test_base.h" | 10 #include "ash/test/ash_test_base.h" |
| 13 #include "ash/wm/widget_finder.h" | 11 #include "ash/wm/widget_finder.h" |
| 14 #include "base/memory/ptr_util.h" | 12 #include "base/memory/ptr_util.h" |
| 15 #include "base/strings/stringprintf.h" | 13 #include "base/strings/stringprintf.h" |
| 16 #include "ui/display/display.h" | 14 #include "ui/display/display.h" |
| 17 #include "ui/views/background.h" | 15 #include "ui/views/background.h" |
| 18 #include "ui/views/widget/native_widget_private.h" | 16 #include "ui/views/widget/native_widget_private.h" |
| 19 #include "ui/views/widget/widget.h" | 17 #include "ui/views/widget/widget.h" |
| 20 | 18 |
| 21 namespace ash { | 19 namespace ash { |
| 22 namespace { | 20 namespace { |
| 23 | |
| 24 using namespace ui::devtools::protocol; | 21 using namespace ui::devtools::protocol; |
| 25 | |
| 26 const int kDefaultChildNodeCount = -1; | 22 const int kDefaultChildNodeCount = -1; |
| 27 const SkColor kBackgroundColor = SK_ColorRED; | 23 const SkColor kBackgroundColor = SK_ColorRED; |
| 28 const SkColor kBorderColor = SK_ColorBLUE; | 24 const SkColor kBorderColor = SK_ColorBLUE; |
| 29 | 25 |
| 30 class TestView : public views::View { | 26 class TestView : public views::View { |
| 31 public: | 27 public: |
| 32 TestView(const char* name) : views::View(), name_(name) {} | 28 TestView(const char* name) : views::View(), name_(name) {} |
| 33 | 29 |
| 34 const char* GetClassName() const override { return name_; } | 30 const char* GetClassName() const override { return name_; } |
| 35 | 31 |
| (...skipping 489 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 525 | 521 |
| 526 TEST_F(AshDevToolsTest, ViewRearranged) { | 522 TEST_F(AshDevToolsTest, ViewRearranged) { |
| 527 std::unique_ptr<views::Widget> widget( | 523 std::unique_ptr<views::Widget> widget( |
| 528 CreateTestWidget(gfx::Rect(1, 1, 1, 1))); | 524 CreateTestWidget(gfx::Rect(1, 1, 1, 1))); |
| 529 aura::Window* window = widget->GetNativeWindow(); | 525 aura::Window* window = widget->GetNativeWindow(); |
| 530 widget->Show(); | 526 widget->Show(); |
| 531 views::View* root_view = widget->GetRootView(); | 527 views::View* root_view = widget->GetRootView(); |
| 532 views::View* parent_view = new views::View; | 528 views::View* parent_view = new views::View; |
| 533 views::View* target_view = new views::View; | 529 views::View* target_view = new views::View; |
| 534 views::View* child_view = new views::View; | 530 views::View* child_view = new views::View; |
| 535 views::View* child_view_1 = new views::View; | |
| 536 | |
| 537 root_view->AddChildView(parent_view); | 531 root_view->AddChildView(parent_view); |
| 538 root_view->AddChildView(target_view); | 532 root_view->AddChildView(target_view); |
| 539 parent_view->AddChildView(child_view); | 533 parent_view->AddChildView(child_view); |
| 540 parent_view->AddChildView(child_view_1); | |
| 541 | 534 |
| 542 // Initialize DOMAgent | 535 // Initialize DOMAgent |
| 543 std::unique_ptr<ui::devtools::protocol::DOM::Node> root; | 536 std::unique_ptr<ui::devtools::protocol::DOM::Node> root; |
| 544 dom_agent()->getDocument(&root); | 537 dom_agent()->getDocument(&root); |
| 545 | 538 |
| 546 DOM::Node* parent_node = FindInRoot(window, root.get()); | 539 DOM::Node* parent_node = FindInRoot(window, root.get()); |
| 547 ASSERT_TRUE(parent_node); | 540 ASSERT_TRUE(parent_node); |
| 548 DOM::Node* widget_node = parent_node->getChildren(nullptr)->get(0); | 541 DOM::Node* widget_node = parent_node->getChildren(nullptr)->get(0); |
| 549 DOM::Node* root_view_node = widget_node->getChildren(nullptr)->get(0); | 542 DOM::Node* root_view_node = widget_node->getChildren(nullptr)->get(0); |
| 550 Array<DOM::Node>* root_view_children = root_view_node->getChildren(nullptr); | 543 Array<DOM::Node>* root_view_children = root_view_node->getChildren(nullptr); |
| 551 ASSERT_TRUE(root_view_children); | 544 ASSERT_TRUE(root_view_children); |
| 552 size_t root_children_size = root_view_children->length(); | 545 size_t root_children_size = root_view_children->length(); |
| 553 ASSERT_TRUE(root_children_size >= 2); | 546 ASSERT_TRUE(root_children_size >= 2); |
| 554 DOM::Node* parent_view_node = root_view_children->get(root_children_size - 2); | 547 DOM::Node* parent_view_node = root_view_children->get(root_children_size - 2); |
| 555 DOM::Node* target_view_node = root_view_children->get(root_children_size - 1); | 548 DOM::Node* target_view_node = root_view_children->get(root_children_size - 1); |
| 556 DOM::Node* child_view_node = parent_view_node->getChildren(nullptr)->get(0); | 549 DOM::Node* child_view_node = parent_view_node->getChildren(nullptr)->get(0); |
| 557 DOM::Node* child_view_node_1 = parent_view_node->getChildren(nullptr)->get(1); | |
| 558 | 550 |
| 559 Compare(parent_view, parent_view_node); | 551 Compare(parent_view, parent_view_node); |
| 560 Compare(target_view, target_view_node); | 552 Compare(target_view, target_view_node); |
| 561 Compare(child_view, child_view_node); | 553 Compare(child_view, child_view_node); |
| 562 Compare(child_view_1, child_view_node_1); | |
| 563 | |
| 564 ASSERT_NE(child_view_node->getNodeId(), child_view_node_1->getNodeId()); | |
| 565 | |
| 566 // Reorder child_view_1 from index 1 to 0 in view::Views tree. This makes DOM | |
| 567 // tree remove view node at position 1 and insert it at position 0. | |
| 568 parent_view->ReorderChildView(child_view_1, 0); | |
| 569 ExpectChildNodeRemoved(parent_view_node->getNodeId(), | |
| 570 child_view_node_1->getNodeId()); | |
| 571 ExpectChildNodeInserted(parent_view_node->getNodeId(), 0); | |
| 572 | |
| 573 target_view->AddChildView(child_view); | 554 target_view->AddChildView(child_view); |
| 574 ExpectChildNodeRemoved(parent_view_node->getNodeId(), | 555 ExpectChildNodeRemoved(parent_view_node->getNodeId(), |
| 575 child_view_node->getNodeId()); | 556 child_view_node->getNodeId()); |
| 576 ExpectChildNodeInserted(target_view_node->getNodeId(), 0); | 557 ExpectChildNodeInserted(target_view_node->getNodeId(), 0); |
| 577 } | 558 } |
| 578 | 559 |
| 579 TEST_F(AshDevToolsTest, ViewRearrangedRemovedAndInserted) { | 560 TEST_F(AshDevToolsTest, ViewRearrangedRemovedAndInserted) { |
| 580 std::unique_ptr<views::Widget> widget( | 561 std::unique_ptr<views::Widget> widget( |
| 581 CreateTestWidget(gfx::Rect(1, 1, 1, 1))); | 562 CreateTestWidget(gfx::Rect(1, 1, 1, 1))); |
| 582 aura::Window* window = widget->GetNativeWindow(); | 563 aura::Window* window = widget->GetNativeWindow(); |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 646 HighlightNode(root_view_node->getNodeId()); | 627 HighlightNode(root_view_node->getNodeId()); |
| 647 ExpectHighlighted(root_view->GetBoundsInScreen(), 0); | 628 ExpectHighlighted(root_view->GetBoundsInScreen(), 0); |
| 648 | 629 |
| 649 HideHighlight(0); | 630 HideHighlight(0); |
| 650 | 631 |
| 651 // Highlight non-existent node | 632 // Highlight non-existent node |
| 652 HighlightNode(10000); | 633 HighlightNode(10000); |
| 653 EXPECT_FALSE(GetHighlightingWindow(0)->IsVisible()); | 634 EXPECT_FALSE(GetHighlightingWindow(0)->IsVisible()); |
| 654 } | 635 } |
| 655 | 636 |
| 656 int GetNodeIdFromWindow(devtools::UIElement* ui_element, aura::Window* window) { | |
| 657 for (auto* child : ui_element->children()) { | |
| 658 if (child->type() == devtools::UIElementType::WINDOW && | |
| 659 static_cast<devtools::WindowElement*>(child)->window() == window) { | |
| 660 return child->node_id(); | |
| 661 } | |
| 662 } | |
| 663 for (auto* child : ui_element->children()) { | |
| 664 if (child->type() == devtools::UIElementType::WINDOW) { | |
| 665 int node_id = GetNodeIdFromWindow(child, window); | |
| 666 if (node_id > 0) | |
| 667 return node_id; | |
| 668 } | |
| 669 } | |
| 670 return 0; | |
| 671 } | |
| 672 | |
| 673 TEST_F(AshDevToolsTest, MultipleDisplayHighlight) { | 637 TEST_F(AshDevToolsTest, MultipleDisplayHighlight) { |
| 674 UpdateDisplay("300x400,500x500"); | 638 UpdateDisplay("300x400,500x500"); |
| 675 | 639 |
| 676 aura::Window::Windows root_windows = Shell::GetAllRootWindows(); | 640 aura::Window::Windows root_windows = Shell::GetAllRootWindows(); |
| 677 std::unique_ptr<aura::Window> window( | 641 std::unique_ptr<aura::Window> window( |
| 678 CreateTestWindowInShellWithBounds(gfx::Rect(1, 2, 30, 40))); | 642 CreateTestWindowInShellWithBounds(gfx::Rect(1, 2, 30, 40))); |
| 679 | 643 |
| 680 std::unique_ptr<ui::devtools::protocol::DOM::Node> root; | 644 std::unique_ptr<ui::devtools::protocol::DOM::Node> root; |
| 681 dom_agent()->getDocument(&root); | 645 dom_agent()->getDocument(&root); |
| 682 | 646 |
| 683 EXPECT_EQ(root_windows[0], window->GetRootWindow()); | 647 EXPECT_EQ(root_windows[0], window->GetRootWindow()); |
| 684 HighlightNode( | 648 HighlightNode(dom_agent()->GetNodeIdFromWindow(window.get())); |
| 685 GetNodeIdFromWindow(dom_agent()->window_element_root(), window.get())); | |
| 686 ExpectHighlighted(window->GetBoundsInScreen(), 0); | 649 ExpectHighlighted(window->GetBoundsInScreen(), 0); |
| 687 | 650 |
| 688 window->SetBoundsInScreen(gfx::Rect(500, 0, 50, 50), GetSecondaryDisplay()); | 651 window->SetBoundsInScreen(gfx::Rect(500, 0, 50, 50), GetSecondaryDisplay()); |
| 689 EXPECT_EQ(root_windows[1], window->GetRootWindow()); | 652 EXPECT_EQ(root_windows[1], window->GetRootWindow()); |
| 690 HighlightNode( | 653 HighlightNode(dom_agent()->GetNodeIdFromWindow(window.get())); |
| 691 GetNodeIdFromWindow(dom_agent()->window_element_root(), window.get())); | |
| 692 ExpectHighlighted(window->GetBoundsInScreen(), 1); | 654 ExpectHighlighted(window->GetBoundsInScreen(), 1); |
| 693 } | 655 } |
| 694 | 656 |
| 695 TEST_F(AshDevToolsTest, WindowWidgetViewGetMatchedStylesForNode) { | 657 TEST_F(AshDevToolsTest, WindowWidgetViewGetMatchedStylesForNode) { |
| 696 std::unique_ptr<views::Widget> widget( | 658 std::unique_ptr<views::Widget> widget( |
| 697 CreateTestWidget(gfx::Rect(1, 1, 1, 1))); | 659 CreateTestWidget(gfx::Rect(1, 1, 1, 1))); |
| 698 aura::Window* parent_window = widget->GetNativeWindow(); | 660 aura::Window* parent_window = widget->GetNativeWindow(); |
| 699 std::unique_ptr<aura::Window> window(CreateChildWindow(parent_window)); | 661 std::unique_ptr<aura::Window> window(CreateChildWindow(parent_window)); |
| 700 gfx::Rect window_bounds(2, 2, 3, 3); | 662 gfx::Rect window_bounds(2, 2, 3, 3); |
| 701 gfx::Rect widget_bounds(50, 50, 100, 75); | 663 gfx::Rect widget_bounds(50, 50, 100, 75); |
| (...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 815 SetStyleTexts(root_view_node, "\nheight: 73;\n ", true); | 777 SetStyleTexts(root_view_node, "\nheight: 73;\n ", true); |
| 816 EXPECT_EQ(gfx::Rect(25, 35, 45, 73), root_view->bounds()); | 778 EXPECT_EQ(gfx::Rect(25, 35, 45, 73), root_view->bounds()); |
| 817 | 779 |
| 818 SetStyleTexts(root_view_node, "\nx: 10; y: 23; width: 52;\nvisibility: 1;\n", | 780 SetStyleTexts(root_view_node, "\nx: 10; y: 23; width: 52;\nvisibility: 1;\n", |
| 819 true); | 781 true); |
| 820 EXPECT_EQ(gfx::Rect(10, 23, 52, 73), root_view->bounds()); | 782 EXPECT_EQ(gfx::Rect(10, 23, 52, 73), root_view->bounds()); |
| 821 EXPECT_TRUE(root_view->visible()); | 783 EXPECT_TRUE(root_view->visible()); |
| 822 } | 784 } |
| 823 | 785 |
| 824 } // namespace ash | 786 } // namespace ash |
| OLD | NEW |