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

Side by Side Diff: chrome/test/chromedriver/session_commands.cc

Issue 12978003: [chromedriver] Fix 3 bugs about web view, window handle and target window. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebase. Created 7 years, 9 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
« no previous file with comments | « chrome/test/chromedriver/session.cc ('k') | chrome/test/chromedriver/session_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2013 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/session_commands.h" 5 #include "chrome/test/chromedriver/session_commands.h"
6 6
7 #include <list> 7 #include <list>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/callback.h" 10 #include "base/callback.h"
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after
112 112
113 value->reset(new StringValue(WebViewIdToWindowHandle(web_view->GetId()))); 113 value->reset(new StringValue(WebViewIdToWindowHandle(web_view->GetId())));
114 return Status(kOk); 114 return Status(kOk);
115 } 115 }
116 116
117 Status ExecuteClose( 117 Status ExecuteClose(
118 SessionMap* session_map, 118 SessionMap* session_map,
119 Session* session, 119 Session* session,
120 const base::DictionaryValue& params, 120 const base::DictionaryValue& params,
121 scoped_ptr<base::Value>* value) { 121 scoped_ptr<base::Value>* value) {
122 std::list<WebView*> web_views; 122 std::list<std::string> web_view_ids;
123 Status status = session->chrome->GetWebViews(&web_views); 123 Status status = session->chrome->GetWebViewIds(&web_view_ids);
124 if (status.IsError()) 124 if (status.IsError())
125 return status; 125 return status;
126 bool is_last_web_view = web_views.size() == 1u; 126 bool is_last_web_view = web_view_ids.size() == 1u;
127 web_views.clear(); 127 web_view_ids.clear();
128 128
129 WebView* web_view = NULL; 129 WebView* web_view = NULL;
130 status = session->GetTargetWindow(&web_view); 130 status = session->GetTargetWindow(&web_view);
131 if (status.IsError()) 131 if (status.IsError())
132 return status; 132 return status;
133 133
134 status = web_view->Close(); 134 status = web_view->Close();
135 if (status.IsError()) 135 if (status.IsError())
136 return status; 136 return status;
137 137
138 status = session->chrome->GetWebViews(&web_views); 138 status = session->chrome->GetWebViewIds(&web_view_ids);
139 if ((status.code() == kChromeNotReachable && is_last_web_view) || 139 if ((status.code() == kChromeNotReachable && is_last_web_view) ||
140 (status.IsOk() && web_views.empty())) { 140 (status.IsOk() && web_view_ids.empty())) {
141 CHECK(session_map->Remove(session->id)); 141 CHECK(session_map->Remove(session->id));
142 return Status(kOk); 142 return Status(kOk);
143 } 143 }
144 return status; 144 return status;
145 } 145 }
146 146
147 Status ExecuteGetWindowHandles( 147 Status ExecuteGetWindowHandles(
148 Session* session, 148 Session* session,
149 const base::DictionaryValue& params, 149 const base::DictionaryValue& params,
150 scoped_ptr<base::Value>* value) { 150 scoped_ptr<base::Value>* value) {
151 std::list<WebView*> web_views; 151 std::list<std::string> web_view_ids;
152 Status status = session->chrome->GetWebViews(&web_views); 152 Status status = session->chrome->GetWebViewIds(&web_view_ids);
153 if (status.IsError()) 153 if (status.IsError())
154 return status; 154 return status;
155 base::ListValue window_ids; 155 scoped_ptr<base::ListValue> window_ids(new base::ListValue());
156 for (std::list<WebView*>::const_iterator it = web_views.begin(); 156 for (std::list<std::string>::const_iterator it = web_view_ids.begin();
157 it != web_views.end(); ++it) { 157 it != web_view_ids.end(); ++it) {
158 window_ids.AppendString(WebViewIdToWindowHandle((*it)->GetId())); 158 window_ids->AppendString(WebViewIdToWindowHandle(*it));
159 } 159 }
160 value->reset(window_ids.DeepCopy()); 160 value->reset(window_ids.release());
161 return Status(kOk); 161 return Status(kOk);
162 } 162 }
163 163
164 Status ExecuteSwitchToWindow( 164 Status ExecuteSwitchToWindow(
165 Session* session, 165 Session* session,
166 const base::DictionaryValue& params, 166 const base::DictionaryValue& params,
167 scoped_ptr<base::Value>* value) { 167 scoped_ptr<base::Value>* value) {
168 std::string name; 168 std::string name;
169 if (!params.GetString("name", &name) || name.empty()) 169 if (!params.GetString("name", &name) || name.empty())
170 return Status(kUnknownError, "'name' must be a nonempty string"); 170 return Status(kUnknownError, "'name' must be a nonempty string");
171 171
172 std::list<WebView*> web_views; 172 std::list<std::string> web_view_ids;
173 Status status = session->chrome->GetWebViews(&web_views); 173 Status status = session->chrome->GetWebViewIds(&web_view_ids);
174 if (status.IsError()) 174 if (status.IsError())
175 return status; 175 return status;
176 176
177 WebView* web_view = NULL;
178
179 std::string web_view_id; 177 std::string web_view_id;
178 bool found = false;
180 if (WindowHandleToWebViewId(name, &web_view_id)) { 179 if (WindowHandleToWebViewId(name, &web_view_id)) {
181 // Check if any web_view matches |web_view_id|. 180 // Check if any web_view matches |web_view_id|.
182 for (std::list<WebView*>::const_iterator it = web_views.begin(); 181 for (std::list<std::string>::const_iterator it = web_view_ids.begin();
183 it != web_views.end(); ++it) { 182 it != web_view_ids.end(); ++it) {
184 if ((*it)->GetId() == web_view_id) { 183 if (*it == web_view_id) {
185 web_view = *it; 184 found = true;
186 break; 185 break;
187 } 186 }
188 } 187 }
189 } else { 188 } else {
190 // Check if any of the tab window names match |name|. 189 // Check if any of the tab window names match |name|.
191 const char* kGetWindowNameScript = "function() { return window.name; }"; 190 const char* kGetWindowNameScript = "function() { return window.name; }";
192 base::ListValue args; 191 base::ListValue args;
193 for (std::list<WebView*>::const_iterator it = web_views.begin(); 192 for (std::list<std::string>::const_iterator it = web_view_ids.begin();
194 it != web_views.end(); ++it) { 193 it != web_view_ids.end(); ++it) {
195 scoped_ptr<base::Value> result; 194 scoped_ptr<base::Value> result;
196 status = (*it)->CallFunction("", kGetWindowNameScript, args, &result); 195 WebView* web_view;
196 status = session->chrome->GetWebViewById(*it, &web_view);
197 if (status.IsError())
198 return status;
199 status = web_view->ConnectIfNecessary();
200 if (status.IsError())
201 return status;
202 status = web_view->CallFunction("", kGetWindowNameScript, args, &result);
197 if (status.IsError()) 203 if (status.IsError())
198 return status; 204 return status;
199 std::string window_name; 205 std::string window_name;
200 if (!result->GetAsString(&window_name)) 206 if (!result->GetAsString(&window_name))
201 return Status(kUnknownError, "failed to get window name"); 207 return Status(kUnknownError, "failed to get window name");
202 if (window_name == name) { 208 if (window_name == name) {
203 web_view = *it; 209 web_view_id = *it;
210 found = true;
204 break; 211 break;
205 } 212 }
206 } 213 }
207 } 214 }
208 215
209 if (!web_view) 216 if (!found)
210 return Status(kNoSuchWindow); 217 return Status(kNoSuchWindow);
211 session->window = web_view->GetId(); 218 session->window = web_view_id;
212 session->SwitchToTopFrame(); 219 session->SwitchToTopFrame();
213 session->mouse_position = WebPoint(0, 0); 220 session->mouse_position = WebPoint(0, 0);
214 return Status(kOk); 221 return Status(kOk);
215 } 222 }
216 223
217 Status ExecuteSetTimeout( 224 Status ExecuteSetTimeout(
218 Session* session, 225 Session* session,
219 const base::DictionaryValue& params, 226 const base::DictionaryValue& params,
220 scoped_ptr<base::Value>* value) { 227 scoped_ptr<base::Value>* value) {
221 int ms; 228 int ms;
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after
334 return status; 341 return status;
335 342
336 bool is_pending; 343 bool is_pending;
337 status = web_view->IsPendingNavigation( 344 status = web_view->IsPendingNavigation(
338 session->GetCurrentFrameId(), &is_pending); 345 session->GetCurrentFrameId(), &is_pending);
339 if (status.IsError()) 346 if (status.IsError())
340 return status; 347 return status;
341 value->reset(new base::FundamentalValue(is_pending)); 348 value->reset(new base::FundamentalValue(is_pending));
342 return Status(kOk); 349 return Status(kOk);
343 } 350 }
OLDNEW
« no previous file with comments | « chrome/test/chromedriver/session.cc ('k') | chrome/test/chromedriver/session_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698