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 #ifndef EXTENSIONS_BROWSER_PRELOAD_CHECK_TEST_UTIL_H_ |
| 6 #define EXTENSIONS_BROWSER_PRELOAD_CHECK_TEST_UTIL_H_ |
| 7 |
| 8 #include <memory> |
| 9 |
| 10 #include "extensions/browser/preload_check.h" |
| 11 |
| 12 namespace base { |
| 13 class RunLoop; |
| 14 } |
| 15 |
| 16 namespace extensions { |
| 17 |
| 18 // Provides a callback method for a PreloadCheck that stores its results. |
| 19 class PreloadCheckRunner { |
| 20 public: |
| 21 PreloadCheckRunner(); |
| 22 virtual ~PreloadCheckRunner(); |
| 23 |
| 24 // Starts the check, providing OnCheckComplete as the callback. |
| 25 void Run(PreloadCheck* check); |
| 26 |
| 27 // Starts the check and waits for its callback to execute. |
| 28 void RunUntilComplete(PreloadCheck* check); |
| 29 |
| 30 // Runs the message loop until OnCheckComplete is called. |
| 31 void WaitForCompletion(); |
| 32 |
| 33 // Runs the message loop until idle. Useful to see whether OnCheckComplete is |
| 34 // called without waiting indefinitely. |
| 35 void WaitForIdle(); |
| 36 |
| 37 PreloadCheck::ResultCallback GetCallback(); |
| 38 |
| 39 const PreloadCheck::Errors& errors() const { return errors_; } |
| 40 bool called() const { return called_; } |
| 41 |
| 42 private: |
| 43 void OnCheckComplete(PreloadCheck::Errors errors); |
| 44 |
| 45 PreloadCheck::Errors errors_; |
| 46 bool called_; |
| 47 |
| 48 // Using a RunLoop data member would trigger tricky timing troubles. |
| 49 std::unique_ptr<base::RunLoop> run_loop_; |
| 50 |
| 51 DISALLOW_COPY_AND_ASSIGN(PreloadCheckRunner); |
| 52 }; |
| 53 |
| 54 } // namespace extensions |
| 55 |
| 56 #endif // EXTENSIONS_BROWSER_PRELOAD_CHECK_TEST_UTIL_H_ |
OLD | NEW |