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 #ifndef EXTENSIONS_BROWSER_PRELOAD_CHECK_TEST_UTIL_H_ | 5 #ifndef EXTENSIONS_BROWSER_PRELOAD_CHECK_TEST_UTIL_H_ |
6 #define EXTENSIONS_BROWSER_PRELOAD_CHECK_TEST_UTIL_H_ | 6 #define EXTENSIONS_BROWSER_PRELOAD_CHECK_TEST_UTIL_H_ |
7 | 7 |
8 #include <memory> | 8 #include <memory> |
9 | 9 |
10 #include "base/macros.h" | 10 #include "base/macros.h" |
(...skipping 11 matching lines...) Expand all Loading... |
22 public: | 22 public: |
23 PreloadCheckRunner(); | 23 PreloadCheckRunner(); |
24 virtual ~PreloadCheckRunner(); | 24 virtual ~PreloadCheckRunner(); |
25 | 25 |
26 // Starts the check, providing OnCheckComplete as the callback. | 26 // Starts the check, providing OnCheckComplete as the callback. |
27 void Run(PreloadCheck* check); | 27 void Run(PreloadCheck* check); |
28 | 28 |
29 // Starts the check and waits for its callback to execute. | 29 // Starts the check and waits for its callback to execute. |
30 void RunUntilComplete(PreloadCheck* check); | 30 void RunUntilComplete(PreloadCheck* check); |
31 | 31 |
32 // Runs the message loop until OnCheckComplete is called. | |
33 void WaitForCompletion(); | |
34 | |
35 // Runs the message loop until idle. Useful to see whether OnCheckComplete is | 32 // Runs the message loop until idle. Useful to see whether OnCheckComplete is |
36 // called without waiting indefinitely. | 33 // called without waiting indefinitely. |
37 void WaitForIdle(); | 34 void WaitForIdle(); |
38 | 35 |
| 36 // Runs the message loop until OnCheckComplete is called. |
| 37 void WaitForComplete(); |
| 38 |
39 PreloadCheck::ResultCallback GetCallback(); | 39 PreloadCheck::ResultCallback GetCallback(); |
40 | 40 |
41 const PreloadCheck::Errors& errors() const { return errors_; } | 41 const PreloadCheck::Errors& errors() const { return errors_; } |
42 bool called() const { return called_; } | 42 bool called() const { return called_; } |
43 | 43 |
44 private: | 44 private: |
45 void OnCheckComplete(PreloadCheck::Errors errors); | 45 void OnCheckComplete(PreloadCheck::Errors errors); |
46 | 46 |
47 PreloadCheck::Errors errors_; | 47 PreloadCheck::Errors errors_; |
48 bool called_; | 48 bool called_; |
49 | 49 |
50 // Using a RunLoop data member would trigger tricky timing troubles. | 50 // Using a RunLoop data member would trigger tricky timing troubles. |
51 std::unique_ptr<base::RunLoop> run_loop_; | 51 std::unique_ptr<base::RunLoop> run_loop_; |
52 | 52 |
53 DISALLOW_COPY_AND_ASSIGN(PreloadCheckRunner); | 53 DISALLOW_COPY_AND_ASSIGN(PreloadCheckRunner); |
54 }; | 54 }; |
55 | 55 |
56 // Stub for a PreloadCheck that returns the desired error(s). | 56 // Stub for a PreloadCheck that returns the desired error(s). |
57 class PreloadCheckStub : public PreloadCheck { | 57 class PreloadCheckStub : public PreloadCheck { |
58 public: | 58 public: |
59 explicit PreloadCheckStub(bool is_async = false); | 59 PreloadCheckStub(bool is_async = false, const Errors& errors = Errors()); |
60 ~PreloadCheckStub() override; | 60 ~PreloadCheckStub() override; |
61 | 61 |
62 void AddError(Error error); | 62 void AddError(Error error); |
63 void set_error_message(const base::string16& message) { message_ = message; } | 63 void set_error_message(const base::string16& message) { message_ = message; } |
| 64 bool started() const { return started_; } |
64 | 65 |
65 // PreloadCheck: | 66 // PreloadCheck: |
66 void Start(ResultCallback callback) override; | 67 void Start(ResultCallback callback) override; |
67 base::string16 GetErrorMessage() const override; | 68 // base::string16 GetErrorMessage() const override; |
68 | 69 |
69 private: | 70 private: |
70 void StartInternal(ResultCallback callback); | 71 void StartInternal(ResultCallback callback); |
71 | 72 |
72 bool is_async_; | 73 bool is_async_; |
73 Errors errors_; | 74 Errors errors_; |
74 base::string16 message_; | 75 base::string16 message_; |
| 76 bool started_; |
75 | 77 |
76 DISALLOW_COPY_AND_ASSIGN(PreloadCheckStub); | 78 DISALLOW_COPY_AND_ASSIGN(PreloadCheckStub); |
77 }; | 79 }; |
78 | 80 |
79 } // namespace extensions | 81 } // namespace extensions |
80 | 82 |
81 #endif // EXTENSIONS_BROWSER_PRELOAD_CHECK_TEST_UTIL_H_ | 83 #endif // EXTENSIONS_BROWSER_PRELOAD_CHECK_TEST_UTIL_H_ |
OLD | NEW |