OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/memory/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.h" |
(...skipping 16 matching lines...) Expand all Loading... |
27 | 27 |
28 bool WebDriverCommand::Init(Response* const response) { | 28 bool WebDriverCommand::Init(Response* const response) { |
29 // There should be at least 3 path segments to match "/session/$id". | 29 // There should be at least 3 path segments to match "/session/$id". |
30 std::string session_id = GetPathVariable(2); | 30 std::string session_id = GetPathVariable(2); |
31 if (session_id.length() == 0) { | 31 if (session_id.length() == 0) { |
32 response->SetError( | 32 response->SetError( |
33 new Error(kBadRequest, "No session ID specified")); | 33 new Error(kBadRequest, "No session ID specified")); |
34 return false; | 34 return false; |
35 } | 35 } |
36 | 36 |
| 37 VLOG(1) << "Fetching session: " << session_id; |
37 session_ = SessionManager::GetInstance()->GetSession(session_id); | 38 session_ = SessionManager::GetInstance()->GetSession(session_id); |
38 if (session_ == NULL) { | 39 if (session_ == NULL) { |
39 response->SetError( | 40 response->SetError( |
40 new Error(kSessionNotFound, "Session not found: " + session_id)); | 41 new Error(kSessionNotFound, "Session not found: " + session_id)); |
41 return false; | 42 return false; |
42 } | 43 } |
43 | 44 |
44 LOG(INFO) << "Waiting for the page to stop loading"; | 45 // TODO(kkania): Do not use the standard automation timeout for this, |
45 Error* error = session_->WaitForAllTabsToStopLoading(); | 46 // and throw an error if it does not succeed. |
46 if (error) { | 47 scoped_ptr<Error> error(session_->WaitForAllTabsToStopLoading()); |
47 response->SetError(error); | 48 if (error.get()) { |
48 return false; | 49 LOG(WARNING) << error->ToString(); |
49 } | 50 } |
50 LOG(INFO) << "Done waiting for the page to stop loading"; | 51 error.reset(session_->SwitchToTopFrameIfCurrentFrameInvalid()); |
51 error = session_->SwitchToTopFrameIfCurrentFrameInvalid(); | 52 if (error.get()) { |
52 if (error) { | 53 LOG(WARNING) << error->ToString(); |
53 response->SetError(error); | |
54 return false; | |
55 } | 54 } |
56 | 55 |
57 response->SetField("sessionId", Value::CreateStringValue(session_id)); | 56 response->SetField("sessionId", Value::CreateStringValue(session_id)); |
58 return true; | 57 return true; |
59 } | 58 } |
60 | 59 |
61 } // namespace webdriver | 60 } // namespace webdriver |
OLD | NEW |