| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "base/message_loop/message_loop.h" | 5 #include "base/message_loop/message_loop.h" |
| 6 #include "chrome/browser/ui/views/toolbar/reload_button.h" | 6 #include "chrome/browser/ui/views/toolbar/reload_button.h" |
| 7 #include "chrome/test/base/chrome_render_view_host_test_harness.h" |
| 8 #include "chrome/test/base/testing_profile.h" |
| 7 #include "testing/gtest/include/gtest/gtest.h" | 9 #include "testing/gtest/include/gtest/gtest.h" |
| 8 #include "ui/events/event_utils.h" | 10 #include "ui/events/event_utils.h" |
| 9 | 11 |
| 10 class ReloadButtonTest : public testing::Test { | 12 class ReloadButtonTest : public ChromeRenderViewHostTestHarness { |
| 11 public: | 13 public: |
| 12 ReloadButtonTest(); | 14 ReloadButtonTest(); |
| 13 | 15 |
| 14 void CheckState(bool enabled, | 16 void CheckState(bool enabled, |
| 15 ReloadButton::Mode intended_mode, | 17 ReloadButton::Mode intended_mode, |
| 16 ReloadButton::Mode visible_mode, | 18 ReloadButton::Mode visible_mode, |
| 17 bool double_click_timer_running, | 19 bool double_click_timer_running, |
| 18 bool stop_to_reload_timer_running); | 20 bool stop_to_reload_timer_running); |
| 19 | 21 |
| 20 // These accessors eliminate the need to declare each testcase as a friend. | 22 // These accessors eliminate the need to declare each testcase as a friend. |
| 21 void set_mouse_hovered(bool hovered) { | 23 void set_mouse_hovered(bool hovered) { |
| 22 reload_.testing_mouse_hovered_ = hovered; | 24 reload_.testing_mouse_hovered_ = hovered; |
| 23 } | 25 } |
| 24 int reload_count() { return reload_.testing_reload_count_; } | 26 int reload_count() { return reload_.testing_reload_count_; } |
| 25 | 27 |
| 26 protected: | 28 protected: |
| 27 // We need a message loop for the timers to post events. | 29 // We need a message loop for the timers to post events. |
| 28 base::MessageLoop loop_; | 30 base::MessageLoop loop_; |
| 29 | 31 |
| 30 ReloadButton reload_; | 32 ReloadButton reload_; |
| 31 }; | 33 }; |
| 32 | 34 |
| 33 ReloadButtonTest::ReloadButtonTest() : reload_(NULL) { | 35 ReloadButtonTest::ReloadButtonTest() : reload_(profile(), nullptr) { |
| 34 // Set the timer delays to 0 so that timers will fire as soon as we tell the | 36 // Set the timer delays to 0 so that timers will fire as soon as we tell the |
| 35 // message loop to run pending tasks. | 37 // message loop to run pending tasks. |
| 36 reload_.double_click_timer_delay_ = base::TimeDelta(); | 38 reload_.double_click_timer_delay_ = base::TimeDelta(); |
| 37 reload_.stop_to_reload_timer_delay_ = base::TimeDelta(); | 39 reload_.stop_to_reload_timer_delay_ = base::TimeDelta(); |
| 38 } | 40 } |
| 39 | 41 |
| 40 void ReloadButtonTest::CheckState(bool enabled, | 42 void ReloadButtonTest::CheckState(bool enabled, |
| 41 ReloadButton::Mode intended_mode, | 43 ReloadButton::Mode intended_mode, |
| 42 ReloadButton::Mode visible_mode, | 44 ReloadButton::Mode visible_mode, |
| 43 bool double_click_timer_running, | 45 bool double_click_timer_running, |
| (...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 148 reload_.ButtonPressed(&reload_, e); | 150 reload_.ButtonPressed(&reload_, e); |
| 149 reload_.ChangeMode(ReloadButton::MODE_STOP, false); | 151 reload_.ChangeMode(ReloadButton::MODE_STOP, false); |
| 150 set_mouse_hovered(true); | 152 set_mouse_hovered(true); |
| 151 reload_.ChangeMode(ReloadButton::MODE_RELOAD, false); | 153 reload_.ChangeMode(ReloadButton::MODE_RELOAD, false); |
| 152 | 154 |
| 153 // Now fire the stop-to-reload timer. This should reset the button. | 155 // Now fire the stop-to-reload timer. This should reset the button. |
| 154 loop_.RunUntilIdle(); | 156 loop_.RunUntilIdle(); |
| 155 CheckState(true, ReloadButton::MODE_RELOAD, ReloadButton::MODE_RELOAD, false, | 157 CheckState(true, ReloadButton::MODE_RELOAD, ReloadButton::MODE_RELOAD, false, |
| 156 false); | 158 false); |
| 157 } | 159 } |
| OLD | NEW |