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

Side by Side Diff: ash/common/system/tray/tri_view_unittest.cc

Issue 2538513002: [ash-md] Fixed TriView to relayout child Views when their preferred size changed. (Closed)
Patch Set: Created 4 years 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 <memory> 5 #include <memory>
6 6
7 #include "ash/common/system/tray/tri_view.h" 7 #include "ash/common/system/tray/tri_view.h"
8 #include "base/memory/ptr_util.h" 8 #include "base/memory/ptr_util.h"
9 #include "testing/gtest/include/gtest/gtest.h" 9 #include "testing/gtest/include/gtest/gtest.h"
10 #include "ui/gfx/geometry/insets.h" 10 #include "ui/gfx/geometry/insets.h"
11 #include "ui/gfx/geometry/rect_conversions.h" 11 #include "ui/gfx/geometry/rect_conversions.h"
12 #include "ui/views/layout/box_layout.h"
12 #include "ui/views/test/test_layout_manager.h" 13 #include "ui/views/test/test_layout_manager.h"
13 #include "ui/views/test/test_views.h" 14 #include "ui/views/test/test_views.h"
14 #include "ui/views/view.h" 15 #include "ui/views/view.h"
15 16
16 namespace ash { 17 namespace ash {
18 namespace {
19
20 // Returns a layout manager that will size views according to their preferred
21 // size.
22 std::unique_ptr<views::LayoutManager> CreatePreferredSizeLayoutManager() {
23 auto layout = base::MakeUnique<views::BoxLayout>(
24 views::BoxLayout::kHorizontal, 0, 0, 0);
25 layout->set_cross_axis_alignment(
26 views::BoxLayout::CROSS_AXIS_ALIGNMENT_START);
27 return std::move(layout);
28 }
29
30 } // namespace
17 31
18 class TriViewTest : public testing::Test { 32 class TriViewTest : public testing::Test {
19 public: 33 public:
20 TriViewTest(); 34 TriViewTest();
21 35
22 protected: 36 protected:
23 // Returns the bounds of |child| in the coordinate space of 37 // Returns the bounds of |child| in the coordinate space of
24 // |tri_view_|. 38 // |tri_view_|.
25 gfx::Rect GetBoundsInHost(const views::View* child) const; 39 gfx::Rect GetBoundsInHost(const views::View* child) const;
26 40
(...skipping 286 matching lines...) Expand 10 before | Expand all | Expand 10 after
313 tri_view_->SetFlexForContainer(TriView::Container::CENTER, 1.f); 327 tri_view_->SetFlexForContainer(TriView::Container::CENTER, 1.f);
314 tri_view_->SetMaxSize(TriView::Container::CENTER, kMaxCenterSize); 328 tri_view_->SetMaxSize(TriView::Container::CENTER, kMaxCenterSize);
315 tri_view_->Layout(); 329 tri_view_->Layout();
316 330
317 EXPECT_EQ(kViewSize, GetBoundsInHost(start_child).size()); 331 EXPECT_EQ(kViewSize, GetBoundsInHost(start_child).size());
318 EXPECT_EQ(kExpectedCenterSize, 332 EXPECT_EQ(kExpectedCenterSize,
319 GetBoundsInHost(GetContainer(TriView::Container::CENTER)).size()); 333 GetBoundsInHost(GetContainer(TriView::Container::CENTER)).size());
320 EXPECT_EQ(kViewSize, GetBoundsInHost(end_child).size()); 334 EXPECT_EQ(kViewSize, GetBoundsInHost(end_child).size());
321 } 335 }
322 336
337 TEST_F(TriViewTest, ChildViewsPreferredSizeChanged) {
338 const int kHostWidth = 500;
339 const gfx::Size kMinStartSize(100, 10);
340
341 tri_view_->SetBounds(0, 0, kHostWidth, 10);
342 tri_view_->SetMinSize(TriView::Container::START, kMinStartSize);
343 tri_view_->SetContainerLayout(TriView::Container::START,
344 CreatePreferredSizeLayoutManager());
345 tri_view_->SetFlexForContainer(TriView::Container::CENTER, 1.f);
346 tri_view_->Layout();
347
348 views::ProportionallySizedView* child_view =
349 new views::ProportionallySizedView(1);
350 tri_view_->AddView(TriView::Container::START, child_view);
351
352 child_view->SetPreferredWidth(1);
353 EXPECT_EQ(child_view->GetPreferredSize(), child_view->size());
354
355 child_view->SetPreferredWidth(2);
356 EXPECT_EQ(child_view->GetPreferredSize(), child_view->size());
357 }
358
323 } // namespace ash 359 } // namespace ash
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698