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

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

Issue 2230053002: [chromedriver] Added option to make element references W3C compliant. Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebased code with w3c flag change. Created 4 years, 4 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
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/chrome/web_view_impl.h" 5 #include "chrome/test/chromedriver/chrome/web_view_impl.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 #include <utility> 8 #include <utility>
9 9
10 #include "base/bind.h" 10 #include "base/bind.h"
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after
119 return ""; 119 return "";
120 } 120 }
121 } 121 }
122 122
123 } // namespace 123 } // namespace
124 124
125 WebViewImpl::WebViewImpl(const std::string& id, 125 WebViewImpl::WebViewImpl(const std::string& id,
126 const BrowserInfo* browser_info, 126 const BrowserInfo* browser_info,
127 std::unique_ptr<DevToolsClient> client, 127 std::unique_ptr<DevToolsClient> client,
128 const DeviceMetrics* device_metrics, 128 const DeviceMetrics* device_metrics,
129 std::string page_load_strategy) 129 std::string page_load_strategy,
130 const bool w3c_compliant)
samuong 2016/08/11 18:13:20 nit: move the |w3c_compliant| parameter up to the
roisinmcl 2016/08/13 01:47:26 Done.
130 : id_(id), 131 : id_(id),
132 w3c_compliant_(w3c_compliant),
131 browser_info_(browser_info), 133 browser_info_(browser_info),
132 dom_tracker_(new DomTracker(client.get())), 134 dom_tracker_(new DomTracker(client.get())),
133 frame_tracker_(new FrameTracker(client.get())), 135 frame_tracker_(new FrameTracker(client.get())),
134 dialog_manager_(new JavaScriptDialogManager(client.get())), 136 dialog_manager_(new JavaScriptDialogManager(client.get())),
135 navigation_tracker_(PageLoadStrategy::Create( 137 navigation_tracker_(PageLoadStrategy::Create(
136 page_load_strategy, client.get(), 138 page_load_strategy, client.get(),
137 browser_info, dialog_manager_.get())), 139 browser_info, dialog_manager_.get())),
138 mobile_emulation_override_manager_( 140 mobile_emulation_override_manager_(
139 new MobileEmulationOverrideManager(client.get(), device_metrics)), 141 new MobileEmulationOverrideManager(client.get(), device_metrics)),
140 geolocation_override_manager_( 142 geolocation_override_manager_(
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after
265 return internal::EvaluateScriptAndGetValue( 267 return internal::EvaluateScriptAndGetValue(
266 client_.get(), context_id, expression, result); 268 client_.get(), context_id, expression, result);
267 } 269 }
268 270
269 Status WebViewImpl::CallFunction(const std::string& frame, 271 Status WebViewImpl::CallFunction(const std::string& frame,
270 const std::string& function, 272 const std::string& function,
271 const base::ListValue& args, 273 const base::ListValue& args,
272 std::unique_ptr<base::Value>* result) { 274 std::unique_ptr<base::Value>* result) {
273 std::string json; 275 std::string json;
274 base::JSONWriter::Write(args, &json); 276 base::JSONWriter::Write(args, &json);
277 std::string w3c = w3c_compliant_ ? "true" : "false";
275 // TODO(zachconrad): Second null should be array of shadow host ids. 278 // TODO(zachconrad): Second null should be array of shadow host ids.
276 std::string expression = base::StringPrintf( 279 std::string expression = base::StringPrintf(
277 "(%s).apply(null, [null, %s, %s])", 280 "(%s).apply(null, [null, %s, %s, %s])",
278 kCallFunctionScript, 281 kCallFunctionScript,
279 function.c_str(), 282 function.c_str(),
280 json.c_str()); 283 json.c_str(),
284 w3c.c_str());
281 std::unique_ptr<base::Value> temp_result; 285 std::unique_ptr<base::Value> temp_result;
282 Status status = EvaluateScript(frame, expression, &temp_result); 286 Status status = EvaluateScript(frame, expression, &temp_result);
283 if (status.IsError()) 287 if (status.IsError())
284 return status; 288 return status;
285 return internal::ParseCallFunctionResult(*temp_result, result); 289 return internal::ParseCallFunctionResult(*temp_result, result);
286 } 290 }
287 291
288 Status WebViewImpl::CallAsyncFunction(const std::string& frame, 292 Status WebViewImpl::CallAsyncFunction(const std::string& frame,
289 const std::string& function, 293 const std::string& function,
290 const base::ListValue& args, 294 const base::ListValue& args,
(...skipping 18 matching lines...) Expand all
309 const base::ListValue& args, 313 const base::ListValue& args,
310 std::string* out_frame) { 314 std::string* out_frame) {
311 int context_id; 315 int context_id;
312 Status status = GetContextIdForFrame(frame_tracker_.get(), frame, 316 Status status = GetContextIdForFrame(frame_tracker_.get(), frame,
313 &context_id); 317 &context_id);
314 if (status.IsError()) 318 if (status.IsError())
315 return status; 319 return status;
316 bool found_node; 320 bool found_node;
317 int node_id; 321 int node_id;
318 status = internal::GetNodeIdFromFunction( 322 status = internal::GetNodeIdFromFunction(
319 client_.get(), context_id, function, args, &found_node, &node_id); 323 client_.get(), context_id, function, args,
324 &found_node, &node_id, w3c_compliant_);
320 if (status.IsError()) 325 if (status.IsError())
321 return status; 326 return status;
322 if (!found_node) 327 if (!found_node)
323 return Status(kNoSuchFrame); 328 return Status(kNoSuchFrame);
324 return dom_tracker_->GetFrameIdForNode(node_id, out_frame); 329 return dom_tracker_->GetFrameIdForNode(node_id, out_frame);
325 } 330 }
326 331
327 Status WebViewImpl::DispatchMouseEvents(const std::list<MouseEvent>& events, 332 Status WebViewImpl::DispatchMouseEvents(const std::list<MouseEvent>& events,
328 const std::string& frame) { 333 const std::string& frame) {
329 double page_scale_factor = 1.0; 334 double page_scale_factor = 1.0;
(...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after
511 Status status = GetContextIdForFrame(frame_tracker_.get(), frame, 516 Status status = GetContextIdForFrame(frame_tracker_.get(), frame,
512 &context_id); 517 &context_id);
513 if (status.IsError()) 518 if (status.IsError())
514 return status; 519 return status;
515 base::ListValue args; 520 base::ListValue args;
516 args.Append(element.DeepCopy()); 521 args.Append(element.DeepCopy());
517 bool found_node; 522 bool found_node;
518 int node_id; 523 int node_id;
519 status = internal::GetNodeIdFromFunction( 524 status = internal::GetNodeIdFromFunction(
520 client_.get(), context_id, "function(element) { return element; }", 525 client_.get(), context_id, "function(element) { return element; }",
521 args, &found_node, &node_id); 526 args, &found_node, &node_id, w3c_compliant_);
522 if (status.IsError()) 527 if (status.IsError())
523 return status; 528 return status;
524 if (!found_node) 529 if (!found_node)
525 return Status(kUnknownError, "no node ID for file input"); 530 return Status(kUnknownError, "no node ID for file input");
526 base::DictionaryValue params; 531 base::DictionaryValue params;
527 params.SetInteger("nodeId", node_id); 532 params.SetInteger("nodeId", node_id);
528 params.Set("files", file_list.DeepCopy()); 533 params.Set("files", file_list.DeepCopy());
529 return client_->SendCommand("DOM.setFileInputFiles", params); 534 return client_->SendCommand("DOM.setFileInputFiles", params);
530 } 535 }
531 536
(...skipping 286 matching lines...) Expand 10 before | Expand all | Expand 10 after
818 } 823 }
819 result->reset(unscoped_value->DeepCopy()); 824 result->reset(unscoped_value->DeepCopy());
820 return Status(kOk); 825 return Status(kOk);
821 } 826 }
822 827
823 Status GetNodeIdFromFunction(DevToolsClient* client, 828 Status GetNodeIdFromFunction(DevToolsClient* client,
824 int context_id, 829 int context_id,
825 const std::string& function, 830 const std::string& function,
826 const base::ListValue& args, 831 const base::ListValue& args,
827 bool* found_node, 832 bool* found_node,
828 int* node_id) { 833 int* node_id,
834 bool w3c_compliant) {
829 std::string json; 835 std::string json;
830 base::JSONWriter::Write(args, &json); 836 base::JSONWriter::Write(args, &json);
837 std::string w3c = w3c_compliant ? "true" : "false";
831 // TODO(zachconrad): Second null should be array of shadow host ids. 838 // TODO(zachconrad): Second null should be array of shadow host ids.
832 std::string expression = base::StringPrintf( 839 std::string expression = base::StringPrintf(
833 "(%s).apply(null, [null, %s, %s, true])", 840 "(%s).apply(null, [null, %s, %s, %s, true])",
834 kCallFunctionScript, 841 kCallFunctionScript,
835 function.c_str(), 842 function.c_str(),
836 json.c_str()); 843 json.c_str(),
844 w3c.c_str());
837 845
838 bool got_object; 846 bool got_object;
839 std::string element_id; 847 std::string element_id;
840 Status status = internal::EvaluateScriptAndGetObject( 848 Status status = internal::EvaluateScriptAndGetObject(
841 client, context_id, expression, &got_object, &element_id); 849 client, context_id, expression, &got_object, &element_id);
842 if (status.IsError()) 850 if (status.IsError())
843 return status; 851 return status;
844 if (!got_object) { 852 if (!got_object) {
845 *found_node = false; 853 *found_node = false;
846 return Status(kOk); 854 return Status(kOk);
(...skipping 20 matching lines...) Expand all
867 if (status.IsError()) 875 if (status.IsError())
868 return status; 876 return status;
869 877
870 if (!cmd_result->GetInteger("nodeId", node_id)) 878 if (!cmd_result->GetInteger("nodeId", node_id))
871 return Status(kUnknownError, "DOM.requestNode missing int 'nodeId'"); 879 return Status(kUnknownError, "DOM.requestNode missing int 'nodeId'");
872 *found_node = true; 880 *found_node = true;
873 return Status(kOk); 881 return Status(kOk);
874 } 882 }
875 883
876 } // namespace internal 884 } // namespace internal
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698