| 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" |
| 11 #include "base/location.h" |
| 11 #include "base/memory/scoped_ptr.h" | 12 #include "base/memory/scoped_ptr.h" |
| 12 #include "base/message_loop/message_loop.h" | |
| 13 #include "base/run_loop.h" | 13 #include "base/run_loop.h" |
| 14 #include "base/single_thread_task_runner.h" |
| 14 #include "base/synchronization/lock.h" | 15 #include "base/synchronization/lock.h" |
| 15 #include "base/threading/thread.h" | 16 #include "base/threading/thread.h" |
| 16 #include "base/values.h" | 17 #include "base/values.h" |
| 17 #include "chrome/test/chromedriver/chrome/status.h" | 18 #include "chrome/test/chromedriver/chrome/status.h" |
| 18 #include "chrome/test/chromedriver/chrome/stub_chrome.h" | 19 #include "chrome/test/chromedriver/chrome/stub_chrome.h" |
| 19 #include "chrome/test/chromedriver/chrome/stub_web_view.h" | 20 #include "chrome/test/chromedriver/chrome/stub_web_view.h" |
| 20 #include "chrome/test/chromedriver/chrome/web_view.h" | 21 #include "chrome/test/chromedriver/chrome/web_view.h" |
| 21 #include "chrome/test/chromedriver/command_listener_proxy.h" | 22 #include "chrome/test/chromedriver/command_listener_proxy.h" |
| 22 #include "chrome/test/chromedriver/commands.h" | 23 #include "chrome/test/chromedriver/commands.h" |
| 23 #include "chrome/test/chromedriver/element_commands.h" | 24 #include "chrome/test/chromedriver/element_commands.h" |
| (...skipping 187 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 211 run_loop->Quit(); | 212 run_loop->Quit(); |
| 212 } | 213 } |
| 213 | 214 |
| 214 } // namespace | 215 } // namespace |
| 215 | 216 |
| 216 TEST(CommandsTest, ExecuteSessionCommand) { | 217 TEST(CommandsTest, ExecuteSessionCommand) { |
| 217 SessionThreadMap map; | 218 SessionThreadMap map; |
| 218 linked_ptr<base::Thread> thread(new base::Thread("1")); | 219 linked_ptr<base::Thread> thread(new base::Thread("1")); |
| 219 ASSERT_TRUE(thread->Start()); | 220 ASSERT_TRUE(thread->Start()); |
| 220 std::string id("id"); | 221 std::string id("id"); |
| 221 thread->message_loop()->PostTask( | 222 thread->task_runner()->PostTask( |
| 222 FROM_HERE, | 223 FROM_HERE, |
| 223 base::Bind(&internal::CreateSessionOnSessionThreadForTesting, id)); | 224 base::Bind(&internal::CreateSessionOnSessionThreadForTesting, id)); |
| 224 map[id] = thread; | 225 map[id] = thread; |
| 225 | 226 |
| 226 base::DictionaryValue params; | 227 base::DictionaryValue params; |
| 227 params.SetInteger("param", 5); | 228 params.SetInteger("param", 5); |
| 228 base::FundamentalValue expected_value(6); | 229 base::FundamentalValue expected_value(6); |
| 229 SessionCommand cmd = base::Bind( | 230 SessionCommand cmd = base::Bind( |
| 230 &ExecuteSimpleCommand, id, ¶ms, &expected_value); | 231 &ExecuteSimpleCommand, id, ¶ms, &expected_value); |
| 231 | 232 |
| (...skipping 461 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 693 run_loop->Quit(); | 694 run_loop->Quit(); |
| 694 } | 695 } |
| 695 | 696 |
| 696 } // namespace | 697 } // namespace |
| 697 | 698 |
| 698 TEST(CommandsTest, SuccessNotifyingCommandListeners) { | 699 TEST(CommandsTest, SuccessNotifyingCommandListeners) { |
| 699 SessionThreadMap map; | 700 SessionThreadMap map; |
| 700 linked_ptr<base::Thread> thread(new base::Thread("1")); | 701 linked_ptr<base::Thread> thread(new base::Thread("1")); |
| 701 ASSERT_TRUE(thread->Start()); | 702 ASSERT_TRUE(thread->Start()); |
| 702 std::string id("id"); | 703 std::string id("id"); |
| 703 thread->message_loop()->PostTask( | 704 thread->task_runner()->PostTask( |
| 704 FROM_HERE, | 705 FROM_HERE, |
| 705 base::Bind(&internal::CreateSessionOnSessionThreadForTesting, id)); | 706 base::Bind(&internal::CreateSessionOnSessionThreadForTesting, id)); |
| 706 | 707 |
| 707 map[id] = thread; | 708 map[id] = thread; |
| 708 | 709 |
| 709 base::DictionaryValue params; | 710 base::DictionaryValue params; |
| 710 scoped_ptr<MockCommandListener> listener(new MockCommandListener()); | 711 scoped_ptr<MockCommandListener> listener(new MockCommandListener()); |
| 711 CommandListenerProxy* proxy = new CommandListenerProxy(listener.get()); | 712 CommandListenerProxy* proxy = new CommandListenerProxy(listener.get()); |
| 712 // We add |proxy| to the session instead of adding |listener| directly so that | 713 // We add |proxy| to the session instead of adding |listener| directly so that |
| 713 // after the session is destroyed by ExecuteQuitSessionCommand, we can still | 714 // after the session is destroyed by ExecuteQuitSessionCommand, we can still |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 782 ASSERT_FALSE(GetThreadLocalSession()); | 783 ASSERT_FALSE(GetThreadLocalSession()); |
| 783 } | 784 } |
| 784 | 785 |
| 785 } // namespace | 786 } // namespace |
| 786 | 787 |
| 787 TEST(CommandsTest, ErrorNotifyingCommandListeners) { | 788 TEST(CommandsTest, ErrorNotifyingCommandListeners) { |
| 788 SessionThreadMap map; | 789 SessionThreadMap map; |
| 789 linked_ptr<base::Thread> thread(new base::Thread("1")); | 790 linked_ptr<base::Thread> thread(new base::Thread("1")); |
| 790 ASSERT_TRUE(thread->Start()); | 791 ASSERT_TRUE(thread->Start()); |
| 791 std::string id("id"); | 792 std::string id("id"); |
| 792 thread->message_loop()->PostTask( | 793 thread->task_runner()->PostTask( |
| 793 FROM_HERE, | 794 FROM_HERE, |
| 794 base::Bind(&internal::CreateSessionOnSessionThreadForTesting, id)); | 795 base::Bind(&internal::CreateSessionOnSessionThreadForTesting, id)); |
| 795 map[id] = thread; | 796 map[id] = thread; |
| 796 | 797 |
| 797 // In SuccessNotifyingCommandListenersBeforeCommand, we verified BeforeCommand | 798 // In SuccessNotifyingCommandListenersBeforeCommand, we verified BeforeCommand |
| 798 // was called before (as opposed to after) command execution. We don't need to | 799 // was called before (as opposed to after) command execution. We don't need to |
| 799 // verify this again, so we can just add |listener| with PostTask. | 800 // verify this again, so we can just add |listener| with PostTask. |
| 800 CommandListener* listener = new FailingCommandListener(); | 801 CommandListener* listener = new FailingCommandListener(); |
| 801 thread->message_loop()->PostTask( | 802 thread->task_runner()->PostTask( |
| 802 FROM_HERE, | 803 FROM_HERE, base::Bind(&AddListenerToSessionIfSessionExists, listener)); |
| 803 base::Bind(&AddListenerToSessionIfSessionExists, listener)); | |
| 804 | 804 |
| 805 base::DictionaryValue params; | 805 base::DictionaryValue params; |
| 806 // The command should never be executed if BeforeCommand fails for a listener. | 806 // The command should never be executed if BeforeCommand fails for a listener. |
| 807 SessionCommand cmd = base::Bind(&ShouldNotBeCalled); | 807 SessionCommand cmd = base::Bind(&ShouldNotBeCalled); |
| 808 base::MessageLoop loop; | 808 base::MessageLoop loop; |
| 809 base::RunLoop run_loop; | 809 base::RunLoop run_loop; |
| 810 | 810 |
| 811 ExecuteSessionCommand( | 811 ExecuteSessionCommand( |
| 812 &map, | 812 &map, |
| 813 "cmd", | 813 "cmd", |
| 814 cmd, | 814 cmd, |
| 815 false, | 815 false, |
| 816 params, | 816 params, |
| 817 id, | 817 id, |
| 818 base::Bind(&OnFailBecauseErrorNotifyingListeners, &run_loop)); | 818 base::Bind(&OnFailBecauseErrorNotifyingListeners, &run_loop)); |
| 819 run_loop.Run(); | 819 run_loop.Run(); |
| 820 | 820 |
| 821 thread->message_loop()->PostTask( | 821 thread->task_runner()->PostTask(FROM_HERE, |
| 822 FROM_HERE, | 822 base::Bind(&VerifySessionWasDeleted)); |
| 823 base::Bind(&VerifySessionWasDeleted)); | |
| 824 } | 823 } |
| OLD | NEW |