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
131
132
133
134
135
136
137
138
|
// Copyright (c) 2010 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/reload_button_gtk.h"
#include "testing/gtest/include/gtest/gtest.h"
class ReloadButtonGtkPeer {
public:
explicit ReloadButtonGtkPeer(ReloadButtonGtk* reload) : reload_(reload) { }
// const accessors for internal state
ReloadButtonGtk::Mode intended_mode() const {
return reload_->intended_mode_;
}
ReloadButtonGtk::Mode visible_mode() const { return reload_->visible_mode_; }
// mutators for internal state
void SetState(GtkStateType state) {
gtk_widget_set_state(reload_->widget(), state);
}
void set_intended_mode(ReloadButtonGtk::Mode mode) {
reload_->intended_mode_ = mode;
}
void set_visible_mode(ReloadButtonGtk::Mode mode) {
reload_->visible_mode_ = mode;
}
void set_timer_running() {
reload_->pretend_timer_is_running_for_unittest_ = true;
}
void set_timer_stopped() {
reload_->pretend_timer_is_running_for_unittest_ = false;
}
// forwarders to private methods
gboolean OnLeave() {
return reload_->OnLeaveNotify(reload_->widget(), NULL);
}
void OnClicked() {
reload_->OnClicked(reload_->widget());
}
private:
ReloadButtonGtk* const reload_;
};
namespace {
class ReloadButtonGtkTest : public testing::Test {
protected:
ReloadButtonGtkTest() : reload_(NULL, NULL), peer_(&reload_) { }
protected:
ReloadButtonGtk reload_;
ReloadButtonGtkPeer peer_;
};
TEST_F(ReloadButtonGtkTest, ChangeModeReload) {
reload_.ChangeMode(ReloadButtonGtk::MODE_RELOAD, true);
EXPECT_EQ(ReloadButtonGtk::MODE_RELOAD, peer_.intended_mode());
EXPECT_EQ(ReloadButtonGtk::MODE_RELOAD, peer_.visible_mode());
}
TEST_F(ReloadButtonGtkTest, ChangeModeStop) {
reload_.ChangeMode(ReloadButtonGtk::MODE_STOP, true);
EXPECT_EQ(ReloadButtonGtk::MODE_STOP, peer_.intended_mode());
EXPECT_EQ(ReloadButtonGtk::MODE_STOP, peer_.visible_mode());
}
TEST_F(ReloadButtonGtkTest, ScheduleChangeModeNormalReload) {
peer_.set_visible_mode(ReloadButtonGtk::MODE_STOP);
peer_.SetState(GTK_STATE_NORMAL);
reload_.ChangeMode(ReloadButtonGtk::MODE_RELOAD, false);
EXPECT_EQ(ReloadButtonGtk::MODE_RELOAD, peer_.intended_mode());
EXPECT_EQ(ReloadButtonGtk::MODE_RELOAD, peer_.visible_mode());
}
TEST_F(ReloadButtonGtkTest, ScheduleChangeModeHotReload) {
peer_.set_visible_mode(ReloadButtonGtk::MODE_STOP);
peer_.SetState(GTK_STATE_PRELIGHT);
reload_.ChangeMode(ReloadButtonGtk::MODE_RELOAD, false);
EXPECT_EQ(ReloadButtonGtk::MODE_RELOAD, peer_.intended_mode());
EXPECT_EQ(ReloadButtonGtk::MODE_STOP, peer_.visible_mode());
}
TEST_F(ReloadButtonGtkTest, ScheduleChangeModeNormalStop) {
peer_.set_visible_mode(ReloadButtonGtk::MODE_RELOAD);
peer_.SetState(GTK_STATE_NORMAL);
reload_.ChangeMode(ReloadButtonGtk::MODE_STOP, false);
EXPECT_EQ(ReloadButtonGtk::MODE_STOP, peer_.intended_mode());
EXPECT_EQ(ReloadButtonGtk::MODE_STOP, peer_.visible_mode());
}
TEST_F(ReloadButtonGtkTest, ScheduleChangeModeHotStop) {
peer_.set_visible_mode(ReloadButtonGtk::MODE_RELOAD);
peer_.SetState(GTK_STATE_PRELIGHT);
reload_.ChangeMode(ReloadButtonGtk::MODE_STOP, false);
EXPECT_EQ(ReloadButtonGtk::MODE_STOP, peer_.intended_mode());
EXPECT_EQ(ReloadButtonGtk::MODE_STOP, peer_.visible_mode());
}
TEST_F(ReloadButtonGtkTest, ScheduleChangeModeTimerHotStop) {
peer_.set_visible_mode(ReloadButtonGtk::MODE_RELOAD);
peer_.SetState(GTK_STATE_PRELIGHT);
peer_.set_timer_running();
reload_.ChangeMode(ReloadButtonGtk::MODE_STOP, false);
peer_.set_timer_stopped();
EXPECT_EQ(ReloadButtonGtk::MODE_STOP, peer_.intended_mode());
EXPECT_EQ(ReloadButtonGtk::MODE_RELOAD, peer_.visible_mode());
}
TEST_F(ReloadButtonGtkTest, OnLeaveIntendedStop) {
peer_.SetState(GTK_STATE_PRELIGHT);
peer_.set_visible_mode(ReloadButtonGtk::MODE_RELOAD);
peer_.set_intended_mode(ReloadButtonGtk::MODE_STOP);
peer_.OnLeave();
EXPECT_EQ(ReloadButtonGtk::MODE_STOP, peer_.visible_mode());
EXPECT_EQ(ReloadButtonGtk::MODE_STOP, peer_.intended_mode());
}
TEST_F(ReloadButtonGtkTest, OnLeaveIntendedReload) {
peer_.SetState(GTK_STATE_PRELIGHT);
peer_.set_visible_mode(ReloadButtonGtk::MODE_STOP);
peer_.set_intended_mode(ReloadButtonGtk::MODE_RELOAD);
peer_.OnLeave();
EXPECT_EQ(ReloadButtonGtk::MODE_RELOAD, peer_.visible_mode());
EXPECT_EQ(ReloadButtonGtk::MODE_RELOAD, peer_.intended_mode());
}
TEST_F(ReloadButtonGtkTest, OnClickedStop) {
peer_.set_visible_mode(ReloadButtonGtk::MODE_STOP);
peer_.OnClicked();
EXPECT_EQ(ReloadButtonGtk::MODE_RELOAD, peer_.visible_mode());
EXPECT_EQ(ReloadButtonGtk::MODE_RELOAD, peer_.intended_mode());
}
} // namespace
|