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

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

Issue 2947463002: [Extensions Bindings] Add a bindings/ subdirectory under renderer (Closed)
Patch Set: . Created 3 years, 5 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
« no previous file with comments | « extensions/renderer/api_binding_test.cc ('k') | extensions/renderer/api_binding_test_util.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright 2016 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_BINDING_TEST_UTIL_H_
6 #define EXTENSIONS_RENDERER_API_BINDING_TEST_UTIL_H_
7
8 #include <memory>
9 #include <string>
10
11 #include "base/strings/string_piece.h"
12 #include "v8/include/v8.h"
13
14 namespace base {
15 class DictionaryValue;
16 class ListValue;
17 class Value;
18 }
19
20 namespace extensions {
21
22 // Returns a string with all single quotes replaced with double quotes. Useful
23 // to write JSON strings without needing to escape quotes.
24 std::string ReplaceSingleQuotes(base::StringPiece str);
25
26 // Returns a base::Value parsed from |str|. EXPECTs the conversion to succeed.
27 std::unique_ptr<base::Value> ValueFromString(base::StringPiece str);
28
29 // As above, but returning a ListValue.
30 std::unique_ptr<base::ListValue> ListValueFromString(base::StringPiece str);
31
32 // As above, but returning a DictionaryValue.
33 std::unique_ptr<base::DictionaryValue> DictionaryValueFromString(
34 base::StringPiece str);
35
36 // Converts the given |value| to a JSON string. EXPECTs the conversion to
37 // succeed.
38 std::string ValueToString(const base::Value& value);
39
40 // Converts the given |value| to a string. Returns "empty", "undefined", "null",
41 // or "function" for unserializable values. Note this differs from
42 // gin::V8ToString, which only accepts v8::String values.
43 std::string V8ToString(v8::Local<v8::Value> value,
44 v8::Local<v8::Context> context);
45
46 // Returns a v8::Value result from compiling and running |source|, or an empty
47 // local on failure.
48 v8::Local<v8::Value> V8ValueFromScriptSource(v8::Local<v8::Context> context,
49 base::StringPiece source);
50
51 // Returns a v8::Function parsed from the given |source|. EXPECTs the conversion
52 // to succeed.
53 v8::Local<v8::Function> FunctionFromString(v8::Local<v8::Context> context,
54 base::StringPiece source);
55
56 // Converts the given |value| to a base::Value and returns the result.
57 std::unique_ptr<base::Value> V8ToBaseValue(v8::Local<v8::Value> value,
58 v8::Local<v8::Context> context);
59
60 // Calls the given |function| with the specified |receiver| and arguments, and
61 // returns the result. EXPECTs no errors to be thrown.
62 v8::Local<v8::Value> RunFunction(v8::Local<v8::Function> function,
63 v8::Local<v8::Context> context,
64 v8::Local<v8::Value> receiver,
65 int argc,
66 v8::Local<v8::Value> argv[]);
67
68 // Like RunFunction(), but uses v8::Undefined for the receiver.
69 v8::Local<v8::Value> RunFunction(v8::Local<v8::Function> function,
70 v8::Local<v8::Context> context,
71 int argc,
72 v8::Local<v8::Value> argv[]);
73
74 // Like RunFunction(), but uses the |context|'s Global for the receiver.
75 v8::Local<v8::Value> RunFunctionOnGlobal(v8::Local<v8::Function> function,
76 v8::Local<v8::Context> context,
77 int argc,
78 v8::Local<v8::Value> argv[]);
79
80 // Like RunFunctionOnGlobal(), but doesn't return the result. This is useful
81 // for binding in places a result isn't expected.
82 void RunFunctionOnGlobalAndIgnoreResult(v8::Local<v8::Function> function,
83 v8::Local<v8::Context> context,
84 int argc,
85 v8::Local<v8::Value> argv[]);
86
87 // Like RunFunctionOnGlobal(), but returns a persistent handle for the result.
88 v8::Global<v8::Value> RunFunctionOnGlobalAndReturnHandle(
89 v8::Local<v8::Function> function,
90 v8::Local<v8::Context> context,
91 int argc,
92 v8::Local<v8::Value> argv[]);
93
94 // Calls the given |function| with the specified |receiver| and arguments, but
95 // EXPECTs the function to throw the |expected_error|.
96 void RunFunctionAndExpectError(v8::Local<v8::Function> function,
97 v8::Local<v8::Context> context,
98 v8::Local<v8::Value> receiver,
99 int argc,
100 v8::Local<v8::Value> argv[],
101 const std::string& expected_error);
102
103 // Like RunFunctionAndExpectError(), but uses v8::Undefined for the receiver.
104 void RunFunctionAndExpectError(v8::Local<v8::Function> function,
105 v8::Local<v8::Context> context,
106 int argc,
107 v8::Local<v8::Value> argv[],
108 const std::string& expected_error);
109
110 // Returns the property with the given |key| from the |object|. EXPECTs the
111 // operation not throw an error, but doesn't assume the key is present.
112 v8::Local<v8::Value> GetPropertyFromObject(v8::Local<v8::Object> object,
113 v8::Local<v8::Context> context,
114 base::StringPiece key);
115
116 // As above, but converts the result to a base::Value.
117 std::unique_ptr<base::Value> GetBaseValuePropertyFromObject(
118 v8::Local<v8::Object> object,
119 v8::Local<v8::Context> context,
120 base::StringPiece key);
121
122 // As above, but returns a JSON-serialized version of the value, or
123 // "undefined", "null", "function", or "empty".
124 std::string GetStringPropertyFromObject(v8::Local<v8::Object> object,
125 v8::Local<v8::Context> context,
126 base::StringPiece key);
127
128 } // extensions
129
130 #endif // EXTENSIONS_RENDERER_API_BINDING_TEST_UTIL_H_
OLDNEW
« no previous file with comments | « extensions/renderer/api_binding_test.cc ('k') | extensions/renderer/api_binding_test_util.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698