[Android WebView] Fix webview perf bot switchover to use org.chromium.webview_shell...
[chromium-blink-merge.git] / net / base / test_completion_callback.cc
blob0765850367389f1390e8c9365da56897435f70c6
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"
7 #include "base/bind.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"
13 namespace net {
15 namespace internal {
17 void TestCompletionCallbackBaseInternal::DidSetResult() {
18 have_result_ = true;
19 if (run_loop_)
20 run_loop_->Quit();
23 void TestCompletionCallbackBaseInternal::WaitForResult() {
24 DCHECK(!run_loop_);
25 if (!have_result_) {
26 run_loop_.reset(new base::RunLoop());
27 run_loop_->Run();
28 run_loop_.reset();
29 DCHECK(have_result_);
30 // A huge number of tests depend on this class running events after the
31 // result is set.
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())
79 result = ERR_FAILED;
80 TestCompletionCallback::SetResult(result);
83 } // namespace net