OLD | NEW |
1 // Copyright 2017 The Chromium Authors. All rights reserved. | 1 // Copyright 2017 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "extensions/browser/preload_check_test_util.h" | 5 #include "extensions/browser/preload_check_test_util.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/bind_helpers.h" | 8 #include "base/bind_helpers.h" |
9 #include "base/logging.h" | 9 #include "base/logging.h" |
10 #include "base/memory/ptr_util.h" | 10 #include "base/memory/ptr_util.h" |
(...skipping 18 matching lines...) Expand all Loading... |
29 } | 29 } |
30 | 30 |
31 void PreloadCheckRunner::Run(PreloadCheck* check) { | 31 void PreloadCheckRunner::Run(PreloadCheck* check) { |
32 check->Start(GetCallback()); | 32 check->Start(GetCallback()); |
33 } | 33 } |
34 | 34 |
35 void PreloadCheckRunner::RunUntilComplete(PreloadCheck* check) { | 35 void PreloadCheckRunner::RunUntilComplete(PreloadCheck* check) { |
36 Run(check); | 36 Run(check); |
37 ASSERT_FALSE(called_); | 37 ASSERT_FALSE(called_); |
38 | 38 |
39 run_loop_ = base::MakeUnique<base::RunLoop>(); | 39 WaitForComplete(); |
40 run_loop_->Run(); | |
41 ASSERT_TRUE(called_); | 40 ASSERT_TRUE(called_); |
42 } | 41 } |
43 | 42 |
44 PreloadCheck::ResultCallback PreloadCheckRunner::GetCallback() { | 43 PreloadCheck::ResultCallback PreloadCheckRunner::GetCallback() { |
45 return base::Bind(&PreloadCheckRunner::OnCheckComplete, | 44 return base::Bind(&PreloadCheckRunner::OnCheckComplete, |
46 base::Unretained(this)); | 45 base::Unretained(this)); |
47 } | 46 } |
48 | 47 |
49 void PreloadCheckRunner::WaitForIdle() { | 48 void PreloadCheckRunner::WaitForIdle() { |
50 run_loop_ = base::MakeUnique<base::RunLoop>(); | 49 run_loop_ = base::MakeUnique<base::RunLoop>(); |
51 run_loop_->RunUntilIdle(); | 50 run_loop_->RunUntilIdle(); |
52 } | 51 } |
53 | 52 |
| 53 void PreloadCheckRunner::WaitForComplete() { |
| 54 run_loop_ = base::MakeUnique<base::RunLoop>(); |
| 55 run_loop_->Run(); |
| 56 } |
| 57 |
54 // PreloadCheckStub: | 58 // PreloadCheckStub: |
55 PreloadCheckStub::PreloadCheckStub(bool is_async) | 59 PreloadCheckStub::PreloadCheckStub(bool is_async, const Errors& errors) |
56 : PreloadCheck(nullptr), is_async_(is_async) {} | 60 : PreloadCheck(nullptr), |
| 61 is_async_(is_async), |
| 62 errors_(errors), |
| 63 started_(false) {} |
57 | 64 |
58 PreloadCheckStub::~PreloadCheckStub() {} | 65 PreloadCheckStub::~PreloadCheckStub() {} |
59 | 66 |
60 void PreloadCheckStub::AddError(Error error) { | 67 void PreloadCheckStub::AddError(Error error) { |
61 errors_.insert(error); | 68 errors_.insert(error); |
62 } | 69 } |
63 | 70 |
64 void PreloadCheckStub::Start(ResultCallback callback) { | 71 void PreloadCheckStub::Start(ResultCallback callback) { |
65 DCHECK(!callback.is_null()); | 72 DCHECK(!callback.is_null()); |
| 73 started_ = true; |
66 if (is_async_) { | 74 if (is_async_) { |
67 base::ThreadTaskRunnerHandle::Get()->PostTask( | 75 base::ThreadTaskRunnerHandle::Get()->PostTask( |
68 FROM_HERE, base::Bind(&PreloadCheckStub::StartInternal, | 76 FROM_HERE, base::Bind(&PreloadCheckStub::StartInternal, |
69 base::Unretained(this), base::Passed(&callback))); | 77 base::Unretained(this), base::Passed(&callback))); |
70 } else { | 78 } else { |
71 StartInternal(std::move(callback)); | 79 StartInternal(std::move(callback)); |
72 } | 80 } |
73 } | 81 } |
74 | 82 |
75 void PreloadCheckStub::StartInternal(ResultCallback callback) { | 83 void PreloadCheckStub::StartInternal(ResultCallback callback) { |
76 std::move(callback).Run(errors_); | 84 std::move(callback).Run(errors_); |
77 } | 85 } |
78 | 86 |
| 87 /* |
79 base::string16 PreloadCheckStub::GetErrorMessage() const { | 88 base::string16 PreloadCheckStub::GetErrorMessage() const { |
80 return message_; | 89 return message_; |
81 } | 90 } |
| 91 */ |
82 | 92 |
83 } // namespace extensions | 93 } // namespace extensions |
OLD | NEW |