chromium/extensions/renderer/bindings/api_bindings_system_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_bindings_system_unittest.h"

#include "base/containers/contains.h"
#include "base/functional/bind.h"
#include "base/functional/callback_helpers.h"
#include "base/strings/stringprintf.h"
#include "extensions/common/mojom/event_dispatcher.mojom.h"
#include "extensions/renderer/bindings/api_binding.h"
#include "extensions/renderer/bindings/api_binding_hooks.h"
#include "extensions/renderer/bindings/api_binding_hooks_test_delegate.h"
#include "extensions/renderer/bindings/api_binding_test_util.h"
#include "extensions/renderer/bindings/api_binding_types.h"
#include "extensions/renderer/bindings/api_bindings_system.h"
#include "extensions/renderer/bindings/api_invocation_errors.h"
#include "extensions/renderer/bindings/test_interaction_provider.h"
#include "gin/arguments.h"
#include "gin/converter.h"
#include "gin/try_catch.h"
#include "testing/gmock/include/gmock/gmock.h"

namespace extensions {

namespace {

// Fake API for testing.
const char kAlphaAPIName[] =;
const char kAlphaAPISpec[] =;

// Another fake API for testing.
const char kBetaAPIName[] =;
const char kBetaAPISpec[] =;

const char kGammaAPIName[] =;
const char kGammaAPISpec[] =;

// JS strings used for registering custom callbacks for testing.
const char kCustomCallbackHook[] =;
const char kCustomCallbackThrowHook[] =;

bool AllowAllAPIs(v8::Local<v8::Context> context, const std::string& name) {}

bool AllowPromises(v8::Local<v8::Context> context) {}

}  // namespace

APIBindingsSystemTest::APIBindingsSystemTest() = default;
APIBindingsSystemTest::~APIBindingsSystemTest() = default;

void APIBindingsSystemTest::SetUp() {}

void APIBindingsSystemTest::TearDown() {}

void APIBindingsSystemTest::OnWillDisposeContext(
    v8::Local<v8::Context> context) {}

std::vector<APIBindingsSystemTest::FakeSpec> APIBindingsSystemTest::GetAPIs() {}

v8::Local<v8::Object> APIBindingsSystemTest::GetLastErrorParent(
    v8::Local<v8::Context> context,
    v8::Local<v8::Object>* secondary_parent) {}

void APIBindingsSystemTest::AddConsoleError(v8::Local<v8::Context> context,
                                            const std::string& error) {}

const base::Value::Dict& APIBindingsSystemTest::GetAPISchema(
    const std::string& api_name) {}

void APIBindingsSystemTest::OnAPIRequest(
    std::unique_ptr<APIRequestHandler::Request> request,
    v8::Local<v8::Context> context) {}

void APIBindingsSystemTest::OnEventListenersChanged(
    const std::string& event_name,
    binding::EventListenersChanged changed,
    const base::Value::Dict* filter,
    bool was_manual,
    v8::Local<v8::Context> context) {}

void APIBindingsSystemTest::ValidateLastRequest(
    const std::string& expected_name,
    const std::string& expected_arguments) {}

v8::Local<v8::Value> APIBindingsSystemTest::CallFunctionOnObject(
    v8::Local<v8::Context> context,
    v8::Local<v8::Object> object,
    const std::string& script_source) {}

// Tests API object initialization, calling a method on the supplied APIs, and
// triggering the callback for the request.
TEST_F(APIBindingsSystemTest, TestInitializationAndCallbacks) {}

// Tests adding a custom hook to an API.
TEST_F(APIBindingsSystemTest, TestCustomHooks) {}

// Tests a call with a callback into an API using a setCustomCallback hook
// works as expected.
TEST_F(APIBindingsSystemTest, TestSetCustomCallback_SuccessWithCallback) {}

// Tests a call with a promise into an API using a setCustomCallback hook works
// as expected.
TEST_F(APIBindingsSystemTest, TestSetCustomCallback_SuccessWithPromise) {}

// Tests that an error thrown in a setCustomCallback hook while using a callback
// based call works as expected.
TEST_F(APIBindingsSystemTest, TestSetCustomCallback_ErrorWithCallback) {}

// Tests that an error thrown in a setCustomCallback hook while using a promise
// based call works as expected.
TEST_F(APIBindingsSystemTest, TestSetCustomCallback_ErrorWithPromise) {}

// Test that references to other API's types works.
TEST_F(APIBindingsSystemTest, CrossAPIReferences) {}

TEST_F(APIBindingsSystemTest, TestCustomEvent) {}

}  // namespace extensions