OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 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/chromedriver/commands.h" | 5 #include "chrome/test/chromedriver/commands.h" |
6 | 6 |
7 #include "base/callback.h" | 7 #include "base/callback.h" |
8 #include "base/file_util.h" | 8 #include "base/file_util.h" |
9 #include "base/stringprintf.h" | 9 #include "base/stringprintf.h" |
10 #include "base/sys_info.h" | 10 #include "base/sys_info.h" |
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
111 | 111 |
112 scoped_ptr<ChromeDesktopImpl> chrome_desktop(new ChromeDesktopImpl( | 112 scoped_ptr<ChromeDesktopImpl> chrome_desktop(new ChromeDesktopImpl( |
113 context_getter, port, socket_factory)); | 113 context_getter, port, socket_factory)); |
114 status = chrome_desktop->Launch(chrome_exe, args_list, extensions_list, | 114 status = chrome_desktop->Launch(chrome_exe, args_list, extensions_list, |
115 prefs_dict, local_state_dict); | 115 prefs_dict, local_state_dict); |
116 chrome.reset(chrome_desktop.release()); | 116 chrome.reset(chrome_desktop.release()); |
117 } | 117 } |
118 if (status.IsError()) | 118 if (status.IsError()) |
119 return Status(kSessionNotCreatedException, status.message()); | 119 return Status(kSessionNotCreatedException, status.message()); |
120 | 120 |
121 std::list<WebView*> web_views; | 121 std::list<std::string> web_view_ids; |
122 status = chrome->GetWebViews(&web_views); | 122 status = chrome->GetWebViewIds(&web_view_ids); |
123 if (status.IsError() || web_views.empty()) { | 123 if (status.IsError() || web_view_ids.empty()) { |
124 chrome->Quit(); | 124 chrome->Quit(); |
125 return status.IsError() ? status : | 125 return status.IsError() ? status : |
126 Status(kUnknownError, "unable to discover open window in chrome"); | 126 Status(kUnknownError, "unable to discover open window in chrome"); |
127 } | 127 } |
128 WebView* default_web_view = web_views.front(); | |
129 | 128 |
130 std::string new_id = session_id; | 129 std::string new_id = session_id; |
131 if (new_id.empty()) | 130 if (new_id.empty()) |
132 new_id = GenerateId(); | 131 new_id = GenerateId(); |
133 scoped_ptr<Session> session(new Session(new_id, chrome.Pass())); | 132 scoped_ptr<Session> session(new Session(new_id, chrome.Pass())); |
134 if (!session->thread.Start()) { | 133 if (!session->thread.Start()) { |
135 chrome->Quit(); | 134 chrome->Quit(); |
136 return Status(kUnknownError, | 135 return Status(kUnknownError, |
137 "failed to start a thread for the new session"); | 136 "failed to start a thread for the new session"); |
138 } | 137 } |
139 session->window = default_web_view->GetId(); | 138 session->window = web_view_ids.front(); |
140 out_value->reset(session->capabilities->DeepCopy()); | 139 out_value->reset(session->capabilities->DeepCopy()); |
141 *out_session_id = new_id; | 140 *out_session_id = new_id; |
142 | 141 |
143 scoped_refptr<SessionAccessor> accessor( | 142 scoped_refptr<SessionAccessor> accessor( |
144 new SessionAccessorImpl(session.Pass())); | 143 new SessionAccessorImpl(session.Pass())); |
145 session_map->Set(new_id, accessor); | 144 session_map->Set(new_id, accessor); |
146 | 145 |
147 return Status(kOk); | 146 return Status(kOk); |
148 } | 147 } |
149 | 148 |
150 Status ExecuteQuitAll( | 149 Status ExecuteQuitAll( |
151 Command quit_command, | 150 Command quit_command, |
152 SessionMap* session_map, | 151 SessionMap* session_map, |
153 const base::DictionaryValue& params, | 152 const base::DictionaryValue& params, |
154 const std::string& session_id, | 153 const std::string& session_id, |
155 scoped_ptr<base::Value>* out_value, | 154 scoped_ptr<base::Value>* out_value, |
156 std::string* out_session_id) { | 155 std::string* out_session_id) { |
157 std::vector<std::string> session_ids; | 156 std::vector<std::string> session_ids; |
158 session_map->GetKeys(&session_ids); | 157 session_map->GetKeys(&session_ids); |
159 for (size_t i = 0; i < session_ids.size(); ++i) { | 158 for (size_t i = 0; i < session_ids.size(); ++i) { |
160 scoped_ptr<base::Value> unused_value; | 159 scoped_ptr<base::Value> unused_value; |
161 std::string unused_session_id; | 160 std::string unused_session_id; |
162 quit_command.Run(params, session_ids[i], &unused_value, &unused_session_id); | 161 quit_command.Run(params, session_ids[i], &unused_value, &unused_session_id); |
163 } | 162 } |
164 return Status(kOk); | 163 return Status(kOk); |
165 } | 164 } |
OLD | NEW |