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

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

Issue 2712793002: chromeos: Adds AshDevToolsTest to common_unittests (Closed)
Patch Set: Created 3 years, 10 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
« no previous file with comments | « ash/BUILD.gn ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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/common/devtools/ash_devtools_css_agent.h" 5 #include "ash/common/devtools/ash_devtools_css_agent.h"
6 #include "ash/common/devtools/ash_devtools_dom_agent.h" 6 #include "ash/common/devtools/ash_devtools_dom_agent.h"
7 #include "ash/common/test/ash_test.h" 7 #include "ash/common/test/ash_test.h"
8 #include "ash/common/wm_lookup.h" 8 #include "ash/common/wm_lookup.h"
9 #include "ash/common/wm_shell.h" 9 #include "ash/common/wm_shell.h"
10 #include "ash/common/wm_window.h" 10 #include "ash/common/wm_window.h"
(...skipping 215 matching lines...) Expand 10 before | Expand all | Expand 10 after
226 } 226 }
227 227
228 void ExpectChildNodeRemoved(int parent_id, int node_id) { 228 void ExpectChildNodeRemoved(int parent_id, int node_id) {
229 EXPECT_EQ(1, frontend_channel()->CountProtocolNotificationMessage( 229 EXPECT_EQ(1, frontend_channel()->CountProtocolNotificationMessage(
230 base::StringPrintf( 230 base::StringPrintf(
231 "{\"method\":\"DOM.childNodeRemoved\",\"params\":{" 231 "{\"method\":\"DOM.childNodeRemoved\",\"params\":{"
232 "\"parentNodeId\":%d,\"nodeId\":%d}}", 232 "\"parentNodeId\":%d,\"nodeId\":%d}}",
233 parent_id, node_id))); 233 parent_id, node_id)));
234 } 234 }
235 235
236 void ExpectStyleSheetChanged(int node_id) { 236 int GetStyleSheetChangedCount(int node_id) {
237 EXPECT_EQ(1, frontend_channel()->CountProtocolNotificationMessage( 237 return frontend_channel()->CountProtocolNotificationMessage(
238 base::StringPrintf( 238 base::StringPrintf("{\"method\":\"CSS.styleSheetChanged\",\"params\":{"
239 "{\"method\":\"CSS.styleSheetChanged\",\"params\":{" 239 "\"styleSheetId\":\"%d\"}}",
240 "\"styleSheetId\":\"%d\"}}", 240 node_id));
241 node_id)));
242 } 241 }
243 242
244 void CompareNodeBounds(DOM::Node* node, const gfx::Rect& bounds) { 243 void CompareNodeBounds(DOM::Node* node, const gfx::Rect& bounds) {
245 Maybe<CSS::CSSStyle> styles; 244 Maybe<CSS::CSSStyle> styles;
246 css_agent_->getMatchedStylesForNode(node->getNodeId(), &styles); 245 css_agent_->getMatchedStylesForNode(node->getNodeId(), &styles);
247 ASSERT_TRUE(styles.isJust()); 246 ASSERT_TRUE(styles.isJust());
248 Array<CSS::CSSProperty>* properties = styles.fromJust()->getCssProperties(); 247 Array<CSS::CSSProperty>* properties = styles.fromJust()->getCssProperties();
249 EXPECT_EQ(bounds.height(), GetPropertyByName("height", properties)); 248 EXPECT_EQ(bounds.height(), GetPropertyByName("height", properties));
250 EXPECT_EQ(bounds.width(), GetPropertyByName("width", properties)); 249 EXPECT_EQ(bounds.width(), GetPropertyByName("width", properties));
251 EXPECT_EQ(bounds.x(), GetPropertyByName("x", properties)); 250 EXPECT_EQ(bounds.x(), GetPropertyByName("x", properties));
(...skipping 413 matching lines...) Expand 10 before | Expand all | Expand 10 after
665 664
666 CompareNodeBounds(parent_node, widget_bounds); 665 CompareNodeBounds(parent_node, widget_bounds);
667 CompareNodeBounds(parent_children->get(1), window_bounds); 666 CompareNodeBounds(parent_children->get(1), window_bounds);
668 CompareNodeBounds(parent_children->get(0)->getChildren(nullptr)->get(0), 667 CompareNodeBounds(parent_children->get(0)->getChildren(nullptr)->get(0),
669 view_bounds); 668 view_bounds);
670 } 669 }
671 670
672 TEST_F(AshDevToolsTest, WindowWidgetViewStyleSheetChanged) { 671 TEST_F(AshDevToolsTest, WindowWidgetViewStyleSheetChanged) {
673 std::unique_ptr<views::Widget> widget( 672 std::unique_ptr<views::Widget> widget(
674 CreateTestWidget(gfx::Rect(1, 1, 1, 1))); 673 CreateTestWidget(gfx::Rect(1, 1, 1, 1)));
675 WmWindow* parent_window = WmLookup::Get()->GetWindowForWidget(widget.get()); 674 WmWindow* widget_window = WmLookup::Get()->GetWindowForWidget(widget.get());
676 std::unique_ptr<WindowOwner> child_owner(CreateChildWindow(parent_window)); 675 std::unique_ptr<WindowOwner> child_owner(CreateChildWindow(widget_window));
677 WmWindow* window = child_owner->window(); 676 WmWindow* child = child_owner->window();
678 677
679 std::unique_ptr<ui::devtools::protocol::DOM::Node> root; 678 std::unique_ptr<ui::devtools::protocol::DOM::Node> root;
680 dom_agent()->getDocument(&root); 679 dom_agent()->getDocument(&root);
681 680
682 gfx::Rect window_bounds(2, 2, 3, 3); 681 gfx::Rect child_bounds(2, 2, 3, 3);
683 gfx::Rect widget_bounds(10, 10, 5, 6); 682 gfx::Rect widget_bounds(10, 10, 150, 160);
sky 2017/02/22 20:44:51 This and increasing the expected count to 2 (line
684 gfx::Rect view_bounds(4, 4, 3, 3); 683 gfx::Rect view_bounds(4, 4, 3, 3);
685 window->SetBounds(window_bounds); 684 child->SetBounds(child_bounds);
686 widget->SetBounds(widget_bounds); 685 widget->SetBounds(widget_bounds);
687 widget->GetRootView()->SetBoundsRect(view_bounds); 686 widget->GetRootView()->SetBoundsRect(view_bounds);
688 687
689 DOM::Node* parent_node = FindInRoot(parent_window, root.get()); 688 DOM::Node* widget_node = FindInRoot(widget_window, root.get());
690 ASSERT_TRUE(parent_node); 689 ASSERT_TRUE(widget_node);
691 Array<DOM::Node>* parent_children = parent_node->getChildren(nullptr); 690 Array<DOM::Node>* widget_node_children = widget_node->getChildren(nullptr);
692 ASSERT_TRUE(parent_children); 691 ASSERT_TRUE(widget_node_children);
693 692
694 ExpectStyleSheetChanged(parent_node->getNodeId()); 693 EXPECT_EQ(1, GetStyleSheetChangedCount(widget_node->getNodeId()));
695 ExpectStyleSheetChanged(parent_children->get(1)->getNodeId()); 694 EXPECT_EQ(
696 ExpectStyleSheetChanged( 695 1, GetStyleSheetChangedCount(widget_node_children->get(1)->getNodeId()));
697 parent_children->get(0)->getChildren(nullptr)->get(0)->getNodeId()); 696 EXPECT_EQ(2,
697 GetStyleSheetChangedCount(widget_node_children->get(0)
698 ->getChildren(nullptr)
699 ->get(0)
700 ->getNodeId()));
698 } 701 }
699 702
700 TEST_F(AshDevToolsTest, WindowWidgetViewSetStyleText) { 703 TEST_F(AshDevToolsTest, WindowWidgetViewSetStyleText) {
701 std::unique_ptr<views::Widget> widget( 704 std::unique_ptr<views::Widget> widget(
702 CreateTestWidget(gfx::Rect(0, 0, 400, 400))); 705 CreateTestWidget(gfx::Rect(0, 0, 400, 400)));
703 WmWindow* parent_window = WmLookup::Get()->GetWindowForWidget(widget.get()); 706 WmWindow* parent_window = WmLookup::Get()->GetWindowForWidget(widget.get());
704 std::unique_ptr<WindowOwner> child_owner(CreateChildWindow(parent_window)); 707 std::unique_ptr<WindowOwner> child_owner(CreateChildWindow(parent_window));
705 WmWindow* window = child_owner->window(); 708 WmWindow* window = child_owner->window();
706 views::View* root_view = widget->GetRootView(); 709 views::View* root_view = widget->GetRootView();
707 710
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
754 EXPECT_EQ(gfx::Rect(25, 35, 45, 20), root_view->bounds()); // Not changed 757 EXPECT_EQ(gfx::Rect(25, 35, 45, 20), root_view->bounds()); // Not changed
755 758
756 SetStyleTexts(root_view_node, "\nheight: 73;\n ", true); 759 SetStyleTexts(root_view_node, "\nheight: 73;\n ", true);
757 EXPECT_EQ(gfx::Rect(25, 35, 45, 73), root_view->bounds()); 760 EXPECT_EQ(gfx::Rect(25, 35, 45, 73), root_view->bounds());
758 761
759 SetStyleTexts(root_view_node, "\nx: 10; y: 23; width: 52;\n ", true); 762 SetStyleTexts(root_view_node, "\nx: 10; y: 23; width: 52;\n ", true);
760 EXPECT_EQ(gfx::Rect(10, 23, 52, 73), root_view->bounds()); 763 EXPECT_EQ(gfx::Rect(10, 23, 52, 73), root_view->bounds());
761 } 764 }
762 765
763 } // namespace ash 766 } // namespace ash
OLDNEW
« no previous file with comments | « ash/BUILD.gn ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698