diff --git a/src/webgpu/api/operation/adapter/requestAdapter.spec.ts b/src/webgpu/api/operation/adapter/requestAdapter.spec.ts index 5f5754442b13..b1fe7f39bce3 100644 --- a/src/webgpu/api/operation/adapter/requestAdapter.spec.ts +++ b/src/webgpu/api/operation/adapter/requestAdapter.spec.ts @@ -4,6 +4,7 @@ Tests for GPU.requestAdapter. Test all possible options to requestAdapter. default, low-power, and high performance should all always return adapters. forceFallbackAdapter may or may not return an adapter. +invalid featureLevel values should not return an adapter. GPU.requestAdapter can technically return null for any reason but we need test functionality so the test requires an adapter except @@ -26,6 +27,8 @@ const powerPreferenceModes: Array = [ 'high-performance', ]; const forceFallbackOptions: Array = [undefined, false, true]; +const validFeatureLevels: Array = [undefined, 'core', 'compatibility']; +const invalidFeatureLevels: Array = ['cor', 'Core', 'compatability', '', ' ']; async function testAdapter(t: Fixture, adapter: GPUAdapter | null) { assert(adapter !== null, 'Failed to get adapter.'); @@ -120,6 +123,20 @@ g.test('requestAdapter') await testAdapter(t, adapter); }); +g.test('requestAdapter_invalid_featureLevel') + .desc(`request adapter with invalid featureLevel string values return null`) + .params(u => u.combine('featureLevel', [...validFeatureLevels, ...invalidFeatureLevels])) + .fn(async t => { + const { featureLevel } = t.params; + const adapter = await getGPU(t.rec).requestAdapter({ featureLevel }); + + if (!validFeatureLevels.includes(featureLevel)) { + assert(adapter === null); + } else { + await testAdapter(t, adapter); + } + }); + g.test('requestAdapter_no_parameters') .desc(`request adapter with no parameters`) .fn(async t => {