Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(93)

Side by Side Diff: chrome/test/webdriver/commands/create_session.cc

Issue 6507015: Implement the target locator commands for ChromeDriver. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: ... Created 9 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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/create_session.h" 5 #include "chrome/test/webdriver/commands/create_session.h"
6 6
7 #include <sstream> 7 #include <sstream>
8 #include <string> 8 #include <string>
9 9
10 #include "base/values.h" 10 #include "base/values.h"
11 #include "chrome/app/chrome_command_ids.h" 11 #include "chrome/app/chrome_command_ids.h"
12 #include "chrome/common/chrome_constants.h" 12 #include "chrome/common/chrome_constants.h"
13 #include "chrome/test/webdriver/session.h" 13 #include "chrome/test/webdriver/session.h"
14 #include "chrome/test/webdriver/session_manager.h" 14 #include "chrome/test/webdriver/session_manager.h"
15 15
16 namespace webdriver { 16 namespace webdriver {
17 17
18 CreateSession::CreateSession(const std::vector<std::string>& path_segments, 18 CreateSession::CreateSession(const std::vector<std::string>& path_segments,
19 const DictionaryValue* const parameters) 19 const DictionaryValue* const parameters)
20 : Command(path_segments, parameters) {} 20 : Command(path_segments, parameters) {}
21 21
22 CreateSession::~CreateSession() {} 22 CreateSession::~CreateSession() {}
23 23
24 bool CreateSession::DoesPost() { return true; } 24 bool CreateSession::DoesPost() { return true; }
25 25
26 void CreateSession::ExecutePost(Response* const response) { 26 void CreateSession::ExecutePost(Response* const response) {
27 SessionManager* session_manager = SessionManager::GetInstance(); 27 // Session manages its own liftime, so do not call delete.
28 Session* session = session_manager->Create(); 28 Session* session = new Session();
29 if (!session) {
30 SET_WEBDRIVER_ERROR(response,
31 "Failed to create session",
32 kInternalServerError);
33 return;
34 }
35
36 std::string session_id = session->id();
37 if (!session->Init()) { 29 if (!session->Init()) {
38 session_manager->Delete(session_id);
39 SET_WEBDRIVER_ERROR(response, 30 SET_WEBDRIVER_ERROR(response,
40 "Failed to initialize session", 31 "Failed to initialize session",
41 kInternalServerError); 32 kInternalServerError);
42 return; 33 return;
43 } 34 }
44 35
45 VLOG(1) << "Created session " << session_id; 36 SessionManager* session_manager = SessionManager::GetInstance();
37 VLOG(1) << "Created session " << session->id();
46 std::ostringstream stream; 38 std::ostringstream stream;
47 stream << "http://" << session_manager->GetAddress() << "/session/" 39 stream << "http://" << session_manager->GetAddress() << "/session/"
48 << session_id; 40 << session->id();
49 response->set_status(kSeeOther); 41 response->set_status(kSeeOther);
50 response->set_value(Value::CreateStringValue(stream.str())); 42 response->set_value(Value::CreateStringValue(stream.str()));
51 } 43 }
52 44
53 } // namespace webdriver 45 } // namespace webdriver
OLDNEW
« no previous file with comments | « chrome/test/webdriver/commands/command.cc ('k') | chrome/test/webdriver/commands/session_with_id.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698