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 #include "extensions/renderer/bindings/event_emitter.h" | 5 #include "extensions/renderer/bindings/event_emitter.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/memory/ptr_util.h" | 8 #include "base/memory/ptr_util.h" |
9 #include "base/values.h" | 9 #include "base/values.h" |
10 #include "extensions/renderer/bindings/api_binding_test.h" | 10 #include "extensions/renderer/bindings/api_binding_test.h" |
(...skipping 11 matching lines...) Expand all Loading... |
22 | 22 |
23 } // namespace | 23 } // namespace |
24 | 24 |
25 using EventEmitterUnittest = APIBindingTest; | 25 using EventEmitterUnittest = APIBindingTest; |
26 | 26 |
27 TEST_F(EventEmitterUnittest, TestDispatchMethod) { | 27 TEST_F(EventEmitterUnittest, TestDispatchMethod) { |
28 v8::HandleScope handle_scope(isolate()); | 28 v8::HandleScope handle_scope(isolate()); |
29 v8::Local<v8::Context> context = MainContext(); | 29 v8::Local<v8::Context> context = MainContext(); |
30 | 30 |
31 auto listeners = base::MakeUnique<UnfilteredEventListeners>( | 31 auto listeners = base::MakeUnique<UnfilteredEventListeners>( |
32 base::Bind(&DoNothingOnListenerChange), binding::kNoListenerMax); | 32 base::Bind(&DoNothingOnListenerChange), binding::kNoListenerMax, true); |
33 | 33 |
34 // The test util methods enforce that functions always throw or always don't | 34 // The test util methods enforce that functions always throw or always don't |
35 // throw, but we test listeners that do both. Provide implementations for | 35 // throw, but we test listeners that do both. Provide implementations for |
36 // running functions that don't enforce throw behavior. | 36 // running functions that don't enforce throw behavior. |
37 auto run_js_sync = [](v8::Local<v8::Function> function, | 37 auto run_js_sync = [](v8::Local<v8::Function> function, |
38 v8::Local<v8::Context> context, int argc, | 38 v8::Local<v8::Context> context, int argc, |
39 v8::Local<v8::Value> argv[]) { | 39 v8::Local<v8::Value> argv[]) { |
40 v8::Global<v8::Value> global_result; | 40 v8::Global<v8::Value> global_result; |
41 v8::Local<v8::Value> result; | 41 v8::Local<v8::Value> result; |
42 if (function->Call(context, context->Global(), argc, argv).ToLocal(&result)) | 42 if (function->Call(context, context->Global(), argc, argv).ToLocal(&result)) |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
110 for (const char* property : | 110 for (const char* property : |
111 {"eventArgs1", "eventArgs2", "eventArgs3", "eventArgs4"}) { | 111 {"eventArgs1", "eventArgs2", "eventArgs3", "eventArgs4"}) { |
112 EXPECT_EQ(kExpectedEventArgs, GetStringPropertyFromObject( | 112 EXPECT_EQ(kExpectedEventArgs, GetStringPropertyFromObject( |
113 context->Global(), context, property)); | 113 context->Global(), context, property)); |
114 } | 114 } |
115 EXPECT_EQ("{\"results\":[\"listener1\",{\"listener\":\"listener2\"}]}", | 115 EXPECT_EQ("{\"results\":[\"listener1\",{\"listener\":\"listener2\"}]}", |
116 V8ToString(dispatch_result, context)); | 116 V8ToString(dispatch_result, context)); |
117 } | 117 } |
118 | 118 |
119 } // namespace extensions | 119 } // namespace extensions |
OLD | NEW |