Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(43)

Side by Side Diff: chrome/test/chromedriver/commands.cc

Issue 12052004: [chromedriver] Create release script and handle Chrome/ChromeDriver versions. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: . Created 7 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 bool only_one, 28 bool only_one,
25 Session* session, 29 Session* session,
26 const base::DictionaryValue& params, 30 const base::DictionaryValue& params,
27 scoped_ptr<base::Value>* value) { 31 scoped_ptr<base::Value>* value) {
28 std::string strategy; 32 std::string strategy;
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
110 std::string message = base::StringPrintf( 114 std::string message = base::StringPrintf(
111 "no chrome binary at %" PRFilePath, 115 "no chrome binary at %" PRFilePath,
112 path_str.c_str()); 116 path_str.c_str());
113 return Status(kUnknownError, message); 117 return Status(kUnknownError, message);
114 } 118 }
115 } 119 }
116 Status status = launcher->Launch(chrome_exe, &chrome); 120 Status status = launcher->Launch(chrome_exe, &chrome);
117 if (status.IsError()) 121 if (status.IsError())
118 return Status(kSessionNotCreatedException, status.message()); 122 return Status(kSessionNotCreatedException, status.message());
119 123
124 scoped_ptr<base::Environment> env(base::Environment::Create());
125 scoped_ptr<base::Value> chrome_version_value;
126 std::string chrome_version;
127 status = chrome->EvaluateScript(
128 "",
129 "navigator.appVersion.match(/Chrome\\/.* /)[0].split('/')[1].trim()",
130 &chrome_version_value);
131 if (status.IsError() || !chrome_version_value->GetAsString(&chrome_version))
132 return Status(kUnknownError, "unable to detect Chrome version");
133 // Check the version of Chrome is supported.
134 // Allow the version check to be skipped for testing/development purposes.
135 if (!env->HasVar("IGNORE_CHROME_VERSION")) {
136 int build_no;
137 std::vector<std::string> chrome_version_parts;
138 base::SplitString(chrome_version, '.', &chrome_version_parts);
139 if (chrome_version_parts.size() != 4 ||
140 !base::StringToInt(chrome_version_parts[2], &build_no)) {
141 return Status(kUnknownError, "unrecognized Chrome version: " +
142 chrome_version);
143 }
144 if (build_no < kMinimumSupportedChromeBuildNo)
145 return Status(kUnknownError, "Chrome version must be >= " +
146 GetMinimumSupportedChromeVersion());
147 }
148
120 uint64 msb = base::RandUint64(); 149 uint64 msb = base::RandUint64();
121 uint64 lsb = base::RandUint64(); 150 uint64 lsb = base::RandUint64();
122 std::string new_id = 151 std::string new_id =
123 base::StringPrintf("%016" PRIx64 "%016" PRIx64, msb, lsb); 152 base::StringPrintf("%016" PRIx64 "%016" PRIx64, msb, lsb);
124 scoped_ptr<Session> session(new Session(new_id, chrome.Pass())); 153 scoped_ptr<Session> session(new Session(new_id, chrome.Pass()));
125 scoped_refptr<SessionAccessor> accessor( 154 scoped_refptr<SessionAccessor> accessor(
126 new SessionAccessorImpl(session.Pass())); 155 new SessionAccessorImpl(session.Pass()));
127 session_map->Set(new_id, accessor); 156 session_map->Set(new_id, accessor);
128 157
129 base::DictionaryValue* returned_value = new base::DictionaryValue(); 158 base::DictionaryValue* returned_value = new base::DictionaryValue();
130 returned_value->SetString("browserName", "chrome"); 159 returned_value->SetString("browserName", "chrome");
160 returned_value->SetString("version", chrome_version);
161 returned_value->SetString("driverVersion", kChromeDriverVersion);
131 out_value->reset(returned_value); 162 out_value->reset(returned_value);
132 *out_session_id = new_id; 163 *out_session_id = new_id;
133 return Status(kOk); 164 return Status(kOk);
134 } 165 }
135 166
136 Status ExecuteQuitAll( 167 Status ExecuteQuitAll(
137 Command quit_command, 168 Command quit_command,
138 SessionMap* session_map, 169 SessionMap* session_map,
139 const base::DictionaryValue& params, 170 const base::DictionaryValue& params,
140 const std::string& session_id, 171 const std::string& session_id,
(...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after
302 return session->chrome->EvaluateScript( 333 return session->chrome->EvaluateScript(
303 "", "window.history.forward();", value); 334 "", "window.history.forward();", value);
304 } 335 }
305 336
306 Status ExecuteRefresh( 337 Status ExecuteRefresh(
307 Session* session, 338 Session* session,
308 const base::DictionaryValue& params, 339 const base::DictionaryValue& params,
309 scoped_ptr<base::Value>* value) { 340 scoped_ptr<base::Value>* value) {
310 return session->chrome->Reload(); 341 return session->chrome->Reload();
311 } 342 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698