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

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

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

Powered by Google App Engine
This is Rietveld 408576698