OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/commands.h" | 5 #include "chrome/test/chromedriver/commands.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 | 8 |
9 #include <memory> | 9 #include <memory> |
10 #include <string> | 10 #include <string> |
(...skipping 345 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
356 if (only_one_) { | 356 if (only_one_) { |
357 base::DictionaryValue element; | 357 base::DictionaryValue element; |
358 element.SetString("ELEMENT", "1"); | 358 element.SetString("ELEMENT", "1"); |
359 result_.reset(element.DeepCopy()); | 359 result_.reset(element.DeepCopy()); |
360 } else { | 360 } else { |
361 base::DictionaryValue element1; | 361 base::DictionaryValue element1; |
362 element1.SetString("ELEMENT", "1"); | 362 element1.SetString("ELEMENT", "1"); |
363 base::DictionaryValue element2; | 363 base::DictionaryValue element2; |
364 element2.SetString("ELEMENT", "2"); | 364 element2.SetString("ELEMENT", "2"); |
365 base::ListValue list; | 365 base::ListValue list; |
366 list.Append(element1.DeepCopy()); | 366 list.Append(element1.CreateDeepCopy()); |
367 list.Append(element2.DeepCopy()); | 367 list.Append(element2.CreateDeepCopy()); |
368 result_.reset(list.DeepCopy()); | 368 result_ = list.CreateDeepCopy(); |
369 } | 369 } |
370 break; | 370 break; |
371 } | 371 } |
372 case kElementNotExistsQueryOnce: { | 372 case kElementNotExistsQueryOnce: { |
373 if (only_one_) | 373 if (only_one_) |
374 result_ = base::Value::CreateNullValue(); | 374 result_ = base::Value::CreateNullValue(); |
375 else | 375 else |
376 result_.reset(new base::ListValue()); | 376 result_.reset(new base::ListValue()); |
377 break; | 377 break; |
378 } | 378 } |
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
453 base::DictionaryValue params; | 453 base::DictionaryValue params; |
454 params.SetString("using", "id"); | 454 params.SetString("using", "id"); |
455 params.SetString("value", "a"); | 455 params.SetString("value", "a"); |
456 std::unique_ptr<base::Value> result; | 456 std::unique_ptr<base::Value> result; |
457 ASSERT_EQ(kOk, | 457 ASSERT_EQ(kOk, |
458 ExecuteFindElement(1, &session, &web_view, params, &result, | 458 ExecuteFindElement(1, &session, &web_view, params, &result, |
459 nullptr).code()); | 459 nullptr).code()); |
460 base::DictionaryValue param; | 460 base::DictionaryValue param; |
461 param.SetString("id", "a"); | 461 param.SetString("id", "a"); |
462 base::ListValue expected_args; | 462 base::ListValue expected_args; |
463 expected_args.Append(param.DeepCopy()); | 463 expected_args.Append(param.CreateDeepCopy()); |
464 web_view.Verify("frame_id1", &expected_args, result.get()); | 464 web_view.Verify("frame_id1", &expected_args, result.get()); |
465 } | 465 } |
466 | 466 |
467 TEST(CommandsTest, FailedFindElement) { | 467 TEST(CommandsTest, FailedFindElement) { |
468 FindElementWebView web_view(true, kElementNotExistsQueryOnce); | 468 FindElementWebView web_view(true, kElementNotExistsQueryOnce); |
469 Session session("id"); | 469 Session session("id"); |
470 base::DictionaryValue params; | 470 base::DictionaryValue params; |
471 params.SetString("using", "id"); | 471 params.SetString("using", "id"); |
472 params.SetString("value", "a"); | 472 params.SetString("value", "a"); |
473 std::unique_ptr<base::Value> result; | 473 std::unique_ptr<base::Value> result; |
(...skipping 10 matching lines...) Expand all Loading... |
484 base::DictionaryValue params; | 484 base::DictionaryValue params; |
485 params.SetString("using", "name"); | 485 params.SetString("using", "name"); |
486 params.SetString("value", "b"); | 486 params.SetString("value", "b"); |
487 std::unique_ptr<base::Value> result; | 487 std::unique_ptr<base::Value> result; |
488 ASSERT_EQ(kOk, | 488 ASSERT_EQ(kOk, |
489 ExecuteFindElements(1, &session, &web_view, params, &result, | 489 ExecuteFindElements(1, &session, &web_view, params, &result, |
490 nullptr).code()); | 490 nullptr).code()); |
491 base::DictionaryValue param; | 491 base::DictionaryValue param; |
492 param.SetString("name", "b"); | 492 param.SetString("name", "b"); |
493 base::ListValue expected_args; | 493 base::ListValue expected_args; |
494 expected_args.Append(param.DeepCopy()); | 494 expected_args.Append(param.CreateDeepCopy()); |
495 web_view.Verify("frame_id2", &expected_args, result.get()); | 495 web_view.Verify("frame_id2", &expected_args, result.get()); |
496 } | 496 } |
497 | 497 |
498 TEST(CommandsTest, FailedFindElements) { | 498 TEST(CommandsTest, FailedFindElements) { |
499 Session session("id"); | 499 Session session("id"); |
500 FindElementWebView web_view(false, kElementNotExistsQueryOnce); | 500 FindElementWebView web_view(false, kElementNotExistsQueryOnce); |
501 base::DictionaryValue params; | 501 base::DictionaryValue params; |
502 params.SetString("using", "id"); | 502 params.SetString("using", "id"); |
503 params.SetString("value", "a"); | 503 params.SetString("value", "a"); |
504 std::unique_ptr<base::Value> result; | 504 std::unique_ptr<base::Value> result; |
(...skipping 17 matching lines...) Expand all Loading... |
522 std::unique_ptr<base::Value> result; | 522 std::unique_ptr<base::Value> result; |
523 ASSERT_EQ( | 523 ASSERT_EQ( |
524 kOk, | 524 kOk, |
525 ExecuteFindChildElement( | 525 ExecuteFindChildElement( |
526 1, &session, &web_view, element_id, params, &result).code()); | 526 1, &session, &web_view, element_id, params, &result).code()); |
527 base::DictionaryValue locator_param; | 527 base::DictionaryValue locator_param; |
528 locator_param.SetString("tag name", "div"); | 528 locator_param.SetString("tag name", "div"); |
529 base::DictionaryValue root_element_param; | 529 base::DictionaryValue root_element_param; |
530 root_element_param.SetString("ELEMENT", element_id); | 530 root_element_param.SetString("ELEMENT", element_id); |
531 base::ListValue expected_args; | 531 base::ListValue expected_args; |
532 expected_args.Append(locator_param.DeepCopy()); | 532 expected_args.Append(locator_param.CreateDeepCopy()); |
533 expected_args.Append(root_element_param.DeepCopy()); | 533 expected_args.Append(root_element_param.CreateDeepCopy()); |
534 web_view.Verify("frame_id3", &expected_args, result.get()); | 534 web_view.Verify("frame_id3", &expected_args, result.get()); |
535 } | 535 } |
536 | 536 |
537 TEST(CommandsTest, FailedFindChildElement) { | 537 TEST(CommandsTest, FailedFindChildElement) { |
538 Session session("id"); | 538 Session session("id"); |
539 FindElementWebView web_view(true, kElementNotExistsQueryOnce); | 539 FindElementWebView web_view(true, kElementNotExistsQueryOnce); |
540 base::DictionaryValue params; | 540 base::DictionaryValue params; |
541 params.SetString("using", "id"); | 541 params.SetString("using", "id"); |
542 params.SetString("value", "a"); | 542 params.SetString("value", "a"); |
543 std::string element_id = "1"; | 543 std::string element_id = "1"; |
(...skipping 16 matching lines...) Expand all Loading... |
560 std::unique_ptr<base::Value> result; | 560 std::unique_ptr<base::Value> result; |
561 ASSERT_EQ( | 561 ASSERT_EQ( |
562 kOk, | 562 kOk, |
563 ExecuteFindChildElements( | 563 ExecuteFindChildElements( |
564 1, &session, &web_view, element_id, params, &result).code()); | 564 1, &session, &web_view, element_id, params, &result).code()); |
565 base::DictionaryValue locator_param; | 565 base::DictionaryValue locator_param; |
566 locator_param.SetString("class name", "c"); | 566 locator_param.SetString("class name", "c"); |
567 base::DictionaryValue root_element_param; | 567 base::DictionaryValue root_element_param; |
568 root_element_param.SetString("ELEMENT", element_id); | 568 root_element_param.SetString("ELEMENT", element_id); |
569 base::ListValue expected_args; | 569 base::ListValue expected_args; |
570 expected_args.Append(locator_param.DeepCopy()); | 570 expected_args.Append(locator_param.CreateDeepCopy()); |
571 expected_args.Append(root_element_param.DeepCopy()); | 571 expected_args.Append(root_element_param.CreateDeepCopy()); |
572 web_view.Verify("frame_id4", &expected_args, result.get()); | 572 web_view.Verify("frame_id4", &expected_args, result.get()); |
573 } | 573 } |
574 | 574 |
575 TEST(CommandsTest, FailedFindChildElements) { | 575 TEST(CommandsTest, FailedFindChildElements) { |
576 Session session("id"); | 576 Session session("id"); |
577 FindElementWebView web_view(false, kElementNotExistsQueryOnce); | 577 FindElementWebView web_view(false, kElementNotExistsQueryOnce); |
578 base::DictionaryValue params; | 578 base::DictionaryValue params; |
579 params.SetString("using", "id"); | 579 params.SetString("using", "id"); |
580 params.SetString("value", "a"); | 580 params.SetString("value", "a"); |
581 std::string element_id = "1"; | 581 std::string element_id = "1"; |
(...skipping 246 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
828 cmd, | 828 cmd, |
829 false, | 829 false, |
830 params, | 830 params, |
831 id, | 831 id, |
832 base::Bind(&OnFailBecauseErrorNotifyingListeners, &run_loop)); | 832 base::Bind(&OnFailBecauseErrorNotifyingListeners, &run_loop)); |
833 run_loop.Run(); | 833 run_loop.Run(); |
834 | 834 |
835 thread->task_runner()->PostTask(FROM_HERE, | 835 thread->task_runner()->PostTask(FROM_HERE, |
836 base::Bind(&VerifySessionWasDeleted)); | 836 base::Bind(&VerifySessionWasDeleted)); |
837 } | 837 } |
OLD | NEW |