OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "chrome/test/chromedriver/commands.h" | 5 #include "chrome/test/chromedriver/commands.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/callback.h" | 8 #include "base/callback.h" |
| 9 #include "base/environment.h" |
9 #include "base/file_util.h" | 10 #include "base/file_util.h" |
10 #include "base/format_macros.h" | 11 #include "base/format_macros.h" |
11 #include "base/rand_util.h" | 12 #include "base/rand_util.h" |
| 13 #include "base/string_number_conversions.h" |
| 14 #include "base/string_split.h" |
12 #include "base/stringprintf.h" | 15 #include "base/stringprintf.h" |
13 #include "base/time.h" | 16 #include "base/time.h" |
14 #include "base/values.h" | 17 #include "base/values.h" |
15 #include "chrome/test/chromedriver/chrome.h" | 18 #include "chrome/test/chromedriver/chrome.h" |
16 #include "chrome/test/chromedriver/chrome_launcher.h" | 19 #include "chrome/test/chromedriver/chrome_launcher.h" |
17 #include "chrome/test/chromedriver/session.h" | 20 #include "chrome/test/chromedriver/session.h" |
18 #include "chrome/test/chromedriver/status.h" | 21 #include "chrome/test/chromedriver/status.h" |
| 22 #include "chrome/test/chromedriver/version.h" |
19 #include "third_party/webdriver/atoms.h" | 23 #include "third_party/webdriver/atoms.h" |
20 | 24 |
21 namespace { | 25 namespace { |
22 | 26 |
23 Status FindElementByJs( | 27 Status FindElementByJs( |
24 int interval_ms, | 28 int interval_ms, |
25 bool only_one, | 29 bool only_one, |
26 bool has_root_element, | 30 bool has_root_element, |
27 Session* session, | 31 Session* session, |
28 const base::DictionaryValue& params, | 32 const base::DictionaryValue& params, |
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
109 std::string message = base::StringPrintf( | 113 std::string message = base::StringPrintf( |
110 "no chrome binary at %" PRFilePath, | 114 "no chrome binary at %" PRFilePath, |
111 path_str.c_str()); | 115 path_str.c_str()); |
112 return Status(kUnknownError, message); | 116 return Status(kUnknownError, message); |
113 } | 117 } |
114 } | 118 } |
115 Status status = launcher->Launch(chrome_exe, &chrome); | 119 Status status = launcher->Launch(chrome_exe, &chrome); |
116 if (status.IsError()) | 120 if (status.IsError()) |
117 return Status(kSessionNotCreatedException, status.message()); | 121 return Status(kSessionNotCreatedException, status.message()); |
118 | 122 |
| 123 scoped_ptr<base::Environment> env(base::Environment::Create()); |
| 124 scoped_ptr<base::Value> chrome_version_value; |
| 125 std::string chrome_version; |
| 126 status = chrome->EvaluateScript( |
| 127 "", |
| 128 "navigator.appVersion.match(/Chrome\\/.* /)[0].split('/')[1].trim()", |
| 129 &chrome_version_value); |
| 130 if (status.IsError() || !chrome_version_value->GetAsString(&chrome_version)) |
| 131 return Status(kUnknownError, "unable to detect Chrome version"); |
| 132 // Check the version of Chrome is supported. |
| 133 // Allow the version check to be skipped for testing/development purposes. |
| 134 if (!env->HasVar("IGNORE_CHROME_VERSION")) { |
| 135 int build_no; |
| 136 std::vector<std::string> chrome_version_parts; |
| 137 base::SplitString(chrome_version, '.', &chrome_version_parts); |
| 138 if (chrome_version_parts.size() != 4 || |
| 139 !base::StringToInt(chrome_version_parts[2], &build_no)) { |
| 140 return Status(kUnknownError, "unrecognized Chrome version: " + |
| 141 chrome_version); |
| 142 } |
| 143 if (build_no < kMinimumSupportedChromeBuildNo) |
| 144 return Status(kUnknownError, "Chrome version must be >= " + |
| 145 GetMinimumSupportedChromeVersion()); |
| 146 } |
| 147 |
119 uint64 msb = base::RandUint64(); | 148 uint64 msb = base::RandUint64(); |
120 uint64 lsb = base::RandUint64(); | 149 uint64 lsb = base::RandUint64(); |
121 std::string new_id = | 150 std::string new_id = |
122 base::StringPrintf("%016" PRIx64 "%016" PRIx64, msb, lsb); | 151 base::StringPrintf("%016" PRIx64 "%016" PRIx64, msb, lsb); |
123 scoped_ptr<Session> session(new Session(new_id, chrome.Pass())); | 152 scoped_ptr<Session> session(new Session(new_id, chrome.Pass())); |
124 scoped_refptr<SessionAccessor> accessor( | 153 scoped_refptr<SessionAccessor> accessor( |
125 new SessionAccessorImpl(session.Pass())); | 154 new SessionAccessorImpl(session.Pass())); |
126 session_map->Set(new_id, accessor); | 155 session_map->Set(new_id, accessor); |
127 | 156 |
128 base::DictionaryValue* returned_value = new base::DictionaryValue(); | 157 base::DictionaryValue* returned_value = new base::DictionaryValue(); |
129 returned_value->SetString("browserName", "chrome"); | 158 returned_value->SetString("browserName", "chrome"); |
| 159 returned_value->SetString("version", chrome_version); |
| 160 returned_value->SetString("driverVersion", kChromeDriverVersion); |
130 out_value->reset(returned_value); | 161 out_value->reset(returned_value); |
131 *out_session_id = new_id; | 162 *out_session_id = new_id; |
132 return Status(kOk); | 163 return Status(kOk); |
133 } | 164 } |
134 | 165 |
135 Status ExecuteQuitAll( | 166 Status ExecuteQuitAll( |
136 Command quit_command, | 167 Command quit_command, |
137 SessionMap* session_map, | 168 SessionMap* session_map, |
138 const base::DictionaryValue& params, | 169 const base::DictionaryValue& params, |
139 const std::string& session_id, | 170 const std::string& session_id, |
(...skipping 179 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
319 return session->chrome->EvaluateScript( | 350 return session->chrome->EvaluateScript( |
320 "", "window.history.forward();", value); | 351 "", "window.history.forward();", value); |
321 } | 352 } |
322 | 353 |
323 Status ExecuteRefresh( | 354 Status ExecuteRefresh( |
324 Session* session, | 355 Session* session, |
325 const base::DictionaryValue& params, | 356 const base::DictionaryValue& params, |
326 scoped_ptr<base::Value>* value) { | 357 scoped_ptr<base::Value>* value) { |
327 return session->chrome->Reload(); | 358 return session->chrome->Reload(); |
328 } | 359 } |
OLD | NEW |