| 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/chrome_desktop_impl.h" | 5 #include "chrome/test/chromedriver/chrome/chrome_desktop_impl.h" |
| 6 | 6 |
| 7 #include "base/files/file_path.h" | 7 #include "base/files/file_path.h" |
| 8 #include "base/logging.h" | 8 #include "base/logging.h" |
| 9 #include "base/posix/eintr_wrapper.h" | 9 #include "base/posix/eintr_wrapper.h" |
| 10 #include "base/process/kill.h" | 10 #include "base/process/kill.h" |
| (...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 94 LOG(WARNING) << "chromedriver automation extension directory: " | 94 LOG(WARNING) << "chromedriver automation extension directory: " |
| 95 << extension_dir.value(); | 95 << extension_dir.value(); |
| 96 } | 96 } |
| 97 } | 97 } |
| 98 | 98 |
| 99 Status ChromeDesktopImpl::WaitForPageToLoad(const std::string& url, | 99 Status ChromeDesktopImpl::WaitForPageToLoad(const std::string& url, |
| 100 const base::TimeDelta& timeout, | 100 const base::TimeDelta& timeout, |
| 101 scoped_ptr<WebView>* web_view) { | 101 scoped_ptr<WebView>* web_view) { |
| 102 base::TimeTicks deadline = base::TimeTicks::Now() + timeout; | 102 base::TimeTicks deadline = base::TimeTicks::Now() + timeout; |
| 103 std::string id; | 103 std::string id; |
| 104 WebViewInfo::Type type = WebViewInfo::Type::kPage; |
| 104 while (base::TimeTicks::Now() < deadline) { | 105 while (base::TimeTicks::Now() < deadline) { |
| 105 WebViewsInfo views_info; | 106 WebViewsInfo views_info; |
| 106 Status status = devtools_http_client_->GetWebViewsInfo(&views_info); | 107 Status status = devtools_http_client_->GetWebViewsInfo(&views_info); |
| 107 if (status.IsError()) | 108 if (status.IsError()) |
| 108 return status; | 109 return status; |
| 109 | 110 |
| 110 for (size_t i = 0; i < views_info.GetSize(); ++i) { | 111 for (size_t i = 0; i < views_info.GetSize(); ++i) { |
| 111 if (views_info.Get(i).url.find(url) == 0) { | 112 const WebViewInfo& view_info = views_info.Get(i); |
| 112 id = views_info.Get(i).id; | 113 if (view_info.url.find(url) == 0) { |
| 114 id = view_info.id; |
| 115 type = view_info.type; |
| 113 break; | 116 break; |
| 114 } | 117 } |
| 115 } | 118 } |
| 116 if (!id.empty()) | 119 if (!id.empty()) |
| 117 break; | 120 break; |
| 118 base::PlatformThread::Sleep(base::TimeDelta::FromMilliseconds(100)); | 121 base::PlatformThread::Sleep(base::TimeDelta::FromMilliseconds(100)); |
| 119 } | 122 } |
| 120 if (id.empty()) | 123 if (id.empty()) |
| 121 return Status(kUnknownError, "page could not be found: " + url); | 124 return Status(kUnknownError, "page could not be found: " + url); |
| 122 | 125 |
| 126 const DeviceMetrics* device_metrics = devtools_http_client_->device_metrics(); |
| 127 if (type == WebViewInfo::Type::kApp || |
| 128 type == WebViewInfo::Type::kBackgroundPage) { |
| 129 // Apps and extensions don't work on Android, so it doesn't make sense to |
| 130 // provide override device metrics in mobile emulation mode, and can also |
| 131 // potentially crash the renderer, for more details see: |
| 132 // https://code.google.com/p/chromedriver/issues/detail?id=1205 |
| 133 device_metrics = nullptr; |
| 134 } |
| 123 scoped_ptr<WebView> web_view_tmp( | 135 scoped_ptr<WebView> web_view_tmp( |
| 124 new WebViewImpl(id, | 136 new WebViewImpl(id, |
| 125 devtools_http_client_->browser_info(), | 137 devtools_http_client_->browser_info(), |
| 126 devtools_http_client_->CreateClient(id), | 138 devtools_http_client_->CreateClient(id), |
| 127 devtools_http_client_->device_metrics())); | 139 device_metrics)); |
| 128 Status status = web_view_tmp->ConnectIfNecessary(); | 140 Status status = web_view_tmp->ConnectIfNecessary(); |
| 129 if (status.IsError()) | 141 if (status.IsError()) |
| 130 return status; | 142 return status; |
| 131 | 143 |
| 132 status = web_view_tmp->WaitForPendingNavigations( | 144 status = web_view_tmp->WaitForPendingNavigations( |
| 133 std::string(), deadline - base::TimeTicks::Now(), false); | 145 std::string(), deadline - base::TimeTicks::Now(), false); |
| 134 if (status.IsOk()) | 146 if (status.IsOk()) |
| 135 *web_view = web_view_tmp.Pass(); | 147 *web_view = web_view_tmp.Pass(); |
| 136 return status; | 148 return status; |
| 137 } | 149 } |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 178 // we're using a temporary user data directory, we're going to delete | 190 // we're using a temporary user data directory, we're going to delete |
| 179 // the temporary directory anyway, so just send SIGKILL immediately. | 191 // the temporary directory anyway, so just send SIGKILL immediately. |
| 180 if (!KillProcess(process_, !user_data_dir_.IsValid())) | 192 if (!KillProcess(process_, !user_data_dir_.IsValid())) |
| 181 return Status(kUnknownError, "cannot kill Chrome"); | 193 return Status(kUnknownError, "cannot kill Chrome"); |
| 182 return Status(kOk); | 194 return Status(kOk); |
| 183 } | 195 } |
| 184 | 196 |
| 185 const base::CommandLine& ChromeDesktopImpl::command() const { | 197 const base::CommandLine& ChromeDesktopImpl::command() const { |
| 186 return command_; | 198 return command_; |
| 187 } | 199 } |
| OLD | NEW |