blob: ec1e6240d6cab20bb0078569c89f15d418a56b16 [file] [log] [blame]
// 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/threading/BackgroundTaskRunner.h"
#include "platform/ThreadSafeFunctional.h"
#include "platform/WaitableEvent.h"
#include "public/platform/WebTraceLocation.h"
#include "testing/gtest/include/gtest/gtest.h"
namespace {
using namespace blink;
void PingPongTask(WaitableEvent* doneEvent)
{
doneEvent->signal();
}
class BackgroundTaskRunnerTest : public testing::Test {
};
TEST_F(BackgroundTaskRunnerTest, RunShortTaskOnBackgroundThread)
{
OwnPtr<WaitableEvent> doneEvent = adoptPtr(new WaitableEvent());
BackgroundTaskRunner::postOnBackgroundThread(BLINK_FROM_HERE, threadSafeBind(&PingPongTask, AllowCrossThreadAccess(doneEvent.get())), BackgroundTaskRunner::TaskSizeShortRunningTask);
// Test passes by not hanging on the following wait().
doneEvent->wait();
}
TEST_F(BackgroundTaskRunnerTest, RunLongTaskOnBackgroundThread)
{
OwnPtr<WaitableEvent> doneEvent = adoptPtr(new WaitableEvent());
BackgroundTaskRunner::postOnBackgroundThread(BLINK_FROM_HERE, threadSafeBind(&PingPongTask, AllowCrossThreadAccess(doneEvent.get())), BackgroundTaskRunner::TaskSizeLongRunningTask);
// Test passes by not hanging on the following wait().
doneEvent->wait();
}
} // unnamed namespace