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

Side by Side Diff: ipc/ipc_sync_channel_unittest.cc

Issue 10914161: Fix ownership of the helper thread in IPCSyncChannelTest.SyncMessageFilter (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 3 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 | « no previous file | no next file » | 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 1068 matching lines...) Expand 10 before | Expand all | Expand 10 after
1079 workers.push_back(new SimpleClient()); 1079 workers.push_back(new SimpleClient());
1080 RunTest(workers); 1080 RunTest(workers);
1081 } 1081 }
1082 1082
1083 //----------------------------------------------------------------------------- 1083 //-----------------------------------------------------------------------------
1084 1084
1085 namespace { 1085 namespace {
1086 1086
1087 class TestSyncMessageFilter : public SyncMessageFilter { 1087 class TestSyncMessageFilter : public SyncMessageFilter {
1088 public: 1088 public:
1089 TestSyncMessageFilter(base::WaitableEvent* shutdown_event, Worker* worker) 1089 TestSyncMessageFilter(base::WaitableEvent* shutdown_event,
1090 Worker* worker,
1091 scoped_refptr<base::MessageLoopProxy> message_loop)
1090 : SyncMessageFilter(shutdown_event), 1092 : SyncMessageFilter(shutdown_event),
1091 worker_(worker), 1093 worker_(worker),
1092 thread_("helper_thread") { 1094 message_loop_(message_loop) {
1093 base::Thread::Options options;
1094 options.message_loop_type = MessageLoop::TYPE_DEFAULT;
1095 thread_.StartWithOptions(options);
1096 } 1095 }
1097 1096
1098 virtual void OnFilterAdded(Channel* channel) { 1097 virtual void OnFilterAdded(Channel* channel) {
1099 SyncMessageFilter::OnFilterAdded(channel); 1098 SyncMessageFilter::OnFilterAdded(channel);
1100 thread_.message_loop()->PostTask( 1099 message_loop_->PostTask(
1101 FROM_HERE, 1100 FROM_HERE,
1102 base::Bind(&TestSyncMessageFilter::SendMessageOnHelperThread, this)); 1101 base::Bind(&TestSyncMessageFilter::SendMessageOnHelperThread, this));
1103 } 1102 }
1104 1103
1105 void SendMessageOnHelperThread() { 1104 void SendMessageOnHelperThread() {
1106 int answer = 0; 1105 int answer = 0;
1107 bool result = Send(new SyncChannelTestMsg_AnswerToLife(&answer)); 1106 bool result = Send(new SyncChannelTestMsg_AnswerToLife(&answer));
1108 DCHECK(result); 1107 DCHECK(result);
1109 DCHECK_EQ(answer, 42); 1108 DCHECK_EQ(answer, 42);
1110 1109
1111 worker_->Done(); 1110 worker_->Done();
1112 } 1111 }
1113 1112
1114 private: 1113 private:
1115 virtual ~TestSyncMessageFilter() {} 1114 virtual ~TestSyncMessageFilter() {}
1116 1115
1117 Worker* worker_; 1116 Worker* worker_;
1118 base::Thread thread_; 1117 scoped_refptr<base::MessageLoopProxy> message_loop_;
1119 }; 1118 };
1120 1119
1121 class SyncMessageFilterServer : public Worker { 1120 class SyncMessageFilterServer : public Worker {
1122 public: 1121 public:
1123 SyncMessageFilterServer() 1122 SyncMessageFilterServer()
1124 : Worker(Channel::MODE_SERVER, "sync_message_filter_server") { 1123 : Worker(Channel::MODE_SERVER, "sync_message_filter_server"),
1125 filter_ = new TestSyncMessageFilter(shutdown_event(), this); 1124 thread_("helper_thread") {
1125 base::Thread::Options options;
1126 options.message_loop_type = MessageLoop::TYPE_DEFAULT;
1127 thread_.StartWithOptions(options);
1128 filter_ = new TestSyncMessageFilter(shutdown_event(), this,
1129 thread_.message_loop_proxy());
1126 } 1130 }
1127 1131
1128 void Run() { 1132 void Run() {
1129 channel()->AddFilter(filter_.get()); 1133 channel()->AddFilter(filter_.get());
1130 } 1134 }
1131 1135
1136 base::Thread thread_;
1132 scoped_refptr<TestSyncMessageFilter> filter_; 1137 scoped_refptr<TestSyncMessageFilter> filter_;
1133 }; 1138 };
1134 1139
1135 // This class provides functionality to test the case that a Send on the sync 1140 // This class provides functionality to test the case that a Send on the sync
1136 // channel does not crash after the channel has been closed. 1141 // channel does not crash after the channel has been closed.
1137 class ServerSendAfterClose : public Worker { 1142 class ServerSendAfterClose : public Worker {
1138 public: 1143 public:
1139 ServerSendAfterClose() 1144 ServerSendAfterClose()
1140 : Worker(Channel::MODE_SERVER, "simpler_server"), 1145 : Worker(Channel::MODE_SERVER, "simpler_server"),
1141 send_result_(true) { 1146 send_result_(true) {
(...skipping 809 matching lines...) Expand 10 before | Expand all | Expand 10 after
1951 1956
1952 } // namespace 1957 } // namespace
1953 1958
1954 // Windows needs to send an out-of-band secret to verify the client end of the 1959 // Windows needs to send an out-of-band secret to verify the client end of the
1955 // channel. Test that we still connect correctly in that case. 1960 // channel. Test that we still connect correctly in that case.
1956 TEST_F(IPCSyncChannelTest, Verified) { 1961 TEST_F(IPCSyncChannelTest, Verified) {
1957 Verified(); 1962 Verified();
1958 } 1963 }
1959 1964
1960 } // namespace IPC 1965 } // namespace IPC
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698