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

Side by Side Diff: views/view_unittest.cc

Issue 6253005: touch: Gesture manager receives the touch-sequence status. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Update unittest for gesture manager. Created 9 years, 11 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 | Annotate | Revision Log
« no previous file with comments | « views/touchui/gesture_manager.cc ('k') | views/widget/root_view.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) 2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2010 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 <map> 5 #include <map>
6 6
7 #include "base/string_util.h" 7 #include "base/string_util.h"
8 #include "base/utf_string_conversions.h" 8 #include "base/utf_string_conversions.h"
9 #include "gfx/canvas_skia.h" 9 #include "gfx/canvas_skia.h"
10 #include "gfx/path.h" 10 #include "gfx/path.h"
(...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after
171 View* child_; 171 View* child_;
172 172
173 // MouseEvent 173 // MouseEvent
174 int last_mouse_event_type_; 174 int last_mouse_event_type_;
175 gfx::Point location_; 175 gfx::Point location_;
176 176
177 #if defined(TOUCH_UI) 177 #if defined(TOUCH_UI)
178 // TouchEvent 178 // TouchEvent
179 int last_touch_event_type_; 179 int last_touch_event_type_;
180 bool last_touch_event_was_handled_; 180 bool last_touch_event_was_handled_;
181 bool in_touch_sequence_;
181 #endif 182 #endif
182 183
183 // Painting 184 // Painting
184 SkRect last_clip_; 185 SkRect last_clip_;
185 186
186 // Accelerators 187 // Accelerators
187 std::map<Accelerator, int> accelerator_count_map_; 188 std::map<Accelerator, int> accelerator_count_map_;
188 }; 189 };
189 190
190 #if defined(TOUCH_UI) 191 #if defined(TOUCH_UI)
191 // Mock instance of the GestureManager for testing. 192 // Mock instance of the GestureManager for testing.
192 class MockGestureManager : public GestureManager { 193 class MockGestureManager : public GestureManager {
193 public: 194 public:
194 // Reset all test state 195 // Reset all test state
195 void Reset() { 196 void Reset() {
196 last_touch_event_ = 0; 197 last_touch_event_ = 0;
197 last_view_ = NULL; 198 last_view_ = NULL;
198 previously_handled_flag_ = false; 199 previously_handled_flag_ = false;
199 dispatched_synthetic_event_ = false; 200 dispatched_synthetic_event_ = false;
200 } 201 }
201 202
202 bool ProcessTouchEventForGesture(const TouchEvent& event, 203 bool ProcessTouchEventForGesture(const TouchEvent& event,
203 View* source, 204 View* source,
204 bool previouslyHandled); 205 View::TouchStatus status);
205 MockGestureManager(); 206 MockGestureManager();
206 207
207 bool previously_handled_flag_; 208 bool previously_handled_flag_;
208 int last_touch_event_; 209 int last_touch_event_;
209 View *last_view_; 210 View *last_view_;
210 bool dispatched_synthetic_event_; 211 bool dispatched_synthetic_event_;
211 212
212 DISALLOW_COPY_AND_ASSIGN(MockGestureManager); 213 DISALLOW_COPY_AND_ASSIGN(MockGestureManager);
213 }; 214 };
214 215
(...skipping 192 matching lines...) Expand 10 before | Expand all | Expand 10 after
407 window->CloseNow(); 408 window->CloseNow();
408 } 409 }
409 410
410 #if defined(TOUCH_UI) 411 #if defined(TOUCH_UI)
411 //////////////////////////////////////////////////////////////////////////////// 412 ////////////////////////////////////////////////////////////////////////////////
412 // TouchEvent 413 // TouchEvent
413 //////////////////////////////////////////////////////////////////////////////// 414 ////////////////////////////////////////////////////////////////////////////////
414 bool MockGestureManager::ProcessTouchEventForGesture( 415 bool MockGestureManager::ProcessTouchEventForGesture(
415 const TouchEvent& event, 416 const TouchEvent& event,
416 View* source, 417 View* source,
417 bool previouslyHandled) { 418 View::TouchStatus status) {
418 if (previouslyHandled) { 419 if (status != View::TOUCH_STATUS_UNKNOWN) {
419 dispatched_synthetic_event_ = false; 420 dispatched_synthetic_event_ = false;
420 return false; 421 return false;
421 } 422 }
422 last_touch_event_ = event.GetType(); 423 last_touch_event_ = event.GetType();
423 last_view_ = source; 424 last_view_ = source;
424 previously_handled_flag_ = previouslyHandled; 425 previously_handled_flag_ = status != View::TOUCH_STATUS_UNKNOWN;
425 dispatched_synthetic_event_ = true; 426 dispatched_synthetic_event_ = true;
426 return true; 427 return true;
427 } 428 }
428 429
429 MockGestureManager::MockGestureManager() { 430 MockGestureManager::MockGestureManager() {
430 } 431 }
431 432
432 View::TouchStatus TestView::OnTouchEvent(const TouchEvent& event) { 433 View::TouchStatus TestView::OnTouchEvent(const TouchEvent& event) {
433 last_touch_event_type_ = event.GetType(); 434 last_touch_event_type_ = event.GetType();
434 location_.SetPoint(event.x(), event.y()); 435 location_.SetPoint(event.x(), event.y());
436 if (!in_touch_sequence_) {
437 if (event.GetType() == Event::ET_TOUCH_PRESSED) {
438 in_touch_sequence_ = true;
439 return TOUCH_STATUS_START;
440 }
441 } else {
442 if (event.GetType() == Event::ET_TOUCH_RELEASED) {
443 in_touch_sequence_ = false;
444 return TOUCH_STATUS_END;
445 }
446 return TOUCH_STATUS_CONTINUE;
447 }
435 return last_touch_event_was_handled_ ? TOUCH_STATUS_CONTINUE : 448 return last_touch_event_was_handled_ ? TOUCH_STATUS_CONTINUE :
436 TOUCH_STATUS_UNKNOWN; 449 TOUCH_STATUS_UNKNOWN;
437 } 450 }
438 451
439 TEST_F(ViewTest, TouchEvent) { 452 TEST_F(ViewTest, TouchEvent) {
440 MockGestureManager* gm = new MockGestureManager(); 453 MockGestureManager* gm = new MockGestureManager();
441 454
442 TestView* v1 = new TestView(); 455 TestView* v1 = new TestView();
443 v1->SetBounds(0, 0, 300, 300); 456 v1->SetBounds(0, 0, 300, 300);
444 457
(...skipping 1023 matching lines...) Expand 10 before | Expand all | Expand 10 after
1468 #endif 1481 #endif
1469 } 1482 }
1470 1483
1471 TEST_F(ViewTest, ChangeNativeViewHierarchyChangeHierarchy) { 1484 TEST_F(ViewTest, ChangeNativeViewHierarchyChangeHierarchy) {
1472 // TODO(georgey): Fix the test for Linux 1485 // TODO(georgey): Fix the test for Linux
1473 #if defined(OS_WIN) 1486 #if defined(OS_WIN)
1474 TestChangeNativeViewHierarchy test(this); 1487 TestChangeNativeViewHierarchy test(this);
1475 test.CheckChangingHierarhy(); 1488 test.CheckChangingHierarhy();
1476 #endif 1489 #endif
1477 } 1490 }
OLDNEW
« no previous file with comments | « views/touchui/gesture_manager.cc ('k') | views/widget/root_view.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698