OLD | NEW |
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/stringprintf.h" | 10 #include "base/stringprintf.h" |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
71 socket_factory_(socket_factory), | 71 socket_factory_(socket_factory), |
72 log_(log), | 72 log_(log), |
73 server_url_(base::StringPrintf("http://127.0.0.1:%d", port)), | 73 server_url_(base::StringPrintf("http://127.0.0.1:%d", port)), |
74 web_socket_url_prefix_( | 74 web_socket_url_prefix_( |
75 base::StringPrintf("ws://127.0.0.1:%d/devtools/page/", port)) {} | 75 base::StringPrintf("ws://127.0.0.1:%d/devtools/page/", port)) {} |
76 | 76 |
77 DevToolsHttpClient::~DevToolsHttpClient() {} | 77 DevToolsHttpClient::~DevToolsHttpClient() {} |
78 | 78 |
79 Status DevToolsHttpClient::GetVersion(std::string* version) { | 79 Status DevToolsHttpClient::GetVersion(std::string* version) { |
80 std::string data; | 80 std::string data; |
81 if (!FetchUrlAndLog(server_url_ + "/json/version", context_getter_, &data)) | 81 if (!FetchUrlAndLog( |
| 82 server_url_ + "/json/version", context_getter_.get(), &data)) |
82 return Status(kChromeNotReachable); | 83 return Status(kChromeNotReachable); |
83 | 84 |
84 return internal::ParseVersionInfo(data, version); | 85 return internal::ParseVersionInfo(data, version); |
85 } | 86 } |
86 | 87 |
87 Status DevToolsHttpClient::GetWebViewsInfo(WebViewsInfo* views_info) { | 88 Status DevToolsHttpClient::GetWebViewsInfo(WebViewsInfo* views_info) { |
88 std::string data; | 89 std::string data; |
89 if (!FetchUrlAndLog(server_url_ + "/json", context_getter_, &data)) | 90 if (!FetchUrlAndLog(server_url_ + "/json", context_getter_.get(), &data)) |
90 return Status(kChromeNotReachable); | 91 return Status(kChromeNotReachable); |
91 | 92 |
92 return internal::ParseWebViewsInfo(data, views_info); | 93 return internal::ParseWebViewsInfo(data, views_info); |
93 } | 94 } |
94 | 95 |
95 scoped_ptr<DevToolsClient> DevToolsHttpClient::CreateClient( | 96 scoped_ptr<DevToolsClient> DevToolsHttpClient::CreateClient( |
96 const std::string& id) { | 97 const std::string& id) { |
97 return scoped_ptr<DevToolsClient>(new DevToolsClientImpl( | 98 return scoped_ptr<DevToolsClient>(new DevToolsClientImpl( |
98 socket_factory_, | 99 socket_factory_, |
99 web_socket_url_prefix_ + id, | 100 web_socket_url_prefix_ + id, |
100 id, | 101 id, |
101 base::Bind( | 102 base::Bind( |
102 &DevToolsHttpClient::CloseFrontends, base::Unretained(this), id), | 103 &DevToolsHttpClient::CloseFrontends, base::Unretained(this), id), |
103 log_)); | 104 log_)); |
104 } | 105 } |
105 | 106 |
106 Status DevToolsHttpClient::CloseWebView(const std::string& id) { | 107 Status DevToolsHttpClient::CloseWebView(const std::string& id) { |
107 std::string data; | 108 std::string data; |
108 if (!FetchUrlAndLog( | 109 if (!FetchUrlAndLog( |
109 server_url_ + "/json/close/" + id, context_getter_, &data)) { | 110 server_url_ + "/json/close/" + id, context_getter_.get(), &data)) { |
110 return Status(kOk); // Closing the last web view leads chrome to quit. | 111 return Status(kOk); // Closing the last web view leads chrome to quit. |
111 } | 112 } |
112 | 113 |
113 // Wait for the target window to be completely closed. | 114 // Wait for the target window to be completely closed. |
114 base::Time deadline = base::Time::Now() + base::TimeDelta::FromSeconds(20); | 115 base::Time deadline = base::Time::Now() + base::TimeDelta::FromSeconds(20); |
115 while (base::Time::Now() < deadline) { | 116 while (base::Time::Now() < deadline) { |
116 WebViewsInfo views_info; | 117 WebViewsInfo views_info; |
117 Status status = GetWebViewsInfo(&views_info); | 118 Status status = GetWebViewsInfo(&views_info); |
118 if (status.code() == kChromeNotReachable) | 119 if (status.code() == kChromeNotReachable) |
119 return Status(kOk); | 120 return Status(kOk); |
(...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
269 if (!dict->GetString("Browser", version)) { | 270 if (!dict->GetString("Browser", version)) { |
270 return Status( | 271 return Status( |
271 kUnknownError, | 272 kUnknownError, |
272 "Chrome version must be >= " + GetMinimumSupportedChromeVersion(), | 273 "Chrome version must be >= " + GetMinimumSupportedChromeVersion(), |
273 Status(kUnknownError, "version info doesn't include string 'Browser'")); | 274 Status(kUnknownError, "version info doesn't include string 'Browser'")); |
274 } | 275 } |
275 return Status(kOk); | 276 return Status(kOk); |
276 } | 277 } |
277 | 278 |
278 } // namespace internal | 279 } // namespace internal |
OLD | NEW |