summaryrefslogtreecommitdiffstats
path: root/chrome/test/webdriver/commands/mouse_commands.h
blob: cc6f931aa132a07ae9884a60cee5a6bc7d0fcc88 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
// Copyright (c) 2011 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef CHROME_TEST_WEBDRIVER_COMMANDS_MOUSE_COMMANDS_H_
#define CHROME_TEST_WEBDRIVER_COMMANDS_MOUSE_COMMANDS_H_

#include <string>
#include <vector>

#include "chrome/test/webdriver/commands/webelement_commands.h"
#include "chrome/test/webdriver/web_element_id.h"

class DictionaryValue;

namespace gfx {
class Point;
}

namespace webdriver {

class Error;
class Response;

// Base class for the following API command classes.
// - /session/:sessionId/element/:id/click
// - /session/:sessionId/element/:id/hover
// - /session/:sessionId/element/:id/drag
class ElementMouseCommand : public WebElementCommand {
 public:
  ElementMouseCommand(const std::vector<std::string>& path_segments,
                      const DictionaryValue* const parameters);
  virtual ~ElementMouseCommand();

  virtual bool DoesPost();
  virtual void ExecutePost(Response* const response);
  virtual Error* Action(const gfx::Point& location) = 0;

 private:
  DISALLOW_COPY_AND_ASSIGN(ElementMouseCommand);
};

// Click this element. If this causes a new page to load, this method will
// block until the page has loaded. At this point, you should discard all
// references to this element and any further operations performed on this
// element will have undefined behaviour unless you know that the element
// and the page will still be present. See:
// http://selenium.googlecode.com/svn/trunk/docs/api/java/org/openqa/selenium/WebElement.html#click()
class MoveAndClickCommand : public ElementMouseCommand {
 public:
  MoveAndClickCommand(const std::vector<std::string>& path_segments,
                      const DictionaryValue* const parameters);
  virtual ~MoveAndClickCommand();

  virtual Error* Action(const gfx::Point& location);

 private:
  DISALLOW_COPY_AND_ASSIGN(MoveAndClickCommand);
};

// Move the mouse over an element. See:
// http://code.google.com/p/selenium/wiki/JsonWireProtocol#/session/:sessionId/element/:id/hover
class HoverCommand : public ElementMouseCommand {
 public:
  HoverCommand(const std::vector<std::string>& path_segments,
               const DictionaryValue* const parameters);
  virtual ~HoverCommand();

  virtual Error* Action(const gfx::Point& location);

 private:
  DISALLOW_COPY_AND_ASSIGN(HoverCommand);
};

// Drag and drop an element. The distance to drag an element should be
// specified relative to the upper-left corner of the page. See:
// http://code.google.com/p/selenium/wiki/JsonWireProtocol#/session/:sessionId/element/:id/drag
class DragCommand : public ElementMouseCommand {
 public:
  DragCommand(const std::vector<std::string>& path_segments,
              const DictionaryValue* const parameters);
  virtual ~DragCommand();

  virtual bool Init(Response* const response);
  virtual Error* Action(const gfx::Point& location);

 private:
  int drag_x_, drag_y_;

  DISALLOW_COPY_AND_ASSIGN(DragCommand);
};

// Base class for the following API command classes.
// - /session/:sessionId/moveto
// - /session/:sessionId/click
// - /session/:sessionId/buttondown
// - /session/:sessionId/buttonup
// - /session/:sessionId/doubleclick
class AdvancedMouseCommand : public WebDriverCommand {
 public:
  AdvancedMouseCommand(const std::vector<std::string>& path_segments,
                       const DictionaryValue* const parameters);
  virtual ~AdvancedMouseCommand();

  virtual bool DoesPost();

 private:
  DISALLOW_COPY_AND_ASSIGN(AdvancedMouseCommand);
};

// Move the mouse by an offset of the specified element. If no element is
// specified, the move is relative to the current mouse cursor. If an element is
// provided but no offset, the mouse will be moved to the center of the element.
// If the element is not visible, it will be scrolled into view.
// http://code.google.com/p/selenium/wiki/JsonWireProtocol#/session/:sessionId/moveto
class MoveToCommand : public AdvancedMouseCommand {
 public:
  MoveToCommand(const std::vector<std::string>& path_segments,
                const DictionaryValue* const parameters);
  virtual ~MoveToCommand();

  virtual bool Init(Response* const response);
  virtual void ExecutePost(Response* const response);

 private:
  bool has_element_;
  WebElementId element_;
  bool has_offset_;
  int x_offset_;
  int y_offset_;

  DISALLOW_COPY_AND_ASSIGN(MoveToCommand);
};

// Click any mouse button (at the coordinates set by the last moveto command).
// Note that calling this command after calling buttondown and before calling
// button up (or any out-of-order interactions sequence) will yield undefined
// behaviour).
// http://code.google.com/p/selenium/wiki/JsonWireProtocol#/session/:sessionId/click
class ClickCommand : public AdvancedMouseCommand {
 public:
  ClickCommand(const std::vector<std::string>& path_segments,
               const DictionaryValue* const parameters);
  virtual ~ClickCommand();

  virtual bool Init(Response* const response);
  virtual void ExecutePost(Response* const response);

 private:
  int button_;

  DISALLOW_COPY_AND_ASSIGN(ClickCommand);
};

// Click and hold the left mouse button (at the coordinates set by the last
// moveto command). Note that the next mouse-related command that should follow
// is buttondown . Any other mouse command (such as click or another call to
// buttondown) will yield undefined behaviour.
// http://code.google.com/p/selenium/wiki/JsonWireProtocol#/session/:sessionId/buttondown
class ButtonDownCommand : public AdvancedMouseCommand {
 public:
  ButtonDownCommand(const std::vector<std::string>& path_segments,
                    const DictionaryValue* const parameters);
  virtual ~ButtonDownCommand();

  virtual void ExecutePost(Response* const response);

 private:
  DISALLOW_COPY_AND_ASSIGN(ButtonDownCommand);
};

// Releases the mouse button previously held (where the mouse is currently at).
// Must be called once for every buttondown command issued. See the note in
// click and buttondown about implications of out-of-order commands.
// http://code.google.com/p/selenium/wiki/JsonWireProtocol#/session/:sessionId/buttonup
class ButtonUpCommand : public AdvancedMouseCommand {
 public:
  ButtonUpCommand(const std::vector<std::string>& path_segments,
                  const DictionaryValue* const parameters);
  virtual ~ButtonUpCommand();

  virtual void ExecutePost(Response* const response);

 private:
  DISALLOW_COPY_AND_ASSIGN(ButtonUpCommand);
};

// Double-clicks at the current mouse coordinates (set by moveto).
// http://code.google.com/p/selenium/wiki/JsonWireProtocol#/session/:sessionId/doubleclick
class DoubleClickCommand : public AdvancedMouseCommand {
 public:
  DoubleClickCommand(const std::vector<std::string>& ps,
                     const DictionaryValue* const parameters);
  virtual ~DoubleClickCommand();

  virtual void ExecutePost(Response* const response);

 private:
  DISALLOW_COPY_AND_ASSIGN(DoubleClickCommand);
};

}  // namespace webdriver

#endif  // CHROME_TEST_WEBDRIVER_COMMANDS_MOUSE_COMMANDS_H_