Chromium Code Reviews| 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/session_commands.h" | 5 #include "chrome/test/chromedriver/session_commands.h" |
| 6 | 6 |
| 7 #include <list> | 7 #include <list> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/callback.h" | 10 #include "base/callback.h" |
| 11 #include "base/files/file_util.h" | 11 #include "base/files/file_util.h" |
| 12 #include "base/logging.h" // For CHECK macros. | 12 #include "base/logging.h" // For CHECK macros. |
| 13 #include "base/memory/ref_counted.h" | 13 #include "base/memory/ref_counted.h" |
| 14 #include "base/message_loop/message_loop_proxy.h" | 14 #include "base/message_loop/message_loop_proxy.h" |
| 15 #include "base/strings/stringprintf.h" | |
| 15 #include "base/synchronization/lock.h" | 16 #include "base/synchronization/lock.h" |
| 16 #include "base/synchronization/waitable_event.h" | 17 #include "base/synchronization/waitable_event.h" |
| 17 #include "base/values.h" | 18 #include "base/values.h" |
| 18 #include "chrome/test/chromedriver/basic_types.h" | 19 #include "chrome/test/chromedriver/basic_types.h" |
| 19 #include "chrome/test/chromedriver/capabilities.h" | 20 #include "chrome/test/chromedriver/capabilities.h" |
| 20 #include "chrome/test/chromedriver/chrome/automation_extension.h" | 21 #include "chrome/test/chromedriver/chrome/automation_extension.h" |
| 21 #include "chrome/test/chromedriver/chrome/browser_info.h" | 22 #include "chrome/test/chromedriver/chrome/browser_info.h" |
| 22 #include "chrome/test/chromedriver/chrome/chrome.h" | 23 #include "chrome/test/chromedriver/chrome/chrome.h" |
| 23 #include "chrome/test/chromedriver/chrome/chrome_android_impl.h" | 24 #include "chrome/test/chromedriver/chrome/chrome_android_impl.h" |
| 24 #include "chrome/test/chromedriver/chrome/chrome_desktop_impl.h" | 25 #include "chrome/test/chromedriver/chrome/chrome_desktop_impl.h" |
| (...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 98 if (status.IsOk()) { | 99 if (status.IsOk()) { |
| 99 chrome_caps->SetString( | 100 chrome_caps->SetString( |
| 100 "userDataDir", | 101 "userDataDir", |
| 101 desktop->command().GetSwitchValueNative("user-data-dir")); | 102 desktop->command().GetSwitchValueNative("user-data-dir")); |
| 102 } | 103 } |
| 103 | 104 |
| 104 caps->Set("chrome", chrome_caps.release()); | 105 caps->Set("chrome", chrome_caps.release()); |
| 105 return caps.Pass(); | 106 return caps.Pass(); |
| 106 } | 107 } |
| 107 | 108 |
| 109 Status CheckSessionCreated(Session* session) { | |
| 110 WebView* web_view = NULL; | |
| 111 Status status = session->GetTargetWindow(&web_view); | |
| 112 if (status.IsError()) | |
| 113 return Status(kSessionNotCreatedException, status); | |
| 114 | |
| 115 status = web_view->ConnectIfNecessary(); | |
| 116 if (status.IsError()) | |
| 117 return Status(kSessionNotCreatedException, status); | |
| 118 | |
| 119 base::ListValue args; | |
| 120 args.AppendString("ping"); | |
| 121 scoped_ptr<base::Value> result(new base::StringValue(std::string())); | |
| 122 status = web_view->CallFunction(session->GetCurrentFrameId(), | |
| 123 "function(s){return s.replace('i','o')}", | |
|
stgao
2015/03/14 00:22:03
For the purpose of sanity check, maybe a simple "r
samuong
2015/03/14 17:17:46
Done.
| |
| 124 args, &result); | |
| 125 if (status.IsError()) | |
| 126 return Status(kSessionNotCreatedException, status); | |
| 127 | |
| 128 std::string response; | |
| 129 if (!result->GetAsString(&response) || response != "pong") { | |
| 130 return Status(kSessionNotCreatedException, | |
| 131 base::StringPrintf("unexpected response from browser")); | |
|
stgao
2015/03/14 00:22:03
It seems other places use raw strings directly, li
samuong
2015/03/14 17:17:46
Done. It's no longer needed, so I've removed it.
| |
| 132 } | |
| 133 | |
| 134 return Status(kOk); | |
| 135 } | |
| 136 | |
| 108 Status InitSessionHelper( | 137 Status InitSessionHelper( |
| 109 const InitSessionParams& bound_params, | 138 const InitSessionParams& bound_params, |
| 110 Session* session, | 139 Session* session, |
| 111 const base::DictionaryValue& params, | 140 const base::DictionaryValue& params, |
| 112 scoped_ptr<base::Value>* value) { | 141 scoped_ptr<base::Value>* value) { |
| 113 session->driver_log.reset( | 142 session->driver_log.reset( |
| 114 new WebDriverLog(WebDriverLog::kDriverType, Log::kAll)); | 143 new WebDriverLog(WebDriverLog::kDriverType, Log::kAll)); |
| 115 const base::DictionaryValue* desired_caps; | 144 const base::DictionaryValue* desired_caps; |
| 116 if (!params.GetDictionary("desiredCapabilities", &desired_caps)) | 145 if (!params.GetDictionary("desiredCapabilities", &desired_caps)) |
| 117 return Status(kUnknownError, "cannot find dict 'desiredCapabilities'"); | 146 return Status(kUnknownError, "cannot find dict 'desiredCapabilities'"); |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 158 if (status.IsError() || web_view_ids.empty()) { | 187 if (status.IsError() || web_view_ids.empty()) { |
| 159 return status.IsError() ? status : | 188 return status.IsError() ? status : |
| 160 Status(kUnknownError, "unable to discover open window in chrome"); | 189 Status(kUnknownError, "unable to discover open window in chrome"); |
| 161 } | 190 } |
| 162 | 191 |
| 163 session->window = web_view_ids.front(); | 192 session->window = web_view_ids.front(); |
| 164 session->detach = capabilities.detach; | 193 session->detach = capabilities.detach; |
| 165 session->force_devtools_screenshot = capabilities.force_devtools_screenshot; | 194 session->force_devtools_screenshot = capabilities.force_devtools_screenshot; |
| 166 session->capabilities = CreateCapabilities(session->chrome.get()); | 195 session->capabilities = CreateCapabilities(session->chrome.get()); |
| 167 value->reset(session->capabilities->DeepCopy()); | 196 value->reset(session->capabilities->DeepCopy()); |
| 168 return Status(kOk); | 197 return CheckSessionCreated(session); |
| 169 } | 198 } |
| 170 | 199 |
| 171 } // namespace | 200 } // namespace |
| 172 | 201 |
| 173 Status ExecuteInitSession( | 202 Status ExecuteInitSession( |
| 174 const InitSessionParams& bound_params, | 203 const InitSessionParams& bound_params, |
| 175 Session* session, | 204 Session* session, |
| 176 const base::DictionaryValue& params, | 205 const base::DictionaryValue& params, |
| 177 scoped_ptr<base::Value>* value) { | 206 scoped_ptr<base::Value>* value) { |
| 178 Status status = InitSessionHelper(bound_params, session, params, value); | 207 Status status = InitSessionHelper(bound_params, session, params, value); |
| (...skipping 506 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 685 Status ExecuteSetAutoReporting( | 714 Status ExecuteSetAutoReporting( |
| 686 Session* session, | 715 Session* session, |
| 687 const base::DictionaryValue& params, | 716 const base::DictionaryValue& params, |
| 688 scoped_ptr<base::Value>* value) { | 717 scoped_ptr<base::Value>* value) { |
| 689 bool enabled; | 718 bool enabled; |
| 690 if (!params.GetBoolean("enabled", &enabled)) | 719 if (!params.GetBoolean("enabled", &enabled)) |
| 691 return Status(kUnknownError, "missing parameter 'enabled'"); | 720 return Status(kUnknownError, "missing parameter 'enabled'"); |
| 692 session->auto_reporting_enabled = enabled; | 721 session->auto_reporting_enabled = enabled; |
| 693 return Status(kOk); | 722 return Status(kOk); |
| 694 } | 723 } |
| OLD | NEW |