1 // 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.
5 #include "net/base/test_completion_callback.h"
8 #include "base/bind_helpers.h"
9 #include "base/compiler_specific.h"
10 #include "base/run_loop.h"
11 #include "net/base/io_buffer.h"
17 void TestCompletionCallbackBaseInternal::DidSetResult() {
23 void TestCompletionCallbackBaseInternal::WaitForResult() {
26 run_loop_
.reset(new base::RunLoop());
30 // A huge number of tests depend on this class running events after the
32 // TODO(mmenke): We really should fix this.
33 base::RunLoop().RunUntilIdle();
35 have_result_
= false; // Auto-reset for next callback.
38 TestCompletionCallbackBaseInternal::TestCompletionCallbackBaseInternal()
39 : have_result_(false) {
42 TestCompletionCallbackBaseInternal::~TestCompletionCallbackBaseInternal() {
45 } // namespace internal
47 TestClosure::TestClosure()
48 : closure_(base::Bind(&TestClosure::DidSetResult
, base::Unretained(this))) {
51 TestClosure::~TestClosure() {
54 TestCompletionCallback::TestCompletionCallback()
55 : callback_(base::Bind(&TestCompletionCallback::SetResult
,
56 base::Unretained(this))) {
59 TestCompletionCallback::~TestCompletionCallback() {
62 TestInt64CompletionCallback::TestInt64CompletionCallback()
63 : callback_(base::Bind(&TestInt64CompletionCallback::SetResult
,
64 base::Unretained(this))) {
67 TestInt64CompletionCallback::~TestInt64CompletionCallback() {
70 ReleaseBufferCompletionCallback::ReleaseBufferCompletionCallback(
71 IOBuffer
* buffer
) : buffer_(buffer
) {
74 ReleaseBufferCompletionCallback::~ReleaseBufferCompletionCallback() {
77 void ReleaseBufferCompletionCallback::SetResult(int result
) {
78 if (!buffer_
->HasOneRef())
80 TestCompletionCallback::SetResult(result
);