| 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/public/cpp/shell_window_ids.h" |
| 7 #include "ash/root_window_controller.h" | 8 #include "ash/root_window_controller.h" |
| 8 #include "ash/shell.h" | 9 #include "ash/shell.h" |
| 9 #include "ash/shell_port.h" | 10 #include "ash/shell_port.h" |
| 10 #include "ash/test/ash_test.h" | 11 #include "ash/test/ash_test.h" |
| 11 #include "ash/wm/widget_finder.h" | 12 #include "ash/wm/widget_finder.h" |
| 12 #include "ash/wm_window.h" | 13 #include "ash/wm_window.h" |
| 13 #include "base/memory/ptr_util.h" | 14 #include "base/memory/ptr_util.h" |
| 14 #include "base/strings/stringprintf.h" | 15 #include "base/strings/stringprintf.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" |
| (...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 169 void ExpectHighlighted(const gfx::Rect& bounds, int root_window_index) { | 170 void ExpectHighlighted(const gfx::Rect& bounds, int root_window_index) { |
| 170 aura::Window* highlighting_window = GetHighlightingWindow(root_window_index); | 171 aura::Window* highlighting_window = GetHighlightingWindow(root_window_index); |
| 171 EXPECT_TRUE(highlighting_window->IsVisible()); | 172 EXPECT_TRUE(highlighting_window->IsVisible()); |
| 172 EXPECT_EQ(bounds, highlighting_window->GetBoundsInScreen()); | 173 EXPECT_EQ(bounds, highlighting_window->GetBoundsInScreen()); |
| 173 EXPECT_EQ(kBackgroundColor, GetInternalWidgetForWindow(highlighting_window) | 174 EXPECT_EQ(kBackgroundColor, GetInternalWidgetForWindow(highlighting_window) |
| 174 ->GetRootView() | 175 ->GetRootView() |
| 175 ->background() | 176 ->background() |
| 176 ->get_color()); | 177 ->get_color()); |
| 177 } | 178 } |
| 178 | 179 |
| 180 WmWindow* GetPrimaryRootWindow() { |
| 181 return ShellPort::Get()->GetPrimaryRootWindow(); |
| 182 } |
| 183 |
| 179 } // namespace | 184 } // namespace |
| 180 | 185 |
| 181 class AshDevToolsTest : public AshTest { | 186 class AshDevToolsTest : public AshTest { |
| 182 public: | 187 public: |
| 183 AshDevToolsTest() {} | 188 AshDevToolsTest() {} |
| 184 ~AshDevToolsTest() override {} | 189 ~AshDevToolsTest() override {} |
| 185 | 190 |
| 186 views::internal::NativeWidgetPrivate* CreateTestNativeWidget() { | 191 views::internal::NativeWidgetPrivate* CreateTestNativeWidget() { |
| 187 views::Widget* widget = new views::Widget; | 192 views::Widget* widget = new views::Widget; |
| 188 views::Widget::InitParams params; | 193 views::Widget::InitParams params; |
| (...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 339 Compare(widget, widget_node); | 344 Compare(widget, widget_node); |
| 340 // Destroy NativeWidget followed by |widget| | 345 // Destroy NativeWidget followed by |widget| |
| 341 widget->CloseNow(); | 346 widget->CloseNow(); |
| 342 } | 347 } |
| 343 | 348 |
| 344 TEST_F(AshDevToolsTest, WindowAddedChildNodeInserted) { | 349 TEST_F(AshDevToolsTest, WindowAddedChildNodeInserted) { |
| 345 // Initialize DOMAgent | 350 // Initialize DOMAgent |
| 346 std::unique_ptr<ui::devtools::protocol::DOM::Node> root; | 351 std::unique_ptr<ui::devtools::protocol::DOM::Node> root; |
| 347 dom_agent()->getDocument(&root); | 352 dom_agent()->getDocument(&root); |
| 348 | 353 |
| 349 WmWindow* parent_window = ShellPort::Get()->GetPrimaryRootWindow(); | 354 WmWindow* root_window = GetPrimaryRootWindow(); |
| 350 DOM::Node* parent_node = root->getChildren(nullptr)->get(0); | 355 WmWindow* parent_window = root_window->GetChildren()[0]; |
| 356 DOM::Node* parent_node = FindInRoot(parent_window, root.get()); |
| 351 Array<DOM::Node>* parent_node_children = parent_node->getChildren(nullptr); | 357 Array<DOM::Node>* parent_node_children = parent_node->getChildren(nullptr); |
| 352 DOM::Node* sibling_node = | 358 DOM::Node* sibling_node = |
| 353 parent_node_children->get(parent_node_children->length() - 1); | 359 parent_node_children->get(parent_node_children->length() - 1); |
| 354 | 360 |
| 355 std::unique_ptr<WindowOwner> child_owner(CreateChildWindow(parent_window)); | 361 std::unique_ptr<WindowOwner> child_owner(CreateChildWindow(parent_window)); |
| 356 ExpectChildNodeInserted(parent_node->getNodeId(), sibling_node->getNodeId()); | 362 ExpectChildNodeInserted(parent_node->getNodeId(), sibling_node->getNodeId()); |
| 357 } | 363 } |
| 358 | 364 |
| 359 TEST_F(AshDevToolsTest, WindowDestroyedChildNodeRemoved) { | 365 TEST_F(AshDevToolsTest, WindowDestroyedChildNodeRemoved) { |
| 360 // Initialize DOMAgent | 366 // Initialize DOMAgent |
| 361 std::unique_ptr<ui::devtools::protocol::DOM::Node> root; | 367 std::unique_ptr<ui::devtools::protocol::DOM::Node> root; |
| 362 dom_agent()->getDocument(&root); | 368 dom_agent()->getDocument(&root); |
| 363 | 369 |
| 364 WmWindow* parent_window = | 370 WmWindow* root_window = GetPrimaryRootWindow(); |
| 365 ShellPort::Get()->GetPrimaryRootWindow()->GetChildren()[0]; | 371 WmWindow* rotation_window = root_window->GetChildren()[0]; |
| 372 WmWindow* parent_window = rotation_window->GetChildren()[0]; |
| 366 WmWindow* child_window = parent_window->GetChildren()[0]; | 373 WmWindow* child_window = parent_window->GetChildren()[0]; |
| 367 DOM::Node* root_node = root->getChildren(nullptr)->get(0); | 374 DOM::Node* root_node = |
| 375 root->getChildren(nullptr)->get(0)->getChildren(nullptr)->get(0); |
| 368 DOM::Node* parent_node = root_node->getChildren(nullptr)->get(0); | 376 DOM::Node* parent_node = root_node->getChildren(nullptr)->get(0); |
| 369 DOM::Node* child_node = parent_node->getChildren(nullptr)->get(0); | 377 DOM::Node* child_node = parent_node->getChildren(nullptr)->get(0); |
| 370 | 378 |
| 371 Compare(parent_window, parent_node); | 379 Compare(parent_window, parent_node); |
| 372 Compare(child_window, child_node); | 380 Compare(child_window, child_node); |
| 373 child_window->Destroy(); | 381 child_window->Destroy(); |
| 374 ExpectChildNodeRemoved(parent_node->getNodeId(), child_node->getNodeId()); | 382 ExpectChildNodeRemoved(parent_node->getNodeId(), child_node->getNodeId()); |
| 375 } | 383 } |
| 376 | 384 |
| 377 TEST_F(AshDevToolsTest, WindowReorganizedChildNodeRearranged) { | 385 TEST_F(AshDevToolsTest, WindowReorganizedChildNodeRearranged) { |
| 378 // Initialize DOMAgent | 386 // Initialize DOMAgent |
| 379 std::unique_ptr<ui::devtools::protocol::DOM::Node> root; | 387 std::unique_ptr<ui::devtools::protocol::DOM::Node> root; |
| 380 dom_agent()->getDocument(&root); | 388 dom_agent()->getDocument(&root); |
| 381 | 389 |
| 382 WmWindow* root_window = ShellPort::Get()->GetPrimaryRootWindow(); | 390 WmWindow* root_window = GetPrimaryRootWindow(); |
| 383 WmWindow* target_window = root_window->GetChildren()[1]; | 391 WmWindow* rotation_window = root_window->GetChildren()[0]; |
| 384 WmWindow* child_window = root_window->GetChildren()[0]->GetChildren()[0]; | 392 WmWindow* parent_window = rotation_window->GetChildren()[0]; |
| 393 WmWindow* target_window = rotation_window->GetChildren()[1]; |
| 394 WmWindow* child_window = parent_window->GetChildren()[0]; |
| 385 | 395 |
| 386 DOM::Node* root_node = root->getChildren(nullptr)->get(0); | 396 DOM::Node* root_node = |
| 397 root->getChildren(nullptr)->get(0)->getChildren(nullptr)->get(0); |
| 387 DOM::Node* parent_node = root_node->getChildren(nullptr)->get(0); | 398 DOM::Node* parent_node = root_node->getChildren(nullptr)->get(0); |
| 388 DOM::Node* target_node = root_node->getChildren(nullptr)->get(1); | 399 DOM::Node* target_node = root_node->getChildren(nullptr)->get(1); |
| 389 Array<DOM::Node>* target_node_children = target_node->getChildren(nullptr); | 400 Array<DOM::Node>* target_node_children = target_node->getChildren(nullptr); |
| 390 DOM::Node* sibling_node = | 401 DOM::Node* sibling_node = |
| 391 target_node_children->get(target_node_children->length() - 1); | 402 target_node_children->get(target_node_children->length() - 1); |
| 392 DOM::Node* child_node = parent_node->getChildren(nullptr)->get(0); | 403 DOM::Node* child_node = parent_node->getChildren(nullptr)->get(0); |
| 393 | 404 |
| 405 Compare(parent_window, parent_node); |
| 394 Compare(target_window, target_node); | 406 Compare(target_window, target_node); |
| 395 Compare(child_window, child_node); | 407 Compare(child_window, child_node); |
| 396 target_window->AddChild(child_window); | 408 target_window->AddChild(child_window); |
| 397 ExpectChildNodeRemoved(parent_node->getNodeId(), child_node->getNodeId()); | 409 ExpectChildNodeRemoved(parent_node->getNodeId(), child_node->getNodeId()); |
| 398 ExpectChildNodeInserted(target_node->getNodeId(), sibling_node->getNodeId()); | 410 ExpectChildNodeInserted(target_node->getNodeId(), sibling_node->getNodeId()); |
| 399 } | 411 } |
| 400 | 412 |
| 401 TEST_F(AshDevToolsTest, WindowReorganizedChildNodeRemovedAndInserted) { | 413 TEST_F(AshDevToolsTest, WindowReorganizedChildNodeRemovedAndInserted) { |
| 402 WmWindow* root_window = ShellPort::Get()->GetPrimaryRootWindow(); | 414 WmWindow* root_window = GetPrimaryRootWindow(); |
| 403 WmWindow* target_window = root_window->GetChildren()[1]; | 415 WmWindow* rotation_window = root_window->GetChildren()[0]; |
| 404 WmWindow* parent_window = root_window->GetChildren()[0]; | 416 WmWindow* parent_window = rotation_window->GetChildren()[0]; |
| 417 WmWindow* target_window = rotation_window->GetChildren()[1]; |
| 405 std::unique_ptr<WindowOwner> child_owner(CreateChildWindow(parent_window)); | 418 std::unique_ptr<WindowOwner> child_owner(CreateChildWindow(parent_window)); |
| 406 WmWindow* child_window = child_owner->window(); | 419 WmWindow* child_window = child_owner->window(); |
| 407 | 420 |
| 408 // Initialize DOMAgent | 421 // Initialize DOMAgent |
| 409 std::unique_ptr<ui::devtools::protocol::DOM::Node> root; | 422 std::unique_ptr<ui::devtools::protocol::DOM::Node> root; |
| 410 dom_agent()->getDocument(&root); | 423 dom_agent()->getDocument(&root); |
| 411 DOM::Node* root_node = root->getChildren(nullptr)->get(0); | 424 DOM::Node* root_node = |
| 412 | 425 root->getChildren(nullptr)->get(0)->getChildren(nullptr)->get(0); |
| 413 DOM::Node* parent_node = root_node->getChildren(nullptr)->get(0); | 426 DOM::Node* parent_node = root_node->getChildren(nullptr)->get(0); |
| 414 DOM::Node* target_node = root_node->getChildren(nullptr)->get(1); | 427 DOM::Node* target_node = root_node->getChildren(nullptr)->get(1); |
| 415 Array<DOM::Node>* target_node_children = target_node->getChildren(nullptr); | 428 Array<DOM::Node>* target_node_children = target_node->getChildren(nullptr); |
| 416 DOM::Node* sibling_node = | 429 DOM::Node* sibling_node = |
| 417 target_node_children->get(target_node_children->length() - 1); | 430 target_node_children->get(target_node_children->length() - 1); |
| 418 Array<DOM::Node>* parent_node_children = parent_node->getChildren(nullptr); | 431 Array<DOM::Node>* parent_node_children = parent_node->getChildren(nullptr); |
| 419 DOM::Node* child_node = | 432 DOM::Node* child_node = |
| 420 parent_node_children->get(parent_node_children->length() - 1); | 433 parent_node_children->get(parent_node_children->length() - 1); |
| 421 | 434 |
| 435 Compare(parent_window, parent_node); |
| 422 Compare(target_window, target_node); | 436 Compare(target_window, target_node); |
| 423 Compare(child_window, child_node); | 437 Compare(child_window, child_node); |
| 424 parent_window->RemoveChild(child_window); | 438 parent_window->RemoveChild(child_window); |
| 425 target_window->AddChild(child_window); | 439 target_window->AddChild(child_window); |
| 426 ExpectChildNodeRemoved(parent_node->getNodeId(), child_node->getNodeId()); | 440 ExpectChildNodeRemoved(parent_node->getNodeId(), child_node->getNodeId()); |
| 427 ExpectChildNodeInserted(target_node->getNodeId(), sibling_node->getNodeId()); | 441 ExpectChildNodeInserted(target_node->getNodeId(), sibling_node->getNodeId()); |
| 428 } | 442 } |
| 429 | 443 |
| 430 TEST_F(AshDevToolsTest, WindowStackingChangedChildNodeRemovedAndInserted) { | 444 TEST_F(AshDevToolsTest, WindowStackingChangedChildNodeRemovedAndInserted) { |
| 431 // Initialize DOMAgent | 445 // Initialize DOMAgent |
| 432 std::unique_ptr<ui::devtools::protocol::DOM::Node> root; | 446 std::unique_ptr<ui::devtools::protocol::DOM::Node> root; |
| 433 dom_agent()->getDocument(&root); | 447 dom_agent()->getDocument(&root); |
| 434 | 448 |
| 435 WmWindow* parent_window = ShellPort::Get()->GetPrimaryRootWindow(); | 449 WmWindow* root_window = GetPrimaryRootWindow(); |
| 450 WmWindow* parent_window = root_window->GetChildren()[0]; |
| 436 WmWindow* child_window = parent_window->GetChildren()[0]; | 451 WmWindow* child_window = parent_window->GetChildren()[0]; |
| 437 WmWindow* target_window = parent_window->GetChildren()[1]; | 452 WmWindow* target_window = parent_window->GetChildren()[1]; |
| 438 | 453 |
| 439 DOM::Node* parent_node = root->getChildren(nullptr)->get(0); | 454 DOM::Node* parent_node = |
| 455 root->getChildren(nullptr)->get(0)->getChildren(nullptr)->get(0); |
| 440 Array<DOM::Node>* parent_node_children = parent_node->getChildren(nullptr); | 456 Array<DOM::Node>* parent_node_children = parent_node->getChildren(nullptr); |
| 441 DOM::Node* child_node = parent_node_children->get(0); | 457 DOM::Node* child_node = parent_node_children->get(0); |
| 442 DOM::Node* sibling_node = parent_node_children->get(1); | 458 DOM::Node* sibling_node = parent_node_children->get(1); |
| 443 int parent_id = parent_node->getNodeId(); | 459 int parent_id = parent_node->getNodeId(); |
| 444 | 460 |
| 445 Compare(parent_window, parent_node); | 461 Compare(parent_window, parent_node); |
| 446 Compare(child_window, child_node); | 462 Compare(child_window, child_node); |
| 447 parent_window->StackChildAbove(child_window, target_window); | 463 parent_window->StackChildAbove(child_window, target_window); |
| 448 ExpectChildNodeRemoved(parent_id, child_node->getNodeId()); | 464 ExpectChildNodeRemoved(parent_id, child_node->getNodeId()); |
| 449 ExpectChildNodeInserted(parent_id, sibling_node->getNodeId()); | 465 ExpectChildNodeInserted(parent_id, sibling_node->getNodeId()); |
| (...skipping 316 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 766 SetStyleTexts(root_view_node, "\nheight: 73;\n ", true); | 782 SetStyleTexts(root_view_node, "\nheight: 73;\n ", true); |
| 767 EXPECT_EQ(gfx::Rect(25, 35, 45, 73), root_view->bounds()); | 783 EXPECT_EQ(gfx::Rect(25, 35, 45, 73), root_view->bounds()); |
| 768 | 784 |
| 769 SetStyleTexts(root_view_node, "\nx: 10; y: 23; width: 52;\nvisibility: 1;\n", | 785 SetStyleTexts(root_view_node, "\nx: 10; y: 23; width: 52;\nvisibility: 1;\n", |
| 770 true); | 786 true); |
| 771 EXPECT_EQ(gfx::Rect(10, 23, 52, 73), root_view->bounds()); | 787 EXPECT_EQ(gfx::Rect(10, 23, 52, 73), root_view->bounds()); |
| 772 EXPECT_TRUE(root_view->visible()); | 788 EXPECT_TRUE(root_view->visible()); |
| 773 } | 789 } |
| 774 | 790 |
| 775 } // namespace ash | 791 } // namespace ash |
| OLD | NEW |