OLD | NEW |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 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 | 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 #include "base/bind.h" | 5 #include "base/bind.h" |
6 #include "base/memory/ptr_util.h" | 6 #include "base/memory/ptr_util.h" |
7 #include "base/stl_util.h" | 7 #include "base/stl_util.h" |
8 #include "base/strings/stringprintf.h" | 8 #include "base/strings/stringprintf.h" |
9 #include "base/values.h" | 9 #include "base/values.h" |
10 #include "extensions/renderer/api_binding.h" | 10 #include "extensions/renderer/api_binding.h" |
(...skipping 1133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1144 } | 1144 } |
1145 }; | 1145 }; |
1146 | 1146 |
1147 check_supports_filters("unfilteredOne", false); | 1147 check_supports_filters("unfilteredOne", false); |
1148 check_supports_filters("unfilteredTwo", false); | 1148 check_supports_filters("unfilteredTwo", false); |
1149 check_supports_filters("unfilteredThree", false); | 1149 check_supports_filters("unfilteredThree", false); |
1150 check_supports_filters("filteredOne", true); | 1150 check_supports_filters("filteredOne", true); |
1151 check_supports_filters("filteredTwo", true); | 1151 check_supports_filters("filteredTwo", true); |
1152 } | 1152 } |
1153 | 1153 |
| 1154 TEST_F(APIBindingUnittest, HooksTemplateInitializer) { |
| 1155 SetFunctions(kFunctions); |
| 1156 |
| 1157 // Register a hook for the test.oneString method. |
| 1158 auto hooks = base::MakeUnique<APIBindingHooksTestDelegate>(); |
| 1159 auto hook = [](v8::Isolate* isolate, |
| 1160 v8::Local<v8::ObjectTemplate> object_template, |
| 1161 const APITypeReferenceMap& type_refs) { |
| 1162 object_template->Set(gin::StringToSymbol(isolate, "hookedProperty"), |
| 1163 gin::ConvertToV8(isolate, 42)); |
| 1164 }; |
| 1165 hooks->SetTemplateInitializer(base::Bind(hook)); |
| 1166 SetHooksDelegate(std::move(hooks)); |
| 1167 |
| 1168 InitializeBinding(); |
| 1169 |
| 1170 v8::HandleScope handle_scope(isolate()); |
| 1171 v8::Local<v8::Context> context = MainContext(); |
| 1172 |
| 1173 v8::Local<v8::Object> binding_object = |
| 1174 binding()->CreateInstance(context, base::Bind(&AllowAllAPIs)); |
| 1175 |
| 1176 // The extra property should be present on the binding object. |
| 1177 EXPECT_EQ("42", GetStringPropertyFromObject(binding_object, context, |
| 1178 "hookedProperty")); |
| 1179 // Sanity check: other values should still be there. |
| 1180 EXPECT_EQ("function", |
| 1181 GetStringPropertyFromObject(binding_object, context, "oneString")); |
| 1182 } |
| 1183 |
1154 } // namespace extensions | 1184 } // namespace extensions |
OLD | NEW |