blob: 8664bf73306f17c73d9136008d5259265671f767 [file] [log] [blame]
[email protected]ef948e62012-09-04 22:27:431// Copyright (c) 2012 The Chromium Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#include "base/bind.h"
6#include "base/memory/ref_counted.h"
[email protected]f368eeb2013-07-17 23:53:327#include "base/message_loop/message_loop.h"
fdoray2ad58be2016-06-22 20:36:168#include "base/run_loop.h"
9#include "base/single_thread_task_runner.h"
[email protected]ef948e62012-09-04 22:27:4310#include "remoting/base/auto_thread_task_runner.h"
11#include "testing/gtest/include/gtest/gtest.h"
12
13namespace {
14
[email protected]3d871d92012-12-07 07:36:4515void SetFlagTask(bool* success) {
[email protected]ef948e62012-09-04 22:27:4316 *success = true;
17}
18
19} // namespace
20
21namespace remoting {
22
[email protected]3d871d92012-12-07 07:36:4523TEST(AutoThreadTaskRunnerTest, StartAndStop) {
[email protected]ef948e62012-09-04 22:27:4324 // Create a task runner.
[email protected]faea9d2d2013-04-30 03:18:4425 base::MessageLoop message_loop;
26 scoped_refptr<AutoThreadTaskRunner> task_runner = new AutoThreadTaskRunner(
ki.stfu659c758f2015-10-12 20:10:0627 message_loop.task_runner(), base::MessageLoop::QuitWhenIdleClosure());
[email protected]ef948e62012-09-04 22:27:4328
29 // Post a task to make sure it is executed.
30 bool success = false;
fdoray2ad58be2016-06-22 20:36:1631 message_loop.task_runner()->PostTask(FROM_HERE,
32 base::Bind(&SetFlagTask, &success));
[email protected]ef948e62012-09-04 22:27:4333
34 task_runner = NULL;
fdoray2ad58be2016-06-22 20:36:1635 base::RunLoop().Run();
[email protected]ef948e62012-09-04 22:27:4336 EXPECT_TRUE(success);
37}
38
[email protected]ef948e62012-09-04 22:27:4339} // namespace remoting