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" | |
11 #include "base/memory/weak_ptr.h" | |
12 #include "base/strings/string16.h" | |
10 #include "extensions/browser/preload_check.h" | 13 #include "extensions/browser/preload_check.h" |
11 | 14 |
12 namespace base { | 15 namespace base { |
13 class RunLoop; | 16 class RunLoop; |
14 } | 17 } |
15 | 18 |
16 namespace extensions { | 19 namespace extensions { |
17 | 20 |
18 // Provides a callback method for a PreloadCheck that stores its results. | 21 // Provides a callback method for a PreloadCheck that stores its results. |
19 class PreloadCheckRunner { | 22 class PreloadCheckRunner { |
(...skipping 24 matching lines...) Expand all Loading... | |
44 | 47 |
45 PreloadCheck::Errors errors_; | 48 PreloadCheck::Errors errors_; |
46 bool called_; | 49 bool called_; |
47 | 50 |
48 // Using a RunLoop data member would trigger tricky timing troubles. | 51 // Using a RunLoop data member would trigger tricky timing troubles. |
49 std::unique_ptr<base::RunLoop> run_loop_; | 52 std::unique_ptr<base::RunLoop> run_loop_; |
50 | 53 |
51 DISALLOW_COPY_AND_ASSIGN(PreloadCheckRunner); | 54 DISALLOW_COPY_AND_ASSIGN(PreloadCheckRunner); |
52 }; | 55 }; |
53 | 56 |
57 // Stub for a PreloadCheck that returns the desired error(s). | |
58 class PreloadCheckStub : public PreloadCheck { | |
59 public: | |
60 PreloadCheckStub(); | |
61 ~PreloadCheckStub() override; | |
62 | |
63 void AddError(Error error); | |
64 void set_error_message(const base::string16& message) { message_ = message; } | |
65 | |
66 bool is_async() const { return is_async_; } | |
67 void set_is_async(bool is_async) { is_async_ = is_async; } | |
68 | |
69 // PreloadCheck: | |
70 void Start(ResultCallback callback) override; | |
71 base::string16 GetErrorMessage() const override; | |
72 | |
73 private: | |
74 void RunCallback(ResultCallback callback); | |
75 | |
76 // Defaults to false. | |
Devlin
2017/03/24 16:21:48
optional: if you use c++11 fanciness and inline th
michaelpg
2017/03/24 21:48:28
Cool! Done in a couple other places.
| |
77 bool is_async_; | |
78 Errors errors_; | |
79 base::string16 message_; | |
80 | |
81 base::WeakPtrFactory<PreloadCheckStub> weak_ptr_factory_; | |
82 | |
83 DISALLOW_COPY_AND_ASSIGN(PreloadCheckStub); | |
84 }; | |
85 | |
54 } // namespace extensions | 86 } // namespace extensions |
55 | 87 |
56 #endif // EXTENSIONS_BROWSER_PRELOAD_CHECK_TEST_UTIL_H_ | 88 #endif // EXTENSIONS_BROWSER_PRELOAD_CHECK_TEST_UTIL_H_ |
OLD | NEW |