1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style license that can be 3 // found in the LICENSE file. 4 5 #ifndef CHROME_TEST_WEBDRIVER_COMMANDS_MOUSE_COMMANDS_H_ 6 #define CHROME_TEST_WEBDRIVER_COMMANDS_MOUSE_COMMANDS_H_ 7 8 #include <string> 9 #include <vector> 10 11 #include "chrome/test/webdriver/commands/webelement_commands.h" 12 #include "chrome/test/webdriver/webdriver_element_id.h" 13 14 namespace base { 15 class DictionaryValue; 16 } 17 18 namespace webdriver { 19 20 class Response; 21 22 // Click an element. See: 23 // http://selenium.googlecode.com/svn/trunk/docs/api/java/org/openqa/selenium/WebElement.html#click() 24 class MoveAndClickCommand : public WebElementCommand { 25 public: 26 MoveAndClickCommand(const std::vector<std::string>& path_segments, 27 const base::DictionaryValue* const parameters); 28 virtual ~MoveAndClickCommand(); 29 30 virtual bool DoesPost() OVERRIDE; 31 virtual void ExecutePost(Response* const response) OVERRIDE; 32 33 private: 34 DISALLOW_COPY_AND_ASSIGN(MoveAndClickCommand); 35 }; 36 37 // Move the mouse over an element. See: 38 // http://code.google.com/p/selenium/wiki/JsonWireProtocol#/session/:sessionId/element/:id/hover 39 class HoverCommand : public WebElementCommand { 40 public: 41 HoverCommand(const std::vector<std::string>& path_segments, 42 const base::DictionaryValue* const parameters); 43 virtual ~HoverCommand(); 44 45 virtual bool DoesPost() OVERRIDE; 46 virtual void ExecutePost(Response* const response) OVERRIDE; 47 48 private: 49 DISALLOW_COPY_AND_ASSIGN(HoverCommand); 50 }; 51 52 // Drag and drop an element. The distance to drag an element should be 53 // specified relative to the upper-left corner of the page. See: 54 // http://code.google.com/p/selenium/wiki/JsonWireProtocol#/session/:sessionId/element/:id/drag 55 class DragCommand : public WebElementCommand { 56 public: 57 DragCommand(const std::vector<std::string>& path_segments, 58 const base::DictionaryValue* const parameters); 59 virtual ~DragCommand(); 60 61 virtual bool Init(Response* const response) OVERRIDE; 62 virtual bool DoesPost() OVERRIDE; 63 virtual void ExecutePost(Response* const response) OVERRIDE; 64 65 private: 66 int drag_x_, drag_y_; 67 68 DISALLOW_COPY_AND_ASSIGN(DragCommand); 69 }; 70 71 // Base class for the following API command classes. 72 // - /session/:sessionId/moveto 73 // - /session/:sessionId/click 74 // - /session/:sessionId/buttondown 75 // - /session/:sessionId/buttonup 76 // - /session/:sessionId/doubleclick 77 class AdvancedMouseCommand : public WebDriverCommand { 78 public: 79 AdvancedMouseCommand(const std::vector<std::string>& path_segments, 80 const base::DictionaryValue* const parameters); 81 virtual ~AdvancedMouseCommand(); 82 83 virtual bool DoesPost() OVERRIDE; 84 85 private: 86 DISALLOW_COPY_AND_ASSIGN(AdvancedMouseCommand); 87 }; 88 89 // Move the mouse by an offset of the specified element. If no element is 90 // specified, the move is relative to the current mouse cursor. If an element is 91 // provided but no offset, the mouse will be moved to the center of the element. 92 // If the element is not visible, it will be scrolled into view. 93 // http://code.google.com/p/selenium/wiki/JsonWireProtocol#/session/:sessionId/moveto 94 class MoveToCommand : public AdvancedMouseCommand { 95 public: 96 MoveToCommand(const std::vector<std::string>& path_segments, 97 const base::DictionaryValue* const parameters); 98 virtual ~MoveToCommand(); 99 100 virtual bool Init(Response* const response) OVERRIDE; 101 virtual void ExecutePost(Response* const response) OVERRIDE; 102 103 private: 104 bool has_element_; 105 ElementId element_; 106 bool has_offset_; 107 int x_offset_; 108 int y_offset_; 109 110 DISALLOW_COPY_AND_ASSIGN(MoveToCommand); 111 }; 112 113 // Click any mouse button (at the coordinates set by the last moveto command). 114 // Note that calling this command after calling buttondown and before calling 115 // button up (or any out-of-order interactions sequence) will yield undefined 116 // behaviour). 117 // http://code.google.com/p/selenium/wiki/JsonWireProtocol#/session/:sessionId/click 118 class ClickCommand : public AdvancedMouseCommand { 119 public: 120 ClickCommand(const std::vector<std::string>& path_segments, 121 const base::DictionaryValue* const parameters); 122 virtual ~ClickCommand(); 123 124 virtual bool Init(Response* const response) OVERRIDE; 125 virtual void ExecutePost(Response* const response) OVERRIDE; 126 127 private: 128 int button_; 129 130 DISALLOW_COPY_AND_ASSIGN(ClickCommand); 131 }; 132 133 // Click and hold the left mouse button (at the coordinates set by the last 134 // moveto command). Note that the next mouse-related command that should follow 135 // is buttondown . Any other mouse command (such as click or another call to 136 // buttondown) will yield undefined behaviour. 137 // http://code.google.com/p/selenium/wiki/JsonWireProtocol#/session/:sessionId/buttondown 138 class ButtonDownCommand : public AdvancedMouseCommand { 139 public: 140 ButtonDownCommand(const std::vector<std::string>& path_segments, 141 const base::DictionaryValue* const parameters); 142 virtual ~ButtonDownCommand(); 143 144 virtual void ExecutePost(Response* const response) OVERRIDE; 145 146 private: 147 DISALLOW_COPY_AND_ASSIGN(ButtonDownCommand); 148 }; 149 150 // Releases the mouse button previously held (where the mouse is currently at). 151 // Must be called once for every buttondown command issued. See the note in 152 // click and buttondown about implications of out-of-order commands. 153 // http://code.google.com/p/selenium/wiki/JsonWireProtocol#/session/:sessionId/buttonup 154 class ButtonUpCommand : public AdvancedMouseCommand { 155 public: 156 ButtonUpCommand(const std::vector<std::string>& path_segments, 157 const base::DictionaryValue* const parameters); 158 virtual ~ButtonUpCommand(); 159 160 virtual void ExecutePost(Response* const response) OVERRIDE; 161 162 private: 163 DISALLOW_COPY_AND_ASSIGN(ButtonUpCommand); 164 }; 165 166 // Double-clicks at the current mouse coordinates (set by moveto). 167 // http://code.google.com/p/selenium/wiki/JsonWireProtocol#/session/:sessionId/doubleclick 168 class DoubleClickCommand : public AdvancedMouseCommand { 169 public: 170 DoubleClickCommand(const std::vector<std::string>& ps, 171 const base::DictionaryValue* const parameters); 172 virtual ~DoubleClickCommand(); 173 174 virtual void ExecutePost(Response* const response) OVERRIDE; 175 176 private: 177 DISALLOW_COPY_AND_ASSIGN(DoubleClickCommand); 178 }; 179 180 } // namespace webdriver 181 182 #endif // CHROME_TEST_WEBDRIVER_COMMANDS_MOUSE_COMMANDS_H_ 183