| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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/wm/header_painter.h" | 5 #include "ash/wm/default_header_painter.h" |
| 6 | 6 |
| 7 #include "ash/shell.h" | 7 #include "ash/shell.h" |
| 8 #include "ash/test/ash_test_base.h" | 8 #include "ash/test/ash_test_base.h" |
| 9 #include "ash/wm/caption_buttons/frame_caption_button_container_view.h" | 9 #include "ash/wm/caption_buttons/frame_caption_button_container_view.h" |
| 10 #include "ash/wm/window_state.h" | 10 #include "ash/wm/window_state.h" |
| 11 #include "base/memory/scoped_ptr.h" | 11 #include "base/memory/scoped_ptr.h" |
| 12 #include "grit/ash_resources.h" | 12 #include "grit/ash_resources.h" |
| 13 #include "ui/gfx/font_list.h" | 13 #include "ui/gfx/font_list.h" |
| 14 #include "ui/views/widget/widget.h" | 14 #include "ui/views/widget/widget.h" |
| 15 #include "ui/views/window/non_client_view.h" | 15 #include "ui/views/window/non_client_view.h" |
| 16 | 16 |
| 17 using ash::HeaderPainter; | |
| 18 using views::NonClientFrameView; | |
| 19 using views::Widget; | 17 using views::Widget; |
| 20 | 18 |
| 21 namespace ash { | 19 namespace ash { |
| 22 | 20 |
| 23 class HeaderPainterTest : public ash::test::AshTestBase { | 21 class DefaultHeaderPainterTest : public ash::test::AshTestBase { |
| 24 public: | 22 public: |
| 25 // Creates a test widget that owns its native widget. | 23 // Creates a test widget that owns its native widget. |
| 26 Widget* CreateTestWidget() { | 24 Widget* CreateTestWidget() { |
| 27 Widget* widget = new Widget; | 25 Widget* widget = new Widget; |
| 28 Widget::InitParams params; | 26 Widget::InitParams params; |
| 29 params.ownership = Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET; | 27 params.ownership = Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET; |
| 30 params.context = CurrentContext(); | 28 params.context = CurrentContext(); |
| 31 widget->Init(params); | 29 widget->Init(params); |
| 32 return widget; | 30 return widget; |
| 33 } | 31 } |
| 34 }; | 32 }; |
| 35 | 33 |
| 36 // Ensure the title text is vertically aligned with the window icon. | 34 // Ensure the title text is vertically aligned with the window icon. |
| 37 TEST_F(HeaderPainterTest, TitleIconAlignment) { | 35 TEST_F(DefaultHeaderPainterTest, TitleIconAlignment) { |
| 38 scoped_ptr<Widget> w(CreateTestWidget()); | 36 scoped_ptr<Widget> w(CreateTestWidget()); |
| 39 ash::FrameCaptionButtonContainerView container(w.get(), | 37 ash::FrameCaptionButtonContainerView container(w.get(), |
| 40 ash::FrameCaptionButtonContainerView::MINIMIZE_ALLOWED); | 38 ash::FrameCaptionButtonContainerView::MINIMIZE_ALLOWED); |
| 41 views::View window_icon; | 39 views::View window_icon; |
| 42 window_icon.SetBounds(0, 0, 16, 16); | |
| 43 w->SetBounds(gfx::Rect(0, 0, 500, 500)); | 40 w->SetBounds(gfx::Rect(0, 0, 500, 500)); |
| 44 w->Show(); | 41 w->Show(); |
| 45 | 42 |
| 46 gfx::FontList default_font_list; | 43 DefaultHeaderPainter painter; |
| 47 | 44 painter.Init(w.get(), |
| 48 // 1) Non-browser windows. | 45 w->non_client_view()->frame_view(), |
| 49 HeaderPainter non_browser_painter; | 46 &window_icon, |
| 50 non_browser_painter.Init(HeaderPainter::STYLE_OTHER, | 47 &container); |
| 51 w.get(), | 48 painter.LayoutHeader(); |
| 52 w->non_client_view()->frame_view(), | 49 gfx::Rect title_bounds = painter.GetTitleBounds(); |
| 53 &window_icon, | |
| 54 &container); | |
| 55 non_browser_painter.LayoutHeader(); | |
| 56 gfx::Rect non_browser_header_title_bounds = | |
| 57 non_browser_painter.GetTitleBounds(default_font_list); | |
| 58 EXPECT_EQ(window_icon.bounds().CenterPoint().y(), | 50 EXPECT_EQ(window_icon.bounds().CenterPoint().y(), |
| 59 non_browser_header_title_bounds.CenterPoint().y()); | 51 title_bounds.CenterPoint().y()); |
| 60 | |
| 61 // 2) Non-maximized browser windows. | |
| 62 HeaderPainter browser_painter; | |
| 63 browser_painter.Init(HeaderPainter::STYLE_BROWSER, | |
| 64 w.get(), | |
| 65 w->non_client_view()->frame_view(), | |
| 66 &window_icon, | |
| 67 &container); | |
| 68 browser_painter.LayoutHeader(); | |
| 69 gfx::Rect browser_header_title_bounds = | |
| 70 browser_painter.GetTitleBounds(default_font_list); | |
| 71 EXPECT_EQ(window_icon.bounds().CenterPoint().y(), | |
| 72 browser_header_title_bounds.CenterPoint().y()); | |
| 73 | |
| 74 // 3) Maximized browser windows. | |
| 75 w->Maximize(); | |
| 76 browser_painter.LayoutHeader(); | |
| 77 gfx::Rect maximized_browser_header_title_bounds = | |
| 78 browser_painter.GetTitleBounds(default_font_list); | |
| 79 EXPECT_EQ(window_icon.bounds().CenterPoint().y(), | |
| 80 maximized_browser_header_title_bounds.CenterPoint().y()); | |
| 81 } | 52 } |
| 82 | 53 |
| 83 } // namespace ash | 54 } // namespace ash |
| OLD | NEW |