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