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

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

Issue 2514733002: Scheduler: Deprecate CancellableTaskFactory in favor of WebTaskRunner::postCancellableTask (3) (Closed)
Patch Set: rebase 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 side-by-side diff with in-line comments
Download patch
Index: third_party/WebKit/Source/platform/scheduler/CancellableTaskFactoryTest.cpp
diff --git a/third_party/WebKit/Source/platform/scheduler/CancellableTaskFactoryTest.cpp b/third_party/WebKit/Source/platform/scheduler/CancellableTaskFactoryTest.cpp
deleted file mode 100644
index 58f6059609a8f960af8fb21cc21d42bbb4f37209..0000000000000000000000000000000000000000
--- a/third_party/WebKit/Source/platform/scheduler/CancellableTaskFactoryTest.cpp
+++ /dev/null
@@ -1,200 +0,0 @@
-// Copyright 2015 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#include "platform/scheduler/CancellableTaskFactory.h"
-
-#include "platform/heap/Handle.h"
-#include "testing/gtest/include/gtest/gtest.h"
-#include "wtf/PtrUtil.h"
-#include <memory>
-
-namespace blink {
-
-namespace {
-
-class TestCancellableTaskFactory final : public CancellableTaskFactory {
- public:
- explicit TestCancellableTaskFactory(std::unique_ptr<WTF::Closure> closure)
- : CancellableTaskFactory(std::move(closure)) {}
-};
-
-} // namespace
-
-using CancellableTaskFactoryTest = testing::Test;
-
-TEST_F(CancellableTaskFactoryTest, IsPending_TaskNotCreated) {
- TestCancellableTaskFactory factory(nullptr);
-
- EXPECT_FALSE(factory.isPending());
-}
-
-TEST_F(CancellableTaskFactoryTest, IsPending_TaskCreated) {
- TestCancellableTaskFactory factory(nullptr);
- std::unique_ptr<WebTaskRunner::Task> task =
- wrapUnique(factory.cancelAndCreate());
-
- EXPECT_TRUE(factory.isPending());
-}
-
-void EmptyFn() {}
-
-TEST_F(CancellableTaskFactoryTest, IsPending_TaskCreatedAndRun) {
- TestCancellableTaskFactory factory(WTF::bind(&EmptyFn));
- {
- std::unique_ptr<WebTaskRunner::Task> task =
- wrapUnique(factory.cancelAndCreate());
- task->run();
- }
-
- EXPECT_FALSE(factory.isPending());
-}
-
-TEST_F(CancellableTaskFactoryTest, IsPending_TaskCreatedAndDestroyed) {
- TestCancellableTaskFactory factory(nullptr);
- delete factory.cancelAndCreate();
-
- EXPECT_FALSE(factory.isPending());
-}
-
-TEST_F(CancellableTaskFactoryTest, IsPending_TaskCreatedAndCancelled) {
- TestCancellableTaskFactory factory(nullptr);
- std::unique_ptr<WebTaskRunner::Task> task =
- wrapUnique(factory.cancelAndCreate());
- factory.cancel();
-
- EXPECT_FALSE(factory.isPending());
-}
-
-void AddOne(int* ptr) {
- *ptr += 1;
-}
-
-TEST_F(CancellableTaskFactoryTest, Run_ClosureIsExecuted) {
- int executionCount = 0;
- TestCancellableTaskFactory factory(
- WTF::bind(&AddOne, WTF::unretained(&executionCount)));
- std::unique_ptr<WebTaskRunner::Task> task =
- wrapUnique(factory.cancelAndCreate());
- task->run();
-
- EXPECT_EQ(1, executionCount);
-}
-
-TEST_F(CancellableTaskFactoryTest, Run_ClosureIsExecutedOnlyOnce) {
- int executionCount = 0;
- TestCancellableTaskFactory factory(
- WTF::bind(&AddOne, WTF::unretained(&executionCount)));
- std::unique_ptr<WebTaskRunner::Task> task =
- wrapUnique(factory.cancelAndCreate());
- task->run();
- task->run();
- task->run();
- task->run();
-
- EXPECT_EQ(1, executionCount);
-}
-
-TEST_F(CancellableTaskFactoryTest, Run_FactoryDestructionPreventsExecution) {
- int executionCount = 0;
- std::unique_ptr<WebTaskRunner::Task> task;
- {
- TestCancellableTaskFactory factory(
- WTF::bind(&AddOne, WTF::unretained(&executionCount)));
- task = wrapUnique(factory.cancelAndCreate());
- }
- task->run();
-
- EXPECT_EQ(0, executionCount);
-}
-
-TEST_F(CancellableTaskFactoryTest, Run_TasksInSequence) {
- int executionCount = 0;
- TestCancellableTaskFactory factory(
- WTF::bind(&AddOne, WTF::unretained(&executionCount)));
-
- std::unique_ptr<WebTaskRunner::Task> taskA =
- wrapUnique(factory.cancelAndCreate());
- taskA->run();
- EXPECT_EQ(1, executionCount);
-
- std::unique_ptr<WebTaskRunner::Task> taskB =
- wrapUnique(factory.cancelAndCreate());
- taskB->run();
- EXPECT_EQ(2, executionCount);
-
- std::unique_ptr<WebTaskRunner::Task> taskC =
- wrapUnique(factory.cancelAndCreate());
- taskC->run();
- EXPECT_EQ(3, executionCount);
-}
-
-TEST_F(CancellableTaskFactoryTest, Cancel) {
- int executionCount = 0;
- TestCancellableTaskFactory factory(
- WTF::bind(&AddOne, WTF::unretained(&executionCount)));
- std::unique_ptr<WebTaskRunner::Task> task =
- wrapUnique(factory.cancelAndCreate());
- factory.cancel();
- task->run();
-
- EXPECT_EQ(0, executionCount);
-}
-
-TEST_F(CancellableTaskFactoryTest, CreatingANewTaskCancelsPreviousOnes) {
- int executionCount = 0;
- TestCancellableTaskFactory factory(
- WTF::bind(&AddOne, WTF::unretained(&executionCount)));
-
- std::unique_ptr<WebTaskRunner::Task> taskA =
- wrapUnique(factory.cancelAndCreate());
- std::unique_ptr<WebTaskRunner::Task> taskB =
- wrapUnique(factory.cancelAndCreate());
-
- taskA->run();
- EXPECT_EQ(0, executionCount);
-
- taskB->run();
- EXPECT_EQ(1, executionCount);
-}
-
-namespace {
-
-class GCObject final : public GarbageCollectedFinalized<GCObject> {
- public:
- GCObject()
- : m_factory(CancellableTaskFactory::create(this, &GCObject::run)) {}
-
- ~GCObject() { s_destructed++; }
-
- void run() { s_invoked++; }
-
- DEFINE_INLINE_TRACE() {}
-
- static int s_destructed;
- static int s_invoked;
-
- std::unique_ptr<CancellableTaskFactory> m_factory;
-};
-
-int GCObject::s_destructed = 0;
-int GCObject::s_invoked = 0;
-
-} // namespace
-
-TEST(CancellableTaskFactoryTest, GarbageCollectedWeak) {
- GCObject* object = new GCObject();
- std::unique_ptr<WebTaskRunner::Task> task =
- wrapUnique(object->m_factory->cancelAndCreate());
- object = nullptr;
- ThreadState::current()->collectAllGarbage();
- task->run();
- // The owning object will have been GCed and the task will have
- // lost its weak reference. Verify that it wasn't invoked.
- EXPECT_EQ(0, GCObject::s_invoked);
-
- // ..and just to make sure |object| was indeed destructed.
- EXPECT_EQ(1, GCObject::s_destructed);
-}
-
-} // namespace blink

Powered by Google App Engine
This is Rietveld 408576698