blob: e82e55a13e33b3c43adf2d122483aa60612d8caf [file] [log] [blame]
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<script src="../resources/testharness.js"></script>
<script src="../resources/testharnessreport.js"></script>
</head>
<body>
<script>
async function getEncryptedData(transform)
{
const chunk = await transform.readable.getReader().read();
const value = new Uint8Array(chunk.value);
return [...value];
}
promise_test(async (test) => {
const key = await crypto.subtle.importKey("raw", new Uint8Array([143, 77, 43, 10, 72, 19, 37, 67, 236, 219, 24, 93, 26, 165, 91, 178]), "HKDF", false, ["deriveBits", "deriveKey"]);
const transform1 = new SFrameTransform;
const transform2 = new SFrameTransform;
const transform3 = new SFrameTransform;
await transform1.setEncryptionKey(key);
await transform2.setEncryptionKey(key);
await transform3.setEncryptionKey(key);
const buffer1 = new ArrayBuffer(10);
const buffer2 = new ArrayBuffer(11);
const view1 = new Uint8Array(buffer1);
const view2 = new Uint8Array(buffer2, 1);
for (let i = 0 ; i < buffer1.byteLength; ++i) {
view1[i] = i;
view2[i] = i;
}
transform1.writable.getWriter().write(buffer1);
transform2.writable.getWriter().write(view1);
transform3.writable.getWriter().write(view2);
const result1 = await getEncryptedData(transform1);
const result2 = await getEncryptedData(transform2);
const result3 = await getEncryptedData(transform3);
assert_array_equals(result1, result2, "result2");
assert_array_equals(result1, result3, "result3");
}, "Uint8Array as input to SFrameTransform");
</script>
</body>
</html>