Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(661)

Side by Side Diff: extensions/renderer/api_bindings_system_unittest.h

Issue 2947463002: [Extensions Bindings] Add a bindings/ subdirectory under renderer (Closed)
Patch Set: . Created 3 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(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_RENDERER_API_BINDINGS_SYSTEM_UNITTEST_H_
6 #define EXTENSIONS_RENDERER_API_BINDINGS_SYSTEM_UNITTEST_H_
7
8 #include <map>
9 #include <memory>
10 #include <string>
11
12 #include "base/macros.h"
13 #include "extensions/renderer/api_binding_test.h"
14 #include "extensions/renderer/api_binding_types.h"
15 #include "extensions/renderer/api_request_handler.h"
16 #include "v8/include/v8.h"
17
18 namespace base {
19 class DictionaryValue;
20 }
21
22 namespace extensions {
23 class APIBindingsSystem;
24
25 // The base class to test the APIBindingsSystem. This allows subclasses to
26 // retrieve API schemas differently.
27 class APIBindingsSystemTest : public APIBindingTest {
28 protected:
29 // A struct representing a "fake" API, including the name and specification.
30 // The specification is expected to be a JSON-serializable string that
31 // specifies the types, methods, and events of an API in the same syntax as
32 // the real extension APIs.
33 struct FakeSpec {
34 const char* name;
35 const char* spec;
36 };
37
38 APIBindingsSystemTest();
39 ~APIBindingsSystemTest() override;
40 void SetUp() override;
41 void TearDown() override;
42 void OnWillDisposeContext(v8::Local<v8::Context> context) override;
43
44 // Returns the collection of fake APIs to be used in the test, allowing
45 // subclasses to return their own specifications.
46 virtual std::vector<FakeSpec> GetAPIs();
47
48 // Returns the object to be used as the parent for the `lastError`. The
49 // default returns an empty JS object (assumes no last errors will be set).
50 virtual v8::Local<v8::Object> GetLastErrorParent(
51 v8::Local<v8::Context> context);
52
53 // Returns the DictionaryValue representing the schema with the given API
54 // name.
55 const base::DictionaryValue& GetAPISchema(const std::string& api_name);
56
57 // Callback for event listeners changing.
58 void OnEventListenersChanged(const std::string& event_name,
59 binding::EventListenersChanged changed,
60 const base::DictionaryValue* filter,
61 bool was_manual,
62 v8::Local<v8::Context> context);
63
64 // Callback for an API request being made. Stores the request in
65 // |last_request_|.
66 void OnAPIRequest(std::unique_ptr<APIRequestHandler::Request> request,
67 v8::Local<v8::Context> context);
68
69 // Checks that |last_request_| exists and was provided with the
70 // |expected_name| and |expected_arguments|.
71 void ValidateLastRequest(const std::string& expected_name,
72 const std::string& expected_arguments);
73
74 // Wraps the given |script source| in (function(obj) { ... }) and executes
75 // the result function, passing in |object| for an argument. Returns the
76 // result of calling the function.
77 v8::Local<v8::Value> CallFunctionOnObject(v8::Local<v8::Context> context,
78 v8::Local<v8::Object> object,
79 const std::string& script_source);
80
81 const APIRequestHandler::Request* last_request() const {
82 return last_request_.get();
83 }
84 void reset_last_request() { last_request_.reset(); }
85 APIBindingsSystem* bindings_system() { return bindings_system_.get(); }
86
87 private:
88 // The API schemas for the fake APIs.
89 std::map<std::string, std::unique_ptr<base::DictionaryValue>> api_schemas_;
90
91 // The APIBindingsSystem associated with the test. Safe to use across multiple
92 // contexts.
93 std::unique_ptr<APIBindingsSystem> bindings_system_;
94
95 // The last request to be received from the APIBindingsSystem, or null if
96 // there is none.
97 std::unique_ptr<APIRequestHandler::Request> last_request_;
98
99 DISALLOW_COPY_AND_ASSIGN(APIBindingsSystemTest);
100 };
101
102 } // namespace extensions
103
104 #endif // EXTENSIONS_RENDERER_API_BINDINGS_SYSTEM_UNITTEST_H_
OLDNEW
« no previous file with comments | « extensions/renderer/api_bindings_system.cc ('k') | extensions/renderer/api_bindings_system_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698