chromium/third_party/blink/renderer/modules/webgpu/gpu_context_lost_test.cc

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

#include "base/functional/callback.h"
#include "base/memory/raw_ptr.h"
#include "base/run_loop.h"
#include "base/test/mock_callback.h"
#include "gpu/command_buffer/client/webgpu_interface_stub.h"
#include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "third_party/blink/renderer/bindings/core/v8/v8_binding_for_testing.h"
#include "third_party/blink/renderer/core/frame/local_dom_window.h"
#include "third_party/blink/renderer/core/frame/local_frame.h"
#include "third_party/blink/renderer/core/frame/navigator.h"
#include "third_party/blink/renderer/core/testing/dummy_page_holder.h"
#include "third_party/blink/renderer/modules/webgpu/gpu.h"
#include "third_party/blink/renderer/platform/graphics/gpu/dawn_control_client_holder.h"
#include "third_party/blink/renderer/platform/graphics/gpu/drawing_buffer_test_helpers.h"
#include "third_party/blink/renderer/platform/testing/task_environment.h"

namespace blink {

namespace {

class WebGPUContextProviderForTest
    : public WebGraphicsContext3DProviderForTests {};

class WebGPUContextLostTest : public testing::Test {};

// Test that the context provider is destructed after the last reference to
// its owning DawnControlClientHolder is dropped.
TEST_F(WebGPUContextLostTest, DestructedAfterLastRefDropped) {}

// Test that the GPU lost context callback marks the context lost, but does not
// destruct it.
TEST_F(WebGPUContextLostTest, GPULostContext) {}

// Test that the GPU lost context callback marks the context lost, and then when
// the context is recreated, the context still lives until the previous
// DawnControlClientHolder is destroyed.
TEST_F(WebGPUContextLostTest, RecreatedAfterGPULostContext) {}

// Test that ContextDestroyed lifecycle event destructs the context.
TEST_F(WebGPUContextLostTest, ContextDestroyed) {}

}  // namespace

}  // namespace blink