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 #include "media/audio/async_socket_io_handler.h" | 5 #include "media/audio/async_socket_io_handler.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "testing/gtest/include/gtest/gtest.h" | 8 #include "testing/gtest/include/gtest/gtest.h" |
9 | 9 |
10 namespace { | 10 namespace { |
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
99 pair[1].Send(kAsyncSocketIoTestString, kAsyncSocketIoTestStringLength); | 99 pair[1].Send(kAsyncSocketIoTestString, kAsyncSocketIoTestStringLength); |
100 MessageLoop::current()->PostDelayedTask(FROM_HERE, MessageLoop::QuitClosure(), | 100 MessageLoop::current()->PostDelayedTask(FROM_HERE, MessageLoop::QuitClosure(), |
101 base::TimeDelta::FromMilliseconds(100)); | 101 base::TimeDelta::FromMilliseconds(100)); |
102 MessageLoop::current()->Run(); | 102 MessageLoop::current()->Run(); |
103 | 103 |
104 EXPECT_TRUE(reader.IssueRead()); | 104 EXPECT_TRUE(reader.IssueRead()); |
105 EXPECT_EQ(strcmp(reader.buffer(), kAsyncSocketIoTestString), 0); | 105 EXPECT_EQ(strcmp(reader.buffer(), kAsyncSocketIoTestString), 0); |
106 // We've now verified that the read happened synchronously, but it's not | 106 // We've now verified that the read happened synchronously, but it's not |
107 // guaranteed that the callback has been issued since the callback will be | 107 // guaranteed that the callback has been issued since the callback will be |
108 // called asynchronously even though the read may have been done. | 108 // called asynchronously even though the read may have been done. |
109 // So we call RunAllPending() to allow any event notifications or APC's on | 109 // So we call RunUntilIdle() to allow any event notifications or APC's on |
110 // Windows, to execute before checking the count of how many callbacks we've | 110 // Windows, to execute before checking the count of how many callbacks we've |
111 // received. | 111 // received. |
112 MessageLoop::current()->RunAllPending(); | 112 MessageLoop::current()->RunUntilIdle(); |
113 EXPECT_EQ(1, reader.callbacks_received()); | 113 EXPECT_EQ(1, reader.callbacks_received()); |
114 } | 114 } |
115 | 115 |
116 // Calls Read() from within a callback to test that simple read "loops" work. | 116 // Calls Read() from within a callback to test that simple read "loops" work. |
117 TEST(AsyncSocketIoHandlerTest, ReadFromCallback) { | 117 TEST(AsyncSocketIoHandlerTest, ReadFromCallback) { |
118 MessageLoopForIO loop; | 118 MessageLoopForIO loop; |
119 | 119 |
120 base::CancelableSyncSocket pair[2]; | 120 base::CancelableSyncSocket pair[2]; |
121 ASSERT_TRUE(base::CancelableSyncSocket::CreatePair(&pair[0], &pair[1])); | 121 ASSERT_TRUE(base::CancelableSyncSocket::CreatePair(&pair[0], &pair[1])); |
122 | 122 |
(...skipping 10 matching lines...) Expand all Loading... |
133 base::TimeDelta::FromMilliseconds(milliseconds)); | 133 base::TimeDelta::FromMilliseconds(milliseconds)); |
134 milliseconds += 10; | 134 milliseconds += 10; |
135 } | 135 } |
136 | 136 |
137 MessageLoop::current()->PostDelayedTask(FROM_HERE, MessageLoop::QuitClosure(), | 137 MessageLoop::current()->PostDelayedTask(FROM_HERE, MessageLoop::QuitClosure(), |
138 base::TimeDelta::FromMilliseconds(100 + milliseconds)); | 138 base::TimeDelta::FromMilliseconds(100 + milliseconds)); |
139 | 139 |
140 MessageLoop::current()->Run(); | 140 MessageLoop::current()->Run(); |
141 EXPECT_EQ(kReadOperationCount, reader.callbacks_received()); | 141 EXPECT_EQ(kReadOperationCount, reader.callbacks_received()); |
142 } | 142 } |
OLD | NEW |