[webnn] Add tests for WebNN API constant (fillSequence) (#43801)

* [webnn] Add tests for WebNN API constant (fillSequence)

* [webnn] Update test data with negative start

* [webnn] Update test data for integer test cases

* [webnn] Add a test with negative integer step
diff --git a/webnn/constant.https.any.js b/webnn/constant.https.any.js
new file mode 100644
index 0000000..afb020d
--- /dev/null
+++ b/webnn/constant.https.any.js
@@ -0,0 +1,10 @@
+// META: title=test WebNN API constant
+// META: global=window,dedicatedworker
+// META: script=./resources/utils.js
+// META: timeout=long
+
+'use strict';
+
+// https://webmachinelearning.github.io/webnn/#api-mlgraphbuilder-constant-range
+
+testWebNNOperation('constant', buildConstantRange);
\ No newline at end of file
diff --git a/webnn/gpu/constant.https.any.js b/webnn/gpu/constant.https.any.js
new file mode 100644
index 0000000..7e0933f
--- /dev/null
+++ b/webnn/gpu/constant.https.any.js
@@ -0,0 +1,10 @@
+// META: title=test WebNN API constant
+// META: global=window,dedicatedworker
+// META: script=../resources/utils.js
+// META: timeout=long
+
+'use strict';
+
+// https://webmachinelearning.github.io/webnn/#api-mlgraphbuilder-constant-range
+
+testWebNNOperation('constant', buildConstantRange, 'gpu');
\ No newline at end of file
diff --git a/webnn/resources/test_data/constant.json b/webnn/resources/test_data/constant.json
new file mode 100644
index 0000000..06fe0a7
--- /dev/null
+++ b/webnn/resources/test_data/constant.json
@@ -0,0 +1,754 @@
+{
+  "tests": [
+    {
+      "name": "constant float32 0D tensor of default float32 type",
+      "inputs": {
+        "start": {
+          "data": 0.22992068529129028,
+          "type": "float32"
+        },
+        "step": {
+          "data": 0.7537541389465332,
+          "type": "float32"
+        }
+      },
+      "outputShape": [],
+      "expected": {
+        "name": "output",
+        "shape": [],
+        "data": [
+          0.22992068529129028
+        ],
+        "type": "float32"
+      }
+    },
+    {
+      "name": "constant float32 1D tensor of default float32 type",
+      "inputs": {
+        "start": {
+          "data": 0.22992068529129028,
+          "type": "float32"
+        },
+        "step": {
+          "data": 0.7537541389465332,
+          "type": "float32"
+        }
+      },
+      "outputShape": [24],
+      "expected": {
+        "name": "output",
+        "shape": [24],
+        "data": [
+          0.22992068529129028,
+          0.9836748242378235,
+          1.737428903579712,
+          2.491183042526245,
+          3.2449371814727783,
+          3.9986913204193115,
+          4.752445697784424,
+          5.506199836730957,
+          6.25995397567749,
+          7.013708114624023,
+          7.767462253570557,
+          8.52121639251709,
+          9.274970054626465,
+          10.028724670410156,
+          10.782478332519531,
+          11.536232948303223,
+          12.289986610412598,
+          13.043741226196289,
+          13.797494888305664,
+          14.551249504089355,
+          15.30500316619873,
+          16.058757781982422,
+          16.812511444091797,
+          17.566265106201172
+        ],
+        "type": "float32"
+      }
+    },
+    {
+      "name": "constant float32 2D tensor of default float32 type",
+      "inputs": {
+        "start": {
+          "data": 0.22992068529129028,
+          "type": "float32"
+        },
+        "step": {
+          "data": 0.7537541389465332,
+          "type": "float32"
+        }
+      },
+      "outputShape": [4, 6],
+      "expected": {
+        "name": "output",
+        "shape": [4, 6],
+        "data": [
+          0.22992068529129028,
+          0.9836748242378235,
+          1.737428903579712,
+          2.491183042526245,
+          3.2449371814727783,
+          3.9986913204193115,
+          4.752445697784424,
+          5.506199836730957,
+          6.25995397567749,
+          7.013708114624023,
+          7.767462253570557,
+          8.52121639251709,
+          9.274970054626465,
+          10.028724670410156,
+          10.782478332519531,
+          11.536232948303223,
+          12.289986610412598,
+          13.043741226196289,
+          13.797494888305664,
+          14.551249504089355,
+          15.30500316619873,
+          16.058757781982422,
+          16.812511444091797,
+          17.566265106201172
+        ],
+        "type": "float32"
+      }
+    },
+    {
+      "name": "constant float32 3D tensor of default float32 type",
+      "inputs": {
+        "start": {
+          "data": 0.22992068529129028,
+          "type": "float32"
+        },
+        "step": {
+          "data": 0.7537541389465332,
+          "type": "float32"
+        }
+      },
+      "outputShape": [2, 3, 4],
+      "expected": {
+        "name": "output",
+        "shape": [2, 3, 4],
+        "data": [
+          0.22992068529129028,
+          0.9836748242378235,
+          1.737428903579712,
+          2.491183042526245,
+          3.2449371814727783,
+          3.9986913204193115,
+          4.752445697784424,
+          5.506199836730957,
+          6.25995397567749,
+          7.013708114624023,
+          7.767462253570557,
+          8.52121639251709,
+          9.274970054626465,
+          10.028724670410156,
+          10.782478332519531,
+          11.536232948303223,
+          12.289986610412598,
+          13.043741226196289,
+          13.797494888305664,
+          14.551249504089355,
+          15.30500316619873,
+          16.058757781982422,
+          16.812511444091797,
+          17.566265106201172
+        ],
+        "type": "float32"
+      }
+    },
+    {
+      "name": "constant float32 4D tensor of default float32 type",
+      "inputs": {
+        "start": {
+          "data": 0.22992068529129028,
+          "type": "float32"
+        },
+        "step": {
+          "data": 0.7537541389465332,
+          "type": "float32"
+        }
+      },
+      "outputShape": [2, 2, 2, 3],
+      "expected": {
+        "name": "output",
+        "shape": [2, 2, 2, 3],
+        "data": [
+          0.22992068529129028,
+          0.9836748242378235,
+          1.737428903579712,
+          2.491183042526245,
+          3.2449371814727783,
+          3.9986913204193115,
+          4.752445697784424,
+          5.506199836730957,
+          6.25995397567749,
+          7.013708114624023,
+          7.767462253570557,
+          8.52121639251709,
+          9.274970054626465,
+          10.028724670410156,
+          10.782478332519531,
+          11.536232948303223,
+          12.289986610412598,
+          13.043741226196289,
+          13.797494888305664,
+          14.551249504089355,
+          15.30500316619873,
+          16.058757781982422,
+          16.812511444091797,
+          17.566265106201172
+        ],
+        "type": "float32"
+      }
+    },
+    {
+      "name": "constant float32 4D tensor of default float32 type step > 0",
+      "inputs": {
+        "start": {
+          "data": 0.22992068529129028,
+          "type": "float32"
+        },
+        "step": {
+          "data": 0.7615746259689331,
+          "type": "float32"
+        }
+      },
+      "outputShape": [2, 2, 2, 3],
+      "expected": {
+        "name": "output",
+        "shape": [2, 2, 2, 3],
+        "data": [
+          0.22992068529129028,
+          0.9914953112602234,
+          1.7530698776245117,
+          2.5146446228027344,
+          3.276219129562378,
+          4.0377936363220215,
+          4.799368381500244,
+          5.560943126678467,
+          6.3225178718566895,
+          7.084092140197754,
+          7.845666885375977,
+          8.6072416305542,
+          9.368816375732422,
+          10.130391120910645,
+          10.891965866088867,
+          11.653539657592773,
+          12.415114402770996,
+          13.176689147949219,
+          13.938263893127441,
+          14.699838638305664,
+          15.461413383483887,
+          16.22298812866211,
+          16.984561920166016,
+          17.746137619018555
+        ],
+        "type": "float32"
+      }
+    },
+    {
+      "name": "constant float32 4D tensor of default float32 type step = 0",
+      "inputs": {
+        "start": {
+          "data": 0.22992068529129028,
+          "type": "float32"
+        },
+        "step": {
+          "data": 0,
+          "type": "float32"
+        }
+      },
+      "outputShape": [2, 2, 2, 3],
+      "expected": {
+        "name": "output",
+        "shape": [2, 2, 2, 3],
+        "data": [
+          0.22992068529129028,
+          0.22992068529129028,
+          0.22992068529129028,
+          0.22992068529129028,
+          0.22992068529129028,
+          0.22992068529129028,
+          0.22992068529129028,
+          0.22992068529129028,
+          0.22992068529129028,
+          0.22992068529129028,
+          0.22992068529129028,
+          0.22992068529129028,
+          0.22992068529129028,
+          0.22992068529129028,
+          0.22992068529129028,
+          0.22992068529129028,
+          0.22992068529129028,
+          0.22992068529129028,
+          0.22992068529129028,
+          0.22992068529129028,
+          0.22992068529129028,
+          0.22992068529129028,
+          0.22992068529129028,
+          0.22992068529129028
+        ],
+        "type": "float32"
+      }
+    },
+    {
+      "name": "constant float32 4D tensor of default float32 type step < 0",
+      "inputs": {
+        "start": {
+          "data": 0.22992068529129028,
+          "type": "float32"
+        },
+        "step": {
+          "data": -0.6248052716255188,
+          "type": "float32"
+        }
+      },
+      "outputShape": [2, 2, 2, 3],
+      "expected": {
+        "name": "output",
+        "shape": [2, 2, 2, 3],
+        "data": [
+          0.22992068529129028,
+          -0.3948845863342285,
+          -1.0196897983551025,
+          -1.6444951295852661,
+          -2.2693004608154297,
+          -2.8941056728363037,
+          -3.5189108848571777,
+          -4.143716335296631,
+          -4.768521308898926,
+          -5.393326759338379,
+          -6.018132209777832,
+          -6.642937183380127,
+          -7.26774263381958,
+          -7.892547607421875,
+          -8.517353057861328,
+          -9.142158508300781,
+          -9.766963958740234,
+          -10.391769409179688,
+          -11.016573905944824,
+          -11.641379356384277,
+          -12.26618480682373,
+          -12.890990257263184,
+          -13.515795707702637,
+          -14.140600204467773
+        ],
+        "type": "float32"
+      }
+    },
+    {
+      "name": "constant float32 5D tensor of default float32 type",
+      "inputs": {
+        "start": {
+          "data": 0.22992068529129028,
+          "type": "float32"
+        },
+        "step": {
+          "data": 0.7537541389465332,
+          "type": "float32"
+        }
+      },
+      "outputShape": [2, 1, 4, 1, 3],
+      "expected": {
+        "name": "output",
+        "shape": [2, 1, 4, 1, 3],
+        "data": [
+          0.22992068529129028,
+          0.9836748242378235,
+          1.737428903579712,
+          2.491183042526245,
+          3.2449371814727783,
+          3.9986913204193115,
+          4.752445697784424,
+          5.506199836730957,
+          6.25995397567749,
+          7.013708114624023,
+          7.767462253570557,
+          8.52121639251709,
+          9.274970054626465,
+          10.028724670410156,
+          10.782478332519531,
+          11.536232948303223,
+          12.289986610412598,
+          13.043741226196289,
+          13.797494888305664,
+          14.551249504089355,
+          15.30500316619873,
+          16.058757781982422,
+          16.812511444091797,
+          17.566265106201172
+        ],
+        "type": "float32"
+      }
+    },
+    {
+      "name": "constant float32 4D tensor of explict float32 type",
+      "inputs": {
+        "start": {
+          "data": 0.22992068529129028,
+          "type": "float32"
+        },
+        "step": {
+          "data": 0.7537541389465332,
+          "type": "float32"
+        }
+      },
+      "outputShape": [2, 2, 2, 3],
+      "type": "float32",
+      "expected": {
+        "name": "output",
+        "shape": [2, 2, 2, 3],
+        "data": [
+          0.22992068529129028,
+          0.9836748242378235,
+          1.737428903579712,
+          2.491183042526245,
+          3.2449371814727783,
+          3.9986913204193115,
+          4.752445697784424,
+          5.506199836730957,
+          6.25995397567749,
+          7.013708114624023,
+          7.767462253570557,
+          8.52121639251709,
+          9.274970054626465,
+          10.028724670410156,
+          10.782478332519531,
+          11.536232948303223,
+          12.289986610412598,
+          13.043741226196289,
+          13.797494888305664,
+          14.551249504089355,
+          15.30500316619873,
+          16.058757781982422,
+          16.812511444091797,
+          17.566265106201172
+        ],
+        "type": "float32"
+      }
+    },
+    {
+      "name": "constant float32 4D tensor of float16 type",
+      "inputs": {
+        "start": {
+          "data": 0.22992068529129028,
+          "type": "float32"
+        },
+        "step": {
+          "data": 0.7537541389465332,
+          "type": "float32"
+        }
+      },
+      "outputShape": [2, 2, 2, 3],
+      "type": "float16",
+      "expected": {
+        "name": "output",
+        "shape": [2, 2, 2, 3],
+        "data": [
+          0.22998046875,
+          0.98388671875,
+          1.7373046875,
+          2.490234375,
+          3.244140625,
+          3.998046875,
+          4.75390625,
+          5.5078125,
+          6.26171875,
+          7.015625,
+          7.765625,
+          8.5234375,
+          9.2734375,
+          10.03125,
+          10.78125,
+          11.5390625,
+          12.2890625,
+          13.046875,
+          13.796875,
+          14.5546875,
+          15.3046875,
+          16.0625,
+          16.8125,
+          17.5625
+        ],
+        "type": "float16"
+      }
+    },
+    {
+      "name": "constant float32 4D tensor of int32 type",
+      "inputs": {
+        "start": {
+          "data": 7,
+          "type": "float32"
+        },
+        "step": {
+          "data": 1,
+          "type": "float32"
+        }
+      },
+      "outputShape": [2, 2, 2, 3],
+      "type": "int32",
+      "expected": {
+        "name": "output",
+        "shape": [2, 2, 2, 3],
+        "data": [
+          7,
+          8,
+          9,
+          10,
+          11,
+          12,
+          13,
+          14,
+          15,
+          16,
+          17,
+          18,
+          19,
+          20,
+          21,
+          22,
+          23,
+          24,
+          25,
+          26,
+          27,
+          28,
+          29,
+          30
+        ],
+        "type": "int32"
+      }
+    },
+    {
+      "name": "constant float32 4D tensor of uint32 type",
+      "inputs": {
+        "start": {
+          "data": 7,
+          "type": "float32"
+        },
+        "step": {
+          "data": 1,
+          "type": "float32"
+        }
+      },
+      "outputShape": [2, 2, 2, 3],
+      "type": "uint32",
+      "expected": {
+        "name": "output",
+        "shape": [2, 2, 2, 3],
+        "data": [
+          7,
+          8,
+          9,
+          10,
+          11,
+          12,
+          13,
+          14,
+          15,
+          16,
+          17,
+          18,
+          19,
+          20,
+          21,
+          22,
+          23,
+          24,
+          25,
+          26,
+          27,
+          28,
+          29,
+          30
+        ],
+        "type": "uint32"
+      }
+    },
+    {
+      "name": "constant float32 4D tensor of int64 type",
+      "inputs": {
+        "start": {
+          "data": 7,
+          "type": "float32"
+        },
+        "step": {
+          "data": 1,
+          "type": "float32"
+        }
+      },
+      "outputShape": [2, 2, 2, 3],
+      "type": "int64",
+      "expected": {
+        "name": "output",
+        "shape": [2, 2, 2, 3],
+        "data": [
+          "7",
+          "8",
+          "9",
+          "10",
+          "11",
+          "12",
+          "13",
+          "14",
+          "15",
+          "16",
+          "17",
+          "18",
+          "19",
+          "20",
+          "21",
+          "22",
+          "23",
+          "24",
+          "25",
+          "26",
+          "27",
+          "28",
+          "29",
+          "30"
+        ],
+        "type": "int64"
+      }
+    },
+    {
+      "name": "constant float32 4D tensor of int8 type step > 0",
+      "inputs": {
+        "start": {
+          "data": -9,
+          "type": "float32"
+        },
+        "step": {
+          "data": 1,
+          "type": "float32"
+        }
+      },
+      "outputShape": [2, 2, 2, 3],
+      "type": "int8",
+      "expected": {
+        "name": "output",
+        "shape": [2, 2, 2, 3],
+        "data": [
+          -9,
+          -8,
+          -7,
+          -6,
+          -5,
+          -4,
+          -3,
+          -2,
+          -1,
+          0,
+          1,
+          2,
+          3,
+          4,
+          5,
+          6,
+          7,
+          8,
+          9,
+          10,
+          11,
+          12,
+          13,
+          14
+        ],
+        "type": "int8"
+      }
+    },
+    {
+      "name": "constant float32 4D tensor of int8 type step < 0",
+      "inputs": {
+        "start": {
+          "data": 7,
+          "type": "float32"
+        },
+        "step": {
+          "data": -2,
+          "type": "float32"
+        }
+      },
+      "outputShape": [2, 2, 2, 3],
+      "type": "int8",
+      "expected": {
+        "name": "output",
+        "shape": [2, 2, 2, 3],
+        "data": [
+          7,
+          5,
+          3,
+          1,
+          -1,
+          -3,
+          -5,
+          -7,
+          -9,
+          -11,
+          -13,
+          -15,
+          -17,
+          -19,
+          -21,
+          -23,
+          -25,
+          -27,
+          -29,
+          -31,
+          -33,
+          -35,
+          -37,
+          -39
+        ],
+        "type": "int8"
+      }
+    },
+    {
+      "name": "constant float32 4D tensor of uint8 type",
+      "inputs": {
+        "start": {
+          "data": 7,
+          "type": "float32"
+        },
+        "step": {
+          "data": 1,
+          "type": "float32"
+        }
+      },
+      "outputShape": [2, 2, 2, 3],
+      "type": "uint8",
+      "expected": {
+        "name": "output",
+        "shape": [2, 2, 2, 3],
+        "data": [
+          7,
+          8,
+          9,
+          10,
+          11,
+          12,
+          13,
+          14,
+          15,
+          16,
+          17,
+          18,
+          19,
+          20,
+          21,
+          22,
+          23,
+          24,
+          25,
+          26,
+          27,
+          28,
+          29,
+          30
+        ],
+        "type": "uint8"
+      }
+    }
+  ]
+}
\ No newline at end of file
diff --git a/webnn/resources/utils.js b/webnn/resources/utils.js
index f91d662..c1fc294 100644
--- a/webnn/resources/utils.js
+++ b/webnn/resources/utils.js
@@ -292,6 +292,7 @@
   cast: {ULP: {float32: 1, float16: 1, int32: 0, uint32: 0, int64: 0, int8: 0, uint8: 0}},
   clamp: {ULP: {float32: 0, float16: 0}},
   concat: {ULP: {float32: 0, float16: 0}},
+  constant: {ULP: {float32: 2, float16: 2, int32: 0, uint32: 0, int64: 0, int8: 0, uint8: 0}},
   conv2d: {ULP: {float32: getConv2dPrecisionTolerance, float16: getConv2dPrecisionTolerance}},
   convTranspose2d: {ULP: {float32: getConv2dPrecisionTolerance, float16: getConv2dPrecisionTolerance}},
   // Begin Element-wise binary operations
@@ -635,6 +636,13 @@
   return namedOutputOperand;
 };
 
+const buildConstantRange = (operationName, builder, resources) => {
+  const namedOutputOperand = {};
+  // invoke builder.constant(start, step, outputShape, type)
+  namedOutputOperand[resources.expected.name] = builder[operationName](resources.inputs.start, resources.inputs.step, resources.outputShape, resources.type);
+  return namedOutputOperand;
+};
+
 const buildConvTranspose2d = (operationName, builder, resources) => {
   // MLOperand convTranspose2d(MLOperand input, MLOperand filter, optional MLConvTranspose2dOptions options = {});
   const namedOutputOperand = {};