| 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 // Unit test for SyncChannel. | 5 // Unit test for SyncChannel. |
| 6 | 6 |
| 7 #include "ipc/ipc_sync_channel.h" | 7 #include "ipc/ipc_sync_channel.h" |
| 8 | 8 |
| 9 #include <string> | 9 #include <string> |
| 10 #include <vector> | 10 #include <vector> |
| 11 | 11 |
| 12 #include "base/basictypes.h" | 12 #include "base/basictypes.h" |
| 13 #include "base/bind.h" | 13 #include "base/bind.h" |
| 14 #include "base/logging.h" | 14 #include "base/logging.h" |
| 15 #include "base/memory/scoped_ptr.h" | 15 #include "base/memory/scoped_ptr.h" |
| 16 #include "base/message_loop.h" | 16 #include "base/message_loop.h" |
| 17 #include "base/process_util.h" |
| 17 #include "base/stl_util.h" | 18 #include "base/stl_util.h" |
| 18 #include "base/string_util.h" | 19 #include "base/string_util.h" |
| 19 #include "base/third_party/dynamic_annotations/dynamic_annotations.h" | 20 #include "base/third_party/dynamic_annotations/dynamic_annotations.h" |
| 20 #include "base/threading/platform_thread.h" | 21 #include "base/threading/platform_thread.h" |
| 21 #include "base/threading/thread.h" | 22 #include "base/threading/thread.h" |
| 22 #include "base/synchronization/waitable_event.h" | 23 #include "base/synchronization/waitable_event.h" |
| 23 #include "ipc/ipc_message.h" | 24 #include "ipc/ipc_message.h" |
| 24 #include "ipc/ipc_sync_message_filter.h" | 25 #include "ipc/ipc_sync_message_filter.h" |
| 25 #include "ipc/ipc_sync_message_unittest.h" | 26 #include "ipc/ipc_sync_message_unittest.h" |
| 26 #include "testing/gtest/include/gtest/gtest.h" | 27 #include "testing/gtest/include/gtest/gtest.h" |
| (...skipping 1734 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1761 const std::string& reply_text) | 1762 const std::string& reply_text) |
| 1762 : Worker(channel_name, Channel::MODE_SERVER), | 1763 : Worker(channel_name, Channel::MODE_SERVER), |
| 1763 reply_text_(reply_text) { | 1764 reply_text_(reply_text) { |
| 1764 Worker::OverrideThread(listener_thread); | 1765 Worker::OverrideThread(listener_thread); |
| 1765 } | 1766 } |
| 1766 | 1767 |
| 1767 virtual void OnNestedTestMsg(Message* reply_msg) { | 1768 virtual void OnNestedTestMsg(Message* reply_msg) { |
| 1768 VLOG(1) << __FUNCTION__ << " Sending reply: " << reply_text_; | 1769 VLOG(1) << __FUNCTION__ << " Sending reply: " << reply_text_; |
| 1769 SyncChannelNestedTestMsg_String::WriteReplyParams(reply_msg, reply_text_); | 1770 SyncChannelNestedTestMsg_String::WriteReplyParams(reply_msg, reply_text_); |
| 1770 Send(reply_msg); | 1771 Send(reply_msg); |
| 1772 ASSERT_EQ(channel()->peer_pid(), base::GetCurrentProcId()); |
| 1771 Done(); | 1773 Done(); |
| 1772 } | 1774 } |
| 1773 | 1775 |
| 1774 private: | 1776 private: |
| 1775 std::string reply_text_; | 1777 std::string reply_text_; |
| 1776 }; | 1778 }; |
| 1777 | 1779 |
| 1778 class VerifiedClient : public Worker { | 1780 class VerifiedClient : public Worker { |
| 1779 public: | 1781 public: |
| 1780 VerifiedClient(base::Thread* listener_thread, | 1782 VerifiedClient(base::Thread* listener_thread, |
| 1781 const std::string& channel_name, | 1783 const std::string& channel_name, |
| 1782 const std::string& expected_text) | 1784 const std::string& expected_text) |
| 1783 : Worker(channel_name, Channel::MODE_CLIENT), | 1785 : Worker(channel_name, Channel::MODE_CLIENT), |
| 1784 expected_text_(expected_text) { | 1786 expected_text_(expected_text) { |
| 1785 Worker::OverrideThread(listener_thread); | 1787 Worker::OverrideThread(listener_thread); |
| 1786 } | 1788 } |
| 1787 | 1789 |
| 1788 virtual void Run() { | 1790 virtual void Run() { |
| 1789 std::string response; | 1791 std::string response; |
| 1790 SyncMessage* msg = new SyncChannelNestedTestMsg_String(&response); | 1792 SyncMessage* msg = new SyncChannelNestedTestMsg_String(&response); |
| 1791 bool result = Send(msg); | 1793 bool result = Send(msg); |
| 1792 DCHECK(result); | 1794 DCHECK(result); |
| 1793 DCHECK_EQ(response, expected_text_); | 1795 DCHECK_EQ(response, expected_text_); |
| 1794 | 1796 |
| 1795 VLOG(1) << __FUNCTION__ << " Received reply: " << response; | 1797 VLOG(1) << __FUNCTION__ << " Received reply: " << response; |
| 1798 ASSERT_EQ(channel()->peer_pid(), base::GetCurrentProcId()); |
| 1796 Done(); | 1799 Done(); |
| 1797 } | 1800 } |
| 1798 | 1801 |
| 1799 private: | 1802 private: |
| 1800 bool pump_during_send_; | 1803 bool pump_during_send_; |
| 1801 std::string expected_text_; | 1804 std::string expected_text_; |
| 1802 }; | 1805 }; |
| 1803 | 1806 |
| 1804 void Verified() { | 1807 void Verified() { |
| 1805 std::vector<Worker*> workers; | 1808 std::vector<Worker*> workers; |
| (...skipping 26 matching lines...) Expand all Loading... |
| 1832 | 1835 |
| 1833 } // namespace | 1836 } // namespace |
| 1834 | 1837 |
| 1835 // Windows needs to send an out-of-band secret to verify the client end of the | 1838 // Windows needs to send an out-of-band secret to verify the client end of the |
| 1836 // channel. Test that we still connect correctly in that case. | 1839 // channel. Test that we still connect correctly in that case. |
| 1837 TEST_F(IPCSyncChannelTest, Verified) { | 1840 TEST_F(IPCSyncChannelTest, Verified) { |
| 1838 Verified(); | 1841 Verified(); |
| 1839 } | 1842 } |
| 1840 | 1843 |
| 1841 } // namespace IPC | 1844 } // namespace IPC |
| OLD | NEW |