chromium/third_party/blink/renderer/modules/wake_lock/wake_lock_test_utils.cc

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

#ifdef UNSAFE_BUFFERS_BUILD
// TODO(crbug.com/351564777): Remove this and convert code to safer constructs.
#pragma allow_unsafe_buffers
#endif

#include "third_party/blink/renderer/modules/wake_lock/wake_lock_test_utils.h"

#include <tuple>
#include <utility>

#include "base/check.h"
#include "base/notreached.h"
#include "base/run_loop.h"
#include "mojo/public/cpp/bindings/pending_receiver.h"
#include "third_party/blink/public/platform/browser_interface_broker_proxy.h"
#include "third_party/blink/renderer/bindings/core/v8/script_function.h"
#include "third_party/blink/renderer/bindings/core/v8/v8_dom_exception.h"
#include "third_party/blink/renderer/bindings/modules/v8/v8_wake_lock_sentinel.h"
#include "third_party/blink/renderer/core/dom/document.h"
#include "third_party/blink/renderer/core/dom/dom_exception.h"
#include "third_party/blink/renderer/core/frame/local_frame.h"
#include "third_party/blink/renderer/modules/wake_lock/wake_lock_sentinel.h"
#include "third_party/blink/renderer/modules/wake_lock/wake_lock_type.h"
#include "third_party/blink/renderer/platform/bindings/v8_binding.h"
#include "third_party/blink/renderer/platform/heap/heap_test_utilities.h"
#include "third_party/blink/renderer/platform/wtf/allocator/allocator.h"
#include "third_party/blink/renderer/platform/wtf/functional.h"

namespace blink {

PermissionDescriptorPtr;

namespace {

void RunWithStack(base::RunLoop* run_loop) {}

// Helper class for WaitForPromise{Fulfillment,Rejection}(). It provides a
// function that invokes |callback| when a ScriptPromiseUntyped is resolved.
class ClosureRunnerCallable final : public ScriptFunction::Callable {};

V8WakeLockType::Enum ToBlinkWakeLockType(
    device::mojom::blink::WakeLockType type) {}

}  // namespace

// MockWakeLock

MockWakeLock::MockWakeLock() = default;
MockWakeLock::~MockWakeLock() = default;

void MockWakeLock::Bind(
    mojo::PendingReceiver<device::mojom::blink::WakeLock> receiver) {}

void MockWakeLock::Unbind() {}

void MockWakeLock::WaitForRequest() {}

void MockWakeLock::WaitForCancelation() {}

void MockWakeLock::OnConnectionError() {}

void MockWakeLock::RequestWakeLock() {}

void MockWakeLock::CancelWakeLock() {}

void MockWakeLock::AddClient(
    mojo::PendingReceiver<device::mojom::blink::WakeLock>) {}
void MockWakeLock::ChangeType(device::mojom::blink::WakeLockType,
                              ChangeTypeCallback) {}
void MockWakeLock::HasWakeLockForTests(HasWakeLockForTestsCallback) {}

// MockWakeLockService

MockWakeLockService::MockWakeLockService() = default;
MockWakeLockService::~MockWakeLockService() = default;

void MockWakeLockService::BindRequest(mojo::ScopedMessagePipeHandle handle) {}

MockWakeLock& MockWakeLockService::get_wake_lock(V8WakeLockType::Enum type) {}

void MockWakeLockService::GetWakeLock(
    device::mojom::blink::WakeLockType type,
    device::mojom::blink::WakeLockReason reason,
    const String& description,
    mojo::PendingReceiver<device::mojom::blink::WakeLock> receiver) {}

// MockPermissionService

MockPermissionService::MockPermissionService() = default;
MockPermissionService::~MockPermissionService() = default;

void MockPermissionService::BindRequest(mojo::ScopedMessagePipeHandle handle) {}

void MockPermissionService::SetPermissionResponse(
    V8WakeLockType::Enum type,
    mojom::blink::PermissionStatus status) {}

void MockPermissionService::OnConnectionError() {}

bool MockPermissionService::GetWakeLockTypeFromDescriptor(
    const PermissionDescriptorPtr& descriptor,
    V8WakeLockType::Enum* output) {}

void MockPermissionService::WaitForPermissionRequest(
    V8WakeLockType::Enum type) {}

void MockPermissionService::HasPermission(PermissionDescriptorPtr permission,
                                          HasPermissionCallback callback) {}

void MockPermissionService::RegisterPageEmbeddedPermissionControl(
    Vector<mojom::blink::PermissionDescriptorPtr> permissions,
    mojo::PendingRemote<mojom::blink::EmbeddedPermissionControlClient> client) {}

void MockPermissionService::RequestPageEmbeddedPermission(
    mojom::blink::EmbeddedPermissionRequestDescriptorPtr permissions,
    RequestPageEmbeddedPermissionCallback) {}

void MockPermissionService::RequestPermission(
    PermissionDescriptorPtr permission,
    bool user_gesture,
    RequestPermissionCallback callback) {}

void MockPermissionService::RequestPermissions(
    Vector<PermissionDescriptorPtr> permissions,
    bool user_gesture,
    mojom::blink::PermissionService::RequestPermissionsCallback) {}

void MockPermissionService::RevokePermission(PermissionDescriptorPtr permission,
                                             RevokePermissionCallback) {}

void MockPermissionService::AddPermissionObserver(
    PermissionDescriptorPtr permission,
    mojom::blink::PermissionStatus last_known_status,
    mojo::PendingRemote<mojom::blink::PermissionObserver>) {}

void MockPermissionService::AddPageEmbeddedPermissionObserver(
    PermissionDescriptorPtr permission,
    mojom::blink::PermissionStatus last_known_status,
    mojo::PendingRemote<mojom::blink::PermissionObserver>) {}

void MockPermissionService::NotifyEventListener(
    PermissionDescriptorPtr permission,
    const String& event_type,
    bool is_added) {}
// WakeLockTestingContext

WakeLockTestingContext::WakeLockTestingContext(
    MockWakeLockService* mock_wake_lock_service) {}

WakeLockTestingContext::~WakeLockTestingContext() {}

LocalDOMWindow* WakeLockTestingContext::DomWindow() {}

LocalFrame* WakeLockTestingContext::Frame() {}

ScriptState* WakeLockTestingContext::GetScriptState() {}

MockPermissionService& WakeLockTestingContext::GetPermissionService() {}

void WakeLockTestingContext::WaitForPromiseFulfillment(
    ScriptPromiseUntyped promise) {}

// Synchronously waits for |promise| to be rejected.
void WakeLockTestingContext::WaitForPromiseRejection(
    ScriptPromiseUntyped promise) {}

// ScriptPromiseUtils

// static
v8::Promise::PromiseState ScriptPromiseUtils::GetPromiseState(
    const ScriptPromise<WakeLockSentinel>& promise) {}

// static
DOMException* ScriptPromiseUtils::GetPromiseResolutionAsDOMException(
    v8::Isolate* isolate,
    const ScriptPromise<WakeLockSentinel>& promise) {}

// static
WakeLockSentinel* ScriptPromiseUtils::GetPromiseResolutionAsWakeLockSentinel(
    v8::Isolate* isolate,
    const ScriptPromise<WakeLockSentinel>& promise) {}

}  // namespace blink