OLD | NEW |
(Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "chrome/test/webdriver/commands/webdriver_command.h" |
| 6 |
| 7 #include <string> |
| 8 |
| 9 #include "base/logging.h" |
| 10 #include "base/singleton.h" |
| 11 #include "base/string_util.h" |
| 12 #include "base/values.h" |
| 13 #include "base/json/json_reader.h" |
| 14 #include "base/json/json_writer.h" |
| 15 #include "chrome/app/chrome_dll_resource.h" |
| 16 #include "chrome/common/chrome_constants.h" |
| 17 #include "chrome/common/chrome_switches.h" |
| 18 #include "chrome/test/automation/automation_proxy.h" |
| 19 #include "chrome/test/automation/browser_proxy.h" |
| 20 #include "chrome/test/automation/tab_proxy.h" |
| 21 #include "chrome/test/automation/window_proxy.h" |
| 22 #include "chrome/test/webdriver/utility_functions.h" |
| 23 #include "views/event.h" |
| 24 |
| 25 namespace webdriver { |
| 26 |
| 27 const std::string WebDriverCommand::kElementDictionaryKey = "ELEMENT"; |
| 28 |
| 29 bool WebDriverCommand::IsElementIdDictionary( |
| 30 const DictionaryValue* const dictionary) { |
| 31 // Test that it has the element key and that it is a string. |
| 32 Value* element_id; |
| 33 return dictionary->Get(kElementDictionaryKey, &element_id) && |
| 34 element_id->GetType() == Value::TYPE_STRING; |
| 35 } |
| 36 |
| 37 DictionaryValue* WebDriverCommand::GetElementIdAsDictionaryValue( |
| 38 const std::string& element_id) { |
| 39 DictionaryValue* dictionary = new DictionaryValue; |
| 40 dictionary->SetString(kElementDictionaryKey, element_id); |
| 41 return dictionary; |
| 42 } |
| 43 |
| 44 bool WebDriverCommand::Init(Response* const response) { |
| 45 // There should be at least 3 path segments to match "/session/$id". |
| 46 std::string session_id = GetPathVariable(2); |
| 47 if (session_id.length() == 0) { |
| 48 response->set_value(Value::CreateStringValue("No session ID specified")); |
| 49 response->set_status(kBadRequest); |
| 50 return false; |
| 51 } |
| 52 |
| 53 LOG(INFO) << "Fetching session: " << session_id; |
| 54 session_ = Singleton<SessionManager>::get()->GetSession(session_id); |
| 55 if (session_ == NULL) { |
| 56 response->set_value(Value::CreateStringValue( |
| 57 "Session not found: " + session_id)); |
| 58 response->set_status(kSessionNotFound); |
| 59 return false; |
| 60 } |
| 61 |
| 62 response->SetField("sessionId", Value::CreateStringValue(session_id)); |
| 63 return !RequiresValidTab() || VerifyTabIsValid(response); |
| 64 } |
| 65 |
| 66 bool WebDriverCommand::VerifyTabIsValid(Response* response) { |
| 67 tab_ = session_->ActivateTab(); |
| 68 if (!tab_.get()) { |
| 69 response->set_value(Value::CreateStringValue( |
| 70 "Lost session window handle; did you close the window?")); |
| 71 response->set_status(kNoSuchWindow); |
| 72 return false; |
| 73 } |
| 74 return true; |
| 75 } |
| 76 } // namespace webdriver |
| 77 |
OLD | NEW |