| 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 "base/memory/ptr_util.h" | 5 #include "base/memory/ptr_util.h" |
| 6 #include "base/strings/stringprintf.h" | 6 #include "base/strings/stringprintf.h" |
| 7 #include "components/ui_devtools/views/ui_devtools_css_agent.h" | 7 #include "components/ui_devtools/views/ui_devtools_css_agent.h" |
| 8 #include "components/ui_devtools/views/ui_devtools_dom_agent.h" | 8 #include "components/ui_devtools/views/ui_devtools_dom_agent.h" |
| 9 #include "components/ui_devtools/views/ui_devtools_overlay_agent.h" |
| 9 #include "components/ui_devtools/views/ui_element.h" | 10 #include "components/ui_devtools/views/ui_element.h" |
| 10 #include "components/ui_devtools/views/view_element.h" | 11 #include "components/ui_devtools/views/view_element.h" |
| 11 #include "components/ui_devtools/views/widget_element.h" | 12 #include "components/ui_devtools/views/widget_element.h" |
| 12 #include "components/ui_devtools/views/window_element.h" | 13 #include "components/ui_devtools/views/window_element.h" |
| 13 #include "ui/aura/client/window_parenting_client.h" | 14 #include "ui/aura/client/window_parenting_client.h" |
| 14 #include "ui/aura/window_tree_host.h" | 15 #include "ui/aura/window_tree_host.h" |
| 15 #include "ui/display/display.h" | 16 #include "ui/display/display.h" |
| 16 #include "ui/views/background.h" | 17 #include "ui/views/background.h" |
| 17 #include "ui/views/test/views_test_base.h" | 18 #include "ui/views/test/views_test_base.h" |
| 18 #include "ui/views/widget/native_widget_private.h" | 19 #include "ui/views/widget/native_widget_private.h" |
| (...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 150 | 151 |
| 151 std::unique_ptr<DOM::RGBA> SkColorToRGBA(const SkColor& color) { | 152 std::unique_ptr<DOM::RGBA> SkColorToRGBA(const SkColor& color) { |
| 152 return DOM::RGBA::create() | 153 return DOM::RGBA::create() |
| 153 .setA(SkColorGetA(color) / 255) | 154 .setA(SkColorGetA(color) / 255) |
| 154 .setB(SkColorGetB(color)) | 155 .setB(SkColorGetB(color)) |
| 155 .setG(SkColorGetG(color)) | 156 .setG(SkColorGetG(color)) |
| 156 .setR(SkColorGetR(color)) | 157 .setR(SkColorGetR(color)) |
| 157 .build(); | 158 .build(); |
| 158 } | 159 } |
| 159 | 160 |
| 160 std::unique_ptr<DOM::HighlightConfig> CreateHighlightConfig( | 161 std::unique_ptr<Overlay::HighlightConfig> CreateHighlightConfig( |
| 161 const SkColor& background_color, | 162 const SkColor& background_color, |
| 162 const SkColor& border_color) { | 163 const SkColor& border_color) { |
| 163 return DOM::HighlightConfig::create() | 164 return Overlay::HighlightConfig::create() |
| 164 .setContentColor(SkColorToRGBA(background_color)) | 165 .setContentColor(SkColorToRGBA(background_color)) |
| 165 .setBorderColor(SkColorToRGBA(border_color)) | 166 .setBorderColor(SkColorToRGBA(border_color)) |
| 166 .build(); | 167 .build(); |
| 167 } | 168 } |
| 168 | 169 |
| 169 void ExpectHighlighted(const gfx::Rect& bounds, | 170 void ExpectHighlighted(const gfx::Rect& bounds, |
| 170 aura::Window* highlight_window) { | 171 aura::Window* highlight_window) { |
| 171 ui::Layer* highlighting_layer = GetHighlightingLayer(highlight_window); | 172 ui::Layer* highlighting_layer = GetHighlightingLayer(highlight_window); |
| 172 EXPECT_TRUE(highlighting_layer->visible()); | 173 EXPECT_TRUE(highlighting_layer->visible()); |
| 173 EXPECT_EQ(bounds, highlighting_layer->bounds()); | 174 EXPECT_EQ(bounds, highlighting_layer->bounds()); |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 217 void SetUp() override { | 218 void SetUp() override { |
| 218 fake_frontend_channel_ = base::MakeUnique<FakeFrontendChannel>(); | 219 fake_frontend_channel_ = base::MakeUnique<FakeFrontendChannel>(); |
| 219 uber_dispatcher_ = | 220 uber_dispatcher_ = |
| 220 base::MakeUnique<UberDispatcher>(fake_frontend_channel_.get()); | 221 base::MakeUnique<UberDispatcher>(fake_frontend_channel_.get()); |
| 221 dom_agent_ = base::MakeUnique<ui_devtools::UIDevToolsDOMAgent>(); | 222 dom_agent_ = base::MakeUnique<ui_devtools::UIDevToolsDOMAgent>(); |
| 222 dom_agent_->Init(uber_dispatcher_.get()); | 223 dom_agent_->Init(uber_dispatcher_.get()); |
| 223 css_agent_ = | 224 css_agent_ = |
| 224 base::MakeUnique<ui_devtools::UIDevToolsCSSAgent>(dom_agent_.get()); | 225 base::MakeUnique<ui_devtools::UIDevToolsCSSAgent>(dom_agent_.get()); |
| 225 css_agent_->Init(uber_dispatcher_.get()); | 226 css_agent_->Init(uber_dispatcher_.get()); |
| 226 css_agent_->enable(); | 227 css_agent_->enable(); |
| 228 overlay_agent_ = |
| 229 base::MakeUnique<ui_devtools::UIDevToolsOverlayAgent>(dom_agent_.get()); |
| 230 overlay_agent_->Init(uber_dispatcher_.get()); |
| 231 overlay_agent_->enable(); |
| 227 | 232 |
| 228 // We need to create |dom_agent| first to observe creation of | 233 // We need to create |dom_agent| first to observe creation of |
| 229 // WindowTreeHosts in ViewTestBase::SetUp(). | 234 // WindowTreeHosts in ViewTestBase::SetUp(). |
| 230 views::ViewsTestBase::SetUp(); | 235 views::ViewsTestBase::SetUp(); |
| 231 | 236 |
| 232 top_window = CreateChildWindow(GetPrimaryRootWindow()); | 237 top_window = CreateChildWindow(GetPrimaryRootWindow()); |
| 233 top_default_container_window = CreateChildWindow(GetPrimaryRootWindow()); | 238 top_default_container_window = CreateChildWindow(GetPrimaryRootWindow()); |
| 234 top_overlay_window = CreateChildWindow(GetPrimaryRootWindow(), | 239 top_overlay_window = CreateChildWindow(GetPrimaryRootWindow(), |
| 235 aura::client::WINDOW_TYPE_UNKNOWN); | 240 aura::client::WINDOW_TYPE_UNKNOWN); |
| 236 } | 241 } |
| 237 | 242 |
| 238 void TearDown() override { | 243 void TearDown() override { |
| 239 top_overlay_window.reset(); | 244 top_overlay_window.reset(); |
| 240 top_default_container_window.reset(); | 245 top_default_container_window.reset(); |
| 241 top_window.reset(); | 246 top_window.reset(); |
| 242 css_agent_.reset(); | 247 css_agent_.reset(); |
| 248 overlay_agent_.reset(); |
| 243 dom_agent_.reset(); | 249 dom_agent_.reset(); |
| 244 uber_dispatcher_.reset(); | 250 uber_dispatcher_.reset(); |
| 245 fake_frontend_channel_.reset(); | 251 fake_frontend_channel_.reset(); |
| 246 views::ViewsTestBase::TearDown(); | 252 views::ViewsTestBase::TearDown(); |
| 247 } | 253 } |
| 248 | 254 |
| 249 void ExpectChildNodeInserted(int parent_id, int prev_sibling_id) { | 255 void ExpectChildNodeInserted(int parent_id, int prev_sibling_id) { |
| 250 EXPECT_EQ(1, frontend_channel()->CountProtocolNotificationMessageStartsWith( | 256 EXPECT_EQ(1, frontend_channel()->CountProtocolNotificationMessageStartsWith( |
| 251 base::StringPrintf("{\"method\":\"DOM.childNodeInserted\"," | 257 base::StringPrintf("{\"method\":\"DOM.childNodeInserted\"," |
| 252 "\"params\":{\"parentNodeId\":%d," | 258 "\"params\":{\"parentNodeId\":%d," |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 293 EXPECT_EQ(success, | 299 EXPECT_EQ(success, |
| 294 css_agent_->setStyleTexts(std::move(edits), &output).isSuccess()); | 300 css_agent_->setStyleTexts(std::move(edits), &output).isSuccess()); |
| 295 | 301 |
| 296 if (success) | 302 if (success) |
| 297 ASSERT_TRUE(output); | 303 ASSERT_TRUE(output); |
| 298 else | 304 else |
| 299 ASSERT_FALSE(output); | 305 ASSERT_FALSE(output); |
| 300 } | 306 } |
| 301 | 307 |
| 302 void HighlightNode(int node_id) { | 308 void HighlightNode(int node_id) { |
| 303 dom_agent_->highlightNode( | 309 overlay_agent_->highlightNode( |
| 304 CreateHighlightConfig(kBackgroundColor, kBorderColor), node_id); | 310 CreateHighlightConfig(kBackgroundColor, kBorderColor), node_id); |
| 305 } | 311 } |
| 306 | 312 |
| 307 void HideHighlight(int root_window_index) { | 313 void HideHighlight(int root_window_index) { |
| 308 dom_agent_->hideHighlight(); | 314 dom_agent_->hideHighlight(); |
| 309 DCHECK_GE(root_window_index, 0); | 315 DCHECK_GE(root_window_index, 0); |
| 310 DCHECK_LE(root_window_index, | 316 DCHECK_LE(root_window_index, |
| 311 static_cast<int>(dom_agent()->root_windows().size())); | 317 static_cast<int>(dom_agent()->root_windows().size())); |
| 312 ASSERT_FALSE( | 318 ASSERT_FALSE( |
| 313 GetHighlightingLayer(dom_agent()->root_windows()[root_window_index]) | 319 GetHighlightingLayer(dom_agent()->root_windows()[root_window_index]) |
| 314 ->visible()); | 320 ->visible()); |
| 315 } | 321 } |
| 316 | 322 |
| 317 FakeFrontendChannel* frontend_channel() { | 323 FakeFrontendChannel* frontend_channel() { |
| 318 return fake_frontend_channel_.get(); | 324 return fake_frontend_channel_.get(); |
| 319 } | 325 } |
| 320 | 326 |
| 321 aura::Window* GetPrimaryRootWindow() { | 327 aura::Window* GetPrimaryRootWindow() { |
| 322 DCHECK(dom_agent()->root_windows().size()); | 328 DCHECK(dom_agent()->root_windows().size()); |
| 323 return dom_agent()->root_windows()[0]; | 329 return dom_agent()->root_windows()[0]; |
| 324 } | 330 } |
| 325 | 331 |
| 326 ui_devtools::UIDevToolsCSSAgent* css_agent() { return css_agent_.get(); } | 332 ui_devtools::UIDevToolsCSSAgent* css_agent() { return css_agent_.get(); } |
| 327 ui_devtools::UIDevToolsDOMAgent* dom_agent() { return dom_agent_.get(); } | 333 ui_devtools::UIDevToolsDOMAgent* dom_agent() { return dom_agent_.get(); } |
| 334 ui_devtools::UIDevToolsOverlayAgent* overlay_agent() { |
| 335 return overlay_agent_.get(); |
| 336 } |
| 328 | 337 |
| 329 std::unique_ptr<aura::Window> top_overlay_window; | 338 std::unique_ptr<aura::Window> top_overlay_window; |
| 330 std::unique_ptr<aura::Window> top_window; | 339 std::unique_ptr<aura::Window> top_window; |
| 331 std::unique_ptr<aura::Window> top_default_container_window; | 340 std::unique_ptr<aura::Window> top_default_container_window; |
| 332 | 341 |
| 333 private: | 342 private: |
| 334 std::unique_ptr<UberDispatcher> uber_dispatcher_; | 343 std::unique_ptr<UberDispatcher> uber_dispatcher_; |
| 335 std::unique_ptr<FakeFrontendChannel> fake_frontend_channel_; | 344 std::unique_ptr<FakeFrontendChannel> fake_frontend_channel_; |
| 336 std::unique_ptr<ui_devtools::UIDevToolsDOMAgent> dom_agent_; | 345 std::unique_ptr<ui_devtools::UIDevToolsDOMAgent> dom_agent_; |
| 337 std::unique_ptr<ui_devtools::UIDevToolsCSSAgent> css_agent_; | 346 std::unique_ptr<ui_devtools::UIDevToolsCSSAgent> css_agent_; |
| 347 std::unique_ptr<ui_devtools::UIDevToolsOverlayAgent> overlay_agent_; |
| 338 | 348 |
| 339 DISALLOW_COPY_AND_ASSIGN(UIDevToolsTest); | 349 DISALLOW_COPY_AND_ASSIGN(UIDevToolsTest); |
| 340 }; | 350 }; |
| 341 | 351 |
| 342 TEST_F(UIDevToolsTest, GetDocumentWithWindowWidgetView) { | 352 TEST_F(UIDevToolsTest, GetDocumentWithWindowWidgetView) { |
| 343 std::unique_ptr<views::Widget> widget( | 353 std::unique_ptr<views::Widget> widget( |
| 344 CreateTestWidget(gfx::Rect(1, 1, 1, 1))); | 354 CreateTestWidget(gfx::Rect(1, 1, 1, 1))); |
| 345 aura::Window* parent_window = widget->GetNativeWindow(); | 355 aura::Window* parent_window = widget->GetNativeWindow(); |
| 346 parent_window->SetName("parent_window"); | 356 parent_window->SetName("parent_window"); |
| 347 std::unique_ptr<aura::Window> child_window = CreateChildWindow(parent_window); | 357 std::unique_ptr<aura::Window> child_window = CreateChildWindow(parent_window); |
| (...skipping 520 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 868 SetStyleTexts(root_view_node, "\nheight: 73;\n ", true); | 878 SetStyleTexts(root_view_node, "\nheight: 73;\n ", true); |
| 869 EXPECT_EQ(gfx::Rect(25, 35, 45, 73), root_view->bounds()); | 879 EXPECT_EQ(gfx::Rect(25, 35, 45, 73), root_view->bounds()); |
| 870 | 880 |
| 871 SetStyleTexts(root_view_node, "\nx: 10; y: 23; width: 52;\nvisibility: 1;\n", | 881 SetStyleTexts(root_view_node, "\nx: 10; y: 23; width: 52;\nvisibility: 1;\n", |
| 872 true); | 882 true); |
| 873 EXPECT_EQ(gfx::Rect(10, 23, 52, 73), root_view->bounds()); | 883 EXPECT_EQ(gfx::Rect(10, 23, 52, 73), root_view->bounds()); |
| 874 EXPECT_TRUE(root_view->visible()); | 884 EXPECT_TRUE(root_view->visible()); |
| 875 } | 885 } |
| 876 | 886 |
| 877 } // namespace ui_devtools | 887 } // namespace ui_devtools |
| OLD | NEW |