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_RENDERER_API_BINDINGS_SYSTEM_UNITTEST_H_ | 5 #ifndef EXTENSIONS_RENDERER_API_BINDINGS_SYSTEM_UNITTEST_H_ |
6 #define EXTENSIONS_RENDERER_API_BINDINGS_SYSTEM_UNITTEST_H_ | 6 #define EXTENSIONS_RENDERER_API_BINDINGS_SYSTEM_UNITTEST_H_ |
7 | 7 |
8 #include <map> | 8 #include <map> |
9 #include <memory> | 9 #include <memory> |
10 #include <string> | 10 #include <string> |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
53 // Stores the request in |last_request_|. | 53 // Stores the request in |last_request_|. |
54 void OnAPIRequest(std::unique_ptr<APIRequestHandler::Request> request, | 54 void OnAPIRequest(std::unique_ptr<APIRequestHandler::Request> request, |
55 v8::Local<v8::Context> context); | 55 v8::Local<v8::Context> context); |
56 | 56 |
57 // Checks that |last_request_| exists and was provided with the | 57 // Checks that |last_request_| exists and was provided with the |
58 // |expected_name| and |expected_arguments|. | 58 // |expected_name| and |expected_arguments|. |
59 void ValidateLastRequest(const std::string& expected_name, | 59 void ValidateLastRequest(const std::string& expected_name, |
60 const std::string& expected_arguments); | 60 const std::string& expected_arguments); |
61 | 61 |
62 // Wraps the given |script source| in (function(obj) { ... }) and executes | 62 // Wraps the given |script source| in (function(obj) { ... }) and executes |
63 // the result function, passing in |object| for an argument. | 63 // the result function, passing in |object| for an argument. Returns the |
64 void CallFunctionOnObject(v8::Local<v8::Context> context, | 64 // result of calling the function. |
65 v8::Local<v8::Object> object, | 65 v8::Local<v8::Value> CallFunctionOnObject(v8::Local<v8::Context> context, |
66 const std::string& script_source); | 66 v8::Local<v8::Object> object, |
| 67 const std::string& script_source); |
67 | 68 |
68 const APIRequestHandler::Request* last_request() const { | 69 const APIRequestHandler::Request* last_request() const { |
69 return last_request_.get(); | 70 return last_request_.get(); |
70 } | 71 } |
71 void reset_last_request() { last_request_.reset(); } | 72 void reset_last_request() { last_request_.reset(); } |
72 APIBindingsSystem* bindings_system() { return bindings_system_.get(); } | 73 APIBindingsSystem* bindings_system() { return bindings_system_.get(); } |
73 | 74 |
74 private: | 75 private: |
75 // The API schemas for the fake APIs. | 76 // The API schemas for the fake APIs. |
76 std::map<std::string, std::unique_ptr<base::DictionaryValue>> api_schemas_; | 77 std::map<std::string, std::unique_ptr<base::DictionaryValue>> api_schemas_; |
77 | 78 |
78 // The APIBindingsSystem associated with the test. Safe to use across multiple | 79 // The APIBindingsSystem associated with the test. Safe to use across multiple |
79 // contexts. | 80 // contexts. |
80 std::unique_ptr<APIBindingsSystem> bindings_system_; | 81 std::unique_ptr<APIBindingsSystem> bindings_system_; |
81 | 82 |
82 // The last request to be received from the APIBindingsSystem, or null if | 83 // The last request to be received from the APIBindingsSystem, or null if |
83 // there is none. | 84 // there is none. |
84 std::unique_ptr<APIRequestHandler::Request> last_request_; | 85 std::unique_ptr<APIRequestHandler::Request> last_request_; |
85 | 86 |
86 DISALLOW_COPY_AND_ASSIGN(APIBindingsSystemTest); | 87 DISALLOW_COPY_AND_ASSIGN(APIBindingsSystemTest); |
87 }; | 88 }; |
88 | 89 |
89 } // namespace extensions | 90 } // namespace extensions |
90 | 91 |
91 #endif // EXTENSIONS_RENDERER_API_BINDINGS_SYSTEM_UNITTEST_H_ | 92 #endif // EXTENSIONS_RENDERER_API_BINDINGS_SYSTEM_UNITTEST_H_ |
OLD | NEW |