Upstream version 5.34.104.0
[platform/framework/web/crosswalk.git] / src / ash / wm / custom_frame_view_ash_unittest.cc
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
3 // found in the LICENSE file.
4
5 #include "ash/wm/custom_frame_view_ash.h"
6
7 #include "ash/test/ash_test_base.h"
8 #include "base/memory/scoped_ptr.h"
9 #include "grit/ash_resources.h"
10 #include "ui/base/resource/resource_bundle.h"
11 #include "ui/gfx/image/image_skia.h"
12 #include "ui/views/widget/widget.h"
13 #include "ui/views/widget/widget_delegate.h"
14
15 namespace ash {
16
17 namespace {
18
19 // A views::WidgetDelegate which uses a CustomFrameViewAsh.
20 class TestWidgetDelegate : public views::WidgetDelegateView {
21  public:
22   TestWidgetDelegate() {
23   }
24   virtual ~TestWidgetDelegate() {
25   }
26
27   virtual views::NonClientFrameView* CreateNonClientFrameView(
28       views::Widget* widget) OVERRIDE {
29     custom_frame_view_ = new CustomFrameViewAsh(widget);
30     return custom_frame_view_;
31   }
32
33   CustomFrameViewAsh* custom_frame_view() {
34     return custom_frame_view_;
35   }
36
37  private:
38   // Not owned.
39   CustomFrameViewAsh* custom_frame_view_;
40
41   DISALLOW_COPY_AND_ASSIGN(TestWidgetDelegate);
42 };
43
44 }  // namespace
45
46 typedef test::AshTestBase CustomFrameViewAshTest;
47
48 // Test that the height of the header is correct upon initially displaying
49 // the widget.
50 TEST_F(CustomFrameViewAshTest, HeaderHeight) {
51   TestWidgetDelegate* delegate = new TestWidgetDelegate;
52
53   scoped_ptr<views::Widget> widget(new views::Widget);
54   views::Widget::InitParams params;
55   params.delegate = delegate;
56   params.ownership = views::Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET;
57   params.bounds = gfx::Rect(0, 0, 100, 100);
58   params.context = CurrentContext();
59   widget->Init(params);
60   widget->Show();
61
62   ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance();
63   gfx::ImageSkia* close_button =
64       rb.GetImageSkiaNamed(IDR_AURA_WINDOW_MAXIMIZED_CLOSE);
65
66   // |kSeparatorSize| should match |kHeaderContentSeparatorSize| in
67   // header_painter.cc
68   // TODO(pkotwicz): Clean this test up once the separator overlays the window
69   // controls.
70   const int kSeparatorSize = 1;
71
72   // The header should have enough room for the window controls and the
73   // separator line.
74   EXPECT_EQ(close_button->height() + kSeparatorSize,
75             delegate->custom_frame_view()->GetHeaderView()->height());
76
77   widget->Maximize();
78   close_button = rb.GetImageSkiaNamed(IDR_AURA_WINDOW_MAXIMIZED_CLOSE2);
79   EXPECT_EQ(close_button->height() + kSeparatorSize,
80             delegate->custom_frame_view()->GetHeaderView()->height());
81 }
82
83 }  // namespace ash