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