Index: chrome/test/chromedriver/commands.cc |
diff --git a/chrome/test/chromedriver/commands.cc b/chrome/test/chromedriver/commands.cc |
index 23aeb3b8578501be724f124b9b82d15c230cb7a2..3565cbafb2819d5b3c1502990355a46c156bd563 100644 |
--- a/chrome/test/chromedriver/commands.cc |
+++ b/chrome/test/chromedriver/commands.cc |
@@ -6,9 +6,12 @@ |
#include "base/bind.h" |
#include "base/callback.h" |
+#include "base/environment.h" |
#include "base/file_util.h" |
#include "base/format_macros.h" |
#include "base/rand_util.h" |
+#include "base/string_number_conversions.h" |
+#include "base/string_split.h" |
#include "base/stringprintf.h" |
#include "base/time.h" |
#include "base/values.h" |
@@ -16,6 +19,7 @@ |
#include "chrome/test/chromedriver/chrome_launcher.h" |
#include "chrome/test/chromedriver/session.h" |
#include "chrome/test/chromedriver/status.h" |
+#include "chrome/test/chromedriver/version.h" |
#include "third_party/webdriver/atoms.h" |
namespace { |
@@ -117,6 +121,31 @@ Status ExecuteNewSession( |
if (status.IsError()) |
return Status(kSessionNotCreatedException, status.message()); |
+ scoped_ptr<base::Environment> env(base::Environment::Create()); |
+ scoped_ptr<base::Value> chrome_version_value; |
+ std::string chrome_version; |
+ status = chrome->EvaluateScript( |
+ "", |
+ "navigator.appVersion.match(/Chrome\\/.* /)[0].split('/')[1].trim()", |
+ &chrome_version_value); |
+ if (status.IsError() || !chrome_version_value->GetAsString(&chrome_version)) |
+ return Status(kUnknownError, "unable to detect Chrome version"); |
+ // Check the version of Chrome is supported. |
+ // Allow the version check to be skipped for testing/development purposes. |
+ if (!env->HasVar("IGNORE_CHROME_VERSION")) { |
+ int build_no; |
+ std::vector<std::string> chrome_version_parts; |
+ base::SplitString(chrome_version, '.', &chrome_version_parts); |
+ if (chrome_version_parts.size() != 4 || |
+ !base::StringToInt(chrome_version_parts[2], &build_no)) { |
+ return Status(kUnknownError, "unrecognized Chrome version: " + |
+ chrome_version); |
+ } |
+ if (build_no < kMinimumSupportedChromeBuildNo) |
+ return Status(kUnknownError, "Chrome version must be >= " + |
+ GetMinimumSupportedChromeVersion()); |
+ } |
+ |
uint64 msb = base::RandUint64(); |
uint64 lsb = base::RandUint64(); |
std::string new_id = |
@@ -128,6 +157,8 @@ Status ExecuteNewSession( |
base::DictionaryValue* returned_value = new base::DictionaryValue(); |
returned_value->SetString("browserName", "chrome"); |
+ returned_value->SetString("version", chrome_version); |
+ returned_value->SetString("driverVersion", kChromeDriverVersion); |
out_value->reset(returned_value); |
*out_session_id = new_id; |
return Status(kOk); |