summaryrefslogtreecommitdiffstats
path: root/ash/frame/default_header_painter_unittest.cc
blob: 69225b068325be19e357b05053883ae95a36c2f2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
// Copyright 2014 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "ash/frame/default_header_painter.h"

#include "ash/frame/caption_buttons/frame_caption_button_container_view.h"
#include "ash/shell.h"
#include "ash/test/ash_test_base.h"
#include "ash/wm/window_state.h"
#include "base/memory/scoped_ptr.h"
#include "ui/gfx/font_list.h"
#include "ui/views/test/test_views.h"
#include "ui/views/widget/widget.h"
#include "ui/views/window/non_client_view.h"

using ash::HeaderPainter;
using views::NonClientFrameView;
using views::Widget;

namespace ash {

class DefaultHeaderPainterTest : public ash::test::AshTestBase {
 public:
  // Creates a test widget that owns its native widget.
  Widget* CreateTestWidget() {
    Widget* widget = new Widget;
    Widget::InitParams params;
    params.ownership = Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET;
    params.context = CurrentContext();
    widget->Init(params);
    return widget;
  }
};

// Ensure the title text is vertically aligned with the window icon.
TEST_F(DefaultHeaderPainterTest, TitleIconAlignment) {
  scoped_ptr<Widget> w(CreateTestWidget());
  ash::FrameCaptionButtonContainerView container(w.get());
  views::StaticSizedView window_icon(gfx::Size(16, 16));
  window_icon.SetBounds(0, 0, 16, 16);
  w->SetBounds(gfx::Rect(0, 0, 500, 500));
  w->Show();

  DefaultHeaderPainter painter;
  painter.Init(w.get(),
               w->non_client_view()->frame_view(),
               &container);
  painter.UpdateLeftHeaderView(&window_icon);
  painter.LayoutHeader();
  gfx::Rect title_bounds = painter.GetTitleBounds();
  EXPECT_EQ(window_icon.bounds().CenterPoint().y(),
            title_bounds.CenterPoint().y());
}

// Ensure the light icons are used when appropriate.
TEST_F(DefaultHeaderPainterTest, LightIcons) {
  scoped_ptr<Widget> w(CreateTestWidget());
  ash::FrameCaptionButtonContainerView container(w.get());
  views::StaticSizedView window_icon(gfx::Size(16, 16));
  window_icon.SetBounds(0, 0, 16, 16);
  w->SetBounds(gfx::Rect(0, 0, 500, 500));
  w->Show();

  DefaultHeaderPainter painter;
  painter.Init(w.get(), w->non_client_view()->frame_view(), &container);

  // Check by default light icons are not used.
  painter.mode_ = HeaderPainter::MODE_ACTIVE;
  EXPECT_FALSE(painter.ShouldUseLightImages());
  painter.mode_ = HeaderPainter::MODE_INACTIVE;
  EXPECT_FALSE(painter.ShouldUseLightImages());

  // Check that setting dark colors should use light icons.
  painter.SetFrameColors(SkColorSetRGB(0, 0, 0), SkColorSetRGB(0, 0, 0));
  painter.mode_ = HeaderPainter::MODE_ACTIVE;
  EXPECT_TRUE(painter.ShouldUseLightImages());
  painter.mode_ = HeaderPainter::MODE_INACTIVE;
  EXPECT_TRUE(painter.ShouldUseLightImages());

  // Check that inactive and active colors are used properly.
  painter.SetFrameColors(SkColorSetRGB(0, 0, 0), SkColorSetRGB(255, 255, 255));
  painter.mode_ = HeaderPainter::MODE_ACTIVE;
  EXPECT_TRUE(painter.ShouldUseLightImages());
  painter.mode_ = HeaderPainter::MODE_INACTIVE;
  EXPECT_FALSE(painter.ShouldUseLightImages());

  // Check not so light or dark colors.
  painter.SetFrameColors(SkColorSetRGB(70, 70, 70),
                         SkColorSetRGB(200, 200, 200));
  painter.mode_ = HeaderPainter::MODE_ACTIVE;
  EXPECT_TRUE(painter.ShouldUseLightImages());
  painter.mode_ = HeaderPainter::MODE_INACTIVE;
  EXPECT_FALSE(painter.ShouldUseLightImages());
}

}  // namespace ash