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

Unified Diff: Source/platform/scheduler/CancellableTaskFactoryTest.cpp

Issue 1320023009: Limit stack-allocated uses of CancellableTaskFactory(PassOwnPtr<Closure>). (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Created 5 years, 3 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « Source/platform/scheduler/CancellableTaskFactory.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: Source/platform/scheduler/CancellableTaskFactoryTest.cpp
diff --git a/Source/platform/scheduler/CancellableTaskFactoryTest.cpp b/Source/platform/scheduler/CancellableTaskFactoryTest.cpp
index 02713cd17a0e7cab484788e156d4a840ba577d64..f4d55465959ab0beb1f948d0427807962458676d 100644
--- a/Source/platform/scheduler/CancellableTaskFactoryTest.cpp
+++ b/Source/platform/scheduler/CancellableTaskFactoryTest.cpp
@@ -9,18 +9,30 @@
namespace blink {
+namespace {
+
+class TestCancellableTaskFactory : public CancellableTaskFactory {
+public:
+ explicit TestCancellableTaskFactory(PassOwnPtr<Closure> closure)
+ : CancellableTaskFactory(closure)
+ {
+ }
+};
+
+} // namespace
+
using CancellableTaskFactoryTest = testing::Test;
TEST_F(CancellableTaskFactoryTest, IsPending_TaskNotCreated)
{
- CancellableTaskFactory factory(nullptr);
+ TestCancellableTaskFactory factory(nullptr);
EXPECT_FALSE(factory.isPending());
}
TEST_F(CancellableTaskFactoryTest, IsPending_TaskCreated)
{
- CancellableTaskFactory factory(nullptr);
+ TestCancellableTaskFactory factory(nullptr);
OwnPtr<WebTaskRunner::Task> task = adoptPtr(factory.cancelAndCreate());
EXPECT_TRUE(factory.isPending());
@@ -32,7 +44,7 @@ void EmptyFn()
TEST_F(CancellableTaskFactoryTest, IsPending_TaskCreatedAndRun)
{
- CancellableTaskFactory factory(WTF::bind(&EmptyFn));
+ TestCancellableTaskFactory factory(WTF::bind(&EmptyFn));
{
OwnPtr<WebTaskRunner::Task> task = adoptPtr(factory.cancelAndCreate());
task->run();
@@ -43,7 +55,7 @@ TEST_F(CancellableTaskFactoryTest, IsPending_TaskCreatedAndRun)
TEST_F(CancellableTaskFactoryTest, IsPending_TaskCreatedAndDestroyed)
{
- CancellableTaskFactory factory(nullptr);
+ TestCancellableTaskFactory factory(nullptr);
delete factory.cancelAndCreate();
EXPECT_FALSE(factory.isPending());
@@ -51,7 +63,7 @@ TEST_F(CancellableTaskFactoryTest, IsPending_TaskCreatedAndDestroyed)
TEST_F(CancellableTaskFactoryTest, IsPending_TaskCreatedAndCancelled)
{
- CancellableTaskFactory factory(nullptr);
+ TestCancellableTaskFactory factory(nullptr);
OwnPtr<WebTaskRunner::Task> task = adoptPtr(factory.cancelAndCreate());
factory.cancel();
@@ -60,23 +72,23 @@ TEST_F(CancellableTaskFactoryTest, IsPending_TaskCreatedAndCancelled)
class TestClass {
public:
- CancellableTaskFactory m_factory;
+ OwnPtr<CancellableTaskFactory> m_factory;
TestClass()
- : m_factory(WTF::bind(&TestClass::TestFn, this))
+ : m_factory(CancellableTaskFactory::create(this, &TestClass::TestFn))
{
}
void TestFn()
{
- EXPECT_FALSE(m_factory.isPending());
+ EXPECT_FALSE(m_factory->isPending());
}
};
TEST_F(CancellableTaskFactoryTest, IsPending_InCallback)
{
TestClass testClass;
- OwnPtr<WebTaskRunner::Task> task = adoptPtr(testClass.m_factory.cancelAndCreate());
+ OwnPtr<WebTaskRunner::Task> task = adoptPtr(testClass.m_factory->cancelAndCreate());
task->run();
}
@@ -88,7 +100,7 @@ void AddOne(int* ptr)
TEST_F(CancellableTaskFactoryTest, Run_ClosureIsExecuted)
{
int executionCount = 0;
- CancellableTaskFactory factory(WTF::bind(&AddOne, &executionCount));
+ TestCancellableTaskFactory factory(WTF::bind(&AddOne, &executionCount));
OwnPtr<WebTaskRunner::Task> task = adoptPtr(factory.cancelAndCreate());
task->run();
@@ -98,7 +110,7 @@ TEST_F(CancellableTaskFactoryTest, Run_ClosureIsExecuted)
TEST_F(CancellableTaskFactoryTest, Run_ClosureIsExecutedOnlyOnce)
{
int executionCount = 0;
- CancellableTaskFactory factory(WTF::bind(&AddOne, &executionCount));
+ TestCancellableTaskFactory factory(WTF::bind(&AddOne, &executionCount));
OwnPtr<WebTaskRunner::Task> task = adoptPtr(factory.cancelAndCreate());
task->run();
task->run();
@@ -113,7 +125,7 @@ TEST_F(CancellableTaskFactoryTest, Run_FactoryDestructionPreventsExecution)
int executionCount = 0;
OwnPtr<WebTaskRunner::Task> task;
{
- CancellableTaskFactory factory(WTF::bind(&AddOne, &executionCount));
+ TestCancellableTaskFactory factory(WTF::bind(&AddOne, &executionCount));
task = adoptPtr(factory.cancelAndCreate());
}
task->run();
@@ -124,7 +136,7 @@ TEST_F(CancellableTaskFactoryTest, Run_FactoryDestructionPreventsExecution)
TEST_F(CancellableTaskFactoryTest, Run_TasksInSequence)
{
int executionCount = 0;
- CancellableTaskFactory factory(WTF::bind(&AddOne, &executionCount));
+ TestCancellableTaskFactory factory(WTF::bind(&AddOne, &executionCount));
OwnPtr<WebTaskRunner::Task> taskA = adoptPtr(factory.cancelAndCreate());
taskA->run();
@@ -142,7 +154,7 @@ TEST_F(CancellableTaskFactoryTest, Run_TasksInSequence)
TEST_F(CancellableTaskFactoryTest, Cancel)
{
int executionCount = 0;
- CancellableTaskFactory factory(WTF::bind(&AddOne, &executionCount));
+ TestCancellableTaskFactory factory(WTF::bind(&AddOne, &executionCount));
OwnPtr<WebTaskRunner::Task> task = adoptPtr(factory.cancelAndCreate());
factory.cancel();
task->run();
@@ -153,7 +165,7 @@ TEST_F(CancellableTaskFactoryTest, Cancel)
TEST_F(CancellableTaskFactoryTest, CreatingANewTaskCancelsPreviousOnes)
{
int executionCount = 0;
- CancellableTaskFactory factory(WTF::bind(&AddOne, &executionCount));
+ TestCancellableTaskFactory factory(WTF::bind(&AddOne, &executionCount));
OwnPtr<WebTaskRunner::Task> taskA = adoptPtr(factory.cancelAndCreate());
OwnPtr<WebTaskRunner::Task> taskB = adoptPtr(factory.cancelAndCreate());
« no previous file with comments | « Source/platform/scheduler/CancellableTaskFactory.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698