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

Side by Side Diff: ash/wm/user_activity_detector_unittest.cc

Issue 11570012: events: Update key-event handlers to not return EventResult. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: tot-merge-for-landing Created 8 years 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 | Annotate | Revision Log
« no previous file with comments | « ash/wm/user_activity_detector.cc ('k') | ash/wm/window_cycle_controller.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 "ash/wm/user_activity_detector.h" 5 #include "ash/wm/user_activity_detector.h"
6 6
7 #include "ash/shell.h" 7 #include "ash/shell.h"
8 #include "ash/test/ash_test_base.h" 8 #include "ash/test/ash_test_base.h"
9 #include "ash/wm/user_activity_observer.h" 9 #include "ash/wm/user_activity_observer.h"
10 #include "base/compiler_specific.h" 10 #include "base/compiler_specific.h"
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
85 DISALLOW_COPY_AND_ASSIGN(UserActivityDetectorTest); 85 DISALLOW_COPY_AND_ASSIGN(UserActivityDetectorTest);
86 }; 86 };
87 87
88 // Checks that the observer is notified in response to different types of input 88 // Checks that the observer is notified in response to different types of input
89 // events. 89 // events.
90 TEST_F(UserActivityDetectorTest, Basic) { 90 TEST_F(UserActivityDetectorTest, Basic) {
91 scoped_ptr<aura::Window> window(CreateTestWindowInShellWithId(12345)); 91 scoped_ptr<aura::Window> window(CreateTestWindowInShellWithId(12345));
92 92
93 ui::KeyEvent key_event(ui::ET_KEY_PRESSED, ui::VKEY_A, ui::EF_NONE, false); 93 ui::KeyEvent key_event(ui::ET_KEY_PRESSED, ui::VKEY_A, ui::EF_NONE, false);
94 SetEventTarget(window.get(), &key_event); 94 SetEventTarget(window.get(), &key_event);
95 EXPECT_EQ(ui::ER_UNHANDLED, detector_->OnKeyEvent(&key_event)); 95 detector_->OnKeyEvent(&key_event);
96 EXPECT_FALSE(key_event.handled());
96 EXPECT_EQ(1, observer_->num_invocations()); 97 EXPECT_EQ(1, observer_->num_invocations());
97 observer_->reset_stats(); 98 observer_->reset_stats();
98 99
99 base::TimeDelta advance_delta = 100 base::TimeDelta advance_delta =
100 base::TimeDelta::FromSeconds(UserActivityDetector::kNotifyIntervalMs); 101 base::TimeDelta::FromSeconds(UserActivityDetector::kNotifyIntervalMs);
101 AdvanceTime(advance_delta); 102 AdvanceTime(advance_delta);
102 ui::MouseEvent mouse_event( 103 ui::MouseEvent mouse_event(
103 ui::ET_MOUSE_MOVED, gfx::Point(), gfx::Point(), ui::EF_NONE); 104 ui::ET_MOUSE_MOVED, gfx::Point(), gfx::Point(), ui::EF_NONE);
104 SetEventTarget(window.get(), &mouse_event); 105 SetEventTarget(window.get(), &mouse_event);
105 EXPECT_FALSE(detector_->OnMouseEvent(&mouse_event)); 106 EXPECT_FALSE(detector_->OnMouseEvent(&mouse_event));
(...skipping 28 matching lines...) Expand all
134 observer_->reset_stats(); 135 observer_->reset_stats();
135 } 136 }
136 137
137 // Checks that observers aren't notified too frequently. 138 // Checks that observers aren't notified too frequently.
138 TEST_F(UserActivityDetectorTest, RateLimitNotifications) { 139 TEST_F(UserActivityDetectorTest, RateLimitNotifications) {
139 scoped_ptr<aura::Window> window(CreateTestWindowInShellWithId(12345)); 140 scoped_ptr<aura::Window> window(CreateTestWindowInShellWithId(12345));
140 141
141 // The observer should be notified about a key event. 142 // The observer should be notified about a key event.
142 ui::KeyEvent event(ui::ET_KEY_PRESSED, ui::VKEY_A, ui::EF_NONE, false); 143 ui::KeyEvent event(ui::ET_KEY_PRESSED, ui::VKEY_A, ui::EF_NONE, false);
143 SetEventTarget(window.get(), &event); 144 SetEventTarget(window.get(), &event);
144 EXPECT_FALSE(detector_->OnKeyEvent(&event)); 145 detector_->OnKeyEvent(&event);
146 EXPECT_FALSE(event.handled());
145 EXPECT_EQ(1, observer_->num_invocations()); 147 EXPECT_EQ(1, observer_->num_invocations());
146 observer_->reset_stats(); 148 observer_->reset_stats();
147 149
148 // It shouldn't be notified if a second event occurs 150 // It shouldn't be notified if a second event occurs
149 // in the same instant in time. 151 // in the same instant in time.
150 EXPECT_FALSE(detector_->OnKeyEvent(&event)); 152 detector_->OnKeyEvent(&event);
153 EXPECT_FALSE(event.handled());
151 EXPECT_EQ(0, observer_->num_invocations()); 154 EXPECT_EQ(0, observer_->num_invocations());
152 observer_->reset_stats(); 155 observer_->reset_stats();
153 156
154 // Advance the time, but not quite enough for another notification to be sent. 157 // Advance the time, but not quite enough for another notification to be sent.
155 AdvanceTime( 158 AdvanceTime(
156 base::TimeDelta::FromMilliseconds( 159 base::TimeDelta::FromMilliseconds(
157 UserActivityDetector::kNotifyIntervalMs - 100)); 160 UserActivityDetector::kNotifyIntervalMs - 100));
158 EXPECT_EQ(ui::ER_UNHANDLED, detector_->OnKeyEvent(&event)); 161 detector_->OnKeyEvent(&event);
162 EXPECT_FALSE(event.handled());
159 EXPECT_EQ(0, observer_->num_invocations()); 163 EXPECT_EQ(0, observer_->num_invocations());
160 observer_->reset_stats(); 164 observer_->reset_stats();
161 165
162 // Advance time by the notification interval, definitely moving out of the 166 // Advance time by the notification interval, definitely moving out of the
163 // rate limit. This should let us trigger another notification. 167 // rate limit. This should let us trigger another notification.
164 AdvanceTime(base::TimeDelta::FromMilliseconds( 168 AdvanceTime(base::TimeDelta::FromMilliseconds(
165 UserActivityDetector::kNotifyIntervalMs)); 169 UserActivityDetector::kNotifyIntervalMs));
166 170
167 EXPECT_EQ(ui::ER_UNHANDLED, detector_->OnKeyEvent(&event)); 171 detector_->OnKeyEvent(&event);
172 EXPECT_FALSE(event.handled());
168 EXPECT_EQ(1, observer_->num_invocations()); 173 EXPECT_EQ(1, observer_->num_invocations());
169 } 174 }
170 175
171 // Checks that the detector ignores synthetic mouse events. 176 // Checks that the detector ignores synthetic mouse events.
172 TEST_F(UserActivityDetectorTest, IgnoreSyntheticMouseEvents) { 177 TEST_F(UserActivityDetectorTest, IgnoreSyntheticMouseEvents) {
173 scoped_ptr<aura::Window> window(CreateTestWindowInShellWithId(12345)); 178 scoped_ptr<aura::Window> window(CreateTestWindowInShellWithId(12345));
174 ui::MouseEvent mouse_event( 179 ui::MouseEvent mouse_event(
175 ui::ET_MOUSE_MOVED, gfx::Point(), gfx::Point(), ui::EF_IS_SYNTHESIZED); 180 ui::ET_MOUSE_MOVED, gfx::Point(), gfx::Point(), ui::EF_IS_SYNTHESIZED);
176 SetEventTarget(window.get(), &mouse_event); 181 SetEventTarget(window.get(), &mouse_event);
177 EXPECT_EQ(ui::ER_UNHANDLED, detector_->OnMouseEvent(&mouse_event)); 182 EXPECT_EQ(ui::ER_UNHANDLED, detector_->OnMouseEvent(&mouse_event));
178 EXPECT_EQ(0, observer_->num_invocations()); 183 EXPECT_EQ(0, observer_->num_invocations());
179 } 184 }
180 185
181 } // namespace test 186 } // namespace test
182 } // namespace ash 187 } // namespace ash
OLDNEW
« no previous file with comments | « ash/wm/user_activity_detector.cc ('k') | ash/wm/window_cycle_controller.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698