| 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/DataConsumerTee.h" | 5 #include "modules/fetch/DataConsumerTee.h" |
| 6 | 6 |
| 7 #include "core/testing/DummyPageHolder.h" | 7 #include "core/testing/DummyPageHolder.h" |
| 8 #include "core/testing/NullExecutionContext.h" | 8 #include "core/testing/NullExecutionContext.h" |
| 9 #include "modules/fetch/DataConsumerHandleTestUtil.h" | 9 #include "modules/fetch/DataConsumerHandleTestUtil.h" |
| 10 #include "platform/Task.h" | 10 #include "platform/Task.h" |
| 11 #include "platform/ThreadSafeFunctional.h" | 11 #include "platform/ThreadSafeFunctional.h" |
| 12 #include "platform/WaitableEvent.h" |
| 12 #include "platform/WebThreadSupportingGC.h" | 13 #include "platform/WebThreadSupportingGC.h" |
| 13 #include "public/platform/Platform.h" | 14 #include "public/platform/Platform.h" |
| 14 #include "public/platform/WebThread.h" | 15 #include "public/platform/WebThread.h" |
| 15 #include "public/platform/WebTraceLocation.h" | 16 #include "public/platform/WebTraceLocation.h" |
| 16 #include "public/platform/WebWaitableEvent.h" | |
| 17 #include "testing/gtest/include/gtest/gtest.h" | 17 #include "testing/gtest/include/gtest/gtest.h" |
| 18 #include "wtf/PassRefPtr.h" | 18 #include "wtf/PassRefPtr.h" |
| 19 #include "wtf/RefPtr.h" | 19 #include "wtf/RefPtr.h" |
| 20 #include <string.h> | 20 #include <string.h> |
| 21 #include <v8.h> | 21 #include <v8.h> |
| 22 | 22 |
| 23 namespace blink { | 23 namespace blink { |
| 24 namespace { | 24 namespace { |
| 25 | 25 |
| 26 using ::testing::InSequence; | 26 using ::testing::InSequence; |
| (...skipping 23 matching lines...) Expand all Loading... |
| 50 { | 50 { |
| 51 return String(v.data(), v.size()); | 51 return String(v.data(), v.size()); |
| 52 } | 52 } |
| 53 | 53 |
| 54 template<typename Handle> | 54 template<typename Handle> |
| 55 class TeeCreationThread { | 55 class TeeCreationThread { |
| 56 public: | 56 public: |
| 57 void run(PassOwnPtr<Handle> src, OwnPtr<Handle>* dest1, OwnPtr<Handle>* dest
2) | 57 void run(PassOwnPtr<Handle> src, OwnPtr<Handle>* dest1, OwnPtr<Handle>* dest
2) |
| 58 { | 58 { |
| 59 m_thread = adoptPtr(new Thread("src thread", Thread::WithExecutionContex
t)); | 59 m_thread = adoptPtr(new Thread("src thread", Thread::WithExecutionContex
t)); |
| 60 m_waitableEvent = adoptPtr(Platform::current()->createWaitableEvent()); | 60 m_waitableEvent = adoptPtr(new WaitableEvent()); |
| 61 m_thread->thread()->postTask(BLINK_FROM_HERE, new Task(threadSafeBind(&T
eeCreationThread<Handle>::runInternal, AllowCrossThreadAccess(this), src, AllowC
rossThreadAccess(dest1), AllowCrossThreadAccess(dest2)))); | 61 m_thread->thread()->postTask(BLINK_FROM_HERE, new Task(threadSafeBind(&T
eeCreationThread<Handle>::runInternal, AllowCrossThreadAccess(this), src, AllowC
rossThreadAccess(dest1), AllowCrossThreadAccess(dest2)))); |
| 62 m_waitableEvent->wait(); | 62 m_waitableEvent->wait(); |
| 63 } | 63 } |
| 64 | 64 |
| 65 Thread* thread() { return m_thread.get(); } | 65 Thread* thread() { return m_thread.get(); } |
| 66 | 66 |
| 67 private: | 67 private: |
| 68 void runInternal(PassOwnPtr<Handle> src, OwnPtr<Handle>* dest1, OwnPtr<Handl
e>* dest2) | 68 void runInternal(PassOwnPtr<Handle> src, OwnPtr<Handle>* dest1, OwnPtr<Handl
e>* dest2) |
| 69 { | 69 { |
| 70 DataConsumerTee::create(m_thread->executionContext(), src, dest1, dest2)
; | 70 DataConsumerTee::create(m_thread->executionContext(), src, dest1, dest2)
; |
| 71 m_waitableEvent->signal(); | 71 m_waitableEvent->signal(); |
| 72 } | 72 } |
| 73 | 73 |
| 74 OwnPtr<Thread> m_thread; | 74 OwnPtr<Thread> m_thread; |
| 75 OwnPtr<WebWaitableEvent> m_waitableEvent; | 75 OwnPtr<WaitableEvent> m_waitableEvent; |
| 76 }; | 76 }; |
| 77 | 77 |
| 78 TEST(DataConsumerTeeTest, CreateDone) | 78 TEST(DataConsumerTeeTest, CreateDone) |
| 79 { | 79 { |
| 80 OwnPtr<Handle> src(Handle::create()); | 80 OwnPtr<Handle> src(Handle::create()); |
| 81 OwnPtr<WebDataConsumerHandle> dest1, dest2; | 81 OwnPtr<WebDataConsumerHandle> dest1, dest2; |
| 82 | 82 |
| 83 src->add(Command(Command::Done)); | 83 src->add(Command(Command::Done)); |
| 84 | 84 |
| 85 OwnPtr<TeeCreationThread<WebDataConsumerHandle>> t = adoptPtr(new TeeCreatio
nThread<WebDataConsumerHandle>()); | 85 OwnPtr<TeeCreationThread<WebDataConsumerHandle>> t = adoptPtr(new TeeCreatio
nThread<WebDataConsumerHandle>()); |
| (...skipping 323 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 409 OwnPtr<HandleReadResult> res2 = r2.wait(); | 409 OwnPtr<HandleReadResult> res2 = r2.wait(); |
| 410 | 410 |
| 411 EXPECT_EQ(kDone, res1->result()); | 411 EXPECT_EQ(kDone, res1->result()); |
| 412 EXPECT_EQ(0u, res1->data().size()); | 412 EXPECT_EQ(0u, res1->data().size()); |
| 413 EXPECT_EQ(kDone, res2->result()); | 413 EXPECT_EQ(kDone, res2->result()); |
| 414 EXPECT_EQ(0u, res2->data().size()); | 414 EXPECT_EQ(0u, res2->data().size()); |
| 415 } | 415 } |
| 416 | 416 |
| 417 } // namespace | 417 } // namespace |
| 418 } // namespace blink | 418 } // namespace blink |
| OLD | NEW |