| OLD | NEW |
| 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/window_commands.h" | 5 #include "chrome/test/chromedriver/window_commands.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include <list> | 9 #include <list> |
| 10 #include <string> | 10 #include <string> |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 77 std::string name; | 77 std::string name; |
| 78 std::string value; | 78 std::string value; |
| 79 std::string domain; | 79 std::string domain; |
| 80 std::string path; | 80 std::string path; |
| 81 double expiry; | 81 double expiry; |
| 82 bool http_only; | 82 bool http_only; |
| 83 bool secure; | 83 bool secure; |
| 84 bool session; | 84 bool session; |
| 85 }; | 85 }; |
| 86 | 86 |
| 87 base::DictionaryValue* CreateDictionaryFrom(const Cookie& cookie) { | 87 std::unique_ptr<base::DictionaryValue> CreateDictionaryFrom( |
| 88 base::DictionaryValue* dict = new base::DictionaryValue(); | 88 const Cookie& cookie) { |
| 89 std::unique_ptr<base::DictionaryValue> dict(new base::DictionaryValue()); |
| 89 dict->SetString("name", cookie.name); | 90 dict->SetString("name", cookie.name); |
| 90 dict->SetString("value", cookie.value); | 91 dict->SetString("value", cookie.value); |
| 91 if (!cookie.domain.empty()) | 92 if (!cookie.domain.empty()) |
| 92 dict->SetString("domain", cookie.domain); | 93 dict->SetString("domain", cookie.domain); |
| 93 if (!cookie.path.empty()) | 94 if (!cookie.path.empty()) |
| 94 dict->SetString("path", cookie.path); | 95 dict->SetString("path", cookie.path); |
| 95 if (!cookie.session) | 96 if (!cookie.session) |
| 96 dict->SetDouble("expiry", cookie.expiry); | 97 dict->SetDouble("expiry", cookie.expiry); |
| 97 dict->SetBoolean("httpOnly", cookie.http_only); | 98 dict->SetBoolean("httpOnly", cookie.http_only); |
| 98 dict->SetBoolean("secure", cookie.secure); | 99 dict->SetBoolean("secure", cookie.secure); |
| (...skipping 240 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 339 if (id->IsType(base::Value::TYPE_NULL)) { | 340 if (id->IsType(base::Value::TYPE_NULL)) { |
| 340 session->SwitchToTopFrame(); | 341 session->SwitchToTopFrame(); |
| 341 return Status(kOk); | 342 return Status(kOk); |
| 342 } | 343 } |
| 343 | 344 |
| 344 std::string script; | 345 std::string script; |
| 345 base::ListValue args; | 346 base::ListValue args; |
| 346 const base::DictionaryValue* id_dict; | 347 const base::DictionaryValue* id_dict; |
| 347 if (id->GetAsDictionary(&id_dict)) { | 348 if (id->GetAsDictionary(&id_dict)) { |
| 348 script = "function(elem) { return elem; }"; | 349 script = "function(elem) { return elem; }"; |
| 349 args.Append(id_dict->DeepCopy()); | 350 args.Append(id_dict->CreateDeepCopy()); |
| 350 } else { | 351 } else { |
| 351 script = | 352 script = |
| 352 "function(xpath) {" | 353 "function(xpath) {" |
| 353 " return document.evaluate(xpath, document, null, " | 354 " return document.evaluate(xpath, document, null, " |
| 354 " XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue;" | 355 " XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue;" |
| 355 "}"; | 356 "}"; |
| 356 std::string xpath = "(/html/body//iframe|/html/frameset//frame)"; | 357 std::string xpath = "(/html/body//iframe|/html/frameset//frame)"; |
| 357 std::string id_string; | 358 std::string id_string; |
| 358 int id_int; | 359 int id_int; |
| 359 if (id->GetAsString(&id_string)) { | 360 if (id->GetAsString(&id_string)) { |
| (...skipping 20 matching lines...) Expand all Loading... |
| 380 const base::DictionaryValue* element; | 381 const base::DictionaryValue* element; |
| 381 if (!result->GetAsDictionary(&element)) | 382 if (!result->GetAsDictionary(&element)) |
| 382 return Status(kUnknownError, "fail to locate the sub frame element"); | 383 return Status(kUnknownError, "fail to locate the sub frame element"); |
| 383 | 384 |
| 384 std::string chrome_driver_id = GenerateId(); | 385 std::string chrome_driver_id = GenerateId(); |
| 385 const char kSetFrameIdentifier[] = | 386 const char kSetFrameIdentifier[] = |
| 386 "function(frame, id) {" | 387 "function(frame, id) {" |
| 387 " frame.setAttribute('cd_frame_id_', id);" | 388 " frame.setAttribute('cd_frame_id_', id);" |
| 388 "}"; | 389 "}"; |
| 389 base::ListValue new_args; | 390 base::ListValue new_args; |
| 390 new_args.Append(element->DeepCopy()); | 391 new_args.Append(element->CreateDeepCopy()); |
| 391 new_args.AppendString(chrome_driver_id); | 392 new_args.AppendString(chrome_driver_id); |
| 392 result.reset(NULL); | 393 result.reset(NULL); |
| 393 status = web_view->CallFunction( | 394 status = web_view->CallFunction( |
| 394 session->GetCurrentFrameId(), kSetFrameIdentifier, new_args, &result); | 395 session->GetCurrentFrameId(), kSetFrameIdentifier, new_args, &result); |
| 395 if (status.IsError()) | 396 if (status.IsError()) |
| 396 return status; | 397 return status; |
| 397 session->SwitchToSubFrame(frame, chrome_driver_id); | 398 session->SwitchToSubFrame(frame, chrome_driver_id); |
| 398 return Status(kOk); | 399 return Status(kOk); |
| 399 } | 400 } |
| 400 | 401 |
| (...skipping 494 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 895 | 896 |
| 896 Status ExecuteAddCookie(Session* session, | 897 Status ExecuteAddCookie(Session* session, |
| 897 WebView* web_view, | 898 WebView* web_view, |
| 898 const base::DictionaryValue& params, | 899 const base::DictionaryValue& params, |
| 899 std::unique_ptr<base::Value>* value, | 900 std::unique_ptr<base::Value>* value, |
| 900 Timeout* timeout) { | 901 Timeout* timeout) { |
| 901 const base::DictionaryValue* cookie; | 902 const base::DictionaryValue* cookie; |
| 902 if (!params.GetDictionary("cookie", &cookie)) | 903 if (!params.GetDictionary("cookie", &cookie)) |
| 903 return Status(kUnknownError, "missing 'cookie'"); | 904 return Status(kUnknownError, "missing 'cookie'"); |
| 904 base::ListValue args; | 905 base::ListValue args; |
| 905 args.Append(cookie->DeepCopy()); | 906 args.Append(cookie->CreateDeepCopy()); |
| 906 std::unique_ptr<base::Value> result; | 907 std::unique_ptr<base::Value> result; |
| 907 return web_view->CallFunction( | 908 return web_view->CallFunction( |
| 908 session->GetCurrentFrameId(), kAddCookieScript, args, &result); | 909 session->GetCurrentFrameId(), kAddCookieScript, args, &result); |
| 909 } | 910 } |
| 910 | 911 |
| 911 Status ExecuteDeleteCookie(Session* session, | 912 Status ExecuteDeleteCookie(Session* session, |
| 912 WebView* web_view, | 913 WebView* web_view, |
| 913 const base::DictionaryValue& params, | 914 const base::DictionaryValue& params, |
| 914 std::unique_ptr<base::Value>* value, | 915 std::unique_ptr<base::Value>* value, |
| 915 Timeout* timeout) { | 916 Timeout* timeout) { |
| (...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1063 return status; | 1064 return status; |
| 1064 } | 1065 } |
| 1065 | 1066 |
| 1066 Status ExecuteTakeHeapSnapshot(Session* session, | 1067 Status ExecuteTakeHeapSnapshot(Session* session, |
| 1067 WebView* web_view, | 1068 WebView* web_view, |
| 1068 const base::DictionaryValue& params, | 1069 const base::DictionaryValue& params, |
| 1069 std::unique_ptr<base::Value>* value, | 1070 std::unique_ptr<base::Value>* value, |
| 1070 Timeout* timeout) { | 1071 Timeout* timeout) { |
| 1071 return web_view->TakeHeapSnapshot(value); | 1072 return web_view->TakeHeapSnapshot(value); |
| 1072 } | 1073 } |
| OLD | NEW |