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

Side by Side Diff: third_party/WebKit/Source/modules/fetch/DataConsumerTeeTest.cpp

Issue 1713143002: Remove most of the blink::Task wrapping of WTF::Function outside WebTaskRunner (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase. Created 4 years, 9 months 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
OLDNEW
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"
11 #include "platform/ThreadSafeFunctional.h" 10 #include "platform/ThreadSafeFunctional.h"
12 #include "platform/WaitableEvent.h" 11 #include "platform/WaitableEvent.h"
13 #include "platform/WebThreadSupportingGC.h" 12 #include "platform/WebThreadSupportingGC.h"
14 #include "public/platform/Platform.h" 13 #include "public/platform/Platform.h"
15 #include "public/platform/WebThread.h" 14 #include "public/platform/WebThread.h"
16 #include "public/platform/WebTraceLocation.h" 15 #include "public/platform/WebTraceLocation.h"
17 #include "testing/gtest/include/gtest/gtest.h" 16 #include "testing/gtest/include/gtest/gtest.h"
18 #include "wtf/PassRefPtr.h" 17 #include "wtf/PassRefPtr.h"
19 #include "wtf/RefPtr.h" 18 #include "wtf/RefPtr.h"
20 #include <string.h> 19 #include <string.h>
(...skipping 30 matching lines...) Expand all
51 return String(v.data(), v.size()); 50 return String(v.data(), v.size());
52 } 51 }
53 52
54 template<typename Handle> 53 template<typename Handle>
55 class TeeCreationThread { 54 class TeeCreationThread {
56 public: 55 public:
57 void run(PassOwnPtr<Handle> src, OwnPtr<Handle>* dest1, OwnPtr<Handle>* dest 2) 56 void run(PassOwnPtr<Handle> src, OwnPtr<Handle>* dest1, OwnPtr<Handle>* dest 2)
58 { 57 {
59 m_thread = adoptPtr(new Thread("src thread", Thread::WithExecutionContex t)); 58 m_thread = adoptPtr(new Thread("src thread", Thread::WithExecutionContex t));
60 m_waitableEvent = adoptPtr(new WaitableEvent()); 59 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)))); 60 m_thread->thread()->postTask(BLINK_FROM_HERE, threadSafeBind(&TeeCreatio nThread<Handle>::runInternal, AllowCrossThreadAccess(this), src, AllowCrossThrea dAccess(dest1), AllowCrossThreadAccess(dest2)));
62 m_waitableEvent->wait(); 61 m_waitableEvent->wait();
63 } 62 }
64 63
65 Thread* thread() { return m_thread.get(); } 64 Thread* thread() { return m_thread.get(); }
66 65
67 private: 66 private:
68 void runInternal(PassOwnPtr<Handle> src, OwnPtr<Handle>* dest1, OwnPtr<Handl e>* dest2) 67 void runInternal(PassOwnPtr<Handle> src, OwnPtr<Handle>* dest1, OwnPtr<Handl e>* dest2)
69 { 68 {
70 DataConsumerTee::create(m_thread->executionContext(), src, dest1, dest2) ; 69 DataConsumerTee::create(m_thread->executionContext(), src, dest1, dest2) ;
71 m_waitableEvent->signal(); 70 m_waitableEvent->signal();
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after
206 t->run(src.release(), &dest1, &dest2); 205 t->run(src.release(), &dest1, &dest2);
207 206
208 ASSERT_TRUE(dest1); 207 ASSERT_TRUE(dest1);
209 ASSERT_TRUE(dest2); 208 ASSERT_TRUE(dest2);
210 209
211 HandleReaderRunner<HandleReader> r1(dest1.release()); 210 HandleReaderRunner<HandleReader> r1(dest1.release());
212 HandleReaderRunner<HandleReader> r2(dest2.release()); 211 HandleReaderRunner<HandleReader> r2(dest2.release());
213 212
214 // We can pass a raw pointer because the subsequent |wait| calls ensure 213 // We can pass a raw pointer because the subsequent |wait| calls ensure
215 // t->thread() is alive. 214 // t->thread() is alive.
216 t->thread()->thread()->postTask(BLINK_FROM_HERE, new Task(threadSafeBind(pos tStop, AllowCrossThreadAccess(t->thread())))); 215 t->thread()->thread()->postTask(BLINK_FROM_HERE, threadSafeBind(postStop, Al lowCrossThreadAccess(t->thread())));
217 216
218 OwnPtr<HandleReadResult> res1 = r1.wait(); 217 OwnPtr<HandleReadResult> res1 = r1.wait();
219 OwnPtr<HandleReadResult> res2 = r2.wait(); 218 OwnPtr<HandleReadResult> res2 = r2.wait();
220 219
221 EXPECT_EQ(kUnexpectedError, res1->result()); 220 EXPECT_EQ(kUnexpectedError, res1->result());
222 EXPECT_EQ(kUnexpectedError, res2->result()); 221 EXPECT_EQ(kUnexpectedError, res2->result());
223 } 222 }
224 223
225 TEST(DataConsumerTeeTest, DetachSource) 224 TEST(DataConsumerTeeTest, DetachSource)
226 { 225 {
(...skipping 182 matching lines...) Expand 10 before | Expand all | Expand 10 after
409 OwnPtr<HandleReadResult> res2 = r2.wait(); 408 OwnPtr<HandleReadResult> res2 = r2.wait();
410 409
411 EXPECT_EQ(kDone, res1->result()); 410 EXPECT_EQ(kDone, res1->result());
412 EXPECT_EQ(0u, res1->data().size()); 411 EXPECT_EQ(0u, res1->data().size());
413 EXPECT_EQ(kDone, res2->result()); 412 EXPECT_EQ(kDone, res2->result());
414 EXPECT_EQ(0u, res2->data().size()); 413 EXPECT_EQ(0u, res2->data().size());
415 } 414 }
416 415
417 } // namespace 416 } // namespace
418 } // namespace blink 417 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698