Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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. |
|
yhirano
2015/06/17 04:13:34
[optional] How about naming this class as *TestUti
hiroshige
2015/06/17 08:30:23
Done.
| |
| 4 | 4 |
| 5 #include "config.h" | 5 #include "modules/fetch/DataConsumerHandleUtil.h" |
| 6 #include "modules/fetch/CompositeDataConsumerHandle.h" | 6 #include "modules/fetch/FetchDataConsumerHandle.h" |
| 7 | |
| 8 #include "platform/Task.h" | 7 #include "platform/Task.h" |
| 9 #include "platform/ThreadSafeFunctional.h" | 8 #include "platform/ThreadSafeFunctional.h" |
| 10 #include "platform/heap/Handle.h" | 9 #include "platform/heap/Handle.h" |
| 11 #include "public/platform/Platform.h" | 10 #include "public/platform/Platform.h" |
| 11 #include "public/platform/WebDataConsumerHandle.h" | |
| 12 #include "public/platform/WebThread.h" | 12 #include "public/platform/WebThread.h" |
| 13 #include "public/platform/WebTraceLocation.h" | 13 #include "public/platform/WebTraceLocation.h" |
| 14 #include "public/platform/WebWaitableEvent.h" | 14 #include "public/platform/WebWaitableEvent.h" |
| 15 #include "wtf/Locker.h" | 15 #include "wtf/Locker.h" |
| 16 | 16 |
| 17 #include <gmock/gmock.h> | 17 #include <gmock/gmock.h> |
| 18 #include <gtest/gtest.h> | 18 #include <gtest/gtest.h> |
| 19 | 19 |
| 20 namespace blink { | 20 namespace blink { |
| 21 | 21 |
| 22 namespace { | |
| 23 | |
| 24 using Result = WebDataConsumerHandle::Result; | 22 using Result = WebDataConsumerHandle::Result; |
|
yhirano
2015/06/17 04:13:34
I don't like placing many (blink:: global) using d
hiroshige
2015/06/17 08:30:23
Done.
| |
| 25 using Flags = WebDataConsumerHandle::Flags; | 23 using Flags = WebDataConsumerHandle::Flags; |
| 26 using ::testing::InSequence; | 24 using ::testing::InSequence; |
| 27 using ::testing::Return; | 25 using ::testing::Return; |
| 28 using ::testing::StrictMock; | 26 using ::testing::StrictMock; |
| 29 using Checkpoint = StrictMock<::testing::MockFunction<void(int)>>; | 27 using Checkpoint = StrictMock<::testing::MockFunction<void(int)>>; |
| 30 | 28 |
| 31 const Result kShouldWait = WebDataConsumerHandle::ShouldWait; | 29 const Result kShouldWait = WebDataConsumerHandle::ShouldWait; |
|
yhirano
2015/06/17 04:13:34
ditto
hiroshige
2015/06/17 08:30:23
Done.
| |
| 32 const Result kDone = WebDataConsumerHandle::Done; | 30 const Result kDone = WebDataConsumerHandle::Done; |
| 33 const Result kOk = WebDataConsumerHandle::Ok; | 31 const Result kOk = WebDataConsumerHandle::Ok; |
| 34 const Result kUnexpectedError = WebDataConsumerHandle::UnexpectedError; | 32 const Result kUnexpectedError = WebDataConsumerHandle::UnexpectedError; |
| 35 const Flags kNone = WebDataConsumerHandle::FlagNone; | 33 const Flags kNone = WebDataConsumerHandle::FlagNone; |
| 36 | 34 |
| 37 class NoopClient final : public WebDataConsumerHandle::Client { | 35 class NoopClient final : public WebDataConsumerHandle::Client { |
|
yhirano
2015/06/17 04:13:34
I generally like short names in unnamed namespaces
hiroshige
2015/06/17 08:30:23
Moved back some classes to CompositeDataConsumerHa
| |
| 38 public: | 36 public: |
| 39 void didGetReadable() override { } | 37 void didGetReadable() override { } |
| 40 }; | 38 }; |
| 41 | 39 |
| 42 class MockReader : public WebDataConsumerHandle::Reader { | 40 class MockReader : public WebDataConsumerHandle::Reader { |
| 43 public: | 41 public: |
| 44 static PassOwnPtr<StrictMock<MockReader>> create() { return adoptPtr(new Str ictMock<MockReader>); } | 42 static PassOwnPtr<StrictMock<MockReader>> create() { return adoptPtr(new Str ictMock<MockReader>); } |
| 45 | 43 |
| 46 MOCK_METHOD4(read, Result(void*, size_t, Flags, size_t*)); | 44 MOCK_METHOD4(read, Result(void*, size_t, Flags, size_t*)); |
| 47 MOCK_METHOD3(beginRead, Result(const void**, Flags, size_t*)); | 45 MOCK_METHOD3(beginRead, Result(const void**, Flags, size_t*)); |
| (...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 126 }; | 124 }; |
| 127 | 125 |
| 128 void resetReader() { m_reader = nullptr; } | 126 void resetReader() { m_reader = nullptr; } |
| 129 void signalDone() { m_waitableEvent->signal(); } | 127 void signalDone() { m_waitableEvent->signal(); } |
| 130 const String& result() { return m_context->result(); } | 128 const String& result() { return m_context->result(); } |
| 131 WebThread* readingThread() { return m_context->readingThread(); } | 129 WebThread* readingThread() { return m_context->readingThread(); } |
| 132 WebThread* updatingThread() { return m_context->updatingThread(); } | 130 WebThread* updatingThread() { return m_context->updatingThread(); } |
| 133 | 131 |
| 134 protected: | 132 protected: |
| 135 RefPtr<Context> m_context; | 133 RefPtr<Context> m_context; |
| 136 OwnPtr<CompositeDataConsumerHandle> m_handle; | |
| 137 OwnPtr<WebDataConsumerHandle::Reader> m_reader; | 134 OwnPtr<WebDataConsumerHandle::Reader> m_reader; |
| 138 OwnPtr<WebWaitableEvent> m_waitableEvent; | 135 OwnPtr<WebWaitableEvent> m_waitableEvent; |
| 139 NoopClient m_client; | 136 NoopClient m_client; |
| 140 }; | 137 }; |
| 141 | 138 |
| 142 class ThreadingRegistrationTest : public ThreadingTestBase { | 139 class ThreadingHandleNotificationTest : public ThreadingTestBase, public WebData ConsumerHandle::Client { |
| 143 public: | 140 public: |
| 144 using Self = ThreadingRegistrationTest; | 141 using Self = ThreadingHandleNotificationTest; |
| 145 void run() | 142 void run(PassOwnPtr<WebDataConsumerHandle> handle) |
| 146 { | 143 { |
| 147 m_context = Context::create(); | 144 m_context = Context::create(); |
| 148 m_waitableEvent = adoptPtr(Platform::current()->createWaitableEvent()); | 145 m_waitableEvent = adoptPtr(Platform::current()->createWaitableEvent()); |
| 149 m_handle = CompositeDataConsumerHandle::create(adoptPtr(new DataConsumer Handle("handle1", m_context))); | 146 m_handle = handle; |
| 150 | 147 |
| 151 readingThread()->postTask(FROM_HERE, new Task(threadSafeBind(&Self::obta inReader, this))); | 148 readingThread()->postTask(FROM_HERE, new Task(threadSafeBind(&Self::obta inReader, this))); |
| 152 | 149 |
| 153 m_waitableEvent->wait(); | |
| 154 } | |
| 155 | |
| 156 private: | |
| 157 void obtainReader() | |
| 158 { | |
| 159 m_reader = m_handle->obtainReader(&m_client); | |
| 160 updatingThread()->postTask(FROM_HERE, new Task(threadSafeBind(&Self::upd ate, this))); | |
| 161 } | |
| 162 void update() | |
| 163 { | |
| 164 m_handle->update(adoptPtr(new DataConsumerHandle("handle2", m_context))) ; | |
| 165 readingThread()->postTask(FROM_HERE, new Task(threadSafeBind(&Self::rese tReader, this))); | |
| 166 readingThread()->postTask(FROM_HERE, new Task(threadSafeBind(&Self::sign alDone, this))); | |
| 167 } | |
| 168 }; | |
| 169 | |
| 170 class ThreadingRegistrationDeleteHandleTest : public ThreadingTestBase { | |
| 171 public: | |
| 172 using Self = ThreadingRegistrationDeleteHandleTest; | |
| 173 void run() | |
| 174 { | |
| 175 m_context = Context::create(); | |
| 176 m_waitableEvent = adoptPtr(Platform::current()->createWaitableEvent()); | |
| 177 m_handle = CompositeDataConsumerHandle::create(adoptPtr(new DataConsumer Handle("handle1", m_context))); | |
| 178 | |
| 179 readingThread()->postTask(FROM_HERE, new Task(threadSafeBind(&Self::obta inReader, this))); | |
| 180 | |
| 181 m_waitableEvent->wait(); | |
| 182 } | |
| 183 | |
| 184 private: | |
| 185 void obtainReader() | |
| 186 { | |
| 187 m_reader = m_handle->obtainReader(&m_client); | |
| 188 updatingThread()->postTask(FROM_HERE, new Task(threadSafeBind(&Self::upd ate, this))); | |
| 189 } | |
| 190 void update() | |
| 191 { | |
| 192 m_handle->update(adoptPtr(new DataConsumerHandle("handle2", m_context))) ; | |
| 193 m_handle = nullptr; | |
| 194 readingThread()->postTask(FROM_HERE, new Task(threadSafeBind(&Self::rese tReader, this))); | |
| 195 readingThread()->postTask(FROM_HERE, new Task(threadSafeBind(&Self::sign alDone, this))); | |
| 196 } | |
| 197 }; | |
| 198 | |
| 199 class ThreadingRegistrationDeleteReaderTest : public ThreadingTestBase { | |
| 200 public: | |
| 201 using Self = ThreadingRegistrationDeleteReaderTest; | |
| 202 void run() | |
| 203 { | |
| 204 m_context = Context::create(); | |
| 205 m_waitableEvent = adoptPtr(Platform::current()->createWaitableEvent()); | |
| 206 m_handle = CompositeDataConsumerHandle::create(adoptPtr(new DataConsumer Handle("handle1", m_context))); | |
| 207 | |
| 208 readingThread()->postTask(FROM_HERE, new Task(threadSafeBind(&Self::obta inReader, this))); | |
| 209 | |
| 210 m_waitableEvent->wait(); | |
| 211 } | |
| 212 | |
| 213 private: | |
| 214 void obtainReader() | |
| 215 { | |
| 216 m_reader = m_handle->obtainReader(&m_client); | |
| 217 updatingThread()->postTask(FROM_HERE, new Task(threadSafeBind(&Self::upd ate, this))); | |
| 218 } | |
| 219 void update() | |
| 220 { | |
| 221 readingThread()->postTask(FROM_HERE, new Task(threadSafeBind(&Self::rese tReader, this))); | |
| 222 m_handle->update(adoptPtr(new DataConsumerHandle("handle2", m_context))) ; | |
| 223 readingThread()->postTask(FROM_HERE, new Task(threadSafeBind(&Self::rese tReader, this))); | |
| 224 readingThread()->postTask(FROM_HERE, new Task(threadSafeBind(&Self::sign alDone, this))); | |
| 225 } | |
| 226 }; | |
| 227 | |
| 228 class ThreadingUpdatingReaderWhileUpdatingTest : public ThreadingTestBase { | |
| 229 public: | |
| 230 using Self = ThreadingUpdatingReaderWhileUpdatingTest; | |
| 231 void run() | |
| 232 { | |
| 233 m_context = Context::create(); | |
| 234 m_waitableEvent = adoptPtr(Platform::current()->createWaitableEvent()); | |
| 235 m_updateEvent = adoptPtr(Platform::current()->createWaitableEvent()); | |
| 236 m_handle = CompositeDataConsumerHandle::create(adoptPtr(new DataConsumer Handle("handle1", m_context))); | |
| 237 | |
| 238 readingThread()->postTask(FROM_HERE, new Task(threadSafeBind(&Self::obta inReader, this))); | |
| 239 | |
| 240 m_waitableEvent->wait(); | |
| 241 } | |
| 242 | |
| 243 private: | |
| 244 void obtainReader() | |
| 245 { | |
| 246 m_reader = m_handle->obtainReader(&m_client); | |
| 247 updatingThread()->postTask(FROM_HERE, new Task(threadSafeBind(&Self::upd ate, this))); | |
| 248 m_updateEvent->wait(); | |
| 249 } | |
| 250 | |
| 251 void update() | |
| 252 { | |
| 253 readingThread()->postTask(FROM_HERE, new Task(threadSafeBind(&Self::reob tainReader, this))); | |
| 254 m_handle->update(adoptPtr(new DataConsumerHandle("handle2", m_context))) ; | |
| 255 readingThread()->postTask(FROM_HERE, new Task(threadSafeBind(&Self::rese tReader, this))); | |
| 256 readingThread()->postTask(FROM_HERE, new Task(threadSafeBind(&Self::sign alDone, this))); | |
| 257 m_updateEvent->signal(); | |
| 258 } | |
| 259 | |
| 260 void reobtainReader() | |
| 261 { | |
| 262 m_reader = nullptr; | |
| 263 m_reader = m_handle->obtainReader(&m_client); | |
| 264 } | |
| 265 | |
| 266 OwnPtr<WebWaitableEvent> m_updateEvent; | |
| 267 }; | |
| 268 | |
| 269 class ThreadingRegistrationUpdateTwiceAtOneTimeTest : public ThreadingTestBase { | |
| 270 public: | |
| 271 using Self = ThreadingRegistrationUpdateTwiceAtOneTimeTest; | |
| 272 void run() | |
| 273 { | |
| 274 m_context = Context::create(); | |
| 275 m_waitableEvent = adoptPtr(Platform::current()->createWaitableEvent()); | |
| 276 m_handle = CompositeDataConsumerHandle::create(adoptPtr(new DataConsumer Handle("handle1", m_context))); | |
| 277 | |
| 278 readingThread()->postTask(FROM_HERE, new Task(threadSafeBind(&Self::obta inReader, this))); | |
| 279 | |
| 280 m_waitableEvent->wait(); | |
| 281 } | |
| 282 | |
| 283 private: | |
| 284 void obtainReader() | |
| 285 { | |
| 286 m_reader = m_handle->obtainReader(&m_client); | |
| 287 updatingThread()->postTask(FROM_HERE, new Task(threadSafeBind(&Self::upd ate, this))); | |
| 288 } | |
| 289 void update() | |
| 290 { | |
| 291 m_handle->update(adoptPtr(new DataConsumerHandle("handle2", m_context))) ; | |
| 292 m_handle->update(adoptPtr(new DataConsumerHandle("handle3", m_context))) ; | |
| 293 readingThread()->postTask(FROM_HERE, new Task(threadSafeBind(&Self::rese tReader, this))); | |
| 294 readingThread()->postTask(FROM_HERE, new Task(threadSafeBind(&Self::sign alDone, this))); | |
| 295 } | |
| 296 }; | |
| 297 | |
| 298 class ThreadingDoneHandleNotificationTest : public ThreadingTestBase, public Web DataConsumerHandle::Client { | |
| 299 public: | |
| 300 using Self = ThreadingDoneHandleNotificationTest; | |
| 301 void run() | |
| 302 { | |
| 303 m_context = Context::create(); | |
| 304 m_waitableEvent = adoptPtr(Platform::current()->createWaitableEvent()); | |
| 305 m_handle = CompositeDataConsumerHandle::create(CompositeDataConsumerHand le::createDoneHandle()); | |
| 306 | |
| 307 readingThread()->postTask(FROM_HERE, new Task(threadSafeBind(&Self::obta inReader, this))); | |
| 308 | |
| 309 m_waitableEvent->wait(); | 150 m_waitableEvent->wait(); |
| 310 } | 151 } |
| 311 | 152 |
| 312 private: | 153 private: |
| 313 void obtainReader() | 154 void obtainReader() |
| 314 { | 155 { |
| 315 m_reader = m_handle->obtainReader(this); | 156 m_reader = m_handle->obtainReader(this); |
| 316 } | 157 } |
| 317 void didGetReadable() override | 158 void didGetReadable() override |
| 318 { | 159 { |
| 319 readingThread()->postTask(FROM_HERE, new Task(threadSafeBind(&Self::rese tReader, this))); | 160 readingThread()->postTask(FROM_HERE, new Task(threadSafeBind(&Self::rese tReader, this))); |
| 320 readingThread()->postTask(FROM_HERE, new Task(threadSafeBind(&Self::sign alDone, this))); | 161 readingThread()->postTask(FROM_HERE, new Task(threadSafeBind(&Self::sign alDone, this))); |
| 321 } | 162 } |
| 163 | |
| 164 OwnPtr<WebDataConsumerHandle> m_handle; | |
| 322 }; | 165 }; |
| 323 | 166 |
| 324 class ThreadingDoneHandleNoNotificationTest : public ThreadingTestBase, public W ebDataConsumerHandle::Client { | 167 class ThreadingHandleNoNotificationTest : public ThreadingTestBase, public WebDa taConsumerHandle::Client { |
| 325 public: | 168 public: |
| 326 using Self = ThreadingDoneHandleNoNotificationTest; | 169 using Self = ThreadingHandleNoNotificationTest; |
| 327 void run() | 170 void run(PassOwnPtr<WebDataConsumerHandle> handle) |
| 328 { | 171 { |
| 329 m_context = Context::create(); | 172 m_context = Context::create(); |
| 330 m_waitableEvent = adoptPtr(Platform::current()->createWaitableEvent()); | 173 m_waitableEvent = adoptPtr(Platform::current()->createWaitableEvent()); |
| 331 m_handle = CompositeDataConsumerHandle::create(CompositeDataConsumerHand le::createDoneHandle()); | 174 m_handle = handle; |
| 332 | 175 |
| 333 readingThread()->postTask(FROM_HERE, new Task(threadSafeBind(&Self::obta inReader, this))); | 176 readingThread()->postTask(FROM_HERE, new Task(threadSafeBind(&Self::obta inReader, this))); |
| 334 | 177 |
| 335 m_waitableEvent->wait(); | 178 m_waitableEvent->wait(); |
| 336 } | 179 } |
| 337 | 180 |
| 338 private: | 181 private: |
| 339 void obtainReader() | 182 void obtainReader() |
| 340 { | 183 { |
| 341 m_reader = m_handle->obtainReader(this); | 184 m_reader = m_handle->obtainReader(this); |
| 342 m_reader = nullptr; | 185 m_reader = nullptr; |
| 343 readingThread()->postTask(FROM_HERE, new Task(threadSafeBind(&Self::sign alDone, this))); | 186 readingThread()->postTask(FROM_HERE, new Task(threadSafeBind(&Self::sign alDone, this))); |
| 344 } | 187 } |
| 345 void didGetReadable() override | 188 void didGetReadable() override |
| 346 { | 189 { |
| 347 ASSERT_NOT_REACHED(); | 190 ASSERT_NOT_REACHED(); |
| 348 } | 191 } |
| 192 | |
| 193 OwnPtr<WebDataConsumerHandle> m_handle; | |
| 349 }; | 194 }; |
| 350 | 195 |
| 351 TEST(CompositeDataConsumerHandleTest, CreateWaitingHandle) | |
| 352 { | |
| 353 char buffer[20]; | |
| 354 const void* p = nullptr; | |
| 355 size_t size = 0; | |
| 356 OwnPtr<WebDataConsumerHandle> handle = CompositeDataConsumerHandle::createWa itingHandle(); | |
| 357 OwnPtr<WebDataConsumerHandle::Reader> reader = handle->obtainReader(nullptr) ; | |
| 358 | |
| 359 EXPECT_EQ(kShouldWait, reader->read(buffer, sizeof(buffer), kNone, &size)); | |
| 360 EXPECT_EQ(kShouldWait, reader->beginRead(&p, kNone, &size)); | |
| 361 EXPECT_EQ(kUnexpectedError, reader->endRead(99)); | |
| 362 } | |
| 363 | |
| 364 TEST(CompositeDataConsumerHandleTest, CreateDoneHandle) | |
| 365 { | |
| 366 char buffer[20]; | |
| 367 const void* p = nullptr; | |
| 368 size_t size = 0; | |
| 369 OwnPtr<WebDataConsumerHandle> handle = CompositeDataConsumerHandle::createDo neHandle(); | |
| 370 OwnPtr<WebDataConsumerHandle::Reader> reader = handle->obtainReader(nullptr) ; | |
| 371 | |
| 372 EXPECT_EQ(kDone, reader->read(buffer, sizeof(buffer), kNone, &size)); | |
| 373 EXPECT_EQ(kDone, reader->beginRead(&p, kNone, &size)); | |
| 374 EXPECT_EQ(kUnexpectedError, reader->endRead(99)); | |
| 375 } | |
| 376 | |
| 377 TEST(CompositeDataConsumerHandleTest, Read) | |
| 378 { | |
| 379 char buffer[20]; | |
| 380 size_t size = 0; | |
| 381 NoopClient client; | |
| 382 Checkpoint checkpoint; | |
| 383 | |
| 384 OwnPtr<MockHandle> handle1 = MockHandle::create(); | |
| 385 OwnPtr<MockHandle> handle2 = MockHandle::create(); | |
| 386 OwnPtr<MockReader> reader1 = MockReader::create(); | |
| 387 OwnPtr<MockReader> reader2 = MockReader::create(); | |
| 388 | |
| 389 InSequence s; | |
| 390 EXPECT_CALL(checkpoint, Call(0)); | |
| 391 EXPECT_CALL(*handle1, obtainReaderInternal(&client)).WillOnce(Return(reader1 .get())); | |
| 392 EXPECT_CALL(checkpoint, Call(1)); | |
| 393 EXPECT_CALL(*reader1, read(buffer, sizeof(buffer), kNone, &size)).WillOnce(R eturn(kOk)); | |
| 394 EXPECT_CALL(checkpoint, Call(2)); | |
| 395 EXPECT_CALL(*handle2, obtainReaderInternal(&client)).WillOnce(Return(reader2 .get())); | |
| 396 EXPECT_CALL(checkpoint, Call(3)); | |
| 397 EXPECT_CALL(*reader2, read(buffer, sizeof(buffer), kNone, &size)).WillOnce(R eturn(kOk)); | |
| 398 EXPECT_CALL(checkpoint, Call(4)); | |
| 399 | |
| 400 // They are adopted by |obtainReader|. | |
| 401 ASSERT_TRUE(reader1.leakPtr()); | |
| 402 ASSERT_TRUE(reader2.leakPtr()); | |
| 403 | |
| 404 OwnPtr<CompositeDataConsumerHandle> handle = CompositeDataConsumerHandle::cr eate(handle1.release()); | |
| 405 checkpoint.Call(0); | |
| 406 OwnPtr<CompositeDataConsumerHandle::Reader> reader = handle->obtainReader(&c lient); | |
| 407 checkpoint.Call(1); | |
| 408 EXPECT_EQ(kOk, reader->read(buffer, sizeof(buffer), kNone, &size)); | |
| 409 checkpoint.Call(2); | |
| 410 handle->update(handle2.release()); | |
| 411 checkpoint.Call(3); | |
| 412 EXPECT_EQ(kOk, reader->read(buffer, sizeof(buffer), kNone, &size)); | |
| 413 checkpoint.Call(4); | |
| 414 } | |
| 415 | |
| 416 TEST(CompositeDataConsumerHandleTest, TwoPhaseRead) | |
| 417 { | |
| 418 const void* p = nullptr; | |
| 419 size_t size = 0; | |
| 420 Checkpoint checkpoint; | |
| 421 | |
| 422 OwnPtr<MockHandle> handle1 = MockHandle::create(); | |
| 423 OwnPtr<MockHandle> handle2 = MockHandle::create(); | |
| 424 OwnPtr<MockReader> reader1 = MockReader::create(); | |
| 425 OwnPtr<MockReader> reader2 = MockReader::create(); | |
| 426 | |
| 427 InSequence s; | |
| 428 EXPECT_CALL(checkpoint, Call(0)); | |
| 429 EXPECT_CALL(*handle1, obtainReaderInternal(nullptr)).WillOnce(Return(reader1 .get())); | |
| 430 EXPECT_CALL(checkpoint, Call(1)); | |
| 431 EXPECT_CALL(*reader1, beginRead(&p, kNone, &size)).WillOnce(Return(kOk)); | |
| 432 EXPECT_CALL(checkpoint, Call(2)); | |
| 433 EXPECT_CALL(*reader1, endRead(0)).WillOnce(Return(kOk)); | |
| 434 EXPECT_CALL(checkpoint, Call(3)); | |
| 435 EXPECT_CALL(*handle2, obtainReaderInternal(nullptr)).WillOnce(Return(reader2 .get())); | |
| 436 EXPECT_CALL(checkpoint, Call(4)); | |
| 437 EXPECT_CALL(*reader2, beginRead(&p, kNone, &size)).WillOnce(Return(kOk)); | |
| 438 EXPECT_CALL(checkpoint, Call(5)); | |
| 439 EXPECT_CALL(*reader2, endRead(0)).WillOnce(Return(kOk)); | |
| 440 EXPECT_CALL(checkpoint, Call(6)); | |
| 441 | |
| 442 // They are adopted by |obtainReader|. | |
| 443 ASSERT_TRUE(reader1.leakPtr()); | |
| 444 ASSERT_TRUE(reader2.leakPtr()); | |
| 445 | |
| 446 OwnPtr<CompositeDataConsumerHandle> handle = CompositeDataConsumerHandle::cr eate(handle1.release()); | |
| 447 checkpoint.Call(0); | |
| 448 OwnPtr<CompositeDataConsumerHandle::Reader> reader = handle->obtainReader(nu llptr); | |
| 449 checkpoint.Call(1); | |
| 450 EXPECT_EQ(kOk, reader->beginRead(&p, kNone, &size)); | |
| 451 checkpoint.Call(2); | |
| 452 EXPECT_EQ(kOk, reader->endRead(0)); | |
| 453 checkpoint.Call(3); | |
| 454 handle->update(handle2.release()); | |
| 455 checkpoint.Call(4); | |
| 456 EXPECT_EQ(kOk, reader->beginRead(&p, kNone, &size)); | |
| 457 checkpoint.Call(5); | |
| 458 EXPECT_EQ(kOk, reader->endRead(0)); | |
| 459 checkpoint.Call(6); | |
| 460 } | |
| 461 | |
| 462 TEST(CompositeDataConsumerHandleTest, HangingTwoPhaseRead) | |
| 463 { | |
| 464 const void* p = nullptr; | |
| 465 size_t size = 0; | |
| 466 Checkpoint checkpoint; | |
| 467 | |
| 468 OwnPtr<MockHandle> handle1 = MockHandle::create(); | |
| 469 OwnPtr<MockHandle> handle2 = MockHandle::create(); | |
| 470 OwnPtr<MockHandle> handle3 = MockHandle::create(); | |
| 471 OwnPtr<MockReader> reader1 = MockReader::create(); | |
| 472 OwnPtr<MockReader> reader2 = MockReader::create(); | |
| 473 OwnPtr<MockReader> reader3 = MockReader::create(); | |
| 474 | |
| 475 InSequence s; | |
| 476 EXPECT_CALL(checkpoint, Call(0)); | |
| 477 EXPECT_CALL(*handle1, obtainReaderInternal(nullptr)).WillOnce(Return(reader1 .get())); | |
| 478 EXPECT_CALL(checkpoint, Call(1)); | |
| 479 EXPECT_CALL(*reader1, beginRead(&p, kNone, &size)).WillOnce(Return(kOk)); | |
| 480 EXPECT_CALL(checkpoint, Call(2)); | |
| 481 EXPECT_CALL(checkpoint, Call(3)); | |
| 482 EXPECT_CALL(*reader1, endRead(0)).WillOnce(Return(kOk)); | |
| 483 EXPECT_CALL(*handle2, obtainReaderInternal(nullptr)).WillOnce(Return(reader2 .get())); | |
| 484 EXPECT_CALL(checkpoint, Call(4)); | |
| 485 EXPECT_CALL(*reader2, beginRead(&p, kNone, &size)).WillOnce(Return(kShouldWa it)); | |
| 486 EXPECT_CALL(checkpoint, Call(5)); | |
| 487 EXPECT_CALL(*handle3, obtainReaderInternal(nullptr)).WillOnce(Return(reader3 .get())); | |
| 488 EXPECT_CALL(checkpoint, Call(6)); | |
| 489 EXPECT_CALL(*reader3, beginRead(&p, kNone, &size)).WillOnce(Return(kOk)); | |
| 490 EXPECT_CALL(checkpoint, Call(7)); | |
| 491 EXPECT_CALL(*reader3, endRead(0)).WillOnce(Return(kOk)); | |
| 492 EXPECT_CALL(checkpoint, Call(8)); | |
| 493 | |
| 494 // They are adopted by |obtainReader|. | |
| 495 ASSERT_TRUE(reader1.leakPtr()); | |
| 496 ASSERT_TRUE(reader2.leakPtr()); | |
| 497 ASSERT_TRUE(reader3.leakPtr()); | |
| 498 | |
| 499 OwnPtr<CompositeDataConsumerHandle> handle = CompositeDataConsumerHandle::cr eate(handle1.release()); | |
| 500 checkpoint.Call(0); | |
| 501 OwnPtr<CompositeDataConsumerHandle::Reader> reader = handle->obtainReader(nu llptr); | |
| 502 checkpoint.Call(1); | |
| 503 EXPECT_EQ(kOk, reader->beginRead(&p, kNone, &size)); | |
| 504 checkpoint.Call(2); | |
| 505 handle->update(handle2.release()); | |
| 506 checkpoint.Call(3); | |
| 507 EXPECT_EQ(kOk, reader->endRead(0)); | |
| 508 checkpoint.Call(4); | |
| 509 EXPECT_EQ(kShouldWait, reader->beginRead(&p, kNone, &size)); | |
| 510 checkpoint.Call(5); | |
| 511 handle->update(handle3.release()); | |
| 512 checkpoint.Call(6); | |
| 513 EXPECT_EQ(kOk, reader->beginRead(&p, kNone, &size)); | |
| 514 checkpoint.Call(7); | |
| 515 EXPECT_EQ(kOk, reader->endRead(0)); | |
| 516 checkpoint.Call(8); | |
| 517 } | |
| 518 | |
| 519 TEST(CompositeDataConsumerHandleTest, RegisterClientOnDifferentThreads) | |
| 520 { | |
| 521 ThreadingRegistrationTest test; | |
| 522 test.run(); | |
| 523 | |
| 524 EXPECT_EQ( | |
| 525 "A reader is attached to handle1 on the reading thread.\n" | |
| 526 "A reader is detached from handle1 on the reading thread.\n" | |
| 527 "A reader is attached to handle2 on the reading thread.\n" | |
| 528 "A reader is detached from handle2 on the reading thread.\n", | |
| 529 test.result()); | |
| 530 } | |
| 531 | |
| 532 TEST(CompositeDataConsumerHandleTest, DeleteHandleWhileUpdating) | |
| 533 { | |
| 534 ThreadingRegistrationDeleteHandleTest test; | |
| 535 test.run(); | |
| 536 | |
| 537 EXPECT_EQ( | |
| 538 "A reader is attached to handle1 on the reading thread.\n" | |
| 539 "A reader is detached from handle1 on the reading thread.\n" | |
| 540 "A reader is attached to handle2 on the reading thread.\n" | |
| 541 "A reader is detached from handle2 on the reading thread.\n", | |
| 542 test.result()); | |
| 543 } | |
| 544 | |
| 545 TEST(CompositeDataConsumerHandleTest, DeleteReaderWhileUpdating) | |
| 546 { | |
| 547 ThreadingRegistrationDeleteReaderTest test; | |
| 548 test.run(); | |
| 549 | |
| 550 EXPECT_EQ( | |
| 551 "A reader is attached to handle1 on the reading thread.\n" | |
| 552 "A reader is detached from handle1 on the reading thread.\n", | |
| 553 test.result()); | |
| 554 } | |
| 555 | |
| 556 TEST(CompositeDataConsumerHandleTest, UpdateReaderWhileUpdating) | |
| 557 { | |
| 558 ThreadingUpdatingReaderWhileUpdatingTest test; | |
| 559 test.run(); | |
| 560 | |
| 561 EXPECT_EQ( | |
| 562 "A reader is attached to handle1 on the reading thread.\n" | |
| 563 "A reader is detached from handle1 on the reading thread.\n" | |
| 564 "A reader is attached to handle2 on the reading thread.\n" | |
| 565 "A reader is detached from handle2 on the reading thread.\n", | |
| 566 test.result()); | |
| 567 } | |
| 568 | |
| 569 TEST(CompositeDataConsumerHandleTest, UpdateTwiceAtOnce) | |
| 570 { | |
| 571 ThreadingRegistrationUpdateTwiceAtOneTimeTest test; | |
| 572 test.run(); | |
| 573 | |
| 574 EXPECT_EQ( | |
| 575 "A reader is attached to handle1 on the reading thread.\n" | |
| 576 "A reader is detached from handle1 on the reading thread.\n" | |
| 577 "A reader is attached to handle3 on the reading thread.\n" | |
| 578 "A reader is detached from handle3 on the reading thread.\n", | |
| 579 test.result()); | |
| 580 } | |
| 581 | |
| 582 TEST(CompositeDataConsumerHandleTest, DoneHandleNotification) | |
| 583 { | |
| 584 ThreadingDoneHandleNotificationTest test; | |
| 585 // Test this function returns. | |
| 586 test.run(); | |
| 587 } | |
| 588 | |
| 589 TEST(CompositeDataConsumerHandleTest, DoneHandleNoNotification) | |
| 590 { | |
| 591 ThreadingDoneHandleNoNotificationTest test; | |
| 592 // Test this function doesn't crash. | |
| 593 test.run(); | |
| 594 } | |
| 595 | |
| 596 } // namespace | |
| 597 | |
| 598 } // namespace blink | 196 } // namespace blink |
| OLD | NEW |