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

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

Issue 2785083002: Use devtools to set user agent in chromedriver (Closed)
Patch Set: Fix New Tab test Created 3 years, 8 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 <utility> 7 #include <utility>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/bind_helpers.h" 10 #include "base/bind_helpers.h"
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
64 } 64 }
65 return NULL; 65 return NULL;
66 } 66 }
67 67
68 DevToolsHttpClient::DevToolsHttpClient( 68 DevToolsHttpClient::DevToolsHttpClient(
69 const NetAddress& address, 69 const NetAddress& address,
70 scoped_refptr<URLRequestContextGetter> context_getter, 70 scoped_refptr<URLRequestContextGetter> context_getter,
71 const SyncWebSocketFactory& socket_factory, 71 const SyncWebSocketFactory& socket_factory,
72 std::unique_ptr<DeviceMetrics> device_metrics, 72 std::unique_ptr<DeviceMetrics> device_metrics,
73 std::unique_ptr<std::set<WebViewInfo::Type>> window_types, 73 std::unique_ptr<std::set<WebViewInfo::Type>> window_types,
74 std::string page_load_strategy) 74 std::string page_load_strategy,
75 std::string user_agent)
75 : context_getter_(context_getter), 76 : context_getter_(context_getter),
76 socket_factory_(socket_factory), 77 socket_factory_(socket_factory),
77 server_url_("http://" + address.ToString()), 78 server_url_("http://" + address.ToString()),
78 web_socket_url_prefix_(base::StringPrintf("ws://%s/devtools/page/", 79 web_socket_url_prefix_(base::StringPrintf("ws://%s/devtools/page/",
79 address.ToString().c_str())), 80 address.ToString().c_str())),
80 device_metrics_(std::move(device_metrics)), 81 device_metrics_(std::move(device_metrics)),
81 window_types_(std::move(window_types)), 82 window_types_(std::move(window_types)),
82 page_load_strategy_(page_load_strategy) { 83 page_load_strategy_(page_load_strategy),
84 user_agent_(user_agent) {
83 window_types_->insert(WebViewInfo::kPage); 85 window_types_->insert(WebViewInfo::kPage);
84 window_types_->insert(WebViewInfo::kApp); 86 window_types_->insert(WebViewInfo::kApp);
85 } 87 }
86 88
87 DevToolsHttpClient::~DevToolsHttpClient() {} 89 DevToolsHttpClient::~DevToolsHttpClient() {}
88 90
89 Status DevToolsHttpClient::Init(const base::TimeDelta& timeout) { 91 Status DevToolsHttpClient::Init(const base::TimeDelta& timeout) {
90 base::TimeTicks deadline = base::TimeTicks::Now() + timeout; 92 base::TimeTicks deadline = base::TimeTicks::Now() + timeout;
91 std::string version_url = server_url_ + "/json/version"; 93 std::string version_url = server_url_ + "/json/version";
92 std::string data; 94 std::string data;
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
150 } 152 }
151 153
152 const BrowserInfo* DevToolsHttpClient::browser_info() { 154 const BrowserInfo* DevToolsHttpClient::browser_info() {
153 return &browser_info_; 155 return &browser_info_;
154 } 156 }
155 157
156 const DeviceMetrics* DevToolsHttpClient::device_metrics() { 158 const DeviceMetrics* DevToolsHttpClient::device_metrics() {
157 return device_metrics_.get(); 159 return device_metrics_.get();
158 } 160 }
159 161
162 const std::string& DevToolsHttpClient::user_agent() const {
163 return user_agent_;
164 }
165
160 bool DevToolsHttpClient::IsBrowserWindow(const WebViewInfo& view) const { 166 bool DevToolsHttpClient::IsBrowserWindow(const WebViewInfo& view) const {
161 return base::ContainsKey(*window_types_, view.type) || 167 return base::ContainsKey(*window_types_, view.type) ||
162 (view.type == WebViewInfo::kOther && 168 (view.type == WebViewInfo::kOther &&
163 (view.url == "chrome://print/" || 169 (view.url == "chrome://print/" ||
164 view.url == "chrome://media-router/")); 170 view.url == "chrome://media-router/"));
165 } 171 }
166 172
167 Status DevToolsHttpClient::CloseFrontends(const std::string& for_client_id) { 173 Status DevToolsHttpClient::CloseFrontends(const std::string& for_client_id) {
168 WebViewsInfo views_info; 174 WebViewsInfo views_info;
169 Status status = GetWebViewsInfo(&views_info); 175 Status status = GetWebViewsInfo(&views_info);
(...skipping 27 matching lines...) Expand all
197 if (status.IsError()) 203 if (status.IsError())
198 return status; 204 return status;
199 } 205 }
200 206
201 for (std::list<std::string>::const_iterator it = docked_frontend_ids.begin(); 207 for (std::list<std::string>::const_iterator it = docked_frontend_ids.begin();
202 it != docked_frontend_ids.end(); ++it) { 208 it != docked_frontend_ids.end(); ++it) {
203 std::unique_ptr<DevToolsClient> client(new DevToolsClientImpl( 209 std::unique_ptr<DevToolsClient> client(new DevToolsClientImpl(
204 socket_factory_, web_socket_url_prefix_ + *it, *it)); 210 socket_factory_, web_socket_url_prefix_ + *it, *it));
205 std::unique_ptr<WebViewImpl> web_view( 211 std::unique_ptr<WebViewImpl> web_view(
206 new WebViewImpl(*it, false, &browser_info_, std::move(client), NULL, 212 new WebViewImpl(*it, false, &browser_info_, std::move(client), NULL,
207 page_load_strategy_)); 213 page_load_strategy_, user_agent_));
208 214
209 status = web_view->ConnectIfNecessary(); 215 status = web_view->ConnectIfNecessary();
210 // Ignore disconnected error, because the debugger might have closed when 216 // Ignore disconnected error, because the debugger might have closed when
211 // its container page was closed above. 217 // its container page was closed above.
212 if (status.IsError() && status.code() != kDisconnected) 218 if (status.IsError() && status.code() != kDisconnected)
213 return status; 219 return status;
214 220
215 std::unique_ptr<base::Value> result; 221 std::unique_ptr<base::Value> result;
216 status = CloseWebView(*it); 222 status = CloseWebView(*it);
217 // Ignore disconnected error, because it may be closed already. 223 // Ignore disconnected error, because it may be closed already.
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after
310 Status status = ParseType(type_as_string, &type); 316 Status status = ParseType(type_as_string, &type);
311 if (status.IsError()) 317 if (status.IsError())
312 return status; 318 return status;
313 temp_views_info.push_back(WebViewInfo(id, debugger_url, url, type)); 319 temp_views_info.push_back(WebViewInfo(id, debugger_url, url, type));
314 } 320 }
315 *views_info = WebViewsInfo(temp_views_info); 321 *views_info = WebViewsInfo(temp_views_info);
316 return Status(kOk); 322 return Status(kOk);
317 } 323 }
318 324
319 } // namespace internal 325 } // namespace internal
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698