chromium/extensions/browser/event_router_unittest.cc

// Copyright 2013 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/browser/event_router.h"

#include <memory>
#include <string>
#include <utility>

#include "base/compiler_specific.h"
#include "base/functional/bind.h"
#include "base/test/bind.h"
#include "base/test/metrics/histogram_tester.h"
#include "base/values.h"
#include "build/build_config.h"
#include "content/public/browser/browser_context.h"
#include "content/public/test/mock_render_process_host.h"
#include "extensions/browser/event_listener_map.h"
#include "extensions/browser/extensions_test.h"
#include "extensions/browser/process_map.h"
#include "extensions/browser/process_map_factory.h"
#include "extensions/browser/test_event_router_observer.h"
#include "extensions/common/constants.h"
#include "extensions/common/extension_api.h"
#include "extensions/common/extension_builder.h"
#include "extensions/common/extension_id.h"
#include "extensions/common/features/feature_provider.h"
#include "extensions/common/features/simple_feature.h"
#include "extensions/common/mojom/context_type.mojom.h"
#include "extensions/common/mojom/event_dispatcher.mojom.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "third_party/blink/public/mojom/service_worker/service_worker_database.mojom-blink-forward.h"

Value;

namespace extensions {

namespace {

// A simple mock to keep track of listener additions and removals.
class MockEventRouterObserver : public EventRouter::Observer {};

class MockEventDispatcher : public mojom::EventDispatcher {};

EventListenerConstructor;

std::unique_ptr<EventListener> CreateEventListenerForExtension(
    const ExtensionId& extension_id,
    const std::string& event_name,
    content::RenderProcessHost* process,
    base::Value::Dict filter) {}

std::unique_ptr<EventListener> CreateEventListenerForURL(
    const GURL& listener_url,
    const std::string& event_name,
    content::RenderProcessHost* process,
    base::Value::Dict filter) {}

std::unique_ptr<EventListener> CreateEventListenerForExtensionServiceWorker(
    const ExtensionId& extension_id,
    int64_t service_worker_version_id,
    int worker_thread_id,
    const std::string& event_name,
    content::RenderProcessHost* process,
    base::Value::Dict filter) {}

// Creates an extension.  If |component| is true, it is created as a component
// extension.  If |persistent| is true, it is created with a persistent
// background page; otherwise it is created with an event page.
scoped_refptr<const Extension> CreateExtension(bool component,
                                               bool persistent) {}

scoped_refptr<const Extension> CreateServiceWorkerExtension() {}

base::Value::Dict CreateHostSuffixFilter(const std::string& suffix) {}

}  // namespace

bool operator<(const EventTarget& e1, const EventTarget& e2) {}

bool operator==(const EventTarget& e1, const EventTarget& e2) {}

std::ostream& operator<<(std::ostream& os, const EventTarget& e) {}

class EventRouterTest : public ExtensionsTest {};

class EventRouterFilterTest : public ExtensionsTest,
                              public testing::WithParamInterface<bool> {};

TEST_F(EventRouterTest, GetBaseEventName) {}

// Tests adding and removing observers from EventRouter.
void EventRouterTest::RunEventRouterObserverTest(
    const EventListenerConstructor& constructor) {}

TEST_F(EventRouterTest, EventRouterObserverForExtensions) {}

TEST_F(EventRouterTest, EventRouterObserverForURLs) {}

TEST_F(EventRouterTest, EventRouterObserverForServiceWorkers) {}

namespace {

// Tracks event dispatches to a specific process.
class EventRouterObserver : public EventRouter::TestObserver {};

// A fake that pretends that all contexts are WebUI.
class ProcessMapFake : public ProcessMap {};

std::unique_ptr<KeyedService> BuildProcessMap(
    content::BrowserContext* profile) {}

}  // namespace

TEST_F(EventRouterTest, WebUIEventsDoNotCrossIncognitoBoundaries) {}

TEST_F(EventRouterTest, MultipleEventRouterObserver) {}

TEST_F(EventRouterTest, TestReportEvent) {}

// Tests adding and removing events with filters.
// TODO(crbug.com/40281129): test is flaky across platforms.
TEST_P(EventRouterFilterTest, DISABLED_Basic) {}

// TODO(crbug.com/40281129): test is flaky across platforms.
TEST_P(EventRouterFilterTest, DISABLED_URLBasedFilteredEventListener) {}

INSTANTIATE_TEST_SUITE_P();
INSTANTIATE_TEST_SUITE_P();

class EventRouterDispatchTest : public ExtensionsTest {};

TEST_F(EventRouterDispatchTest, TestDispatch) {}

// TODO(crbug.com/40281129): test is flaky across platforms.
TEST_F(EventRouterDispatchTest, DISABLED_TestDispatchCallback) {}

}  // namespace extensions