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

Side by Side Diff: components/ui_devtools/devtools/ui_devtools_unittest.cc

Issue 2852733002: Duplicate -Move DevTools out of ash and turn it to a component. (Closed)
Patch Set: move unittest to ui/views 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"
6 #include "ash/devtools/ash_devtools_dom_agent.h"
7 #include "ash/devtools/ui_element.h"
8 #include "ash/devtools/window_element.h"
9 #include "ash/public/cpp/shell_window_ids.h" 5 #include "ash/public/cpp/shell_window_ids.h"
10 #include "ash/shell.h"
11 #include "ash/test/ash_test_base.h"
12 #include "ash/wm/widget_finder.h"
13 #include "base/memory/ptr_util.h" 6 #include "base/memory/ptr_util.h"
14 #include "base/strings/stringprintf.h" 7 #include "base/strings/stringprintf.h"
8 #include "components/ui_devtools/devtools/ui_devtools_css_agent.h"
9 #include "components/ui_devtools/devtools/ui_devtools_dom_agent.h"
10 #include "components/ui_devtools/devtools/ui_element.h"
11 #include "components/ui_devtools/devtools/window_element.h"
15 #include "ui/aura/window_tree_host.h" 12 #include "ui/aura/window_tree_host.h"
16 #include "ui/display/display.h" 13 #include "ui/display/display.h"
17 #include "ui/views/background.h" 14 #include "ui/views/background.h"
15 #include "ui/views/test/views_test_base.h"
18 #include "ui/views/widget/native_widget_private.h" 16 #include "ui/views/widget/native_widget_private.h"
19 #include "ui/views/widget/widget.h" 17 #include "ui/views/widget/widget.h"
20 18
21 namespace ash { 19 namespace ui {
22 namespace { 20 namespace {
23 21
24 using namespace ui::devtools::protocol; 22 using namespace ui::devtools::protocol;
25 23
26 const int kDefaultChildNodeCount = -1; 24 const int kDefaultChildNodeCount = -1;
27 const SkColor kBackgroundColor = SK_ColorRED; 25 const SkColor kBackgroundColor = SK_ColorRED;
28 const SkColor kBorderColor = SK_ColorBLUE; 26 const SkColor kBorderColor = SK_ColorBLUE;
29 27
30 class TestView : public views::View { 28 class TestView : public views::View {
31 public: 29 public:
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
78 Array<std::string>* attributes = node->getAttributes(nullptr); 76 Array<std::string>* attributes = node->getAttributes(nullptr);
79 for (size_t i = 0; i < attributes->length() - 1; i++) { 77 for (size_t i = 0; i < attributes->length() - 1; i++) {
80 if (attributes->get(i) == attribute) 78 if (attributes->get(i) == attribute)
81 return attributes->get(i + 1); 79 return attributes->get(i + 1);
82 } 80 }
83 return nullptr; 81 return nullptr;
84 } 82 }
85 83
86 bool Equals(aura::Window* window, DOM::Node* node) { 84 bool Equals(aura::Window* window, DOM::Node* node) {
87 int children_count = static_cast<int>(window->children().size()); 85 int children_count = static_cast<int>(window->children().size());
88 if (GetInternalWidgetForWindow(window)) 86 if (views::Widget::GetWidgetForNativeView(window))
89 children_count++; 87 children_count++;
90 return "Window" == node->getNodeName() && 88 return "Window" == node->getNodeName() &&
91 window->GetName() == GetAttributeValue("name", node) && 89 window->GetName() == GetAttributeValue("name", node) &&
92 children_count == node->getChildNodeCount(kDefaultChildNodeCount); 90 children_count == node->getChildNodeCount(kDefaultChildNodeCount);
93 } 91 }
94 92
95 void Compare(views::Widget* widget, DOM::Node* node) { 93 void Compare(views::Widget* widget, DOM::Node* node) {
96 EXPECT_EQ("Widget", node->getNodeName()); 94 EXPECT_EQ("Widget", node->getNodeName());
97 EXPECT_EQ(widget->GetName(), GetAttributeValue("name", node)); 95 EXPECT_EQ(widget->GetName(), GetAttributeValue("name", node));
98 EXPECT_EQ(widget->GetRootView() ? 1 : 0, 96 EXPECT_EQ(widget->GetRootView() ? 1 : 0,
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
133 EXPECT_TRUE(base::StringToInt(property->getValue(), &value)); 131 EXPECT_TRUE(base::StringToInt(property->getValue(), &value));
134 return value; 132 return value;
135 } 133 }
136 } 134 }
137 NOTREACHED(); 135 NOTREACHED();
138 return -1; 136 return -1;
139 } 137 }
140 138
141 aura::Window* GetHighlightingWindow(aura::Window* root_window) { 139 aura::Window* GetHighlightingWindow(aura::Window* root_window) {
142 const aura::Window::Windows& overlay_windows = 140 const aura::Window::Windows& overlay_windows =
143 root_window->GetChildById(kShellWindowId_OverlayContainer)->children(); 141 root_window->GetChildById(ash::kShellWindowId_OverlayContainer)
142 ->children();
144 for (aura::Window* window : overlay_windows) { 143 for (aura::Window* window : overlay_windows) {
145 if (window->GetName() == "HighlightingWidget") 144 if (window->GetName() == "HighlightingWidget")
146 return window; 145 return window;
147 } 146 }
148 NOTREACHED(); 147 NOTREACHED();
149 return nullptr; 148 return nullptr;
150 } 149 }
151 150
152 std::unique_ptr<DOM::RGBA> SkColorToRGBA(const SkColor& color) { 151 std::unique_ptr<DOM::RGBA> SkColorToRGBA(const SkColor& color) {
153 return DOM::RGBA::create() 152 return DOM::RGBA::create()
(...skipping 10 matching lines...) Expand all
164 return DOM::HighlightConfig::create() 163 return DOM::HighlightConfig::create()
165 .setContentColor(SkColorToRGBA(background_color)) 164 .setContentColor(SkColorToRGBA(background_color))
166 .setBorderColor(SkColorToRGBA(border_color)) 165 .setBorderColor(SkColorToRGBA(border_color))
167 .build(); 166 .build();
168 } 167 }
169 168
170 void ExpectHighlighted(const gfx::Rect& bounds, aura::Window* root_window) { 169 void ExpectHighlighted(const gfx::Rect& bounds, aura::Window* root_window) {
171 aura::Window* highlighting_window = GetHighlightingWindow(root_window); 170 aura::Window* highlighting_window = GetHighlightingWindow(root_window);
172 EXPECT_TRUE(highlighting_window->IsVisible()); 171 EXPECT_TRUE(highlighting_window->IsVisible());
173 EXPECT_EQ(bounds, highlighting_window->GetBoundsInScreen()); 172 EXPECT_EQ(bounds, highlighting_window->GetBoundsInScreen());
174 EXPECT_EQ(kBackgroundColor, GetInternalWidgetForWindow(highlighting_window) 173 views::Widget* widget =
175 ->GetRootView() 174 views::Widget::GetWidgetForNativeView(highlighting_window);
176 ->background() 175
177 ->get_color()); 176 EXPECT_EQ(kBackgroundColor, widget->GetRootView()->background()->get_color());
178 } 177 }
179 178
180 } // namespace 179 } // namespace
181 180
182 class AshDevToolsTest : public test::AshTestBase { 181 class UIDevToolsTest : public views::ViewsTestBase {
183 public: 182 public:
184 AshDevToolsTest() {} 183 UIDevToolsTest() {}
185 ~AshDevToolsTest() override {} 184 ~UIDevToolsTest() override {}
186 185
187 views::internal::NativeWidgetPrivate* CreateTestNativeWidget() { 186 views::internal::NativeWidgetPrivate* CreateTestNativeWidget() {
188 views::Widget* widget = new views::Widget; 187 views::Widget* widget = new views::Widget;
189 views::Widget::InitParams params; 188 views::Widget::InitParams params;
190 params.ownership = views::Widget::InitParams::NATIVE_WIDGET_OWNS_WIDGET; 189 params.ownership = views::Widget::InitParams::NATIVE_WIDGET_OWNS_WIDGET;
191 params.parent = nullptr; 190 params.parent = nullptr;
192 if (!dom_agent()->root_windows().empty()) { 191 if (!dom_agent()->root_windows().empty()) {
193 params.parent = dom_agent()->root_windows()[0]->GetChildById( 192 params.parent = dom_agent()->root_windows()[0]->GetChildById(
194 kShellWindowId_DefaultContainer); 193 ash::kShellWindowId_DefaultContainer);
195 } 194 }
196 widget->Init(params); 195 widget->Init(params);
197 return widget->native_widget_private(); 196 return widget->native_widget_private();
198 } 197 }
199 198
200 std::unique_ptr<views::Widget> CreateTestWidget(const gfx::Rect& bounds) { 199 std::unique_ptr<views::Widget> CreateTestWidget(
201 return AshTestBase::CreateTestWidget(nullptr, kShellWindowId_Invalid, 200 const gfx::Rect& bounds,
202 bounds); 201 aura::Window* parent = nullptr) {
202 std::unique_ptr<views::Widget> widget(new views::Widget);
203 views::Widget::InitParams params;
204 params.delegate = nullptr;
205 params.ownership = views::Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET;
206 params.bounds = bounds;
207
208 params.parent = parent;
209 if (!parent && !dom_agent()->root_windows().empty()) {
210 params.parent = dom_agent()->root_windows()[0]->GetChildById(
211 ash::kShellWindowId_Invalid);
212 }
213 widget->Init(params);
214 widget->Show();
215 return widget;
216 }
217
218 std::unique_ptr<aura::Window> CreateChildWindow(
219 aura::Window* parent,
220 int id = ash::kShellWindowId_Invalid,
221 ui::wm::WindowType type = ui::wm::WINDOW_TYPE_NORMAL) {
222 std::unique_ptr<aura::Window> window =
223 base::MakeUnique<aura::Window>(nullptr, type);
224 window->Init(ui::LAYER_NOT_DRAWN);
225 window->SetBounds(gfx::Rect());
226 window->set_id(id);
227 parent->AddChild(window.get());
228 window->Show();
229 return window;
203 } 230 }
204 231
205 void SetUp() override { 232 void SetUp() override {
206 fake_frontend_channel_ = base::MakeUnique<FakeFrontendChannel>(); 233 fake_frontend_channel_ = base::MakeUnique<FakeFrontendChannel>();
207 uber_dispatcher_ = 234 uber_dispatcher_ =
208 base::MakeUnique<UberDispatcher>(fake_frontend_channel_.get()); 235 base::MakeUnique<UberDispatcher>(fake_frontend_channel_.get());
209 dom_agent_ = base::MakeUnique<devtools::AshDevToolsDOMAgent>(); 236 dom_agent_ = base::MakeUnique<devtools::UIDevToolsDOMAgent>();
210 dom_agent_->Init(uber_dispatcher_.get()); 237 dom_agent_->Init(uber_dispatcher_.get());
211 css_agent_ = 238 css_agent_ =
212 base::MakeUnique<devtools::AshDevToolsCSSAgent>(dom_agent_.get()); 239 base::MakeUnique<devtools::UIDevToolsCSSAgent>(dom_agent_.get());
213 css_agent_->Init(uber_dispatcher_.get()); 240 css_agent_->Init(uber_dispatcher_.get());
214 css_agent_->enable(); 241 css_agent_->enable();
215 AshTestBase::SetUp(); 242 views::ViewsTestBase::SetUp();
243 top_window = CreateChildWindow(dom_agent()->root_windows()[0]);
244 top_default_container_window = CreateChildWindow(
245 dom_agent()->root_windows()[0], ash::kShellWindowId_DefaultContainer);
246 top_overlay_window = CreateChildWindow(dom_agent()->root_windows()[0],
247 ash::kShellWindowId_OverlayContainer,
248 ui::wm::WINDOW_TYPE_UNKNOWN);
216 } 249 }
217 250
218 void TearDown() override { 251 void TearDown() override {
252 top_overlay_window.reset();
253 top_default_container_window.reset();
254 top_window.reset();
219 css_agent_.reset(); 255 css_agent_.reset();
220 dom_agent_.reset(); 256 dom_agent_.reset();
221 uber_dispatcher_.reset(); 257 uber_dispatcher_.reset();
222 fake_frontend_channel_.reset(); 258 fake_frontend_channel_.reset();
223 AshTestBase::TearDown(); 259 views::ViewsTestBase::TearDown();
224 } 260 }
225 261
226 void ExpectChildNodeInserted(int parent_id, int prev_sibling_id) { 262 void ExpectChildNodeInserted(int parent_id, int prev_sibling_id) {
227 EXPECT_EQ(1, frontend_channel()->CountProtocolNotificationMessageStartsWith( 263 EXPECT_EQ(1, frontend_channel()->CountProtocolNotificationMessageStartsWith(
228 base::StringPrintf("{\"method\":\"DOM.childNodeInserted\"," 264 base::StringPrintf("{\"method\":\"DOM.childNodeInserted\","
229 "\"params\":{\"parentNodeId\":%d," 265 "\"params\":{\"parentNodeId\":%d,"
230 "\"previousNodeId\":%d", 266 "\"previousNodeId\":%d",
231 parent_id, prev_sibling_id))); 267 parent_id, prev_sibling_id)));
232 } 268 }
233 269
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
285 dom_agent_->hideHighlight(); 321 dom_agent_->hideHighlight();
286 ASSERT_FALSE( 322 ASSERT_FALSE(
287 GetHighlightingWindow(dom_agent()->root_windows()[root_window_index]) 323 GetHighlightingWindow(dom_agent()->root_windows()[root_window_index])
288 ->IsVisible()); 324 ->IsVisible());
289 } 325 }
290 326
291 FakeFrontendChannel* frontend_channel() { 327 FakeFrontendChannel* frontend_channel() {
292 return fake_frontend_channel_.get(); 328 return fake_frontend_channel_.get();
293 } 329 }
294 330
295 devtools::AshDevToolsCSSAgent* css_agent() { return css_agent_.get(); } 331 devtools::UIDevToolsCSSAgent* css_agent() { return css_agent_.get(); }
296 devtools::AshDevToolsDOMAgent* dom_agent() { return dom_agent_.get(); } 332 devtools::UIDevToolsDOMAgent* dom_agent() { return dom_agent_.get(); }
333
334 std::unique_ptr<aura::Window> top_overlay_window;
335 std::unique_ptr<aura::Window> top_window;
336 std::unique_ptr<aura::Window> top_default_container_window;
297 337
298 private: 338 private:
299 std::unique_ptr<UberDispatcher> uber_dispatcher_; 339 std::unique_ptr<UberDispatcher> uber_dispatcher_;
300 std::unique_ptr<FakeFrontendChannel> fake_frontend_channel_; 340 std::unique_ptr<FakeFrontendChannel> fake_frontend_channel_;
301 std::unique_ptr<devtools::AshDevToolsDOMAgent> dom_agent_; 341 std::unique_ptr<devtools::UIDevToolsDOMAgent> dom_agent_;
302 std::unique_ptr<devtools::AshDevToolsCSSAgent> css_agent_; 342 std::unique_ptr<devtools::UIDevToolsCSSAgent> css_agent_;
303 343
304 DISALLOW_COPY_AND_ASSIGN(AshDevToolsTest); 344 DISALLOW_COPY_AND_ASSIGN(UIDevToolsTest);
305 }; 345 };
306 346
307 TEST_F(AshDevToolsTest, GetDocumentWithWindowWidgetView) { 347 TEST_F(UIDevToolsTest, GetDocumentWithWindowWidgetView) {
308 std::unique_ptr<views::Widget> widget( 348 std::unique_ptr<views::Widget> widget(
309 CreateTestWidget(gfx::Rect(1, 1, 1, 1))); 349 CreateTestWidget(gfx::Rect(1, 1, 1, 1)));
310 aura::Window* parent_window = widget->GetNativeWindow(); 350 aura::Window* parent_window = widget->GetNativeWindow();
311 parent_window->SetName("parent_window"); 351 parent_window->SetName("parent_window");
312 std::unique_ptr<aura::Window> child_window = CreateChildWindow(parent_window); 352 std::unique_ptr<aura::Window> child_window = CreateChildWindow(parent_window);
313 child_window->SetName("child_window"); 353 child_window->SetName("child_window");
314 widget->Show(); 354 widget->Show();
315 views::View* child_view = new TestView("child_view"); 355 views::View* child_view = new TestView("child_view");
316 widget->GetRootView()->AddChildView(child_view); 356 widget->GetRootView()->AddChildView(child_view);
317 357
318 std::unique_ptr<ui::devtools::protocol::DOM::Node> root; 358 std::unique_ptr<ui::devtools::protocol::DOM::Node> root;
319 dom_agent()->getDocument(&root); 359 dom_agent()->getDocument(&root);
320 360
321 DOM::Node* parent_node = FindInRoot(parent_window, root.get()); 361 DOM::Node* parent_node = FindInRoot(parent_window, root.get());
322 ASSERT_TRUE(parent_node); 362 ASSERT_TRUE(parent_node);
323 Array<DOM::Node>* parent_children = parent_node->getChildren(nullptr); 363 Array<DOM::Node>* parent_children = parent_node->getChildren(nullptr);
324 ASSERT_TRUE(parent_children); 364 ASSERT_TRUE(parent_children);
325 DOM::Node* widget_node = parent_children->get(0); 365 DOM::Node* widget_node = parent_children->get(0);
326 Compare(widget.get(), widget_node); 366 Compare(widget.get(), widget_node);
327 Compare(child_window.get(), parent_children->get(1)); 367 Compare(child_window.get(), parent_children->get(1));
328 Array<DOM::Node>* widget_children = widget_node->getChildren(nullptr); 368 Array<DOM::Node>* widget_children = widget_node->getChildren(nullptr);
329 ASSERT_TRUE(widget_children); 369 ASSERT_TRUE(widget_children);
330 Compare(widget->GetRootView(), widget_children->get(0)); 370 Compare(widget->GetRootView(), widget_children->get(0));
331 ASSERT_TRUE(widget_children->get(0)->getChildren(nullptr)); 371 ASSERT_TRUE(widget_children->get(0)->getChildren(nullptr));
332 Compare(child_view, widget_children->get(0)->getChildren(nullptr)->get(1)); 372 Compare(child_view, widget_children->get(0)->getChildren(nullptr)->get(1));
333 } 373 }
334 374
335 TEST_F(AshDevToolsTest, GetDocumentNativeWidgetOwnsWidget) { 375 TEST_F(UIDevToolsTest, GetDocumentNativeWidgetOwnsWidget) {
336 views::internal::NativeWidgetPrivate* native_widget_private = 376 views::internal::NativeWidgetPrivate* native_widget_private =
337 CreateTestNativeWidget(); 377 CreateTestNativeWidget();
338 views::Widget* widget = native_widget_private->GetWidget(); 378 views::Widget* widget = native_widget_private->GetWidget();
339 aura::Window* parent_window = widget->GetNativeWindow(); 379 aura::Window* parent_window = widget->GetNativeWindow();
340 380
341 std::unique_ptr<ui::devtools::protocol::DOM::Node> root; 381 std::unique_ptr<ui::devtools::protocol::DOM::Node> root;
342 dom_agent()->getDocument(&root); 382 dom_agent()->getDocument(&root);
343 383
344 DOM::Node* parent_node = FindInRoot(parent_window, root.get()); 384 DOM::Node* parent_node = FindInRoot(parent_window, root.get());
345 ASSERT_TRUE(parent_node); 385 ASSERT_TRUE(parent_node);
346 DOM::Node* widget_node = parent_node->getChildren(nullptr)->get(0); 386 DOM::Node* widget_node = parent_node->getChildren(nullptr)->get(0);
347 Compare(widget, widget_node); 387 Compare(widget, widget_node);
348 // Destroy NativeWidget followed by |widget| 388 // Destroy NativeWidget followed by |widget|
349 widget->CloseNow(); 389 widget->CloseNow();
350 } 390 }
351 391
352 TEST_F(AshDevToolsTest, WindowAddedChildNodeInserted) { 392 TEST_F(UIDevToolsTest, WindowAddedChildNodeInserted) {
353 // Initialize DOMAgent 393 // Initialize DOMAgent
394 std::unique_ptr<aura::Window> top_invalid_window_child =
395 CreateChildWindow(top_window.get());
396
354 std::unique_ptr<ui::devtools::protocol::DOM::Node> root; 397 std::unique_ptr<ui::devtools::protocol::DOM::Node> root;
355 dom_agent()->getDocument(&root); 398 dom_agent()->getDocument(&root);
356
357 aura::Window* root_window = dom_agent()->root_windows()[0]; 399 aura::Window* root_window = dom_agent()->root_windows()[0];
358 aura::Window* parent_window = root_window->children()[0]; 400 aura::Window* parent_window = root_window->children()[0];
359 DOM::Node* parent_node = FindInRoot(parent_window, root.get()); 401 DOM::Node* parent_node = FindInRoot(parent_window, root.get());
360 Array<DOM::Node>* parent_node_children = parent_node->getChildren(nullptr); 402 Array<DOM::Node>* parent_node_children = parent_node->getChildren(nullptr);
361 DOM::Node* sibling_node = 403 DOM::Node* sibling_node =
362 parent_node_children->get(parent_node_children->length() - 1); 404 parent_node_children->get(parent_node_children->length() - 1);
363 405
364 std::unique_ptr<aura::Window> child(CreateChildWindow(parent_window)); 406 std::unique_ptr<aura::Window> child(CreateChildWindow(parent_window));
365 ExpectChildNodeInserted(parent_node->getNodeId(), sibling_node->getNodeId()); 407 ExpectChildNodeInserted(parent_node->getNodeId(), sibling_node->getNodeId());
408 top_invalid_window_child.reset();
366 } 409 }
367 410
368 TEST_F(AshDevToolsTest, WindowDestroyedChildNodeRemoved) { 411 TEST_F(UIDevToolsTest, WindowDestroyedChildNodeRemoved) {
412 std::unique_ptr<aura::Window> child_1 = CreateChildWindow(top_window.get());
413 std::unique_ptr<aura::Window> child_2 = CreateChildWindow(child_1.get());
414
369 // Initialize DOMAgent 415 // Initialize DOMAgent
370 std::unique_ptr<ui::devtools::protocol::DOM::Node> root; 416 std::unique_ptr<ui::devtools::protocol::DOM::Node> root;
371 dom_agent()->getDocument(&root); 417 dom_agent()->getDocument(&root);
372 418
373 aura::Window* root_window = dom_agent()->root_windows()[0]; 419 aura::Window* root_window = dom_agent()->root_windows()[0];
374 aura::Window* rotation_window = root_window->children()[0]; 420 aura::Window* rotation_window = root_window->children()[0];
375 aura::Window* parent_window = rotation_window->children()[0]; 421 aura::Window* parent_window = rotation_window->children()[0];
376 aura::Window* child_window = parent_window->children()[0]; 422 aura::Window* child_window = parent_window->children()[0];
377 DOM::Node* root_node = 423 DOM::Node* root_node =
378 root->getChildren(nullptr)->get(0)->getChildren(nullptr)->get(0); 424 root->getChildren(nullptr)->get(0)->getChildren(nullptr)->get(0);
379 DOM::Node* parent_node = root_node->getChildren(nullptr)->get(0); 425 DOM::Node* parent_node = root_node->getChildren(nullptr)->get(0);
380 DOM::Node* child_node = parent_node->getChildren(nullptr)->get(0); 426 DOM::Node* child_node = parent_node->getChildren(nullptr)->get(0);
381 427
382 Compare(parent_window, parent_node); 428 Compare(parent_window, parent_node);
383 Compare(child_window, child_node); 429 Compare(child_window, child_node);
384 delete child_window; 430 child_2.reset();
385 ExpectChildNodeRemoved(parent_node->getNodeId(), child_node->getNodeId()); 431 ExpectChildNodeRemoved(parent_node->getNodeId(), child_node->getNodeId());
432 child_1.reset();
386 } 433 }
387 434
388 TEST_F(AshDevToolsTest, WindowReorganizedChildNodeRearranged) { 435 TEST_F(UIDevToolsTest, WindowReorganizedChildNodeRearranged) {
436 std::unique_ptr<aura::Window> child_1 = CreateChildWindow(top_window.get());
437 std::unique_ptr<aura::Window> child_2 = CreateChildWindow(top_window.get());
438 std::unique_ptr<aura::Window> child_11 = CreateChildWindow(child_1.get());
439 std::unique_ptr<aura::Window> child_21 = CreateChildWindow(child_2.get());
389 // Initialize DOMAgent 440 // Initialize DOMAgent
390 std::unique_ptr<ui::devtools::protocol::DOM::Node> root; 441 std::unique_ptr<ui::devtools::protocol::DOM::Node> root;
391 dom_agent()->getDocument(&root); 442 dom_agent()->getDocument(&root);
392
393 aura::Window* root_window = dom_agent()->root_windows()[0]; 443 aura::Window* root_window = dom_agent()->root_windows()[0];
394 aura::Window* rotation_window = root_window->children()[0]; 444 aura::Window* rotation_window = root_window->children()[0];
395 aura::Window* parent_window = rotation_window->children()[0]; 445 aura::Window* parent_window = rotation_window->children()[0];
396 aura::Window* target_window = rotation_window->children()[1]; 446 aura::Window* target_window = rotation_window->children()[1];
397 aura::Window* child_window = parent_window->children()[0]; 447 aura::Window* child_window = parent_window->children()[0];
398 448
399 DOM::Node* root_node = 449 DOM::Node* root_node =
400 root->getChildren(nullptr)->get(0)->getChildren(nullptr)->get(0); 450 root->getChildren(nullptr)->get(0)->getChildren(nullptr)->get(0);
401 DOM::Node* parent_node = root_node->getChildren(nullptr)->get(0); 451 DOM::Node* parent_node = root_node->getChildren(nullptr)->get(0);
402 DOM::Node* target_node = root_node->getChildren(nullptr)->get(1); 452 DOM::Node* target_node = root_node->getChildren(nullptr)->get(1);
403 Array<DOM::Node>* target_node_children = target_node->getChildren(nullptr); 453 Array<DOM::Node>* target_node_children = target_node->getChildren(nullptr);
404 DOM::Node* sibling_node = 454 DOM::Node* sibling_node =
405 target_node_children->get(target_node_children->length() - 1); 455 target_node_children->get(target_node_children->length() - 1);
406 DOM::Node* child_node = parent_node->getChildren(nullptr)->get(0); 456 DOM::Node* child_node = parent_node->getChildren(nullptr)->get(0);
407 457
408 Compare(parent_window, parent_node); 458 Compare(parent_window, parent_node);
409 Compare(target_window, target_node); 459 Compare(target_window, target_node);
410 Compare(child_window, child_node); 460 Compare(child_window, child_node);
411 target_window->AddChild(child_window); 461 target_window->AddChild(child_window);
412 ExpectChildNodeRemoved(parent_node->getNodeId(), child_node->getNodeId()); 462 ExpectChildNodeRemoved(parent_node->getNodeId(), child_node->getNodeId());
413 ExpectChildNodeInserted(target_node->getNodeId(), sibling_node->getNodeId()); 463 ExpectChildNodeInserted(target_node->getNodeId(), sibling_node->getNodeId());
414 } 464 }
415 465
416 TEST_F(AshDevToolsTest, WindowReorganizedChildNodeRemovedAndInserted) { 466 TEST_F(UIDevToolsTest, WindowReorganizedChildNodeRemovedAndInserted) {
467 std::unique_ptr<aura::Window> child_1 = CreateChildWindow(top_window.get());
468 std::unique_ptr<aura::Window> child_2 = CreateChildWindow(top_window.get());
469 std::unique_ptr<aura::Window> child_21 = CreateChildWindow(child_2.get());
470 std::unique_ptr<aura::Window> child_22 = CreateChildWindow(child_2.get());
471
417 aura::Window* root_window = dom_agent()->root_windows()[0]; 472 aura::Window* root_window = dom_agent()->root_windows()[0];
418 aura::Window* rotation_window = root_window->children()[0]; 473 aura::Window* rotation_window = root_window->children()[0];
419 aura::Window* parent_window = rotation_window->children()[0]; 474 aura::Window* parent_window = rotation_window->children()[0];
420 aura::Window* target_window = rotation_window->children()[1]; 475 aura::Window* target_window = rotation_window->children()[1];
421 std::unique_ptr<aura::Window> child_window(CreateChildWindow(parent_window)); 476 std::unique_ptr<aura::Window> child_window(CreateChildWindow(parent_window));
422 477
423 // Initialize DOMAgent 478 // Initialize DOMAgent
424 std::unique_ptr<ui::devtools::protocol::DOM::Node> root; 479 std::unique_ptr<ui::devtools::protocol::DOM::Node> root;
425 dom_agent()->getDocument(&root); 480 dom_agent()->getDocument(&root);
426 DOM::Node* root_node = 481 DOM::Node* root_node =
427 root->getChildren(nullptr)->get(0)->getChildren(nullptr)->get(0); 482 root->getChildren(nullptr)->get(0)->getChildren(nullptr)->get(0);
428 DOM::Node* parent_node = root_node->getChildren(nullptr)->get(0); 483 DOM::Node* parent_node = root_node->getChildren(nullptr)->get(0);
429 DOM::Node* target_node = root_node->getChildren(nullptr)->get(1); 484 DOM::Node* target_node = root_node->getChildren(nullptr)->get(1);
430 Array<DOM::Node>* target_node_children = target_node->getChildren(nullptr); 485 Array<DOM::Node>* target_node_children = target_node->getChildren(nullptr);
431 DOM::Node* sibling_node = 486 DOM::Node* sibling_node =
432 target_node_children->get(target_node_children->length() - 1); 487 target_node_children->get(target_node_children->length() - 1);
433 Array<DOM::Node>* parent_node_children = parent_node->getChildren(nullptr); 488 Array<DOM::Node>* parent_node_children = parent_node->getChildren(nullptr);
434 DOM::Node* child_node = 489 DOM::Node* child_node =
435 parent_node_children->get(parent_node_children->length() - 1); 490 parent_node_children->get(parent_node_children->length() - 1);
436 491
437 Compare(parent_window, parent_node); 492 Compare(parent_window, parent_node);
438 Compare(target_window, target_node); 493 Compare(target_window, target_node);
439 Compare(child_window.get(), child_node); 494 Compare(child_window.get(), child_node);
440 parent_window->RemoveChild(child_window.get()); 495 parent_window->RemoveChild(child_window.get());
441 target_window->AddChild(child_window.get()); 496 target_window->AddChild(child_window.get());
442 ExpectChildNodeRemoved(parent_node->getNodeId(), child_node->getNodeId()); 497 ExpectChildNodeRemoved(parent_node->getNodeId(), child_node->getNodeId());
443 ExpectChildNodeInserted(target_node->getNodeId(), sibling_node->getNodeId()); 498 ExpectChildNodeInserted(target_node->getNodeId(), sibling_node->getNodeId());
444 } 499 }
445 500
446 TEST_F(AshDevToolsTest, WindowStackingChangedChildNodeRemovedAndInserted) { 501 TEST_F(UIDevToolsTest, WindowStackingChangedChildNodeRemovedAndInserted) {
502 std::unique_ptr<aura::Window> child_11 = CreateChildWindow(top_window.get());
503 std::unique_ptr<aura::Window> child_12 = CreateChildWindow(top_window.get());
504 std::unique_ptr<aura::Window> child_13 = CreateChildWindow(top_window.get());
505
447 // Initialize DOMAgent 506 // Initialize DOMAgent
448 std::unique_ptr<ui::devtools::protocol::DOM::Node> root; 507 std::unique_ptr<ui::devtools::protocol::DOM::Node> root;
449 dom_agent()->getDocument(&root); 508 dom_agent()->getDocument(&root);
450 509
451 aura::Window* root_window = dom_agent()->root_windows()[0]; 510 aura::Window* root_window = dom_agent()->root_windows()[0];
452 aura::Window* parent_window = root_window->children()[0]; 511 aura::Window* parent_window = root_window->children()[0];
453 aura::Window* child_window = parent_window->children()[0]; 512 aura::Window* child_window = parent_window->children()[0];
454 aura::Window* target_window = parent_window->children()[1]; 513 aura::Window* target_window = parent_window->children()[1];
455 514
456 DOM::Node* parent_node = 515 DOM::Node* parent_node =
457 root->getChildren(nullptr)->get(0)->getChildren(nullptr)->get(0); 516 root->getChildren(nullptr)->get(0)->getChildren(nullptr)->get(0);
458 Array<DOM::Node>* parent_node_children = parent_node->getChildren(nullptr); 517 Array<DOM::Node>* parent_node_children = parent_node->getChildren(nullptr);
459 DOM::Node* child_node = parent_node_children->get(0); 518 DOM::Node* child_node = parent_node_children->get(0);
460 DOM::Node* sibling_node = parent_node_children->get(1); 519 DOM::Node* sibling_node = parent_node_children->get(1);
461 int parent_id = parent_node->getNodeId(); 520 int parent_id = parent_node->getNodeId();
462 521
463 Compare(parent_window, parent_node); 522 Compare(parent_window, parent_node);
464 Compare(child_window, child_node); 523 Compare(child_window, child_node);
465 parent_window->StackChildAbove(child_window, target_window); 524 parent_window->StackChildAbove(child_window, target_window);
466 ExpectChildNodeRemoved(parent_id, child_node->getNodeId()); 525 ExpectChildNodeRemoved(parent_id, child_node->getNodeId());
467 ExpectChildNodeInserted(parent_id, sibling_node->getNodeId()); 526 ExpectChildNodeInserted(parent_id, sibling_node->getNodeId());
468 } 527 }
469 528
470 TEST_F(AshDevToolsTest, ViewInserted) { 529 TEST_F(UIDevToolsTest, ViewInserted) {
471 std::unique_ptr<views::Widget> widget( 530 std::unique_ptr<views::Widget> widget(
472 CreateTestWidget(gfx::Rect(1, 1, 1, 1))); 531 CreateTestWidget(gfx::Rect(1, 1, 1, 1)));
473 aura::Window* window = widget->GetNativeWindow(); 532 aura::Window* window = widget->GetNativeWindow();
474 widget->Show(); 533 widget->Show();
475 534
476 // Initialize DOMAgent 535 // Initialize DOMAgent
477 std::unique_ptr<ui::devtools::protocol::DOM::Node> root; 536 std::unique_ptr<ui::devtools::protocol::DOM::Node> root;
478 dom_agent()->getDocument(&root); 537 dom_agent()->getDocument(&root);
479 538
480 DOM::Node* parent_node = FindInRoot(window, root.get()); 539 DOM::Node* parent_node = FindInRoot(window, root.get());
481 ASSERT_TRUE(parent_node); 540 ASSERT_TRUE(parent_node);
482 DOM::Node* widget_node = parent_node->getChildren(nullptr)->get(0); 541 DOM::Node* widget_node = parent_node->getChildren(nullptr)->get(0);
483 DOM::Node* root_view_node = widget_node->getChildren(nullptr)->get(0); 542 DOM::Node* root_view_node = widget_node->getChildren(nullptr)->get(0);
484 Array<DOM::Node>* root_view_children = root_view_node->getChildren(nullptr); 543 Array<DOM::Node>* root_view_children = root_view_node->getChildren(nullptr);
485 ASSERT_TRUE(root_view_children); 544 ASSERT_TRUE(root_view_children);
486 DOM::Node* sibling_view_node = 545 DOM::Node* sibling_view_node =
487 root_view_children->get(root_view_children->length() - 1); 546 root_view_children->get(root_view_children->length() - 1);
488 547
489 widget->GetRootView()->AddChildView(new views::View); 548 widget->GetRootView()->AddChildView(new views::View);
490 ExpectChildNodeInserted(root_view_node->getNodeId(), 549 ExpectChildNodeInserted(root_view_node->getNodeId(),
491 sibling_view_node->getNodeId()); 550 sibling_view_node->getNodeId());
492 } 551 }
493 552
494 TEST_F(AshDevToolsTest, ViewRemoved) { 553 TEST_F(UIDevToolsTest, ViewRemoved) {
495 std::unique_ptr<views::Widget> widget( 554 std::unique_ptr<views::Widget> widget(
496 CreateTestWidget(gfx::Rect(1, 1, 1, 1))); 555 CreateTestWidget(gfx::Rect(1, 1, 1, 1)));
497 // Need to store |view| in unique_ptr because it is removed from the widget 556 // Need to store |view| in unique_ptr because it is removed from the widget
498 // and needs to be destroyed independently 557 // and needs to be destroyed independently
499 std::unique_ptr<views::View> child_view = base::MakeUnique<views::View>(); 558 std::unique_ptr<views::View> child_view = base::MakeUnique<views::View>();
500 aura::Window* window = widget->GetNativeWindow(); 559 aura::Window* window = widget->GetNativeWindow();
501 widget->Show(); 560 widget->Show();
502 views::View* root_view = widget->GetRootView(); 561 views::View* root_view = widget->GetRootView();
503 root_view->AddChildView(child_view.get()); 562 root_view->AddChildView(child_view.get());
504 563
505 // Initialize DOMAgent 564 // Initialize DOMAgent
506 std::unique_ptr<ui::devtools::protocol::DOM::Node> root; 565 std::unique_ptr<ui::devtools::protocol::DOM::Node> root;
507 dom_agent()->getDocument(&root); 566 dom_agent()->getDocument(&root);
508 567
509 DOM::Node* parent_node = FindInRoot(window, root.get()); 568 DOM::Node* parent_node = FindInRoot(window, root.get());
510 ASSERT_TRUE(parent_node); 569 ASSERT_TRUE(parent_node);
511 DOM::Node* widget_node = parent_node->getChildren(nullptr)->get(0); 570 DOM::Node* widget_node = parent_node->getChildren(nullptr)->get(0);
512 DOM::Node* root_view_node = widget_node->getChildren(nullptr)->get(0); 571 DOM::Node* root_view_node = widget_node->getChildren(nullptr)->get(0);
513 Array<DOM::Node>* root_view_children = root_view_node->getChildren(nullptr); 572 Array<DOM::Node>* root_view_children = root_view_node->getChildren(nullptr);
514 ASSERT_TRUE(root_view_children); 573 ASSERT_TRUE(root_view_children);
515 DOM::Node* child_view_node = 574 DOM::Node* child_view_node =
516 root_view_children->get(root_view_children->length() - 1); 575 root_view_children->get(root_view_children->length() - 1);
517 576
518 Compare(child_view.get(), child_view_node); 577 Compare(child_view.get(), child_view_node);
519 root_view->RemoveChildView(child_view.get()); 578 root_view->RemoveChildView(child_view.get());
520 ExpectChildNodeRemoved(root_view_node->getNodeId(), 579 ExpectChildNodeRemoved(root_view_node->getNodeId(),
521 child_view_node->getNodeId()); 580 child_view_node->getNodeId());
522 } 581 }
523 582
524 TEST_F(AshDevToolsTest, ViewRearranged) { 583 TEST_F(UIDevToolsTest, ViewRearranged) {
525 std::unique_ptr<views::Widget> widget( 584 std::unique_ptr<views::Widget> widget(
526 CreateTestWidget(gfx::Rect(1, 1, 1, 1))); 585 CreateTestWidget(gfx::Rect(1, 1, 1, 1)));
527 aura::Window* window = widget->GetNativeWindow(); 586 aura::Window* window = widget->GetNativeWindow();
528 widget->Show(); 587 widget->Show();
529 views::View* root_view = widget->GetRootView(); 588 views::View* root_view = widget->GetRootView();
530 views::View* parent_view = new views::View; 589 views::View* parent_view = new views::View;
531 views::View* target_view = new views::View; 590 views::View* target_view = new views::View;
532 views::View* child_view = new views::View; 591 views::View* child_view = new views::View;
533 views::View* child_view_1 = new views::View; 592 views::View* child_view_1 = new views::View;
534 593
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
567 ExpectChildNodeRemoved(parent_view_node->getNodeId(), 626 ExpectChildNodeRemoved(parent_view_node->getNodeId(),
568 child_view_node_1->getNodeId()); 627 child_view_node_1->getNodeId());
569 ExpectChildNodeInserted(parent_view_node->getNodeId(), 0); 628 ExpectChildNodeInserted(parent_view_node->getNodeId(), 0);
570 629
571 target_view->AddChildView(child_view); 630 target_view->AddChildView(child_view);
572 ExpectChildNodeRemoved(parent_view_node->getNodeId(), 631 ExpectChildNodeRemoved(parent_view_node->getNodeId(),
573 child_view_node->getNodeId()); 632 child_view_node->getNodeId());
574 ExpectChildNodeInserted(target_view_node->getNodeId(), 0); 633 ExpectChildNodeInserted(target_view_node->getNodeId(), 0);
575 } 634 }
576 635
577 TEST_F(AshDevToolsTest, ViewRearrangedRemovedAndInserted) { 636 TEST_F(UIDevToolsTest, ViewRearrangedRemovedAndInserted) {
578 std::unique_ptr<views::Widget> widget( 637 std::unique_ptr<views::Widget> widget(
579 CreateTestWidget(gfx::Rect(1, 1, 1, 1))); 638 CreateTestWidget(gfx::Rect(1, 1, 1, 1)));
580 aura::Window* window = widget->GetNativeWindow(); 639 aura::Window* window = widget->GetNativeWindow();
581 widget->Show(); 640 widget->Show();
582 views::View* root_view = widget->GetRootView(); 641 views::View* root_view = widget->GetRootView();
583 views::View* parent_view = new views::View; 642 views::View* parent_view = new views::View;
584 views::View* target_view = new views::View; 643 views::View* target_view = new views::View;
585 views::View* child_view = new views::View; 644 views::View* child_view = new views::View;
586 root_view->AddChildView(parent_view); 645 root_view->AddChildView(parent_view);
587 root_view->AddChildView(target_view); 646 root_view->AddChildView(target_view);
(...skipping 18 matching lines...) Expand all
606 Compare(parent_view, parent_view_node); 665 Compare(parent_view, parent_view_node);
607 Compare(target_view, target_view_node); 666 Compare(target_view, target_view_node);
608 Compare(child_view, child_view_node); 667 Compare(child_view, child_view_node);
609 parent_view->RemoveChildView(child_view); 668 parent_view->RemoveChildView(child_view);
610 target_view->AddChildView(child_view); 669 target_view->AddChildView(child_view);
611 ExpectChildNodeRemoved(parent_view_node->getNodeId(), 670 ExpectChildNodeRemoved(parent_view_node->getNodeId(),
612 child_view_node->getNodeId()); 671 child_view_node->getNodeId());
613 ExpectChildNodeInserted(target_view_node->getNodeId(), 0); 672 ExpectChildNodeInserted(target_view_node->getNodeId(), 0);
614 } 673 }
615 674
616 TEST_F(AshDevToolsTest, WindowWidgetViewHighlight) { 675 TEST_F(UIDevToolsTest, WindowWidgetViewHighlight) {
676 DCHECK_EQ(dom_agent()->root_windows()[0]->GetChildById(
677 ash::kShellWindowId_OverlayContainer),
678 top_overlay_window.get());
617 std::unique_ptr<views::Widget> widget( 679 std::unique_ptr<views::Widget> widget(
618 CreateTestWidget(gfx::Rect(0, 0, 400, 400))); 680 CreateTestWidget(gfx::Rect(0, 0, 400, 400)));
619 aura::Window* parent_window = widget->GetNativeWindow(); 681 aura::Window* parent_window = widget->GetNativeWindow();
620 std::unique_ptr<aura::Window> window(CreateChildWindow(parent_window)); 682 std::unique_ptr<aura::Window> window(CreateChildWindow(parent_window));
621 views::View* root_view = widget->GetRootView(); 683 views::View* root_view = widget->GetRootView();
622 684
623 std::unique_ptr<ui::devtools::protocol::DOM::Node> root; 685 std::unique_ptr<ui::devtools::protocol::DOM::Node> root;
624 dom_agent()->getDocument(&root); 686 dom_agent()->getDocument(&root);
625 687
626 DOM::Node* parent_node = FindInRoot(parent_window, root.get()); 688 DOM::Node* parent_node = FindInRoot(parent_window, root.get());
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
665 for (auto* child : ui_element->children()) { 727 for (auto* child : ui_element->children()) {
666 if (child->type() == devtools::UIElementType::WINDOW) { 728 if (child->type() == devtools::UIElementType::WINDOW) {
667 int node_id = GetNodeIdFromWindow(child, window); 729 int node_id = GetNodeIdFromWindow(child, window);
668 if (node_id > 0) 730 if (node_id > 0)
669 return node_id; 731 return node_id;
670 } 732 }
671 } 733 }
672 return 0; 734 return 0;
673 } 735 }
674 736
675 TEST_F(AshDevToolsTest, MultipleDisplayHighlight) { 737 // TODO(thanhph): Add UIDevToolsTest.MultipleDisplayHighlight back when multiple
676 UpdateDisplay("300x400,500x500"); 738 // displays are available for ViewTestBase.
677 739
678 aura::Window::Windows root_windows = dom_agent()->root_windows(); 740 TEST_F(UIDevToolsTest, WindowWidgetViewGetMatchedStylesForNode) {
679 std::unique_ptr<aura::Window> window(
680 CreateTestWindowInShellWithBounds(gfx::Rect(1, 2, 30, 40)));
681
682 std::unique_ptr<ui::devtools::protocol::DOM::Node> root;
683 dom_agent()->getDocument(&root);
684
685 EXPECT_EQ(root_windows[0], window->GetRootWindow());
686 HighlightNode(
687 GetNodeIdFromWindow(dom_agent()->window_element_root(), window.get()));
688 ExpectHighlighted(window->GetBoundsInScreen(),
689 dom_agent()->root_windows()[0]);
690
691 window->SetBoundsInScreen(gfx::Rect(500, 0, 50, 50), GetSecondaryDisplay());
692 EXPECT_EQ(root_windows[1], window->GetRootWindow());
693 HighlightNode(
694 GetNodeIdFromWindow(dom_agent()->window_element_root(), window.get()));
695 ExpectHighlighted(window->GetBoundsInScreen(),
696 dom_agent()->root_windows()[1]);
697 }
698
699 TEST_F(AshDevToolsTest, WindowWidgetViewGetMatchedStylesForNode) {
700 std::unique_ptr<views::Widget> widget( 741 std::unique_ptr<views::Widget> widget(
701 CreateTestWidget(gfx::Rect(1, 1, 1, 1))); 742 CreateTestWidget(gfx::Rect(1, 1, 1, 1)));
702 aura::Window* parent_window = widget->GetNativeWindow(); 743 aura::Window* parent_window = widget->GetNativeWindow();
703 std::unique_ptr<aura::Window> window(CreateChildWindow(parent_window)); 744 std::unique_ptr<aura::Window> window(CreateChildWindow(parent_window));
704 gfx::Rect window_bounds(2, 2, 3, 3); 745 gfx::Rect window_bounds(2, 2, 3, 3);
705 gfx::Rect widget_bounds(50, 50, 100, 75); 746 gfx::Rect widget_bounds(50, 50, 100, 75);
706 gfx::Rect view_bounds(4, 4, 3, 3); 747 gfx::Rect view_bounds(4, 4, 3, 3);
707 window->SetBounds(window_bounds); 748 window->SetBounds(window_bounds);
708 widget->SetBounds(widget_bounds); 749 widget->SetBounds(widget_bounds);
709 widget->GetRootView()->SetBoundsRect(view_bounds); 750 widget->GetRootView()->SetBoundsRect(view_bounds);
710 751
711 std::unique_ptr<ui::devtools::protocol::DOM::Node> root; 752 std::unique_ptr<ui::devtools::protocol::DOM::Node> root;
712 dom_agent()->getDocument(&root); 753 dom_agent()->getDocument(&root);
713 754
714 DOM::Node* parent_node = FindInRoot(parent_window, root.get()); 755 DOM::Node* parent_node = FindInRoot(parent_window, root.get());
715 ASSERT_TRUE(parent_node); 756 ASSERT_TRUE(parent_node);
716 Array<DOM::Node>* parent_children = parent_node->getChildren(nullptr); 757 Array<DOM::Node>* parent_children = parent_node->getChildren(nullptr);
717 ASSERT_TRUE(parent_children); 758 ASSERT_TRUE(parent_children);
718 759
719 CompareNodeBounds(parent_node, widget_bounds); 760 CompareNodeBounds(parent_node, widget_bounds);
720 CompareNodeBounds(parent_children->get(1), window_bounds); 761 CompareNodeBounds(parent_children->get(1), window_bounds);
721 CompareNodeBounds(parent_children->get(0)->getChildren(nullptr)->get(0), 762 CompareNodeBounds(parent_children->get(0)->getChildren(nullptr)->get(0),
722 view_bounds); 763 view_bounds);
723 } 764 }
724 765
725 TEST_F(AshDevToolsTest, WindowWidgetViewStyleSheetChanged) { 766 TEST_F(UIDevToolsTest, WindowWidgetViewStyleSheetChanged) {
726 std::unique_ptr<views::Widget> widget( 767 std::unique_ptr<views::Widget> widget(
727 CreateTestWidget(gfx::Rect(1, 1, 1, 1))); 768 CreateTestWidget(gfx::Rect(1, 1, 1, 1)));
728 aura::Window* widget_window = widget->GetNativeWindow(); 769 aura::Window* widget_window = widget->GetNativeWindow();
729 std::unique_ptr<aura::Window> child(CreateChildWindow(widget_window)); 770 std::unique_ptr<aura::Window> child(CreateChildWindow(widget_window));
730 771
731 std::unique_ptr<ui::devtools::protocol::DOM::Node> root; 772 std::unique_ptr<ui::devtools::protocol::DOM::Node> root;
732 dom_agent()->getDocument(&root); 773 dom_agent()->getDocument(&root);
733 774
734 gfx::Rect child_bounds(2, 2, 3, 3); 775 gfx::Rect child_bounds(2, 2, 3, 3);
735 gfx::Rect widget_bounds(10, 10, 150, 160); 776 gfx::Rect widget_bounds(10, 10, 150, 160);
736 gfx::Rect view_bounds(4, 4, 3, 3); 777 gfx::Rect view_bounds(4, 4, 3, 3);
737 child->SetBounds(child_bounds); 778 child->SetBounds(child_bounds);
738 widget->SetBounds(widget_bounds); 779 widget->SetBounds(widget_bounds);
739 widget->GetRootView()->SetBoundsRect(view_bounds); 780 widget->GetRootView()->SetBoundsRect(view_bounds);
740 781
741 DOM::Node* widget_node = FindInRoot(widget_window, root.get()); 782 DOM::Node* widget_node = FindInRoot(widget_window, root.get());
742 ASSERT_TRUE(widget_node); 783 ASSERT_TRUE(widget_node);
743 Array<DOM::Node>* widget_node_children = widget_node->getChildren(nullptr); 784 Array<DOM::Node>* widget_node_children = widget_node->getChildren(nullptr);
744 ASSERT_TRUE(widget_node_children); 785 ASSERT_TRUE(widget_node_children);
745 786
746 EXPECT_EQ(1, GetStyleSheetChangedCount(widget_node->getNodeId())); 787 EXPECT_EQ(1, GetStyleSheetChangedCount(widget_node->getNodeId()));
747 EXPECT_EQ( 788 EXPECT_EQ(
748 1, GetStyleSheetChangedCount(widget_node_children->get(1)->getNodeId())); 789 1, GetStyleSheetChangedCount(widget_node_children->get(1)->getNodeId()));
749 EXPECT_EQ(2, 790 EXPECT_EQ(2, GetStyleSheetChangedCount(widget_node_children->get(0)
750 GetStyleSheetChangedCount(widget_node_children->get(0) 791 ->getChildren(nullptr)
751 ->getChildren(nullptr) 792 ->get(0)
752 ->get(0) 793 ->getNodeId()));
753 ->getNodeId()));
754 } 794 }
755 795
756 TEST_F(AshDevToolsTest, WindowWidgetViewSetStyleText) { 796 TEST_F(UIDevToolsTest, WindowWidgetViewSetStyleText) {
757 std::unique_ptr<views::Widget> widget( 797 std::unique_ptr<views::Widget> widget(
758 CreateTestWidget(gfx::Rect(0, 0, 400, 400))); 798 CreateTestWidget(gfx::Rect(0, 0, 400, 400)));
759 aura::Window* parent_window = widget->GetNativeWindow(); 799 aura::Window* parent_window = widget->GetNativeWindow();
760 std::unique_ptr<aura::Window> window(CreateChildWindow(parent_window)); 800 std::unique_ptr<aura::Window> window(CreateChildWindow(parent_window));
761 views::View* root_view = widget->GetRootView(); 801 views::View* root_view = widget->GetRootView();
762 802
763 std::unique_ptr<ui::devtools::protocol::DOM::Node> root; 803 std::unique_ptr<ui::devtools::protocol::DOM::Node> root;
764 dom_agent()->getDocument(&root); 804 dom_agent()->getDocument(&root);
765 805
766 DOM::Node* parent_node = FindInRoot(parent_window, root.get()); 806 DOM::Node* parent_node = FindInRoot(parent_window, root.get());
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
818 858
819 SetStyleTexts(root_view_node, "\nheight: 73;\n ", true); 859 SetStyleTexts(root_view_node, "\nheight: 73;\n ", true);
820 EXPECT_EQ(gfx::Rect(25, 35, 45, 73), root_view->bounds()); 860 EXPECT_EQ(gfx::Rect(25, 35, 45, 73), root_view->bounds());
821 861
822 SetStyleTexts(root_view_node, "\nx: 10; y: 23; width: 52;\nvisibility: 1;\n", 862 SetStyleTexts(root_view_node, "\nx: 10; y: 23; width: 52;\nvisibility: 1;\n",
823 true); 863 true);
824 EXPECT_EQ(gfx::Rect(10, 23, 52, 73), root_view->bounds()); 864 EXPECT_EQ(gfx::Rect(10, 23, 52, 73), root_view->bounds());
825 EXPECT_TRUE(root_view->visible()); 865 EXPECT_TRUE(root_view->visible());
826 } 866 }
827 867
828 } // namespace ash 868 } // namespace ui
OLDNEW
« no previous file with comments | « components/ui_devtools/devtools/ui_devtools_dom_agent.cc ('k') | components/ui_devtools/devtools/ui_element.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698