summaryrefslogtreecommitdiffstats
path: root/chrome/browser/gtk/go_button_gtk_unittest.cc
blob: 2e2f02727160680c23c0561e0e48ab50c41d9e66 (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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
// Copyright (c) 2009 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 "chrome/browser/gtk/go_button_gtk.h"
#include "base/task.h"
#include "testing/gtest/include/gtest/gtest.h"

class GoButtonGtkPeer {
 public:
  explicit GoButtonGtkPeer(GoButtonGtk* go) : go_(go) { }

  // const accessors for internal state
  GoButtonGtk::Mode intended_mode() const { return go_->intended_mode_; }
  GoButtonGtk::Mode visible_mode() const { return go_->visible_mode_; }

  // mutable accessors for internal state
  ScopedRunnableMethodFactory<GoButtonGtk>* stop_timer() {
    return &go_->stop_timer_;
  }

  // mutators for internal state
  void set_state(GoButtonGtk::ButtonState state) { go_->state_ = state; }
  void set_intended_mode(GoButtonGtk::Mode mode) { go_->intended_mode_ = mode; }
  void set_visible_mode(GoButtonGtk::Mode mode) { go_->visible_mode_ = mode; }

  // forwarders to private methods
  Task* CreateButtonTimerTask() { return go_->CreateButtonTimerTask(); }
  gboolean OnLeave() {
    return GoButtonGtk::OnLeave(GTK_BUTTON(go_->widget()), go_);
  }

  gboolean OnClicked() {
    return GoButtonGtk::OnClicked(GTK_BUTTON(go_->widget()), go_);
  }

 private:
  GoButtonGtk* const go_;
};

namespace {

class GoButtonGtkTest : public testing::Test {
 protected:
  GoButtonGtkTest() : go_(NULL, NULL), peer_(&go_) { }

 protected:
  GoButtonGtk go_;
  GoButtonGtkPeer peer_;
};

TEST_F(GoButtonGtkTest, ChangeModeGo) {
  go_.ChangeMode(GoButtonGtk::MODE_GO, true);
  EXPECT_EQ(GoButtonGtk::MODE_GO, peer_.intended_mode());
  EXPECT_EQ(GoButtonGtk::MODE_GO, peer_.visible_mode());
}

TEST_F(GoButtonGtkTest, ChangeModeStop) {
  go_.ChangeMode(GoButtonGtk::MODE_STOP, true);
  EXPECT_EQ(GoButtonGtk::MODE_STOP, peer_.intended_mode());
  EXPECT_EQ(GoButtonGtk::MODE_STOP, peer_.visible_mode());
}

TEST_F(GoButtonGtkTest, ScheduleChangeModeNormalGo) {
  peer_.set_visible_mode(GoButtonGtk::MODE_STOP);
  peer_.set_state(GoButtonGtk::BS_NORMAL);
  go_.ChangeMode(GoButtonGtk::MODE_GO, false);
  EXPECT_EQ(GoButtonGtk::MODE_GO, peer_.intended_mode());
  EXPECT_EQ(GoButtonGtk::MODE_GO, peer_.visible_mode());
}

TEST_F(GoButtonGtkTest, ScheduleChangeModeHotGo) {
  peer_.set_visible_mode(GoButtonGtk::MODE_STOP);
  peer_.set_state(GoButtonGtk::BS_HOT);
  go_.ChangeMode(GoButtonGtk::MODE_GO, false);
  EXPECT_EQ(GoButtonGtk::MODE_GO, peer_.intended_mode());
  EXPECT_EQ(GoButtonGtk::MODE_STOP, peer_.visible_mode());
}

TEST_F(GoButtonGtkTest, ScheduleChangeModeNormalStop) {
  peer_.set_visible_mode(GoButtonGtk::MODE_GO);
  peer_.set_state(GoButtonGtk::BS_NORMAL);
  go_.ChangeMode(GoButtonGtk::MODE_STOP, false);
  EXPECT_EQ(GoButtonGtk::MODE_STOP, peer_.intended_mode());
  EXPECT_EQ(GoButtonGtk::MODE_STOP, peer_.visible_mode());
}

TEST_F(GoButtonGtkTest, ScheduleChangeModeHotStop) {
  peer_.set_visible_mode(GoButtonGtk::MODE_GO);
  peer_.set_state(GoButtonGtk::BS_HOT);
  go_.ChangeMode(GoButtonGtk::MODE_STOP, false);
  EXPECT_EQ(GoButtonGtk::MODE_STOP, peer_.intended_mode());
  EXPECT_EQ(GoButtonGtk::MODE_STOP, peer_.visible_mode());
}

TEST_F(GoButtonGtkTest, ScheduleChangeModeTimerHotStop) {
  peer_.set_visible_mode(GoButtonGtk::MODE_GO);
  peer_.set_state(GoButtonGtk::BS_HOT);
  scoped_ptr<Task> task(peer_.CreateButtonTimerTask());
  go_.ChangeMode(GoButtonGtk::MODE_STOP, false);
  EXPECT_EQ(GoButtonGtk::MODE_STOP, peer_.intended_mode());
  EXPECT_EQ(GoButtonGtk::MODE_GO, peer_.visible_mode());
}

TEST_F(GoButtonGtkTest, OnLeaveIntendedStop) {
  peer_.set_state(GoButtonGtk::BS_HOT);
  peer_.set_visible_mode(GoButtonGtk::MODE_GO);
  peer_.set_intended_mode(GoButtonGtk::MODE_STOP);
  EXPECT_TRUE(peer_.OnLeave());
  EXPECT_EQ(GoButtonGtk::MODE_STOP, peer_.visible_mode());
  EXPECT_EQ(GoButtonGtk::MODE_STOP, peer_.intended_mode());
}

TEST_F(GoButtonGtkTest, OnLeaveIntendedGo) {
  peer_.set_state(GoButtonGtk::BS_HOT);
  peer_.set_visible_mode(GoButtonGtk::MODE_STOP);
  peer_.set_intended_mode(GoButtonGtk::MODE_GO);
  EXPECT_TRUE(peer_.OnLeave());
  EXPECT_EQ(GoButtonGtk::MODE_GO, peer_.visible_mode());
  EXPECT_EQ(GoButtonGtk::MODE_GO, peer_.intended_mode());
}

TEST_F(GoButtonGtkTest, OnClickedStop) {
  peer_.set_visible_mode(GoButtonGtk::MODE_STOP);
  EXPECT_TRUE(peer_.OnClicked());
  EXPECT_EQ(GoButtonGtk::MODE_GO, peer_.visible_mode());
  EXPECT_EQ(GoButtonGtk::MODE_GO, peer_.intended_mode());
}

}  // namespace