#include "extensions/renderer/bindings/api_event_handler.h"
#include <optional>
#include "base/functional/bind.h"
#include "base/functional/callback_helpers.h"
#include "base/run_loop.h"
#include "base/test/bind.h"
#include "base/test/mock_callback.h"
#include "base/values.h"
#include "extensions/common/mojom/event_dispatcher.mojom.h"
#include "extensions/renderer/bindings/api_binding_test.h"
#include "extensions/renderer/bindings/api_binding_test_util.h"
#include "extensions/renderer/bindings/exception_handler.h"
#include "extensions/renderer/bindings/test_js_runner.h"
#include "gin/arguments.h"
#include "gin/converter.h"
#include "gin/public/context_holder.h"
#include "testing/gmock/include/gmock/gmock.h"
#include "v8/include/v8-object.h"
#include "v8/include/v8-primitive.h"
namespace extensions {
namespace {
MockEventChangeHandler;
std::string GetContextOwner(v8::Local<v8::Context> context) { … }
constexpr char kRemoveListenerFunction[] = …;
void AddListener(v8::Local<v8::Context> context,
v8::Local<v8::Function> listener,
v8::Local<v8::Object> event) { … }
void AddFilteredListener(v8::Local<v8::Context> context,
v8::Local<v8::Function> listener,
v8::Local<v8::Object> event,
v8::Local<v8::Object> filter) { … }
void RemoveListener(v8::Local<v8::Context> context,
v8::Local<v8::Function> listener,
v8::Local<v8::Object> event) { … }
class APIEventHandlerTest : public APIBindingTest { … };
}
TEST_F(APIEventHandlerTest, AddingRemovingAndQueryingEventListeners) { … }
TEST_F(APIEventHandlerTest, FiringEvents) { … }
TEST_F(APIEventHandlerTest, EventArguments) { … }
TEST_F(APIEventHandlerTest, MultipleContexts) { … }
TEST_F(APIEventHandlerTest, DifferentCallingMethods) { … }
TEST_F(APIEventHandlerTest, TestDispatchFromJs) { … }
TEST_F(APIEventHandlerTest, RemovingListenersWhileHandlingEvent) { … }
TEST_F(APIEventHandlerTest, TestEventListenersThrowingExceptions) { … }
TEST_F(APIEventHandlerTest, CallbackNotifications) { … }
TEST_F(APIEventHandlerTest, TestArgumentMassagers) { … }
TEST_F(APIEventHandlerTest, TestFilteredEventWithMassager) { … }
TEST_F(APIEventHandlerTest, TestArgumentMassagersAsyncDispatch) { … }
TEST_F(APIEventHandlerTest, TestArgumentMassagersNeverDispatch) { … }
TEST_F(APIEventHandlerTest, TestArgumentMassagersDispatchResult) { … }
TEST_F(APIEventHandlerTest, TestCreateCustomEvent) { … }
TEST_F(APIEventHandlerTest, TestCreateCustomEventWithCyclicDependency) { … }
TEST_F(APIEventHandlerTest, TestUnmanagedEvents) { … }
TEST_F(APIEventHandlerTest, TestEventsWithoutLazyListeners) { … }
TEST_F(APIEventHandlerTest, TestDispatchingEventsWhileScriptSuspended) { … }
TEST_F(APIEventHandlerTest,
TestListenersThrowingExceptionsAfterScriptSuspension) { … }
TEST_F(APIEventHandlerTest,
TestDispatchingEventAfterListenersRemovedAfterScriptSuspension) { … }
TEST_F(APIEventHandlerTest,
TestListenersFromDifferentContextsWithTheSameOwner) { … }
}