chromium/gpu/config/webgpu_blocklist_unittest.cc

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

#include "gpu/config/webgpu_blocklist.h"

#include "build/build_config.h"
#include "gpu/config/webgpu_blocklist_impl.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "third_party/dawn/include/dawn/webgpu.h"
#include "ui/gl/buildflags.h"

#if BUILDFLAG(IS_ANDROID)
#include "base/android/build_info.h"
#endif

namespace gpu {

bool IsWebGPUAdapterBlocklisted(const WGPUAdapterInfo& info,
                                const char* blocklist_string = "") {}

class WebGPUBlocklistTest : public testing::Test {};

#if BUILDFLAG(IS_ANDROID)
// Android is currently more restrictive than other platforms around which GPUs
// are allowed, which causes the usual tests to fail. This test exercises the
// Android-specific restrictions.

TEST_F(WebGPUBlocklistTest, BlockAndroidVendorId) {
  const auto* build_info = base::android::BuildInfo::GetInstance();

  WGPUAdapterInfo info1 = {};
  info1.vendorID = 0x13B5;

  WGPUAdapterInfo info2 = {};
  info2.vendorID = 0x5143;

  WGPUAdapterInfo info3 = {};
  info3.vendorID = 0x8086;

  if (build_info->sdk_int() < base::android::SDK_VERSION_S) {
    // If the Android version is R or lower everything should be blocked.
    EXPECT_TRUE(IsWebGPUAdapterBlocklisted(info1));
    EXPECT_TRUE(IsWebGPUAdapterBlocklisted(info2));
    EXPECT_TRUE(IsWebGPUAdapterBlocklisted(info3));
    return;
  }

  // Test the default vendor blocks
  EXPECT_FALSE(IsWebGPUAdapterBlocklisted(info1));
  EXPECT_FALSE(IsWebGPUAdapterBlocklisted(info2));
  EXPECT_TRUE(IsWebGPUAdapterBlocklisted(info3));

  // Test that blocking a vendor which is otherwise allowed still works
  EXPECT_TRUE(IsWebGPUAdapterBlocklisted(info1, "13b5"));
  EXPECT_FALSE(IsWebGPUAdapterBlocklisted(info2, "13b5"));

  // Test blocking *
  EXPECT_TRUE(IsWebGPUAdapterBlocklisted(info1, "*"));
  EXPECT_TRUE(IsWebGPUAdapterBlocklisted(info2, "*"));

  // Test blocking a list of patterns
  EXPECT_TRUE(IsWebGPUAdapterBlocklisted(info1, "13b5|5143"));
  EXPECT_TRUE(IsWebGPUAdapterBlocklisted(info2, "13b5|5143"));
}

#else
TEST_F(WebGPUBlocklistTest, BlockVendorId) {}

TEST_F(WebGPUBlocklistTest, BlockDeviceIdOrArch) {}

TEST_F(WebGPUBlocklistTest, BlockDriverDescription) {}
#endif  // BUILDFLAG(IS_ANDROID) else

}  // namespace gpu