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

Side by Side Diff: ipc/ipc_sync_channel_unittest.cc

Issue 8718003: base::Bind: Convert Tasks in ipc_sync_channel_unittest.cc. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Remove static in unnamed namespace. Created 9 years 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) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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 1014 matching lines...) Expand 10 before | Expand all | Expand 10 after
1025 // Crashes flakily, http://crbug.com/70075. 1025 // Crashes flakily, http://crbug.com/70075.
1026 TEST_F(IPCSyncChannelTest, DISABLED_SendWithTimeoutMixedOKAndTimeout) { 1026 TEST_F(IPCSyncChannelTest, DISABLED_SendWithTimeoutMixedOKAndTimeout) {
1027 SendWithTimeoutMixedOKAndTimeout(false); 1027 SendWithTimeoutMixedOKAndTimeout(false);
1028 SendWithTimeoutMixedOKAndTimeout(true); 1028 SendWithTimeoutMixedOKAndTimeout(true);
1029 } 1029 }
1030 1030
1031 //------------------------------------------------------------------------------ 1031 //------------------------------------------------------------------------------
1032 1032
1033 namespace { 1033 namespace {
1034 1034
1035 class NestedTask : public Task { 1035 void NestedCallback(Worker* server) {
1036 public: 1036 // Sleep a bit so that we wake up after the reply has been received.
1037 explicit NestedTask(Worker* server) : server_(server) {} 1037 base::PlatformThread::Sleep(250);
1038 void Run() { 1038 server->SendAnswerToLife(true, base::kNoTimeout, true);
1039 // Sleep a bit so that we wake up after the reply has been received. 1039 }
1040 base::PlatformThread::Sleep(250);
1041 server_->SendAnswerToLife(true, base::kNoTimeout, true);
1042 }
1043 1040
1044 Worker* server_; 1041 bool timeout_occurred = false;
1045 };
1046 1042
1047 static bool timeout_occured = false; 1043 void TimeoutCallback() {
1048 1044 timeout_occurred = true;
1049 class TimeoutTask : public Task { 1045 }
1050 public:
1051 void Run() {
1052 timeout_occured = true;
1053 }
1054 };
1055 1046
1056 class DoneEventRaceServer : public Worker { 1047 class DoneEventRaceServer : public Worker {
1057 public: 1048 public:
1058 DoneEventRaceServer() 1049 DoneEventRaceServer()
1059 : Worker(Channel::MODE_SERVER, "done_event_race_server") { } 1050 : Worker(Channel::MODE_SERVER, "done_event_race_server") { }
1060 1051
1061 void Run() { 1052 void Run() {
1062 MessageLoop::current()->PostTask(FROM_HERE, new NestedTask(this)); 1053 MessageLoop::current()->PostTask(FROM_HERE,
1063 MessageLoop::current()->PostDelayedTask(FROM_HERE, new TimeoutTask(), 9000); 1054 base::Bind(&NestedCallback, this));
1055 MessageLoop::current()->PostDelayedTask(
1056 FROM_HERE, base::Bind(&TimeoutCallback), 9000);
1064 // Even though we have a timeout on the Send, it will succeed since for this 1057 // Even though we have a timeout on the Send, it will succeed since for this
1065 // bug, the reply message comes back and is deserialized, however the done 1058 // bug, the reply message comes back and is deserialized, however the done
1066 // event wasn't set. So we indirectly use the timeout task to notice if a 1059 // event wasn't set. So we indirectly use the timeout task to notice if a
1067 // timeout occurred. 1060 // timeout occurred.
1068 SendAnswerToLife(true, 10000, true); 1061 SendAnswerToLife(true, 10000, true);
1069 DCHECK(!timeout_occured); 1062 DCHECK(!timeout_occurred);
1070 Done(); 1063 Done();
1071 } 1064 }
1072 }; 1065 };
1073 1066
1074 } // namespace 1067 } // namespace
1075 1068
1076 // Tests http://b/1474092 - that if after the done_event is set but before 1069 // Tests http://b/1474092 - that if after the done_event is set but before
1077 // OnObjectSignaled is called another message is sent out, then after its 1070 // OnObjectSignaled is called another message is sent out, then after its
1078 // reply comes back OnObjectSignaled will be called for the first message. 1071 // reply comes back OnObjectSignaled will be called for the first message.
1079 TEST_F(IPCSyncChannelTest, DoneEventRace) { 1072 TEST_F(IPCSyncChannelTest, DoneEventRace) {
(...skipping 256 matching lines...) Expand 10 before | Expand all | Expand 10 after
1336 std::vector<Worker*> workers; 1329 std::vector<Worker*> workers;
1337 workers.push_back(new NonRestrictedDispatchServer); 1330 workers.push_back(new NonRestrictedDispatchServer);
1338 workers.push_back(server); 1331 workers.push_back(server);
1339 workers.push_back( 1332 workers.push_back(
1340 new RestrictedDispatchClient(&sent_ping_event, server, &success)); 1333 new RestrictedDispatchClient(&sent_ping_event, server, &success));
1341 RunTest(workers); 1334 RunTest(workers);
1342 EXPECT_EQ(3, success); 1335 EXPECT_EQ(3, success);
1343 } 1336 }
1344 1337
1345 } // namespace IPC 1338 } // 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