Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(189)

Side by Side Diff: chrome/browser/ui/views/toolbar/reload_button_unittest.cc

Issue 2786693002: Add PointerDetails to ui::MouseEvent's constructors (Closed)
Patch Set: mouse event constructor Created 3 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 "chrome/browser/ui/views/toolbar/reload_button.h" 5 #include "chrome/browser/ui/views/toolbar/reload_button.h"
6 6
7 #include "base/run_loop.h" 7 #include "base/run_loop.h"
8 #include "chrome/test/base/chrome_render_view_host_test_harness.h" 8 #include "chrome/test/base/chrome_render_view_host_test_harness.h"
9 #include "chrome/test/base/testing_profile.h" 9 #include "chrome/test/base/testing_profile.h"
10 #include "testing/gtest/include/gtest/gtest.h" 10 #include "testing/gtest/include/gtest/gtest.h"
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
58 reload_.stop_to_reload_timer_.IsRunning()); 58 reload_.stop_to_reload_timer_.IsRunning());
59 } 59 }
60 60
61 TEST_F(ReloadButtonTest, Basic) { 61 TEST_F(ReloadButtonTest, Basic) {
62 // The stop/reload button starts in the "enabled reload" state with no timers 62 // The stop/reload button starts in the "enabled reload" state with no timers
63 // running. 63 // running.
64 CheckState(true, ReloadButton::MODE_RELOAD, ReloadButton::MODE_RELOAD, false, 64 CheckState(true, ReloadButton::MODE_RELOAD, ReloadButton::MODE_RELOAD, false,
65 false); 65 false);
66 66
67 // Press the button. This should start the double-click timer. 67 // Press the button. This should start the double-click timer.
68 ui::MouseEvent e(ui::ET_MOUSE_PRESSED, gfx::Point(), gfx::Point(), 68 ui::MouseEvent e(
69 ui::EventTimeForNow(), 0, 0); 69 ui::ET_MOUSE_PRESSED, gfx::Point(), gfx::Point(), ui::EventTimeForNow(),
70 0, 0, ui::PointerDetails(ui::EventPointerType::POINTER_TYPE_MOUSE));
70 reload()->ButtonPressed(reload(), e); 71 reload()->ButtonPressed(reload(), e);
71 CheckState(true, ReloadButton::MODE_RELOAD, ReloadButton::MODE_RELOAD, true, 72 CheckState(true, ReloadButton::MODE_RELOAD, ReloadButton::MODE_RELOAD, true,
72 false); 73 false);
73 74
74 // Now change the mode (as if the browser had started loading the page). This 75 // Now change the mode (as if the browser had started loading the page). This
75 // should cancel the double-click timer since the button is not hovered. 76 // should cancel the double-click timer since the button is not hovered.
76 reload()->ChangeMode(ReloadButton::MODE_STOP, false); 77 reload()->ChangeMode(ReloadButton::MODE_STOP, false);
77 CheckState(true, ReloadButton::MODE_STOP, ReloadButton::MODE_STOP, false, 78 CheckState(true, ReloadButton::MODE_STOP, ReloadButton::MODE_STOP, false,
78 false); 79 false);
79 80
80 // Press the button again. This should change back to reload. 81 // Press the button again. This should change back to reload.
81 reload()->ButtonPressed(reload(), e); 82 reload()->ButtonPressed(reload(), e);
82 CheckState(true, ReloadButton::MODE_RELOAD, ReloadButton::MODE_RELOAD, false, 83 CheckState(true, ReloadButton::MODE_RELOAD, ReloadButton::MODE_RELOAD, false,
83 false); 84 false);
84 } 85 }
85 86
86 TEST_F(ReloadButtonTest, DoubleClickTimer) { 87 TEST_F(ReloadButtonTest, DoubleClickTimer) {
87 // Start by pressing the button. 88 // Start by pressing the button.
88 ui::MouseEvent e(ui::ET_MOUSE_PRESSED, gfx::Point(), gfx::Point(), 89 ui::MouseEvent e(
89 ui::EventTimeForNow(), 0, 0); 90 ui::ET_MOUSE_PRESSED, gfx::Point(), gfx::Point(), ui::EventTimeForNow(),
91 0, 0, ui::PointerDetails(ui::EventPointerType::POINTER_TYPE_MOUSE));
90 reload()->ButtonPressed(reload(), e); 92 reload()->ButtonPressed(reload(), e);
91 93
92 // Try to press the button again. This should do nothing because the timer is 94 // Try to press the button again. This should do nothing because the timer is
93 // running. 95 // running.
94 int original_reload_count = reload_count(); 96 int original_reload_count = reload_count();
95 reload()->ButtonPressed(reload(), e); 97 reload()->ButtonPressed(reload(), e);
96 CheckState(true, ReloadButton::MODE_RELOAD, ReloadButton::MODE_RELOAD, true, 98 CheckState(true, ReloadButton::MODE_RELOAD, ReloadButton::MODE_RELOAD, true,
97 false); 99 false);
98 EXPECT_EQ(original_reload_count, reload_count()); 100 EXPECT_EQ(original_reload_count, reload_count());
99 101
100 // Hover the button, and change mode. The visible mode should not change, 102 // Hover the button, and change mode. The visible mode should not change,
101 // again because the timer is running. 103 // again because the timer is running.
102 set_mouse_hovered(true); 104 set_mouse_hovered(true);
103 reload()->ChangeMode(ReloadButton::MODE_STOP, false); 105 reload()->ChangeMode(ReloadButton::MODE_STOP, false);
104 CheckState(true, ReloadButton::MODE_STOP, ReloadButton::MODE_RELOAD, true, 106 CheckState(true, ReloadButton::MODE_STOP, ReloadButton::MODE_RELOAD, true,
105 false); 107 false);
106 108
107 // Now fire the timer. This should complete the mode change. 109 // Now fire the timer. This should complete the mode change.
108 base::RunLoop().RunUntilIdle(); 110 base::RunLoop().RunUntilIdle();
109 CheckState(true, ReloadButton::MODE_STOP, ReloadButton::MODE_STOP, false, 111 CheckState(true, ReloadButton::MODE_STOP, ReloadButton::MODE_STOP, false,
110 false); 112 false);
111 } 113 }
112 114
113 TEST_F(ReloadButtonTest, DisableOnHover) { 115 TEST_F(ReloadButtonTest, DisableOnHover) {
114 // Change to stop and hover. 116 // Change to stop and hover.
115 ui::MouseEvent e(ui::ET_MOUSE_PRESSED, gfx::Point(), gfx::Point(), 117 ui::MouseEvent e(
116 ui::EventTimeForNow(), 0, 0); 118 ui::ET_MOUSE_PRESSED, gfx::Point(), gfx::Point(), ui::EventTimeForNow(),
119 0, 0, ui::PointerDetails(ui::EventPointerType::POINTER_TYPE_MOUSE));
117 reload()->ButtonPressed(reload(), e); 120 reload()->ButtonPressed(reload(), e);
118 reload()->ChangeMode(ReloadButton::MODE_STOP, false); 121 reload()->ChangeMode(ReloadButton::MODE_STOP, false);
119 set_mouse_hovered(true); 122 set_mouse_hovered(true);
120 123
121 // Now change back to reload. This should result in a disabled stop button 124 // Now change back to reload. This should result in a disabled stop button
122 // due to the hover. 125 // due to the hover.
123 reload()->ChangeMode(ReloadButton::MODE_RELOAD, false); 126 reload()->ChangeMode(ReloadButton::MODE_RELOAD, false);
124 CheckState(false, ReloadButton::MODE_RELOAD, ReloadButton::MODE_STOP, false, 127 CheckState(false, ReloadButton::MODE_RELOAD, ReloadButton::MODE_STOP, false,
125 true); 128 true);
126 129
127 // Un-hover the button, which should allow it to reset. 130 // Un-hover the button, which should allow it to reset.
128 set_mouse_hovered(false); 131 set_mouse_hovered(false);
129 ui::MouseEvent e2(ui::ET_MOUSE_MOVED, gfx::Point(), gfx::Point(), 132 ui::MouseEvent e2(
130 ui::EventTimeForNow(), 0, 0); 133 ui::ET_MOUSE_MOVED, gfx::Point(), gfx::Point(), ui::EventTimeForNow(), 0,
134 0, ui::PointerDetails(ui::EventPointerType::POINTER_TYPE_MOUSE));
131 reload()->OnMouseExited(e2); 135 reload()->OnMouseExited(e2);
132 CheckState(true, ReloadButton::MODE_RELOAD, ReloadButton::MODE_RELOAD, false, 136 CheckState(true, ReloadButton::MODE_RELOAD, ReloadButton::MODE_RELOAD, false,
133 false); 137 false);
134 } 138 }
135 139
136 TEST_F(ReloadButtonTest, ResetOnClick) { 140 TEST_F(ReloadButtonTest, ResetOnClick) {
137 // Change to stop and hover. 141 // Change to stop and hover.
138 ui::MouseEvent e(ui::ET_MOUSE_PRESSED, gfx::Point(), gfx::Point(), 142 ui::MouseEvent e(
139 ui::EventTimeForNow(), 0, 0); 143 ui::ET_MOUSE_PRESSED, gfx::Point(), gfx::Point(), ui::EventTimeForNow(),
144 0, 0, ui::PointerDetails(ui::EventPointerType::POINTER_TYPE_MOUSE));
140 reload()->ButtonPressed(reload(), e); 145 reload()->ButtonPressed(reload(), e);
141 reload()->ChangeMode(ReloadButton::MODE_STOP, false); 146 reload()->ChangeMode(ReloadButton::MODE_STOP, false);
142 set_mouse_hovered(true); 147 set_mouse_hovered(true);
143 148
144 // Press the button. This should change back to reload despite the hover, 149 // Press the button. This should change back to reload despite the hover,
145 // because it's a direct user action. 150 // because it's a direct user action.
146 reload()->ButtonPressed(reload(), e); 151 reload()->ButtonPressed(reload(), e);
147 CheckState(true, ReloadButton::MODE_RELOAD, ReloadButton::MODE_RELOAD, false, 152 CheckState(true, ReloadButton::MODE_RELOAD, ReloadButton::MODE_RELOAD, false,
148 false); 153 false);
149 } 154 }
150 155
151 TEST_F(ReloadButtonTest, ResetOnTimer) { 156 TEST_F(ReloadButtonTest, ResetOnTimer) {
152 // Change to stop, hover, and change back to reload. 157 // Change to stop, hover, and change back to reload.
153 ui::MouseEvent e(ui::ET_MOUSE_PRESSED, gfx::Point(), gfx::Point(), 158 ui::MouseEvent e(
154 ui::EventTimeForNow(), 0, 0); 159 ui::ET_MOUSE_PRESSED, gfx::Point(), gfx::Point(), ui::EventTimeForNow(),
160 0, 0, ui::PointerDetails(ui::EventPointerType::POINTER_TYPE_MOUSE));
155 reload()->ButtonPressed(reload(), e); 161 reload()->ButtonPressed(reload(), e);
156 reload()->ChangeMode(ReloadButton::MODE_STOP, false); 162 reload()->ChangeMode(ReloadButton::MODE_STOP, false);
157 set_mouse_hovered(true); 163 set_mouse_hovered(true);
158 reload()->ChangeMode(ReloadButton::MODE_RELOAD, false); 164 reload()->ChangeMode(ReloadButton::MODE_RELOAD, false);
159 165
160 // Now fire the stop-to-reload timer. This should reset the button. 166 // Now fire the stop-to-reload timer. This should reset the button.
161 base::RunLoop().RunUntilIdle(); 167 base::RunLoop().RunUntilIdle();
162 CheckState(true, ReloadButton::MODE_RELOAD, ReloadButton::MODE_RELOAD, false, 168 CheckState(true, ReloadButton::MODE_RELOAD, ReloadButton::MODE_RELOAD, false,
163 false); 169 false);
164 } 170 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698