Automatic update from web-platform-tests [WebNN] Add "webnn" permissions policy feature Implement the "webnn" policy-controlled feature as specified in the WebNN specification [1]. The default allowlist is 'self', which means the WebNN API is available to top-level documents and same-origin iframes by default, but blocked in cross-origin iframes unless explicitly granted via the Permissions-Policy header or iframe allow attribute. When the feature is disabled, navigator.ml.createContext() rejects with a "SecurityError" DOMException per the spec. This CL also changes the WebIDL to only expose the WebNN interfaces to DedicatedWorker and updates related WPTs. [1] https://www.w3.org/TR/webnn/#permissions-policy-integration Bug: 502083483 Change-Id: I5c723e0ea03864fd0b122aed8b3d31f602545a2e Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/7885337 Reviewed-by: Takashi Toyoshima <toyoshim@chromium.org> Reviewed-by: Bo Liu <boliu@chromium.org> Reviewed-by: Reilly Grant <reillyg@chromium.org> Reviewed-by: Kent Tamura <tkent@chromium.org> Reviewed-by: Steven Holte <holte@chromium.org> Commit-Queue: Wang, Wei4 <wei4.wang@intel.com> Cr-Commit-Position: refs/heads/main@{#1642237} -- wpt-commits: 48d66a5560161cc5b7a372c709964963f62a8e58 wpt-pr: 60418
79 lines
2.3 KiB
JavaScript
79 lines
2.3 KiB
JavaScript
// META: title=validation tests for WebNN API input interface
|
|
// META: global=window
|
|
// META: variant=?cpu
|
|
// META: variant=?gpu
|
|
// META: variant=?npu
|
|
// META: script=../resources/utils_validation.js
|
|
|
|
'use strict';
|
|
|
|
// Tests for input(name, descriptor)
|
|
const tests = [
|
|
{
|
|
testName: '[input] Test building a 0-D scalar input with empty shape',
|
|
name: 'input',
|
|
descriptor: {dataType: 'float32', shape: []},
|
|
output: {dataType: 'float32', shape: []},
|
|
},
|
|
{
|
|
testName: '[input] Test building a 1-D input with int64 data type',
|
|
name: 'input',
|
|
descriptor: {dataType: 'int64', shape: [3]},
|
|
output: {dataType: 'int64', shape: [3]},
|
|
},
|
|
{
|
|
testName: '[input] Test building a 2-D input without errors',
|
|
name: 'input',
|
|
descriptor: {dataType: 'float32', shape: [3, 4]},
|
|
output: {dataType: 'float32', shape: [3, 4]},
|
|
},
|
|
{
|
|
testName: '[input] Throw if the name is empty',
|
|
name: '',
|
|
descriptor: {dataType: 'float32', shape: [3, 4]}
|
|
},
|
|
{
|
|
testName: '[input] Throw if a dimension size is 0',
|
|
name: 'input',
|
|
descriptor: {dataType: 'float32', shape: [3, 0]}
|
|
},
|
|
{
|
|
testName:
|
|
'[input] Throw if the value of any element in dimensions is outside the \'unsigned long\' value range',
|
|
name: 'input',
|
|
descriptor: {dataType: 'float32', shape: [kMaxUnsignedLong + 1]}
|
|
},
|
|
{
|
|
testName: '[input] Throw if the number of elements is too large',
|
|
name: 'input',
|
|
descriptor: {
|
|
dataType: 'float32',
|
|
shape: [kMaxUnsignedLong, kMaxUnsignedLong, kMaxUnsignedLong]
|
|
}
|
|
}
|
|
];
|
|
|
|
tests.forEach(
|
|
test => promise_test(async t => {
|
|
const builder = new MLGraphBuilder(context);
|
|
if (test.output) {
|
|
const inputOperand = builder.input(test.name, test.descriptor);
|
|
assert_equals(inputOperand.dataType, test.output.dataType);
|
|
assert_array_equals(inputOperand.shape, test.output.shape);
|
|
} else {
|
|
assert_throws_js(
|
|
TypeError, () => builder.input(test.name, test.descriptor));
|
|
}
|
|
}, test.testName));
|
|
|
|
promise_test(async t => {
|
|
const builder = new MLGraphBuilder(context);
|
|
|
|
const inputDescriptor = {
|
|
dataType: 'float32',
|
|
shape: [context.opSupportLimits().maxTensorByteLength / 4 + 1]};
|
|
|
|
assert_throws_js(
|
|
TypeError, () => builder.input('input', inputDescriptor));
|
|
}, '[input] throw if the output tensor byte length exceeds limit');
|