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 430 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
441 TEST(CommandsTest, SuccessfulFindElement) { | 441 TEST(CommandsTest, SuccessfulFindElement) { |
442 FindElementWebView web_view(true, kElementExistsQueryTwice); | 442 FindElementWebView web_view(true, kElementExistsQueryTwice); |
443 Session session("id"); | 443 Session session("id"); |
444 session.implicit_wait = base::TimeDelta::FromSeconds(1); | 444 session.implicit_wait = base::TimeDelta::FromSeconds(1); |
445 session.SwitchToSubFrame("frame_id1", std::string()); | 445 session.SwitchToSubFrame("frame_id1", std::string()); |
446 base::DictionaryValue params; | 446 base::DictionaryValue params; |
447 params.SetString("using", "id"); | 447 params.SetString("using", "id"); |
448 params.SetString("value", "a"); | 448 params.SetString("value", "a"); |
449 std::unique_ptr<base::Value> result; | 449 std::unique_ptr<base::Value> result; |
450 ASSERT_EQ(kOk, | 450 ASSERT_EQ(kOk, |
451 ExecuteFindElement(1, &session, &web_view, params, &result).code()); | 451 ExecuteFindElement(1, &session, &web_view, params, &result, |
| 452 nullptr).code()); |
452 base::DictionaryValue param; | 453 base::DictionaryValue param; |
453 param.SetString("id", "a"); | 454 param.SetString("id", "a"); |
454 base::ListValue expected_args; | 455 base::ListValue expected_args; |
455 expected_args.Append(param.DeepCopy()); | 456 expected_args.Append(param.DeepCopy()); |
456 web_view.Verify("frame_id1", &expected_args, result.get()); | 457 web_view.Verify("frame_id1", &expected_args, result.get()); |
457 } | 458 } |
458 | 459 |
459 TEST(CommandsTest, FailedFindElement) { | 460 TEST(CommandsTest, FailedFindElement) { |
460 FindElementWebView web_view(true, kElementNotExistsQueryOnce); | 461 FindElementWebView web_view(true, kElementNotExistsQueryOnce); |
461 Session session("id"); | 462 Session session("id"); |
462 base::DictionaryValue params; | 463 base::DictionaryValue params; |
463 params.SetString("using", "id"); | 464 params.SetString("using", "id"); |
464 params.SetString("value", "a"); | 465 params.SetString("value", "a"); |
465 std::unique_ptr<base::Value> result; | 466 std::unique_ptr<base::Value> result; |
466 ASSERT_EQ(kNoSuchElement, | 467 ASSERT_EQ(kNoSuchElement, |
467 ExecuteFindElement(1, &session, &web_view, params, &result).code()); | 468 ExecuteFindElement(1, &session, &web_view, params, &result, |
| 469 nullptr).code()); |
468 } | 470 } |
469 | 471 |
470 TEST(CommandsTest, SuccessfulFindElements) { | 472 TEST(CommandsTest, SuccessfulFindElements) { |
471 FindElementWebView web_view(false, kElementExistsQueryTwice); | 473 FindElementWebView web_view(false, kElementExistsQueryTwice); |
472 Session session("id"); | 474 Session session("id"); |
473 session.implicit_wait = base::TimeDelta::FromSeconds(1); | 475 session.implicit_wait = base::TimeDelta::FromSeconds(1); |
474 session.SwitchToSubFrame("frame_id2", std::string()); | 476 session.SwitchToSubFrame("frame_id2", std::string()); |
475 base::DictionaryValue params; | 477 base::DictionaryValue params; |
476 params.SetString("using", "name"); | 478 params.SetString("using", "name"); |
477 params.SetString("value", "b"); | 479 params.SetString("value", "b"); |
478 std::unique_ptr<base::Value> result; | 480 std::unique_ptr<base::Value> result; |
479 ASSERT_EQ( | 481 ASSERT_EQ(kOk, |
480 kOk, | 482 ExecuteFindElements(1, &session, &web_view, params, &result, |
481 ExecuteFindElements(1, &session, &web_view, params, &result).code()); | 483 nullptr).code()); |
482 base::DictionaryValue param; | 484 base::DictionaryValue param; |
483 param.SetString("name", "b"); | 485 param.SetString("name", "b"); |
484 base::ListValue expected_args; | 486 base::ListValue expected_args; |
485 expected_args.Append(param.DeepCopy()); | 487 expected_args.Append(param.DeepCopy()); |
486 web_view.Verify("frame_id2", &expected_args, result.get()); | 488 web_view.Verify("frame_id2", &expected_args, result.get()); |
487 } | 489 } |
488 | 490 |
489 TEST(CommandsTest, FailedFindElements) { | 491 TEST(CommandsTest, FailedFindElements) { |
490 Session session("id"); | 492 Session session("id"); |
491 FindElementWebView web_view(false, kElementNotExistsQueryOnce); | 493 FindElementWebView web_view(false, kElementNotExistsQueryOnce); |
492 base::DictionaryValue params; | 494 base::DictionaryValue params; |
493 params.SetString("using", "id"); | 495 params.SetString("using", "id"); |
494 params.SetString("value", "a"); | 496 params.SetString("value", "a"); |
495 std::unique_ptr<base::Value> result; | 497 std::unique_ptr<base::Value> result; |
496 ASSERT_EQ( | 498 ASSERT_EQ(kOk, |
497 kOk, | 499 ExecuteFindElements(1, &session, &web_view, params, &result, |
498 ExecuteFindElements(1, &session, &web_view, params, &result).code()); | 500 nullptr).code()); |
499 base::ListValue* list; | 501 base::ListValue* list; |
500 ASSERT_TRUE(result->GetAsList(&list)); | 502 ASSERT_TRUE(result->GetAsList(&list)); |
501 ASSERT_EQ(0U, list->GetSize()); | 503 ASSERT_EQ(0U, list->GetSize()); |
502 } | 504 } |
503 | 505 |
504 TEST(CommandsTest, SuccessfulFindChildElement) { | 506 TEST(CommandsTest, SuccessfulFindChildElement) { |
505 FindElementWebView web_view(true, kElementExistsQueryTwice); | 507 FindElementWebView web_view(true, kElementExistsQueryTwice); |
506 Session session("id"); | 508 Session session("id"); |
507 session.implicit_wait = base::TimeDelta::FromSeconds(1); | 509 session.implicit_wait = base::TimeDelta::FromSeconds(1); |
508 session.SwitchToSubFrame("frame_id3", std::string()); | 510 session.SwitchToSubFrame("frame_id3", std::string()); |
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
583 TEST(CommandsTest, TimeoutInFindElement) { | 585 TEST(CommandsTest, TimeoutInFindElement) { |
584 Session session("id"); | 586 Session session("id"); |
585 FindElementWebView web_view(true, kElementExistsTimeout); | 587 FindElementWebView web_view(true, kElementExistsTimeout); |
586 session.implicit_wait = base::TimeDelta::FromMilliseconds(2); | 588 session.implicit_wait = base::TimeDelta::FromMilliseconds(2); |
587 base::DictionaryValue params; | 589 base::DictionaryValue params; |
588 params.SetString("using", "id"); | 590 params.SetString("using", "id"); |
589 params.SetString("value", "a"); | 591 params.SetString("value", "a"); |
590 params.SetString("id", "1"); | 592 params.SetString("id", "1"); |
591 std::unique_ptr<base::Value> result; | 593 std::unique_ptr<base::Value> result; |
592 ASSERT_EQ(kNoSuchElement, | 594 ASSERT_EQ(kNoSuchElement, |
593 ExecuteFindElement(1, &session, &web_view, params, &result).code()); | 595 ExecuteFindElement(1, &session, &web_view, params, &result, |
| 596 nullptr).code()); |
594 } | 597 } |
595 | 598 |
596 namespace { | 599 namespace { |
597 | 600 |
598 class ErrorCallFunctionWebView : public StubWebView { | 601 class ErrorCallFunctionWebView : public StubWebView { |
599 public: | 602 public: |
600 explicit ErrorCallFunctionWebView(StatusCode code) | 603 explicit ErrorCallFunctionWebView(StatusCode code) |
601 : StubWebView("1"), code_(code) {} | 604 : StubWebView("1"), code_(code) {} |
602 ~ErrorCallFunctionWebView() override {} | 605 ~ErrorCallFunctionWebView() override {} |
603 | 606 |
(...skipping 12 matching lines...) Expand all Loading... |
616 } // namespace | 619 } // namespace |
617 | 620 |
618 TEST(CommandsTest, ErrorFindElement) { | 621 TEST(CommandsTest, ErrorFindElement) { |
619 Session session("id"); | 622 Session session("id"); |
620 ErrorCallFunctionWebView web_view(kUnknownError); | 623 ErrorCallFunctionWebView web_view(kUnknownError); |
621 base::DictionaryValue params; | 624 base::DictionaryValue params; |
622 params.SetString("using", "id"); | 625 params.SetString("using", "id"); |
623 params.SetString("value", "a"); | 626 params.SetString("value", "a"); |
624 std::unique_ptr<base::Value> value; | 627 std::unique_ptr<base::Value> value; |
625 ASSERT_EQ(kUnknownError, | 628 ASSERT_EQ(kUnknownError, |
626 ExecuteFindElement(1, &session, &web_view, params, &value).code()); | 629 ExecuteFindElement(1, &session, &web_view, params, &value, |
| 630 nullptr).code()); |
627 ASSERT_EQ(kUnknownError, | 631 ASSERT_EQ(kUnknownError, |
628 ExecuteFindElements(1, &session, &web_view, params, &value).code()); | 632 ExecuteFindElements(1, &session, &web_view, params, &value, |
| 633 nullptr).code()); |
629 } | 634 } |
630 | 635 |
631 TEST(CommandsTest, ErrorFindChildElement) { | 636 TEST(CommandsTest, ErrorFindChildElement) { |
632 Session session("id"); | 637 Session session("id"); |
633 ErrorCallFunctionWebView web_view(kStaleElementReference); | 638 ErrorCallFunctionWebView web_view(kStaleElementReference); |
634 base::DictionaryValue params; | 639 base::DictionaryValue params; |
635 params.SetString("using", "id"); | 640 params.SetString("using", "id"); |
636 params.SetString("value", "a"); | 641 params.SetString("value", "a"); |
637 std::string element_id = "1"; | 642 std::string element_id = "1"; |
638 std::unique_ptr<base::Value> result; | 643 std::unique_ptr<base::Value> result; |
(...skipping 175 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
814 cmd, | 819 cmd, |
815 false, | 820 false, |
816 params, | 821 params, |
817 id, | 822 id, |
818 base::Bind(&OnFailBecauseErrorNotifyingListeners, &run_loop)); | 823 base::Bind(&OnFailBecauseErrorNotifyingListeners, &run_loop)); |
819 run_loop.Run(); | 824 run_loop.Run(); |
820 | 825 |
821 thread->task_runner()->PostTask(FROM_HERE, | 826 thread->task_runner()->PostTask(FROM_HERE, |
822 base::Bind(&VerifySessionWasDeleted)); | 827 base::Bind(&VerifySessionWasDeleted)); |
823 } | 828 } |
OLD | NEW |