This source file includes following definitions.
- set_mouse_hovered
- reload_count
- CheckState
- TEST_F
- TEST_F
- TEST_F
- TEST_F
- TEST_F
#include "base/message_loop/message_loop.h"
#include "chrome/browser/ui/views/toolbar/reload_button.h"
#include "testing/gtest/include/gtest/gtest.h"
class ReloadButtonTest : public testing::Test {
public:
ReloadButtonTest();
void CheckState(bool enabled,
ReloadButton::Mode intended_mode,
ReloadButton::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_; }
protected:
base::MessageLoop loop_;
ReloadButton reload_;
};
ReloadButtonTest::ReloadButtonTest() : reload_(NULL, NULL) {
reload_.double_click_timer_delay_ = base::TimeDelta();
reload_.stop_to_reload_timer_delay_ = base::TimeDelta();
}
void ReloadButtonTest::CheckState(bool enabled,
ReloadButton::Mode intended_mode,
ReloadButton::Mode visible_mode,
bool double_click_timer_running,
bool stop_to_reload_timer_running) {
EXPECT_EQ(enabled, reload_.enabled());
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(ReloadButtonTest, Basic) {
CheckState(true, ReloadButton::MODE_RELOAD, ReloadButton::MODE_RELOAD, false,
false);
ui::MouseEvent e(ui::ET_MOUSE_PRESSED, gfx::Point(), gfx::Point(), 0, 0);
reload_.ButtonPressed(&reload_, e);
CheckState(true, ReloadButton::MODE_RELOAD, ReloadButton::MODE_RELOAD, true,
false);
reload_.ChangeMode(ReloadButton::MODE_STOP, false);
CheckState(true, ReloadButton::MODE_STOP, ReloadButton::MODE_STOP, false,
false);
reload_.ButtonPressed(&reload_, e);
CheckState(true, ReloadButton::MODE_RELOAD, ReloadButton::MODE_RELOAD, false,
false);
}
TEST_F(ReloadButtonTest, DoubleClickTimer) {
ui::MouseEvent e(ui::ET_MOUSE_PRESSED, gfx::Point(), gfx::Point(), 0, 0);
reload_.ButtonPressed(&reload_, e);
int original_reload_count = reload_count();
reload_.ButtonPressed(&reload_, e);
CheckState(true, ReloadButton::MODE_RELOAD, ReloadButton::MODE_RELOAD, true,
false);
EXPECT_EQ(original_reload_count, reload_count());
set_mouse_hovered(true);
reload_.ChangeMode(ReloadButton::MODE_STOP, false);
CheckState(true, ReloadButton::MODE_STOP, ReloadButton::MODE_RELOAD, true,
false);
loop_.RunUntilIdle();
CheckState(true, ReloadButton::MODE_STOP, ReloadButton::MODE_STOP, false,
false);
}
TEST_F(ReloadButtonTest, DisableOnHover) {
ui::MouseEvent e(ui::ET_MOUSE_PRESSED, gfx::Point(), gfx::Point(), 0, 0);
reload_.ButtonPressed(&reload_, e);
reload_.ChangeMode(ReloadButton::MODE_STOP, false);
set_mouse_hovered(true);
reload_.ChangeMode(ReloadButton::MODE_RELOAD, false);
CheckState(false, ReloadButton::MODE_RELOAD, ReloadButton::MODE_STOP, false,
true);
set_mouse_hovered(false);
ui::MouseEvent e2(ui::ET_MOUSE_MOVED, gfx::Point(), gfx::Point(), 0, 0);
reload_.OnMouseExited(e2);
CheckState(true, ReloadButton::MODE_RELOAD, ReloadButton::MODE_RELOAD, false,
false);
}
TEST_F(ReloadButtonTest, ResetOnClick) {
ui::MouseEvent e(ui::ET_MOUSE_PRESSED, gfx::Point(), gfx::Point(), 0, 0);
reload_.ButtonPressed(&reload_, e);
reload_.ChangeMode(ReloadButton::MODE_STOP, false);
set_mouse_hovered(true);
reload_.ButtonPressed(&reload_, e);
CheckState(true, ReloadButton::MODE_RELOAD, ReloadButton::MODE_RELOAD, false,
false);
}
TEST_F(ReloadButtonTest, ResetOnTimer) {
ui::MouseEvent e(ui::ET_MOUSE_PRESSED, gfx::Point(), gfx::Point(), 0, 0);
reload_.ButtonPressed(&reload_, e);
reload_.ChangeMode(ReloadButton::MODE_STOP, false);
set_mouse_hovered(true);
reload_.ChangeMode(ReloadButton::MODE_RELOAD, false);
loop_.RunUntilIdle();
CheckState(true, ReloadButton::MODE_RELOAD, ReloadButton::MODE_RELOAD, false,
false);
}