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 "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" |
11 #include "content/shell/renderer/test_runner/WebTestDelegate.h" | |
12 #include "content/shell/renderer/test_runner/mock_spell_check.h" | 11 #include "content/shell/renderer/test_runner/mock_spell_check.h" |
13 #include "content/shell/renderer/test_runner/test_interfaces.h" | 12 #include "content/shell/renderer/test_runner/test_interfaces.h" |
| 13 #include "content/shell/renderer/test_runner/web_test_delegate.h" |
14 #include "content/shell/renderer/test_runner/web_test_proxy.h" | 14 #include "content/shell/renderer/test_runner/web_test_proxy.h" |
15 #include "gin/handle.h" | 15 #include "gin/handle.h" |
16 #include "gin/object_template_builder.h" | 16 #include "gin/object_template_builder.h" |
17 #include "gin/wrappable.h" | 17 #include "gin/wrappable.h" |
18 #include "third_party/WebKit/public/platform/WebString.h" | 18 #include "third_party/WebKit/public/platform/WebString.h" |
19 #include "third_party/WebKit/public/platform/WebVector.h" | 19 #include "third_party/WebKit/public/platform/WebVector.h" |
20 #include "third_party/WebKit/public/web/WebContextMenuData.h" | 20 #include "third_party/WebKit/public/web/WebContextMenuData.h" |
21 #include "third_party/WebKit/public/web/WebFrame.h" | 21 #include "third_party/WebKit/public/web/WebFrame.h" |
22 #include "third_party/WebKit/public/web/WebKit.h" | 22 #include "third_party/WebKit/public/web/WebKit.h" |
23 #include "third_party/WebKit/public/web/WebView.h" | 23 #include "third_party/WebKit/public/web/WebView.h" |
(...skipping 1313 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1337 if (force_layout_on_events_) | 1337 if (force_layout_on_events_) |
1338 view_->layout(); | 1338 view_->layout(); |
1339 | 1339 |
1340 // In the browser, if a keyboard event corresponds to an editor command, | 1340 // In the browser, if a keyboard event corresponds to an editor command, |
1341 // the command will be dispatched to the renderer just before dispatching | 1341 // the command will be dispatched to the renderer just before dispatching |
1342 // the keyboard event, and then it will be executed in the | 1342 // the keyboard event, and then it will be executed in the |
1343 // RenderView::handleCurrentKeyboardEvent() method. | 1343 // RenderView::handleCurrentKeyboardEvent() method. |
1344 // We just simulate the same behavior here. | 1344 // We just simulate the same behavior here. |
1345 std::string edit_command; | 1345 std::string edit_command; |
1346 if (GetEditCommand(event_down, &edit_command)) | 1346 if (GetEditCommand(event_down, &edit_command)) |
1347 delegate_->setEditCommand(edit_command, ""); | 1347 delegate_->SetEditCommand(edit_command, ""); |
1348 | 1348 |
1349 view_->handleInputEvent(event_down); | 1349 view_->handleInputEvent(event_down); |
1350 | 1350 |
1351 if (code == ui::VKEY_ESCAPE && !current_drag_data_.isNull()) { | 1351 if (code == ui::VKEY_ESCAPE && !current_drag_data_.isNull()) { |
1352 WebMouseEvent event; | 1352 WebMouseEvent event; |
1353 InitMouseEvent(WebInputEvent::MouseDown, | 1353 InitMouseEvent(WebInputEvent::MouseDown, |
1354 pressed_button_, | 1354 pressed_button_, |
1355 last_mouse_pos_, | 1355 last_mouse_pos_, |
1356 GetCurrentEventTimeSec(), | 1356 GetCurrentEventTimeSec(), |
1357 click_count_, | 1357 click_count_, |
1358 0, | 1358 0, |
1359 &event); | 1359 &event); |
1360 FinishDragAndDrop(event, blink::WebDragOperationNone); | 1360 FinishDragAndDrop(event, blink::WebDragOperationNone); |
1361 } | 1361 } |
1362 | 1362 |
1363 delegate_->clearEditCommand(); | 1363 delegate_->ClearEditCommand(); |
1364 | 1364 |
1365 if (generate_char) { | 1365 if (generate_char) { |
1366 WebKeyboardEvent event_char = event_up; | 1366 WebKeyboardEvent event_char = event_up; |
1367 event_char.type = WebInputEvent::Char; | 1367 event_char.type = WebInputEvent::Char; |
1368 event_char.keyIdentifier[0] = '\0'; | 1368 event_char.keyIdentifier[0] = '\0'; |
1369 view_->handleInputEvent(event_char); | 1369 view_->handleInputEvent(event_char); |
1370 } | 1370 } |
1371 | 1371 |
1372 view_->handleInputEvent(event_up); | 1372 view_->handleInputEvent(event_up); |
1373 } | 1373 } |
(...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1533 | 1533 |
1534 void EventSender::DumpFilenameBeingDragged() { | 1534 void EventSender::DumpFilenameBeingDragged() { |
1535 WebString filename; | 1535 WebString filename; |
1536 WebVector<WebDragData::Item> items = current_drag_data_.items(); | 1536 WebVector<WebDragData::Item> items = current_drag_data_.items(); |
1537 for (size_t i = 0; i < items.size(); ++i) { | 1537 for (size_t i = 0; i < items.size(); ++i) { |
1538 if (items[i].storageType == WebDragData::Item::StorageTypeBinaryData) { | 1538 if (items[i].storageType == WebDragData::Item::StorageTypeBinaryData) { |
1539 filename = items[i].title; | 1539 filename = items[i].title; |
1540 break; | 1540 break; |
1541 } | 1541 } |
1542 } | 1542 } |
1543 delegate_->printMessage(std::string("Filename being dragged: ") + | 1543 delegate_->PrintMessage(std::string("Filename being dragged: ") + |
1544 filename.utf8().data() + "\n"); | 1544 filename.utf8().data() + "\n"); |
1545 } | 1545 } |
1546 | 1546 |
1547 void EventSender::GestureFlingCancel() { | 1547 void EventSender::GestureFlingCancel() { |
1548 WebGestureEvent event; | 1548 WebGestureEvent event; |
1549 event.type = WebInputEvent::GestureFlingCancel; | 1549 event.type = WebInputEvent::GestureFlingCancel; |
1550 event.timeStampSeconds = GetCurrentEventTimeSec(); | 1550 event.timeStampSeconds = GetCurrentEventTimeSec(); |
1551 | 1551 |
1552 if (force_layout_on_events_) | 1552 if (force_layout_on_events_) |
1553 view_->layout(); | 1553 view_->layout(); |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1608 DoLeapForward(milliseconds); | 1608 DoLeapForward(milliseconds); |
1609 } | 1609 } |
1610 } | 1610 } |
1611 | 1611 |
1612 void EventSender::BeginDragWithFiles(const std::vector<std::string>& files) { | 1612 void EventSender::BeginDragWithFiles(const std::vector<std::string>& files) { |
1613 current_drag_data_.initialize(); | 1613 current_drag_data_.initialize(); |
1614 WebVector<WebString> absolute_filenames(files.size()); | 1614 WebVector<WebString> absolute_filenames(files.size()); |
1615 for (size_t i = 0; i < files.size(); ++i) { | 1615 for (size_t i = 0; i < files.size(); ++i) { |
1616 WebDragData::Item item; | 1616 WebDragData::Item item; |
1617 item.storageType = WebDragData::Item::StorageTypeFilename; | 1617 item.storageType = WebDragData::Item::StorageTypeFilename; |
1618 item.filenameData = delegate_->getAbsoluteWebStringFromUTF8Path(files[i]); | 1618 item.filenameData = delegate_->GetAbsoluteWebStringFromUTF8Path(files[i]); |
1619 current_drag_data_.addItem(item); | 1619 current_drag_data_.addItem(item); |
1620 absolute_filenames[i] = item.filenameData; | 1620 absolute_filenames[i] = item.filenameData; |
1621 } | 1621 } |
1622 current_drag_data_.setFilesystemId( | 1622 current_drag_data_.setFilesystemId( |
1623 delegate_->registerIsolatedFileSystem(absolute_filenames)); | 1623 delegate_->RegisterIsolatedFileSystem(absolute_filenames)); |
1624 current_drag_effects_allowed_ = blink::WebDragOperationCopy; | 1624 current_drag_effects_allowed_ = blink::WebDragOperationCopy; |
1625 | 1625 |
1626 // Provide a drag source. | 1626 // Provide a drag source. |
1627 view_->dragTargetDragEnter(current_drag_data_, | 1627 view_->dragTargetDragEnter(current_drag_data_, |
1628 last_mouse_pos_, | 1628 last_mouse_pos_, |
1629 last_mouse_pos_, | 1629 last_mouse_pos_, |
1630 current_drag_effects_allowed_, | 1630 current_drag_effects_allowed_, |
1631 0); | 1631 0); |
1632 // |is_drag_mode_| saves events and then replays them later. We don't | 1632 // |is_drag_mode_| saves events and then replays them later. We don't |
1633 // need/want that. | 1633 // need/want that. |
(...skipping 235 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1869 GetCurrentEventTimeSec(), | 1869 GetCurrentEventTimeSec(), |
1870 click_count_, | 1870 click_count_, |
1871 0, | 1871 0, |
1872 &event); | 1872 &event); |
1873 event.momentumPhase = WebMouseWheelEvent::PhaseEnded; | 1873 event.momentumPhase = WebMouseWheelEvent::PhaseEnded; |
1874 event.hasPreciseScrollingDeltas = true; | 1874 event.hasPreciseScrollingDeltas = true; |
1875 view_->handleInputEvent(event); | 1875 view_->handleInputEvent(event); |
1876 } | 1876 } |
1877 | 1877 |
1878 void EventSender::ScheduleAsynchronousClick(int button_number, int modifiers) { | 1878 void EventSender::ScheduleAsynchronousClick(int button_number, int modifiers) { |
1879 delegate_->postTask(new MouseDownTask(this, button_number, modifiers)); | 1879 delegate_->PostTask(new MouseDownTask(this, button_number, modifiers)); |
1880 delegate_->postTask(new MouseUpTask(this, button_number, modifiers)); | 1880 delegate_->PostTask(new MouseUpTask(this, button_number, modifiers)); |
1881 } | 1881 } |
1882 | 1882 |
1883 void EventSender::ScheduleAsynchronousKeyDown(const std::string& code_str, | 1883 void EventSender::ScheduleAsynchronousKeyDown(const std::string& code_str, |
1884 int modifiers, | 1884 int modifiers, |
1885 KeyLocationCode location) { | 1885 KeyLocationCode location) { |
1886 delegate_->postTask(new KeyDownTask(this, code_str, modifiers, location)); | 1886 delegate_->PostTask(new KeyDownTask(this, code_str, modifiers, location)); |
1887 } | 1887 } |
1888 | 1888 |
1889 double EventSender::GetCurrentEventTimeSec() { | 1889 double EventSender::GetCurrentEventTimeSec() { |
1890 return (delegate_->getCurrentTimeInMillisecond() + time_offset_ms_) / 1000.0; | 1890 return (delegate_->GetCurrentTimeInMillisecond() + time_offset_ms_) / 1000.0; |
1891 } | 1891 } |
1892 | 1892 |
1893 void EventSender::DoLeapForward(int milliseconds) { | 1893 void EventSender::DoLeapForward(int milliseconds) { |
1894 time_offset_ms_ += milliseconds; | 1894 time_offset_ms_ += milliseconds; |
1895 } | 1895 } |
1896 | 1896 |
1897 void EventSender::SendCurrentTouchEvent(WebInputEvent::Type type) { | 1897 void EventSender::SendCurrentTouchEvent(WebInputEvent::Type type) { |
1898 DCHECK_GT(static_cast<unsigned>(WebTouchEvent::touchesLengthCap), | 1898 DCHECK_GT(static_cast<unsigned>(WebTouchEvent::touchesLengthCap), |
1899 touch_points_.size()); | 1899 touch_points_.size()); |
1900 if (force_layout_on_events_) | 1900 if (force_layout_on_events_) |
(...skipping 390 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2291 } | 2291 } |
2292 default: | 2292 default: |
2293 NOTREACHED(); | 2293 NOTREACHED(); |
2294 } | 2294 } |
2295 } | 2295 } |
2296 | 2296 |
2297 replaying_saved_events_ = false; | 2297 replaying_saved_events_ = false; |
2298 } | 2298 } |
2299 | 2299 |
2300 } // namespace content | 2300 } // namespace content |
OLD | NEW |