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

Side by Side Diff: content/shell/renderer/test_runner/event_sender.cc

Issue 584203003: EventSender: Added checks for missing arguments (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: s/DCHECKs/ThrowErrors. Added similar checks in other places. Created 6 years, 3 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 "content/shell/renderer/test_runner/event_sender.h" 5 #include "content/shell/renderer/test_runner/event_sender.h"
6 6
7 #include "base/basictypes.h" 7 #include "base/basictypes.h"
8 #include "base/logging.h" 8 #include "base/logging.h"
9 #include "base/strings/stringprintf.h" 9 #include "base/strings/stringprintf.h"
10 #include "content/public/common/page_zoom.h" 10 #include "content/public/common/page_zoom.h"
(...skipping 1622 matching lines...) Expand 10 before | Expand all | Expand 10 after
1633 // need/want that. 1633 // need/want that.
1634 is_drag_mode_ = false; 1634 is_drag_mode_ = false;
1635 1635
1636 // Make the rest of eventSender think a drag is in progress. 1636 // Make the rest of eventSender think a drag is in progress.
1637 pressed_button_ = WebMouseEvent::ButtonLeft; 1637 pressed_button_ = WebMouseEvent::ButtonLeft;
1638 } 1638 }
1639 1639
1640 void EventSender::AddTouchPoint(gin::Arguments* args) { 1640 void EventSender::AddTouchPoint(gin::Arguments* args) {
1641 double x; 1641 double x;
1642 double y; 1642 double y;
1643 args->GetNext(&x); 1643 if (!args->GetNext(&x)) {
1644 args->GetNext(&y); 1644 args->ThrowError();
1645 return;
1646 }
1647 if (!args->GetNext(&y)) {
1648 args->ThrowError();
earthdok 2014/09/23 15:44:46 Why not merge the two if statements? (Unless of co
mustaq 2014/09/23 15:56:16 Good point. The merging doesn't obscure the error
1649 return;
1650 }
1645 1651
1646 WebTouchPoint touch_point; 1652 WebTouchPoint touch_point;
1647 touch_point.state = WebTouchPoint::StatePressed; 1653 touch_point.state = WebTouchPoint::StatePressed;
1648 touch_point.position = WebFloatPoint(static_cast<float>(x), 1654 touch_point.position = WebFloatPoint(static_cast<float>(x),
1649 static_cast<float>(y)); 1655 static_cast<float>(y));
1650 touch_point.screenPosition = touch_point.position; 1656 touch_point.screenPosition = touch_point.position;
1651 1657
1652 if (!args->PeekNext().IsEmpty()) { 1658 if (!args->PeekNext().IsEmpty()) {
1653 double radius_x; 1659 double radius_x;
1654 if (!args->GetNext(&radius_x)) { 1660 if (!args->GetNext(&radius_x)) {
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after
1754 InitMouseWheelEvent(args, true, &event); 1760 InitMouseWheelEvent(args, true, &event);
1755 view_->handleInputEvent(event); 1761 view_->handleInputEvent(event);
1756 } 1762 }
1757 1763
1758 void EventSender::MouseMoveTo(gin::Arguments* args) { 1764 void EventSender::MouseMoveTo(gin::Arguments* args) {
1759 if (force_layout_on_events_) 1765 if (force_layout_on_events_)
1760 view_->layout(); 1766 view_->layout();
1761 1767
1762 double x; 1768 double x;
1763 double y; 1769 double y;
1764 args->GetNext(&x); 1770 if (!args->GetNext(&x)) {
1765 args->GetNext(&y); 1771 args->ThrowError();
1772 return;
1773 }
1774 if (!args->GetNext(&y)) {
1775 args->ThrowError();
1776 return;
1777 }
1766 WebPoint mouse_pos(static_cast<int>(x), static_cast<int>(y)); 1778 WebPoint mouse_pos(static_cast<int>(x), static_cast<int>(y));
1767 1779
1768 int modifiers = 0; 1780 int modifiers = 0;
1769 if (!args->PeekNext().IsEmpty()) 1781 if (!args->PeekNext().IsEmpty())
1770 modifiers = GetKeyModifiersFromV8(args->PeekNext()); 1782 modifiers = GetKeyModifiersFromV8(args->PeekNext());
1771 1783
1772 if (is_drag_mode_ && pressed_button_ == WebMouseEvent::ButtonLeft && 1784 if (is_drag_mode_ && pressed_button_ == WebMouseEvent::ButtonLeft &&
1773 !replaying_saved_events_) { 1785 !replaying_saved_events_) {
1774 SavedEvent saved_event; 1786 SavedEvent saved_event;
1775 saved_event.type = SavedEvent::TYPE_MOUSE_MOVE; 1787 saved_event.type = SavedEvent::TYPE_MOUSE_MOVE;
(...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after
1917 --i; 1929 --i;
1918 } else 1930 } else
1919 touch_point->state = WebTouchPoint::StateStationary; 1931 touch_point->state = WebTouchPoint::StateStationary;
1920 } 1932 }
1921 } 1933 }
1922 1934
1923 void EventSender::GestureEvent(WebInputEvent::Type type, 1935 void EventSender::GestureEvent(WebInputEvent::Type type,
1924 gin::Arguments* args) { 1936 gin::Arguments* args) {
1925 double x; 1937 double x;
1926 double y; 1938 double y;
1927 args->GetNext(&x); 1939 if (!args->GetNext(&x)) {
1928 args->GetNext(&y); 1940 args->ThrowError();
1929 WebPoint point(x, y); 1941 return;
1942 }
1943 if (!args->GetNext(&y)) {
1944 args->ThrowError();
1945 return;
1946 }
1930 1947
1931 WebGestureEvent event; 1948 WebGestureEvent event;
1932 event.type = type; 1949 event.type = type;
1933 1950
1934 switch (type) { 1951 switch (type) {
1935 case WebInputEvent::GestureScrollUpdate: 1952 case WebInputEvent::GestureScrollUpdate:
1936 case WebInputEvent::GestureScrollUpdateWithoutPropagation: 1953 case WebInputEvent::GestureScrollUpdateWithoutPropagation:
1937 event.data.scrollUpdate.deltaX = static_cast<float>(x); 1954 event.data.scrollUpdate.deltaX = static_cast<float>(x);
1938 event.data.scrollUpdate.deltaY = static_cast<float>(y); 1955 event.data.scrollUpdate.deltaY = static_cast<float>(y);
1939 event.x = current_gesture_location_.x; 1956 event.x = current_gesture_location_.x;
1940 event.y = current_gesture_location_.y; 1957 event.y = current_gesture_location_.y;
1941 current_gesture_location_.x = 1958 current_gesture_location_.x =
1942 current_gesture_location_.x + event.data.scrollUpdate.deltaX; 1959 current_gesture_location_.x + event.data.scrollUpdate.deltaX;
1943 current_gesture_location_.y = 1960 current_gesture_location_.y =
1944 current_gesture_location_.y + event.data.scrollUpdate.deltaY; 1961 current_gesture_location_.y + event.data.scrollUpdate.deltaY;
1945 break; 1962 break;
1946 case WebInputEvent::GestureScrollBegin: 1963 case WebInputEvent::GestureScrollBegin:
1947 current_gesture_location_ = WebPoint(point.x, point.y); 1964 current_gesture_location_ = WebPoint(x, y);
1948 event.x = current_gesture_location_.x; 1965 event.x = current_gesture_location_.x;
1949 event.y = current_gesture_location_.y; 1966 event.y = current_gesture_location_.y;
1950 break; 1967 break;
1951 case WebInputEvent::GestureScrollEnd: 1968 case WebInputEvent::GestureScrollEnd:
1952 case WebInputEvent::GestureFlingStart: 1969 case WebInputEvent::GestureFlingStart:
1953 event.x = current_gesture_location_.x; 1970 event.x = current_gesture_location_.x;
1954 event.y = current_gesture_location_.y; 1971 event.y = current_gesture_location_.y;
1955 break; 1972 break;
1956 case WebInputEvent::GestureTap: 1973 case WebInputEvent::GestureTap:
1957 { 1974 {
(...skipping 14 matching lines...) Expand all
1972 } 1989 }
1973 if (!args->PeekNext().IsEmpty()) { 1990 if (!args->PeekNext().IsEmpty()) {
1974 if (!args->GetNext(&height)) { 1991 if (!args->GetNext(&height)) {
1975 args->ThrowError(); 1992 args->ThrowError();
1976 return; 1993 return;
1977 } 1994 }
1978 } 1995 }
1979 event.data.tap.tapCount = tap_count; 1996 event.data.tap.tapCount = tap_count;
1980 event.data.tap.width = width; 1997 event.data.tap.width = width;
1981 event.data.tap.height = height; 1998 event.data.tap.height = height;
1982 event.x = point.x; 1999 event.x = x;
1983 event.y = point.y; 2000 event.y = y;
1984 break; 2001 break;
1985 } 2002 }
1986 case WebInputEvent::GestureTapUnconfirmed: 2003 case WebInputEvent::GestureTapUnconfirmed:
1987 if (!args->PeekNext().IsEmpty()) { 2004 if (!args->PeekNext().IsEmpty()) {
1988 float tap_count; 2005 float tap_count;
1989 if (!args->GetNext(&tap_count)) { 2006 if (!args->GetNext(&tap_count)) {
1990 args->ThrowError(); 2007 args->ThrowError();
1991 return; 2008 return;
1992 } 2009 }
1993 event.data.tap.tapCount = tap_count; 2010 event.data.tap.tapCount = tap_count;
1994 } else { 2011 } else {
1995 event.data.tap.tapCount = 1; 2012 event.data.tap.tapCount = 1;
1996 } 2013 }
1997 event.x = point.x; 2014 event.x = x;
1998 event.y = point.y; 2015 event.y = y;
1999 break; 2016 break;
2000 case WebInputEvent::GestureTapDown: 2017 case WebInputEvent::GestureTapDown:
2001 { 2018 {
2002 float width = 30; 2019 float width = 30;
2003 float height = 30; 2020 float height = 30;
2004 if (!args->PeekNext().IsEmpty()) { 2021 if (!args->PeekNext().IsEmpty()) {
2005 if (!args->GetNext(&width)) { 2022 if (!args->GetNext(&width)) {
2006 args->ThrowError(); 2023 args->ThrowError();
2007 return; 2024 return;
2008 } 2025 }
2009 } 2026 }
2010 if (!args->PeekNext().IsEmpty()) { 2027 if (!args->PeekNext().IsEmpty()) {
2011 if (!args->GetNext(&height)) { 2028 if (!args->GetNext(&height)) {
2012 args->ThrowError(); 2029 args->ThrowError();
2013 return; 2030 return;
2014 } 2031 }
2015 } 2032 }
2016 event.x = point.x; 2033 event.x = x;
2017 event.y = point.y; 2034 event.y = y;
2018 event.data.tapDown.width = width; 2035 event.data.tapDown.width = width;
2019 event.data.tapDown.height = height; 2036 event.data.tapDown.height = height;
2020 break; 2037 break;
2021 } 2038 }
2022 case WebInputEvent::GestureShowPress: 2039 case WebInputEvent::GestureShowPress:
2023 { 2040 {
2024 float width = 30; 2041 float width = 30;
2025 float height = 30; 2042 float height = 30;
2026 if (!args->PeekNext().IsEmpty()) { 2043 if (!args->PeekNext().IsEmpty()) {
2027 if (!args->GetNext(&width)) { 2044 if (!args->GetNext(&width)) {
2028 args->ThrowError(); 2045 args->ThrowError();
2029 return; 2046 return;
2030 } 2047 }
2031 if (!args->PeekNext().IsEmpty()) { 2048 if (!args->PeekNext().IsEmpty()) {
2032 if (!args->GetNext(&height)) { 2049 if (!args->GetNext(&height)) {
2033 args->ThrowError(); 2050 args->ThrowError();
2034 return; 2051 return;
2035 } 2052 }
2036 } 2053 }
2037 } 2054 }
2038 event.x = point.x; 2055 event.x = x;
2039 event.y = point.y; 2056 event.y = y;
2040 event.data.showPress.width = width; 2057 event.data.showPress.width = width;
2041 event.data.showPress.height = height; 2058 event.data.showPress.height = height;
2042 break; 2059 break;
2043 } 2060 }
2044 case WebInputEvent::GestureTapCancel: 2061 case WebInputEvent::GestureTapCancel:
2045 event.x = point.x; 2062 event.x = x;
2046 event.y = point.y; 2063 event.y = y;
2047 break; 2064 break;
2048 case WebInputEvent::GestureLongPress: 2065 case WebInputEvent::GestureLongPress:
2049 event.x = point.x; 2066 event.x = x;
2050 event.y = point.y; 2067 event.y = y;
2051 if (!args->PeekNext().IsEmpty()) { 2068 if (!args->PeekNext().IsEmpty()) {
2052 float width; 2069 float width;
2053 if (!args->GetNext(&width)) { 2070 if (!args->GetNext(&width)) {
2054 args->ThrowError(); 2071 args->ThrowError();
2055 return; 2072 return;
2056 } 2073 }
2057 event.data.longPress.width = width; 2074 event.data.longPress.width = width;
2058 if (!args->PeekNext().IsEmpty()) { 2075 if (!args->PeekNext().IsEmpty()) {
2059 float height; 2076 float height;
2060 if (!args->GetNext(&height)) { 2077 if (!args->GetNext(&height)) {
2061 args->ThrowError(); 2078 args->ThrowError();
2062 return; 2079 return;
2063 } 2080 }
2064 event.data.longPress.height = height; 2081 event.data.longPress.height = height;
2065 } 2082 }
2066 } 2083 }
2067 break; 2084 break;
2068 case WebInputEvent::GestureLongTap: 2085 case WebInputEvent::GestureLongTap:
2069 event.x = point.x; 2086 event.x = x;
2070 event.y = point.y; 2087 event.y = y;
2071 if (!args->PeekNext().IsEmpty()) { 2088 if (!args->PeekNext().IsEmpty()) {
2072 float width; 2089 float width;
2073 if (!args->GetNext(&width)) { 2090 if (!args->GetNext(&width)) {
2074 args->ThrowError(); 2091 args->ThrowError();
2075 return; 2092 return;
2076 } 2093 }
2077 event.data.longPress.width = width; 2094 event.data.longPress.width = width;
2078 if (!args->PeekNext().IsEmpty()) { 2095 if (!args->PeekNext().IsEmpty()) {
2079 float height; 2096 float height;
2080 if (!args->GetNext(&height)) { 2097 if (!args->GetNext(&height)) {
2081 args->ThrowError(); 2098 args->ThrowError();
2082 return; 2099 return;
2083 } 2100 }
2084 event.data.longPress.height = height; 2101 event.data.longPress.height = height;
2085 } 2102 }
2086 } 2103 }
2087 break; 2104 break;
2088 case WebInputEvent::GestureTwoFingerTap: 2105 case WebInputEvent::GestureTwoFingerTap:
2089 event.x = point.x; 2106 event.x = x;
2090 event.y = point.y; 2107 event.y = y;
2091 if (!args->PeekNext().IsEmpty()) { 2108 if (!args->PeekNext().IsEmpty()) {
2092 float first_finger_width; 2109 float first_finger_width;
2093 if (!args->GetNext(&first_finger_width)) { 2110 if (!args->GetNext(&first_finger_width)) {
2094 args->ThrowError(); 2111 args->ThrowError();
2095 return; 2112 return;
2096 } 2113 }
2097 event.data.twoFingerTap.firstFingerWidth = first_finger_width; 2114 event.data.twoFingerTap.firstFingerWidth = first_finger_width;
2098 if (!args->PeekNext().IsEmpty()) { 2115 if (!args->PeekNext().IsEmpty()) {
2099 float first_finger_height; 2116 float first_finger_height;
2100 if (!args->GetNext(&first_finger_height)) { 2117 if (!args->GetNext(&first_finger_height)) {
(...skipping 15 matching lines...) Expand all
2116 if (force_layout_on_events_) 2133 if (force_layout_on_events_)
2117 view_->layout(); 2134 view_->layout();
2118 2135
2119 bool result = view_->handleInputEvent(event); 2136 bool result = view_->handleInputEvent(event);
2120 2137
2121 // Long press might start a drag drop session. Complete it if so. 2138 // Long press might start a drag drop session. Complete it if so.
2122 if (type == WebInputEvent::GestureLongPress && !current_drag_data_.isNull()) { 2139 if (type == WebInputEvent::GestureLongPress && !current_drag_data_.isNull()) {
2123 WebMouseEvent mouse_event; 2140 WebMouseEvent mouse_event;
2124 InitMouseEvent(WebInputEvent::MouseDown, 2141 InitMouseEvent(WebInputEvent::MouseDown,
2125 pressed_button_, 2142 pressed_button_,
2126 point, 2143 WebPoint(x, y),
2127 GetCurrentEventTimeSec(), 2144 GetCurrentEventTimeSec(),
2128 click_count_, 2145 click_count_,
2129 0, 2146 0,
2130 &mouse_event); 2147 &mouse_event);
2131 2148
2132 FinishDragAndDrop(mouse_event, blink::WebDragOperationNone); 2149 FinishDragAndDrop(mouse_event, blink::WebDragOperationNone);
2133 } 2150 }
2134 args->Return(result); 2151 args->Return(result);
2135 } 2152 }
2136 2153
(...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after
2291 } 2308 }
2292 default: 2309 default:
2293 NOTREACHED(); 2310 NOTREACHED();
2294 } 2311 }
2295 } 2312 }
2296 2313
2297 replaying_saved_events_ = false; 2314 replaying_saved_events_ = false;
2298 } 2315 }
2299 2316
2300 } // namespace content 2317 } // namespace content
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698