Chromium Code Reviews| Index: chrome/browser/ui/views/toolbar/reload_button_unittest.cc |
| diff --git a/chrome/browser/ui/views/toolbar/reload_button_unittest.cc b/chrome/browser/ui/views/toolbar/reload_button_unittest.cc |
| index fe705117d469f5e57753b45a2677338f924e621c..531bfe53a6afffe74f6915042aa931d6d0e022e6 100644 |
| --- a/chrome/browser/ui/views/toolbar/reload_button_unittest.cc |
| +++ b/chrome/browser/ui/views/toolbar/reload_button_unittest.cc |
| @@ -2,12 +2,14 @@ |
| // Use of this source code is governed by a BSD-style license that can be |
| // found in the LICENSE file. |
| -#include "base/run_loop.h" |
| #include "chrome/browser/ui/views/toolbar/reload_button.h" |
| + |
| +#include "base/run_loop.h" |
| #include "chrome/test/base/chrome_render_view_host_test_harness.h" |
| #include "chrome/test/base/testing_profile.h" |
| #include "testing/gtest/include/gtest/gtest.h" |
| #include "ui/events/event_utils.h" |
| +#include "ui/views/test/test_views_delegate.h" |
| class ReloadButtonTest : public ChromeRenderViewHostTestHarness { |
| public: |
| @@ -26,7 +28,13 @@ class ReloadButtonTest : public ChromeRenderViewHostTestHarness { |
| int reload_count() { return reload_.testing_reload_count_; } |
| protected: |
| + ReloadButton& reload() { return reload_; } |
|
Peter Kasting
2017/03/03 00:05:55
Nit: I suggest returning a pointer rather than a n
|
| + |
| + private: |
| + views::TestViewsDelegate views_delegate_; |
| ReloadButton reload_; |
| + |
| + DISALLOW_COPY_AND_ASSIGN(ReloadButtonTest); |
| }; |
| ReloadButtonTest::ReloadButtonTest() : reload_(profile(), nullptr) { |
| @@ -59,18 +67,18 @@ TEST_F(ReloadButtonTest, Basic) { |
| // Press the button. This should start the double-click timer. |
| ui::MouseEvent e(ui::ET_MOUSE_PRESSED, gfx::Point(), gfx::Point(), |
| ui::EventTimeForNow(), 0, 0); |
| - reload_.ButtonPressed(&reload_, e); |
| + reload().ButtonPressed(&reload(), e); |
| CheckState(true, ReloadButton::MODE_RELOAD, ReloadButton::MODE_RELOAD, true, |
| false); |
| // Now change the mode (as if the browser had started loading the page). This |
| // should cancel the double-click timer since the button is not hovered. |
| - reload_.ChangeMode(ReloadButton::MODE_STOP, false); |
| + reload().ChangeMode(ReloadButton::MODE_STOP, false); |
| CheckState(true, ReloadButton::MODE_STOP, ReloadButton::MODE_STOP, false, |
| false); |
| // Press the button again. This should change back to reload. |
| - reload_.ButtonPressed(&reload_, e); |
| + reload().ButtonPressed(&reload(), e); |
| CheckState(true, ReloadButton::MODE_RELOAD, ReloadButton::MODE_RELOAD, false, |
| false); |
| } |
| @@ -79,12 +87,12 @@ TEST_F(ReloadButtonTest, DoubleClickTimer) { |
| // Start by pressing the button. |
| ui::MouseEvent e(ui::ET_MOUSE_PRESSED, gfx::Point(), gfx::Point(), |
| ui::EventTimeForNow(), 0, 0); |
| - reload_.ButtonPressed(&reload_, e); |
| + reload().ButtonPressed(&reload(), e); |
| // Try to press the button again. This should do nothing because the timer is |
| // running. |
| int original_reload_count = reload_count(); |
| - reload_.ButtonPressed(&reload_, e); |
| + reload().ButtonPressed(&reload(), e); |
| CheckState(true, ReloadButton::MODE_RELOAD, ReloadButton::MODE_RELOAD, true, |
| false); |
| EXPECT_EQ(original_reload_count, reload_count()); |
| @@ -92,7 +100,7 @@ TEST_F(ReloadButtonTest, DoubleClickTimer) { |
| // Hover the button, and change mode. The visible mode should not change, |
| // again because the timer is running. |
| set_mouse_hovered(true); |
| - reload_.ChangeMode(ReloadButton::MODE_STOP, false); |
| + reload().ChangeMode(ReloadButton::MODE_STOP, false); |
| CheckState(true, ReloadButton::MODE_STOP, ReloadButton::MODE_RELOAD, true, |
| false); |
| @@ -106,13 +114,13 @@ TEST_F(ReloadButtonTest, DisableOnHover) { |
| // Change to stop and hover. |
| ui::MouseEvent e(ui::ET_MOUSE_PRESSED, gfx::Point(), gfx::Point(), |
| ui::EventTimeForNow(), 0, 0); |
| - reload_.ButtonPressed(&reload_, e); |
| - reload_.ChangeMode(ReloadButton::MODE_STOP, false); |
| + reload().ButtonPressed(&reload(), e); |
| + reload().ChangeMode(ReloadButton::MODE_STOP, false); |
| set_mouse_hovered(true); |
| // Now change back to reload. This should result in a disabled stop button |
| // due to the hover. |
| - reload_.ChangeMode(ReloadButton::MODE_RELOAD, false); |
| + reload().ChangeMode(ReloadButton::MODE_RELOAD, false); |
| CheckState(false, ReloadButton::MODE_RELOAD, ReloadButton::MODE_STOP, false, |
| true); |
| @@ -120,7 +128,7 @@ TEST_F(ReloadButtonTest, DisableOnHover) { |
| set_mouse_hovered(false); |
| ui::MouseEvent e2(ui::ET_MOUSE_MOVED, gfx::Point(), gfx::Point(), |
| ui::EventTimeForNow(), 0, 0); |
| - reload_.OnMouseExited(e2); |
| + reload().OnMouseExited(e2); |
| CheckState(true, ReloadButton::MODE_RELOAD, ReloadButton::MODE_RELOAD, false, |
| false); |
| } |
| @@ -129,13 +137,13 @@ TEST_F(ReloadButtonTest, ResetOnClick) { |
| // Change to stop and hover. |
| ui::MouseEvent e(ui::ET_MOUSE_PRESSED, gfx::Point(), gfx::Point(), |
| ui::EventTimeForNow(), 0, 0); |
| - reload_.ButtonPressed(&reload_, e); |
| - reload_.ChangeMode(ReloadButton::MODE_STOP, false); |
| + reload().ButtonPressed(&reload(), e); |
| + reload().ChangeMode(ReloadButton::MODE_STOP, false); |
| set_mouse_hovered(true); |
| // Press the button. This should change back to reload despite the hover, |
| // because it's a direct user action. |
| - reload_.ButtonPressed(&reload_, e); |
| + reload().ButtonPressed(&reload(), e); |
| CheckState(true, ReloadButton::MODE_RELOAD, ReloadButton::MODE_RELOAD, false, |
| false); |
| } |
| @@ -144,10 +152,10 @@ TEST_F(ReloadButtonTest, ResetOnTimer) { |
| // Change to stop, hover, and change back to reload. |
| ui::MouseEvent e(ui::ET_MOUSE_PRESSED, gfx::Point(), gfx::Point(), |
| ui::EventTimeForNow(), 0, 0); |
| - reload_.ButtonPressed(&reload_, e); |
| - reload_.ChangeMode(ReloadButton::MODE_STOP, false); |
| + reload().ButtonPressed(&reload(), e); |
| + reload().ChangeMode(ReloadButton::MODE_STOP, false); |
| set_mouse_hovered(true); |
| - reload_.ChangeMode(ReloadButton::MODE_RELOAD, false); |
| + reload().ChangeMode(ReloadButton::MODE_RELOAD, false); |
| // Now fire the stop-to-reload timer. This should reset the button. |
| base::RunLoop().RunUntilIdle(); |