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

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

Issue 288193004: [Chromedriver] Add Device Metrics override support to ChromeDriver via Capabilities (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 7 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
OLDNEW
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2013 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/chrome/devtools_http_client.h" 5 #include "chrome/test/chromedriver/chrome/devtools_http_client.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/bind_helpers.h" 8 #include "base/bind_helpers.h"
9 #include "base/json/json_reader.h" 9 #include "base/json/json_reader.h"
10 #include "base/strings/string_number_conversions.h" 10 #include "base/strings/string_number_conversions.h"
11 #include "base/strings/string_split.h" 11 #include "base/strings/string_split.h"
12 #include "base/strings/stringprintf.h" 12 #include "base/strings/stringprintf.h"
13 #include "base/threading/platform_thread.h" 13 #include "base/threading/platform_thread.h"
14 #include "base/time/time.h" 14 #include "base/time/time.h"
15 #include "base/values.h" 15 #include "base/values.h"
16 #include "chrome/test/chromedriver/chrome/device_metrics.h"
16 #include "chrome/test/chromedriver/chrome/devtools_client_impl.h" 17 #include "chrome/test/chromedriver/chrome/devtools_client_impl.h"
17 #include "chrome/test/chromedriver/chrome/log.h" 18 #include "chrome/test/chromedriver/chrome/log.h"
18 #include "chrome/test/chromedriver/chrome/status.h" 19 #include "chrome/test/chromedriver/chrome/status.h"
19 #include "chrome/test/chromedriver/chrome/version.h" 20 #include "chrome/test/chromedriver/chrome/version.h"
20 #include "chrome/test/chromedriver/chrome/web_view_impl.h" 21 #include "chrome/test/chromedriver/chrome/web_view_impl.h"
21 #include "chrome/test/chromedriver/net/net_util.h" 22 #include "chrome/test/chromedriver/net/net_util.h"
22 #include "chrome/test/chromedriver/net/url_request_context_getter.h" 23 #include "chrome/test/chromedriver/net/url_request_context_getter.h"
23 24
24 namespace { 25 namespace {
25 26
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
60 for (size_t i = 0; i < views_info.size(); ++i) { 61 for (size_t i = 0; i < views_info.size(); ++i) {
61 if (views_info[i].id == id) 62 if (views_info[i].id == id)
62 return &views_info[i]; 63 return &views_info[i];
63 } 64 }
64 return NULL; 65 return NULL;
65 } 66 }
66 67
67 DevToolsHttpClient::DevToolsHttpClient( 68 DevToolsHttpClient::DevToolsHttpClient(
68 const NetAddress& address, 69 const NetAddress& address,
69 scoped_refptr<URLRequestContextGetter> context_getter, 70 scoped_refptr<URLRequestContextGetter> context_getter,
70 const SyncWebSocketFactory& socket_factory) 71 const SyncWebSocketFactory& socket_factory,
72 scoped_ptr<DeviceMetrics> device_metrics)
71 : context_getter_(context_getter), 73 : context_getter_(context_getter),
72 socket_factory_(socket_factory), 74 socket_factory_(socket_factory),
73 server_url_("http://" + address.ToString()), 75 server_url_("http://" + address.ToString()),
74 web_socket_url_prefix_(base::StringPrintf( 76 web_socket_url_prefix_(base::StringPrintf(
75 "ws://%s/devtools/page/", address.ToString().c_str())) {} 77 "ws://%s/devtools/page/", address.ToString().c_str())),
78 device_metrics_(device_metrics.Pass()) {}
76 79
77 DevToolsHttpClient::~DevToolsHttpClient() {} 80 DevToolsHttpClient::~DevToolsHttpClient() {}
78 81
79 Status DevToolsHttpClient::Init(const base::TimeDelta& timeout) { 82 Status DevToolsHttpClient::Init(const base::TimeDelta& timeout) {
80 base::TimeTicks deadline = base::TimeTicks::Now() + timeout; 83 base::TimeTicks deadline = base::TimeTicks::Now() + timeout;
81 std::string browser_version; 84 std::string browser_version;
82 std::string blink_version; 85 std::string blink_version;
83 86
84 while (true) { 87 while (true) {
85 Status status = GetVersion(&browser_version, &blink_version); 88 Status status = GetVersion(&browser_version, &blink_version);
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after
189 if (!FetchUrlAndLog( 192 if (!FetchUrlAndLog(
190 server_url_ + "/json/activate/" + id, context_getter_.get(), &data)) 193 server_url_ + "/json/activate/" + id, context_getter_.get(), &data))
191 return Status(kUnknownError, "cannot activate web view"); 194 return Status(kUnknownError, "cannot activate web view");
192 return Status(kOk); 195 return Status(kOk);
193 } 196 }
194 197
195 const BrowserInfo* DevToolsHttpClient::browser_info() { 198 const BrowserInfo* DevToolsHttpClient::browser_info() {
196 return &browser_info_; 199 return &browser_info_;
197 } 200 }
198 201
202 const DeviceMetrics* DevToolsHttpClient::device_metrics() {
203 return device_metrics_.get();
204 }
205
199 Status DevToolsHttpClient::GetVersion(std::string* browser_version, 206 Status DevToolsHttpClient::GetVersion(std::string* browser_version,
200 std::string* blink_version) { 207 std::string* blink_version) {
201 std::string data; 208 std::string data;
202 if (!FetchUrlAndLog( 209 if (!FetchUrlAndLog(
203 server_url_ + "/json/version", context_getter_.get(), &data)) 210 server_url_ + "/json/version", context_getter_.get(), &data))
204 return Status(kChromeNotReachable); 211 return Status(kChromeNotReachable);
205 212
206 return internal::ParseVersionInfo(data, browser_version, blink_version); 213 return internal::ParseVersionInfo(data, browser_version, blink_version);
207 } 214 }
208 215
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
241 } 248 }
242 249
243 for (std::list<std::string>::const_iterator it = docked_frontend_ids.begin(); 250 for (std::list<std::string>::const_iterator it = docked_frontend_ids.begin();
244 it != docked_frontend_ids.end(); ++it) { 251 it != docked_frontend_ids.end(); ++it) {
245 scoped_ptr<DevToolsClient> client(new DevToolsClientImpl( 252 scoped_ptr<DevToolsClient> client(new DevToolsClientImpl(
246 socket_factory_, 253 socket_factory_,
247 web_socket_url_prefix_ + *it, 254 web_socket_url_prefix_ + *it,
248 *it, 255 *it,
249 base::Bind(&FakeCloseFrontends))); 256 base::Bind(&FakeCloseFrontends)));
250 scoped_ptr<WebViewImpl> web_view( 257 scoped_ptr<WebViewImpl> web_view(
251 new WebViewImpl(*it, &browser_info_, client.Pass())); 258 new WebViewImpl(*it, &browser_info_, client.Pass(), NULL));
252 259
253 status = web_view->ConnectIfNecessary(); 260 status = web_view->ConnectIfNecessary();
254 // Ignore disconnected error, because the debugger might have closed when 261 // Ignore disconnected error, because the debugger might have closed when
255 // its container page was closed above. 262 // its container page was closed above.
256 if (status.IsError() && status.code() != kDisconnected) 263 if (status.IsError() && status.code() != kDisconnected)
257 return status; 264 return status;
258 265
259 scoped_ptr<base::Value> result; 266 scoped_ptr<base::Value> result;
260 status = web_view->EvaluateScript( 267 status = web_view->EvaluateScript(
261 std::string(), 268 std::string(),
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after
361 Status(kUnknownError, "version info doesn't include string 'Browser'")); 368 Status(kUnknownError, "version info doesn't include string 'Browser'"));
362 } 369 }
363 if (!dict->GetString("WebKit-Version", blink_version)) { 370 if (!dict->GetString("WebKit-Version", blink_version)) {
364 return Status(kUnknownError, 371 return Status(kUnknownError,
365 "version info doesn't include string 'WebKit-Version'"); 372 "version info doesn't include string 'WebKit-Version'");
366 } 373 }
367 return Status(kOk); 374 return Status(kOk);
368 } 375 }
369 376
370 } // namespace internal 377 } // namespace internal
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698