OLD | NEW |
(Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "extensions/browser/preload_check_test_util.h" |
| 6 |
| 7 #include "base/bind.h" |
| 8 #include "base/bind_helpers.h" |
| 9 #include "base/logging.h" |
| 10 #include "base/memory/ptr_util.h" |
| 11 #include "base/run_loop.h" |
| 12 #include "testing/gtest/include/gtest/gtest.h" |
| 13 |
| 14 namespace extensions { |
| 15 |
| 16 PreloadCheckRunner::PreloadCheckRunner() : called_(false) {} |
| 17 PreloadCheckRunner::~PreloadCheckRunner() {} |
| 18 |
| 19 void PreloadCheckRunner::OnCheckComplete(PreloadCheck::Errors errors) { |
| 20 ASSERT_FALSE(called_); |
| 21 called_ = true; |
| 22 errors_ = errors; |
| 23 if (run_loop_) |
| 24 run_loop_->Quit(); |
| 25 } |
| 26 |
| 27 void PreloadCheckRunner::Run(PreloadCheck* check) { |
| 28 check->Start(GetCallback()); |
| 29 } |
| 30 |
| 31 void PreloadCheckRunner::RunUntilComplete(PreloadCheck* check) { |
| 32 Run(check); |
| 33 ASSERT_FALSE(called_); |
| 34 |
| 35 run_loop_ = base::MakeUnique<base::RunLoop>(); |
| 36 run_loop_->Run(); |
| 37 ASSERT_TRUE(called_); |
| 38 } |
| 39 |
| 40 PreloadCheck::ResultCallback PreloadCheckRunner::GetCallback() { |
| 41 return base::Bind(&PreloadCheckRunner::OnCheckComplete, |
| 42 base::Unretained(this)); |
| 43 } |
| 44 |
| 45 void PreloadCheckRunner::WaitForIdle() { |
| 46 run_loop_ = base::MakeUnique<base::RunLoop>(); |
| 47 run_loop_->RunUntilIdle(); |
| 48 } |
| 49 |
| 50 } // namespace extensions |
OLD | NEW |