| 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 <string> | 5 #include <string> |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/callback.h" | 8 #include "base/callback.h" |
| 9 #include "base/compiler_specific.h" | 9 #include "base/compiler_specific.h" |
| 10 #include "base/files/file_path.h" | 10 #include "base/files/file_path.h" |
| (...skipping 255 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 266 } | 266 } |
| 267 case kElementNotExistsQueryOnce: { | 267 case kElementNotExistsQueryOnce: { |
| 268 if (only_one_) | 268 if (only_one_) |
| 269 result_.reset(base::Value::CreateNullValue()); | 269 result_.reset(base::Value::CreateNullValue()); |
| 270 else | 270 else |
| 271 result_.reset(new base::ListValue()); | 271 result_.reset(new base::ListValue()); |
| 272 break; | 272 break; |
| 273 } | 273 } |
| 274 } | 274 } |
| 275 } | 275 } |
| 276 virtual ~FindElementWebView() {} | 276 ~FindElementWebView() override {} |
| 277 | 277 |
| 278 void Verify(const std::string& expected_frame, | 278 void Verify(const std::string& expected_frame, |
| 279 const base::ListValue* expected_args, | 279 const base::ListValue* expected_args, |
| 280 const base::Value* actrual_result) { | 280 const base::Value* actrual_result) { |
| 281 EXPECT_EQ(expected_frame, frame_); | 281 EXPECT_EQ(expected_frame, frame_); |
| 282 std::string function; | 282 std::string function; |
| 283 if (only_one_) | 283 if (only_one_) |
| 284 function = webdriver::atoms::asString(webdriver::atoms::FIND_ELEMENT); | 284 function = webdriver::atoms::asString(webdriver::atoms::FIND_ELEMENT); |
| 285 else | 285 else |
| 286 function = webdriver::atoms::asString(webdriver::atoms::FIND_ELEMENTS); | 286 function = webdriver::atoms::asString(webdriver::atoms::FIND_ELEMENTS); |
| 287 EXPECT_EQ(function, function_); | 287 EXPECT_EQ(function, function_); |
| 288 ASSERT_TRUE(args_.get()); | 288 ASSERT_TRUE(args_.get()); |
| 289 EXPECT_TRUE(expected_args->Equals(args_.get())); | 289 EXPECT_TRUE(expected_args->Equals(args_.get())); |
| 290 ASSERT_TRUE(actrual_result); | 290 ASSERT_TRUE(actrual_result); |
| 291 EXPECT_TRUE(result_->Equals(actrual_result)); | 291 EXPECT_TRUE(result_->Equals(actrual_result)); |
| 292 } | 292 } |
| 293 | 293 |
| 294 // Overridden from WebView: | 294 // Overridden from WebView: |
| 295 virtual Status CallFunction(const std::string& frame, | 295 Status CallFunction(const std::string& frame, |
| 296 const std::string& function, | 296 const std::string& function, |
| 297 const base::ListValue& args, | 297 const base::ListValue& args, |
| 298 scoped_ptr<base::Value>* result) override { | 298 scoped_ptr<base::Value>* result) override { |
| 299 ++current_count_; | 299 ++current_count_; |
| 300 if (scenario_ == kElementExistsTimeout || | 300 if (scenario_ == kElementExistsTimeout || |
| 301 (scenario_ == kElementExistsQueryTwice && current_count_ == 1)) { | 301 (scenario_ == kElementExistsQueryTwice && current_count_ == 1)) { |
| 302 // Always return empty result when testing timeout. | 302 // Always return empty result when testing timeout. |
| 303 if (only_one_) | 303 if (only_one_) |
| 304 result->reset(base::Value::CreateNullValue()); | 304 result->reset(base::Value::CreateNullValue()); |
| 305 else | 305 else |
| 306 result->reset(new base::ListValue()); | 306 result->reset(new base::ListValue()); |
| 307 } else { | 307 } else { |
| 308 switch (scenario_) { | 308 switch (scenario_) { |
| (...skipping 185 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 494 ASSERT_EQ(kNoSuchElement, | 494 ASSERT_EQ(kNoSuchElement, |
| 495 ExecuteFindElement(1, &session, &web_view, params, &result).code()); | 495 ExecuteFindElement(1, &session, &web_view, params, &result).code()); |
| 496 } | 496 } |
| 497 | 497 |
| 498 namespace { | 498 namespace { |
| 499 | 499 |
| 500 class ErrorCallFunctionWebView : public StubWebView { | 500 class ErrorCallFunctionWebView : public StubWebView { |
| 501 public: | 501 public: |
| 502 explicit ErrorCallFunctionWebView(StatusCode code) | 502 explicit ErrorCallFunctionWebView(StatusCode code) |
| 503 : StubWebView("1"), code_(code) {} | 503 : StubWebView("1"), code_(code) {} |
| 504 virtual ~ErrorCallFunctionWebView() {} | 504 ~ErrorCallFunctionWebView() override {} |
| 505 | 505 |
| 506 // Overridden from WebView: | 506 // Overridden from WebView: |
| 507 virtual Status CallFunction(const std::string& frame, | 507 Status CallFunction(const std::string& frame, |
| 508 const std::string& function, | 508 const std::string& function, |
| 509 const base::ListValue& args, | 509 const base::ListValue& args, |
| 510 scoped_ptr<base::Value>* result) override { | 510 scoped_ptr<base::Value>* result) override { |
| 511 return Status(code_); | 511 return Status(code_); |
| 512 } | 512 } |
| 513 | 513 |
| 514 private: | 514 private: |
| 515 StatusCode code_; | 515 StatusCode code_; |
| 516 }; | 516 }; |
| 517 | 517 |
| 518 } // namespace | 518 } // namespace |
| 519 | 519 |
| 520 TEST(CommandsTest, ErrorFindElement) { | 520 TEST(CommandsTest, ErrorFindElement) { |
| (...skipping 25 matching lines...) Expand all Loading... |
| 546 kStaleElementReference, | 546 kStaleElementReference, |
| 547 ExecuteFindChildElements( | 547 ExecuteFindChildElements( |
| 548 1, &session, &web_view, element_id, params, &result).code()); | 548 1, &session, &web_view, element_id, params, &result).code()); |
| 549 } | 549 } |
| 550 | 550 |
| 551 namespace { | 551 namespace { |
| 552 | 552 |
| 553 class MockCommandListener : public CommandListener { | 553 class MockCommandListener : public CommandListener { |
| 554 public: | 554 public: |
| 555 MockCommandListener() : called_(false) {} | 555 MockCommandListener() : called_(false) {} |
| 556 virtual ~MockCommandListener() {} | 556 ~MockCommandListener() override {} |
| 557 | 557 |
| 558 virtual Status BeforeCommand(const std::string& command_name) override { | 558 Status BeforeCommand(const std::string& command_name) override { |
| 559 called_ = true; | 559 called_ = true; |
| 560 EXPECT_STREQ("cmd", command_name.c_str()); | 560 EXPECT_STREQ("cmd", command_name.c_str()); |
| 561 return Status(kOk); | 561 return Status(kOk); |
| 562 } | 562 } |
| 563 | 563 |
| 564 void VerifyCalled() { | 564 void VerifyCalled() { |
| 565 EXPECT_TRUE(called_); | 565 EXPECT_TRUE(called_); |
| 566 } | 566 } |
| 567 | 567 |
| 568 void VerifyNotCalled() { | 568 void VerifyNotCalled() { |
| (...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 653 run_loop_testlistener.Run(); | 653 run_loop_testlistener.Run(); |
| 654 | 654 |
| 655 listener->VerifyCalled(); | 655 listener->VerifyCalled(); |
| 656 } | 656 } |
| 657 | 657 |
| 658 namespace { | 658 namespace { |
| 659 | 659 |
| 660 class FailingCommandListener : public CommandListener { | 660 class FailingCommandListener : public CommandListener { |
| 661 public: | 661 public: |
| 662 FailingCommandListener() {} | 662 FailingCommandListener() {} |
| 663 virtual ~FailingCommandListener() {} | 663 ~FailingCommandListener() override {} |
| 664 | 664 |
| 665 virtual Status BeforeCommand(const std::string& command_name) override { | 665 Status BeforeCommand(const std::string& command_name) override { |
| 666 return Status(kUnknownError); | 666 return Status(kUnknownError); |
| 667 } | 667 } |
| 668 }; | 668 }; |
| 669 | 669 |
| 670 void AddListenerToSessionIfSessionExists(CommandListener* listener) { | 670 void AddListenerToSessionIfSessionExists(CommandListener* listener) { |
| 671 Session* session = GetThreadLocalSession(); | 671 Session* session = GetThreadLocalSession(); |
| 672 if (session) { | 672 if (session) { |
| 673 session->command_listeners.push_back(listener); | 673 session->command_listeners.push_back(listener); |
| 674 } | 674 } |
| 675 } | 675 } |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 721 false, | 721 false, |
| 722 params, | 722 params, |
| 723 id, | 723 id, |
| 724 base::Bind(&OnFailBecauseErrorNotifyingListeners, &run_loop)); | 724 base::Bind(&OnFailBecauseErrorNotifyingListeners, &run_loop)); |
| 725 run_loop.Run(); | 725 run_loop.Run(); |
| 726 | 726 |
| 727 thread->message_loop()->PostTask( | 727 thread->message_loop()->PostTask( |
| 728 FROM_HERE, | 728 FROM_HERE, |
| 729 base::Bind(&VerifySessionWasDeleted)); | 729 base::Bind(&VerifySessionWasDeleted)); |
| 730 } | 730 } |
| OLD | NEW |