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

Side by Side Diff: third_party/WebKit/Source/platform/scheduler/CancellableTaskFactoryTest.cpp

Issue 2506553002: Scheduler: Deprecate CancellableTaskFactory in favor of WebTaskRunner::postCancellableTask (Closed)
Patch Set: add comments Created 4 years, 1 month 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 "platform/scheduler/CancellableTaskFactory.h" 5 #include "platform/scheduler/CancellableTaskFactory.h"
6 6
7 #include "platform/heap/Handle.h" 7 #include "platform/heap/Handle.h"
8 #include "testing/gtest/include/gtest/gtest.h" 8 #include "testing/gtest/include/gtest/gtest.h"
9 #include "wtf/PtrUtil.h" 9 #include "wtf/PtrUtil.h"
10 #include <memory> 10 #include <memory>
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
59 59
60 TEST_F(CancellableTaskFactoryTest, IsPending_TaskCreatedAndCancelled) { 60 TEST_F(CancellableTaskFactoryTest, IsPending_TaskCreatedAndCancelled) {
61 TestCancellableTaskFactory factory(nullptr); 61 TestCancellableTaskFactory factory(nullptr);
62 std::unique_ptr<WebTaskRunner::Task> task = 62 std::unique_ptr<WebTaskRunner::Task> task =
63 wrapUnique(factory.cancelAndCreate()); 63 wrapUnique(factory.cancelAndCreate());
64 factory.cancel(); 64 factory.cancel();
65 65
66 EXPECT_FALSE(factory.isPending()); 66 EXPECT_FALSE(factory.isPending());
67 } 67 }
68 68
69 class TestClass {
70 public:
71 std::unique_ptr<CancellableTaskFactory> m_factory;
72
73 TestClass()
74 : m_factory(CancellableTaskFactory::create(this, &TestClass::TestFn)) {}
75
76 void TestFn() { EXPECT_FALSE(m_factory->isPending()); }
77 };
78
79 TEST_F(CancellableTaskFactoryTest, IsPending_InCallback) {
80 TestClass testClass;
81 std::unique_ptr<WebTaskRunner::Task> task =
82 wrapUnique(testClass.m_factory->cancelAndCreate());
83 task->run();
84 }
85
86 void AddOne(int* ptr) { 69 void AddOne(int* ptr) {
87 *ptr += 1; 70 *ptr += 1;
88 } 71 }
89 72
90 TEST_F(CancellableTaskFactoryTest, Run_ClosureIsExecuted) { 73 TEST_F(CancellableTaskFactoryTest, Run_ClosureIsExecuted) {
91 int executionCount = 0; 74 int executionCount = 0;
92 TestCancellableTaskFactory factory( 75 TestCancellableTaskFactory factory(
93 WTF::bind(&AddOne, WTF::unretained(&executionCount))); 76 WTF::bind(&AddOne, WTF::unretained(&executionCount)));
94 std::unique_ptr<WebTaskRunner::Task> task = 77 std::unique_ptr<WebTaskRunner::Task> task =
95 wrapUnique(factory.cancelAndCreate()); 78 wrapUnique(factory.cancelAndCreate());
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after
208 task->run(); 191 task->run();
209 // The owning object will have been GCed and the task will have 192 // The owning object will have been GCed and the task will have
210 // lost its weak reference. Verify that it wasn't invoked. 193 // lost its weak reference. Verify that it wasn't invoked.
211 EXPECT_EQ(0, GCObject::s_invoked); 194 EXPECT_EQ(0, GCObject::s_invoked);
212 195
213 // ..and just to make sure |object| was indeed destructed. 196 // ..and just to make sure |object| was indeed destructed.
214 EXPECT_EQ(1, GCObject::s_destructed); 197 EXPECT_EQ(1, GCObject::s_destructed);
215 } 198 }
216 199
217 } // namespace blink 200 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698