| 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" |
| (...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 131 // this function does only what LayoutTests are expecting: | 131 // this function does only what LayoutTests are expecting: |
| 132 // - Many test checks the count of items. So returning non-zero value makes | 132 // - Many test checks the count of items. So returning non-zero value makes |
| 133 // sense. | 133 // sense. |
| 134 // - Some test compares the count before and after some action. So changing the | 134 // - Some test compares the count before and after some action. So changing the |
| 135 // count based on flags also makes sense. This function is doing such for some | 135 // count based on flags also makes sense. This function is doing such for some |
| 136 // flags. | 136 // flags. |
| 137 // - Some test even checks actual string content. So providing it would be also | 137 // - Some test even checks actual string content. So providing it would be also |
| 138 // helpful. | 138 // helpful. |
| 139 std::vector<std::string> MakeMenuItemStringsFor( | 139 std::vector<std::string> MakeMenuItemStringsFor( |
| 140 WebContextMenuData* context_menu, | 140 WebContextMenuData* context_menu, |
| 141 WebTestRunner::WebTestDelegate* delegate) { | 141 WebTestDelegate* delegate) { |
| 142 // These constants are based on Safari's context menu because tests are made | 142 // These constants are based on Safari's context menu because tests are made |
| 143 // for it. | 143 // for it. |
| 144 static const char* kNonEditableMenuStrings[] = { | 144 static const char* kNonEditableMenuStrings[] = { |
| 145 "Back", | 145 "Back", |
| 146 "Reload Page", | 146 "Reload Page", |
| 147 "Open in Dashbaord", | 147 "Open in Dashbaord", |
| 148 "<separator>", | 148 "<separator>", |
| 149 "View Source", | 149 "View Source", |
| 150 "Save Page As", | 150 "Save Page As", |
| 151 "Print Page", | 151 "Print Page", |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 196 const float kScrollbarPixelsPerTick = 40.0f; | 196 const float kScrollbarPixelsPerTick = 40.0f; |
| 197 | 197 |
| 198 WebMouseEvent::Button GetButtonTypeFromButtonNumber(int button_code) { | 198 WebMouseEvent::Button GetButtonTypeFromButtonNumber(int button_code) { |
| 199 if (!button_code) | 199 if (!button_code) |
| 200 return WebMouseEvent::ButtonLeft; | 200 return WebMouseEvent::ButtonLeft; |
| 201 if (button_code == 2) | 201 if (button_code == 2) |
| 202 return WebMouseEvent::ButtonRight; | 202 return WebMouseEvent::ButtonRight; |
| 203 return WebMouseEvent::ButtonMiddle; | 203 return WebMouseEvent::ButtonMiddle; |
| 204 } | 204 } |
| 205 | 205 |
| 206 class MouseDownTask : public WebTestRunner::WebMethodTask<EventSender> { | 206 class MouseDownTask : public WebMethodTask<EventSender> { |
| 207 public: | 207 public: |
| 208 MouseDownTask(EventSender* obj, int button_number, int modifiers) | 208 MouseDownTask(EventSender* obj, int button_number, int modifiers) |
| 209 : WebMethodTask<EventSender>(obj), | 209 : WebMethodTask<EventSender>(obj), |
| 210 button_number_(button_number), | 210 button_number_(button_number), |
| 211 modifiers_(modifiers) {} | 211 modifiers_(modifiers) {} |
| 212 | 212 |
| 213 virtual void runIfValid() OVERRIDE { | 213 virtual void runIfValid() OVERRIDE { |
| 214 m_object->MouseDown(button_number_, modifiers_); | 214 m_object->MouseDown(button_number_, modifiers_); |
| 215 } | 215 } |
| 216 | 216 |
| 217 private: | 217 private: |
| 218 int button_number_; | 218 int button_number_; |
| 219 int modifiers_; | 219 int modifiers_; |
| 220 }; | 220 }; |
| 221 | 221 |
| 222 class MouseUpTask : public WebTestRunner::WebMethodTask<EventSender> { | 222 class MouseUpTask : public WebMethodTask<EventSender> { |
| 223 public: | 223 public: |
| 224 MouseUpTask(EventSender* obj, int button_number, int modifiers) | 224 MouseUpTask(EventSender* obj, int button_number, int modifiers) |
| 225 : WebMethodTask<EventSender>(obj), | 225 : WebMethodTask<EventSender>(obj), |
| 226 button_number_(button_number), | 226 button_number_(button_number), |
| 227 modifiers_(modifiers) {} | 227 modifiers_(modifiers) {} |
| 228 | 228 |
| 229 virtual void runIfValid() OVERRIDE { | 229 virtual void runIfValid() OVERRIDE { |
| 230 m_object->MouseUp(button_number_, modifiers_); | 230 m_object->MouseUp(button_number_, modifiers_); |
| 231 } | 231 } |
| 232 | 232 |
| 233 private: | 233 private: |
| 234 int button_number_; | 234 int button_number_; |
| 235 int modifiers_; | 235 int modifiers_; |
| 236 }; | 236 }; |
| 237 | 237 |
| 238 class KeyDownTask : public WebTestRunner::WebMethodTask<EventSender> { | 238 class KeyDownTask : public WebMethodTask<EventSender> { |
| 239 public: | 239 public: |
| 240 KeyDownTask(EventSender* obj, | 240 KeyDownTask(EventSender* obj, |
| 241 const std::string code_str, | 241 const std::string code_str, |
| 242 int modifiers, | 242 int modifiers, |
| 243 KeyLocationCode location) | 243 KeyLocationCode location) |
| 244 : WebMethodTask<EventSender>(obj), | 244 : WebMethodTask<EventSender>(obj), |
| 245 code_str_(code_str), | 245 code_str_(code_str), |
| 246 modifiers_(modifiers), | 246 modifiers_(modifiers), |
| 247 location_(location) {} | 247 location_(location) {} |
| 248 | 248 |
| (...skipping 751 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1000 | 1000 |
| 1001 WebMouseEvent::Button EventSender::last_button_type_ = | 1001 WebMouseEvent::Button EventSender::last_button_type_ = |
| 1002 WebMouseEvent::ButtonNone; | 1002 WebMouseEvent::ButtonNone; |
| 1003 | 1003 |
| 1004 EventSender::SavedEvent::SavedEvent() | 1004 EventSender::SavedEvent::SavedEvent() |
| 1005 : type(TYPE_UNSPECIFIED), | 1005 : type(TYPE_UNSPECIFIED), |
| 1006 button_type(WebMouseEvent::ButtonNone), | 1006 button_type(WebMouseEvent::ButtonNone), |
| 1007 milliseconds(0), | 1007 milliseconds(0), |
| 1008 modifiers(0) {} | 1008 modifiers(0) {} |
| 1009 | 1009 |
| 1010 EventSender::EventSender(WebTestRunner::TestInterfaces* interfaces) | 1010 EventSender::EventSender(TestInterfaces* interfaces) |
| 1011 : interfaces_(interfaces), | 1011 : interfaces_(interfaces), |
| 1012 delegate_(NULL), | 1012 delegate_(NULL), |
| 1013 view_(NULL), | 1013 view_(NULL), |
| 1014 force_layout_on_events_(false), | 1014 force_layout_on_events_(false), |
| 1015 is_drag_mode_(true), | 1015 is_drag_mode_(true), |
| 1016 touch_modifiers_(0), | 1016 touch_modifiers_(0), |
| 1017 touch_cancelable_(true), | 1017 touch_cancelable_(true), |
| 1018 replaying_saved_events_(false), | 1018 replaying_saved_events_(false), |
| 1019 current_drag_effects_allowed_(blink::WebDragOperationNone), | 1019 current_drag_effects_allowed_(blink::WebDragOperationNone), |
| 1020 last_click_time_sec_(0), | 1020 last_click_time_sec_(0), |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1072 | 1072 |
| 1073 touch_modifiers_ = 0; | 1073 touch_modifiers_ = 0; |
| 1074 touch_cancelable_ = true; | 1074 touch_cancelable_ = true; |
| 1075 touch_points_.clear(); | 1075 touch_points_.clear(); |
| 1076 } | 1076 } |
| 1077 | 1077 |
| 1078 void EventSender::Install(WebFrame* frame) { | 1078 void EventSender::Install(WebFrame* frame) { |
| 1079 EventSenderBindings::Install(weak_factory_.GetWeakPtr(), frame); | 1079 EventSenderBindings::Install(weak_factory_.GetWeakPtr(), frame); |
| 1080 } | 1080 } |
| 1081 | 1081 |
| 1082 void EventSender::SetDelegate(WebTestRunner::WebTestDelegate* delegate) { | 1082 void EventSender::SetDelegate(WebTestDelegate* delegate) { |
| 1083 delegate_ = delegate; | 1083 delegate_ = delegate; |
| 1084 } | 1084 } |
| 1085 | 1085 |
| 1086 void EventSender::SetWebView(WebView* view) { | 1086 void EventSender::SetWebView(WebView* view) { |
| 1087 view_ = view; | 1087 view_ = view; |
| 1088 } | 1088 } |
| 1089 | 1089 |
| 1090 void EventSender::SetContextMenuData(const WebContextMenuData& data) { | 1090 void EventSender::SetContextMenuData(const WebContextMenuData& data) { |
| 1091 last_context_menu_data_.reset(new WebContextMenuData(data)); | 1091 last_context_menu_data_.reset(new WebContextMenuData(data)); |
| 1092 } | 1092 } |
| (...skipping 302 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1395 window_list.at(i)->webView()->setZoomLevel( | 1395 window_list.at(i)->webView()->setZoomLevel( |
| 1396 window_list.at(i)->webView()->zoomLevel() - 1); | 1396 window_list.at(i)->webView()->zoomLevel() - 1); |
| 1397 } | 1397 } |
| 1398 } | 1398 } |
| 1399 | 1399 |
| 1400 void EventSender::SetPageZoomFactor(double zoom_factor) { | 1400 void EventSender::SetPageZoomFactor(double zoom_factor) { |
| 1401 const std::vector<WebTestProxyBase*>& window_list = interfaces_->windowList(); | 1401 const std::vector<WebTestProxyBase*>& window_list = interfaces_->windowList(); |
| 1402 | 1402 |
| 1403 for (size_t i = 0; i < window_list.size(); ++i) { | 1403 for (size_t i = 0; i < window_list.size(); ++i) { |
| 1404 window_list.at(i)->webView()->setZoomLevel( | 1404 window_list.at(i)->webView()->setZoomLevel( |
| 1405 content::ZoomFactorToZoomLevel(zoom_factor)); | 1405 ZoomFactorToZoomLevel(zoom_factor)); |
| 1406 } | 1406 } |
| 1407 } | 1407 } |
| 1408 | 1408 |
| 1409 void EventSender::SetPageScaleFactor(float scale_factor, int x, int y) { | 1409 void EventSender::SetPageScaleFactor(float scale_factor, int x, int y) { |
| 1410 view_->setPageScaleFactorLimits(scale_factor, scale_factor); | 1410 view_->setPageScaleFactorLimits(scale_factor, scale_factor); |
| 1411 view_->setPageScaleFactor(scale_factor, WebPoint(x, y)); | 1411 view_->setPageScaleFactor(scale_factor, WebPoint(x, y)); |
| 1412 } | 1412 } |
| 1413 | 1413 |
| 1414 void EventSender::ClearTouchPoints() { | 1414 void EventSender::ClearTouchPoints() { |
| 1415 touch_points_.clear(); | 1415 touch_points_.clear(); |
| (...skipping 755 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2171 } | 2171 } |
| 2172 default: | 2172 default: |
| 2173 NOTREACHED(); | 2173 NOTREACHED(); |
| 2174 } | 2174 } |
| 2175 } | 2175 } |
| 2176 | 2176 |
| 2177 replaying_saved_events_ = false; | 2177 replaying_saved_events_ = false; |
| 2178 } | 2178 } |
| 2179 | 2179 |
| 2180 } // namespace content | 2180 } // namespace content |
| OLD | NEW |