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

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: 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
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/callback.h" 9 #include "base/callback.h"
10 #include "base/logging.h" // For CHECK macros. 10 #include "base/logging.h" // For CHECK macros.
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after
99 if (status.IsError()) 99 if (status.IsError())
100 return status; 100 return status;
101 101
102 return web_view->Close(); 102 return web_view->Close();
103 } 103 }
104 104
105 Status ExecuteGetWindowHandles( 105 Status ExecuteGetWindowHandles(
106 Session* session, 106 Session* session,
107 const base::DictionaryValue& params, 107 const base::DictionaryValue& params,
108 scoped_ptr<base::Value>* value) { 108 scoped_ptr<base::Value>* value) {
109 std::list<WebView*> web_views; 109 std::list<std::string> web_view_ids;
110 Status status = session->chrome->GetWebViews(&web_views); 110 Status status = session->chrome->GetWebViewIds(&web_view_ids);
111 if (status.IsError()) 111 if (status.IsError())
112 return status; 112 return status;
113 base::ListValue window_ids; 113 scoped_ptr<base::ListValue> window_ids(new base::ListValue());
114 for (std::list<WebView*>::const_iterator it = web_views.begin(); 114 for (std::list<std::string>::const_iterator it = web_view_ids.begin();
115 it != web_views.end(); ++it) { 115 it != web_view_ids.end(); ++it) {
116 window_ids.AppendString(WebViewIdToWindowHandle((*it)->GetId())); 116 window_ids->AppendString(WebViewIdToWindowHandle(*it));
117 } 117 }
118 value->reset(window_ids.DeepCopy()); 118 value->reset(window_ids.release());
119 return Status(kOk); 119 return Status(kOk);
120 } 120 }
121 121
122 Status ExecuteSwitchToWindow( 122 Status ExecuteSwitchToWindow(
123 Session* session, 123 Session* session,
124 const base::DictionaryValue& params, 124 const base::DictionaryValue& params,
125 scoped_ptr<base::Value>* value) { 125 scoped_ptr<base::Value>* value) {
126 std::string name; 126 std::string name;
127 if (!params.GetString("name", &name) || name.empty()) 127 if (!params.GetString("name", &name) || name.empty())
128 return Status(kUnknownError, "'name' must be a nonempty string"); 128 return Status(kUnknownError, "'name' must be a nonempty string");
129 129
130 std::list<WebView*> web_views; 130 std::list<std::string> web_view_ids;
131 Status status = session->chrome->GetWebViews(&web_views); 131 Status status = session->chrome->GetWebViewIds(&web_view_ids);
132 if (status.IsError()) 132 if (status.IsError())
133 return status; 133 return status;
134 134
135 WebView* web_view = NULL;
136
137 std::string web_view_id; 135 std::string web_view_id;
136 bool found = false;
138 if (WindowHandleToWebViewId(name, &web_view_id)) { 137 if (WindowHandleToWebViewId(name, &web_view_id)) {
139 // Check if any web_view matches |web_view_id|. 138 // Check if any web_view matches |web_view_id|.
140 for (std::list<WebView*>::const_iterator it = web_views.begin(); 139 for (std::list<std::string>::const_iterator it = web_view_ids.begin();
141 it != web_views.end(); ++it) { 140 it != web_view_ids.end(); ++it) {
142 if ((*it)->GetId() == web_view_id) { 141 if (*it == web_view_id) {
143 web_view = *it; 142 found = true;
144 break; 143 break;
145 } 144 }
146 } 145 }
147 } else { 146 } else {
148 // Check if any of the tab window names match |name|. 147 // Check if any of the tab window names match |name|.
149 const char* kGetWindowNameScript = "function() { return window.name; }"; 148 const char* kGetWindowNameScript = "function() { return window.name; }";
150 base::ListValue args; 149 base::ListValue args;
151 for (std::list<WebView*>::const_iterator it = web_views.begin(); 150 for (std::list<std::string>::const_iterator it = web_view_ids.begin();
152 it != web_views.end(); ++it) { 151 it != web_view_ids.end(); ++it) {
153 scoped_ptr<base::Value> result; 152 scoped_ptr<base::Value> result;
154 status = (*it)->CallFunction("", kGetWindowNameScript, args, &result); 153 WebView* web_view;
154 status = session->chrome->GetWebViewById(*it, &web_view);
155 if (status.IsError())
156 return status;
157 status = web_view->CallFunction("", kGetWindowNameScript, args, &result);
155 if (status.IsError()) 158 if (status.IsError())
156 return status; 159 return status;
157 std::string window_name; 160 std::string window_name;
158 if (!result->GetAsString(&window_name)) 161 if (!result->GetAsString(&window_name))
159 return Status(kUnknownError, "failed to get window name"); 162 return Status(kUnknownError, "failed to get window name");
160 if (window_name == name) { 163 if (window_name == name) {
161 web_view = *it; 164 web_view_id = *it;
165 found = true;
162 break; 166 break;
163 } 167 }
164 } 168 }
165 } 169 }
166 170
167 if (!web_view) 171 if (!found)
168 return Status(kNoSuchWindow); 172 return Status(kNoSuchWindow);
169 session->window = web_view->GetId(); 173 session->window = web_view_id;
170 session->SwitchToTopFrame(); 174 session->SwitchToTopFrame();
171 session->mouse_position = WebPoint(0, 0); 175 session->mouse_position = WebPoint(0, 0);
172 return Status(kOk); 176 return Status(kOk);
173 } 177 }
174 178
175 Status ExecuteSetTimeout( 179 Status ExecuteSetTimeout(
176 Session* session, 180 Session* session,
177 const base::DictionaryValue& params, 181 const base::DictionaryValue& params,
178 scoped_ptr<base::Value>* value) { 182 scoped_ptr<base::Value>* value) {
179 int ms; 183 int ms;
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after
292 return status; 296 return status;
293 297
294 bool is_pending; 298 bool is_pending;
295 status = web_view->IsPendingNavigation( 299 status = web_view->IsPendingNavigation(
296 session->GetCurrentFrameId(), &is_pending); 300 session->GetCurrentFrameId(), &is_pending);
297 if (status.IsError()) 301 if (status.IsError())
298 return status; 302 return status;
299 value->reset(new base::FundamentalValue(is_pending)); 303 value->reset(new base::FundamentalValue(is_pending));
300 return Status(kOk); 304 return Status(kOk);
301 } 305 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698