Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(233)

Side by Side Diff: ipc/ipc_sync_channel_unittest.cc

Issue 9960058: ipc: don't treat replies with the unblock flag set as regular messages (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: git try Created 8 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « ipc/ipc_sync_channel.cc ('k') | ipc/ipc_sync_message_unittest.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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>
(...skipping 1732 matching lines...) Expand 10 before | Expand all | Expand 10 after
1743 workers.push_back(new RestrictedDispatchPipeWorker( 1743 workers.push_back(new RestrictedDispatchPipeWorker(
1744 "channel1", &event1, "channel2", &event2, 2, NULL)); 1744 "channel1", &event1, "channel2", &event2, 2, NULL));
1745 workers.push_back(new RestrictedDispatchPipeWorker( 1745 workers.push_back(new RestrictedDispatchPipeWorker(
1746 "channel2", &event2, "channel3", &event3, 3, NULL)); 1746 "channel2", &event2, "channel3", &event3, 3, NULL));
1747 workers.push_back(new RestrictedDispatchPipeWorker( 1747 workers.push_back(new RestrictedDispatchPipeWorker(
1748 "channel3", &event3, "channel0", &event0, 4, NULL)); 1748 "channel3", &event3, "channel0", &event0, 4, NULL));
1749 RunTest(workers); 1749 RunTest(workers);
1750 EXPECT_EQ(3, success); 1750 EXPECT_EQ(3, success);
1751 } 1751 }
1752 1752
1753
1754 //-----------------------------------------------------------------------------
1755 //
1756 // This test case inspired by crbug.com/122443
1757 // We want to make sure a reply message with the unblock flag set correctly
1758 // behaves as a reply, not a regular message.
1759 // We have 3 workers. Server1 will send a message to Server2 (which will block),
1760 // during which it will dispatch a message comming from Client, at which point
1761 // it will send another message to Server2. While sending that second message it
1762 // will receive a reply from Server1 with the unblock flag.
1763
1764 namespace {
1765
1766 class ReentrantReplyServer1 : public Worker {
1767 public:
1768 ReentrantReplyServer1(WaitableEvent* server_ready)
1769 : Worker("reentrant_reply1", Channel::MODE_SERVER),
1770 server_ready_(server_ready) { }
1771
1772 void Run() {
1773 server2_channel_.reset(new SyncChannel(
1774 "reentrant_reply2", Channel::MODE_CLIENT, this,
1775 ipc_thread().message_loop_proxy(), true, shutdown_event()));
1776 server_ready_->Signal();
1777 Message* msg = new SyncChannelTestMsg_Reentrant1();
1778 server2_channel_->Send(msg);
1779 server2_channel_.reset();
1780 Done();
1781 }
1782
1783 private:
1784 bool OnMessageReceived(const Message& message) {
1785 IPC_BEGIN_MESSAGE_MAP(ReentrantReplyServer1, message)
1786 IPC_MESSAGE_HANDLER(SyncChannelTestMsg_Reentrant2, OnReentrant2)
1787 IPC_REPLY_HANDLER(OnReply)
1788 IPC_END_MESSAGE_MAP()
1789 return true;
1790 }
1791
1792 void OnReentrant2() {
1793 Message* msg = new SyncChannelTestMsg_Reentrant3();
1794 server2_channel_->Send(msg);
1795 }
1796
1797 void OnReply(const Message& message) {
1798 // If we get here, the Send() will never receive the reply (thus would
1799 // hang), so abort instead.
1800 LOG(FATAL) << "Reply message was dispatched";
1801 }
1802
1803 WaitableEvent* server_ready_;
1804 scoped_ptr<SyncChannel> server2_channel_;
1805 };
1806
1807 class ReentrantReplyServer2 : public Worker {
1808 public:
1809 ReentrantReplyServer2()
1810 : Worker("reentrant_reply2", Channel::MODE_SERVER),
1811 reply_(NULL) { }
1812
1813 private:
1814 bool OnMessageReceived(const Message& message) {
1815 IPC_BEGIN_MESSAGE_MAP(ReentrantReplyServer2, message)
1816 IPC_MESSAGE_HANDLER_DELAY_REPLY(
1817 SyncChannelTestMsg_Reentrant1, OnReentrant1)
1818 IPC_MESSAGE_HANDLER(SyncChannelTestMsg_Reentrant3, OnReentrant3)
1819 IPC_END_MESSAGE_MAP()
1820 return true;
1821 }
1822
1823 void OnReentrant1(Message* reply) {
1824 DCHECK(!reply_);
1825 reply_ = reply;
1826 }
1827
1828 void OnReentrant3() {
1829 DCHECK(reply_);
1830 Message* reply = reply_;
1831 reply_ = NULL;
1832 reply->set_unblock(true);
1833 Send(reply);
1834 Done();
1835 }
1836
1837 Message* reply_;
1838 };
1839
1840 class ReentrantReplyClient : public Worker {
1841 public:
1842 ReentrantReplyClient(WaitableEvent* server_ready)
1843 : Worker("reentrant_reply1", Channel::MODE_CLIENT),
1844 server_ready_(server_ready) { }
1845
1846 void Run() {
1847 server_ready_->Wait();
1848 Send(new SyncChannelTestMsg_Reentrant2());
1849 Done();
1850 }
1851
1852 private:
1853 WaitableEvent* server_ready_;
1854 };
1855
1856 } // namespace
1857
1858 TEST_F(IPCSyncChannelTest, ReentrantReply) {
1859 std::vector<Worker*> workers;
1860 WaitableEvent server_ready(false, false);
1861 workers.push_back(new ReentrantReplyServer2());
1862 workers.push_back(new ReentrantReplyServer1(&server_ready));
1863 workers.push_back(new ReentrantReplyClient(&server_ready));
1864 RunTest(workers);
1865 }
1866
1753 //----------------------------------------------------------------------------- 1867 //-----------------------------------------------------------------------------
1754 1868
1755 // Generate a validated channel ID using Channel::GenerateVerifiedChannelID(). 1869 // Generate a validated channel ID using Channel::GenerateVerifiedChannelID().
1756 namespace { 1870 namespace {
1757 1871
1758 class VerifiedServer : public Worker { 1872 class VerifiedServer : public Worker {
1759 public: 1873 public:
1760 VerifiedServer(base::Thread* listener_thread, 1874 VerifiedServer(base::Thread* listener_thread,
1761 const std::string& channel_name, 1875 const std::string& channel_name,
1762 const std::string& reply_text) 1876 const std::string& reply_text)
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
1835 1949
1836 } // namespace 1950 } // namespace
1837 1951
1838 // Windows needs to send an out-of-band secret to verify the client end of the 1952 // Windows needs to send an out-of-band secret to verify the client end of the
1839 // channel. Test that we still connect correctly in that case. 1953 // channel. Test that we still connect correctly in that case.
1840 TEST_F(IPCSyncChannelTest, Verified) { 1954 TEST_F(IPCSyncChannelTest, Verified) {
1841 Verified(); 1955 Verified();
1842 } 1956 }
1843 1957
1844 } // namespace IPC 1958 } // namespace IPC
OLDNEW
« no previous file with comments | « ipc/ipc_sync_channel.cc ('k') | ipc/ipc_sync_message_unittest.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698