| 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/testing_profile.h" |
| 7 #include "testing/gtest/include/gtest/gtest.h" | 8 #include "testing/gtest/include/gtest/gtest.h" |
| 8 #include "ui/events/event_utils.h" | 9 #include "ui/events/event_utils.h" |
| 9 | 10 |
| 10 class ReloadButtonTest : public testing::Test { | 11 class ReloadButtonTest : public testing::Test { |
| 11 public: | 12 public: |
| 12 ReloadButtonTest(); | 13 ReloadButtonTest(); |
| 13 | 14 |
| 14 void CheckState(bool enabled, | 15 void CheckState(bool enabled, |
| 15 ReloadButton::Mode intended_mode, | 16 ReloadButton::Mode intended_mode, |
| 16 ReloadButton::Mode visible_mode, | 17 ReloadButton::Mode visible_mode, |
| 17 bool double_click_timer_running, | 18 bool double_click_timer_running, |
| 18 bool stop_to_reload_timer_running); | 19 bool stop_to_reload_timer_running); |
| 19 | 20 |
| 20 // These accessors eliminate the need to declare each testcase as a friend. | 21 // These accessors eliminate the need to declare each testcase as a friend. |
| 21 void set_mouse_hovered(bool hovered) { | 22 void set_mouse_hovered(bool hovered) { |
| 22 reload_.testing_mouse_hovered_ = hovered; | 23 reload_.testing_mouse_hovered_ = hovered; |
| 23 } | 24 } |
| 24 int reload_count() { return reload_.testing_reload_count_; } | 25 int reload_count() { return reload_.testing_reload_count_; } |
| 25 | 26 |
| 26 protected: | 27 protected: |
| 27 // We need a message loop for the timers to post events. | 28 // We need a message loop for the timers to post events. |
| 28 base::MessageLoop loop_; | 29 base::MessageLoop loop_; |
| 29 | 30 |
| 31 TestingProfile profile_; |
| 32 |
| 30 ReloadButton reload_; | 33 ReloadButton reload_; |
| 31 }; | 34 }; |
| 32 | 35 |
| 33 ReloadButtonTest::ReloadButtonTest() : reload_(NULL) { | 36 ReloadButtonTest::ReloadButtonTest() : reload_(&profile_, nullptr) { |
| 34 // Set the timer delays to 0 so that timers will fire as soon as we tell the | 37 // Set the timer delays to 0 so that timers will fire as soon as we tell the |
| 35 // message loop to run pending tasks. | 38 // message loop to run pending tasks. |
| 36 reload_.double_click_timer_delay_ = base::TimeDelta(); | 39 reload_.double_click_timer_delay_ = base::TimeDelta(); |
| 37 reload_.stop_to_reload_timer_delay_ = base::TimeDelta(); | 40 reload_.stop_to_reload_timer_delay_ = base::TimeDelta(); |
| 38 } | 41 } |
| 39 | 42 |
| 40 void ReloadButtonTest::CheckState(bool enabled, | 43 void ReloadButtonTest::CheckState(bool enabled, |
| 41 ReloadButton::Mode intended_mode, | 44 ReloadButton::Mode intended_mode, |
| 42 ReloadButton::Mode visible_mode, | 45 ReloadButton::Mode visible_mode, |
| 43 bool double_click_timer_running, | 46 bool double_click_timer_running, |
| (...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 148 reload_.ButtonPressed(&reload_, e); | 151 reload_.ButtonPressed(&reload_, e); |
| 149 reload_.ChangeMode(ReloadButton::MODE_STOP, false); | 152 reload_.ChangeMode(ReloadButton::MODE_STOP, false); |
| 150 set_mouse_hovered(true); | 153 set_mouse_hovered(true); |
| 151 reload_.ChangeMode(ReloadButton::MODE_RELOAD, false); | 154 reload_.ChangeMode(ReloadButton::MODE_RELOAD, false); |
| 152 | 155 |
| 153 // Now fire the stop-to-reload timer. This should reset the button. | 156 // Now fire the stop-to-reload timer. This should reset the button. |
| 154 loop_.RunUntilIdle(); | 157 loop_.RunUntilIdle(); |
| 155 CheckState(true, ReloadButton::MODE_RELOAD, ReloadButton::MODE_RELOAD, false, | 158 CheckState(true, ReloadButton::MODE_RELOAD, ReloadButton::MODE_RELOAD, false, |
| 156 false); | 159 false); |
| 157 } | 160 } |
| OLD | NEW |