| 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/common/devtools/ash_devtools_css_agent.h" |
| 5 #include "ash/common/devtools/ash_devtools_dom_agent.h" | 6 #include "ash/common/devtools/ash_devtools_dom_agent.h" |
| 6 | |
| 7 #include "ash/common/test/ash_test.h" | 7 #include "ash/common/test/ash_test.h" |
| 8 #include "ash/common/wm_lookup.h" | 8 #include "ash/common/wm_lookup.h" |
| 9 #include "ash/common/wm_root_window_controller.h" | 9 #include "ash/common/wm_root_window_controller.h" |
| 10 #include "ash/common/wm_shell.h" | 10 #include "ash/common/wm_shell.h" |
| 11 #include "ash/common/wm_window.h" | 11 #include "ash/common/wm_window.h" |
| 12 #include "base/strings/stringprintf.h" | 12 #include "base/strings/stringprintf.h" |
| 13 #include "ui/display/display.h" |
| 14 #include "ui/views/background.h" |
| 13 #include "ui/views/widget/native_widget_private.h" | 15 #include "ui/views/widget/native_widget_private.h" |
| 14 #include "ui/views/widget/widget.h" | 16 #include "ui/views/widget/widget.h" |
| 15 | 17 |
| 16 namespace ash { | 18 namespace ash { |
| 17 namespace { | 19 namespace { |
| 18 using namespace ui::devtools::protocol; | 20 using namespace ui::devtools::protocol; |
| 19 const int kDefaultChildNodeCount = -1; | 21 const int kDefaultChildNodeCount = -1; |
| 22 const SkColor kBackgroundColor = SK_ColorRED; |
| 23 const SkColor kBorderColor = SK_ColorBLUE; |
| 20 | 24 |
| 21 class TestView : public views::View { | 25 class TestView : public views::View { |
| 22 public: | 26 public: |
| 23 TestView(const char* name) : views::View(), name_(name) {} | 27 TestView(const char* name) : views::View(), name_(name) {} |
| 24 | 28 |
| 25 const char* GetClassName() const override { return name_; } | 29 const char* GetClassName() const override { return name_; } |
| 26 | 30 |
| 27 private: | 31 private: |
| 28 const char* name_; | 32 const char* name_; |
| 29 | 33 |
| (...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 108 Array<DOM::Node>* children = root->getChildren(nullptr); | 112 Array<DOM::Node>* children = root->getChildren(nullptr); |
| 109 DOM::Node* window_node = nullptr; | 113 DOM::Node* window_node = nullptr; |
| 110 for (size_t i = 0; i < children->length(); i++) { | 114 for (size_t i = 0; i < children->length(); i++) { |
| 111 window_node = FindInRoot(window, children->get(i)); | 115 window_node = FindInRoot(window, children->get(i)); |
| 112 if (window_node) | 116 if (window_node) |
| 113 return window_node; | 117 return window_node; |
| 114 } | 118 } |
| 115 return window_node; | 119 return window_node; |
| 116 } | 120 } |
| 117 | 121 |
| 122 int GetPropertyByName(const std::string& name, |
| 123 Array<CSS::CSSProperty>* properties) { |
| 124 for (size_t i = 0; i < properties->length(); i++) { |
| 125 CSS::CSSProperty* property = properties->get(i); |
| 126 if (property->getName() == name) { |
| 127 int value; |
| 128 EXPECT_TRUE(base::StringToInt(property->getValue(), &value)); |
| 129 return value; |
| 130 } |
| 131 } |
| 132 NOTREACHED(); |
| 133 return -1; |
| 134 } |
| 135 |
| 136 WmWindow* GetHighlightingWindow(int root_window_index) { |
| 137 WmWindow::Windows overlay_windows = |
| 138 WmShell::Get() |
| 139 ->GetAllRootWindows()[root_window_index] |
| 140 ->GetChildByShellWindowId(kShellWindowId_OverlayContainer) |
| 141 ->GetChildren(); |
| 142 for (WmWindow* window : overlay_windows) { |
| 143 if (window->GetName() == "HighlightingWidget") |
| 144 return window; |
| 145 } |
| 146 NOTREACHED(); |
| 147 return nullptr; |
| 148 } |
| 149 |
| 150 std::unique_ptr<DOM::RGBA> SkColorToRGBA(const SkColor& color) { |
| 151 return DOM::RGBA::create() |
| 152 .setA(SkColorGetA(color) / 255) |
| 153 .setB(SkColorGetB(color)) |
| 154 .setG(SkColorGetG(color)) |
| 155 .setR(SkColorGetR(color)) |
| 156 .build(); |
| 157 } |
| 158 |
| 159 std::unique_ptr<DOM::HighlightConfig> CreateHighlightConfig( |
| 160 const SkColor& background_color, |
| 161 const SkColor& border_color) { |
| 162 return DOM::HighlightConfig::create() |
| 163 .setContentColor(SkColorToRGBA(background_color)) |
| 164 .setBorderColor(SkColorToRGBA(border_color)) |
| 165 .build(); |
| 166 } |
| 167 |
| 168 void ExpectHighlighted(const gfx::Rect& bounds, int root_window_index) { |
| 169 WmWindow* highlighting_window = GetHighlightingWindow(root_window_index); |
| 170 EXPECT_TRUE(highlighting_window->IsVisible()); |
| 171 EXPECT_EQ(bounds, highlighting_window->GetBoundsInScreen()); |
| 172 EXPECT_EQ(kBackgroundColor, highlighting_window->GetInternalWidget() |
| 173 ->GetRootView() |
| 174 ->background() |
| 175 ->get_color()); |
| 176 } |
| 177 |
| 118 } // namespace | 178 } // namespace |
| 119 | 179 |
| 120 class AshDevToolsTest : public AshTest { | 180 class AshDevToolsTest : public AshTest { |
| 121 public: | 181 public: |
| 122 AshDevToolsTest() {} | 182 AshDevToolsTest() {} |
| 123 ~AshDevToolsTest() override {} | 183 ~AshDevToolsTest() override {} |
| 124 | 184 |
| 125 views::internal::NativeWidgetPrivate* CreateTestNativeWidget() { | 185 views::internal::NativeWidgetPrivate* CreateTestNativeWidget() { |
| 126 views::Widget* widget = new views::Widget; | 186 views::Widget* widget = new views::Widget; |
| 127 views::Widget::InitParams params; | 187 views::Widget::InitParams params; |
| 128 params.ownership = views::Widget::InitParams::NATIVE_WIDGET_OWNS_WIDGET; | 188 params.ownership = views::Widget::InitParams::NATIVE_WIDGET_OWNS_WIDGET; |
| 129 WmShell::Get() | 189 WmShell::Get() |
| 130 ->GetPrimaryRootWindow() | 190 ->GetPrimaryRootWindowController() |
| 131 ->GetRootWindowController() | |
| 132 ->ConfigureWidgetInitParamsForContainer( | 191 ->ConfigureWidgetInitParamsForContainer( |
| 133 widget, kShellWindowId_DefaultContainer, ¶ms); | 192 widget, kShellWindowId_DefaultContainer, ¶ms); |
| 134 widget->Init(params); | 193 widget->Init(params); |
| 135 return widget->native_widget_private(); | 194 return widget->native_widget_private(); |
| 136 } | 195 } |
| 137 | 196 |
| 138 void SetUp() override { | 197 void SetUp() override { |
| 139 AshTest::SetUp(); | 198 AshTest::SetUp(); |
| 140 fake_frontend_channel_ = base::MakeUnique<FakeFrontendChannel>(); | 199 fake_frontend_channel_ = base::MakeUnique<FakeFrontendChannel>(); |
| 141 uber_dispatcher_ = | 200 uber_dispatcher_ = |
| 142 base::MakeUnique<UberDispatcher>(fake_frontend_channel_.get()); | 201 base::MakeUnique<UberDispatcher>(fake_frontend_channel_.get()); |
| 143 dom_agent_ = | 202 dom_agent_ = |
| 144 base::MakeUnique<devtools::AshDevToolsDOMAgent>(WmShell::Get()); | 203 base::MakeUnique<devtools::AshDevToolsDOMAgent>(WmShell::Get()); |
| 145 dom_agent_->Init(uber_dispatcher_.get()); | 204 dom_agent_->Init(uber_dispatcher_.get()); |
| 205 css_agent_ = |
| 206 base::MakeUnique<devtools::AshDevToolsCSSAgent>(dom_agent_.get()); |
| 207 css_agent_->Init(uber_dispatcher_.get()); |
| 208 css_agent_->enable(); |
| 146 } | 209 } |
| 147 | 210 |
| 148 void TearDown() override { | 211 void TearDown() override { |
| 212 css_agent_.reset(); |
| 149 dom_agent_.reset(); | 213 dom_agent_.reset(); |
| 150 uber_dispatcher_.reset(); | 214 uber_dispatcher_.reset(); |
| 151 fake_frontend_channel_.reset(); | 215 fake_frontend_channel_.reset(); |
| 152 AshTest::TearDown(); | 216 AshTest::TearDown(); |
| 153 } | 217 } |
| 154 | 218 |
| 155 void ExpectChildNodeInserted(int parent_id, int prev_sibling_id) { | 219 void ExpectChildNodeInserted(int parent_id, int prev_sibling_id) { |
| 156 EXPECT_EQ(1, frontend_channel()->CountProtocolNotificationMessageStartsWith( | 220 EXPECT_EQ(1, frontend_channel()->CountProtocolNotificationMessageStartsWith( |
| 157 base::StringPrintf("{\"method\":\"DOM.childNodeInserted\"," | 221 base::StringPrintf("{\"method\":\"DOM.childNodeInserted\"," |
| 158 "\"params\":{\"parentNodeId\":%d," | 222 "\"params\":{\"parentNodeId\":%d," |
| 159 "\"previousNodeId\":%d", | 223 "\"previousNodeId\":%d", |
| 160 parent_id, prev_sibling_id))); | 224 parent_id, prev_sibling_id))); |
| 161 } | 225 } |
| 162 | 226 |
| 163 void ExpectChildNodeRemoved(int parent_id, int node_id) { | 227 void ExpectChildNodeRemoved(int parent_id, int node_id) { |
| 164 EXPECT_EQ(1, frontend_channel()->CountProtocolNotificationMessage( | 228 EXPECT_EQ(1, frontend_channel()->CountProtocolNotificationMessage( |
| 165 base::StringPrintf( | 229 base::StringPrintf( |
| 166 "{\"method\":\"DOM.childNodeRemoved\",\"params\":{" | 230 "{\"method\":\"DOM.childNodeRemoved\",\"params\":{" |
| 167 "\"parentNodeId\":%d,\"nodeId\":%d}}", | 231 "\"parentNodeId\":%d,\"nodeId\":%d}}", |
| 168 parent_id, node_id))); | 232 parent_id, node_id))); |
| 169 } | 233 } |
| 170 | 234 |
| 235 void ExpectStyleSheetChanged(int node_id) { |
| 236 EXPECT_EQ(1, frontend_channel()->CountProtocolNotificationMessage( |
| 237 base::StringPrintf( |
| 238 "{\"method\":\"CSS.styleSheetChanged\",\"params\":{" |
| 239 "\"styleSheetId\":\"%d\"}}", |
| 240 node_id))); |
| 241 } |
| 242 |
| 243 void CompareNodeBounds(DOM::Node* node, const gfx::Rect& bounds) { |
| 244 Maybe<CSS::CSSStyle> styles; |
| 245 css_agent_->getMatchedStylesForNode(node->getNodeId(), &styles); |
| 246 ASSERT_TRUE(styles.isJust()); |
| 247 Array<CSS::CSSProperty>* properties = styles.fromJust()->getCssProperties(); |
| 248 EXPECT_EQ(bounds.height(), GetPropertyByName("height", properties)); |
| 249 EXPECT_EQ(bounds.width(), GetPropertyByName("width", properties)); |
| 250 EXPECT_EQ(bounds.x(), GetPropertyByName("x", properties)); |
| 251 EXPECT_EQ(bounds.y(), GetPropertyByName("y", properties)); |
| 252 } |
| 253 |
| 254 void SetStyleTexts(DOM::Node* node, |
| 255 const std::string& style_text, |
| 256 bool success) { |
| 257 auto edits = Array<CSS::StyleDeclarationEdit>::create(); |
| 258 auto edit = CSS::StyleDeclarationEdit::create() |
| 259 .setStyleSheetId(base::IntToString(node->getNodeId())) |
| 260 .setText(style_text) |
| 261 .build(); |
| 262 edits->addItem(std::move(edit)); |
| 263 std::unique_ptr<Array<CSS::CSSStyle>> output; |
| 264 EXPECT_EQ(success, |
| 265 css_agent_->setStyleTexts(std::move(edits), &output).isSuccess()); |
| 266 |
| 267 if (success) |
| 268 ASSERT_TRUE(output); |
| 269 else |
| 270 ASSERT_FALSE(output); |
| 271 } |
| 272 |
| 273 void HighlightNode(int node_id) { |
| 274 dom_agent_->highlightNode( |
| 275 CreateHighlightConfig(kBackgroundColor, kBorderColor), node_id); |
| 276 } |
| 277 |
| 278 void HideHighlight(int root_window_index) { |
| 279 dom_agent_->hideHighlight(); |
| 280 ASSERT_FALSE(GetHighlightingWindow(root_window_index)->IsVisible()); |
| 281 } |
| 282 |
| 171 FakeFrontendChannel* frontend_channel() { | 283 FakeFrontendChannel* frontend_channel() { |
| 172 return fake_frontend_channel_.get(); | 284 return fake_frontend_channel_.get(); |
| 173 } | 285 } |
| 174 | 286 |
| 287 devtools::AshDevToolsCSSAgent* css_agent() { return css_agent_.get(); } |
| 175 devtools::AshDevToolsDOMAgent* dom_agent() { return dom_agent_.get(); } | 288 devtools::AshDevToolsDOMAgent* dom_agent() { return dom_agent_.get(); } |
| 176 | 289 |
| 177 private: | 290 private: |
| 178 std::unique_ptr<UberDispatcher> uber_dispatcher_; | 291 std::unique_ptr<UberDispatcher> uber_dispatcher_; |
| 179 std::unique_ptr<FakeFrontendChannel> fake_frontend_channel_; | 292 std::unique_ptr<FakeFrontendChannel> fake_frontend_channel_; |
| 180 std::unique_ptr<devtools::AshDevToolsDOMAgent> dom_agent_; | 293 std::unique_ptr<devtools::AshDevToolsDOMAgent> dom_agent_; |
| 294 std::unique_ptr<devtools::AshDevToolsCSSAgent> css_agent_; |
| 181 | 295 |
| 182 DISALLOW_COPY_AND_ASSIGN(AshDevToolsTest); | 296 DISALLOW_COPY_AND_ASSIGN(AshDevToolsTest); |
| 183 }; | 297 }; |
| 184 | 298 |
| 185 TEST_F(AshDevToolsTest, GetDocumentWithWindowWidgetView) { | 299 TEST_F(AshDevToolsTest, GetDocumentWithWindowWidgetView) { |
| 186 std::unique_ptr<views::Widget> widget( | 300 std::unique_ptr<views::Widget> widget( |
| 187 CreateTestWidget(gfx::Rect(1, 1, 1, 1))); | 301 CreateTestWidget(gfx::Rect(1, 1, 1, 1))); |
| 188 WmWindow* parent_window = WmLookup::Get()->GetWindowForWidget(widget.get()); | 302 WmWindow* parent_window = WmLookup::Get()->GetWindowForWidget(widget.get()); |
| 189 parent_window->SetName("parent_window"); | 303 parent_window->SetName("parent_window"); |
| 190 std::unique_ptr<WindowOwner> child_owner(CreateChildWindow(parent_window)); | 304 std::unique_ptr<WindowOwner> child_owner(CreateChildWindow(parent_window)); |
| (...skipping 276 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 467 Compare(parent_view, parent_view_node); | 581 Compare(parent_view, parent_view_node); |
| 468 Compare(target_view, target_view_node); | 582 Compare(target_view, target_view_node); |
| 469 Compare(child_view, child_view_node); | 583 Compare(child_view, child_view_node); |
| 470 parent_view->RemoveChildView(child_view); | 584 parent_view->RemoveChildView(child_view); |
| 471 target_view->AddChildView(child_view); | 585 target_view->AddChildView(child_view); |
| 472 ExpectChildNodeRemoved(parent_view_node->getNodeId(), | 586 ExpectChildNodeRemoved(parent_view_node->getNodeId(), |
| 473 child_view_node->getNodeId()); | 587 child_view_node->getNodeId()); |
| 474 ExpectChildNodeInserted(target_view_node->getNodeId(), 0); | 588 ExpectChildNodeInserted(target_view_node->getNodeId(), 0); |
| 475 } | 589 } |
| 476 | 590 |
| 591 TEST_F(AshDevToolsTest, WindowWidgetViewHighlight) { |
| 592 std::unique_ptr<views::Widget> widget( |
| 593 CreateTestWidget(gfx::Rect(0, 0, 400, 400))); |
| 594 WmWindow* parent_window = WmLookup::Get()->GetWindowForWidget(widget.get()); |
| 595 std::unique_ptr<WindowOwner> child_owner(CreateChildWindow(parent_window)); |
| 596 WmWindow* window = child_owner->window(); |
| 597 views::View* root_view = widget->GetRootView(); |
| 598 |
| 599 std::unique_ptr<ui::devtools::protocol::DOM::Node> root; |
| 600 dom_agent()->getDocument(&root); |
| 601 |
| 602 DOM::Node* parent_node = FindInRoot(parent_window, root.get()); |
| 603 ASSERT_TRUE(parent_node); |
| 604 Array<DOM::Node>* parent_children = parent_node->getChildren(nullptr); |
| 605 ASSERT_TRUE(parent_children); |
| 606 DOM::Node* window_node = parent_children->get(1); |
| 607 DOM::Node* widget_node = parent_children->get(0); |
| 608 DOM::Node* root_view_node = widget_node->getChildren(nullptr)->get(0); |
| 609 |
| 610 HighlightNode(window_node->getNodeId()); |
| 611 ExpectHighlighted(window->GetBoundsInScreen(), 0); |
| 612 |
| 613 HideHighlight(0); |
| 614 |
| 615 HighlightNode(widget_node->getNodeId()); |
| 616 ExpectHighlighted(widget->GetWindowBoundsInScreen(), 0); |
| 617 |
| 618 HideHighlight(0); |
| 619 |
| 620 HighlightNode(root_view_node->getNodeId()); |
| 621 ExpectHighlighted(root_view->GetBoundsInScreen(), 0); |
| 622 |
| 623 HideHighlight(0); |
| 624 |
| 625 // Highlight non-existent node |
| 626 HighlightNode(10000); |
| 627 EXPECT_FALSE(GetHighlightingWindow(0)->IsVisible()); |
| 628 } |
| 629 |
| 630 TEST_F(AshDevToolsTest, MultipleDisplayHighlight) { |
| 631 if (!SupportsMultipleDisplays()) |
| 632 return; |
| 633 UpdateDisplay("300x400,500x500"); |
| 634 |
| 635 WmWindow::Windows root_windows = WmShell::Get()->GetAllRootWindows(); |
| 636 std::unique_ptr<WindowOwner> window_owner( |
| 637 CreateTestWindow(gfx::Rect(1, 2, 30, 40))); |
| 638 WmWindow* window = window_owner->window(); |
| 639 |
| 640 std::unique_ptr<ui::devtools::protocol::DOM::Node> root; |
| 641 dom_agent()->getDocument(&root); |
| 642 |
| 643 EXPECT_EQ(root_windows[0], window->GetRootWindow()); |
| 644 HighlightNode(dom_agent()->GetNodeIdFromWindow(window)); |
| 645 ExpectHighlighted(window->GetBoundsInScreen(), 0); |
| 646 |
| 647 window->SetBoundsInScreen(gfx::Rect(500, 0, 50, 50), GetSecondaryDisplay()); |
| 648 EXPECT_EQ(root_windows[1], window->GetRootWindow()); |
| 649 HighlightNode(dom_agent()->GetNodeIdFromWindow(window)); |
| 650 ExpectHighlighted(window->GetBoundsInScreen(), 1); |
| 651 } |
| 652 |
| 653 TEST_F(AshDevToolsTest, WindowWidgetViewGetMatchedStylesForNode) { |
| 654 std::unique_ptr<views::Widget> widget( |
| 655 CreateTestWidget(gfx::Rect(1, 1, 1, 1))); |
| 656 WmWindow* parent_window = WmLookup::Get()->GetWindowForWidget(widget.get()); |
| 657 std::unique_ptr<WindowOwner> child_owner(CreateChildWindow(parent_window)); |
| 658 WmWindow* window = child_owner->window(); |
| 659 gfx::Rect window_bounds(2, 2, 3, 3); |
| 660 gfx::Rect widget_bounds(50, 50, 100, 75); |
| 661 gfx::Rect view_bounds(4, 4, 3, 3); |
| 662 window->SetBounds(window_bounds); |
| 663 widget->SetBounds(widget_bounds); |
| 664 widget->GetRootView()->SetBoundsRect(view_bounds); |
| 665 |
| 666 std::unique_ptr<ui::devtools::protocol::DOM::Node> root; |
| 667 dom_agent()->getDocument(&root); |
| 668 |
| 669 DOM::Node* parent_node = FindInRoot(parent_window, root.get()); |
| 670 ASSERT_TRUE(parent_node); |
| 671 Array<DOM::Node>* parent_children = parent_node->getChildren(nullptr); |
| 672 ASSERT_TRUE(parent_children); |
| 673 |
| 674 CompareNodeBounds(parent_node, widget_bounds); |
| 675 CompareNodeBounds(parent_children->get(1), window_bounds); |
| 676 CompareNodeBounds(parent_children->get(0)->getChildren(nullptr)->get(0), |
| 677 view_bounds); |
| 678 } |
| 679 |
| 680 TEST_F(AshDevToolsTest, WindowWidgetViewStyleSheetChanged) { |
| 681 std::unique_ptr<views::Widget> widget( |
| 682 CreateTestWidget(gfx::Rect(1, 1, 1, 1))); |
| 683 WmWindow* parent_window = WmLookup::Get()->GetWindowForWidget(widget.get()); |
| 684 std::unique_ptr<WindowOwner> child_owner(CreateChildWindow(parent_window)); |
| 685 WmWindow* window = child_owner->window(); |
| 686 |
| 687 std::unique_ptr<ui::devtools::protocol::DOM::Node> root; |
| 688 dom_agent()->getDocument(&root); |
| 689 |
| 690 gfx::Rect window_bounds(2, 2, 3, 3); |
| 691 gfx::Rect widget_bounds(10, 10, 5, 6); |
| 692 gfx::Rect view_bounds(4, 4, 3, 3); |
| 693 window->SetBounds(window_bounds); |
| 694 widget->SetBounds(widget_bounds); |
| 695 widget->GetRootView()->SetBoundsRect(view_bounds); |
| 696 |
| 697 DOM::Node* parent_node = FindInRoot(parent_window, root.get()); |
| 698 ASSERT_TRUE(parent_node); |
| 699 Array<DOM::Node>* parent_children = parent_node->getChildren(nullptr); |
| 700 ASSERT_TRUE(parent_children); |
| 701 |
| 702 ExpectStyleSheetChanged(parent_node->getNodeId()); |
| 703 ExpectStyleSheetChanged(parent_children->get(1)->getNodeId()); |
| 704 ExpectStyleSheetChanged( |
| 705 parent_children->get(0)->getChildren(nullptr)->get(0)->getNodeId()); |
| 706 } |
| 707 |
| 708 TEST_F(AshDevToolsTest, WindowWidgetViewSetStyleText) { |
| 709 std::unique_ptr<views::Widget> widget( |
| 710 CreateTestWidget(gfx::Rect(0, 0, 400, 400))); |
| 711 WmWindow* parent_window = WmLookup::Get()->GetWindowForWidget(widget.get()); |
| 712 std::unique_ptr<WindowOwner> child_owner(CreateChildWindow(parent_window)); |
| 713 WmWindow* window = child_owner->window(); |
| 714 views::View* root_view = widget->GetRootView(); |
| 715 |
| 716 std::unique_ptr<ui::devtools::protocol::DOM::Node> root; |
| 717 dom_agent()->getDocument(&root); |
| 718 |
| 719 DOM::Node* parent_node = FindInRoot(parent_window, root.get()); |
| 720 ASSERT_TRUE(parent_node); |
| 721 Array<DOM::Node>* parent_children = parent_node->getChildren(nullptr); |
| 722 ASSERT_TRUE(parent_children); |
| 723 |
| 724 // Test different combinations on window node |
| 725 DOM::Node* window_node = parent_children->get(1); |
| 726 |
| 727 SetStyleTexts(window_node, "x: 25; y:35; width: 5; height: 20;", true); |
| 728 EXPECT_EQ(gfx::Rect(25, 35, 5, 20), window->GetBounds()); |
| 729 |
| 730 SetStyleTexts(window_node, "test_nothing_happens:1;", false); |
| 731 EXPECT_EQ(gfx::Rect(25, 35, 5, 20), window->GetBounds()); // Not changed |
| 732 |
| 733 SetStyleTexts(window_node, "\nheight: 10;\n ", true); |
| 734 EXPECT_EQ(gfx::Rect(25, 35, 5, 10), window->GetBounds()); |
| 735 |
| 736 SetStyleTexts(window_node, "\nx: 10; y: 23; width: 52;\n ", true); |
| 737 EXPECT_EQ(gfx::Rect(10, 23, 52, 10), window->GetBounds()); |
| 738 |
| 739 // Test different combinations on widget node |
| 740 DOM::Node* widget_node = parent_children->get(0); |
| 741 |
| 742 SetStyleTexts(widget_node, "x: 25; y:35; width: 53; height: 64;", true); |
| 743 EXPECT_EQ(gfx::Rect(25, 35, 53, 64), widget->GetRestoredBounds()); |
| 744 |
| 745 SetStyleTexts(widget_node, "test_nothing_happens:1;", false); |
| 746 EXPECT_EQ(gfx::Rect(25, 35, 53, 64), |
| 747 widget->GetRestoredBounds()); // Not changed |
| 748 |
| 749 SetStyleTexts(widget_node, "\nheight: 123;\n ", true); |
| 750 EXPECT_EQ(gfx::Rect(25, 35, 53, 123), widget->GetRestoredBounds()); |
| 751 |
| 752 SetStyleTexts(widget_node, "\nx: 10; y: 23; width: 98;\n ", true); |
| 753 EXPECT_EQ(gfx::Rect(10, 23, 98, 123), widget->GetRestoredBounds()); |
| 754 |
| 755 // Test different combinations on view node |
| 756 DOM::Node* root_view_node = widget_node->getChildren(nullptr)->get(0); |
| 757 |
| 758 SetStyleTexts(root_view_node, "x: 25; y:35; width: 45; height: 20;", true); |
| 759 EXPECT_EQ(gfx::Rect(25, 35, 45, 20), root_view->bounds()); |
| 760 |
| 761 SetStyleTexts(root_view_node, "test_nothing_happens:1;", false); |
| 762 EXPECT_EQ(gfx::Rect(25, 35, 45, 20), root_view->bounds()); // Not changed |
| 763 |
| 764 SetStyleTexts(root_view_node, "\nheight: 73;\n ", true); |
| 765 EXPECT_EQ(gfx::Rect(25, 35, 45, 73), root_view->bounds()); |
| 766 |
| 767 SetStyleTexts(root_view_node, "\nx: 10; y: 23; width: 52;\n ", true); |
| 768 EXPECT_EQ(gfx::Rect(10, 23, 52, 73), root_view->bounds()); |
| 769 } |
| 770 |
| 477 } // namespace ash | 771 } // namespace ash |
| OLD | NEW |