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" | 7 #include "ash/devtools/ui_element.h" |
8 #include "ash/devtools/window_element.h" | 8 #include "ash/devtools/window_element.h" |
9 #include "ash/public/cpp/shell_window_ids.h" | 9 #include "ash/public/cpp/shell_window_ids.h" |
10 #include "ash/root_window_controller.h" | |
11 #include "ash/shell.h" | 10 #include "ash/shell.h" |
12 #include "ash/test/ash_test_base.h" | 11 #include "ash/test/ash_test_base.h" |
13 #include "ash/wm/widget_finder.h" | 12 #include "ash/wm/widget_finder.h" |
14 #include "base/memory/ptr_util.h" | 13 #include "base/memory/ptr_util.h" |
15 #include "base/strings/stringprintf.h" | 14 #include "base/strings/stringprintf.h" |
15 #include "ui/aura/window_tree_host.h" | |
16 #include "ui/display/display.h" | 16 #include "ui/display/display.h" |
17 #include "ui/views/background.h" | 17 #include "ui/views/background.h" |
18 #include "ui/views/widget/native_widget_private.h" | 18 #include "ui/views/widget/native_widget_private.h" |
19 #include "ui/views/widget/widget.h" | 19 #include "ui/views/widget/widget.h" |
20 | 20 |
21 namespace ash { | 21 namespace ash { |
22 namespace { | 22 namespace { |
23 | 23 |
24 using namespace ui::devtools::protocol; | 24 using namespace ui::devtools::protocol; |
25 | 25 |
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
131 if (property->getName() == name) { | 131 if (property->getName() == name) { |
132 int value; | 132 int value; |
133 EXPECT_TRUE(base::StringToInt(property->getValue(), &value)); | 133 EXPECT_TRUE(base::StringToInt(property->getValue(), &value)); |
134 return value; | 134 return value; |
135 } | 135 } |
136 } | 136 } |
137 NOTREACHED(); | 137 NOTREACHED(); |
138 return -1; | 138 return -1; |
139 } | 139 } |
140 | 140 |
141 aura::Window* GetHighlightingWindow(int root_window_index) { | 141 aura::Window* GetHighlightingWindow(aura::Window* root_window) { |
142 const aura::Window::Windows& overlay_windows = | 142 const aura::Window::Windows& overlay_windows = root_window->children(); |
143 Shell::GetAllRootWindows()[root_window_index] | |
144 ->GetChildById(kShellWindowId_OverlayContainer) | |
145 ->children(); | |
146 for (aura::Window* window : overlay_windows) { | 143 for (aura::Window* window : overlay_windows) { |
147 if (window->GetName() == "HighlightingWidget") | 144 if (window->GetName() == "HighlightingWidget") |
148 return window; | 145 return window; |
149 } | 146 } |
150 NOTREACHED(); | 147 NOTREACHED(); |
151 return nullptr; | 148 return nullptr; |
152 } | 149 } |
153 | 150 |
154 std::unique_ptr<DOM::RGBA> SkColorToRGBA(const SkColor& color) { | 151 std::unique_ptr<DOM::RGBA> SkColorToRGBA(const SkColor& color) { |
155 return DOM::RGBA::create() | 152 return DOM::RGBA::create() |
156 .setA(SkColorGetA(color) / 255) | 153 .setA(SkColorGetA(color) / 255) |
157 .setB(SkColorGetB(color)) | 154 .setB(SkColorGetB(color)) |
158 .setG(SkColorGetG(color)) | 155 .setG(SkColorGetG(color)) |
159 .setR(SkColorGetR(color)) | 156 .setR(SkColorGetR(color)) |
160 .build(); | 157 .build(); |
161 } | 158 } |
162 | 159 |
163 std::unique_ptr<DOM::HighlightConfig> CreateHighlightConfig( | 160 std::unique_ptr<DOM::HighlightConfig> CreateHighlightConfig( |
164 const SkColor& background_color, | 161 const SkColor& background_color, |
165 const SkColor& border_color) { | 162 const SkColor& border_color) { |
166 return DOM::HighlightConfig::create() | 163 return DOM::HighlightConfig::create() |
167 .setContentColor(SkColorToRGBA(background_color)) | 164 .setContentColor(SkColorToRGBA(background_color)) |
168 .setBorderColor(SkColorToRGBA(border_color)) | 165 .setBorderColor(SkColorToRGBA(border_color)) |
169 .build(); | 166 .build(); |
170 } | 167 } |
171 | 168 |
172 void ExpectHighlighted(const gfx::Rect& bounds, int root_window_index) { | 169 void ExpectHighlighted(const gfx::Rect& bounds, aura::Window* root_window) { |
173 aura::Window* highlighting_window = GetHighlightingWindow(root_window_index); | 170 aura::Window* highlighting_window = GetHighlightingWindow(root_window); |
174 EXPECT_TRUE(highlighting_window->IsVisible()); | 171 EXPECT_TRUE(highlighting_window->IsVisible()); |
175 EXPECT_EQ(bounds, highlighting_window->GetBoundsInScreen()); | 172 EXPECT_EQ(bounds, highlighting_window->GetBoundsInScreen()); |
176 EXPECT_EQ(kBackgroundColor, GetInternalWidgetForWindow(highlighting_window) | 173 EXPECT_EQ(kBackgroundColor, GetInternalWidgetForWindow(highlighting_window) |
177 ->GetRootView() | 174 ->GetRootView() |
178 ->background() | 175 ->background() |
179 ->get_color()); | 176 ->get_color()); |
180 } | 177 } |
181 | 178 |
182 aura::Window* GetPrimaryRootWindow() { | |
183 return Shell::Get()->GetPrimaryRootWindow(); | |
184 } | |
185 | |
186 } // namespace | 179 } // namespace |
187 | 180 |
188 class AshDevToolsTest : public test::AshTestBase { | 181 class AshDevToolsTest : public test::AshTestBase { |
189 public: | 182 public: |
190 AshDevToolsTest() {} | 183 AshDevToolsTest() {} |
191 ~AshDevToolsTest() override {} | 184 ~AshDevToolsTest() override {} |
192 | 185 |
193 views::internal::NativeWidgetPrivate* CreateTestNativeWidget() { | 186 views::internal::NativeWidgetPrivate* CreateTestNativeWidget() { |
194 views::Widget* widget = new views::Widget; | 187 views::Widget* widget = new views::Widget; |
195 views::Widget::InitParams params; | 188 views::Widget::InitParams params; |
196 params.ownership = views::Widget::InitParams::NATIVE_WIDGET_OWNS_WIDGET; | 189 params.ownership = views::Widget::InitParams::NATIVE_WIDGET_OWNS_WIDGET; |
197 Shell::GetPrimaryRootWindowController() | 190 DCHECK(dom_agent()->root_windows().size()); |
sadrul
2017/05/25 04:21:03
This DCHECK is not needed.
thanhph
2017/05/28 00:04:25
Done.
| |
198 ->ConfigureWidgetInitParamsForContainer( | 191 params.parent = |
199 widget, kShellWindowId_DefaultContainer, ¶ms); | 192 GetPrimaryRootWindow()->GetChildById(kShellWindowId_DefaultContainer); |
sadrul
2017/05/25 04:21:03
Remove this.
thanhph
2017/05/28 00:04:25
Done.
| |
200 widget->Init(params); | 193 widget->Init(params); |
201 return widget->native_widget_private(); | 194 return widget->native_widget_private(); |
202 } | 195 } |
203 | 196 |
204 std::unique_ptr<views::Widget> CreateTestWidget(const gfx::Rect& bounds) { | 197 std::unique_ptr<views::Widget> CreateTestWidget(const gfx::Rect& bounds) { |
205 return AshTestBase::CreateTestWidget(nullptr, kShellWindowId_Invalid, | 198 return AshTestBase::CreateTestWidget(nullptr, kShellWindowId_Invalid, |
206 bounds); | 199 bounds); |
207 } | 200 } |
208 | 201 |
209 void SetUp() override { | 202 void SetUp() override { |
210 AshTestBase::SetUp(); | |
211 fake_frontend_channel_ = base::MakeUnique<FakeFrontendChannel>(); | 203 fake_frontend_channel_ = base::MakeUnique<FakeFrontendChannel>(); |
212 uber_dispatcher_ = | 204 uber_dispatcher_ = |
213 base::MakeUnique<UberDispatcher>(fake_frontend_channel_.get()); | 205 base::MakeUnique<UberDispatcher>(fake_frontend_channel_.get()); |
214 dom_agent_ = base::MakeUnique<devtools::AshDevToolsDOMAgent>(); | 206 dom_agent_ = base::MakeUnique<devtools::AshDevToolsDOMAgent>(); |
215 dom_agent_->Init(uber_dispatcher_.get()); | 207 dom_agent_->Init(uber_dispatcher_.get()); |
216 css_agent_ = | 208 css_agent_ = |
217 base::MakeUnique<devtools::AshDevToolsCSSAgent>(dom_agent_.get()); | 209 base::MakeUnique<devtools::AshDevToolsCSSAgent>(dom_agent_.get()); |
218 css_agent_->Init(uber_dispatcher_.get()); | 210 css_agent_->Init(uber_dispatcher_.get()); |
219 css_agent_->enable(); | 211 css_agent_->enable(); |
212 AshTestBase::SetUp(); | |
sadrul
2017/05/25 04:21:03
Add a comment explaining why this needs to happen
thanhph
2017/05/28 00:04:25
Done.
| |
220 } | 213 } |
221 | 214 |
222 void TearDown() override { | 215 void TearDown() override { |
223 css_agent_.reset(); | 216 css_agent_.reset(); |
224 dom_agent_.reset(); | 217 dom_agent_.reset(); |
225 uber_dispatcher_.reset(); | 218 uber_dispatcher_.reset(); |
226 fake_frontend_channel_.reset(); | 219 fake_frontend_channel_.reset(); |
227 AshTestBase::TearDown(); | 220 AshTestBase::TearDown(); |
228 } | 221 } |
229 | 222 |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
280 ASSERT_FALSE(output); | 273 ASSERT_FALSE(output); |
281 } | 274 } |
282 | 275 |
283 void HighlightNode(int node_id) { | 276 void HighlightNode(int node_id) { |
284 dom_agent_->highlightNode( | 277 dom_agent_->highlightNode( |
285 CreateHighlightConfig(kBackgroundColor, kBorderColor), node_id); | 278 CreateHighlightConfig(kBackgroundColor, kBorderColor), node_id); |
286 } | 279 } |
287 | 280 |
288 void HideHighlight(int root_window_index) { | 281 void HideHighlight(int root_window_index) { |
289 dom_agent_->hideHighlight(); | 282 dom_agent_->hideHighlight(); |
290 ASSERT_FALSE(GetHighlightingWindow(root_window_index)->IsVisible()); | 283 DCHECK_GE(root_window_index, 0); |
284 DCHECK_LE(root_window_index, | |
285 static_cast<int>(dom_agent()->root_windows().size())); | |
286 ASSERT_FALSE( | |
287 GetHighlightingWindow(dom_agent()->root_windows()[root_window_index]) | |
288 ->IsVisible()); | |
291 } | 289 } |
292 | 290 |
293 FakeFrontendChannel* frontend_channel() { | 291 FakeFrontendChannel* frontend_channel() { |
294 return fake_frontend_channel_.get(); | 292 return fake_frontend_channel_.get(); |
295 } | 293 } |
296 | 294 |
295 aura::Window* GetPrimaryRootWindow() { | |
296 DCHECK(dom_agent()->root_windows().size()); | |
297 return dom_agent()->root_windows()[0]; | |
298 } | |
299 | |
297 devtools::AshDevToolsCSSAgent* css_agent() { return css_agent_.get(); } | 300 devtools::AshDevToolsCSSAgent* css_agent() { return css_agent_.get(); } |
298 devtools::AshDevToolsDOMAgent* dom_agent() { return dom_agent_.get(); } | 301 devtools::AshDevToolsDOMAgent* dom_agent() { return dom_agent_.get(); } |
299 | 302 |
300 private: | 303 private: |
301 std::unique_ptr<UberDispatcher> uber_dispatcher_; | 304 std::unique_ptr<UberDispatcher> uber_dispatcher_; |
302 std::unique_ptr<FakeFrontendChannel> fake_frontend_channel_; | 305 std::unique_ptr<FakeFrontendChannel> fake_frontend_channel_; |
303 std::unique_ptr<devtools::AshDevToolsDOMAgent> dom_agent_; | 306 std::unique_ptr<devtools::AshDevToolsDOMAgent> dom_agent_; |
304 std::unique_ptr<devtools::AshDevToolsCSSAgent> css_agent_; | 307 std::unique_ptr<devtools::AshDevToolsCSSAgent> css_agent_; |
305 | 308 |
306 DISALLOW_COPY_AND_ASSIGN(AshDevToolsTest); | 309 DISALLOW_COPY_AND_ASSIGN(AshDevToolsTest); |
(...skipping 320 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
627 | 630 |
628 DOM::Node* parent_node = FindInRoot(parent_window, root.get()); | 631 DOM::Node* parent_node = FindInRoot(parent_window, root.get()); |
629 ASSERT_TRUE(parent_node); | 632 ASSERT_TRUE(parent_node); |
630 Array<DOM::Node>* parent_children = parent_node->getChildren(nullptr); | 633 Array<DOM::Node>* parent_children = parent_node->getChildren(nullptr); |
631 ASSERT_TRUE(parent_children); | 634 ASSERT_TRUE(parent_children); |
632 DOM::Node* window_node = parent_children->get(1); | 635 DOM::Node* window_node = parent_children->get(1); |
633 DOM::Node* widget_node = parent_children->get(0); | 636 DOM::Node* widget_node = parent_children->get(0); |
634 DOM::Node* root_view_node = widget_node->getChildren(nullptr)->get(0); | 637 DOM::Node* root_view_node = widget_node->getChildren(nullptr)->get(0); |
635 | 638 |
636 HighlightNode(window_node->getNodeId()); | 639 HighlightNode(window_node->getNodeId()); |
637 ExpectHighlighted(window->GetBoundsInScreen(), 0); | 640 ExpectHighlighted(window->GetBoundsInScreen(), GetPrimaryRootWindow()); |
638 | 641 |
639 HideHighlight(0); | 642 HideHighlight(0); |
640 | 643 |
641 HighlightNode(widget_node->getNodeId()); | 644 HighlightNode(widget_node->getNodeId()); |
642 ExpectHighlighted(widget->GetWindowBoundsInScreen(), 0); | 645 ExpectHighlighted(widget->GetWindowBoundsInScreen(), GetPrimaryRootWindow()); |
643 | 646 |
644 HideHighlight(0); | 647 HideHighlight(0); |
645 | 648 |
646 HighlightNode(root_view_node->getNodeId()); | 649 HighlightNode(root_view_node->getNodeId()); |
647 ExpectHighlighted(root_view->GetBoundsInScreen(), 0); | 650 ExpectHighlighted(root_view->GetBoundsInScreen(), GetPrimaryRootWindow()); |
648 | 651 |
649 HideHighlight(0); | 652 HideHighlight(0); |
650 | 653 |
651 // Highlight non-existent node | 654 // Highlight non-existent node |
652 HighlightNode(10000); | 655 HighlightNode(10000); |
653 EXPECT_FALSE(GetHighlightingWindow(0)->IsVisible()); | 656 EXPECT_FALSE(GetHighlightingWindow(GetPrimaryRootWindow())->IsVisible()); |
654 } | 657 } |
655 | 658 |
656 int GetNodeIdFromWindow(devtools::UIElement* ui_element, aura::Window* window) { | 659 int GetNodeIdFromWindow(devtools::UIElement* ui_element, aura::Window* window) { |
657 for (auto* child : ui_element->children()) { | 660 for (auto* child : ui_element->children()) { |
658 if (child->type() == devtools::UIElementType::WINDOW && | 661 if (child->type() == devtools::UIElementType::WINDOW && |
659 static_cast<devtools::WindowElement*>(child)->window() == window) { | 662 static_cast<devtools::WindowElement*>(child)->window() == window) { |
660 return child->node_id(); | 663 return child->node_id(); |
661 } | 664 } |
662 } | 665 } |
663 for (auto* child : ui_element->children()) { | 666 for (auto* child : ui_element->children()) { |
664 if (child->type() == devtools::UIElementType::WINDOW) { | 667 if (child->type() == devtools::UIElementType::WINDOW) { |
665 int node_id = GetNodeIdFromWindow(child, window); | 668 int node_id = GetNodeIdFromWindow(child, window); |
666 if (node_id > 0) | 669 if (node_id > 0) |
667 return node_id; | 670 return node_id; |
668 } | 671 } |
669 } | 672 } |
670 return 0; | 673 return 0; |
671 } | 674 } |
672 | 675 |
673 TEST_F(AshDevToolsTest, MultipleDisplayHighlight) { | 676 // TODO(thanhph): Make test AshDevToolsTest.MultipleDisplayHighlight work with |
674 UpdateDisplay("300x400,500x500"); | 677 // multiple displays by updating params.parent in |
675 | 678 // InitializeHighlightingWidget(). |
sadrul
2017/05/25 04:21:03
Can you file a bug to fix highlighting widget for
thanhph
2017/05/28 00:04:25
Done.
| |
676 aura::Window::Windows root_windows = Shell::GetAllRootWindows(); | |
677 std::unique_ptr<aura::Window> window( | |
678 CreateTestWindowInShellWithBounds(gfx::Rect(1, 2, 30, 40))); | |
679 | |
680 std::unique_ptr<ui::devtools::protocol::DOM::Node> root; | |
681 dom_agent()->getDocument(&root); | |
682 | |
683 EXPECT_EQ(root_windows[0], window->GetRootWindow()); | |
684 HighlightNode( | |
685 GetNodeIdFromWindow(dom_agent()->window_element_root(), window.get())); | |
686 ExpectHighlighted(window->GetBoundsInScreen(), 0); | |
687 | |
688 window->SetBoundsInScreen(gfx::Rect(500, 0, 50, 50), GetSecondaryDisplay()); | |
689 EXPECT_EQ(root_windows[1], window->GetRootWindow()); | |
690 HighlightNode( | |
691 GetNodeIdFromWindow(dom_agent()->window_element_root(), window.get())); | |
692 ExpectHighlighted(window->GetBoundsInScreen(), 1); | |
693 } | |
694 | 679 |
695 TEST_F(AshDevToolsTest, WindowWidgetViewGetMatchedStylesForNode) { | 680 TEST_F(AshDevToolsTest, WindowWidgetViewGetMatchedStylesForNode) { |
696 std::unique_ptr<views::Widget> widget( | 681 std::unique_ptr<views::Widget> widget( |
697 CreateTestWidget(gfx::Rect(1, 1, 1, 1))); | 682 CreateTestWidget(gfx::Rect(1, 1, 1, 1))); |
698 aura::Window* parent_window = widget->GetNativeWindow(); | 683 aura::Window* parent_window = widget->GetNativeWindow(); |
699 std::unique_ptr<aura::Window> window(CreateChildWindow(parent_window)); | 684 std::unique_ptr<aura::Window> window(CreateChildWindow(parent_window)); |
700 gfx::Rect window_bounds(2, 2, 3, 3); | 685 gfx::Rect window_bounds(2, 2, 3, 3); |
701 gfx::Rect widget_bounds(50, 50, 100, 75); | 686 gfx::Rect widget_bounds(50, 50, 100, 75); |
702 gfx::Rect view_bounds(4, 4, 3, 3); | 687 gfx::Rect view_bounds(4, 4, 3, 3); |
703 window->SetBounds(window_bounds); | 688 window->SetBounds(window_bounds); |
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
815 SetStyleTexts(root_view_node, "\nheight: 73;\n ", true); | 800 SetStyleTexts(root_view_node, "\nheight: 73;\n ", true); |
816 EXPECT_EQ(gfx::Rect(25, 35, 45, 73), root_view->bounds()); | 801 EXPECT_EQ(gfx::Rect(25, 35, 45, 73), root_view->bounds()); |
817 | 802 |
818 SetStyleTexts(root_view_node, "\nx: 10; y: 23; width: 52;\nvisibility: 1;\n", | 803 SetStyleTexts(root_view_node, "\nx: 10; y: 23; width: 52;\nvisibility: 1;\n", |
819 true); | 804 true); |
820 EXPECT_EQ(gfx::Rect(10, 23, 52, 73), root_view->bounds()); | 805 EXPECT_EQ(gfx::Rect(10, 23, 52, 73), root_view->bounds()); |
821 EXPECT_TRUE(root_view->visible()); | 806 EXPECT_TRUE(root_view->visible()); |
822 } | 807 } |
823 | 808 |
824 } // namespace ash | 809 } // namespace ash |
OLD | NEW |