| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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/webdriver/commands/webdriver_command.h" | 5 #include "chrome/test/webdriver/commands/webdriver_command.h" |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 | 8 |
| 9 #include "base/logging.h" | 9 #include "base/logging.h" |
| 10 #include "base/singleton.h" | 10 #include "base/singleton.h" |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 44 bool WebDriverCommand::Init(Response* const response) { | 44 bool WebDriverCommand::Init(Response* const response) { |
| 45 // There should be at least 3 path segments to match "/session/$id". | 45 // There should be at least 3 path segments to match "/session/$id". |
| 46 std::string session_id = GetPathVariable(2); | 46 std::string session_id = GetPathVariable(2); |
| 47 if (session_id.length() == 0) { | 47 if (session_id.length() == 0) { |
| 48 response->set_value(Value::CreateStringValue("No session ID specified")); | 48 response->set_value(Value::CreateStringValue("No session ID specified")); |
| 49 response->set_status(kBadRequest); | 49 response->set_status(kBadRequest); |
| 50 return false; | 50 return false; |
| 51 } | 51 } |
| 52 | 52 |
| 53 VLOG(1) << "Fetching session: " << session_id; | 53 VLOG(1) << "Fetching session: " << session_id; |
| 54 session_ = Singleton<SessionManager>::get()->GetSession(session_id); | 54 session_ = SessionManager::GetInstance()->GetSession(session_id); |
| 55 if (session_ == NULL) { | 55 if (session_ == NULL) { |
| 56 response->set_value(Value::CreateStringValue( | 56 response->set_value(Value::CreateStringValue( |
| 57 "Session not found: " + session_id)); | 57 "Session not found: " + session_id)); |
| 58 response->set_status(kSessionNotFound); | 58 response->set_status(kSessionNotFound); |
| 59 return false; | 59 return false; |
| 60 } | 60 } |
| 61 | 61 |
| 62 response->SetField("sessionId", Value::CreateStringValue(session_id)); | 62 response->SetField("sessionId", Value::CreateStringValue(session_id)); |
| 63 return !RequiresValidTab() || VerifyTabIsValid(response); | 63 return !RequiresValidTab() || VerifyTabIsValid(response); |
| 64 } | 64 } |
| 65 | 65 |
| 66 bool WebDriverCommand::VerifyTabIsValid(Response* response) { | 66 bool WebDriverCommand::VerifyTabIsValid(Response* response) { |
| 67 tab_ = session_->ActiveTab(); | 67 tab_ = session_->ActiveTab(); |
| 68 if (!tab_.get()) { | 68 if (!tab_.get()) { |
| 69 response->set_value(Value::CreateStringValue( | 69 response->set_value(Value::CreateStringValue( |
| 70 "Lost session window handle; did you close the window?")); | 70 "Lost session window handle; did you close the window?")); |
| 71 response->set_status(kNoSuchWindow); | 71 response->set_status(kNoSuchWindow); |
| 72 return false; | 72 return false; |
| 73 } | 73 } |
| 74 return true; | 74 return true; |
| 75 } | 75 } |
| 76 | 76 |
| 77 } // namespace webdriver | 77 } // namespace webdriver |
| 78 | 78 |
| OLD | NEW |