| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/frame/default_header_painter.h" | 5 #include "ash/frame/default_header_painter.h" |
| 6 | 6 |
| 7 #include <memory> | 7 #include <memory> |
| 8 | 8 |
| 9 #include "ash/common/wm/window_state.h" | 9 #include "ash/common/shell_window_ids.h" |
| 10 #include "ash/frame/caption_buttons/frame_caption_button_container_view.h" | 10 #include "ash/frame/caption_buttons/frame_caption_button_container_view.h" |
| 11 #include "ash/shell.h" | |
| 12 #include "ash/test/ash_test_base.h" | 11 #include "ash/test/ash_test_base.h" |
| 13 #include "ui/gfx/font_list.h" | |
| 14 #include "ui/views/test/test_views.h" | 12 #include "ui/views/test/test_views.h" |
| 15 #include "ui/views/widget/widget.h" | 13 #include "ui/views/widget/widget.h" |
| 16 #include "ui/views/window/non_client_view.h" | 14 #include "ui/views/window/non_client_view.h" |
| 17 | 15 |
| 18 using ash::HeaderPainter; | 16 using ash::HeaderPainter; |
| 19 using views::NonClientFrameView; | 17 using views::NonClientFrameView; |
| 20 using views::Widget; | 18 using views::Widget; |
| 21 | 19 |
| 22 namespace ash { | 20 namespace ash { |
| 23 | 21 |
| 24 class DefaultHeaderPainterTest : public ash::test::AshTestBase { | 22 using DefaultHeaderPainterTest = test::AshTestBase; |
| 25 public: | |
| 26 // Creates a test widget that owns its native widget. | |
| 27 Widget* CreateTestWidget() { | |
| 28 Widget* widget = new Widget; | |
| 29 Widget::InitParams params; | |
| 30 params.ownership = Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET; | |
| 31 params.context = CurrentContext(); | |
| 32 widget->Init(params); | |
| 33 return widget; | |
| 34 } | |
| 35 }; | |
| 36 | 23 |
| 37 // Ensure the title text is vertically aligned with the window icon. | 24 // Ensure the title text is vertically aligned with the window icon. |
| 38 TEST_F(DefaultHeaderPainterTest, TitleIconAlignment) { | 25 TEST_F(DefaultHeaderPainterTest, TitleIconAlignment) { |
| 39 std::unique_ptr<Widget> w(CreateTestWidget()); | 26 std::unique_ptr<Widget> w = CreateTestWidget( |
| 27 nullptr, kShellWindowId_DefaultContainer, gfx::Rect(1, 2, 3, 4)); |
| 40 ash::FrameCaptionButtonContainerView container(w.get()); | 28 ash::FrameCaptionButtonContainerView container(w.get()); |
| 41 views::StaticSizedView window_icon(gfx::Size(16, 16)); | 29 views::StaticSizedView window_icon(gfx::Size(16, 16)); |
| 42 window_icon.SetBounds(0, 0, 16, 16); | 30 window_icon.SetBounds(0, 0, 16, 16); |
| 43 w->SetBounds(gfx::Rect(0, 0, 500, 500)); | 31 w->SetBounds(gfx::Rect(0, 0, 500, 500)); |
| 44 w->Show(); | 32 w->Show(); |
| 45 | 33 |
| 46 DefaultHeaderPainter painter; | 34 DefaultHeaderPainter painter; |
| 47 painter.Init(w.get(), w->non_client_view()->frame_view(), &container); | 35 painter.Init(w.get(), w->non_client_view()->frame_view(), &container); |
| 48 painter.UpdateLeftHeaderView(&window_icon); | 36 painter.UpdateLeftHeaderView(&window_icon); |
| 49 painter.LayoutHeader(); | 37 painter.LayoutHeader(); |
| 50 gfx::Rect title_bounds = painter.GetTitleBounds(); | 38 gfx::Rect title_bounds = painter.GetTitleBounds(); |
| 51 EXPECT_EQ(window_icon.bounds().CenterPoint().y(), | 39 EXPECT_EQ(window_icon.bounds().CenterPoint().y(), |
| 52 title_bounds.CenterPoint().y()); | 40 title_bounds.CenterPoint().y()); |
| 53 } | 41 } |
| 54 | 42 |
| 55 // Ensure the light icons are used when appropriate. | 43 // Ensure the light icons are used when appropriate. |
| 56 TEST_F(DefaultHeaderPainterTest, LightIcons) { | 44 TEST_F(DefaultHeaderPainterTest, LightIcons) { |
| 57 std::unique_ptr<Widget> w(CreateTestWidget()); | 45 std::unique_ptr<Widget> w = CreateTestWidget( |
| 46 nullptr, kShellWindowId_DefaultContainer, gfx::Rect(1, 2, 3, 4)); |
| 58 ash::FrameCaptionButtonContainerView container(w.get()); | 47 ash::FrameCaptionButtonContainerView container(w.get()); |
| 59 views::StaticSizedView window_icon(gfx::Size(16, 16)); | 48 views::StaticSizedView window_icon(gfx::Size(16, 16)); |
| 60 window_icon.SetBounds(0, 0, 16, 16); | 49 window_icon.SetBounds(0, 0, 16, 16); |
| 61 w->SetBounds(gfx::Rect(0, 0, 500, 500)); | 50 w->SetBounds(gfx::Rect(0, 0, 500, 500)); |
| 62 w->Show(); | 51 w->Show(); |
| 63 | 52 |
| 64 DefaultHeaderPainter painter; | 53 DefaultHeaderPainter painter; |
| 65 painter.Init(w.get(), w->non_client_view()->frame_view(), &container); | 54 painter.Init(w.get(), w->non_client_view()->frame_view(), &container); |
| 66 | 55 |
| 67 // Check by default light icons are not used. | 56 // Check by default light icons are not used. |
| (...skipping 19 matching lines...) Expand all Loading... |
| 87 // Check not so light or dark colors. | 76 // Check not so light or dark colors. |
| 88 painter.SetFrameColors(SkColorSetRGB(70, 70, 70), | 77 painter.SetFrameColors(SkColorSetRGB(70, 70, 70), |
| 89 SkColorSetRGB(200, 200, 200)); | 78 SkColorSetRGB(200, 200, 200)); |
| 90 painter.mode_ = HeaderPainter::MODE_ACTIVE; | 79 painter.mode_ = HeaderPainter::MODE_ACTIVE; |
| 91 EXPECT_TRUE(painter.ShouldUseLightImages()); | 80 EXPECT_TRUE(painter.ShouldUseLightImages()); |
| 92 painter.mode_ = HeaderPainter::MODE_INACTIVE; | 81 painter.mode_ = HeaderPainter::MODE_INACTIVE; |
| 93 EXPECT_FALSE(painter.ShouldUseLightImages()); | 82 EXPECT_FALSE(painter.ShouldUseLightImages()); |
| 94 } | 83 } |
| 95 | 84 |
| 96 } // namespace ash | 85 } // namespace ash |
| OLD | NEW |