diff options
author | jmikhail@google.com <jmikhail@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-11-25 03:29:22 +0000 |
---|---|---|
committer | jmikhail@google.com <jmikhail@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-11-25 03:29:22 +0000 |
commit | 55ab5016295a0404f8a62d61145b5cd3eee4050a (patch) | |
tree | 31e6146e8533495e3d9326c1ea62e417bad46628 /chrome/test | |
parent | 6bcd58a7acff30eb360422c9d10324f708d8ba32 (diff) | |
download | chromium_src-55ab5016295a0404f8a62d61145b5cd3eee4050a.zip chromium_src-55ab5016295a0404f8a62d61145b5cd3eee4050a.tar.gz chromium_src-55ab5016295a0404f8a62d61145b5cd3eee4050a.tar.bz2 |
Get the current user input speed. The server should return one of
{SLOW|MEDIUM|FAST}. How these constants map to actual input speed is still
browser specific and not covered by the wire protocol. This change implements
the following url:
/session/:sessionId/speed
BUG=none
TEST=none
Review URL: http://codereview.chromium.org/3647001
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@67380 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/test')
-rw-r--r-- | chrome/test/webdriver/commands/speed_command.cc | 86 | ||||
-rw-r--r-- | chrome/test/webdriver/commands/speed_command.h | 44 | ||||
-rw-r--r-- | chrome/test/webdriver/server.cc | 2 | ||||
-rw-r--r-- | chrome/test/webdriver/session.h | 7 |
4 files changed, 139 insertions, 0 deletions
diff --git a/chrome/test/webdriver/commands/speed_command.cc b/chrome/test/webdriver/commands/speed_command.cc new file mode 100644 index 0000000..e09602d --- /dev/null +++ b/chrome/test/webdriver/commands/speed_command.cc @@ -0,0 +1,86 @@ +// Copyright (c) 2010 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. + +#include <string> + +#include "base/utf_string_conversions.h" +#include "chrome/test/webdriver/commands/speed_command.h" + +namespace webdriver { + +bool SpeedCommand::Init(Response* const response) { + std::string speed; + + if (!WebDriverCommand::Init(response)) { + SET_WEBDRIVER_ERROR(response, "Failure on Init for setting speed", + kInternalServerError); + return false; + } + + // The speed parameter must be passed in as SLOW, MEDIUM, or FAST. + // The command must also be in all upper case letters. + if (!GetStringASCIIParameter("speed", &speed)) { + SET_WEBDRIVER_ERROR(response, "Request missing speed parameter", + kBadRequest); + return false; + } + + if (speed.compare("SLOW") == 0) { + LOG(INFO) << "Speed set to slow"; + speed_ = Session::kSlow; + } else if (speed.compare("MEDIUM") == 0) { + LOG(INFO) << "Speed set to medium"; + speed_ = Session::kMedium; + } else if (speed.compare("FAST") == 0) { + LOG(INFO) << "Speed set to fast" << std::endl; + speed_ = Session::kFast; + } else { + // If the speed is invalid throw and error in the POST response. + LOG(INFO) << "Requested an unknown speed: " << speed; + speed_ = Session::kUnknown; + } + + return true; +} + +void SpeedCommand::ExecuteGet(Response* const response) { + switch (session_->speed()) { + case Session::kSlow: + response->set_value(new StringValue("SLOW")); + response->set_status(kSuccess); + break; + + case Session::kMedium: + response->set_value(new StringValue("MEDIUM")); + response->set_status(kSuccess); + break; + + case Session::kFast: + response->set_value(new StringValue("FAST")); + response->set_status(kSuccess); + break; + + default: + // The speed should have never been set to unknown. + SET_WEBDRIVER_ERROR(response, "Unknown speed set", + kInternalServerError); + NOTREACHED(); + break; + } +} + +void SpeedCommand::ExecutePost(Response* const response) { + if (speed_ == Session::kUnknown) { + SET_WEBDRIVER_ERROR(response, "Invalid speed requested", + kInternalServerError); + return; + } + + session_->set_speed(speed_); + response->set_value(new StringValue("success")); + response->set_status(kSuccess); +} + +} // namespace webdriver + diff --git a/chrome/test/webdriver/commands/speed_command.h b/chrome/test/webdriver/commands/speed_command.h new file mode 100644 index 0000000..7c8c7eb --- /dev/null +++ b/chrome/test/webdriver/commands/speed_command.h @@ -0,0 +1,44 @@ +// Copyright (c) 2010 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_SPEED_COMMAND_H_ +#define CHROME_TEST_WEBDRIVER_COMMANDS_SPEED_COMMAND_H_ + +#include <string> +#include <vector> + +#include "chrome/test/webdriver/session.h" +#include "chrome/test/webdriver/commands/webdriver_command.h" + +namespace webdriver { + +// Controls how fast chrome should simulate user typing and mouse movements. +// By default the speed is set to medium however webdriver has not defined +// what this speed means accross browsers. Currently speed is ignored. +// See: http://code.google.com/p/selenium/wiki/JsonWireProtocol#/session/:sessionId/speed +class SpeedCommand : public WebDriverCommand { + public: + SpeedCommand(const std::vector<std::string>& path_segments, + const DictionaryValue* const parameters) + : WebDriverCommand(path_segments, parameters), speed_(Session::kMedium) {} + virtual ~SpeedCommand() {} + + virtual bool Init(Response* const response); + + virtual bool DoesGet() { return true; } + virtual bool DoesPost() { return true; } + virtual void ExecuteGet(Response* const response); + virtual void ExecutePost(Response* const response); + + private: + Session::Speed speed_; + virtual bool RequiresValidTab() { return true; } + + DISALLOW_COPY_AND_ASSIGN(SpeedCommand); +}; + +} // namespace webdriver + +#endif // CHROME_TEST_WEBDRIVER_COMMANDS_SPEED_COMMAND_H_ + diff --git a/chrome/test/webdriver/server.cc b/chrome/test/webdriver/server.cc index f80659b..ad496b1 100644 --- a/chrome/test/webdriver/server.cc +++ b/chrome/test/webdriver/server.cc @@ -29,6 +29,7 @@ #include "chrome/test/webdriver/commands/navigate_commands.h" #include "chrome/test/webdriver/commands/session_with_id.h" #include "chrome/test/webdriver/commands/source_command.h" +#include "chrome/test/webdriver/commands/speed_command.h" #include "chrome/test/webdriver/commands/title_command.h" #include "chrome/test/webdriver/commands/url_command.h" @@ -65,6 +66,7 @@ void InitCallbacks(struct mg_context* ctx) { SetCallback<SourceCommand>(ctx, "/session/*/source"); SetCallback<TitleCommand>(ctx, "/session/*/title"); SetCallback<URLCommand>(ctx, "/session/*/url"); + SetCallback<SpeedCommand>(ctx, "/session/*/speed"); // Since the /session/* is a wild card that would match the above URIs, this // line MUST be the last registered URI with the server. diff --git a/chrome/test/webdriver/session.h b/chrome/test/webdriver/session.h index ad62833..253a065 100644 --- a/chrome/test/webdriver/session.h +++ b/chrome/test/webdriver/session.h @@ -62,6 +62,12 @@ class Session : private UITestBase { implicit_wait_ = timeout > 0 ? timeout : 0; } + typedef enum Speed { kSlow, kMedium, kFast, kUnknown }; + inline Speed speed() { return speed_; } + inline void set_speed(Speed speed) { + speed_ = speed; + } + inline const char* tmp_profile_dir() { return tmp_profile_dir_; }; @@ -86,6 +92,7 @@ class Session : private UITestBase { scoped_refptr<TabProxy> tab_; int implicit_wait_; + Speed speed_; ProfileDir tmp_profile_dir_; // The XPath to the frame within this session's active tab which all |