| OLD | NEW |
| 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 "components/test_runner/event_sender.h" | 5 #include "components/test_runner/event_sender.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include "base/bind.h" |
| 10 #include "base/bind_helpers.h" |
| 9 #include "base/command_line.h" | 11 #include "base/command_line.h" |
| 10 #include "base/logging.h" | 12 #include "base/logging.h" |
| 11 #include "base/macros.h" | 13 #include "base/macros.h" |
| 12 #include "base/strings/string16.h" | 14 #include "base/strings/string16.h" |
| 13 #include "base/strings/string_util.h" | 15 #include "base/strings/string_util.h" |
| 14 #include "base/strings/stringprintf.h" | 16 #include "base/strings/stringprintf.h" |
| 15 #include "base/strings/utf_string_conversions.h" | 17 #include "base/strings/utf_string_conversions.h" |
| 16 #include "build/build_config.h" | 18 #include "build/build_config.h" |
| 17 #include "components/test_runner/mock_spell_check.h" | 19 #include "components/test_runner/mock_spell_check.h" |
| 18 #include "components/test_runner/test_interfaces.h" | 20 #include "components/test_runner/test_interfaces.h" |
| 21 #include "components/test_runner/web_task.h" |
| 19 #include "components/test_runner/web_test_delegate.h" | 22 #include "components/test_runner/web_test_delegate.h" |
| 20 #include "components/test_runner/web_test_proxy.h" | 23 #include "components/test_runner/web_test_proxy.h" |
| 21 #include "gin/handle.h" | 24 #include "gin/handle.h" |
| 22 #include "gin/object_template_builder.h" | 25 #include "gin/object_template_builder.h" |
| 23 #include "gin/wrappable.h" | 26 #include "gin/wrappable.h" |
| 24 #include "third_party/WebKit/public/platform/WebPointerProperties.h" | 27 #include "third_party/WebKit/public/platform/WebPointerProperties.h" |
| 25 #include "third_party/WebKit/public/platform/WebString.h" | 28 #include "third_party/WebKit/public/platform/WebString.h" |
| 26 #include "third_party/WebKit/public/platform/WebVector.h" | 29 #include "third_party/WebKit/public/platform/WebVector.h" |
| 27 #include "third_party/WebKit/public/web/WebContextMenuData.h" | 30 #include "third_party/WebKit/public/web/WebContextMenuData.h" |
| 28 #include "third_party/WebKit/public/web/WebFrame.h" | 31 #include "third_party/WebKit/public/web/WebFrame.h" |
| (...skipping 289 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 318 } | 321 } |
| 319 } | 322 } |
| 320 | 323 |
| 321 return strings; | 324 return strings; |
| 322 } | 325 } |
| 323 | 326 |
| 324 // How much we should scroll per event - the value here is chosen to match the | 327 // How much we should scroll per event - the value here is chosen to match the |
| 325 // WebKit impl and layout test results. | 328 // WebKit impl and layout test results. |
| 326 const float kScrollbarPixelsPerTick = 40.0f; | 329 const float kScrollbarPixelsPerTick = 40.0f; |
| 327 | 330 |
| 328 class MouseDownTask : public WebMethodTask<EventSender> { | |
| 329 public: | |
| 330 MouseDownTask(EventSender* obj, int button_number, int modifiers) | |
| 331 : WebMethodTask<EventSender>(obj), | |
| 332 button_number_(button_number), | |
| 333 modifiers_(modifiers) {} | |
| 334 | |
| 335 void RunIfValid() override { object_->MouseDown(button_number_, modifiers_); } | |
| 336 | |
| 337 private: | |
| 338 int button_number_; | |
| 339 int modifiers_; | |
| 340 }; | |
| 341 | |
| 342 class MouseUpTask : public WebMethodTask<EventSender> { | |
| 343 public: | |
| 344 MouseUpTask(EventSender* obj, int button_number, int modifiers) | |
| 345 : WebMethodTask<EventSender>(obj), | |
| 346 button_number_(button_number), | |
| 347 modifiers_(modifiers) {} | |
| 348 | |
| 349 void RunIfValid() override { object_->MouseUp(button_number_, modifiers_); } | |
| 350 | |
| 351 private: | |
| 352 int button_number_; | |
| 353 int modifiers_; | |
| 354 }; | |
| 355 | |
| 356 class KeyDownTask : public WebMethodTask<EventSender> { | |
| 357 public: | |
| 358 KeyDownTask(EventSender* obj, | |
| 359 const std::string code_str, | |
| 360 int modifiers, | |
| 361 KeyLocationCode location) | |
| 362 : WebMethodTask<EventSender>(obj), | |
| 363 code_str_(code_str), | |
| 364 modifiers_(modifiers), | |
| 365 location_(location) {} | |
| 366 | |
| 367 void RunIfValid() override { | |
| 368 object_->KeyDown(code_str_, modifiers_, location_); | |
| 369 } | |
| 370 | |
| 371 private: | |
| 372 std::string code_str_; | |
| 373 int modifiers_; | |
| 374 KeyLocationCode location_; | |
| 375 }; | |
| 376 | |
| 377 bool NeedsShiftModifier(int keyCode) { | 331 bool NeedsShiftModifier(int keyCode) { |
| 378 // If code is an uppercase letter, assign a SHIFT key to eventDown.modifier. | 332 // If code is an uppercase letter, assign a SHIFT key to eventDown.modifier. |
| 379 return (keyCode & 0xFF) >= 'A' && (keyCode & 0xFF) <= 'Z'; | 333 return (keyCode & 0xFF) >= 'A' && (keyCode & 0xFF) <= 'Z'; |
| 380 } | 334 } |
| 381 | 335 |
| 382 // Get the edit command corresponding to a keyboard event. | 336 // Get the edit command corresponding to a keyboard event. |
| 383 // Returns true if the specified event corresponds to an edit command, the name | 337 // Returns true if the specified event corresponds to an edit command, the name |
| 384 // of the edit command will be stored in |*name|. | 338 // of the edit command will be stored in |*name|. |
| 385 bool GetEditCommand(const WebKeyboardEvent& event, std::string* name) { | 339 bool GetEditCommand(const WebKeyboardEvent& event, std::string* name) { |
| 386 #if defined(OS_MACOSX) | 340 #if defined(OS_MACOSX) |
| (...skipping 832 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1219 wm_sys_char_ = WM_SYSCHAR; | 1173 wm_sys_char_ = WM_SYSCHAR; |
| 1220 wm_sys_dead_char_ = WM_SYSDEADCHAR; | 1174 wm_sys_dead_char_ = WM_SYSDEADCHAR; |
| 1221 #endif | 1175 #endif |
| 1222 | 1176 |
| 1223 last_mouse_pos_ = WebPoint(0, 0); | 1177 last_mouse_pos_ = WebPoint(0, 0); |
| 1224 last_click_time_sec_ = 0; | 1178 last_click_time_sec_ = 0; |
| 1225 last_click_pos_ = WebPoint(0, 0); | 1179 last_click_pos_ = WebPoint(0, 0); |
| 1226 last_button_type_ = WebMouseEvent::ButtonNone; | 1180 last_button_type_ = WebMouseEvent::ButtonNone; |
| 1227 touch_points_.clear(); | 1181 touch_points_.clear(); |
| 1228 last_context_menu_data_.reset(); | 1182 last_context_menu_data_.reset(); |
| 1229 task_list_.RevokeAll(); | 1183 weak_factory_.InvalidateWeakPtrs(); |
| 1230 current_gesture_location_ = WebPoint(0, 0); | 1184 current_gesture_location_ = WebPoint(0, 0); |
| 1231 mouse_event_queue_.clear(); | 1185 mouse_event_queue_.clear(); |
| 1232 | 1186 |
| 1233 time_offset_ms_ = 0; | 1187 time_offset_ms_ = 0; |
| 1234 click_count_ = 0; | 1188 click_count_ = 0; |
| 1235 | 1189 |
| 1236 touch_modifiers_ = 0; | 1190 touch_modifiers_ = 0; |
| 1237 touch_cancelable_ = true; | 1191 touch_cancelable_ = true; |
| 1238 touch_points_.clear(); | 1192 touch_points_.clear(); |
| 1239 } | 1193 } |
| (...skipping 775 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2015 last_mouse_pos_, | 1969 last_mouse_pos_, |
| 2016 GetCurrentEventTimeSec(), | 1970 GetCurrentEventTimeSec(), |
| 2017 click_count_, | 1971 click_count_, |
| 2018 0, | 1972 0, |
| 2019 &event); | 1973 &event); |
| 2020 HandleInputEventOnViewOrPopup(event); | 1974 HandleInputEventOnViewOrPopup(event); |
| 2021 } | 1975 } |
| 2022 | 1976 |
| 2023 | 1977 |
| 2024 void EventSender::ScheduleAsynchronousClick(int button_number, int modifiers) { | 1978 void EventSender::ScheduleAsynchronousClick(int button_number, int modifiers) { |
| 2025 delegate_->PostTask(new MouseDownTask(this, button_number, modifiers)); | 1979 delegate_->PostTask(new WebCallbackTask( |
| 2026 delegate_->PostTask(new MouseUpTask(this, button_number, modifiers)); | 1980 base::Bind(&EventSender::MouseDown, weak_factory_.GetWeakPtr(), |
| 1981 button_number, modifiers))); |
| 1982 delegate_->PostTask(new WebCallbackTask( |
| 1983 base::Bind(&EventSender::MouseUp, weak_factory_.GetWeakPtr(), |
| 1984 button_number, modifiers))); |
| 2027 } | 1985 } |
| 2028 | 1986 |
| 2029 void EventSender::ScheduleAsynchronousKeyDown(const std::string& code_str, | 1987 void EventSender::ScheduleAsynchronousKeyDown(const std::string& code_str, |
| 2030 int modifiers, | 1988 int modifiers, |
| 2031 KeyLocationCode location) { | 1989 KeyLocationCode location) { |
| 2032 delegate_->PostTask(new KeyDownTask(this, code_str, modifiers, location)); | 1990 delegate_->PostTask(new WebCallbackTask( |
| 1991 base::Bind(&EventSender::KeyDown, weak_factory_.GetWeakPtr(), code_str, |
| 1992 modifiers, location))); |
| 2033 } | 1993 } |
| 2034 | 1994 |
| 2035 double EventSender::GetCurrentEventTimeSec() { | 1995 double EventSender::GetCurrentEventTimeSec() { |
| 2036 return (base::TimeTicks::Now() - base::TimeTicks()).InSecondsF() + | 1996 return (base::TimeTicks::Now() - base::TimeTicks()).InSecondsF() + |
| 2037 time_offset_ms_ / 1000.0; | 1997 time_offset_ms_ / 1000.0; |
| 2038 } | 1998 } |
| 2039 | 1999 |
| 2040 void EventSender::DoLeapForward(int milliseconds) { | 2000 void EventSender::DoLeapForward(int milliseconds) { |
| 2041 time_offset_ms_ += milliseconds; | 2001 time_offset_ms_ += milliseconds; |
| 2042 } | 2002 } |
| (...skipping 612 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2655 &end_event); | 2615 &end_event); |
| 2656 end_event.data.scrollEnd.deltaUnits = | 2616 end_event.data.scrollEnd.deltaUnits = |
| 2657 begin_event.data.scrollBegin.deltaHintUnits; | 2617 begin_event.data.scrollBegin.deltaHintUnits; |
| 2658 | 2618 |
| 2659 if (force_layout_on_events_) | 2619 if (force_layout_on_events_) |
| 2660 view_->updateAllLifecyclePhases(); | 2620 view_->updateAllLifecyclePhases(); |
| 2661 HandleInputEventOnViewOrPopup(end_event); | 2621 HandleInputEventOnViewOrPopup(end_event); |
| 2662 } | 2622 } |
| 2663 | 2623 |
| 2664 } // namespace test_runner | 2624 } // namespace test_runner |
| OLD | NEW |