| 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. |
| 4 | 4 |
| 5 #include "modules/fetch/CompositeDataConsumerHandle.h" | 5 #include "modules/fetch/CompositeDataConsumerHandle.h" |
| 6 | 6 |
| 7 #include "modules/fetch/DataConsumerHandleTestUtil.h" | 7 #include "modules/fetch/DataConsumerHandleTestUtil.h" |
| 8 #include "platform/Task.h" | 8 #include "platform/Task.h" |
| 9 #include "platform/ThreadSafeFunctional.h" | 9 #include "platform/ThreadSafeFunctional.h" |
| 10 #include "platform/WaitableEvent.h" |
| 10 #include "platform/heap/Handle.h" | 11 #include "platform/heap/Handle.h" |
| 11 #include "public/platform/Platform.h" | 12 #include "public/platform/Platform.h" |
| 12 #include "public/platform/WebThread.h" | 13 #include "public/platform/WebThread.h" |
| 13 #include "public/platform/WebTraceLocation.h" | 14 #include "public/platform/WebTraceLocation.h" |
| 14 #include "public/platform/WebWaitableEvent.h" | |
| 15 #include "testing/gmock/include/gmock/gmock.h" | 15 #include "testing/gmock/include/gmock/gmock.h" |
| 16 #include "testing/gtest/include/gtest/gtest.h" | 16 #include "testing/gtest/include/gtest/gtest.h" |
| 17 #include "wtf/Locker.h" | 17 #include "wtf/Locker.h" |
| 18 | 18 |
| 19 namespace blink { | 19 namespace blink { |
| 20 | 20 |
| 21 namespace { | 21 namespace { |
| 22 | 22 |
| 23 using ::testing::InSequence; | 23 using ::testing::InSequence; |
| 24 using ::testing::Return; | 24 using ::testing::Return; |
| (...skipping 26 matching lines...) Expand all Loading... |
| 51 }; | 51 }; |
| 52 | 52 |
| 53 class ThreadingRegistrationTest : public DataConsumerHandleTestUtil::ThreadingTe
stBase { | 53 class ThreadingRegistrationTest : public DataConsumerHandleTestUtil::ThreadingTe
stBase { |
| 54 public: | 54 public: |
| 55 using Self = ThreadingRegistrationTest; | 55 using Self = ThreadingRegistrationTest; |
| 56 static PassRefPtr<Self> create() { return adoptRef(new Self); } | 56 static PassRefPtr<Self> create() { return adoptRef(new Self); } |
| 57 | 57 |
| 58 void run() | 58 void run() |
| 59 { | 59 { |
| 60 ThreadHolder holder(this); | 60 ThreadHolder holder(this); |
| 61 m_waitableEvent = adoptPtr(Platform::current()->createWaitableEvent()); | 61 m_waitableEvent = adoptPtr(new WaitableEvent()); |
| 62 | 62 |
| 63 postTaskToUpdatingThreadAndWait(BLINK_FROM_HERE, new Task(threadSafeBind
(&Self::createHandle, this))); | 63 postTaskToUpdatingThreadAndWait(BLINK_FROM_HERE, new Task(threadSafeBind
(&Self::createHandle, this))); |
| 64 postTaskToReadingThreadAndWait(BLINK_FROM_HERE, new Task(threadSafeBind(
&Self::obtainReader, this))); | 64 postTaskToReadingThreadAndWait(BLINK_FROM_HERE, new Task(threadSafeBind(
&Self::obtainReader, this))); |
| 65 } | 65 } |
| 66 | 66 |
| 67 private: | 67 private: |
| 68 ThreadingRegistrationTest() = default; | 68 ThreadingRegistrationTest() = default; |
| 69 | 69 |
| 70 void createHandle() | 70 void createHandle() |
| 71 { | 71 { |
| (...skipping 18 matching lines...) Expand all Loading... |
| 90 }; | 90 }; |
| 91 | 91 |
| 92 class ThreadingRegistrationDeleteHandleTest : public DataConsumerHandleTestUtil:
:ThreadingTestBase { | 92 class ThreadingRegistrationDeleteHandleTest : public DataConsumerHandleTestUtil:
:ThreadingTestBase { |
| 93 public: | 93 public: |
| 94 using Self = ThreadingRegistrationDeleteHandleTest; | 94 using Self = ThreadingRegistrationDeleteHandleTest; |
| 95 static PassRefPtr<Self> create() { return adoptRef(new Self); } | 95 static PassRefPtr<Self> create() { return adoptRef(new Self); } |
| 96 | 96 |
| 97 void run() | 97 void run() |
| 98 { | 98 { |
| 99 ThreadHolder holder(this); | 99 ThreadHolder holder(this); |
| 100 m_waitableEvent = adoptPtr(Platform::current()->createWaitableEvent()); | 100 m_waitableEvent = adoptPtr(new WaitableEvent()); |
| 101 | 101 |
| 102 postTaskToUpdatingThreadAndWait(BLINK_FROM_HERE, new Task(threadSafeBind
(&Self::createHandle, this))); | 102 postTaskToUpdatingThreadAndWait(BLINK_FROM_HERE, new Task(threadSafeBind
(&Self::createHandle, this))); |
| 103 postTaskToReadingThreadAndWait(BLINK_FROM_HERE, new Task(threadSafeBind(
&Self::obtainReader, this))); | 103 postTaskToReadingThreadAndWait(BLINK_FROM_HERE, new Task(threadSafeBind(
&Self::obtainReader, this))); |
| 104 } | 104 } |
| 105 | 105 |
| 106 private: | 106 private: |
| 107 ThreadingRegistrationDeleteHandleTest() = default; | 107 ThreadingRegistrationDeleteHandleTest() = default; |
| 108 | 108 |
| 109 void createHandle() | 109 void createHandle() |
| 110 { | 110 { |
| (...skipping 20 matching lines...) Expand all Loading... |
| 131 }; | 131 }; |
| 132 | 132 |
| 133 class ThreadingRegistrationDeleteReaderTest : public DataConsumerHandleTestUtil:
:ThreadingTestBase { | 133 class ThreadingRegistrationDeleteReaderTest : public DataConsumerHandleTestUtil:
:ThreadingTestBase { |
| 134 public: | 134 public: |
| 135 using Self = ThreadingRegistrationDeleteReaderTest; | 135 using Self = ThreadingRegistrationDeleteReaderTest; |
| 136 static PassRefPtr<Self> create() { return adoptRef(new Self); } | 136 static PassRefPtr<Self> create() { return adoptRef(new Self); } |
| 137 | 137 |
| 138 void run() | 138 void run() |
| 139 { | 139 { |
| 140 ThreadHolder holder(this); | 140 ThreadHolder holder(this); |
| 141 m_waitableEvent = adoptPtr(Platform::current()->createWaitableEvent()); | 141 m_waitableEvent = adoptPtr(new WaitableEvent()); |
| 142 | 142 |
| 143 postTaskToUpdatingThreadAndWait(BLINK_FROM_HERE, new Task(threadSafeBind
(&Self::createHandle, this))); | 143 postTaskToUpdatingThreadAndWait(BLINK_FROM_HERE, new Task(threadSafeBind
(&Self::createHandle, this))); |
| 144 postTaskToReadingThreadAndWait(BLINK_FROM_HERE, new Task(threadSafeBind(
&Self::obtainReader, this))); | 144 postTaskToReadingThreadAndWait(BLINK_FROM_HERE, new Task(threadSafeBind(
&Self::obtainReader, this))); |
| 145 } | 145 } |
| 146 | 146 |
| 147 private: | 147 private: |
| 148 ThreadingRegistrationDeleteReaderTest() = default; | 148 ThreadingRegistrationDeleteReaderTest() = default; |
| 149 | 149 |
| 150 void createHandle() | 150 void createHandle() |
| 151 { | 151 { |
| (...skipping 20 matching lines...) Expand all Loading... |
| 172 }; | 172 }; |
| 173 | 173 |
| 174 class ThreadingUpdatingReaderWhileUpdatingTest : public DataConsumerHandleTestUt
il::ThreadingTestBase { | 174 class ThreadingUpdatingReaderWhileUpdatingTest : public DataConsumerHandleTestUt
il::ThreadingTestBase { |
| 175 public: | 175 public: |
| 176 using Self = ThreadingUpdatingReaderWhileUpdatingTest; | 176 using Self = ThreadingUpdatingReaderWhileUpdatingTest; |
| 177 static PassRefPtr<Self> create() { return adoptRef(new Self); } | 177 static PassRefPtr<Self> create() { return adoptRef(new Self); } |
| 178 | 178 |
| 179 void run() | 179 void run() |
| 180 { | 180 { |
| 181 ThreadHolder holder(this); | 181 ThreadHolder holder(this); |
| 182 m_waitableEvent = adoptPtr(Platform::current()->createWaitableEvent()); | 182 m_waitableEvent = adoptPtr(new WaitableEvent()); |
| 183 m_updateEvent = adoptPtr(Platform::current()->createWaitableEvent()); | 183 m_updateEvent = adoptPtr(new WaitableEvent()); |
| 184 | 184 |
| 185 postTaskToUpdatingThreadAndWait(BLINK_FROM_HERE, new Task(threadSafeBind
(&Self::createHandle, this))); | 185 postTaskToUpdatingThreadAndWait(BLINK_FROM_HERE, new Task(threadSafeBind
(&Self::createHandle, this))); |
| 186 postTaskToReadingThreadAndWait(BLINK_FROM_HERE, new Task(threadSafeBind(
&Self::obtainReader, this))); | 186 postTaskToReadingThreadAndWait(BLINK_FROM_HERE, new Task(threadSafeBind(
&Self::obtainReader, this))); |
| 187 } | 187 } |
| 188 | 188 |
| 189 private: | 189 private: |
| 190 ThreadingUpdatingReaderWhileUpdatingTest() = default; | 190 ThreadingUpdatingReaderWhileUpdatingTest() = default; |
| 191 | 191 |
| 192 void createHandle() | 192 void createHandle() |
| 193 { | 193 { |
| (...skipping 19 matching lines...) Expand all Loading... |
| 213 } | 213 } |
| 214 | 214 |
| 215 void reobtainReader() | 215 void reobtainReader() |
| 216 { | 216 { |
| 217 m_reader = nullptr; | 217 m_reader = nullptr; |
| 218 m_reader = m_handle->obtainReader(&m_client); | 218 m_reader = m_handle->obtainReader(&m_client); |
| 219 } | 219 } |
| 220 | 220 |
| 221 OwnPtr<WebDataConsumerHandle> m_handle; | 221 OwnPtr<WebDataConsumerHandle> m_handle; |
| 222 CrossThreadPersistent<CompositeDataConsumerHandle::Updater> m_updater; | 222 CrossThreadPersistent<CompositeDataConsumerHandle::Updater> m_updater; |
| 223 OwnPtr<WebWaitableEvent> m_updateEvent; | 223 OwnPtr<WaitableEvent> m_updateEvent; |
| 224 }; | 224 }; |
| 225 | 225 |
| 226 class ThreadingRegistrationUpdateTwiceAtOneTimeTest : public DataConsumerHandleT
estUtil::ThreadingTestBase { | 226 class ThreadingRegistrationUpdateTwiceAtOneTimeTest : public DataConsumerHandleT
estUtil::ThreadingTestBase { |
| 227 public: | 227 public: |
| 228 using Self = ThreadingRegistrationUpdateTwiceAtOneTimeTest; | 228 using Self = ThreadingRegistrationUpdateTwiceAtOneTimeTest; |
| 229 static PassRefPtr<Self> create() { return adoptRef(new Self); } | 229 static PassRefPtr<Self> create() { return adoptRef(new Self); } |
| 230 | 230 |
| 231 void run() | 231 void run() |
| 232 { | 232 { |
| 233 ThreadHolder holder(this); | 233 ThreadHolder holder(this); |
| 234 m_waitableEvent = adoptPtr(Platform::current()->createWaitableEvent()); | 234 m_waitableEvent = adoptPtr(new WaitableEvent()); |
| 235 m_updateEvent = adoptPtr(Platform::current()->createWaitableEvent()); | 235 m_updateEvent = adoptPtr(new WaitableEvent()); |
| 236 | 236 |
| 237 postTaskToUpdatingThreadAndWait(BLINK_FROM_HERE, new Task(threadSafeBind
(&Self::createHandle, this))); | 237 postTaskToUpdatingThreadAndWait(BLINK_FROM_HERE, new Task(threadSafeBind
(&Self::createHandle, this))); |
| 238 postTaskToReadingThreadAndWait(BLINK_FROM_HERE, new Task(threadSafeBind(
&Self::obtainReader, this))); | 238 postTaskToReadingThreadAndWait(BLINK_FROM_HERE, new Task(threadSafeBind(
&Self::obtainReader, this))); |
| 239 } | 239 } |
| 240 | 240 |
| 241 private: | 241 private: |
| 242 ThreadingRegistrationUpdateTwiceAtOneTimeTest() = default; | 242 ThreadingRegistrationUpdateTwiceAtOneTimeTest() = default; |
| 243 | 243 |
| 244 void createHandle() | 244 void createHandle() |
| 245 { | 245 { |
| (...skipping 13 matching lines...) Expand all Loading... |
| 259 m_updater->update(DataConsumerHandle::create("handle2", m_context)); | 259 m_updater->update(DataConsumerHandle::create("handle2", m_context)); |
| 260 m_updater->update(DataConsumerHandle::create("handle3", m_context)); | 260 m_updater->update(DataConsumerHandle::create("handle3", m_context)); |
| 261 m_updateEvent->signal(); | 261 m_updateEvent->signal(); |
| 262 m_updater.clear(); | 262 m_updater.clear(); |
| 263 postTaskToReadingThread(BLINK_FROM_HERE, new Task(threadSafeBind(&Self::
resetReader, this))); | 263 postTaskToReadingThread(BLINK_FROM_HERE, new Task(threadSafeBind(&Self::
resetReader, this))); |
| 264 postTaskToReadingThread(BLINK_FROM_HERE, new Task(threadSafeBind(&Self::
signalDone, this))); | 264 postTaskToReadingThread(BLINK_FROM_HERE, new Task(threadSafeBind(&Self::
signalDone, this))); |
| 265 } | 265 } |
| 266 | 266 |
| 267 OwnPtr<WebDataConsumerHandle> m_handle; | 267 OwnPtr<WebDataConsumerHandle> m_handle; |
| 268 CrossThreadPersistent<CompositeDataConsumerHandle::Updater> m_updater; | 268 CrossThreadPersistent<CompositeDataConsumerHandle::Updater> m_updater; |
| 269 OwnPtr<WebWaitableEvent> m_updateEvent; | 269 OwnPtr<WaitableEvent> m_updateEvent; |
| 270 }; | 270 }; |
| 271 | 271 |
| 272 TEST(CompositeDataConsumerHandleTest, Read) | 272 TEST(CompositeDataConsumerHandleTest, Read) |
| 273 { | 273 { |
| 274 char buffer[20]; | 274 char buffer[20]; |
| 275 size_t size = 0; | 275 size_t size = 0; |
| 276 DataConsumerHandleTestUtil::NoopClient client; | 276 DataConsumerHandleTestUtil::NoopClient client; |
| 277 Checkpoint checkpoint; | 277 Checkpoint checkpoint; |
| 278 | 278 |
| 279 OwnPtr<MockHandle> handle1 = MockHandle::create(); | 279 OwnPtr<MockHandle> handle1 = MockHandle::create(); |
| (...skipping 209 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 489 { | 489 { |
| 490 RefPtr<DataConsumerHandleTestUtil::ThreadingHandleNoNotificationTest> test =
DataConsumerHandleTestUtil::ThreadingHandleNoNotificationTest::create(); | 490 RefPtr<DataConsumerHandleTestUtil::ThreadingHandleNoNotificationTest> test =
DataConsumerHandleTestUtil::ThreadingHandleNoNotificationTest::create(); |
| 491 CompositeDataConsumerHandle::Updater* updater = nullptr; | 491 CompositeDataConsumerHandle::Updater* updater = nullptr; |
| 492 // Test this function doesn't crash. | 492 // Test this function doesn't crash. |
| 493 test->run(CompositeDataConsumerHandle::create(createDoneDataConsumerHandle()
, &updater)); | 493 test->run(CompositeDataConsumerHandle::create(createDoneDataConsumerHandle()
, &updater)); |
| 494 } | 494 } |
| 495 | 495 |
| 496 } // namespace | 496 } // namespace |
| 497 | 497 |
| 498 } // namespace blink | 498 } // namespace blink |
| OLD | NEW |