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

Side by Side Diff: extensions/renderer/api_binding_unittest.cc

Issue 2697363003: [Extensions Bindings] Move request dispatch to APIRequestHandler (Closed)
Patch Set: . Created 3 years, 10 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
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 108 matching lines...) Expand 10 before | Expand all | Expand 10 after
119 } 119 }
120 120
121 void OnEventListenersChanged(const std::string& event_name, 121 void OnEventListenersChanged(const std::string& event_name,
122 binding::EventListenersChanged change, 122 binding::EventListenersChanged change,
123 v8::Local<v8::Context> context) {} 123 v8::Local<v8::Context> context) {}
124 124
125 } // namespace 125 } // namespace
126 126
127 class APIBindingUnittest : public APIBindingTest { 127 class APIBindingUnittest : public APIBindingTest {
128 public: 128 public:
129 void OnFunctionCall(std::unique_ptr<APIBinding::Request> request, 129 void OnFunctionCall(std::unique_ptr<APIRequestHandler::Request> request,
130 v8::Local<v8::Context> context) { 130 v8::Local<v8::Context> context) {
131 last_request_ = std::move(request); 131 last_request_ = std::move(request);
132 } 132 }
133 133
134 protected: 134 protected:
135 APIBindingUnittest() 135 APIBindingUnittest()
136 : type_refs_(APITypeReferenceMap::InitializeTypeCallback()) {} 136 : type_refs_(APITypeReferenceMap::InitializeTypeCallback()) {}
137 void SetUp() override { 137 void SetUp() override {
138 APIBindingTest::SetUp(); 138 APIBindingTest::SetUp();
139 request_handler_ = base::MakeUnique<APIRequestHandler>( 139 request_handler_ = base::MakeUnique<APIRequestHandler>(
140 base::Bind(&APIBindingUnittest::OnFunctionCall, base::Unretained(this)),
140 base::Bind(&RunFunctionOnGlobalAndIgnoreResult), 141 base::Bind(&RunFunctionOnGlobalAndIgnoreResult),
141 APILastError(APILastError::GetParent())); 142 APILastError(APILastError::GetParent()));
142 } 143 }
143 144
144 void TearDown() override { 145 void TearDown() override {
145 request_handler_.reset(); 146 request_handler_.reset();
146 event_handler_.reset(); 147 event_handler_.reset();
147 binding_.reset(); 148 binding_.reset();
148 APIBindingTest::TearDown(); 149 APIBindingTest::TearDown();
149 } 150 }
(...skipping 27 matching lines...) Expand all
177 if (!binding_hooks_) { 178 if (!binding_hooks_) {
178 binding_hooks_ = 179 binding_hooks_ =
179 base::MakeUnique<APIBindingHooks>(binding::RunJSFunctionSync()); 180 base::MakeUnique<APIBindingHooks>(binding::RunJSFunctionSync());
180 } 181 }
181 event_handler_ = base::MakeUnique<APIEventHandler>( 182 event_handler_ = base::MakeUnique<APIEventHandler>(
182 base::Bind(&RunFunctionOnGlobalAndIgnoreResult), 183 base::Bind(&RunFunctionOnGlobalAndIgnoreResult),
183 base::Bind(&OnEventListenersChanged)); 184 base::Bind(&OnEventListenersChanged));
184 binding_ = base::MakeUnique<APIBinding>( 185 binding_ = base::MakeUnique<APIBinding>(
185 "test", binding_functions_.get(), binding_types_.get(), 186 "test", binding_functions_.get(), binding_types_.get(),
186 binding_events_.get(), binding_properties_.get(), 187 binding_events_.get(), binding_properties_.get(),
187 base::Bind(&APIBindingUnittest::OnFunctionCall, base::Unretained(this)),
188 std::move(binding_hooks_), &type_refs_, request_handler_.get(), 188 std::move(binding_hooks_), &type_refs_, request_handler_.get(),
189 event_handler_.get()); 189 event_handler_.get());
190 EXPECT_EQ(!binding_types_.get(), type_refs_.empty()); 190 EXPECT_EQ(!binding_types_.get(), type_refs_.empty());
191 } 191 }
192 192
193 void ExpectPass(v8::Local<v8::Object> object, 193 void ExpectPass(v8::Local<v8::Object> object,
194 const std::string& script_source, 194 const std::string& script_source,
195 const std::string& expected_json_arguments_single_quotes, 195 const std::string& expected_json_arguments_single_quotes,
196 bool expect_callback) { 196 bool expect_callback) {
197 ExpectPass(ContextLocal(), object, script_source, 197 ExpectPass(ContextLocal(), object, script_source,
(...skipping 11 matching lines...) Expand all
209 } 209 }
210 210
211 void ExpectFailure(v8::Local<v8::Object> object, 211 void ExpectFailure(v8::Local<v8::Object> object,
212 const std::string& script_source, 212 const std::string& script_source,
213 const std::string& expected_error) { 213 const std::string& expected_error) {
214 RunTest(ContextLocal(), object, script_source, false, std::string(), false, 214 RunTest(ContextLocal(), object, script_source, false, std::string(), false,
215 expected_error); 215 expected_error);
216 } 216 }
217 217
218 bool HandlerWasInvoked() const { return last_request_ != nullptr; } 218 bool HandlerWasInvoked() const { return last_request_ != nullptr; }
219 const APIBinding::Request* last_request() const { 219 const APIRequestHandler::Request* last_request() const {
220 return last_request_.get(); 220 return last_request_.get();
221 } 221 }
222 void reset_last_request() { last_request_.reset(); } 222 void reset_last_request() { last_request_.reset(); }
223 APIBinding* binding() { return binding_.get(); } 223 APIBinding* binding() { return binding_.get(); }
224 APIEventHandler* event_handler() { return event_handler_.get(); } 224 APIEventHandler* event_handler() { return event_handler_.get(); }
225 APIRequestHandler* request_handler() { return request_handler_.get(); } 225 APIRequestHandler* request_handler() { return request_handler_.get(); }
226 const APITypeReferenceMap& type_refs() const { return type_refs_; } 226 const APITypeReferenceMap& type_refs() const { return type_refs_; }
227 227
228 private: 228 private:
229 void RunTest(v8::Local<v8::Context> context, 229 void RunTest(v8::Local<v8::Context> context,
230 v8::Local<v8::Object> object, 230 v8::Local<v8::Object> object,
231 const std::string& script_source, 231 const std::string& script_source,
232 bool should_pass, 232 bool should_pass,
233 const std::string& expected_json_arguments, 233 const std::string& expected_json_arguments,
234 bool expect_callback, 234 bool expect_callback,
235 const std::string& expected_error); 235 const std::string& expected_error);
236 236
237 std::unique_ptr<APIBinding::Request> last_request_; 237 std::unique_ptr<APIRequestHandler::Request> last_request_;
238 std::unique_ptr<APIBinding> binding_; 238 std::unique_ptr<APIBinding> binding_;
239 std::unique_ptr<APIEventHandler> event_handler_; 239 std::unique_ptr<APIEventHandler> event_handler_;
240 std::unique_ptr<APIRequestHandler> request_handler_; 240 std::unique_ptr<APIRequestHandler> request_handler_;
241 APITypeReferenceMap type_refs_; 241 APITypeReferenceMap type_refs_;
242 242
243 std::unique_ptr<base::ListValue> binding_functions_; 243 std::unique_ptr<base::ListValue> binding_functions_;
244 std::unique_ptr<base::ListValue> binding_events_; 244 std::unique_ptr<base::ListValue> binding_events_;
245 std::unique_ptr<base::ListValue> binding_types_; 245 std::unique_ptr<base::ListValue> binding_types_;
246 std::unique_ptr<base::DictionaryValue> binding_properties_; 246 std::unique_ptr<base::DictionaryValue> binding_properties_;
247 std::unique_ptr<APIBindingHooks> binding_hooks_; 247 std::unique_ptr<APIBindingHooks> binding_hooks_;
(...skipping 797 matching lines...) Expand 10 before | Expand all | Expand 10 after
1045 1045
1046 blink::WebScopedUserGesture user_gesture(nullptr); 1046 blink::WebScopedUserGesture user_gesture(nullptr);
1047 RunFunction(function, context, arraysize(argv), argv); 1047 RunFunction(function, context, arraysize(argv), argv);
1048 ASSERT_TRUE(last_request()); 1048 ASSERT_TRUE(last_request());
1049 EXPECT_TRUE(last_request()->has_user_gesture); 1049 EXPECT_TRUE(last_request()->has_user_gesture);
1050 1050
1051 reset_last_request(); 1051 reset_last_request();
1052 } 1052 }
1053 1053
1054 } // namespace extensions 1054 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698