| 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 "testing/gtest/include/gtest/gtest.h" | 7 #include "testing/gtest/include/gtest/gtest.h" |
| 8 | 8 |
| 9 class ReloadButtonTest : public testing::Test { | 9 class ReloadButtonTest : public testing::Test { |
| 10 public: | 10 public: |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 50 reload_.stop_to_reload_timer_.IsRunning()); | 50 reload_.stop_to_reload_timer_.IsRunning()); |
| 51 } | 51 } |
| 52 | 52 |
| 53 TEST_F(ReloadButtonTest, Basic) { | 53 TEST_F(ReloadButtonTest, Basic) { |
| 54 // The stop/reload button starts in the "enabled reload" state with no timers | 54 // The stop/reload button starts in the "enabled reload" state with no timers |
| 55 // running. | 55 // running. |
| 56 CheckState(true, ReloadButton::MODE_RELOAD, ReloadButton::MODE_RELOAD, false, | 56 CheckState(true, ReloadButton::MODE_RELOAD, ReloadButton::MODE_RELOAD, false, |
| 57 false); | 57 false); |
| 58 | 58 |
| 59 // Press the button. This should start the double-click timer. | 59 // Press the button. This should start the double-click timer. |
| 60 ui::MouseEvent e(ui::ET_MOUSE_PRESSED, gfx::Point(), gfx::Point(), 0); | 60 ui::MouseEvent e(ui::ET_MOUSE_PRESSED, gfx::Point(), gfx::Point(), 0, 0); |
| 61 reload_.ButtonPressed(&reload_, e); | 61 reload_.ButtonPressed(&reload_, e); |
| 62 CheckState(true, ReloadButton::MODE_RELOAD, ReloadButton::MODE_RELOAD, true, | 62 CheckState(true, ReloadButton::MODE_RELOAD, ReloadButton::MODE_RELOAD, true, |
| 63 false); | 63 false); |
| 64 | 64 |
| 65 // Now change the mode (as if the browser had started loading the page). This | 65 // Now change the mode (as if the browser had started loading the page). This |
| 66 // should cancel the double-click timer since the button is not hovered. | 66 // should cancel the double-click timer since the button is not hovered. |
| 67 reload_.ChangeMode(ReloadButton::MODE_STOP, false); | 67 reload_.ChangeMode(ReloadButton::MODE_STOP, false); |
| 68 CheckState(true, ReloadButton::MODE_STOP, ReloadButton::MODE_STOP, false, | 68 CheckState(true, ReloadButton::MODE_STOP, ReloadButton::MODE_STOP, false, |
| 69 false); | 69 false); |
| 70 | 70 |
| 71 // Press the button again. This should change back to reload. | 71 // Press the button again. This should change back to reload. |
| 72 reload_.ButtonPressed(&reload_, e); | 72 reload_.ButtonPressed(&reload_, e); |
| 73 CheckState(true, ReloadButton::MODE_RELOAD, ReloadButton::MODE_RELOAD, false, | 73 CheckState(true, ReloadButton::MODE_RELOAD, ReloadButton::MODE_RELOAD, false, |
| 74 false); | 74 false); |
| 75 } | 75 } |
| 76 | 76 |
| 77 TEST_F(ReloadButtonTest, DoubleClickTimer) { | 77 TEST_F(ReloadButtonTest, DoubleClickTimer) { |
| 78 // Start by pressing the button. | 78 // Start by pressing the button. |
| 79 ui::MouseEvent e(ui::ET_MOUSE_PRESSED, gfx::Point(), gfx::Point(), 0); | 79 ui::MouseEvent e(ui::ET_MOUSE_PRESSED, gfx::Point(), gfx::Point(), 0, 0); |
| 80 reload_.ButtonPressed(&reload_, e); | 80 reload_.ButtonPressed(&reload_, e); |
| 81 | 81 |
| 82 // Try to press the button again. This should do nothing because the timer is | 82 // Try to press the button again. This should do nothing because the timer is |
| 83 // running. | 83 // running. |
| 84 int original_reload_count = reload_count(); | 84 int original_reload_count = reload_count(); |
| 85 reload_.ButtonPressed(&reload_, e); | 85 reload_.ButtonPressed(&reload_, e); |
| 86 CheckState(true, ReloadButton::MODE_RELOAD, ReloadButton::MODE_RELOAD, true, | 86 CheckState(true, ReloadButton::MODE_RELOAD, ReloadButton::MODE_RELOAD, true, |
| 87 false); | 87 false); |
| 88 EXPECT_EQ(original_reload_count, reload_count()); | 88 EXPECT_EQ(original_reload_count, reload_count()); |
| 89 | 89 |
| 90 // Hover the button, and change mode. The visible mode should not change, | 90 // Hover the button, and change mode. The visible mode should not change, |
| 91 // again because the timer is running. | 91 // again because the timer is running. |
| 92 set_mouse_hovered(true); | 92 set_mouse_hovered(true); |
| 93 reload_.ChangeMode(ReloadButton::MODE_STOP, false); | 93 reload_.ChangeMode(ReloadButton::MODE_STOP, false); |
| 94 CheckState(true, ReloadButton::MODE_STOP, ReloadButton::MODE_RELOAD, true, | 94 CheckState(true, ReloadButton::MODE_STOP, ReloadButton::MODE_RELOAD, true, |
| 95 false); | 95 false); |
| 96 | 96 |
| 97 // Now fire the timer. This should complete the mode change. | 97 // Now fire the timer. This should complete the mode change. |
| 98 loop_.RunUntilIdle(); | 98 loop_.RunUntilIdle(); |
| 99 CheckState(true, ReloadButton::MODE_STOP, ReloadButton::MODE_STOP, false, | 99 CheckState(true, ReloadButton::MODE_STOP, ReloadButton::MODE_STOP, false, |
| 100 false); | 100 false); |
| 101 } | 101 } |
| 102 | 102 |
| 103 TEST_F(ReloadButtonTest, DisableOnHover) { | 103 TEST_F(ReloadButtonTest, DisableOnHover) { |
| 104 // Change to stop and hover. | 104 // Change to stop and hover. |
| 105 ui::MouseEvent e(ui::ET_MOUSE_PRESSED, gfx::Point(), gfx::Point(), 0); | 105 ui::MouseEvent e(ui::ET_MOUSE_PRESSED, gfx::Point(), gfx::Point(), 0, 0); |
| 106 reload_.ButtonPressed(&reload_, e); | 106 reload_.ButtonPressed(&reload_, e); |
| 107 reload_.ChangeMode(ReloadButton::MODE_STOP, false); | 107 reload_.ChangeMode(ReloadButton::MODE_STOP, false); |
| 108 set_mouse_hovered(true); | 108 set_mouse_hovered(true); |
| 109 | 109 |
| 110 // Now change back to reload. This should result in a disabled stop button | 110 // Now change back to reload. This should result in a disabled stop button |
| 111 // due to the hover. | 111 // due to the hover. |
| 112 reload_.ChangeMode(ReloadButton::MODE_RELOAD, false); | 112 reload_.ChangeMode(ReloadButton::MODE_RELOAD, false); |
| 113 CheckState(false, ReloadButton::MODE_RELOAD, ReloadButton::MODE_STOP, false, | 113 CheckState(false, ReloadButton::MODE_RELOAD, ReloadButton::MODE_STOP, false, |
| 114 true); | 114 true); |
| 115 | 115 |
| 116 // Un-hover the button, which should allow it to reset. | 116 // Un-hover the button, which should allow it to reset. |
| 117 set_mouse_hovered(false); | 117 set_mouse_hovered(false); |
| 118 ui::MouseEvent e2(ui::ET_MOUSE_MOVED, gfx::Point(), gfx::Point(), 0); | 118 ui::MouseEvent e2(ui::ET_MOUSE_MOVED, gfx::Point(), gfx::Point(), 0, 0); |
| 119 reload_.OnMouseExited(e2); | 119 reload_.OnMouseExited(e2); |
| 120 CheckState(true, ReloadButton::MODE_RELOAD, ReloadButton::MODE_RELOAD, false, | 120 CheckState(true, ReloadButton::MODE_RELOAD, ReloadButton::MODE_RELOAD, false, |
| 121 false); | 121 false); |
| 122 } | 122 } |
| 123 | 123 |
| 124 TEST_F(ReloadButtonTest, ResetOnClick) { | 124 TEST_F(ReloadButtonTest, ResetOnClick) { |
| 125 // Change to stop and hover. | 125 // Change to stop and hover. |
| 126 ui::MouseEvent e(ui::ET_MOUSE_PRESSED, gfx::Point(), gfx::Point(), 0); | 126 ui::MouseEvent e(ui::ET_MOUSE_PRESSED, gfx::Point(), gfx::Point(), 0, 0); |
| 127 reload_.ButtonPressed(&reload_, e); | 127 reload_.ButtonPressed(&reload_, e); |
| 128 reload_.ChangeMode(ReloadButton::MODE_STOP, false); | 128 reload_.ChangeMode(ReloadButton::MODE_STOP, false); |
| 129 set_mouse_hovered(true); | 129 set_mouse_hovered(true); |
| 130 | 130 |
| 131 // Press the button. This should change back to reload despite the hover, | 131 // Press the button. This should change back to reload despite the hover, |
| 132 // because it's a direct user action. | 132 // because it's a direct user action. |
| 133 reload_.ButtonPressed(&reload_, e); | 133 reload_.ButtonPressed(&reload_, e); |
| 134 CheckState(true, ReloadButton::MODE_RELOAD, ReloadButton::MODE_RELOAD, false, | 134 CheckState(true, ReloadButton::MODE_RELOAD, ReloadButton::MODE_RELOAD, false, |
| 135 false); | 135 false); |
| 136 } | 136 } |
| 137 | 137 |
| 138 TEST_F(ReloadButtonTest, ResetOnTimer) { | 138 TEST_F(ReloadButtonTest, ResetOnTimer) { |
| 139 // Change to stop, hover, and change back to reload. | 139 // Change to stop, hover, and change back to reload. |
| 140 ui::MouseEvent e(ui::ET_MOUSE_PRESSED, gfx::Point(), gfx::Point(), 0); | 140 ui::MouseEvent e(ui::ET_MOUSE_PRESSED, gfx::Point(), gfx::Point(), 0, 0); |
| 141 reload_.ButtonPressed(&reload_, e); | 141 reload_.ButtonPressed(&reload_, e); |
| 142 reload_.ChangeMode(ReloadButton::MODE_STOP, false); | 142 reload_.ChangeMode(ReloadButton::MODE_STOP, false); |
| 143 set_mouse_hovered(true); | 143 set_mouse_hovered(true); |
| 144 reload_.ChangeMode(ReloadButton::MODE_RELOAD, false); | 144 reload_.ChangeMode(ReloadButton::MODE_RELOAD, false); |
| 145 | 145 |
| 146 // Now fire the stop-to-reload timer. This should reset the button. | 146 // Now fire the stop-to-reload timer. This should reset the button. |
| 147 loop_.RunUntilIdle(); | 147 loop_.RunUntilIdle(); |
| 148 CheckState(true, ReloadButton::MODE_RELOAD, ReloadButton::MODE_RELOAD, false, | 148 CheckState(true, ReloadButton::MODE_RELOAD, ReloadButton::MODE_RELOAD, false, |
| 149 false); | 149 false); |
| 150 } | 150 } |
| OLD | NEW |