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

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

Issue 2865713003: Remove ash dependency. (Closed)
Patch Set: nits. Created 3 years, 7 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/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
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 =
143 Shell::GetAllRootWindows()[root_window_index] 143 root_window->GetChildById(kShellWindowId_OverlayContainer)->children();
144 ->GetChildById(kShellWindowId_OverlayContainer)
145 ->children();
146 for (aura::Window* window : overlay_windows) { 144 for (aura::Window* window : overlay_windows) {
147 if (window->GetName() == "HighlightingWidget") 145 if (window->GetName() == "HighlightingWidget")
148 return window; 146 return window;
149 } 147 }
150 NOTREACHED(); 148 NOTREACHED();
151 return nullptr; 149 return nullptr;
152 } 150 }
153 151
154 std::unique_ptr<DOM::RGBA> SkColorToRGBA(const SkColor& color) { 152 std::unique_ptr<DOM::RGBA> SkColorToRGBA(const SkColor& color) {
155 return DOM::RGBA::create() 153 return DOM::RGBA::create()
156 .setA(SkColorGetA(color) / 255) 154 .setA(SkColorGetA(color) / 255)
157 .setB(SkColorGetB(color)) 155 .setB(SkColorGetB(color))
158 .setG(SkColorGetG(color)) 156 .setG(SkColorGetG(color))
159 .setR(SkColorGetR(color)) 157 .setR(SkColorGetR(color))
160 .build(); 158 .build();
161 } 159 }
162 160
163 std::unique_ptr<DOM::HighlightConfig> CreateHighlightConfig( 161 std::unique_ptr<DOM::HighlightConfig> CreateHighlightConfig(
164 const SkColor& background_color, 162 const SkColor& background_color,
165 const SkColor& border_color) { 163 const SkColor& border_color) {
166 return DOM::HighlightConfig::create() 164 return DOM::HighlightConfig::create()
167 .setContentColor(SkColorToRGBA(background_color)) 165 .setContentColor(SkColorToRGBA(background_color))
168 .setBorderColor(SkColorToRGBA(border_color)) 166 .setBorderColor(SkColorToRGBA(border_color))
169 .build(); 167 .build();
170 } 168 }
171 169
172 void ExpectHighlighted(const gfx::Rect& bounds, int root_window_index) { 170 void ExpectHighlighted(const gfx::Rect& bounds, aura::Window* root_window) {
173 aura::Window* highlighting_window = GetHighlightingWindow(root_window_index); 171 aura::Window* highlighting_window = GetHighlightingWindow(root_window);
174 EXPECT_TRUE(highlighting_window->IsVisible()); 172 EXPECT_TRUE(highlighting_window->IsVisible());
175 EXPECT_EQ(bounds, highlighting_window->GetBoundsInScreen()); 173 EXPECT_EQ(bounds, highlighting_window->GetBoundsInScreen());
176 EXPECT_EQ(kBackgroundColor, GetInternalWidgetForWindow(highlighting_window) 174 EXPECT_EQ(kBackgroundColor, GetInternalWidgetForWindow(highlighting_window)
177 ->GetRootView() 175 ->GetRootView()
178 ->background() 176 ->background()
179 ->get_color()); 177 ->get_color());
180 } 178 }
181 179
182 aura::Window* GetPrimaryRootWindow() {
183 return Shell::Get()->GetPrimaryRootWindow();
184 }
185
186 } // namespace 180 } // namespace
187 181
188 class AshDevToolsTest : public test::AshTestBase { 182 class AshDevToolsTest : public test::AshTestBase {
189 public: 183 public:
190 AshDevToolsTest() {} 184 AshDevToolsTest() {}
191 ~AshDevToolsTest() override {} 185 ~AshDevToolsTest() override {}
192 186
193 views::internal::NativeWidgetPrivate* CreateTestNativeWidget() { 187 views::internal::NativeWidgetPrivate* CreateTestNativeWidget() {
194 views::Widget* widget = new views::Widget; 188 views::Widget* widget = new views::Widget;
195 views::Widget::InitParams params; 189 views::Widget::InitParams params;
196 params.ownership = views::Widget::InitParams::NATIVE_WIDGET_OWNS_WIDGET; 190 params.ownership = views::Widget::InitParams::NATIVE_WIDGET_OWNS_WIDGET;
197 Shell::GetPrimaryRootWindowController() 191 params.parent = nullptr;
198 ->ConfigureWidgetInitParamsForContainer( 192 if (!dom_agent()->root_windows().empty()) {
199 widget, kShellWindowId_DefaultContainer, &params); 193 params.parent = dom_agent()->root_windows()[0]->GetChildById(
194 kShellWindowId_DefaultContainer);
195 }
200 widget->Init(params); 196 widget->Init(params);
201 return widget->native_widget_private(); 197 return widget->native_widget_private();
202 } 198 }
203 199
204 std::unique_ptr<views::Widget> CreateTestWidget(const gfx::Rect& bounds) { 200 std::unique_ptr<views::Widget> CreateTestWidget(const gfx::Rect& bounds) {
205 return AshTestBase::CreateTestWidget(nullptr, kShellWindowId_Invalid, 201 return AshTestBase::CreateTestWidget(nullptr, kShellWindowId_Invalid,
206 bounds); 202 bounds);
207 } 203 }
208 204
209 void SetUp() override { 205 void SetUp() override {
210 AshTestBase::SetUp();
211 fake_frontend_channel_ = base::MakeUnique<FakeFrontendChannel>(); 206 fake_frontend_channel_ = base::MakeUnique<FakeFrontendChannel>();
212 uber_dispatcher_ = 207 uber_dispatcher_ =
213 base::MakeUnique<UberDispatcher>(fake_frontend_channel_.get()); 208 base::MakeUnique<UberDispatcher>(fake_frontend_channel_.get());
214 dom_agent_ = base::MakeUnique<devtools::AshDevToolsDOMAgent>(); 209 dom_agent_ = base::MakeUnique<devtools::AshDevToolsDOMAgent>();
215 dom_agent_->Init(uber_dispatcher_.get()); 210 dom_agent_->Init(uber_dispatcher_.get());
216 css_agent_ = 211 css_agent_ =
217 base::MakeUnique<devtools::AshDevToolsCSSAgent>(dom_agent_.get()); 212 base::MakeUnique<devtools::AshDevToolsCSSAgent>(dom_agent_.get());
218 css_agent_->Init(uber_dispatcher_.get()); 213 css_agent_->Init(uber_dispatcher_.get());
219 css_agent_->enable(); 214 css_agent_->enable();
215 AshTestBase::SetUp();
220 } 216 }
221 217
222 void TearDown() override { 218 void TearDown() override {
223 css_agent_.reset(); 219 css_agent_.reset();
224 dom_agent_.reset(); 220 dom_agent_.reset();
225 uber_dispatcher_.reset(); 221 uber_dispatcher_.reset();
226 fake_frontend_channel_.reset(); 222 fake_frontend_channel_.reset();
227 AshTestBase::TearDown(); 223 AshTestBase::TearDown();
228 } 224 }
229 225
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
280 ASSERT_FALSE(output); 276 ASSERT_FALSE(output);
281 } 277 }
282 278
283 void HighlightNode(int node_id) { 279 void HighlightNode(int node_id) {
284 dom_agent_->highlightNode( 280 dom_agent_->highlightNode(
285 CreateHighlightConfig(kBackgroundColor, kBorderColor), node_id); 281 CreateHighlightConfig(kBackgroundColor, kBorderColor), node_id);
286 } 282 }
287 283
288 void HideHighlight(int root_window_index) { 284 void HideHighlight(int root_window_index) {
289 dom_agent_->hideHighlight(); 285 dom_agent_->hideHighlight();
290 ASSERT_FALSE(GetHighlightingWindow(root_window_index)->IsVisible()); 286 ASSERT_FALSE(
287 GetHighlightingWindow(dom_agent()->root_windows()[root_window_index])
sadrul 2017/05/23 17:32:47 First assert that |root_window_index| is valid.
thanhph 2017/05/24 15:15:21 Done.
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
297 devtools::AshDevToolsCSSAgent* css_agent() { return css_agent_.get(); } 295 devtools::AshDevToolsCSSAgent* css_agent() { return css_agent_.get(); }
298 devtools::AshDevToolsDOMAgent* dom_agent() { return dom_agent_.get(); } 296 devtools::AshDevToolsDOMAgent* dom_agent() { return dom_agent_.get(); }
299 297
300 private: 298 private:
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
349 Compare(widget, widget_node); 347 Compare(widget, widget_node);
350 // Destroy NativeWidget followed by |widget| 348 // Destroy NativeWidget followed by |widget|
351 widget->CloseNow(); 349 widget->CloseNow();
352 } 350 }
353 351
354 TEST_F(AshDevToolsTest, WindowAddedChildNodeInserted) { 352 TEST_F(AshDevToolsTest, WindowAddedChildNodeInserted) {
355 // Initialize DOMAgent 353 // Initialize DOMAgent
356 std::unique_ptr<ui::devtools::protocol::DOM::Node> root; 354 std::unique_ptr<ui::devtools::protocol::DOM::Node> root;
357 dom_agent()->getDocument(&root); 355 dom_agent()->getDocument(&root);
358 356
359 aura::Window* root_window = GetPrimaryRootWindow(); 357 aura::Window* root_window = dom_agent()->root_windows()[0];
sadrul 2017/05/23 17:32:47 Can we move GetPrimaryRootWindow() as a function i
thanhph 2017/05/24 15:15:21 Done.
360 aura::Window* parent_window = root_window->children()[0]; 358 aura::Window* parent_window = root_window->children()[0];
361 DOM::Node* parent_node = FindInRoot(parent_window, root.get()); 359 DOM::Node* parent_node = FindInRoot(parent_window, root.get());
362 Array<DOM::Node>* parent_node_children = parent_node->getChildren(nullptr); 360 Array<DOM::Node>* parent_node_children = parent_node->getChildren(nullptr);
363 DOM::Node* sibling_node = 361 DOM::Node* sibling_node =
364 parent_node_children->get(parent_node_children->length() - 1); 362 parent_node_children->get(parent_node_children->length() - 1);
365 363
366 std::unique_ptr<aura::Window> child(CreateChildWindow(parent_window)); 364 std::unique_ptr<aura::Window> child(CreateChildWindow(parent_window));
367 ExpectChildNodeInserted(parent_node->getNodeId(), sibling_node->getNodeId()); 365 ExpectChildNodeInserted(parent_node->getNodeId(), sibling_node->getNodeId());
368 } 366 }
369 367
370 TEST_F(AshDevToolsTest, WindowDestroyedChildNodeRemoved) { 368 TEST_F(AshDevToolsTest, WindowDestroyedChildNodeRemoved) {
371 // Initialize DOMAgent 369 // Initialize DOMAgent
372 std::unique_ptr<ui::devtools::protocol::DOM::Node> root; 370 std::unique_ptr<ui::devtools::protocol::DOM::Node> root;
373 dom_agent()->getDocument(&root); 371 dom_agent()->getDocument(&root);
374 372
375 aura::Window* root_window = GetPrimaryRootWindow(); 373 aura::Window* root_window = dom_agent()->root_windows()[0];
376 aura::Window* rotation_window = root_window->children()[0]; 374 aura::Window* rotation_window = root_window->children()[0];
377 aura::Window* parent_window = rotation_window->children()[0]; 375 aura::Window* parent_window = rotation_window->children()[0];
378 aura::Window* child_window = parent_window->children()[0]; 376 aura::Window* child_window = parent_window->children()[0];
379 DOM::Node* root_node = 377 DOM::Node* root_node =
380 root->getChildren(nullptr)->get(0)->getChildren(nullptr)->get(0); 378 root->getChildren(nullptr)->get(0)->getChildren(nullptr)->get(0);
381 DOM::Node* parent_node = root_node->getChildren(nullptr)->get(0); 379 DOM::Node* parent_node = root_node->getChildren(nullptr)->get(0);
382 DOM::Node* child_node = parent_node->getChildren(nullptr)->get(0); 380 DOM::Node* child_node = parent_node->getChildren(nullptr)->get(0);
383 381
384 Compare(parent_window, parent_node); 382 Compare(parent_window, parent_node);
385 Compare(child_window, child_node); 383 Compare(child_window, child_node);
386 delete child_window; 384 delete child_window;
387 ExpectChildNodeRemoved(parent_node->getNodeId(), child_node->getNodeId()); 385 ExpectChildNodeRemoved(parent_node->getNodeId(), child_node->getNodeId());
388 } 386 }
389 387
390 TEST_F(AshDevToolsTest, WindowReorganizedChildNodeRearranged) { 388 TEST_F(AshDevToolsTest, WindowReorganizedChildNodeRearranged) {
391 // Initialize DOMAgent 389 // Initialize DOMAgent
392 std::unique_ptr<ui::devtools::protocol::DOM::Node> root; 390 std::unique_ptr<ui::devtools::protocol::DOM::Node> root;
393 dom_agent()->getDocument(&root); 391 dom_agent()->getDocument(&root);
394 392
395 aura::Window* root_window = GetPrimaryRootWindow(); 393 aura::Window* root_window = dom_agent()->root_windows()[0];
396 aura::Window* rotation_window = root_window->children()[0]; 394 aura::Window* rotation_window = root_window->children()[0];
397 aura::Window* parent_window = rotation_window->children()[0]; 395 aura::Window* parent_window = rotation_window->children()[0];
398 aura::Window* target_window = rotation_window->children()[1]; 396 aura::Window* target_window = rotation_window->children()[1];
399 aura::Window* child_window = parent_window->children()[0]; 397 aura::Window* child_window = parent_window->children()[0];
400 398
401 DOM::Node* root_node = 399 DOM::Node* root_node =
402 root->getChildren(nullptr)->get(0)->getChildren(nullptr)->get(0); 400 root->getChildren(nullptr)->get(0)->getChildren(nullptr)->get(0);
403 DOM::Node* parent_node = root_node->getChildren(nullptr)->get(0); 401 DOM::Node* parent_node = root_node->getChildren(nullptr)->get(0);
404 DOM::Node* target_node = root_node->getChildren(nullptr)->get(1); 402 DOM::Node* target_node = root_node->getChildren(nullptr)->get(1);
405 Array<DOM::Node>* target_node_children = target_node->getChildren(nullptr); 403 Array<DOM::Node>* target_node_children = target_node->getChildren(nullptr);
406 DOM::Node* sibling_node = 404 DOM::Node* sibling_node =
407 target_node_children->get(target_node_children->length() - 1); 405 target_node_children->get(target_node_children->length() - 1);
408 DOM::Node* child_node = parent_node->getChildren(nullptr)->get(0); 406 DOM::Node* child_node = parent_node->getChildren(nullptr)->get(0);
409 407
410 Compare(parent_window, parent_node); 408 Compare(parent_window, parent_node);
411 Compare(target_window, target_node); 409 Compare(target_window, target_node);
412 Compare(child_window, child_node); 410 Compare(child_window, child_node);
413 target_window->AddChild(child_window); 411 target_window->AddChild(child_window);
414 ExpectChildNodeRemoved(parent_node->getNodeId(), child_node->getNodeId()); 412 ExpectChildNodeRemoved(parent_node->getNodeId(), child_node->getNodeId());
415 ExpectChildNodeInserted(target_node->getNodeId(), sibling_node->getNodeId()); 413 ExpectChildNodeInserted(target_node->getNodeId(), sibling_node->getNodeId());
416 } 414 }
417 415
418 TEST_F(AshDevToolsTest, WindowReorganizedChildNodeRemovedAndInserted) { 416 TEST_F(AshDevToolsTest, WindowReorganizedChildNodeRemovedAndInserted) {
419 aura::Window* root_window = GetPrimaryRootWindow(); 417 aura::Window* root_window = dom_agent()->root_windows()[0];
420 aura::Window* rotation_window = root_window->children()[0]; 418 aura::Window* rotation_window = root_window->children()[0];
421 aura::Window* parent_window = rotation_window->children()[0]; 419 aura::Window* parent_window = rotation_window->children()[0];
422 aura::Window* target_window = rotation_window->children()[1]; 420 aura::Window* target_window = rotation_window->children()[1];
423 std::unique_ptr<aura::Window> child_window(CreateChildWindow(parent_window)); 421 std::unique_ptr<aura::Window> child_window(CreateChildWindow(parent_window));
424 422
425 // Initialize DOMAgent 423 // Initialize DOMAgent
426 std::unique_ptr<ui::devtools::protocol::DOM::Node> root; 424 std::unique_ptr<ui::devtools::protocol::DOM::Node> root;
427 dom_agent()->getDocument(&root); 425 dom_agent()->getDocument(&root);
428 DOM::Node* root_node = 426 DOM::Node* root_node =
429 root->getChildren(nullptr)->get(0)->getChildren(nullptr)->get(0); 427 root->getChildren(nullptr)->get(0)->getChildren(nullptr)->get(0);
(...skipping 13 matching lines...) Expand all
443 target_window->AddChild(child_window.get()); 441 target_window->AddChild(child_window.get());
444 ExpectChildNodeRemoved(parent_node->getNodeId(), child_node->getNodeId()); 442 ExpectChildNodeRemoved(parent_node->getNodeId(), child_node->getNodeId());
445 ExpectChildNodeInserted(target_node->getNodeId(), sibling_node->getNodeId()); 443 ExpectChildNodeInserted(target_node->getNodeId(), sibling_node->getNodeId());
446 } 444 }
447 445
448 TEST_F(AshDevToolsTest, WindowStackingChangedChildNodeRemovedAndInserted) { 446 TEST_F(AshDevToolsTest, WindowStackingChangedChildNodeRemovedAndInserted) {
449 // Initialize DOMAgent 447 // Initialize DOMAgent
450 std::unique_ptr<ui::devtools::protocol::DOM::Node> root; 448 std::unique_ptr<ui::devtools::protocol::DOM::Node> root;
451 dom_agent()->getDocument(&root); 449 dom_agent()->getDocument(&root);
452 450
453 aura::Window* root_window = GetPrimaryRootWindow(); 451 aura::Window* root_window = dom_agent()->root_windows()[0];
454 aura::Window* parent_window = root_window->children()[0]; 452 aura::Window* parent_window = root_window->children()[0];
455 aura::Window* child_window = parent_window->children()[0]; 453 aura::Window* child_window = parent_window->children()[0];
456 aura::Window* target_window = parent_window->children()[1]; 454 aura::Window* target_window = parent_window->children()[1];
457 455
458 DOM::Node* parent_node = 456 DOM::Node* parent_node =
459 root->getChildren(nullptr)->get(0)->getChildren(nullptr)->get(0); 457 root->getChildren(nullptr)->get(0)->getChildren(nullptr)->get(0);
460 Array<DOM::Node>* parent_node_children = parent_node->getChildren(nullptr); 458 Array<DOM::Node>* parent_node_children = parent_node->getChildren(nullptr);
461 DOM::Node* child_node = parent_node_children->get(0); 459 DOM::Node* child_node = parent_node_children->get(0);
462 DOM::Node* sibling_node = parent_node_children->get(1); 460 DOM::Node* sibling_node = parent_node_children->get(1);
463 int parent_id = parent_node->getNodeId(); 461 int parent_id = parent_node->getNodeId();
(...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after
627 625
628 DOM::Node* parent_node = FindInRoot(parent_window, root.get()); 626 DOM::Node* parent_node = FindInRoot(parent_window, root.get());
629 ASSERT_TRUE(parent_node); 627 ASSERT_TRUE(parent_node);
630 Array<DOM::Node>* parent_children = parent_node->getChildren(nullptr); 628 Array<DOM::Node>* parent_children = parent_node->getChildren(nullptr);
631 ASSERT_TRUE(parent_children); 629 ASSERT_TRUE(parent_children);
632 DOM::Node* window_node = parent_children->get(1); 630 DOM::Node* window_node = parent_children->get(1);
633 DOM::Node* widget_node = parent_children->get(0); 631 DOM::Node* widget_node = parent_children->get(0);
634 DOM::Node* root_view_node = widget_node->getChildren(nullptr)->get(0); 632 DOM::Node* root_view_node = widget_node->getChildren(nullptr)->get(0);
635 633
636 HighlightNode(window_node->getNodeId()); 634 HighlightNode(window_node->getNodeId());
637 ExpectHighlighted(window->GetBoundsInScreen(), 0); 635 ExpectHighlighted(window->GetBoundsInScreen(),
636 dom_agent()->root_windows()[0]);
638 637
639 HideHighlight(0); 638 HideHighlight(0);
640 639
641 HighlightNode(widget_node->getNodeId()); 640 HighlightNode(widget_node->getNodeId());
642 ExpectHighlighted(widget->GetWindowBoundsInScreen(), 0); 641 ExpectHighlighted(widget->GetWindowBoundsInScreen(),
642 dom_agent()->root_windows()[0]);
643 643
644 HideHighlight(0); 644 HideHighlight(0);
645 645
646 HighlightNode(root_view_node->getNodeId()); 646 HighlightNode(root_view_node->getNodeId());
647 ExpectHighlighted(root_view->GetBoundsInScreen(), 0); 647 ExpectHighlighted(root_view->GetBoundsInScreen(),
648 dom_agent()->root_windows()[0]);
648 649
649 HideHighlight(0); 650 HideHighlight(0);
650 651
651 // Highlight non-existent node 652 // Highlight non-existent node
652 HighlightNode(10000); 653 HighlightNode(10000);
653 EXPECT_FALSE(GetHighlightingWindow(0)->IsVisible()); 654 EXPECT_FALSE(
655 GetHighlightingWindow(dom_agent()->root_windows()[0])->IsVisible());
654 } 656 }
655 657
656 int GetNodeIdFromWindow(devtools::UIElement* ui_element, aura::Window* window) { 658 int GetNodeIdFromWindow(devtools::UIElement* ui_element, aura::Window* window) {
657 for (auto* child : ui_element->children()) { 659 for (auto* child : ui_element->children()) {
658 if (child->type() == devtools::UIElementType::WINDOW && 660 if (child->type() == devtools::UIElementType::WINDOW &&
659 static_cast<devtools::WindowElement*>(child)->window() == window) { 661 static_cast<devtools::WindowElement*>(child)->window() == window) {
660 return child->node_id(); 662 return child->node_id();
661 } 663 }
662 } 664 }
663 for (auto* child : ui_element->children()) { 665 for (auto* child : ui_element->children()) {
664 if (child->type() == devtools::UIElementType::WINDOW) { 666 if (child->type() == devtools::UIElementType::WINDOW) {
665 int node_id = GetNodeIdFromWindow(child, window); 667 int node_id = GetNodeIdFromWindow(child, window);
666 if (node_id > 0) 668 if (node_id > 0)
667 return node_id; 669 return node_id;
668 } 670 }
669 } 671 }
670 return 0; 672 return 0;
671 } 673 }
672 674
673 TEST_F(AshDevToolsTest, MultipleDisplayHighlight) { 675 TEST_F(AshDevToolsTest, MultipleDisplayHighlight) {
674 UpdateDisplay("300x400,500x500"); 676 UpdateDisplay("300x400,500x500");
675 677
676 aura::Window::Windows root_windows = Shell::GetAllRootWindows(); 678 aura::Window::Windows root_windows = dom_agent()->root_windows();
sadrul 2017/05/23 17:32:47 const auto& root_windows = dom_agent()->root_windo
thanhph 2017/05/24 15:15:21 I removed this test for now as we discussed. Added
677 std::unique_ptr<aura::Window> window( 679 std::unique_ptr<aura::Window> window(
678 CreateTestWindowInShellWithBounds(gfx::Rect(1, 2, 30, 40))); 680 CreateTestWindowInShellWithBounds(gfx::Rect(1, 2, 30, 40)));
679 681
680 std::unique_ptr<ui::devtools::protocol::DOM::Node> root; 682 std::unique_ptr<ui::devtools::protocol::DOM::Node> root;
681 dom_agent()->getDocument(&root); 683 dom_agent()->getDocument(&root);
682 684
683 EXPECT_EQ(root_windows[0], window->GetRootWindow()); 685 EXPECT_EQ(root_windows[0], window->GetRootWindow());
684 HighlightNode( 686 HighlightNode(
685 GetNodeIdFromWindow(dom_agent()->window_element_root(), window.get())); 687 GetNodeIdFromWindow(dom_agent()->window_element_root(), window.get()));
686 ExpectHighlighted(window->GetBoundsInScreen(), 0); 688 ExpectHighlighted(window->GetBoundsInScreen(),
689 dom_agent()->root_windows()[0]);
687 690
688 window->SetBoundsInScreen(gfx::Rect(500, 0, 50, 50), GetSecondaryDisplay()); 691 window->SetBoundsInScreen(gfx::Rect(500, 0, 50, 50), GetSecondaryDisplay());
689 EXPECT_EQ(root_windows[1], window->GetRootWindow()); 692 EXPECT_EQ(root_windows[1], window->GetRootWindow());
690 HighlightNode( 693 HighlightNode(
691 GetNodeIdFromWindow(dom_agent()->window_element_root(), window.get())); 694 GetNodeIdFromWindow(dom_agent()->window_element_root(), window.get()));
692 ExpectHighlighted(window->GetBoundsInScreen(), 1); 695 ExpectHighlighted(window->GetBoundsInScreen(),
696 dom_agent()->root_windows()[1]);
693 } 697 }
694 698
695 TEST_F(AshDevToolsTest, WindowWidgetViewGetMatchedStylesForNode) { 699 TEST_F(AshDevToolsTest, WindowWidgetViewGetMatchedStylesForNode) {
696 std::unique_ptr<views::Widget> widget( 700 std::unique_ptr<views::Widget> widget(
697 CreateTestWidget(gfx::Rect(1, 1, 1, 1))); 701 CreateTestWidget(gfx::Rect(1, 1, 1, 1)));
698 aura::Window* parent_window = widget->GetNativeWindow(); 702 aura::Window* parent_window = widget->GetNativeWindow();
699 std::unique_ptr<aura::Window> window(CreateChildWindow(parent_window)); 703 std::unique_ptr<aura::Window> window(CreateChildWindow(parent_window));
700 gfx::Rect window_bounds(2, 2, 3, 3); 704 gfx::Rect window_bounds(2, 2, 3, 3);
701 gfx::Rect widget_bounds(50, 50, 100, 75); 705 gfx::Rect widget_bounds(50, 50, 100, 75);
702 gfx::Rect view_bounds(4, 4, 3, 3); 706 gfx::Rect view_bounds(4, 4, 3, 3);
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after
815 SetStyleTexts(root_view_node, "\nheight: 73;\n ", true); 819 SetStyleTexts(root_view_node, "\nheight: 73;\n ", true);
816 EXPECT_EQ(gfx::Rect(25, 35, 45, 73), root_view->bounds()); 820 EXPECT_EQ(gfx::Rect(25, 35, 45, 73), root_view->bounds());
817 821
818 SetStyleTexts(root_view_node, "\nx: 10; y: 23; width: 52;\nvisibility: 1;\n", 822 SetStyleTexts(root_view_node, "\nx: 10; y: 23; width: 52;\nvisibility: 1;\n",
819 true); 823 true);
820 EXPECT_EQ(gfx::Rect(10, 23, 52, 73), root_view->bounds()); 824 EXPECT_EQ(gfx::Rect(10, 23, 52, 73), root_view->bounds());
821 EXPECT_TRUE(root_view->visible()); 825 EXPECT_TRUE(root_view->visible());
822 } 826 }
823 827
824 } // namespace ash 828 } // namespace ash
OLDNEW
« ash/devtools/ash_devtools_dom_agent.cc ('K') | « ash/devtools/ash_devtools_dom_agent.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698