summaryrefslogtreecommitdiff
path: root/chromium/third_party/blink/renderer/platform/scheduler/common/background_scheduler_unittest.cc
blob: bcd2372cda496fc11a84e37f454c91b9ff325e4a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
// 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 "third_party/blink/renderer/platform/scheduler/public/background_scheduler.h"

#include <memory>
#include "base/location.h"
#include "base/test/scoped_task_environment.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "third_party/blink/renderer/platform/cross_thread_functional.h"
#include "third_party/blink/renderer/platform/waitable_event.h"

namespace blink {

namespace {

void PingPongTask(WaitableEvent* done_event) {
  done_event->Signal();
}

}  // namespace

TEST(BackgroundSchedulerTest, RunOnBackgroundThread) {
  base::test::ScopedTaskEnvironment scoped_task_environment;
  std::unique_ptr<WaitableEvent> done_event = std::make_unique<WaitableEvent>();
  background_scheduler::PostOnBackgroundThread(
      FROM_HERE,
      CrossThreadBind(&PingPongTask, CrossThreadUnretained(done_event.get())));
  // Test passes by not hanging on the following wait().
  done_event->Wait();
}

}  // namespace blink