Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(60)

Side by Side Diff: ash/devtools/ash_devtools_unittest.cc

Issue 2808723004: Renames WmShell to ShellPort (Closed)
Patch Set: feedback Created 3 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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/root_window_controller.h" 7 #include "ash/root_window_controller.h"
8 #include "ash/shell_port.h"
8 #include "ash/test/ash_test.h" 9 #include "ash/test/ash_test.h"
9 #include "ash/wm/widget_finder.h" 10 #include "ash/wm/widget_finder.h"
10 #include "ash/wm_shell.h"
11 #include "ash/wm_window.h" 11 #include "ash/wm_window.h"
12 #include "base/memory/ptr_util.h" 12 #include "base/memory/ptr_util.h"
13 #include "base/strings/stringprintf.h" 13 #include "base/strings/stringprintf.h"
14 #include "ui/display/display.h" 14 #include "ui/display/display.h"
15 #include "ui/views/background.h" 15 #include "ui/views/background.h"
16 #include "ui/views/widget/native_widget_private.h" 16 #include "ui/views/widget/native_widget_private.h"
17 #include "ui/views/widget/widget.h" 17 #include "ui/views/widget/widget.h"
18 18
19 namespace ash { 19 namespace ash {
20 namespace { 20 namespace {
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after
129 EXPECT_TRUE(base::StringToInt(property->getValue(), &value)); 129 EXPECT_TRUE(base::StringToInt(property->getValue(), &value));
130 return value; 130 return value;
131 } 131 }
132 } 132 }
133 NOTREACHED(); 133 NOTREACHED();
134 return -1; 134 return -1;
135 } 135 }
136 136
137 WmWindow* GetHighlightingWindow(int root_window_index) { 137 WmWindow* GetHighlightingWindow(int root_window_index) {
138 WmWindow::Windows overlay_windows = 138 WmWindow::Windows overlay_windows =
139 WmShell::Get() 139 ShellPort::Get()
140 ->GetAllRootWindows()[root_window_index] 140 ->GetAllRootWindows()[root_window_index]
141 ->GetChildByShellWindowId(kShellWindowId_OverlayContainer) 141 ->GetChildByShellWindowId(kShellWindowId_OverlayContainer)
142 ->GetChildren(); 142 ->GetChildren();
143 for (WmWindow* window : overlay_windows) { 143 for (WmWindow* window : overlay_windows) {
144 if (window->aura_window()->GetName() == "HighlightingWidget") 144 if (window->aura_window()->GetName() == "HighlightingWidget")
145 return window; 145 return window;
146 } 146 }
147 NOTREACHED(); 147 NOTREACHED();
148 return nullptr; 148 return nullptr;
149 } 149 }
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
181 181
182 class AshDevToolsTest : public AshTest { 182 class AshDevToolsTest : public AshTest {
183 public: 183 public:
184 AshDevToolsTest() {} 184 AshDevToolsTest() {}
185 ~AshDevToolsTest() override {} 185 ~AshDevToolsTest() override {}
186 186
187 views::internal::NativeWidgetPrivate* CreateTestNativeWidget() { 187 views::internal::NativeWidgetPrivate* CreateTestNativeWidget() {
188 views::Widget* widget = new views::Widget; 188 views::Widget* widget = new views::Widget;
189 views::Widget::InitParams params; 189 views::Widget::InitParams params;
190 params.ownership = views::Widget::InitParams::NATIVE_WIDGET_OWNS_WIDGET; 190 params.ownership = views::Widget::InitParams::NATIVE_WIDGET_OWNS_WIDGET;
191 WmShell::Get() 191 ShellPort::Get()
192 ->GetPrimaryRootWindowController() 192 ->GetPrimaryRootWindowController()
193 ->ConfigureWidgetInitParamsForContainer( 193 ->ConfigureWidgetInitParamsForContainer(
194 widget, kShellWindowId_DefaultContainer, &params); 194 widget, kShellWindowId_DefaultContainer, &params);
195 widget->Init(params); 195 widget->Init(params);
196 return widget->native_widget_private(); 196 return widget->native_widget_private();
197 } 197 }
198 198
199 void SetUp() override { 199 void SetUp() override {
200 AshTest::SetUp(); 200 AshTest::SetUp();
201 fake_frontend_channel_ = base::MakeUnique<FakeFrontendChannel>(); 201 fake_frontend_channel_ = base::MakeUnique<FakeFrontendChannel>();
(...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after
340 Compare(widget, widget_node); 340 Compare(widget, widget_node);
341 // Destroy NativeWidget followed by |widget| 341 // Destroy NativeWidget followed by |widget|
342 widget->CloseNow(); 342 widget->CloseNow();
343 } 343 }
344 344
345 TEST_F(AshDevToolsTest, WindowAddedChildNodeInserted) { 345 TEST_F(AshDevToolsTest, WindowAddedChildNodeInserted) {
346 // Initialize DOMAgent 346 // Initialize DOMAgent
347 std::unique_ptr<ui::devtools::protocol::DOM::Node> root; 347 std::unique_ptr<ui::devtools::protocol::DOM::Node> root;
348 dom_agent()->getDocument(&root); 348 dom_agent()->getDocument(&root);
349 349
350 WmWindow* parent_window = WmShell::Get()->GetPrimaryRootWindow(); 350 WmWindow* parent_window = ShellPort::Get()->GetPrimaryRootWindow();
351 DOM::Node* parent_node = root->getChildren(nullptr)->get(0); 351 DOM::Node* parent_node = root->getChildren(nullptr)->get(0);
352 Array<DOM::Node>* parent_node_children = parent_node->getChildren(nullptr); 352 Array<DOM::Node>* parent_node_children = parent_node->getChildren(nullptr);
353 DOM::Node* sibling_node = 353 DOM::Node* sibling_node =
354 parent_node_children->get(parent_node_children->length() - 1); 354 parent_node_children->get(parent_node_children->length() - 1);
355 355
356 std::unique_ptr<WindowOwner> child_owner(CreateChildWindow(parent_window)); 356 std::unique_ptr<WindowOwner> child_owner(CreateChildWindow(parent_window));
357 ExpectChildNodeInserted(parent_node->getNodeId(), sibling_node->getNodeId()); 357 ExpectChildNodeInserted(parent_node->getNodeId(), sibling_node->getNodeId());
358 } 358 }
359 359
360 TEST_F(AshDevToolsTest, WindowDestroyedChildNodeRemoved) { 360 TEST_F(AshDevToolsTest, WindowDestroyedChildNodeRemoved) {
361 // Initialize DOMAgent 361 // Initialize DOMAgent
362 std::unique_ptr<ui::devtools::protocol::DOM::Node> root; 362 std::unique_ptr<ui::devtools::protocol::DOM::Node> root;
363 dom_agent()->getDocument(&root); 363 dom_agent()->getDocument(&root);
364 364
365 WmWindow* parent_window = 365 WmWindow* parent_window =
366 WmShell::Get()->GetPrimaryRootWindow()->GetChildren()[0]; 366 ShellPort::Get()->GetPrimaryRootWindow()->GetChildren()[0];
367 WmWindow* child_window = parent_window->GetChildren()[0]; 367 WmWindow* child_window = parent_window->GetChildren()[0];
368 DOM::Node* root_node = root->getChildren(nullptr)->get(0); 368 DOM::Node* root_node = root->getChildren(nullptr)->get(0);
369 DOM::Node* parent_node = root_node->getChildren(nullptr)->get(0); 369 DOM::Node* parent_node = root_node->getChildren(nullptr)->get(0);
370 DOM::Node* child_node = parent_node->getChildren(nullptr)->get(0); 370 DOM::Node* child_node = parent_node->getChildren(nullptr)->get(0);
371 371
372 Compare(parent_window, parent_node); 372 Compare(parent_window, parent_node);
373 Compare(child_window, child_node); 373 Compare(child_window, child_node);
374 child_window->Destroy(); 374 child_window->Destroy();
375 ExpectChildNodeRemoved(parent_node->getNodeId(), child_node->getNodeId()); 375 ExpectChildNodeRemoved(parent_node->getNodeId(), child_node->getNodeId());
376 } 376 }
377 377
378 TEST_F(AshDevToolsTest, WindowReorganizedChildNodeRearranged) { 378 TEST_F(AshDevToolsTest, WindowReorganizedChildNodeRearranged) {
379 // Initialize DOMAgent 379 // Initialize DOMAgent
380 std::unique_ptr<ui::devtools::protocol::DOM::Node> root; 380 std::unique_ptr<ui::devtools::protocol::DOM::Node> root;
381 dom_agent()->getDocument(&root); 381 dom_agent()->getDocument(&root);
382 382
383 WmWindow* root_window = WmShell::Get()->GetPrimaryRootWindow(); 383 WmWindow* root_window = ShellPort::Get()->GetPrimaryRootWindow();
384 WmWindow* target_window = root_window->GetChildren()[1]; 384 WmWindow* target_window = root_window->GetChildren()[1];
385 WmWindow* child_window = root_window->GetChildren()[0]->GetChildren()[0]; 385 WmWindow* child_window = root_window->GetChildren()[0]->GetChildren()[0];
386 386
387 DOM::Node* root_node = root->getChildren(nullptr)->get(0); 387 DOM::Node* root_node = root->getChildren(nullptr)->get(0);
388 DOM::Node* parent_node = root_node->getChildren(nullptr)->get(0); 388 DOM::Node* parent_node = root_node->getChildren(nullptr)->get(0);
389 DOM::Node* target_node = root_node->getChildren(nullptr)->get(1); 389 DOM::Node* target_node = root_node->getChildren(nullptr)->get(1);
390 Array<DOM::Node>* target_node_children = target_node->getChildren(nullptr); 390 Array<DOM::Node>* target_node_children = target_node->getChildren(nullptr);
391 DOM::Node* sibling_node = 391 DOM::Node* sibling_node =
392 target_node_children->get(target_node_children->length() - 1); 392 target_node_children->get(target_node_children->length() - 1);
393 DOM::Node* child_node = parent_node->getChildren(nullptr)->get(0); 393 DOM::Node* child_node = parent_node->getChildren(nullptr)->get(0);
394 394
395 Compare(target_window, target_node); 395 Compare(target_window, target_node);
396 Compare(child_window, child_node); 396 Compare(child_window, child_node);
397 target_window->AddChild(child_window); 397 target_window->AddChild(child_window);
398 ExpectChildNodeRemoved(parent_node->getNodeId(), child_node->getNodeId()); 398 ExpectChildNodeRemoved(parent_node->getNodeId(), child_node->getNodeId());
399 ExpectChildNodeInserted(target_node->getNodeId(), sibling_node->getNodeId()); 399 ExpectChildNodeInserted(target_node->getNodeId(), sibling_node->getNodeId());
400 } 400 }
401 401
402 TEST_F(AshDevToolsTest, WindowReorganizedChildNodeRemovedAndInserted) { 402 TEST_F(AshDevToolsTest, WindowReorganizedChildNodeRemovedAndInserted) {
403 WmWindow* root_window = WmShell::Get()->GetPrimaryRootWindow(); 403 WmWindow* root_window = ShellPort::Get()->GetPrimaryRootWindow();
404 WmWindow* target_window = root_window->GetChildren()[1]; 404 WmWindow* target_window = root_window->GetChildren()[1];
405 WmWindow* parent_window = root_window->GetChildren()[0]; 405 WmWindow* parent_window = root_window->GetChildren()[0];
406 std::unique_ptr<WindowOwner> child_owner(CreateChildWindow(parent_window)); 406 std::unique_ptr<WindowOwner> child_owner(CreateChildWindow(parent_window));
407 WmWindow* child_window = child_owner->window(); 407 WmWindow* child_window = child_owner->window();
408 408
409 // Initialize DOMAgent 409 // Initialize DOMAgent
410 std::unique_ptr<ui::devtools::protocol::DOM::Node> root; 410 std::unique_ptr<ui::devtools::protocol::DOM::Node> root;
411 dom_agent()->getDocument(&root); 411 dom_agent()->getDocument(&root);
412 DOM::Node* root_node = root->getChildren(nullptr)->get(0); 412 DOM::Node* root_node = root->getChildren(nullptr)->get(0);
413 413
(...skipping 12 matching lines...) Expand all
426 target_window->AddChild(child_window); 426 target_window->AddChild(child_window);
427 ExpectChildNodeRemoved(parent_node->getNodeId(), child_node->getNodeId()); 427 ExpectChildNodeRemoved(parent_node->getNodeId(), child_node->getNodeId());
428 ExpectChildNodeInserted(target_node->getNodeId(), sibling_node->getNodeId()); 428 ExpectChildNodeInserted(target_node->getNodeId(), sibling_node->getNodeId());
429 } 429 }
430 430
431 TEST_F(AshDevToolsTest, WindowStackingChangedChildNodeRemovedAndInserted) { 431 TEST_F(AshDevToolsTest, WindowStackingChangedChildNodeRemovedAndInserted) {
432 // Initialize DOMAgent 432 // Initialize DOMAgent
433 std::unique_ptr<ui::devtools::protocol::DOM::Node> root; 433 std::unique_ptr<ui::devtools::protocol::DOM::Node> root;
434 dom_agent()->getDocument(&root); 434 dom_agent()->getDocument(&root);
435 435
436 WmWindow* parent_window = WmShell::Get()->GetPrimaryRootWindow(); 436 WmWindow* parent_window = ShellPort::Get()->GetPrimaryRootWindow();
437 WmWindow* child_window = parent_window->GetChildren()[0]; 437 WmWindow* child_window = parent_window->GetChildren()[0];
438 WmWindow* target_window = parent_window->GetChildren()[1]; 438 WmWindow* target_window = parent_window->GetChildren()[1];
439 439
440 DOM::Node* parent_node = root->getChildren(nullptr)->get(0); 440 DOM::Node* parent_node = root->getChildren(nullptr)->get(0);
441 Array<DOM::Node>* parent_node_children = parent_node->getChildren(nullptr); 441 Array<DOM::Node>* parent_node_children = parent_node->getChildren(nullptr);
442 DOM::Node* child_node = parent_node_children->get(0); 442 DOM::Node* child_node = parent_node_children->get(0);
443 DOM::Node* sibling_node = parent_node_children->get(1); 443 DOM::Node* sibling_node = parent_node_children->get(1);
444 int parent_id = parent_node->getNodeId(); 444 int parent_id = parent_node->getNodeId();
445 445
446 Compare(parent_window, parent_node); 446 Compare(parent_window, parent_node);
(...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after
616 HideHighlight(0); 616 HideHighlight(0);
617 617
618 // Highlight non-existent node 618 // Highlight non-existent node
619 HighlightNode(10000); 619 HighlightNode(10000);
620 EXPECT_FALSE(GetHighlightingWindow(0)->IsVisible()); 620 EXPECT_FALSE(GetHighlightingWindow(0)->IsVisible());
621 } 621 }
622 622
623 TEST_F(AshDevToolsTest, MultipleDisplayHighlight) { 623 TEST_F(AshDevToolsTest, MultipleDisplayHighlight) {
624 UpdateDisplay("300x400,500x500"); 624 UpdateDisplay("300x400,500x500");
625 625
626 WmWindow::Windows root_windows = WmShell::Get()->GetAllRootWindows(); 626 WmWindow::Windows root_windows = ShellPort::Get()->GetAllRootWindows();
627 std::unique_ptr<WindowOwner> window_owner( 627 std::unique_ptr<WindowOwner> window_owner(
628 CreateTestWindow(gfx::Rect(1, 2, 30, 40))); 628 CreateTestWindow(gfx::Rect(1, 2, 30, 40)));
629 WmWindow* window = window_owner->window(); 629 WmWindow* window = window_owner->window();
630 630
631 std::unique_ptr<ui::devtools::protocol::DOM::Node> root; 631 std::unique_ptr<ui::devtools::protocol::DOM::Node> root;
632 dom_agent()->getDocument(&root); 632 dom_agent()->getDocument(&root);
633 633
634 EXPECT_EQ(root_windows[0], window->GetRootWindow()); 634 EXPECT_EQ(root_windows[0], window->GetRootWindow());
635 HighlightNode(dom_agent()->GetNodeIdFromWindow(window)); 635 HighlightNode(dom_agent()->GetNodeIdFromWindow(window));
636 ExpectHighlighted(window->GetBoundsInScreen(), 0); 636 ExpectHighlighted(window->GetBoundsInScreen(), 0);
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after
767 SetStyleTexts(root_view_node, "\nheight: 73;\n ", true); 767 SetStyleTexts(root_view_node, "\nheight: 73;\n ", true);
768 EXPECT_EQ(gfx::Rect(25, 35, 45, 73), root_view->bounds()); 768 EXPECT_EQ(gfx::Rect(25, 35, 45, 73), root_view->bounds());
769 769
770 SetStyleTexts(root_view_node, "\nx: 10; y: 23; width: 52;\nvisibility: 1;\n", 770 SetStyleTexts(root_view_node, "\nx: 10; y: 23; width: 52;\nvisibility: 1;\n",
771 true); 771 true);
772 EXPECT_EQ(gfx::Rect(10, 23, 52, 73), root_view->bounds()); 772 EXPECT_EQ(gfx::Rect(10, 23, 52, 73), root_view->bounds());
773 EXPECT_TRUE(root_view->visible()); 773 EXPECT_TRUE(root_view->visible());
774 } 774 }
775 775
776 } // namespace ash 776 } // namespace ash
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698