This source file includes following definitions.
- set_mouse_hovered
- reload_count
- fake_mouse_leave
- CheckState
- TEST_F
- TEST_F
- TEST_F
- TEST_F
- TEST_F
#include "base/message_loop/message_loop.h"
#include "chrome/browser/ui/gtk/reload_button_gtk.h"
#include "testing/gtest/include/gtest/gtest.h"
class ReloadButtonGtkTest : public testing::Test {
public:
ReloadButtonGtkTest();
void CheckState(bool enabled,
ReloadButtonGtk::Mode intended_mode,
ReloadButtonGtk::Mode visible_mode,
bool double_click_timer_running,
bool stop_to_reload_timer_running);
void set_mouse_hovered(bool hovered) {
reload_.testing_mouse_hovered_ = hovered;
}
int reload_count() { return reload_.testing_reload_count_; }
void fake_mouse_leave() { reload_.OnLeaveNotify(reload_.widget(), NULL); }
protected:
base::MessageLoop loop_;
ReloadButtonGtk reload_;
};
ReloadButtonGtkTest::ReloadButtonGtkTest() : reload_(NULL, NULL) {
reload_.double_click_timer_delay_ = base::TimeDelta();
reload_.stop_to_reload_timer_delay_ = base::TimeDelta();
}
void ReloadButtonGtkTest::CheckState(bool enabled,
ReloadButtonGtk::Mode intended_mode,
ReloadButtonGtk::Mode visible_mode,
bool double_click_timer_running,
bool stop_to_reload_timer_running) {
EXPECT_NE(enabled, reload_.stop_.paint_override() == GTK_STATE_INSENSITIVE);
EXPECT_EQ(intended_mode, reload_.intended_mode_);
EXPECT_EQ(visible_mode, reload_.visible_mode_);
EXPECT_EQ(double_click_timer_running,
reload_.double_click_timer_.IsRunning());
EXPECT_EQ(stop_to_reload_timer_running,
reload_.stop_to_reload_timer_.IsRunning());
}
TEST_F(ReloadButtonGtkTest, Basic) {
CheckState(true, ReloadButtonGtk::MODE_RELOAD, ReloadButtonGtk::MODE_RELOAD,
false, false);
gtk_button_clicked(GTK_BUTTON(reload_.widget()));
CheckState(true, ReloadButtonGtk::MODE_RELOAD, ReloadButtonGtk::MODE_RELOAD,
true, false);
reload_.ChangeMode(ReloadButtonGtk::MODE_STOP, false);
CheckState(true, ReloadButtonGtk::MODE_STOP, ReloadButtonGtk::MODE_STOP,
false, false);
gtk_button_clicked(GTK_BUTTON(reload_.widget()));
CheckState(true, ReloadButtonGtk::MODE_RELOAD, ReloadButtonGtk::MODE_RELOAD,
false, false);
}
TEST_F(ReloadButtonGtkTest, DoubleClickTimer) {
gtk_button_clicked(GTK_BUTTON(reload_.widget()));
int original_reload_count = reload_count();
gtk_button_clicked(GTK_BUTTON(reload_.widget()));
CheckState(true, ReloadButtonGtk::MODE_RELOAD, ReloadButtonGtk::MODE_RELOAD,
true, false);
EXPECT_EQ(original_reload_count, reload_count());
set_mouse_hovered(true);
reload_.ChangeMode(ReloadButtonGtk::MODE_STOP, false);
CheckState(true, ReloadButtonGtk::MODE_STOP, ReloadButtonGtk::MODE_RELOAD,
true, false);
loop_.RunUntilIdle();
CheckState(true, ReloadButtonGtk::MODE_STOP, ReloadButtonGtk::MODE_STOP,
false, false);
}
TEST_F(ReloadButtonGtkTest, DisableOnHover) {
gtk_button_clicked(GTK_BUTTON(reload_.widget()));
reload_.ChangeMode(ReloadButtonGtk::MODE_STOP, false);
set_mouse_hovered(true);
reload_.ChangeMode(ReloadButtonGtk::MODE_RELOAD, false);
CheckState(false, ReloadButtonGtk::MODE_RELOAD, ReloadButtonGtk::MODE_STOP,
false, true);
set_mouse_hovered(false);
fake_mouse_leave();
CheckState(true, ReloadButtonGtk::MODE_RELOAD, ReloadButtonGtk::MODE_RELOAD,
false, false);
}
TEST_F(ReloadButtonGtkTest, ResetOnClick) {
gtk_button_clicked(GTK_BUTTON(reload_.widget()));
reload_.ChangeMode(ReloadButtonGtk::MODE_STOP, false);
set_mouse_hovered(true);
gtk_button_clicked(GTK_BUTTON(reload_.widget()));
CheckState(true, ReloadButtonGtk::MODE_RELOAD, ReloadButtonGtk::MODE_RELOAD,
false, false);
}
TEST_F(ReloadButtonGtkTest, ResetOnTimer) {
gtk_button_clicked(GTK_BUTTON(reload_.widget()));
reload_.ChangeMode(ReloadButtonGtk::MODE_STOP, false);
set_mouse_hovered(true);
reload_.ChangeMode(ReloadButtonGtk::MODE_RELOAD, false);
loop_.RunUntilIdle();
CheckState(true, ReloadButtonGtk::MODE_RELOAD, ReloadButtonGtk::MODE_RELOAD,
false, false);
}