summaryrefslogtreecommitdiffstats
path: root/ash/system/date/date_view_unittest.cc
blob: 931d220694e40beaef775f6f6f33fec526777f2e (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
// Copyright 2013 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/system/date/date_view.h"

#include "ash/test/ash_test_base.h"
#include "ui/views/controls/label.h"

namespace ash {
namespace internal {
namespace tray {

class TimeViewTest : public ash::test::AshTestBase {
 public:
  TimeViewTest() {}
  virtual ~TimeViewTest() {}

  TimeView* time_view() { return time_view_.get(); }

  // Access to private fields of |time_view_|.
  views::Label* horizontal_label() {
    return time_view_->horizontal_label_.get();
  }
  views::Label* vertical_label_hours() {
    return time_view_->vertical_label_hours_.get();
  }
  views::Label* vertical_label_minutes() {
    return time_view_->vertical_label_minutes_.get();
  }

  // Creates a time view with horizontal or vertical |clock_layout|.
  void CreateTimeView(TrayDate::ClockLayout clock_layout) {
    time_view_.reset(new TimeView(clock_layout));
  }

 private:
  scoped_ptr<TimeView> time_view_;

  DISALLOW_COPY_AND_ASSIGN(TimeViewTest);
};

// Test the basics of the time view, mostly to ensure we don't leak memory.
TEST_F(TimeViewTest, Basics) {
  // A newly created horizontal clock only has the horizontal label.
  CreateTimeView(TrayDate::HORIZONTAL_CLOCK);
  EXPECT_EQ(time_view(), horizontal_label()->parent());
  EXPECT_FALSE(vertical_label_hours()->parent());
  EXPECT_FALSE(vertical_label_minutes()->parent());

  // Switching the clock to vertical updates the labels.
  time_view()->UpdateClockLayout(TrayDate::VERTICAL_CLOCK);
  EXPECT_FALSE(horizontal_label()->parent());
  EXPECT_EQ(time_view(), vertical_label_hours()->parent());
  EXPECT_EQ(time_view(), vertical_label_minutes()->parent());

  // Switching back to horizontal updates the labels again.
  time_view()->UpdateClockLayout(TrayDate::HORIZONTAL_CLOCK);
  EXPECT_EQ(time_view(), horizontal_label()->parent());
  EXPECT_FALSE(vertical_label_hours()->parent());
  EXPECT_FALSE(vertical_label_minutes()->parent());
}

}  // namespace tray
}  // namespace internal
}  // namespace ash