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