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/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/command_line.h" | 10 #include "base/command_line.h" |
11 #include "base/file_path.h" | 11 #include "base/file_path.h" |
12 #include "base/logging.h" | |
13 #include "base/stringprintf.h" | 12 #include "base/stringprintf.h" |
14 #include "base/values.h" | 13 #include "base/values.h" |
15 #include "chrome/app/chrome_command_ids.h" | 14 #include "chrome/app/chrome_command_ids.h" |
16 #include "chrome/common/chrome_constants.h" | 15 #include "chrome/common/chrome_constants.h" |
17 #include "chrome/test/webdriver/commands/response.h" | 16 #include "chrome/test/webdriver/commands/response.h" |
18 #include "chrome/test/webdriver/session.h" | 17 #include "chrome/test/webdriver/session.h" |
19 #include "chrome/test/webdriver/session_manager.h" | 18 #include "chrome/test/webdriver/session_manager.h" |
20 #include "chrome/test/webdriver/webdriver_error.h" | 19 #include "chrome/test/webdriver/webdriver_error.h" |
21 | 20 |
22 namespace webdriver { | 21 namespace webdriver { |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
62 switch_string_native.substr(separator_index + 1)); | 61 switch_string_native.substr(separator_index + 1)); |
63 } else { | 62 } else { |
64 command_line_options.AppendSwitch(switch_string); | 63 command_line_options.AppendSwitch(switch_string); |
65 } | 64 } |
66 } | 65 } |
67 } else if (capabilities->HasKey(kCustomSwitchesKey)) { | 66 } else if (capabilities->HasKey(kCustomSwitchesKey)) { |
68 response->SetError(new Error( | 67 response->SetError(new Error( |
69 kBadRequest, "Custom switches must be a list")); | 68 kBadRequest, "Custom switches must be a list")); |
70 return; | 69 return; |
71 } | 70 } |
72 Value* verbose_value; | |
73 if (capabilities->GetWithoutPathExpansion("chrome.verbose", &verbose_value)) { | |
74 bool verbose; | |
75 if (verbose_value->GetAsBoolean(&verbose) && verbose) { | |
76 // Since logging is shared among sessions, if any session requests verbose | |
77 // logging, verbose logging will be enabled for all sessions. It is not | |
78 // possible to turn it off. | |
79 logging::SetMinLogLevel(logging::LOG_INFO); | |
80 } else { | |
81 response->SetError(new Error( | |
82 kBadRequest, "verbose must be a boolean true or false")); | |
83 return; | |
84 } | |
85 } | |
86 | 71 |
87 FilePath browser_exe; | 72 FilePath browser_exe; |
88 FilePath::StringType path; | 73 FilePath::StringType path; |
89 if (capabilities->GetStringWithoutPathExpansion("chrome.binary", &path)) | 74 if (capabilities->GetStringWithoutPathExpansion("chrome.binary", &path)) |
90 browser_exe = FilePath(path); | 75 browser_exe = FilePath(path); |
91 | 76 |
92 // Session manages its own liftime, so do not call delete. | 77 // Session manages its own liftime, so do not call delete. |
93 Session* session = new Session(); | 78 Session* session = new Session(); |
94 Error* error = session->Init(browser_exe, command_line_options); | 79 Error* error = session->Init(browser_exe, command_line_options); |
95 if (error) { | 80 if (error) { |
96 response->SetError(error); | 81 response->SetError(error); |
97 return; | 82 return; |
98 } | 83 } |
99 | 84 |
100 bool native_events_required = false; | 85 bool native_events_required = false; |
101 Value* native_events_value = NULL; | 86 Value* native_events_value = NULL; |
102 if (capabilities->GetWithoutPathExpansion( | 87 if (capabilities->GetWithoutPathExpansion( |
103 "chrome.nativeEvents", &native_events_value)) { | 88 "chrome.nativeEvents", &native_events_value)) { |
104 if (native_events_value->GetAsBoolean(&native_events_required)) { | 89 if (native_events_value->GetAsBoolean(&native_events_required)) { |
105 session->set_use_native_events(native_events_required); | 90 session->set_use_native_events(native_events_required); |
106 } | 91 } |
107 } | 92 } |
108 bool screenshot_on_error = false; | 93 bool screenshot_on_error = false; |
109 if (capabilities->GetBoolean( | 94 if (capabilities->GetBoolean( |
110 "takeScreenshotOnError", &screenshot_on_error)) { | 95 "takeScreenshotOnError", &screenshot_on_error)) { |
111 session->set_screenshot_on_error(screenshot_on_error); | 96 session->set_screenshot_on_error(screenshot_on_error); |
112 } | 97 } |
113 | 98 |
114 LOG(INFO) << "Created session " << session->id(); | 99 VLOG(1) << "Created session " << session->id(); |
115 std::ostringstream stream; | 100 std::ostringstream stream; |
116 SessionManager* session_manager = SessionManager::GetInstance(); | 101 SessionManager* session_manager = SessionManager::GetInstance(); |
117 stream << "http://" << session_manager->GetAddress() << "/session/" | 102 stream << "http://" << session_manager->GetAddress() << "/session/" |
118 << session->id(); | 103 << session->id(); |
119 response->SetStatus(kSeeOther); | 104 response->SetStatus(kSeeOther); |
120 response->SetValue(Value::CreateStringValue(stream.str())); | 105 response->SetValue(Value::CreateStringValue(stream.str())); |
121 } | 106 } |
122 | 107 |
123 } // namespace webdriver | 108 } // namespace webdriver |
OLD | NEW |