1 // Copyright (c) 2012 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/create_session.h" 6 7 #include <string> 8 9 #include "base/command_line.h" 10 #include "base/files/file_path.h" 11 #include "base/files/scoped_temp_dir.h" 12 #include "base/values.h" 13 #include "chrome/test/webdriver/commands/response.h" 14 #include "chrome/test/webdriver/webdriver_error.h" 15 #include "chrome/test/webdriver/webdriver_session.h" 16 #include "chrome/test/webdriver/webdriver_session_manager.h" 17 18 namespace webdriver { 19 20 CreateSession::CreateSession(const std::vector<std::string>& path_segments, 21 const base::DictionaryValue* const parameters) 22 : Command(path_segments, parameters) {} 23 24 CreateSession::~CreateSession() {} 25 26 bool CreateSession::DoesPost() { return true; } 27 28 void CreateSession::ExecutePost(Response* const response) { 29 const base::DictionaryValue* dict; 30 if (!GetDictionaryParameter("desiredCapabilities", &dict)) { 31 response->SetError(new Error( 32 kBadRequest, "Missing or invalid 'desiredCapabilities'")); 33 return; 34 } 35 36 // Session manages its own liftime, so do not call delete. 37 Session* session = new Session(); 38 Error* error = session->Init(dict); 39 if (error) { 40 response->SetError(error); 41 return; 42 } 43 44 // Redirect to a relative URI. Although prohibited by the HTTP standard, 45 // this is what the IEDriver does. Finding the actual IP address is 46 // difficult, and returning the hostname causes perf problems with the python 47 // bindings on Windows. 48 std::ostringstream stream; 49 stream << SessionManager::GetInstance()->url_base() << "/session/" 50 << session->id(); 51 response->SetStatus(kSeeOther); 52 response->SetValue(new base::StringValue(stream.str())); 53 } 54 55 } // namespace webdriver 56