summaryrefslogtreecommitdiffstats
path: root/base/test/thread_test_helper.cc
blob: ad240b382f9937dcd1915bbd1a8dd9a4ce61ed3e (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
35
36
// Copyright (c) 2011 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 "base/test/thread_test_helper.h"

#include "base/bind.h"
#include "base/location.h"

namespace base {

ThreadTestHelper::ThreadTestHelper(MessageLoopProxy* target_thread)
    : test_result_(false),
      target_thread_(target_thread),
      done_event_(false, false) {
}

bool ThreadTestHelper::Run() {
  if (!target_thread_->PostTask(
          FROM_HERE, base::Bind(&ThreadTestHelper::RunInThread, this))) {
    return false;
  }
  done_event_.Wait();
  return test_result_;
}

void ThreadTestHelper::RunTest() { set_test_result(true); }

ThreadTestHelper::~ThreadTestHelper() {}

void ThreadTestHelper::RunInThread() {
  RunTest();
  done_event_.Signal();
}

}  // namespace base