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

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

Issue 12764021: [chromedriver] Support clicking an element in sub frames. (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/web_view_impl.h" 5 #include "chrome/test/chromedriver/web_view_impl.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/json/json_writer.h" 8 #include "base/json/json_writer.h"
9 #include "base/logging.h" 9 #include "base/logging.h"
10 #include "base/stringprintf.h" 10 #include "base/stringprintf.h"
11 #include "base/values.h" 11 #include "base/values.h"
12 #include "chrome/test/chromedriver/basic_types.h"
12 #include "chrome/test/chromedriver/devtools_client_impl.h" 13 #include "chrome/test/chromedriver/devtools_client_impl.h"
13 #include "chrome/test/chromedriver/dom_tracker.h" 14 #include "chrome/test/chromedriver/dom_tracker.h"
14 #include "chrome/test/chromedriver/frame_tracker.h" 15 #include "chrome/test/chromedriver/frame_tracker.h"
15 #include "chrome/test/chromedriver/javascript_dialog_manager.h" 16 #include "chrome/test/chromedriver/javascript_dialog_manager.h"
16 #include "chrome/test/chromedriver/js.h" 17 #include "chrome/test/chromedriver/js.h"
17 #include "chrome/test/chromedriver/navigation_tracker.h" 18 #include "chrome/test/chromedriver/navigation_tracker.h"
18 #include "chrome/test/chromedriver/status.h" 19 #include "chrome/test/chromedriver/status.h"
19 #include "chrome/test/chromedriver/ui_events.h" 20 #include "chrome/test/chromedriver/ui_events.h"
20 #include "chrome/test/chromedriver/web_view_delegate.h" 21 #include "chrome/test/chromedriver/web_view_delegate.h"
21 22
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
75 return "keyUp"; 76 return "keyUp";
76 case kRawKeyDownEventType: 77 case kRawKeyDownEventType:
77 return "rawKeyDown"; 78 return "rawKeyDown";
78 case kCharEventType: 79 case kCharEventType:
79 return "char"; 80 return "char";
80 default: 81 default:
81 return ""; 82 return "";
82 } 83 }
83 } 84 }
84 85
86 Status ParseSubFrame(const base::DictionaryValue* dict, Frame* frame) {
87 std::string id;
88 if (!dict->GetString("id", &id))
89 return Status(kUnknownError, "no id in frame object from DevTools");
90 std::string name;
91 dict->GetString("name", &name);
92 frame->id = id;
93 frame->name = name;
94 return Status(kOk);
95 }
96
97 Status SearchForFrame(const std::string& frame_id,
98 const base::DictionaryValue* frame_resource_tree,
99 std::list<Frame>* out_frames,
100 bool* out_found) {
101 const base::DictionaryValue* current_frame_dict;
102 if (!frame_resource_tree->GetDictionary("frame", &current_frame_dict))
103 return Status(kUnknownError, "no frame in frame resource tree");
104 Frame current_frame;
105 Status status = ParseSubFrame(current_frame_dict, &current_frame);
106 if (status.IsError())
107 return status;
108 if (current_frame.id == frame_id) {
109 out_frames->push_back(current_frame);
110 *out_found = true;
111 return Status(kOk);
112 }
113
114 const base::ListValue* child_frames;
115 if (frame_resource_tree->GetList("childFrames", &child_frames)) {
116 for (size_t i = 0; i < child_frames->GetSize(); ++i) {
117 const base::DictionaryValue* sub_tree;
118 if (!child_frames->GetDictionary(i, &sub_tree))
119 return Status(kUnknownError, "frame should be a dictionary");
120 bool found = false;
121 status = SearchForFrame(frame_id, sub_tree, out_frames, &found);
122 if (status.IsError())
123 return status;
124 if (found) {
125 out_frames->back().index = i;
126 out_frames->back().parent_id = current_frame.id;
127 out_frames->push_back(current_frame);
128 *out_found = true;
129 break;
130 }
131 }
132 }
133 return Status(kOk);
134 }
135
85 } // namespace 136 } // namespace
86 137
87 WebViewImpl::WebViewImpl(const std::string& id, 138 WebViewImpl::WebViewImpl(const std::string& id,
88 DevToolsClient* client, 139 DevToolsClient* client,
89 WebViewDelegate* delegate, 140 WebViewDelegate* delegate,
90 const CloserFunc& closer_func) 141 const CloserFunc& closer_func)
91 : id_(id), 142 : id_(id),
92 dom_tracker_(new DomTracker(client)), 143 dom_tracker_(new DomTracker(client)),
93 frame_tracker_(new FrameTracker(client)), 144 frame_tracker_(new FrameTracker(client)),
94 navigation_tracker_(new NavigationTracker(client)), 145 navigation_tracker_(new NavigationTracker(client)),
(...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after
268 scoped_ptr<base::DictionaryValue> result; 319 scoped_ptr<base::DictionaryValue> result;
269 Status status = client_->SendCommandAndGetResult( 320 Status status = client_->SendCommandAndGetResult(
270 "Page.captureScreenshot", params, &result); 321 "Page.captureScreenshot", params, &result);
271 if (status.IsError()) 322 if (status.IsError())
272 return status; 323 return status;
273 if (!result->GetString("data", screenshot)) 324 if (!result->GetString("data", screenshot))
274 return Status(kUnknownError, "expected string 'data' in response"); 325 return Status(kUnknownError, "expected string 'data' in response");
275 return Status(kOk); 326 return Status(kOk);
276 } 327 }
277 328
329 Status WebViewImpl::GetFramePath(const std::string& frame_id,
330 std::list<Frame>* frames) {
331 base::DictionaryValue params;
332 scoped_ptr<base::DictionaryValue> result;
333 Status status = client_->SendCommandAndGetResult(
334 "Page.getResourceTree", params, &result);
335 if (status.IsError())
336 return status;
337 const base::DictionaryValue* root_frame_tree;
338 if (!result->GetDictionary("frameTree", &root_frame_tree))
339 return Status(kUnknownError, "no frame tree returned by DevTools");
340 bool found = false;
341 status = SearchForFrame(frame_id, root_frame_tree, frames, &found);
342 if (status.IsError())
343 return status;
344 if (!found)
345 return Status(kUnknownError, "frame not found in the frame tree");
346 return Status(kOk);
347 }
348
278 namespace internal { 349 namespace internal {
279 350
280 Status EvaluateScript(DevToolsClient* client, 351 Status EvaluateScript(DevToolsClient* client,
281 int context_id, 352 int context_id,
282 const std::string& expression, 353 const std::string& expression,
283 EvaluateScriptReturnType return_type, 354 EvaluateScriptReturnType return_type,
284 scoped_ptr<base::DictionaryValue>* result) { 355 scoped_ptr<base::DictionaryValue>* result) {
285 base::DictionaryValue params; 356 base::DictionaryValue params;
286 params.SetString("expression", expression); 357 params.SetString("expression", expression);
287 if (context_id) 358 if (context_id)
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after
412 } 483 }
413 if (status.IsError()) 484 if (status.IsError())
414 return status; 485 return status;
415 486
416 if (!cmd_result->GetInteger("nodeId", node_id)) 487 if (!cmd_result->GetInteger("nodeId", node_id))
417 return Status(kUnknownError, "DOM.requestNode missing int 'nodeId'"); 488 return Status(kUnknownError, "DOM.requestNode missing int 'nodeId'");
418 return Status(kOk); 489 return Status(kOk);
419 } 490 }
420 491
421 } // namespace internal 492 } // namespace internal
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698