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> |
(...skipping 1465 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1476 RestrictedDispatchDeadlockServer* peer_; | 1476 RestrictedDispatchDeadlockServer* peer_; |
1477 bool client_kicked_; | 1477 bool client_kicked_; |
1478 }; | 1478 }; |
1479 | 1479 |
1480 class RestrictedDispatchDeadlockClient2 : public Worker { | 1480 class RestrictedDispatchDeadlockClient2 : public Worker { |
1481 public: | 1481 public: |
1482 RestrictedDispatchDeadlockClient2(RestrictedDispatchDeadlockServer* server, | 1482 RestrictedDispatchDeadlockClient2(RestrictedDispatchDeadlockServer* server, |
1483 WaitableEvent* server_ready_event, | 1483 WaitableEvent* server_ready_event, |
1484 WaitableEvent** events) | 1484 WaitableEvent** events) |
1485 : Worker("channel2", Channel::MODE_CLIENT), | 1485 : Worker("channel2", Channel::MODE_CLIENT), |
1486 server_(server), | |
1487 server_ready_event_(server_ready_event), | 1486 server_ready_event_(server_ready_event), |
1488 events_(events), | 1487 events_(events), |
1489 received_msg_(false), | 1488 received_msg_(false), |
1490 received_noarg_reply_(false), | 1489 received_noarg_reply_(false), |
1491 done_issued_(false) {} | 1490 done_issued_(false) {} |
1492 | 1491 |
1493 void Run() { | 1492 void Run() { |
1494 server_ready_event_->Wait(); | 1493 server_ready_event_->Wait(); |
1495 } | 1494 } |
1496 | 1495 |
(...skipping 25 matching lines...) Expand all Loading... |
1522 | 1521 |
1523 void PossiblyDone() { | 1522 void PossiblyDone() { |
1524 if (received_noarg_reply_ && received_msg_) { | 1523 if (received_noarg_reply_ && received_msg_) { |
1525 DCHECK(done_issued_ == false); | 1524 DCHECK(done_issued_ == false); |
1526 done_issued_ = true; | 1525 done_issued_ = true; |
1527 Send(new SyncChannelTestMsg_Done); | 1526 Send(new SyncChannelTestMsg_Done); |
1528 Done(); | 1527 Done(); |
1529 } | 1528 } |
1530 } | 1529 } |
1531 | 1530 |
1532 RestrictedDispatchDeadlockServer* server_; | |
1533 WaitableEvent* server_ready_event_; | 1531 WaitableEvent* server_ready_event_; |
1534 WaitableEvent** events_; | 1532 WaitableEvent** events_; |
1535 bool received_msg_; | 1533 bool received_msg_; |
1536 bool received_noarg_reply_; | 1534 bool received_noarg_reply_; |
1537 bool done_issued_; | 1535 bool done_issued_; |
1538 }; | 1536 }; |
1539 | 1537 |
1540 class RestrictedDispatchDeadlockClient1 : public Worker { | 1538 class RestrictedDispatchDeadlockClient1 : public Worker { |
1541 public: | 1539 public: |
1542 RestrictedDispatchDeadlockClient1(RestrictedDispatchDeadlockServer* server, | 1540 RestrictedDispatchDeadlockClient1(RestrictedDispatchDeadlockServer* server, |
(...skipping 362 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1905 expected_text_(expected_text) { | 1903 expected_text_(expected_text) { |
1906 Worker::OverrideThread(listener_thread); | 1904 Worker::OverrideThread(listener_thread); |
1907 } | 1905 } |
1908 | 1906 |
1909 virtual void Run() { | 1907 virtual void Run() { |
1910 std::string response; | 1908 std::string response; |
1911 SyncMessage* msg = new SyncChannelNestedTestMsg_String(&response); | 1909 SyncMessage* msg = new SyncChannelNestedTestMsg_String(&response); |
1912 bool result = Send(msg); | 1910 bool result = Send(msg); |
1913 DCHECK(result); | 1911 DCHECK(result); |
1914 DCHECK_EQ(response, expected_text_); | 1912 DCHECK_EQ(response, expected_text_); |
| 1913 // expected_text_ is only used in the above DCHECK. This line suppresses the |
| 1914 // "unused private field" warning in release builds. |
| 1915 (void)expected_text_; |
1915 | 1916 |
1916 VLOG(1) << __FUNCTION__ << " Received reply: " << response; | 1917 VLOG(1) << __FUNCTION__ << " Received reply: " << response; |
1917 ASSERT_EQ(channel()->peer_pid(), base::GetCurrentProcId()); | 1918 ASSERT_EQ(channel()->peer_pid(), base::GetCurrentProcId()); |
1918 Done(); | 1919 Done(); |
1919 } | 1920 } |
1920 | 1921 |
1921 private: | 1922 private: |
1922 bool pump_during_send_; | |
1923 std::string expected_text_; | 1923 std::string expected_text_; |
1924 }; | 1924 }; |
1925 | 1925 |
1926 void Verified() { | 1926 void Verified() { |
1927 std::vector<Worker*> workers; | 1927 std::vector<Worker*> workers; |
1928 | 1928 |
1929 // A shared worker thread for servers | 1929 // A shared worker thread for servers |
1930 base::Thread server_worker_thread("Verified_ServerListener"); | 1930 base::Thread server_worker_thread("Verified_ServerListener"); |
1931 ASSERT_TRUE(server_worker_thread.Start()); | 1931 ASSERT_TRUE(server_worker_thread.Start()); |
1932 | 1932 |
(...skipping 21 matching lines...) Expand all Loading... |
1954 | 1954 |
1955 } // namespace | 1955 } // namespace |
1956 | 1956 |
1957 // Windows needs to send an out-of-band secret to verify the client end of the | 1957 // Windows needs to send an out-of-band secret to verify the client end of the |
1958 // channel. Test that we still connect correctly in that case. | 1958 // channel. Test that we still connect correctly in that case. |
1959 TEST_F(IPCSyncChannelTest, Verified) { | 1959 TEST_F(IPCSyncChannelTest, Verified) { |
1960 Verified(); | 1960 Verified(); |
1961 } | 1961 } |
1962 | 1962 |
1963 } // namespace IPC | 1963 } // namespace IPC |
OLD | NEW |