chromium/extensions/renderer/bindings/api_event_handler_unittest.cc

// Copyright 2016 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#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) {}

// Note: Not function-local to RemoveListener() because it's used in one place
// that needs to circumvent RunFunction().
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 {};

}  // namespace

// Tests adding, removing, and querying event listeners by calling the
// associated methods on the JS object.
TEST_F(APIEventHandlerTest, AddingRemovingAndQueryingEventListeners) {}

// Tests listening for and firing different events.
TEST_F(APIEventHandlerTest, FiringEvents) {}

// Tests firing events with arguments.
TEST_F(APIEventHandlerTest, EventArguments) {}

// Test dispatching events to multiple contexts.
TEST_F(APIEventHandlerTest, MultipleContexts) {}

TEST_F(APIEventHandlerTest, DifferentCallingMethods) {}

TEST_F(APIEventHandlerTest, TestDispatchFromJs) {}

// Test listeners that remove themselves in their handling of the event.
TEST_F(APIEventHandlerTest, RemovingListenersWhileHandlingEvent) {}

// Test an event listener throwing an exception.
TEST_F(APIEventHandlerTest, TestEventListenersThrowingExceptions) {}

// Tests being notified as listeners are added or removed from events.
TEST_F(APIEventHandlerTest, CallbackNotifications) {}

// Test registering an argument massager for a given event.
TEST_F(APIEventHandlerTest, TestArgumentMassagers) {}

TEST_F(APIEventHandlerTest, TestFilteredEventWithMassager) {}

// Test registering an argument massager for a given event and dispatching
// asynchronously.
TEST_F(APIEventHandlerTest, TestArgumentMassagersAsyncDispatch) {}

// Test registering an argument massager and never dispatching.
TEST_F(APIEventHandlerTest, TestArgumentMassagersNeverDispatch) {}

// Test that event results of dispatch are passed to the calling argument
// massager. Regression test for https://crbug.com/867310.
TEST_F(APIEventHandlerTest, TestArgumentMassagersDispatchResult) {}

// Test creating a custom event, as is done by a few of our custom bindings.
TEST_F(APIEventHandlerTest, TestCreateCustomEvent) {}

// Test adding a custom event with a cyclic dependency. Nothing should leak.
TEST_F(APIEventHandlerTest, TestCreateCustomEventWithCyclicDependency) {}

TEST_F(APIEventHandlerTest, TestUnmanagedEvents) {}

// Test callback notifications for events that don't support lazy listeners.
TEST_F(APIEventHandlerTest, TestEventsWithoutLazyListeners) {}

// Tests dispatching events while script is suspended.
TEST_F(APIEventHandlerTest, TestDispatchingEventsWhileScriptSuspended) {}

// Tests catching errors thrown by listeners while dispatching after script
// suspension.
TEST_F(APIEventHandlerTest,
       TestListenersThrowingExceptionsAfterScriptSuspension) {}

// Tests dispatching events when listeners are removed between when an event
// was fired (during script suspension) and when the script runs.
TEST_F(APIEventHandlerTest,
       TestDispatchingEventAfterListenersRemovedAfterScriptSuspension) {}

// Test that notifications are properly fired for multiple events with the
// same context owner.
TEST_F(APIEventHandlerTest,
       TestListenersFromDifferentContextsWithTheSameOwner) {}

}  // namespace extensions