Best JavaScript code snippet using wpt
general.any.js
Source:general.any.js
...233 assert_equals(pullCount, 1, 'pull must be invoked');234 });235}, 'ReadableStream with byte source: Automatic pull() after start() and read()');236// View buffers are detached after pull() returns, so record the information at the time that pull() was called.237function extractViewInfo(view) {238 return {239 constructor: view.constructor,240 bufferByteLength: view.buffer.byteLength,241 byteOffset: view.byteOffset,242 byteLength: view.byteLength243 };244}245promise_test(() => {246 let pullCount = 0;247 let controller;248 const byobRequests = [];249 const stream = new ReadableStream({250 start(c) {251 controller = c;252 },253 pull() {254 const byobRequest = controller.byobRequest;255 const view = byobRequest.view;256 byobRequests[pullCount] = {257 nonNull: byobRequest !== null,258 viewNonNull: view !== null,259 viewInfo: extractViewInfo(view)260 };261 if (pullCount === 0) {262 view[0] = 0x01;263 byobRequest.respond(1);264 } else if (pullCount === 1) {265 view[0] = 0x02;266 view[1] = 0x03;267 byobRequest.respond(2);268 }269 ++pullCount;270 },271 type: 'bytes',272 autoAllocateChunkSize: 16273 }, {274 highWaterMark: 0275 });276 const reader = stream.getReader();277 const p0 = reader.read();278 const p1 = reader.read();279 assert_equals(pullCount, 0, 'No pull() as start() just finished and is not yet reflected to the state of the stream');280 return Promise.resolve().then(() => {281 assert_equals(pullCount, 1, 'pull() must have been invoked once');282 const byobRequest = byobRequests[0];283 assert_true(byobRequest.nonNull, 'first byobRequest must not be null');284 assert_true(byobRequest.viewNonNull, 'first byobRequest.view must not be null');285 const viewInfo = byobRequest.viewInfo;286 assert_equals(viewInfo.constructor, Uint8Array, 'first view.constructor should be Uint8Array');287 assert_equals(viewInfo.bufferByteLength, 16, 'first view.buffer.byteLength should be 16');288 assert_equals(viewInfo.byteOffset, 0, 'first view.byteOffset should be 0');289 assert_equals(viewInfo.byteLength, 16, 'first view.byteLength should be 16');290 return p0;291 }).then(result => {292 assert_equals(pullCount, 2, 'pull() must have been invoked twice');293 const value = result.value;294 assert_not_equals(value, undefined, 'first read should have a value');295 assert_equals(value.constructor, Uint8Array, 'first value should be a Uint8Array');296 assert_equals(value.buffer.byteLength, 16, 'first value.buffer.byteLength should be 16');297 assert_equals(value.byteOffset, 0, 'first value.byteOffset should be 0');298 assert_equals(value.byteLength, 1, 'first value.byteLength should be 1');299 assert_equals(value[0], 0x01, 'first value[0] should be 0x01');300 const byobRequest = byobRequests[1];301 assert_true(byobRequest.nonNull, 'second byobRequest must not be null');302 assert_true(byobRequest.viewNonNull, 'second byobRequest.view must not be null');303 const viewInfo = byobRequest.viewInfo;304 assert_equals(viewInfo.constructor, Uint8Array, 'second view.constructor should be Uint8Array');305 assert_equals(viewInfo.bufferByteLength, 16, 'second view.buffer.byteLength should be 16');306 assert_equals(viewInfo.byteOffset, 0, 'second view.byteOffset should be 0');307 assert_equals(viewInfo.byteLength, 16, 'second view.byteLength should be 16');308 return p1;309 }).then(result => {310 assert_equals(pullCount, 2, 'pull() should only be invoked twice');311 const value = result.value;312 assert_not_equals(value, undefined, 'second read should have a value');313 assert_equals(value.constructor, Uint8Array, 'second value should be a Uint8Array');314 assert_equals(value.buffer.byteLength, 16, 'second value.buffer.byteLength should be 16');315 assert_equals(value.byteOffset, 0, 'second value.byteOffset should be 0');316 assert_equals(value.byteLength, 2, 'second value.byteLength should be 2');317 assert_equals(value[0], 0x02, 'second value[0] should be 0x02');318 assert_equals(value[1], 0x03, 'second value[1] should be 0x03');319 });320}, 'ReadableStream with byte source: autoAllocateChunkSize');321promise_test(() => {322 let pullCount = 0;323 let controller;324 const byobRequests = [];325 const stream = new ReadableStream({326 start(c) {327 controller = c;328 },329 pull() {330 const byobRequest = controller.byobRequest;331 const view = byobRequest.view;332 byobRequests[pullCount] = {333 nonNull: byobRequest !== null,334 viewNonNull: view !== null,335 viewInfo: extractViewInfo(view)336 };337 if (pullCount === 0) {338 view[0] = 0x01;339 byobRequest.respond(1);340 } else if (pullCount === 1) {341 view[0] = 0x02;342 view[1] = 0x03;343 byobRequest.respond(2);344 }345 ++pullCount;346 },347 type: 'bytes',348 autoAllocateChunkSize: 16349 }, {350 highWaterMark: 0351 });352 const reader = stream.getReader();353 return reader.read().then(result => {354 const value = result.value;355 assert_not_equals(value, undefined, 'first read should have a value');356 assert_equals(value.constructor, Uint8Array, 'first value should be a Uint8Array');357 assert_equals(value.buffer.byteLength, 16, 'first value.buffer.byteLength should be 16');358 assert_equals(value.byteOffset, 0, 'first value.byteOffset should be 0');359 assert_equals(value.byteLength, 1, 'first value.byteLength should be 1');360 assert_equals(value[0], 0x01, 'first value[0] should be 0x01');361 const byobRequest = byobRequests[0];362 assert_true(byobRequest.nonNull, 'first byobRequest must not be null');363 assert_true(byobRequest.viewNonNull, 'first byobRequest.view must not be null');364 const viewInfo = byobRequest.viewInfo;365 assert_equals(viewInfo.constructor, Uint8Array, 'first view.constructor should be Uint8Array');366 assert_equals(viewInfo.bufferByteLength, 16, 'first view.buffer.byteLength should be 16');367 assert_equals(viewInfo.byteOffset, 0, 'first view.byteOffset should be 0');368 assert_equals(viewInfo.byteLength, 16, 'first view.byteLength should be 16');369 reader.releaseLock();370 const byobReader = stream.getReader({ mode: 'byob' });371 return byobReader.read(new Uint8Array(32));372 }).then(result => {373 const value = result.value;374 assert_not_equals(value, undefined, 'second read should have a value');375 assert_equals(value.constructor, Uint8Array, 'second value should be a Uint8Array');376 assert_equals(value.buffer.byteLength, 32, 'second value.buffer.byteLength should be 32');377 assert_equals(value.byteOffset, 0, 'second value.byteOffset should be 0');378 assert_equals(value.byteLength, 2, 'second value.byteLength should be 2');379 assert_equals(value[0], 0x02, 'second value[0] should be 0x02');380 assert_equals(value[1], 0x03, 'second value[1] should be 0x03');381 const byobRequest = byobRequests[1];382 assert_true(byobRequest.nonNull, 'second byobRequest must not be null');383 assert_true(byobRequest.viewNonNull, 'second byobRequest.view must not be null');384 const viewInfo = byobRequest.viewInfo;385 assert_equals(viewInfo.constructor, Uint8Array, 'second view.constructor should be Uint8Array');386 assert_equals(viewInfo.bufferByteLength, 32, 'second view.buffer.byteLength should be 32');387 assert_equals(viewInfo.byteOffset, 0, 'second view.byteOffset should be 0');388 assert_equals(viewInfo.byteLength, 32, 'second view.byteLength should be 32');389 assert_equals(pullCount, 2, 'pullCount should be 2');390 });391}, 'ReadableStream with byte source: Mix of auto allocate and BYOB');392promise_test(() => {393 let pullCount = 0;394 const stream = new ReadableStream({395 pull() {396 ++pullCount;397 },398 type: 'bytes'399 }, {400 highWaterMark: 0401 });402 const reader = stream.getReader();403 reader.read(new Uint8Array(8));404 assert_equals(pullCount, 0, 'No pull as start() just finished and is not yet reflected to the state of the stream');405 return Promise.resolve().then(() => {406 assert_equals(pullCount, 1, 'pull must be invoked');407 });408}, 'ReadableStream with byte source: Automatic pull() after start() and read(view)');409promise_test(() => {410 let pullCount = 0;411 let controller;412 let desiredSizeInStart;413 let desiredSizeInPull;414 const stream = new ReadableStream({415 start(c) {416 c.enqueue(new Uint8Array(16));417 desiredSizeInStart = c.desiredSize;418 controller = c;419 },420 pull() {421 ++pullCount;422 if (pullCount === 1) {423 desiredSizeInPull = controller.desiredSize;424 }425 },426 type: 'bytes'427 }, {428 highWaterMark: 8429 });430 return Promise.resolve().then(() => {431 assert_equals(pullCount, 0, 'No pull as the queue was filled by start()');432 assert_equals(desiredSizeInStart, -8, 'desiredSize after enqueue() in start()');433 const reader = stream.getReader();434 const promise = reader.read();435 assert_equals(pullCount, 1, 'The first pull() should be made on read()');436 assert_equals(desiredSizeInPull, 8, 'desiredSize in pull()');437 return promise.then(result => {438 assert_false(result.done, 'result.done');439 const view = result.value;440 assert_equals(view.constructor, Uint8Array, 'view.constructor');441 assert_equals(view.buffer.byteLength, 16, 'view.buffer');442 assert_equals(view.byteOffset, 0, 'view.byteOffset');443 assert_equals(view.byteLength, 16, 'view.byteLength');444 });445 });446}, 'ReadableStream with byte source: enqueue(), getReader(), then read()');447promise_test(() => {448 let controller;449 const stream = new ReadableStream({450 start(c) {451 controller = c;452 },453 type: 'bytes'454 });455 const reader = stream.getReader();456 const promise = reader.read().then(result => {457 assert_false(result.done);458 const view = result.value;459 assert_equals(view.constructor, Uint8Array);460 assert_equals(view.buffer.byteLength, 1);461 assert_equals(view.byteOffset, 0);462 assert_equals(view.byteLength, 1);463 });464 controller.enqueue(new Uint8Array(1));465 return promise;466}, 'ReadableStream with byte source: Push source that doesn\'t understand pull signal');467test(() => {468 assert_throws_js(TypeError, () => new ReadableStream({469 pull: 'foo',470 type: 'bytes'471 }), 'constructor should throw');472}, 'ReadableStream with byte source: pull() function is not callable');473promise_test(() => {474 const stream = new ReadableStream({475 start(c) {476 c.enqueue(new Uint16Array(16));477 },478 type: 'bytes'479 });480 const reader = stream.getReader();481 return reader.read().then(result => {482 assert_false(result.done);483 const view = result.value;484 assert_equals(view.constructor, Uint8Array);485 assert_equals(view.buffer.byteLength, 32);486 assert_equals(view.byteOffset, 0);487 assert_equals(view.byteLength, 32);488 });489}, 'ReadableStream with byte source: enqueue() with Uint16Array, getReader(), then read()');490promise_test(t => {491 const stream = new ReadableStream({492 start(c) {493 const view = new Uint8Array(16);494 view[0] = 0x01;495 view[8] = 0x02;496 c.enqueue(view);497 },498 pull: t.unreached_func('pull() should not be called'),499 type: 'bytes'500 });501 const byobReader = stream.getReader({ mode: 'byob' });502 return byobReader.read(new Uint8Array(8)).then(result => {503 assert_false(result.done, 'done');504 const view = result.value;505 assert_equals(view.constructor, Uint8Array, 'value.constructor');506 assert_equals(view.buffer.byteLength, 8, 'value.buffer.byteLength');507 assert_equals(view.byteOffset, 0, 'value.byteOffset');508 assert_equals(view.byteLength, 8, 'value.byteLength');509 assert_equals(view[0], 0x01);510 byobReader.releaseLock();511 const reader = stream.getReader();512 return reader.read();513 }).then(result => {514 assert_false(result.done, 'done');515 const view = result.value;516 assert_equals(view.constructor, Uint8Array, 'value.constructor');517 assert_equals(view.buffer.byteLength, 16, 'value.buffer.byteLength');518 assert_equals(view.byteOffset, 8, 'value.byteOffset');519 assert_equals(view.byteLength, 8, 'value.byteLength');520 assert_equals(view[0], 0x02);521 });522}, 'ReadableStream with byte source: enqueue(), read(view) partially, then read()');523promise_test(t => {524 let controller;525 const stream = new ReadableStream({526 start(c) {527 controller = c;528 },529 pull: t.unreached_func('pull() should not be called'),530 type: 'bytes'531 });532 const reader = stream.getReader();533 controller.enqueue(new Uint8Array(16));534 controller.close();535 return reader.read().then(result => {536 assert_false(result.done, 'done');537 const view = result.value;538 assert_equals(view.byteOffset, 0, 'byteOffset');539 assert_equals(view.byteLength, 16, 'byteLength');540 return reader.read();541 }).then(result => {542 assert_true(result.done, 'done');543 assert_equals(result.value, undefined, 'value');544 });545}, 'ReadableStream with byte source: getReader(), enqueue(), close(), then read()');546promise_test(t => {547 const stream = new ReadableStream({548 start(c) {549 c.enqueue(new Uint8Array(16));550 c.close();551 },552 pull: t.unreached_func('pull() should not be called'),553 type: 'bytes'554 });555 const reader = stream.getReader();556 return reader.read().then(result => {557 assert_false(result.done, 'done');558 const view = result.value;559 assert_equals(view.byteOffset, 0, 'byteOffset');560 assert_equals(view.byteLength, 16, 'byteLength');561 return reader.read();562 }).then(result => {563 assert_true(result.done, 'done');564 assert_equals(result.value, undefined, 'value');565 });566}, 'ReadableStream with byte source: enqueue(), close(), getReader(), then read()');567promise_test(() => {568 let controller;569 let byobRequest;570 const stream = new ReadableStream({571 start(c) {572 controller = c;573 },574 pull() {575 controller.enqueue(new Uint8Array(16));576 byobRequest = controller.byobRequest;577 },578 type: 'bytes'579 });580 const reader = stream.getReader();581 return reader.read().then(result => {582 assert_false(result.done, 'done');583 assert_equals(result.value.byteLength, 16, 'byteLength');584 assert_equals(byobRequest, null, 'byobRequest must be null');585 });586}, 'ReadableStream with byte source: Respond to pull() by enqueue()');587promise_test(() => {588 let pullCount = 0;589 let controller;590 let byobRequest;591 const desiredSizes = [];592 const stream = new ReadableStream({593 start(c) {594 controller = c;595 },596 pull() {597 byobRequest = controller.byobRequest;598 desiredSizes.push(controller.desiredSize);599 controller.enqueue(new Uint8Array(1));600 desiredSizes.push(controller.desiredSize);601 controller.enqueue(new Uint8Array(1));602 desiredSizes.push(controller.desiredSize);603 ++pullCount;604 },605 type: 'bytes'606 }, {607 highWaterMark: 0608 });609 const reader = stream.getReader();610 const p0 = reader.read();611 const p1 = reader.read();612 const p2 = reader.read();613 // Respond to the first pull call.614 controller.enqueue(new Uint8Array(1));615 assert_equals(pullCount, 0, 'pullCount after the enqueue() outside pull');616 return Promise.all([p0, p1, p2]).then(result => {617 assert_equals(pullCount, 1, 'pullCount after completion of all read()s');618 assert_equals(result[0].done, false, 'result[0].done');619 assert_equals(result[0].value.byteLength, 1, 'result[0].value.byteLength');620 assert_equals(result[1].done, false, 'result[1].done');621 assert_equals(result[1].value.byteLength, 1, 'result[1].value.byteLength');622 assert_equals(result[2].done, false, 'result[2].done');623 assert_equals(result[2].value.byteLength, 1, 'result[2].value.byteLength');624 assert_equals(byobRequest, null, 'byobRequest should be null');625 assert_equals(desiredSizes[0], 0, 'desiredSize on pull should be 0');626 assert_equals(desiredSizes[1], 0, 'desiredSize after 1st enqueue() should be 0');627 assert_equals(desiredSizes[2], 0, 'desiredSize after 2nd enqueue() should be 0');628 assert_equals(pullCount, 1, 'pull() should only be called once');629 });630}, 'ReadableStream with byte source: Respond to pull() by enqueue() asynchronously');631promise_test(() => {632 let pullCount = 0;633 let byobRequest;634 const desiredSizes = [];635 const stream = new ReadableStream({636 pull(c) {637 byobRequest = c.byobRequest;638 desiredSizes.push(c.desiredSize);639 if (pullCount < 3) {640 c.enqueue(new Uint8Array(1));641 } else {642 c.close();643 }644 ++pullCount;645 },646 type: 'bytes'647 }, {648 highWaterMark: 256649 });650 const reader = stream.getReader();651 const p0 = reader.read();652 const p1 = reader.read();653 const p2 = reader.read();654 assert_equals(pullCount, 0, 'No pull as start() just finished and is not yet reflected to the state of the stream');655 return Promise.all([p0, p1, p2]).then(result => {656 assert_equals(pullCount, 4, 'pullCount after completion of all read()s');657 assert_equals(result[0].done, false, 'result[0].done');658 assert_equals(result[0].value.byteLength, 1, 'result[0].value.byteLength');659 assert_equals(result[1].done, false, 'result[1].done');660 assert_equals(result[1].value.byteLength, 1, 'result[1].value.byteLength');661 assert_equals(result[2].done, false, 'result[2].done');662 assert_equals(result[2].value.byteLength, 1, 'result[2].value.byteLength');663 assert_equals(byobRequest, null, 'byobRequest should be null');664 assert_equals(desiredSizes[0], 256, 'desiredSize on pull should be 256');665 assert_equals(desiredSizes[1], 256, 'desiredSize after 1st enqueue() should be 256');666 assert_equals(desiredSizes[2], 256, 'desiredSize after 2nd enqueue() should be 256');667 assert_equals(desiredSizes[3], 256, 'desiredSize after 3rd enqueue() should be 256');668 });669}, 'ReadableStream with byte source: Respond to multiple pull() by separate enqueue()');670promise_test(() => {671 let controller;672 let pullCount = 0;673 const byobRequestDefined = [];674 let byobRequestViewDefined;675 const stream = new ReadableStream({676 start(c) {677 controller = c;678 },679 pull() {680 byobRequestDefined.push(controller.byobRequest !== null);681 const initialByobRequest = controller.byobRequest;682 const view = controller.byobRequest.view;683 view[0] = 0x01;684 controller.byobRequest.respond(1);685 byobRequestDefined.push(controller.byobRequest !== null);686 byobRequestViewDefined = initialByobRequest.view !== null;687 ++pullCount;688 },689 type: 'bytes'690 });691 const reader = stream.getReader({ mode: 'byob' });692 return reader.read(new Uint8Array(1)).then(result => {693 assert_false(result.done, 'result.done');694 assert_equals(result.value.byteLength, 1, 'result.value.byteLength');695 assert_equals(result.value[0], 0x01, 'result.value[0]');696 assert_equals(pullCount, 1, 'pull() should be called only once');697 assert_true(byobRequestDefined[0], 'byobRequest must not be null before respond()');698 assert_false(byobRequestDefined[1], 'byobRequest must be null after respond()');699 assert_false(byobRequestViewDefined, 'view of initial byobRequest must be null after respond()');700 });701}, 'ReadableStream with byte source: read(view), then respond()');702promise_test(() => {703 let controller;704 let pullCount = 0;705 const byobRequestDefined = [];706 let byobRequestViewDefined;707 const stream = new ReadableStream({708 start(c) {709 controller = c;710 },711 async pull() {712 byobRequestDefined.push(controller.byobRequest !== null);713 const initialByobRequest = controller.byobRequest;714 const transferredView = await transferArrayBufferView(controller.byobRequest.view);715 transferredView[0] = 0x01;716 controller.byobRequest.respondWithNewView(transferredView);717 byobRequestDefined.push(controller.byobRequest !== null);718 byobRequestViewDefined = initialByobRequest.view !== null;719 ++pullCount;720 },721 type: 'bytes'722 });723 const reader = stream.getReader({ mode: 'byob' });724 return reader.read(new Uint8Array(1)).then(result => {725 assert_false(result.done, 'result.done');726 assert_equals(result.value.byteLength, 1, 'result.value.byteLength');727 assert_equals(result.value[0], 0x01, 'result.value[0]');728 assert_equals(pullCount, 1, 'pull() should be called only once');729 assert_true(byobRequestDefined[0], 'byobRequest must not be null before respondWithNewView()');730 assert_false(byobRequestDefined[1], 'byobRequest must be null after respondWithNewView()');731 assert_false(byobRequestViewDefined, 'view of initial byobRequest must be null after respondWithNewView()');732 });733}, 'ReadableStream with byte source: read(view), then respondWithNewView() with a transferred ArrayBuffer');734promise_test(() => {735 let controller;736 let byobRequestWasDefined;737 let incorrectRespondException;738 const stream = new ReadableStream({739 start(c) {740 controller = c;741 },742 pull() {743 byobRequestWasDefined = controller.byobRequest !== null;744 try {745 controller.byobRequest.respond(2);746 } catch (e) {747 incorrectRespondException = e;748 }749 controller.byobRequest.respond(1);750 },751 type: 'bytes'752 });753 const reader = stream.getReader({ mode: 'byob' });754 return reader.read(new Uint8Array(1)).then(() => {755 assert_true(byobRequestWasDefined, 'byobRequest should be non-null');756 assert_not_equals(incorrectRespondException, undefined, 'respond() must throw');757 assert_equals(incorrectRespondException.name, 'RangeError', 'respond() must throw a RangeError');758 });759}, 'ReadableStream with byte source: read(view), then respond() with too big value');760promise_test(() => {761 let pullCount = 0;762 let controller;763 let byobRequest;764 let viewInfo;765 const stream = new ReadableStream({766 start(c) {767 controller = c;768 },769 pull() {770 ++pullCount;771 byobRequest = controller.byobRequest;772 const view = byobRequest.view;773 viewInfo = extractViewInfo(view);774 view[0] = 0x01;775 view[1] = 0x02;776 view[2] = 0x03;777 controller.byobRequest.respond(3);778 },779 type: 'bytes'780 });781 const reader = stream.getReader({ mode: 'byob' });782 return reader.read(new Uint16Array(2)).then(result => {783 assert_equals(pullCount, 1);784 assert_false(result.done, 'done');785 const view = result.value;786 assert_equals(view.byteOffset, 0, 'byteOffset');787 assert_equals(view.byteLength, 2, 'byteLength');788 const dataView = new DataView(view.buffer, view.byteOffset, view.byteLength);789 assert_equals(dataView.getUint16(0), 0x0102);790 return reader.read(new Uint8Array(1));791 }).then(result => {792 assert_equals(pullCount, 1);793 assert_not_equals(byobRequest, null, 'byobRequest must not be null');794 assert_equals(viewInfo.constructor, Uint8Array, 'view.constructor should be Uint8Array');795 assert_equals(viewInfo.bufferByteLength, 4, 'view.buffer.byteLength should be 4');796 assert_equals(viewInfo.byteOffset, 0, 'view.byteOffset should be 0');797 assert_equals(viewInfo.byteLength, 4, 'view.byteLength should be 4');798 assert_false(result.done, 'done');799 const view = result.value;800 assert_equals(view.byteOffset, 0, 'byteOffset');801 assert_equals(view.byteLength, 1, 'byteLength');802 assert_equals(view[0], 0x03);803 });804}, 'ReadableStream with byte source: respond(3) to read(view) with 2 element Uint16Array enqueues the 1 byte ' +805 'remainder');806promise_test(t => {807 const stream = new ReadableStream({808 start(controller) {809 const view = new Uint8Array(16);810 view[15] = 0x01;811 controller.enqueue(view);812 },813 pull: t.unreached_func('pull() should not be called'),814 type: 'bytes'815 });816 const reader = stream.getReader({ mode: 'byob' });817 return reader.read(new Uint8Array(16)).then(result => {818 assert_false(result.done);819 const view = result.value;820 assert_equals(view.byteOffset, 0);821 assert_equals(view.byteLength, 16);822 assert_equals(view[15], 0x01);823 });824}, 'ReadableStream with byte source: enqueue(), getReader(), then read(view)');825promise_test(t => {826 let cancelCount = 0;827 let reason;828 const passedReason = new TypeError('foo');829 const stream = new ReadableStream({830 start(c) {831 c.enqueue(new Uint8Array(16));832 },833 pull: t.unreached_func('pull() should not be called'),834 cancel(r) {835 if (cancelCount === 0) {836 reason = r;837 }838 ++cancelCount;839 },840 type: 'bytes'841 });842 const reader = stream.getReader();843 return reader.cancel(passedReason).then(result => {844 assert_equals(result, undefined);845 assert_equals(cancelCount, 1);846 assert_equals(reason, passedReason, 'reason should equal the passed reason');847 });848}, 'ReadableStream with byte source: enqueue(), getReader(), then cancel() (mode = not BYOB)');849promise_test(t => {850 let cancelCount = 0;851 let reason;852 const passedReason = new TypeError('foo');853 const stream = new ReadableStream({854 start(c) {855 c.enqueue(new Uint8Array(16));856 },857 pull: t.unreached_func('pull() should not be called'),858 cancel(r) {859 if (cancelCount === 0) {860 reason = r;861 }862 ++cancelCount;863 },864 type: 'bytes'865 });866 const reader = stream.getReader({ mode: 'byob' });867 return reader.cancel(passedReason).then(result => {868 assert_equals(result, undefined);869 assert_equals(cancelCount, 1);870 assert_equals(reason, passedReason, 'reason should equal the passed reason');871 });872}, 'ReadableStream with byte source: enqueue(), getReader(), then cancel() (mode = BYOB)');873promise_test(t => {874 let cancelCount = 0;875 let reason;876 const passedReason = new TypeError('foo');877 let controller;878 const stream = new ReadableStream({879 start(c) {880 controller = c;881 },882 pull: t.unreached_func('pull() should not be called'),883 cancel(r) {884 if (cancelCount === 0) {885 reason = r;886 }887 ++cancelCount;888 return 'bar';889 },890 type: 'bytes'891 });892 const reader = stream.getReader({ mode: 'byob' });893 const readPromise = reader.read(new Uint8Array(1)).then(result => {894 assert_true(result.done, 'result.done');895 assert_equals(result.value, undefined, 'result.value');896 });897 const cancelPromise = reader.cancel(passedReason).then(result => {898 assert_equals(result, undefined, 'cancel() return value should be fulfilled with undefined');899 assert_equals(cancelCount, 1, 'cancel() should be called only once');900 assert_equals(reason, passedReason, 'reason should equal the passed reason');901 });902 return Promise.all([readPromise, cancelPromise]);903}, 'ReadableStream with byte source: getReader(), read(view), then cancel()');904promise_test(() => {905 let pullCount = 0;906 let controller;907 let byobRequest;908 const viewInfos = [];909 const stream = new ReadableStream({910 start(c) {911 controller = c;912 },913 pull() {914 byobRequest = controller.byobRequest;915 viewInfos.push(extractViewInfo(controller.byobRequest.view));916 controller.enqueue(new Uint8Array(1));917 viewInfos.push(extractViewInfo(controller.byobRequest.view));918 ++pullCount;919 },920 type: 'bytes'921 });922 return Promise.resolve().then(() => {923 assert_equals(pullCount, 0, 'No pull() as no read(view) yet');924 const reader = stream.getReader({ mode: 'byob' });925 const promise = reader.read(new Uint16Array(1)).then(result => {926 assert_true(result.done, 'result.done');927 assert_equals(result.value, undefined, 'result.value');928 });929 assert_equals(pullCount, 1, '1 pull() should have been made in response to partial fill by enqueue()');930 assert_not_equals(byobRequest, null, 'byobRequest should not be null');931 assert_equals(viewInfos[0].byteLength, 2, 'byteLength before enqueue() should be 2');932 assert_equals(viewInfos[1].byteLength, 1, 'byteLength after enqueue() should be 1');933 reader.cancel();934 assert_equals(pullCount, 1, 'pull() should only be called once');935 return promise;936 });937}, 'ReadableStream with byte source: cancel() with partially filled pending pull() request');938promise_test(() => {939 let controller;940 let pullCalled = false;941 const stream = new ReadableStream({942 start(c) {943 const view = new Uint8Array(8);944 view[7] = 0x01;945 c.enqueue(view);946 controller = c;947 },948 pull() {949 pullCalled = true;950 },951 type: 'bytes'952 });953 const reader = stream.getReader({ mode: 'byob' });954 const buffer = new ArrayBuffer(16);955 return reader.read(new Uint8Array(buffer, 8, 8)).then(result => {956 assert_false(result.done);957 assert_false(pullCalled, 'pull() must not have been called');958 const view = result.value;959 assert_equals(view.constructor, Uint8Array);960 assert_equals(view.buffer.byteLength, 16);961 assert_equals(view.byteOffset, 8);962 assert_equals(view.byteLength, 8);963 assert_equals(view[7], 0x01);964 });965}, 'ReadableStream with byte source: enqueue(), getReader(), then read(view) where view.buffer is not fully ' +966 'covered by view');967promise_test(() => {968 let controller;969 let pullCalled = false;970 const stream = new ReadableStream({971 start(c) {972 let view;973 view = new Uint8Array(16);974 view[15] = 123;975 c.enqueue(view);976 view = new Uint8Array(8);977 view[7] = 111;978 c.enqueue(view);979 controller = c;980 },981 pull() {982 pullCalled = true;983 },984 type: 'bytes'985 });986 const reader = stream.getReader({ mode: 'byob' });987 return reader.read(new Uint8Array(24)).then(result => {988 assert_false(result.done, 'done');989 assert_false(pullCalled, 'pull() must not have been called');990 const view = result.value;991 assert_equals(view.byteOffset, 0, 'byteOffset');992 assert_equals(view.byteLength, 24, 'byteLength');993 assert_equals(view[15], 123, 'Contents are set from the first chunk');994 assert_equals(view[23], 111, 'Contents are set from the second chunk');995 });996}, 'ReadableStream with byte source: Multiple enqueue(), getReader(), then read(view)');997promise_test(() => {998 let pullCalled = false;999 const stream = new ReadableStream({1000 start(c) {1001 const view = new Uint8Array(16);1002 view[15] = 0x01;1003 c.enqueue(view);1004 },1005 pull() {1006 pullCalled = true;1007 },1008 type: 'bytes'1009 });1010 const reader = stream.getReader({ mode: 'byob' });1011 return reader.read(new Uint8Array(24)).then(result => {1012 assert_false(result.done);1013 assert_false(pullCalled, 'pull() must not have been called');1014 const view = result.value;1015 assert_equals(view.byteOffset, 0);1016 assert_equals(view.byteLength, 16);1017 assert_equals(view[15], 0x01);1018 });1019}, 'ReadableStream with byte source: enqueue(), getReader(), then read(view) with a bigger view');1020promise_test(() => {1021 let pullCalled = false;1022 const stream = new ReadableStream({1023 start(c) {1024 const view = new Uint8Array(16);1025 view[7] = 0x01;1026 view[15] = 0x02;1027 c.enqueue(view);1028 },1029 pull() {1030 pullCalled = true;1031 },1032 type: 'bytes'1033 });1034 const reader = stream.getReader({ mode: 'byob' });1035 return reader.read(new Uint8Array(8)).then(result => {1036 assert_false(result.done, 'done');1037 const view = result.value;1038 assert_equals(view.byteOffset, 0);1039 assert_equals(view.byteLength, 8);1040 assert_equals(view[7], 0x01);1041 return reader.read(new Uint8Array(8));1042 }).then(result => {1043 assert_false(result.done, 'done');1044 assert_false(pullCalled, 'pull() must not have been called');1045 const view = result.value;1046 assert_equals(view.byteOffset, 0);1047 assert_equals(view.byteLength, 8);1048 assert_equals(view[7], 0x02);1049 });1050}, 'ReadableStream with byte source: enqueue(), getReader(), then read(view) with smaller views');1051promise_test(() => {1052 let controller;1053 let viewInfo;1054 const stream = new ReadableStream({1055 start(c) {1056 const view = new Uint8Array(1);1057 view[0] = 0xff;1058 c.enqueue(view);1059 controller = c;1060 },1061 pull() {1062 if (controller.byobRequest === null) {1063 return;1064 }1065 const view = controller.byobRequest.view;1066 viewInfo = extractViewInfo(view);1067 view[0] = 0xaa;1068 controller.byobRequest.respond(1);1069 },1070 type: 'bytes'1071 });1072 const reader = stream.getReader({ mode: 'byob' });1073 return reader.read(new Uint16Array(1)).then(result => {1074 assert_false(result.done);1075 const view = result.value;1076 assert_equals(view.byteOffset, 0);1077 assert_equals(view.byteLength, 2);1078 const dataView = new DataView(view.buffer, view.byteOffset, view.byteLength);1079 assert_equals(dataView.getUint16(0), 0xffaa);1080 assert_equals(viewInfo.constructor, Uint8Array, 'view.constructor should be Uint8Array');1081 assert_equals(viewInfo.bufferByteLength, 2, 'view.buffer.byteLength should be 2');1082 assert_equals(viewInfo.byteOffset, 1, 'view.byteOffset should be 1');1083 assert_equals(viewInfo.byteLength, 1, 'view.byteLength should be 1');1084 });1085}, 'ReadableStream with byte source: enqueue() 1 byte, getReader(), then read(view) with Uint16Array');1086promise_test(() => {1087 let pullCount = 0;1088 let controller;1089 let byobRequest;1090 let viewInfo;1091 let desiredSize;1092 const stream = new ReadableStream({1093 start(c) {1094 const view = new Uint8Array(3);1095 view[0] = 0x01;1096 view[2] = 0x02;1097 c.enqueue(view);1098 controller = c;1099 },1100 pull() {1101 byobRequest = controller.byobRequest;1102 const view = controller.byobRequest.view;1103 viewInfo = extractViewInfo(view);1104 view[0] = 0x03;1105 controller.byobRequest.respond(1);1106 desiredSize = controller.desiredSize;1107 ++pullCount;1108 },1109 type: 'bytes'1110 });1111 // Wait for completion of the start method to be reflected.1112 return Promise.resolve().then(() => {1113 const reader = stream.getReader({ mode: 'byob' });1114 const promise = reader.read(new Uint16Array(2)).then(result => {1115 assert_false(result.done, 'done');1116 const view = result.value;1117 assert_equals(view.constructor, Uint16Array, 'constructor');1118 assert_equals(view.buffer.byteLength, 4, 'buffer.byteLength');1119 assert_equals(view.byteOffset, 0, 'byteOffset');1120 assert_equals(view.byteLength, 2, 'byteLength');1121 const dataView = new DataView(view.buffer, view.byteOffset, view.byteLength);1122 assert_equals(dataView.getUint16(0), 0x0100, 'contents are set');1123 const p = reader.read(new Uint16Array(1));1124 assert_equals(pullCount, 1);1125 return p;1126 }).then(result => {1127 assert_false(result.done, 'done');1128 const view = result.value;1129 assert_equals(view.buffer.byteLength, 2, 'buffer.byteLength');1130 assert_equals(view.byteOffset, 0, 'byteOffset');1131 assert_equals(view.byteLength, 2, 'byteLength');1132 const dataView = new DataView(view.buffer, view.byteOffset, view.byteLength);1133 assert_equals(dataView.getUint16(0), 0x0203, 'contents are set');1134 assert_not_equals(byobRequest, null, 'byobRequest must not be null');1135 assert_equals(viewInfo.constructor, Uint8Array, 'view.constructor should be Uint8Array');1136 assert_equals(viewInfo.bufferByteLength, 2, 'view.buffer.byteLength should be 2');1137 assert_equals(viewInfo.byteOffset, 1, 'view.byteOffset should be 1');1138 assert_equals(viewInfo.byteLength, 1, 'view.byteLength should be 1');1139 assert_equals(desiredSize, 0, 'desiredSize should be zero');1140 });1141 assert_equals(pullCount, 0);1142 return promise;1143 });1144}, 'ReadableStream with byte source: enqueue() 3 byte, getReader(), then read(view) with 2-element Uint16Array');1145promise_test(t => {1146 const stream = new ReadableStream({1147 start(c) {1148 const view = new Uint8Array(1);1149 view[0] = 0xff;1150 c.enqueue(view);1151 c.close();1152 },1153 pull: t.unreached_func('pull() should not be called'),1154 type: 'bytes'1155 });1156 const reader = stream.getReader({ mode: 'byob' });1157 return promise_rejects_js(t, TypeError, reader.read(new Uint16Array(1)), 'read(view) must fail')1158 .then(() => promise_rejects_js(t, TypeError, reader.closed, 'reader.closed should reject'));1159}, 'ReadableStream with byte source: read(view) with Uint16Array on close()-d stream with 1 byte enqueue()-d must ' +1160 'fail');1161promise_test(t => {1162 let controller;1163 const stream = new ReadableStream({1164 start(c) {1165 const view = new Uint8Array(1);1166 view[0] = 0xff;1167 c.enqueue(view);1168 controller = c;1169 },1170 pull: t.unreached_func('pull() should not be called'),1171 type: 'bytes'1172 });1173 const reader = stream.getReader({ mode: 'byob' });1174 const readPromise = reader.read(new Uint16Array(1));1175 assert_throws_js(TypeError, () => controller.close(), 'controller.close() must throw');1176 return promise_rejects_js(t, TypeError, readPromise, 'read(view) must fail')1177 .then(() => promise_rejects_js(t, TypeError, reader.closed, 'reader.closed must reject'));1178}, 'ReadableStream with byte source: A stream must be errored if close()-d before fulfilling read(view) with ' +1179 'Uint16Array');1180test(() => {1181 let controller;1182 new ReadableStream({1183 start(c) {1184 controller = c;1185 },1186 type: 'bytes'1187 });1188 // Enqueue a chunk so that the stream doesn't get closed. This is to check duplicate close() calls are rejected1189 // even if the stream has not yet entered the closed state.1190 const view = new Uint8Array(1);1191 controller.enqueue(view);1192 controller.close();1193 assert_throws_js(TypeError, () => controller.close(), 'controller.close() must throw');1194}, 'ReadableStream with byte source: Throw if close()-ed more than once');1195test(() => {1196 let controller;1197 new ReadableStream({1198 start(c) {1199 controller = c;1200 },1201 type: 'bytes'1202 });1203 // Enqueue a chunk so that the stream doesn't get closed. This is to check enqueue() after close() is rejected1204 // even if the stream has not yet entered the closed state.1205 const view = new Uint8Array(1);1206 controller.enqueue(view);1207 controller.close();1208 assert_throws_js(TypeError, () => controller.enqueue(view), 'controller.close() must throw');1209}, 'ReadableStream with byte source: Throw on enqueue() after close()');1210promise_test(() => {1211 let controller;1212 let byobRequest;1213 let viewInfo;1214 const stream = new ReadableStream({1215 start(c) {1216 controller = c;1217 },1218 pull() {1219 byobRequest = controller.byobRequest;1220 const view = controller.byobRequest.view;1221 viewInfo = extractViewInfo(view);1222 view[15] = 0x01;1223 controller.byobRequest.respond(16);1224 controller.close();1225 },1226 type: 'bytes'1227 });1228 const reader = stream.getReader({ mode: 'byob' });1229 return reader.read(new Uint8Array(16)).then(result => {1230 assert_false(result.done);1231 const view = result.value;1232 assert_equals(view.byteOffset, 0);1233 assert_equals(view.byteLength, 16);1234 assert_equals(view[15], 0x01);1235 return reader.read(new Uint8Array(16));1236 }).then(result => {1237 assert_true(result.done);1238 const view = result.value;1239 assert_equals(view.byteOffset, 0);1240 assert_equals(view.byteLength, 0);1241 assert_not_equals(byobRequest, null, 'byobRequest must not be null');1242 assert_equals(viewInfo.constructor, Uint8Array, 'view.constructor should be Uint8Array');1243 assert_equals(viewInfo.bufferByteLength, 16, 'view.buffer.byteLength should be 16');1244 assert_equals(viewInfo.byteOffset, 0, 'view.byteOffset should be 0');1245 assert_equals(viewInfo.byteLength, 16, 'view.byteLength should be 16');1246 });1247}, 'ReadableStream with byte source: read(view), then respond() and close() in pull()');1248promise_test(() => {1249 let pullCount = 0;1250 let controller;1251 const viewInfos = [];1252 const viewInfosAfterRespond = [];1253 const stream = new ReadableStream({1254 start(c) {1255 controller = c;1256 },1257 pull() {1258 if (controller.byobRequest === null) {1259 return;1260 }1261 for (let i = 0; i < 4; ++i) {1262 const view = controller.byobRequest.view;1263 viewInfos.push(extractViewInfo(view));1264 view[0] = 0x01;1265 controller.byobRequest.respond(1);1266 viewInfosAfterRespond.push(extractViewInfo(view));1267 }1268 ++pullCount;1269 },1270 type: 'bytes'1271 });1272 const reader = stream.getReader({ mode: 'byob' });1273 return reader.read(new Uint32Array(1)).then(result => {1274 assert_false(result.done, 'result.done');1275 const view = result.value;1276 assert_equals(view.byteOffset, 0, 'result.value.byteOffset');1277 assert_equals(view.byteLength, 4, 'result.value.byteLength');1278 assert_equals(view[0], 0x01010101, 'result.value[0]');1279 assert_equals(pullCount, 1, 'pull() should only be called once');1280 for (let i = 0; i < 4; ++i) {1281 assert_equals(viewInfos[i].constructor, Uint8Array, 'view.constructor should be Uint8Array');1282 assert_equals(viewInfos[i].bufferByteLength, 4, 'view.buffer.byteLength should be 4');1283 assert_equals(viewInfos[i].byteOffset, i, 'view.byteOffset should be i');1284 assert_equals(viewInfos[i].byteLength, 4 - i, 'view.byteLength should be 4 - i');1285 assert_equals(viewInfosAfterRespond[i].bufferByteLength, 0, 'view.buffer should be transferred after respond()');1286 }1287 });1288}, 'ReadableStream with byte source: read(view) with Uint32Array, then fill it by multiple respond() calls');1289promise_test(() => {1290 let pullCount = 0;1291 let controller;1292 const viewInfos = [];1293 const viewInfosAfterEnqueue = [];1294 const stream = new ReadableStream({1295 start(c) {1296 controller = c;1297 },1298 pull() {1299 if (controller.byobRequest === null) {1300 return;1301 }1302 for (let i = 0; i < 4; ++i) {1303 const view = controller.byobRequest.view;1304 viewInfos.push(extractViewInfo(view));1305 controller.enqueue(new Uint8Array([0x01]));1306 viewInfosAfterEnqueue.push(extractViewInfo(view));1307 }1308 ++pullCount;1309 },1310 type: 'bytes'1311 });1312 const reader = stream.getReader({ mode: 'byob' });1313 return reader.read(new Uint32Array(1)).then(result => {1314 assert_false(result.done, 'result.done');1315 const view = result.value;1316 assert_equals(view.byteOffset, 0, 'result.value.byteOffset');1317 assert_equals(view.byteLength, 4, 'result.value.byteLength');1318 assert_equals(view[0], 0x01010101, 'result.value[0]');1319 assert_equals(pullCount, 1, 'pull() should only be called once');1320 for (let i = 0; i < 4; ++i) {...
aflprep_general.any.js
Source:aflprep_general.any.js
...227 return Promise.resolve().then(() => {228 assert_equals(pullCount, 1, 'pull must be invoked');229 });230}, 'ReadableStream with byte source: Automatic pull() after start() and read()');231function extractViewInfo(view) {232 return {233 constructor: view.constructor,234 bufferByteLength: view.buffer.byteLength,235 byteOffset: view.byteOffset,236 byteLength: view.byteLength237 };238}239promise_test(() => {240 let pullCount = 0;241 let controller;242 const byobRequests = [];243 const stream = new ReadableStream({244 start(c) {245 controller = c;246 },247 pull() {248 const byobRequest = controller.byobRequest;249 const view = byobRequest.view;250 byobRequests[pullCount] = {251 nonNull: byobRequest !== null,252 viewNonNull: view !== null,253 viewInfo: extractViewInfo(view)254 };255 if (pullCount === 0) {256 view[0] = 0x01;257 byobRequest.respond(1);258 } else if (pullCount === 1) {259 view[0] = 0x02;260 view[1] = 0x03;261 byobRequest.respond(2);262 }263 ++pullCount;264 },265 type: 'bytes',266 autoAllocateChunkSize: 16267 }, {268 highWaterMark: 0269 });270 const reader = stream.getReader();271 const p0 = reader.read();272 const p1 = reader.read();273 assert_equals(pullCount, 0, 'No pull() as start() just finished and is not yet reflected to the state of the stream');274 return Promise.resolve().then(() => {275 assert_equals(pullCount, 1, 'pull() must have been invoked once');276 const byobRequest = byobRequests[0];277 assert_true(byobRequest.nonNull, 'first byobRequest must not be null');278 assert_true(byobRequest.viewNonNull, 'first byobRequest.view must not be null');279 const viewInfo = byobRequest.viewInfo;280 assert_equals(viewInfo.constructor, Uint8Array, 'first view.constructor should be Uint8Array');281 assert_equals(viewInfo.bufferByteLength, 16, 'first view.buffer.byteLength should be 16');282 assert_equals(viewInfo.byteOffset, 0, 'first view.byteOffset should be 0');283 assert_equals(viewInfo.byteLength, 16, 'first view.byteLength should be 16');284 return p0;285 }).then(result => {286 assert_equals(pullCount, 2, 'pull() must have been invoked twice');287 const value = result.value;288 assert_not_equals(value, undefined, 'first read should have a value');289 assert_equals(value.constructor, Uint8Array, 'first value should be a Uint8Array');290 assert_equals(value.buffer.byteLength, 16, 'first value.buffer.byteLength should be 16');291 assert_equals(value.byteOffset, 0, 'first value.byteOffset should be 0');292 assert_equals(value.byteLength, 1, 'first value.byteLength should be 1');293 assert_equals(value[0], 0x01, 'first value[0] should be 0x01');294 const byobRequest = byobRequests[1];295 assert_true(byobRequest.nonNull, 'second byobRequest must not be null');296 assert_true(byobRequest.viewNonNull, 'second byobRequest.view must not be null');297 const viewInfo = byobRequest.viewInfo;298 assert_equals(viewInfo.constructor, Uint8Array, 'second view.constructor should be Uint8Array');299 assert_equals(viewInfo.bufferByteLength, 16, 'second view.buffer.byteLength should be 16');300 assert_equals(viewInfo.byteOffset, 0, 'second view.byteOffset should be 0');301 assert_equals(viewInfo.byteLength, 16, 'second view.byteLength should be 16');302 return p1;303 }).then(result => {304 assert_equals(pullCount, 2, 'pull() should only be invoked twice');305 const value = result.value;306 assert_not_equals(value, undefined, 'second read should have a value');307 assert_equals(value.constructor, Uint8Array, 'second value should be a Uint8Array');308 assert_equals(value.buffer.byteLength, 16, 'second value.buffer.byteLength should be 16');309 assert_equals(value.byteOffset, 0, 'second value.byteOffset should be 0');310 assert_equals(value.byteLength, 2, 'second value.byteLength should be 2');311 assert_equals(value[0], 0x02, 'second value[0] should be 0x02');312 assert_equals(value[1], 0x03, 'second value[1] should be 0x03');313 });314}, 'ReadableStream with byte source: autoAllocateChunkSize');315promise_test(() => {316 let pullCount = 0;317 let controller;318 const byobRequests = [];319 const stream = new ReadableStream({320 start(c) {321 controller = c;322 },323 pull() {324 const byobRequest = controller.byobRequest;325 const view = byobRequest.view;326 byobRequests[pullCount] = {327 nonNull: byobRequest !== null,328 viewNonNull: view !== null,329 viewInfo: extractViewInfo(view)330 };331 if (pullCount === 0) {332 view[0] = 0x01;333 byobRequest.respond(1);334 } else if (pullCount === 1) {335 view[0] = 0x02;336 view[1] = 0x03;337 byobRequest.respond(2);338 }339 ++pullCount;340 },341 type: 'bytes',342 autoAllocateChunkSize: 16343 }, {344 highWaterMark: 0345 });346 const reader = stream.getReader();347 return reader.read().then(result => {348 const value = result.value;349 assert_not_equals(value, undefined, 'first read should have a value');350 assert_equals(value.constructor, Uint8Array, 'first value should be a Uint8Array');351 assert_equals(value.buffer.byteLength, 16, 'first value.buffer.byteLength should be 16');352 assert_equals(value.byteOffset, 0, 'first value.byteOffset should be 0');353 assert_equals(value.byteLength, 1, 'first value.byteLength should be 1');354 assert_equals(value[0], 0x01, 'first value[0] should be 0x01');355 const byobRequest = byobRequests[0];356 assert_true(byobRequest.nonNull, 'first byobRequest must not be null');357 assert_true(byobRequest.viewNonNull, 'first byobRequest.view must not be null');358 const viewInfo = byobRequest.viewInfo;359 assert_equals(viewInfo.constructor, Uint8Array, 'first view.constructor should be Uint8Array');360 assert_equals(viewInfo.bufferByteLength, 16, 'first view.buffer.byteLength should be 16');361 assert_equals(viewInfo.byteOffset, 0, 'first view.byteOffset should be 0');362 assert_equals(viewInfo.byteLength, 16, 'first view.byteLength should be 16');363 reader.releaseLock();364 const byobReader = stream.getReader({ mode: 'byob' });365 return byobReader.read(new Uint8Array(32));366 }).then(result => {367 const value = result.value;368 assert_not_equals(value, undefined, 'second read should have a value');369 assert_equals(value.constructor, Uint8Array, 'second value should be a Uint8Array');370 assert_equals(value.buffer.byteLength, 32, 'second value.buffer.byteLength should be 32');371 assert_equals(value.byteOffset, 0, 'second value.byteOffset should be 0');372 assert_equals(value.byteLength, 2, 'second value.byteLength should be 2');373 assert_equals(value[0], 0x02, 'second value[0] should be 0x02');374 assert_equals(value[1], 0x03, 'second value[1] should be 0x03');375 const byobRequest = byobRequests[1];376 assert_true(byobRequest.nonNull, 'second byobRequest must not be null');377 assert_true(byobRequest.viewNonNull, 'second byobRequest.view must not be null');378 const viewInfo = byobRequest.viewInfo;379 assert_equals(viewInfo.constructor, Uint8Array, 'second view.constructor should be Uint8Array');380 assert_equals(viewInfo.bufferByteLength, 32, 'second view.buffer.byteLength should be 32');381 assert_equals(viewInfo.byteOffset, 0, 'second view.byteOffset should be 0');382 assert_equals(viewInfo.byteLength, 32, 'second view.byteLength should be 32');383 assert_equals(pullCount, 2, 'pullCount should be 2');384 });385}, 'ReadableStream with byte source: Mix of auto allocate and BYOB');386promise_test(() => {387 let pullCount = 0;388 const stream = new ReadableStream({389 pull() {390 ++pullCount;391 },392 type: 'bytes'393 }, {394 highWaterMark: 0395 });396 const reader = stream.getReader();397 reader.read(new Uint8Array(8));398 assert_equals(pullCount, 0, 'No pull as start() just finished and is not yet reflected to the state of the stream');399 return Promise.resolve().then(() => {400 assert_equals(pullCount, 1, 'pull must be invoked');401 });402}, 'ReadableStream with byte source: Automatic pull() after start() and read(view)');403promise_test(() => {404 let pullCount = 0;405 let controller;406 let desiredSizeInStart;407 let desiredSizeInPull;408 const stream = new ReadableStream({409 start(c) {410 c.enqueue(new Uint8Array(16));411 desiredSizeInStart = c.desiredSize;412 controller = c;413 },414 pull() {415 ++pullCount;416 if (pullCount === 1) {417 desiredSizeInPull = controller.desiredSize;418 }419 },420 type: 'bytes'421 }, {422 highWaterMark: 8423 });424 return Promise.resolve().then(() => {425 assert_equals(pullCount, 0, 'No pull as the queue was filled by start()');426 assert_equals(desiredSizeInStart, -8, 'desiredSize after enqueue() in start()');427 const reader = stream.getReader();428 const promise = reader.read();429 assert_equals(pullCount, 1, 'The first pull() should be made on read()');430 assert_equals(desiredSizeInPull, 8, 'desiredSize in pull()');431 return promise.then(result => {432 assert_false(result.done, 'result.done');433 const view = result.value;434 assert_equals(view.constructor, Uint8Array, 'view.constructor');435 assert_equals(view.buffer.byteLength, 16, 'view.buffer');436 assert_equals(view.byteOffset, 0, 'view.byteOffset');437 assert_equals(view.byteLength, 16, 'view.byteLength');438 });439 });440}, 'ReadableStream with byte source: enqueue(), getReader(), then read()');441promise_test(() => {442 let controller;443 const stream = new ReadableStream({444 start(c) {445 controller = c;446 },447 type: 'bytes'448 });449 const reader = stream.getReader();450 const promise = reader.read().then(result => {451 assert_false(result.done);452 const view = result.value;453 assert_equals(view.constructor, Uint8Array);454 assert_equals(view.buffer.byteLength, 1);455 assert_equals(view.byteOffset, 0);456 assert_equals(view.byteLength, 1);457 });458 controller.enqueue(new Uint8Array(1));459 return promise;460}, 'ReadableStream with byte source: Push source that doesn\'t understand pull signal');461test(() => {462 assert_throws_js(TypeError, () => new ReadableStream({463 pull: 'foo',464 type: 'bytes'465 }), 'constructor should throw');466}, 'ReadableStream with byte source: pull() function is not callable');467promise_test(() => {468 const stream = new ReadableStream({469 start(c) {470 c.enqueue(new Uint16Array(16));471 },472 type: 'bytes'473 });474 const reader = stream.getReader();475 return reader.read().then(result => {476 assert_false(result.done);477 const view = result.value;478 assert_equals(view.constructor, Uint8Array);479 assert_equals(view.buffer.byteLength, 32);480 assert_equals(view.byteOffset, 0);481 assert_equals(view.byteLength, 32);482 });483}, 'ReadableStream with byte source: enqueue() with Uint16Array, getReader(), then read()');484promise_test(t => {485 const stream = new ReadableStream({486 start(c) {487 const view = new Uint8Array(16);488 view[0] = 0x01;489 view[8] = 0x02;490 c.enqueue(view);491 },492 pull: t.unreached_func('pull() should not be called'),493 type: 'bytes'494 });495 const byobReader = stream.getReader({ mode: 'byob' });496 return byobReader.read(new Uint8Array(8)).then(result => {497 assert_false(result.done, 'done');498 const view = result.value;499 assert_equals(view.constructor, Uint8Array, 'value.constructor');500 assert_equals(view.buffer.byteLength, 8, 'value.buffer.byteLength');501 assert_equals(view.byteOffset, 0, 'value.byteOffset');502 assert_equals(view.byteLength, 8, 'value.byteLength');503 assert_equals(view[0], 0x01);504 byobReader.releaseLock();505 const reader = stream.getReader();506 return reader.read();507 }).then(result => {508 assert_false(result.done, 'done');509 const view = result.value;510 assert_equals(view.constructor, Uint8Array, 'value.constructor');511 assert_equals(view.buffer.byteLength, 16, 'value.buffer.byteLength');512 assert_equals(view.byteOffset, 8, 'value.byteOffset');513 assert_equals(view.byteLength, 8, 'value.byteLength');514 assert_equals(view[0], 0x02);515 });516}, 'ReadableStream with byte source: enqueue(), read(view) partially, then read()');517promise_test(t => {518 let controller;519 const stream = new ReadableStream({520 start(c) {521 controller = c;522 },523 pull: t.unreached_func('pull() should not be called'),524 type: 'bytes'525 });526 const reader = stream.getReader();527 controller.enqueue(new Uint8Array(16));528 controller.close();529 return reader.read().then(result => {530 assert_false(result.done, 'done');531 const view = result.value;532 assert_equals(view.byteOffset, 0, 'byteOffset');533 assert_equals(view.byteLength, 16, 'byteLength');534 return reader.read();535 }).then(result => {536 assert_true(result.done, 'done');537 assert_equals(result.value, undefined, 'value');538 });539}, 'ReadableStream with byte source: getReader(), enqueue(), close(), then read()');540promise_test(t => {541 const stream = new ReadableStream({542 start(c) {543 c.enqueue(new Uint8Array(16));544 c.close();545 },546 pull: t.unreached_func('pull() should not be called'),547 type: 'bytes'548 });549 const reader = stream.getReader();550 return reader.read().then(result => {551 assert_false(result.done, 'done');552 const view = result.value;553 assert_equals(view.byteOffset, 0, 'byteOffset');554 assert_equals(view.byteLength, 16, 'byteLength');555 return reader.read();556 }).then(result => {557 assert_true(result.done, 'done');558 assert_equals(result.value, undefined, 'value');559 });560}, 'ReadableStream with byte source: enqueue(), close(), getReader(), then read()');561promise_test(() => {562 let controller;563 let byobRequest;564 const stream = new ReadableStream({565 start(c) {566 controller = c;567 },568 pull() {569 controller.enqueue(new Uint8Array(16));570 byobRequest = controller.byobRequest;571 },572 type: 'bytes'573 });574 const reader = stream.getReader();575 return reader.read().then(result => {576 assert_false(result.done, 'done');577 assert_equals(result.value.byteLength, 16, 'byteLength');578 assert_equals(byobRequest, null, 'byobRequest must be null');579 });580}, 'ReadableStream with byte source: Respond to pull() by enqueue()');581promise_test(() => {582 let pullCount = 0;583 let controller;584 let byobRequest;585 const desiredSizes = [];586 const stream = new ReadableStream({587 start(c) {588 controller = c;589 },590 pull() {591 byobRequest = controller.byobRequest;592 desiredSizes.push(controller.desiredSize);593 controller.enqueue(new Uint8Array(1));594 desiredSizes.push(controller.desiredSize);595 controller.enqueue(new Uint8Array(1));596 desiredSizes.push(controller.desiredSize);597 ++pullCount;598 },599 type: 'bytes'600 }, {601 highWaterMark: 0602 });603 const reader = stream.getReader();604 const p0 = reader.read();605 const p1 = reader.read();606 const p2 = reader.read();607 controller.enqueue(new Uint8Array(1));608 assert_equals(pullCount, 0, 'pullCount after the enqueue() outside pull');609 return Promise.all([p0, p1, p2]).then(result => {610 assert_equals(pullCount, 1, 'pullCount after completion of all read()s');611 assert_equals(result[0].done, false, 'result[0].done');612 assert_equals(result[0].value.byteLength, 1, 'result[0].value.byteLength');613 assert_equals(result[1].done, false, 'result[1].done');614 assert_equals(result[1].value.byteLength, 1, 'result[1].value.byteLength');615 assert_equals(result[2].done, false, 'result[2].done');616 assert_equals(result[2].value.byteLength, 1, 'result[2].value.byteLength');617 assert_equals(byobRequest, null, 'byobRequest should be null');618 assert_equals(desiredSizes[0], 0, 'desiredSize on pull should be 0');619 assert_equals(desiredSizes[1], 0, 'desiredSize after 1st enqueue() should be 0');620 assert_equals(desiredSizes[2], 0, 'desiredSize after 2nd enqueue() should be 0');621 assert_equals(pullCount, 1, 'pull() should only be called once');622 });623}, 'ReadableStream with byte source: Respond to pull() by enqueue() asynchronously');624promise_test(() => {625 let pullCount = 0;626 let byobRequest;627 const desiredSizes = [];628 const stream = new ReadableStream({629 pull(c) {630 byobRequest = c.byobRequest;631 desiredSizes.push(c.desiredSize);632 if (pullCount < 3) {633 c.enqueue(new Uint8Array(1));634 } else {635 c.close();636 }637 ++pullCount;638 },639 type: 'bytes'640 }, {641 highWaterMark: 256642 });643 const reader = stream.getReader();644 const p0 = reader.read();645 const p1 = reader.read();646 const p2 = reader.read();647 assert_equals(pullCount, 0, 'No pull as start() just finished and is not yet reflected to the state of the stream');648 return Promise.all([p0, p1, p2]).then(result => {649 assert_equals(pullCount, 4, 'pullCount after completion of all read()s');650 assert_equals(result[0].done, false, 'result[0].done');651 assert_equals(result[0].value.byteLength, 1, 'result[0].value.byteLength');652 assert_equals(result[1].done, false, 'result[1].done');653 assert_equals(result[1].value.byteLength, 1, 'result[1].value.byteLength');654 assert_equals(result[2].done, false, 'result[2].done');655 assert_equals(result[2].value.byteLength, 1, 'result[2].value.byteLength');656 assert_equals(byobRequest, null, 'byobRequest should be null');657 assert_equals(desiredSizes[0], 256, 'desiredSize on pull should be 256');658 assert_equals(desiredSizes[1], 256, 'desiredSize after 1st enqueue() should be 256');659 assert_equals(desiredSizes[2], 256, 'desiredSize after 2nd enqueue() should be 256');660 assert_equals(desiredSizes[3], 256, 'desiredSize after 3rd enqueue() should be 256');661 });662}, 'ReadableStream with byte source: Respond to multiple pull() by separate enqueue()');663promise_test(() => {664 let controller;665 let pullCount = 0;666 const byobRequestDefined = [];667 let byobRequestViewDefined;668 const stream = new ReadableStream({669 start(c) {670 controller = c;671 },672 pull() {673 byobRequestDefined.push(controller.byobRequest !== null);674 const initialByobRequest = controller.byobRequest;675 const view = controller.byobRequest.view;676 view[0] = 0x01;677 controller.byobRequest.respond(1);678 byobRequestDefined.push(controller.byobRequest !== null);679 byobRequestViewDefined = initialByobRequest.view !== null;680 ++pullCount;681 },682 type: 'bytes'683 });684 const reader = stream.getReader({ mode: 'byob' });685 return reader.read(new Uint8Array(1)).then(result => {686 assert_false(result.done, 'result.done');687 assert_equals(result.value.byteLength, 1, 'result.value.byteLength');688 assert_equals(result.value[0], 0x01, 'result.value[0]');689 assert_equals(pullCount, 1, 'pull() should be called only once');690 assert_true(byobRequestDefined[0], 'byobRequest must not be null before respond()');691 assert_false(byobRequestDefined[1], 'byobRequest must be null after respond()');692 assert_false(byobRequestViewDefined, 'view of initial byobRequest must be null after respond()');693 });694}, 'ReadableStream with byte source: read(view), then respond()');695promise_test(() => {696 let controller;697 let pullCount = 0;698 const byobRequestDefined = [];699 let byobRequestViewDefined;700 const stream = new ReadableStream({701 start(c) {702 controller = c;703 },704 async pull() {705 byobRequestDefined.push(controller.byobRequest !== null);706 const initialByobRequest = controller.byobRequest;707 const transferredView = await transferArrayBufferView(controller.byobRequest.view);708 transferredView[0] = 0x01;709 controller.byobRequest.respondWithNewView(transferredView);710 byobRequestDefined.push(controller.byobRequest !== null);711 byobRequestViewDefined = initialByobRequest.view !== null;712 ++pullCount;713 },714 type: 'bytes'715 });716 const reader = stream.getReader({ mode: 'byob' });717 return reader.read(new Uint8Array(1)).then(result => {718 assert_false(result.done, 'result.done');719 assert_equals(result.value.byteLength, 1, 'result.value.byteLength');720 assert_equals(result.value[0], 0x01, 'result.value[0]');721 assert_equals(pullCount, 1, 'pull() should be called only once');722 assert_true(byobRequestDefined[0], 'byobRequest must not be null before respondWithNewView()');723 assert_false(byobRequestDefined[1], 'byobRequest must be null after respondWithNewView()');724 assert_false(byobRequestViewDefined, 'view of initial byobRequest must be null after respondWithNewView()');725 });726}, 'ReadableStream with byte source: read(view), then respondWithNewView() with a transferred ArrayBuffer');727promise_test(() => {728 let controller;729 let byobRequestWasDefined;730 let incorrectRespondException;731 const stream = new ReadableStream({732 start(c) {733 controller = c;734 },735 pull() {736 byobRequestWasDefined = controller.byobRequest !== null;737 try {738 controller.byobRequest.respond(2);739 } catch (e) {740 incorrectRespondException = e;741 }742 controller.byobRequest.respond(1);743 },744 type: 'bytes'745 });746 const reader = stream.getReader({ mode: 'byob' });747 return reader.read(new Uint8Array(1)).then(() => {748 assert_true(byobRequestWasDefined, 'byobRequest should be non-null');749 assert_not_equals(incorrectRespondException, undefined, 'respond() must throw');750 assert_equals(incorrectRespondException.name, 'RangeError', 'respond() must throw a RangeError');751 });752}, 'ReadableStream with byte source: read(view), then respond() with too big value');753promise_test(() => {754 let pullCount = 0;755 let controller;756 let byobRequest;757 let viewInfo;758 const stream = new ReadableStream({759 start(c) {760 controller = c;761 },762 pull() {763 ++pullCount;764 byobRequest = controller.byobRequest;765 const view = byobRequest.view;766 viewInfo = extractViewInfo(view);767 view[0] = 0x01;768 view[1] = 0x02;769 view[2] = 0x03;770 controller.byobRequest.respond(3);771 },772 type: 'bytes'773 });774 const reader = stream.getReader({ mode: 'byob' });775 return reader.read(new Uint16Array(2)).then(result => {776 assert_equals(pullCount, 1);777 assert_false(result.done, 'done');778 const view = result.value;779 assert_equals(view.byteOffset, 0, 'byteOffset');780 assert_equals(view.byteLength, 2, 'byteLength');781 const dataView = new DataView(view.buffer, view.byteOffset, view.byteLength);782 assert_equals(dataView.getUint16(0), 0x0102);783 return reader.read(new Uint8Array(1));784 }).then(result => {785 assert_equals(pullCount, 1);786 assert_not_equals(byobRequest, null, 'byobRequest must not be null');787 assert_equals(viewInfo.constructor, Uint8Array, 'view.constructor should be Uint8Array');788 assert_equals(viewInfo.bufferByteLength, 4, 'view.buffer.byteLength should be 4');789 assert_equals(viewInfo.byteOffset, 0, 'view.byteOffset should be 0');790 assert_equals(viewInfo.byteLength, 4, 'view.byteLength should be 4');791 assert_false(result.done, 'done');792 const view = result.value;793 assert_equals(view.byteOffset, 0, 'byteOffset');794 assert_equals(view.byteLength, 1, 'byteLength');795 assert_equals(view[0], 0x03);796 });797}, 'ReadableStream with byte source: respond(3) to read(view) with 2 element Uint16Array enqueues the 1 byte ' +798 'remainder');799promise_test(t => {800 const stream = new ReadableStream({801 start(controller) {802 const view = new Uint8Array(16);803 view[15] = 0x01;804 controller.enqueue(view);805 },806 pull: t.unreached_func('pull() should not be called'),807 type: 'bytes'808 });809 const reader = stream.getReader({ mode: 'byob' });810 return reader.read(new Uint8Array(16)).then(result => {811 assert_false(result.done);812 const view = result.value;813 assert_equals(view.byteOffset, 0);814 assert_equals(view.byteLength, 16);815 assert_equals(view[15], 0x01);816 });817}, 'ReadableStream with byte source: enqueue(), getReader(), then read(view)');818promise_test(t => {819 let cancelCount = 0;820 let reason;821 const passedReason = new TypeError('foo');822 const stream = new ReadableStream({823 start(c) {824 c.enqueue(new Uint8Array(16));825 },826 pull: t.unreached_func('pull() should not be called'),827 cancel(r) {828 if (cancelCount === 0) {829 reason = r;830 }831 ++cancelCount;832 },833 type: 'bytes'834 });835 const reader = stream.getReader();836 return reader.cancel(passedReason).then(result => {837 assert_equals(result, undefined);838 assert_equals(cancelCount, 1);839 assert_equals(reason, passedReason, 'reason should equal the passed reason');840 });841}, 'ReadableStream with byte source: enqueue(), getReader(), then cancel() (mode = not BYOB)');842promise_test(t => {843 let cancelCount = 0;844 let reason;845 const passedReason = new TypeError('foo');846 const stream = new ReadableStream({847 start(c) {848 c.enqueue(new Uint8Array(16));849 },850 pull: t.unreached_func('pull() should not be called'),851 cancel(r) {852 if (cancelCount === 0) {853 reason = r;854 }855 ++cancelCount;856 },857 type: 'bytes'858 });859 const reader = stream.getReader({ mode: 'byob' });860 return reader.cancel(passedReason).then(result => {861 assert_equals(result, undefined);862 assert_equals(cancelCount, 1);863 assert_equals(reason, passedReason, 'reason should equal the passed reason');864 });865}, 'ReadableStream with byte source: enqueue(), getReader(), then cancel() (mode = BYOB)');866promise_test(t => {867 let cancelCount = 0;868 let reason;869 const passedReason = new TypeError('foo');870 let controller;871 const stream = new ReadableStream({872 start(c) {873 controller = c;874 },875 pull: t.unreached_func('pull() should not be called'),876 cancel(r) {877 if (cancelCount === 0) {878 reason = r;879 }880 ++cancelCount;881 return 'bar';882 },883 type: 'bytes'884 });885 const reader = stream.getReader({ mode: 'byob' });886 const readPromise = reader.read(new Uint8Array(1)).then(result => {887 assert_true(result.done, 'result.done');888 assert_equals(result.value, undefined, 'result.value');889 });890 const cancelPromise = reader.cancel(passedReason).then(result => {891 assert_equals(result, undefined, 'cancel() return value should be fulfilled with undefined');892 assert_equals(cancelCount, 1, 'cancel() should be called only once');893 assert_equals(reason, passedReason, 'reason should equal the passed reason');894 });895 return Promise.all([readPromise, cancelPromise]);896}, 'ReadableStream with byte source: getReader(), read(view), then cancel()');897promise_test(() => {898 let pullCount = 0;899 let controller;900 let byobRequest;901 const viewInfos = [];902 const stream = new ReadableStream({903 start(c) {904 controller = c;905 },906 pull() {907 byobRequest = controller.byobRequest;908 viewInfos.push(extractViewInfo(controller.byobRequest.view));909 controller.enqueue(new Uint8Array(1));910 viewInfos.push(extractViewInfo(controller.byobRequest.view));911 ++pullCount;912 },913 type: 'bytes'914 });915 return Promise.resolve().then(() => {916 assert_equals(pullCount, 0, 'No pull() as no read(view) yet');917 const reader = stream.getReader({ mode: 'byob' });918 const promise = reader.read(new Uint16Array(1)).then(result => {919 assert_true(result.done, 'result.done');920 assert_equals(result.value, undefined, 'result.value');921 });922 assert_equals(pullCount, 1, '1 pull() should have been made in response to partial fill by enqueue()');923 assert_not_equals(byobRequest, null, 'byobRequest should not be null');924 assert_equals(viewInfos[0].byteLength, 2, 'byteLength before enqueue() should be 2');925 assert_equals(viewInfos[1].byteLength, 1, 'byteLength after enqueue() should be 1');926 reader.cancel();927 assert_equals(pullCount, 1, 'pull() should only be called once');928 return promise;929 });930}, 'ReadableStream with byte source: cancel() with partially filled pending pull() request');931promise_test(() => {932 let controller;933 let pullCalled = false;934 const stream = new ReadableStream({935 start(c) {936 const view = new Uint8Array(8);937 view[7] = 0x01;938 c.enqueue(view);939 controller = c;940 },941 pull() {942 pullCalled = true;943 },944 type: 'bytes'945 });946 const reader = stream.getReader({ mode: 'byob' });947 const buffer = new ArrayBuffer(16);948 return reader.read(new Uint8Array(buffer, 8, 8)).then(result => {949 assert_false(result.done);950 assert_false(pullCalled, 'pull() must not have been called');951 const view = result.value;952 assert_equals(view.constructor, Uint8Array);953 assert_equals(view.buffer.byteLength, 16);954 assert_equals(view.byteOffset, 8);955 assert_equals(view.byteLength, 8);956 assert_equals(view[7], 0x01);957 });958}, 'ReadableStream with byte source: enqueue(), getReader(), then read(view) where view.buffer is not fully ' +959 'covered by view');960promise_test(() => {961 let controller;962 let pullCalled = false;963 const stream = new ReadableStream({964 start(c) {965 let view;966 view = new Uint8Array(16);967 view[15] = 123;968 c.enqueue(view);969 view = new Uint8Array(8);970 view[7] = 111;971 c.enqueue(view);972 controller = c;973 },974 pull() {975 pullCalled = true;976 },977 type: 'bytes'978 });979 const reader = stream.getReader({ mode: 'byob' });980 return reader.read(new Uint8Array(24)).then(result => {981 assert_false(result.done, 'done');982 assert_false(pullCalled, 'pull() must not have been called');983 const view = result.value;984 assert_equals(view.byteOffset, 0, 'byteOffset');985 assert_equals(view.byteLength, 24, 'byteLength');986 assert_equals(view[15], 123, 'Contents are set from the first chunk');987 assert_equals(view[23], 111, 'Contents are set from the second chunk');988 });989}, 'ReadableStream with byte source: Multiple enqueue(), getReader(), then read(view)');990promise_test(() => {991 let pullCalled = false;992 const stream = new ReadableStream({993 start(c) {994 const view = new Uint8Array(16);995 view[15] = 0x01;996 c.enqueue(view);997 },998 pull() {999 pullCalled = true;1000 },1001 type: 'bytes'1002 });1003 const reader = stream.getReader({ mode: 'byob' });1004 return reader.read(new Uint8Array(24)).then(result => {1005 assert_false(result.done);1006 assert_false(pullCalled, 'pull() must not have been called');1007 const view = result.value;1008 assert_equals(view.byteOffset, 0);1009 assert_equals(view.byteLength, 16);1010 assert_equals(view[15], 0x01);1011 });1012}, 'ReadableStream with byte source: enqueue(), getReader(), then read(view) with a bigger view');1013promise_test(() => {1014 let pullCalled = false;1015 const stream = new ReadableStream({1016 start(c) {1017 const view = new Uint8Array(16);1018 view[7] = 0x01;1019 view[15] = 0x02;1020 c.enqueue(view);1021 },1022 pull() {1023 pullCalled = true;1024 },1025 type: 'bytes'1026 });1027 const reader = stream.getReader({ mode: 'byob' });1028 return reader.read(new Uint8Array(8)).then(result => {1029 assert_false(result.done, 'done');1030 const view = result.value;1031 assert_equals(view.byteOffset, 0);1032 assert_equals(view.byteLength, 8);1033 assert_equals(view[7], 0x01);1034 return reader.read(new Uint8Array(8));1035 }).then(result => {1036 assert_false(result.done, 'done');1037 assert_false(pullCalled, 'pull() must not have been called');1038 const view = result.value;1039 assert_equals(view.byteOffset, 0);1040 assert_equals(view.byteLength, 8);1041 assert_equals(view[7], 0x02);1042 });1043}, 'ReadableStream with byte source: enqueue(), getReader(), then read(view) with smaller views');1044promise_test(() => {1045 let controller;1046 let viewInfo;1047 const stream = new ReadableStream({1048 start(c) {1049 const view = new Uint8Array(1);1050 view[0] = 0xff;1051 c.enqueue(view);1052 controller = c;1053 },1054 pull() {1055 if (controller.byobRequest === null) {1056 return;1057 }1058 const view = controller.byobRequest.view;1059 viewInfo = extractViewInfo(view);1060 view[0] = 0xaa;1061 controller.byobRequest.respond(1);1062 },1063 type: 'bytes'1064 });1065 const reader = stream.getReader({ mode: 'byob' });1066 return reader.read(new Uint16Array(1)).then(result => {1067 assert_false(result.done);1068 const view = result.value;1069 assert_equals(view.byteOffset, 0);1070 assert_equals(view.byteLength, 2);1071 const dataView = new DataView(view.buffer, view.byteOffset, view.byteLength);1072 assert_equals(dataView.getUint16(0), 0xffaa);1073 assert_equals(viewInfo.constructor, Uint8Array, 'view.constructor should be Uint8Array');1074 assert_equals(viewInfo.bufferByteLength, 2, 'view.buffer.byteLength should be 2');1075 assert_equals(viewInfo.byteOffset, 1, 'view.byteOffset should be 1');1076 assert_equals(viewInfo.byteLength, 1, 'view.byteLength should be 1');1077 });1078}, 'ReadableStream with byte source: enqueue() 1 byte, getReader(), then read(view) with Uint16Array');1079promise_test(() => {1080 let pullCount = 0;1081 let controller;1082 let byobRequest;1083 let viewInfo;1084 let desiredSize;1085 const stream = new ReadableStream({1086 start(c) {1087 const view = new Uint8Array(3);1088 view[0] = 0x01;1089 view[2] = 0x02;1090 c.enqueue(view);1091 controller = c;1092 },1093 pull() {1094 byobRequest = controller.byobRequest;1095 const view = controller.byobRequest.view;1096 viewInfo = extractViewInfo(view);1097 view[0] = 0x03;1098 controller.byobRequest.respond(1);1099 desiredSize = controller.desiredSize;1100 ++pullCount;1101 },1102 type: 'bytes'1103 });1104 return Promise.resolve().then(() => {1105 const reader = stream.getReader({ mode: 'byob' });1106 const promise = reader.read(new Uint16Array(2)).then(result => {1107 assert_false(result.done, 'done');1108 const view = result.value;1109 assert_equals(view.constructor, Uint16Array, 'constructor');1110 assert_equals(view.buffer.byteLength, 4, 'buffer.byteLength');1111 assert_equals(view.byteOffset, 0, 'byteOffset');1112 assert_equals(view.byteLength, 2, 'byteLength');1113 const dataView = new DataView(view.buffer, view.byteOffset, view.byteLength);1114 assert_equals(dataView.getUint16(0), 0x0100, 'contents are set');1115 const p = reader.read(new Uint16Array(1));1116 assert_equals(pullCount, 1);1117 return p;1118 }).then(result => {1119 assert_false(result.done, 'done');1120 const view = result.value;1121 assert_equals(view.buffer.byteLength, 2, 'buffer.byteLength');1122 assert_equals(view.byteOffset, 0, 'byteOffset');1123 assert_equals(view.byteLength, 2, 'byteLength');1124 const dataView = new DataView(view.buffer, view.byteOffset, view.byteLength);1125 assert_equals(dataView.getUint16(0), 0x0203, 'contents are set');1126 assert_not_equals(byobRequest, null, 'byobRequest must not be null');1127 assert_equals(viewInfo.constructor, Uint8Array, 'view.constructor should be Uint8Array');1128 assert_equals(viewInfo.bufferByteLength, 2, 'view.buffer.byteLength should be 2');1129 assert_equals(viewInfo.byteOffset, 1, 'view.byteOffset should be 1');1130 assert_equals(viewInfo.byteLength, 1, 'view.byteLength should be 1');1131 assert_equals(desiredSize, 0, 'desiredSize should be zero');1132 });1133 assert_equals(pullCount, 0);1134 return promise;1135 });1136}, 'ReadableStream with byte source: enqueue() 3 byte, getReader(), then read(view) with 2-element Uint16Array');1137promise_test(t => {1138 const stream = new ReadableStream({1139 start(c) {1140 const view = new Uint8Array(1);1141 view[0] = 0xff;1142 c.enqueue(view);1143 c.close();1144 },1145 pull: t.unreached_func('pull() should not be called'),1146 type: 'bytes'1147 });1148 const reader = stream.getReader({ mode: 'byob' });1149 return promise_rejects_js(t, TypeError, reader.read(new Uint16Array(1)), 'read(view) must fail')1150 .then(() => promise_rejects_js(t, TypeError, reader.closed, 'reader.closed should reject'));1151}, 'ReadableStream with byte source: read(view) with Uint16Array on close()-d stream with 1 byte enqueue()-d must ' +1152 'fail');1153promise_test(t => {1154 let controller;1155 const stream = new ReadableStream({1156 start(c) {1157 const view = new Uint8Array(1);1158 view[0] = 0xff;1159 c.enqueue(view);1160 controller = c;1161 },1162 pull: t.unreached_func('pull() should not be called'),1163 type: 'bytes'1164 });1165 const reader = stream.getReader({ mode: 'byob' });1166 const readPromise = reader.read(new Uint16Array(1));1167 assert_throws_js(TypeError, () => controller.close(), 'controller.close() must throw');1168 return promise_rejects_js(t, TypeError, readPromise, 'read(view) must fail')1169 .then(() => promise_rejects_js(t, TypeError, reader.closed, 'reader.closed must reject'));1170}, 'ReadableStream with byte source: A stream must be errored if close()-d before fulfilling read(view) with ' +1171 'Uint16Array');1172test(() => {1173 let controller;1174 new ReadableStream({1175 start(c) {1176 controller = c;1177 },1178 type: 'bytes'1179 });1180 const view = new Uint8Array(1);1181 controller.enqueue(view);1182 controller.close();1183 assert_throws_js(TypeError, () => controller.close(), 'controller.close() must throw');1184}, 'ReadableStream with byte source: Throw if close()-ed more than once');1185test(() => {1186 let controller;1187 new ReadableStream({1188 start(c) {1189 controller = c;1190 },1191 type: 'bytes'1192 });1193 const view = new Uint8Array(1);1194 controller.enqueue(view);1195 controller.close();1196 assert_throws_js(TypeError, () => controller.enqueue(view), 'controller.close() must throw');1197}, 'ReadableStream with byte source: Throw on enqueue() after close()');1198promise_test(() => {1199 let controller;1200 let byobRequest;1201 let viewInfo;1202 const stream = new ReadableStream({1203 start(c) {1204 controller = c;1205 },1206 pull() {1207 byobRequest = controller.byobRequest;1208 const view = controller.byobRequest.view;1209 viewInfo = extractViewInfo(view);1210 view[15] = 0x01;1211 controller.byobRequest.respond(16);1212 controller.close();1213 },1214 type: 'bytes'1215 });1216 const reader = stream.getReader({ mode: 'byob' });1217 return reader.read(new Uint8Array(16)).then(result => {1218 assert_false(result.done);1219 const view = result.value;1220 assert_equals(view.byteOffset, 0);1221 assert_equals(view.byteLength, 16);1222 assert_equals(view[15], 0x01);1223 return reader.read(new Uint8Array(16));1224 }).then(result => {1225 assert_true(result.done);1226 const view = result.value;1227 assert_equals(view.byteOffset, 0);1228 assert_equals(view.byteLength, 0);1229 assert_not_equals(byobRequest, null, 'byobRequest must not be null');1230 assert_equals(viewInfo.constructor, Uint8Array, 'view.constructor should be Uint8Array');1231 assert_equals(viewInfo.bufferByteLength, 16, 'view.buffer.byteLength should be 16');1232 assert_equals(viewInfo.byteOffset, 0, 'view.byteOffset should be 0');1233 assert_equals(viewInfo.byteLength, 16, 'view.byteLength should be 16');1234 });1235}, 'ReadableStream with byte source: read(view), then respond() and close() in pull()');1236promise_test(() => {1237 let pullCount = 0;1238 let controller;1239 const viewInfos = [];1240 const viewInfosAfterRespond = [];1241 const stream = new ReadableStream({1242 start(c) {1243 controller = c;1244 },1245 pull() {1246 if (controller.byobRequest === null) {1247 return;1248 }1249 for (let i = 0; i < 4; ++i) {1250 const view = controller.byobRequest.view;1251 viewInfos.push(extractViewInfo(view));1252 view[0] = 0x01;1253 controller.byobRequest.respond(1);1254 viewInfosAfterRespond.push(extractViewInfo(view));1255 }1256 ++pullCount;1257 },1258 type: 'bytes'1259 });1260 const reader = stream.getReader({ mode: 'byob' });1261 return reader.read(new Uint32Array(1)).then(result => {1262 assert_false(result.done, 'result.done');1263 const view = result.value;1264 assert_equals(view.byteOffset, 0, 'result.value.byteOffset');1265 assert_equals(view.byteLength, 4, 'result.value.byteLength');1266 assert_equals(view[0], 0x01010101, 'result.value[0]');1267 assert_equals(pullCount, 1, 'pull() should only be called once');1268 for (let i = 0; i < 4; ++i) {1269 assert_equals(viewInfos[i].constructor, Uint8Array, 'view.constructor should be Uint8Array');1270 assert_equals(viewInfos[i].bufferByteLength, 4, 'view.buffer.byteLength should be 4');1271 assert_equals(viewInfos[i].byteOffset, i, 'view.byteOffset should be i');1272 assert_equals(viewInfos[i].byteLength, 4 - i, 'view.byteLength should be 4 - i');1273 assert_equals(viewInfosAfterRespond[i].bufferByteLength, 0, 'view.buffer should be transferred after respond()');1274 }1275 });1276}, 'ReadableStream with byte source: read(view) with Uint32Array, then fill it by multiple respond() calls');1277promise_test(() => {1278 let pullCount = 0;1279 let controller;1280 const viewInfos = [];1281 const viewInfosAfterEnqueue = [];1282 const stream = new ReadableStream({1283 start(c) {1284 controller = c;1285 },1286 pull() {1287 if (controller.byobRequest === null) {1288 return;1289 }1290 for (let i = 0; i < 4; ++i) {1291 const view = controller.byobRequest.view;1292 viewInfos.push(extractViewInfo(view));1293 controller.enqueue(new Uint8Array([0x01]));1294 viewInfosAfterEnqueue.push(extractViewInfo(view));1295 }1296 ++pullCount;1297 },1298 type: 'bytes'1299 });1300 const reader = stream.getReader({ mode: 'byob' });1301 return reader.read(new Uint32Array(1)).then(result => {1302 assert_false(result.done, 'result.done');1303 const view = result.value;1304 assert_equals(view.byteOffset, 0, 'result.value.byteOffset');1305 assert_equals(view.byteLength, 4, 'result.value.byteLength');1306 assert_equals(view[0], 0x01010101, 'result.value[0]');1307 assert_equals(pullCount, 1, 'pull() should only be called once');1308 for (let i = 0; i < 4; ++i) {...
general.js
Source:general.js
...230 assert_equals(pullCount, 1, 'pull must be invoked');231 });232}, 'ReadableStream with byte source: Automatic pull() after start() and read()');233// View buffers are detached after pull() returns, so record the information at the time that pull() was called.234function extractViewInfo(view) {235 return {236 constructor: view.constructor,237 bufferByteLength: view.buffer.byteLength,238 byteOffset: view.byteOffset,239 byteLength: view.byteLength240 };241}242promise_test(() => {243 let pullCount = 0;244 let controller;245 let byobRequest;246 let viewDefined = false;247 let viewInfo;248 const stream = new ReadableStream({249 start(c) {250 controller = c;251 },252 pull() {253 byobRequest = controller.byobRequest;254 const view = byobRequest.view;255 viewDefined = view !== undefined;256 viewInfo = extractViewInfo(view);257 view[0] = 0x01;258 byobRequest.respond(1);259 ++pullCount;260 },261 type: 'bytes',262 autoAllocateChunkSize: 16263 }, {264 highWaterMark: 0265 });266 const reader = stream.getReader();267 const readPromise = reader.read();268 const ignoredReadPromise = reader.read();269 assert_equals(pullCount, 0, 'No pull() as start() just finished and is not yet reflected to the state of the stream');270 return Promise.resolve().then(() => {271 assert_equals(pullCount, 1, 'pull() must have been invoked once');272 assert_not_equals(byobRequest, undefined, 'byobRequest must not be undefined');273 assert_true(viewDefined, 'byobRequest.view must not be undefined');274 assert_equals(viewInfo.constructor, Uint8Array, 'view.constructor should be Uint8Array');275 assert_equals(viewInfo.bufferByteLength, 16, 'view.buffer.byteLength should be 16');276 assert_equals(viewInfo.byteOffset, 0, 'view.byteOffset should be 0');277 assert_equals(viewInfo.byteLength, 16, 'view.byteLength should be 16');278 return readPromise;279 }).then(result => {280 assert_not_equals(result.value, undefined);281 assert_equals(result.value.constructor, Uint8Array);282 assert_equals(result.value.buffer.byteLength, 16);283 assert_equals(result.value.byteOffset, 0);284 assert_equals(result.value.byteLength, 1);285 assert_equals(result.value[0], 0x01);286 assert_equals(pullCount, 1, 'pull() should only be invoked once');287 });288}, 'ReadableStream with byte source: autoAllocateChunkSize');289promise_test(() => {290 let pullCount = 0;291 let controller;292 const byobRequests = [];293 const stream = new ReadableStream({294 start(c) {295 controller = c;296 },297 pull() {298 const byobRequest = controller.byobRequest;299 const view = byobRequest.view;300 byobRequests[pullCount] = {301 defined: byobRequest !== undefined,302 viewDefined: view !== undefined,303 viewInfo: extractViewInfo(view)304 };305 if (pullCount === 0) {306 view[0] = 0x01;307 byobRequest.respond(1);308 } else if (pullCount === 1) {309 view[0] = 0x02;310 view[1] = 0x03;311 byobRequest.respond(2);312 }313 ++pullCount;314 },315 type: 'bytes',316 autoAllocateChunkSize: 16317 }, {318 highWaterMark: 0319 });320 const reader = stream.getReader();321 return reader.read().then(result => {322 assert_not_equals(result.value, undefined);323 assert_equals(result.value.constructor, Uint8Array);324 assert_equals(result.value.buffer.byteLength, 16);325 assert_equals(result.value.byteOffset, 0);326 assert_equals(result.value.byteLength, 1);327 assert_equals(result.value[0], 0x01);328 const byobRequest = byobRequests[0];329 assert_true(byobRequest.defined, 'first byobRequest must not be undefined');330 assert_true(byobRequest.viewDefined, 'first byobRequest.view must not be undefined');331 const viewInfo = byobRequest.viewInfo;332 assert_equals(viewInfo.constructor, Uint8Array, 'first view.constructor should be Uint8Array');333 assert_equals(viewInfo.bufferByteLength, 16, 'first view.buffer.byteLength should be 16');334 assert_equals(viewInfo.byteOffset, 0, 'first view.byteOffset should be 0');335 assert_equals(viewInfo.byteLength, 16, 'first view.byteLength should be 16');336 reader.releaseLock();337 const byobReader = stream.getReader({ mode: 'byob' });338 return byobReader.read(new Uint8Array(32));339 }).then(result => {340 assert_not_equals(result.value, undefined);341 assert_equals(result.value.constructor, Uint8Array);342 assert_equals(result.value.buffer.byteLength, 32);343 assert_equals(result.value.byteOffset, 0);344 assert_equals(result.value.byteLength, 2);345 assert_equals(result.value[0], 0x02);346 assert_equals(result.value[1], 0x03);347 const byobRequest = byobRequests[1];348 assert_true(byobRequest.defined, 'second byobRequest must not be undefined');349 assert_true(byobRequest.viewDefined, 'second byobRequest.view must not be undefined');350 const viewInfo = byobRequest.viewInfo;351 assert_equals(viewInfo.constructor, Uint8Array, 'second view.constructor should be Uint8Array');352 assert_equals(viewInfo.bufferByteLength, 32, 'second view.buffer.byteLength should be 32');353 assert_equals(viewInfo.byteOffset, 0, 'second view.byteOffset should be 0');354 assert_equals(viewInfo.byteLength, 32, 'second view.byteLength should be 32');355 assert_equals(pullCount, 2, 'pullCount should be 2');356 });357}, 'ReadableStream with byte source: Mix of auto allocate and BYOB');358promise_test(() => {359 let pullCount = 0;360 const stream = new ReadableStream({361 pull() {362 ++pullCount;363 },364 type: 'bytes'365 }, {366 highWaterMark: 0367 });368 const reader = stream.getReader();369 reader.read(new Uint8Array(8));370 assert_equals(pullCount, 0, 'No pull as start() just finished and is not yet reflected to the state of the stream');371 return Promise.resolve().then(() => {372 assert_equals(pullCount, 1, 'pull must be invoked');373 });374}, 'ReadableStream with byte source: Automatic pull() after start() and read(view)');375promise_test(() => {376 let pullCount = 0;377 let controller;378 let desiredSizeInStart;379 let desiredSizeInPull;380 const stream = new ReadableStream({381 start(c) {382 c.enqueue(new Uint8Array(16));383 desiredSizeInStart = c.desiredSize;384 controller = c;385 },386 pull() {387 ++pullCount;388 if (pullCount === 1) {389 desiredSizeInPull = controller.desiredSize;390 }391 },392 type: 'bytes'393 }, {394 highWaterMark: 8395 });396 return Promise.resolve().then(() => {397 assert_equals(pullCount, 0, 'No pull as the queue was filled by start()');398 assert_equals(desiredSizeInStart, -8, 'desiredSize after enqueue() in start()');399 const reader = stream.getReader();400 const promise = reader.read();401 assert_equals(pullCount, 1, 'The first pull() should be made on read()');402 assert_equals(desiredSizeInPull, 8, 'desiredSize in pull()');403 return promise.then(result => {404 assert_equals(result.done, false, 'result.done');405 const view = result.value;406 assert_equals(view.constructor, Uint8Array, 'view.constructor');407 assert_equals(view.buffer.byteLength, 16, 'view.buffer');408 assert_equals(view.byteOffset, 0, 'view.byteOffset');409 assert_equals(view.byteLength, 16, 'view.byteLength');410 });411 });412}, 'ReadableStream with byte source: enqueue(), getReader(), then read()');413promise_test(() => {414 let controller;415 const stream = new ReadableStream({416 start(c) {417 controller = c;418 },419 type: 'bytes'420 });421 const reader = stream.getReader();422 const promise = reader.read().then(result => {423 assert_equals(result.done, false);424 const view = result.value;425 assert_equals(view.constructor, Uint8Array);426 assert_equals(view.buffer.byteLength, 1);427 assert_equals(view.byteOffset, 0);428 assert_equals(view.byteLength, 1);429 });430 controller.enqueue(new Uint8Array(1));431 return promise;432}, 'ReadableStream with byte source: Push source that doesn\'t understand pull signal');433promise_test(t => {434 const stream = new ReadableStream({435 pull: 'foo',436 type: 'bytes'437 });438 const reader = stream.getReader();439 return promise_rejects(t, new TypeError(), reader.read(), 'read() must fail');440}, 'ReadableStream with byte source: read(), but pull() function is not callable');441promise_test(t => {442 const stream = new ReadableStream({443 pull: 'foo',444 type: 'bytes'445 });446 const reader = stream.getReader({ mode: 'byob' });447 return promise_rejects(t, new TypeError(), reader.read(new Uint8Array(1)), 'read() must fail');448}, 'ReadableStream with byte source: read(view), but pull() function is not callable');449promise_test(() => {450 const stream = new ReadableStream({451 start(c) {452 c.enqueue(new Uint16Array(16));453 },454 type: 'bytes'455 });456 const reader = stream.getReader();457 return reader.read().then(result => {458 assert_equals(result.done, false);459 const view = result.value;460 assert_equals(view.constructor, Uint8Array);461 assert_equals(view.buffer.byteLength, 32);462 assert_equals(view.byteOffset, 0);463 assert_equals(view.byteLength, 32);464 });465}, 'ReadableStream with byte source: enqueue() with Uint16Array, getReader(), then read()');466promise_test(t => {467 const stream = new ReadableStream({468 start(c) {469 const view = new Uint8Array(16);470 view[0] = 0x01;471 view[8] = 0x02;472 c.enqueue(view);473 },474 pull: t.unreached_func('pull() should not be called'),475 type: 'bytes'476 });477 const byobReader = stream.getReader({ mode: 'byob' });478 return byobReader.read(new Uint8Array(8)).then(result => {479 assert_equals(result.done, false, 'done');480 const view = result.value;481 assert_equals(view.constructor, Uint8Array, 'value.constructor');482 assert_equals(view.buffer.byteLength, 8, 'value.buffer.byteLength');483 assert_equals(view.byteOffset, 0, 'value.byteOffset');484 assert_equals(view.byteLength, 8, 'value.byteLength');485 assert_equals(view[0], 0x01);486 byobReader.releaseLock();487 const reader = stream.getReader();488 return reader.read();489 }).then(result => {490 assert_equals(result.done, false, 'done');491 const view = result.value;492 assert_equals(view.constructor, Uint8Array, 'value.constructor');493 assert_equals(view.buffer.byteLength, 16, 'value.buffer.byteLength');494 assert_equals(view.byteOffset, 8, 'value.byteOffset');495 assert_equals(view.byteLength, 8, 'value.byteLength');496 assert_equals(view[0], 0x02);497 });498}, 'ReadableStream with byte source: enqueue(), read(view) partially, then read()');499promise_test(t => {500 let controller;501 const stream = new ReadableStream({502 start(c) {503 controller = c;504 },505 pull: t.unreached_func('pull() should not be called'),506 type: 'bytes'507 });508 const reader = stream.getReader();509 controller.enqueue(new Uint8Array(16));510 controller.close();511 return reader.read().then(result => {512 assert_equals(result.done, false, 'done');513 const view = result.value;514 assert_equals(view.byteOffset, 0, 'byteOffset');515 assert_equals(view.byteLength, 16, 'byteLength');516 return reader.read();517 }).then(result => {518 assert_equals(result.done, true, 'done');519 assert_equals(result.value, undefined, 'value');520 });521}, 'ReadableStream with byte source: getReader(), enqueue(), close(), then read()');522promise_test(t => {523 const stream = new ReadableStream({524 start(c) {525 c.enqueue(new Uint8Array(16));526 c.close();527 },528 pull: t.unreached_func('pull() should not be called'),529 type: 'bytes'530 });531 const reader = stream.getReader();532 return reader.read().then(result => {533 assert_equals(result.done, false, 'done');534 const view = result.value;535 assert_equals(view.byteOffset, 0, 'byteOffset');536 assert_equals(view.byteLength, 16, 'byteLength');537 return reader.read();538 }).then(result => {539 assert_equals(result.done, true, 'done');540 assert_equals(result.value, undefined, 'value');541 });542}, 'ReadableStream with byte source: enqueue(), close(), getReader(), then read()');543promise_test(() => {544 let controller;545 let byobRequest;546 const stream = new ReadableStream({547 start(c) {548 controller = c;549 },550 pull() {551 controller.enqueue(new Uint8Array(16));552 byobRequest = controller.byobRequest;553 },554 type: 'bytes'555 });556 const reader = stream.getReader();557 return reader.read().then(result => {558 assert_equals(result.done, false, 'done');559 assert_equals(result.value.byteLength, 16, 'byteLength');560 assert_equals(byobRequest, undefined, 'byobRequest must be undefined');561 });562}, 'ReadableStream with byte source: Respond to pull() by enqueue()');563promise_test(() => {564 let pullCount = 0;565 let controller;566 let byobRequest;567 const desiredSizes = [];568 const stream = new ReadableStream({569 start(c) {570 controller = c;571 },572 pull() {573 byobRequest = controller.byobRequest;574 desiredSizes.push(controller.desiredSize);575 controller.enqueue(new Uint8Array(1));576 desiredSizes.push(controller.desiredSize);577 controller.enqueue(new Uint8Array(1));578 desiredSizes.push(controller.desiredSize);579 ++pullCount;580 },581 type: 'bytes'582 }, {583 highWaterMark: 256584 });585 const reader = stream.getReader();586 const p0 = reader.read();587 const p1 = reader.read();588 const p2 = reader.read();589 // Respond to the first pull call.590 controller.enqueue(new Uint8Array(1));591 assert_equals(pullCount, 0, 'pullCount after the enqueue() outside pull');592 return Promise.all([p0, p1, p2]).then(result => {593 assert_equals(pullCount, 1, 'pullCount after completion of all read()s');594 assert_equals(result[0].done, false, 'result[0].done');595 assert_equals(result[0].value.byteLength, 1, 'result[0].value.byteLength');596 assert_equals(result[1].done, false, 'result[1].done');597 assert_equals(result[1].value.byteLength, 1, 'result[1].value.byteLength');598 assert_equals(result[2].done, false, 'result[2].done');599 assert_equals(result[2].value.byteLength, 1, 'result[2].value.byteLength');600 assert_equals(byobRequest, undefined, 'byobRequest should be undefined');601 assert_equals(desiredSizes[0], 256, 'desiredSize on pull should be 256');602 assert_equals(desiredSizes[1], 256, 'desiredSize after 1st enqueue() should be 256');603 assert_equals(desiredSizes[2], 256, 'desiredSize after 2nd enqueue() should be 256');604 assert_equals(pullCount, 1, 'pull() should only be called once');605 });606}, 'ReadableStream with byte source: Respond to pull() by enqueue() asynchronously');607promise_test(() => {608 let controller;609 let pullCount = 0;610 const byobRequestDefined = [];611 const stream = new ReadableStream({612 start(c) {613 controller = c;614 },615 pull() {616 byobRequestDefined.push(controller.byobRequest !== undefined);617 const view = controller.byobRequest.view;618 view[0] = 0x01;619 controller.byobRequest.respond(1);620 byobRequestDefined.push(controller.byobRequest !== undefined);621 ++pullCount;622 },623 type: 'bytes'624 });625 const reader = stream.getReader({ mode: 'byob' });626 return reader.read(new Uint8Array(1)).then(result => {627 assert_equals(result.done, false, 'result.done');628 assert_equals(result.value.byteLength, 1, 'result.value.byteLength');629 assert_equals(result.value[0], 0x01, 'result.value[0]');630 assert_equals(pullCount, 1, 'pull() should be called only once');631 assert_true(byobRequestDefined[0], 'byobRequest must not be undefined before respond()');632 assert_false(byobRequestDefined[1], 'byobRequest must be undefined after respond()');633 });634}, 'ReadableStream with byte source: read(view), then respond()');635promise_test(() => {636 let controller;637 let pullCount = 0;638 const byobRequestDefined = [];639 const stream = new ReadableStream({640 start(c) {641 controller = c;642 },643 pull() {644 byobRequestDefined.push(controller.byobRequest !== undefined);645 // Emulate ArrayBuffer transfer by just creating a new ArrayBuffer and pass it. By checking the result of646 // read(view), we test that the respond()'s buffer argument is working correctly.647 //648 // A real implementation of the underlying byte source would transfer controller.byobRequest.view.buffer into649 // a new ArrayBuffer, then construct a view around it and write to it.650 const transferredView = new Uint8Array(1);651 transferredView[0] = 0x01;652 controller.byobRequest.respondWithNewView(transferredView);653 byobRequestDefined.push(controller.byobRequest !== undefined);654 ++pullCount;655 },656 type: 'bytes'657 });658 const reader = stream.getReader({ mode: 'byob' });659 return reader.read(new Uint8Array(1)).then(result => {660 assert_equals(result.done, false, 'result.done');661 assert_equals(result.value.byteLength, 1, 'result.value.byteLength');662 assert_equals(result.value[0], 0x01, 'result.value[0]');663 assert_equals(pullCount, 1, 'pull() should be called only once');664 assert_true(byobRequestDefined[0], 'byobRequest must not be undefined before respond()');665 assert_false(byobRequestDefined[1], 'byobRequest must be undefined after respond()');666 });667}, 'ReadableStream with byte source: read(view), then respond() with a transferred ArrayBuffer');668promise_test(() => {669 let controller;670 let byobRequestWasDefined;671 let incorrectRespondException;672 const stream = new ReadableStream({673 start(c) {674 controller = c;675 },676 pull() {677 byobRequestWasDefined = controller.byobRequest !== undefined;678 try {679 controller.byobRequest.respond(2);680 } catch (e) {681 incorrectRespondException = e;682 }683 controller.byobRequest.respond(1);684 },685 type: 'bytes'686 });687 const reader = stream.getReader({ mode: 'byob' });688 return reader.read(new Uint8Array(1)).then(() => {689 assert_true(byobRequestWasDefined, 'byobRequest should be defined');690 assert_not_equals(incorrectRespondException, undefined, 'respond() must throw');691 assert_equals(incorrectRespondException.name, 'RangeError', 'respond() must throw a RangeError');692 });693}, 'ReadableStream with byte source: read(view), then respond() with too big value');694promise_test(() => {695 let pullCount = 0;696 let controller;697 let byobRequest;698 let viewInfo;699 const stream = new ReadableStream({700 start(c) {701 controller = c;702 },703 pull() {704 ++pullCount;705 byobRequest = controller.byobRequest;706 const view = byobRequest.view;707 viewInfo = extractViewInfo(view);708 view[0] = 0x01;709 view[1] = 0x02;710 view[2] = 0x03;711 controller.byobRequest.respond(3);712 },713 type: 'bytes'714 });715 const reader = stream.getReader({ mode: 'byob' });716 return reader.read(new Uint16Array(2)).then(result => {717 assert_equals(pullCount, 1);718 assert_equals(result.done, false, 'done');719 const view = result.value;720 assert_equals(view.byteOffset, 0, 'byteOffset');721 assert_equals(view.byteLength, 2, 'byteLength');722 assert_equals(view[0], 0x0201);723 return reader.read(new Uint8Array(1));724 }).then(result => {725 assert_equals(pullCount, 1);726 assert_not_equals(byobRequest, undefined, 'byobRequest must not be undefined');727 assert_equals(viewInfo.constructor, Uint8Array, 'view.constructor should be Uint8Array');728 assert_equals(viewInfo.bufferByteLength, 4, 'view.buffer.byteLength should be 4');729 assert_equals(viewInfo.byteOffset, 0, 'view.byteOffset should be 0');730 assert_equals(viewInfo.byteLength, 4, 'view.byteLength should be 4');731 assert_equals(result.done, false, 'done');732 const view = result.value;733 assert_equals(view.byteOffset, 0, 'byteOffset');734 assert_equals(view.byteLength, 1, 'byteLength');735 assert_equals(view[0], 0x03);736 });737}, 'ReadableStream with byte source: respond(3) to read(view) with 2 element Uint16Array enqueues the 1 byte ' +738 'remainder');739promise_test(t => {740 const stream = new ReadableStream({741 start(controller) {742 const view = new Uint8Array(16);743 view[15] = 0x01;744 controller.enqueue(view);745 },746 pull: t.unreached_func('pull() should not be called'),747 type: 'bytes'748 });749 const reader = stream.getReader({ mode: 'byob' });750 return reader.read(new Uint8Array(16)).then(result => {751 assert_equals(result.done, false);752 const view = result.value;753 assert_equals(view.byteOffset, 0);754 assert_equals(view.byteLength, 16);755 assert_equals(view[15], 0x01);756 });757}, 'ReadableStream with byte source: enqueue(), getReader(), then read(view)');758promise_test(t => {759 let cancelCount = 0;760 let reason;761 const passedReason = new TypeError('foo');762 const stream = new ReadableStream({763 start(c) {764 c.enqueue(new Uint8Array(16));765 },766 pull: t.unreached_func('pull() should not be called'),767 cancel(r) {768 if (cancelCount === 0) {769 reason = r;770 }771 ++cancelCount;772 },773 type: 'bytes'774 });775 const reader = stream.getReader();776 return reader.cancel(passedReason).then(result => {777 assert_equals(result, undefined);778 assert_equals(cancelCount, 1);779 assert_equals(reason, passedReason, 'reason should equal the passed reason');780 });781}, 'ReadableStream with byte source: enqueue(), getReader(), then cancel() (mode = not BYOB)');782promise_test(t => {783 let cancelCount = 0;784 let reason;785 const passedReason = new TypeError('foo');786 const stream = new ReadableStream({787 start(c) {788 c.enqueue(new Uint8Array(16));789 },790 pull: t.unreached_func('pull() should not be called'),791 cancel(r) {792 if (cancelCount === 0) {793 reason = r;794 }795 ++cancelCount;796 },797 type: 'bytes'798 });799 const reader = stream.getReader({ mode: 'byob' });800 return reader.cancel(passedReason).then(result => {801 assert_equals(result, undefined);802 assert_equals(cancelCount, 1);803 assert_equals(reason, passedReason, 'reason should equal the passed reason');804 });805}, 'ReadableStream with byte source: enqueue(), getReader(), then cancel() (mode = BYOB)');806promise_test(t => {807 let cancelCount = 0;808 let reason;809 const passedReason = new TypeError('foo');810 let controller;811 const stream = new ReadableStream({812 start(c) {813 controller = c;814 },815 pull: t.unreached_func('pull() should not be called'),816 cancel(r) {817 if (cancelCount === 0) {818 reason = r;819 controller.byobRequest.respond(0);820 }821 ++cancelCount;822 return 'bar';823 },824 type: 'bytes'825 });826 const reader = stream.getReader({ mode: 'byob' });827 const readPromise = reader.read(new Uint8Array(1)).then(result => {828 assert_equals(result.done, true);829 });830 const cancelPromise = reader.cancel(passedReason).then(result => {831 assert_equals(result, undefined);832 assert_equals(cancelCount, 1);833 assert_equals(reason, passedReason, 'reason should equal the passed reason');834 });835 return Promise.all([readPromise, cancelPromise]);836}, 'ReadableStream with byte source: getReader(), read(view), then cancel()');837promise_test(() => {838 let pullCount = 0;839 let controller;840 let byobRequest;841 const viewInfos = [];842 const stream = new ReadableStream({843 start(c) {844 controller = c;845 },846 pull() {847 byobRequest = controller.byobRequest;848 viewInfos.push(extractViewInfo(controller.byobRequest.view));849 controller.enqueue(new Uint8Array(1));850 viewInfos.push(extractViewInfo(controller.byobRequest.view));851 ++pullCount;852 },853 type: 'bytes'854 });855 return Promise.resolve().then(() => {856 assert_equals(pullCount, 0, 'No pull() as no read(view) yet');857 const reader = stream.getReader({ mode: 'byob' });858 const promise = reader.read(new Uint16Array(1)).then(result => {859 assert_equals(result.done, true, 'result.done');860 assert_equals(result.value.constructor, Uint16Array, 'result.value');861 });862 assert_equals(pullCount, 1, '1 pull() should have been made in response to partial fill by enqueue()');863 assert_not_equals(byobRequest, undefined, 'byobRequest should not be undefined');864 assert_equals(viewInfos[0].byteLength, 2, 'byteLength before enqueue() shouild be 2');865 assert_equals(viewInfos[1].byteLength, 1, 'byteLength after enqueue() should be 1');866 reader.cancel();867 // Tell that the buffer given via pull() is returned.868 controller.byobRequest.respond(0);869 assert_equals(pullCount, 1, 'pull() should only be called once');870 return promise;871 });872}, 'ReadableStream with byte source: cancel() with partially filled pending pull() request');873promise_test(() => {874 let controller;875 let byobRequest;876 const stream = new ReadableStream({877 start(c) {878 const view = new Uint8Array(8);879 view[7] = 0x01;880 c.enqueue(view);881 controller = c;882 },883 pull() {884 byobRequest = controller.byobRequest;885 },886 type: 'bytes'887 });888 const reader = stream.getReader({ mode: 'byob' });889 const buffer = new ArrayBuffer(16);890 return reader.read(new Uint8Array(buffer, 8, 8)).then(result => {891 assert_equals(result.done, false);892 assert_equals(byobRequest, undefined, 'byobRequest must be undefined');893 const view = result.value;894 assert_equals(view.constructor, Uint8Array);895 assert_equals(view.buffer.byteLength, 16);896 assert_equals(view.byteOffset, 8);897 assert_equals(view.byteLength, 8);898 assert_equals(view[7], 0x01);899 });900}, 'ReadableStream with byte source: enqueue(), getReader(), then read(view) where view.buffer is not fully ' +901 'covered by view');902promise_test(() => {903 let controller;904 let byobRequest;905 const stream = new ReadableStream({906 start(c) {907 let view;908 view = new Uint8Array(16);909 view[15] = 123;910 c.enqueue(view);911 view = new Uint8Array(8);912 view[7] = 111;913 c.enqueue(view);914 controller = c;915 },916 pull() {917 byobRequest = controller.byobRequest;918 },919 type: 'bytes'920 });921 const reader = stream.getReader({ mode: 'byob' });922 return reader.read(new Uint8Array(24)).then(result => {923 assert_equals(result.done, false, 'done');924 assert_equals(byobRequest, undefined, 'byobRequest must be undefined');925 const view = result.value;926 assert_equals(view.byteOffset, 0, 'byteOffset');927 assert_equals(view.byteLength, 24, 'byteLength');928 assert_equals(view[15], 123, 'Contents are set from the first chunk');929 assert_equals(view[23], 111, 'Contents are set from the second chunk');930 });931}, 'ReadableStream with byte source: Multiple enqueue(), getReader(), then read(view)');932promise_test(() => {933 let byobRequest;934 const stream = new ReadableStream({935 start(c) {936 const view = new Uint8Array(16);937 view[15] = 0x01;938 c.enqueue(view);939 },940 pull(controller) {941 byobRequest = controller.byobRequest;942 },943 type: 'bytes'944 });945 const reader = stream.getReader({ mode: 'byob' });946 return reader.read(new Uint8Array(24)).then(result => {947 assert_equals(result.done, false);948 assert_equals(byobRequest, undefined, 'byobRequest must be undefined');949 const view = result.value;950 assert_equals(view.byteOffset, 0);951 assert_equals(view.byteLength, 16);952 assert_equals(view[15], 0x01);953 });954}, 'ReadableStream with byte source: enqueue(), getReader(), then read(view) with a bigger view');955promise_test(() => {956 let byobRequest;957 const stream = new ReadableStream({958 start(c) {959 const view = new Uint8Array(16);960 view[7] = 0x01;961 view[15] = 0x02;962 c.enqueue(view);963 },964 pull(controller) {965 byobRequest = controller.byobRequest;966 },967 type: 'bytes'968 });969 const reader = stream.getReader({ mode: 'byob' });970 return reader.read(new Uint8Array(8)).then(result => {971 assert_equals(result.done, false, 'done');972 const view = result.value;973 assert_equals(view.byteOffset, 0);974 assert_equals(view.byteLength, 8);975 assert_equals(view[7], 0x01);976 return reader.read(new Uint8Array(8));977 }).then(result => {978 assert_equals(result.done, false, 'done');979 assert_equals(byobRequest, undefined, 'byobRequest must be undefined');980 const view = result.value;981 assert_equals(view.byteOffset, 0);982 assert_equals(view.byteLength, 8);983 assert_equals(view[7], 0x02);984 });985}, 'ReadableStream with byte source: enqueue(), getReader(), then read(view) with a smaller views');986promise_test(() => {987 let controller;988 let viewInfo;989 const stream = new ReadableStream({990 start(c) {991 const view = new Uint8Array(1);992 view[0] = 0xff;993 c.enqueue(view);994 controller = c;995 },996 pull() {997 if (controller.byobRequest === undefined) {998 return;999 }1000 const view = controller.byobRequest.view;1001 viewInfo = extractViewInfo(view);1002 view[0] = 0xaa;1003 controller.byobRequest.respond(1);1004 },1005 type: 'bytes'1006 });1007 const reader = stream.getReader({ mode: 'byob' });1008 return reader.read(new Uint16Array(1)).then(result => {1009 assert_equals(result.done, false);1010 const view = result.value;1011 assert_equals(view.byteOffset, 0);1012 assert_equals(view.byteLength, 2);1013 assert_equals(view[0], 0xaaff);1014 assert_equals(viewInfo.constructor, Uint8Array, 'view.constructor should be Uint8Array');1015 assert_equals(viewInfo.bufferByteLength, 2, 'view.buffer.byteLength should be 2');1016 assert_equals(viewInfo.byteOffset, 1, 'view.byteOffset should be 1');1017 assert_equals(viewInfo.byteLength, 1, 'view.byteLength should be 1');1018 });1019}, 'ReadableStream with byte source: enqueue() 1 byte, getReader(), then read(view) with Uint16Array');1020promise_test(() => {1021 let pullCount = 0;1022 let controller;1023 let byobRequest;1024 let viewInfo;1025 let desiredSize;1026 const stream = new ReadableStream({1027 start(c) {1028 const view = new Uint8Array(3);1029 view[0] = 0x01;1030 view[2] = 0x02;1031 c.enqueue(view);1032 controller = c;1033 },1034 pull() {1035 byobRequest = controller.byobRequest;1036 const view = controller.byobRequest.view;1037 viewInfo = extractViewInfo(view);1038 view[0] = 0x03;1039 controller.byobRequest.respond(1);1040 desiredSize = controller.desiredSize;1041 ++pullCount;1042 },1043 type: 'bytes'1044 });1045 // Wait for completion of the start method to be reflected.1046 return Promise.resolve().then(() => {1047 const reader = stream.getReader({ mode: 'byob' });1048 const promise = reader.read(new Uint16Array(2)).then(result => {1049 assert_equals(result.done, false, 'done');1050 const view = result.value;1051 assert_equals(view.constructor, Uint16Array, 'constructor');1052 assert_equals(view.buffer.byteLength, 4, 'buffer.byteLength');1053 assert_equals(view.byteOffset, 0, 'byteOffset');1054 assert_equals(view.byteLength, 2, 'byteLength');1055 assert_equals(view[0], 0x0001, 'Contents are set');1056 const p = reader.read(new Uint16Array(1));1057 assert_equals(pullCount, 1);1058 return p;1059 }).then(result => {1060 assert_equals(result.done, false, 'done');1061 const view = result.value;1062 assert_equals(view.buffer.byteLength, 2, 'buffer.byteLength');1063 assert_equals(view.byteOffset, 0, 'byteOffset');1064 assert_equals(view.byteLength, 2, 'byteLength');1065 assert_equals(view[0], 0x0302, 'Contents are set');1066 assert_not_equals(byobRequest, undefined, 'byobRequest must not be undefined');1067 assert_equals(viewInfo.constructor, Uint8Array, 'view.constructor should be Uint8Array');1068 assert_equals(viewInfo.bufferByteLength, 2, 'view.buffer.byteLength should be 2');1069 assert_equals(viewInfo.byteOffset, 1, 'view.byteOffset should be 1');1070 assert_equals(viewInfo.byteLength, 1, 'view.byteLength should be 1');1071 assert_equals(desiredSize, 0, 'desiredSize should be zero');1072 });1073 assert_equals(pullCount, 0);1074 return promise;1075 });1076}, 'ReadableStream with byte source: enqueue() 3 byte, getReader(), then read(view) with 2-element Uint16Array');1077promise_test(t => {1078 const stream = new ReadableStream({1079 start(c) {1080 const view = new Uint8Array(1);1081 view[0] = 0xff;1082 c.enqueue(view);1083 c.close();1084 },1085 pull: t.unreached_func('pull() should not be called'),1086 type: 'bytes'1087 });1088 const reader = stream.getReader({ mode: 'byob' });1089 return promise_rejects(t, new TypeError(), reader.read(new Uint16Array(1)), 'read(view) must fail')1090 .then(() => promise_rejects(t, new TypeError(), reader.closed, 'reader.closed should reject'));1091}, 'ReadableStream with byte source: read(view) with Uint16Array on close()-d stream with 1 byte enqueue()-d must ' +1092 'fail');1093promise_test(t => {1094 let controller;1095 const stream = new ReadableStream({1096 start(c) {1097 const view = new Uint8Array(1);1098 view[0] = 0xff;1099 c.enqueue(view);1100 controller = c;1101 },1102 pull: t.unreached_func('pull() should not be called'),1103 type: 'bytes'1104 });1105 const reader = stream.getReader({ mode: 'byob' });1106 const readPromise = reader.read(new Uint16Array(1));1107 assert_throws(new TypeError(), () => controller.close(), 'controller.close() must throw');1108 return promise_rejects(t, new TypeError(), readPromise, 'read(view) must fail')1109 .then(() => promise_rejects(t, new TypeError(), reader.closed, 'reader.closed must reject'));1110}, 'ReadableStream with byte source: A stream must be errored if close()-d before fulfilling read(view) with ' +1111 'Uint16Array');1112test(() => {1113 let controller;1114 new ReadableStream({1115 start(c) {1116 controller = c;1117 },1118 type: 'bytes'1119 });1120 // Enqueue a chunk so that the stream doesn't get closed. This is to check duplicate close() calls are rejected1121 // even if the stream has not yet entered the closed state.1122 const view = new Uint8Array(1);1123 controller.enqueue(view);1124 controller.close();1125 assert_throws(new TypeError(), () => controller.close(), 'controller.close() must throw');1126}, 'ReadableStream with byte source: Throw if close()-ed more than once');1127test(() => {1128 let controller;1129 new ReadableStream({1130 start(c) {1131 controller = c;1132 },1133 type: 'bytes'1134 });1135 // Enqueue a chunk so that the stream doesn't get closed. This is to check enqueue() after close() is rejected1136 // even if the stream has not yet entered the closed state.1137 const view = new Uint8Array(1);1138 controller.enqueue(view);1139 controller.close();1140 assert_throws(new TypeError(), () => controller.enqueue(view), 'controller.close() must throw');1141}, 'ReadableStream with byte source: Throw on enqueue() after close()');1142promise_test(() => {1143 let controller;1144 let byobRequest;1145 let viewInfo;1146 const stream = new ReadableStream({1147 start(c) {1148 controller = c;1149 },1150 pull() {1151 byobRequest = controller.byobRequest;1152 const view = controller.byobRequest.view;1153 viewInfo = extractViewInfo(view);1154 view[15] = 0x01;1155 controller.byobRequest.respond(16);1156 controller.close();1157 },1158 type: 'bytes'1159 });1160 const reader = stream.getReader({ mode: 'byob' });1161 return reader.read(new Uint8Array(16)).then(result => {1162 assert_equals(result.done, false);1163 const view = result.value;1164 assert_equals(view.byteOffset, 0);1165 assert_equals(view.byteLength, 16);1166 assert_equals(view[15], 0x01);1167 return reader.read(new Uint8Array(16));1168 }).then(result => {1169 assert_equals(result.done, true);1170 const view = result.value;1171 assert_equals(view.byteOffset, 0);1172 assert_equals(view.byteLength, 0);1173 assert_not_equals(byobRequest, undefined, 'byobRequest must not be undefined');1174 assert_equals(viewInfo.constructor, Uint8Array, 'view.constructor should be Uint8Array');1175 assert_equals(viewInfo.bufferByteLength, 16, 'view.buffer.byteLength should be 16');1176 assert_equals(viewInfo.byteOffset, 0, 'view.byteOffset should be 0');1177 assert_equals(viewInfo.byteLength, 16, 'view.byteLength should be 16');1178 });1179}, 'ReadableStream with byte source: read(view), then respond() and close() in pull()');1180promise_test(() => {1181 let pullCount = 0;1182 let controller;1183 const viewInfos = [];1184 const stream = new ReadableStream({1185 start(c) {1186 controller = c;1187 },1188 pull() {1189 if (controller.byobRequest === undefined) {1190 return;1191 }1192 for (let i = 0; i < 4; ++i) {1193 const view = controller.byobRequest.view;1194 viewInfos.push(extractViewInfo(view));1195 view[0] = 0x01;1196 controller.byobRequest.respond(1);1197 }1198 ++pullCount;1199 },1200 type: 'bytes'1201 });1202 const reader = stream.getReader({ mode: 'byob' });1203 return reader.read(new Uint32Array(1)).then(result => {1204 assert_equals(result.done, false);1205 const view = result.value;1206 assert_equals(view.byteOffset, 0);1207 assert_equals(view.byteLength, 4);1208 assert_equals(view[0], 0x01010101);...
Using AI Code Generation
1var wptools = require('wptools');2var page = wptools.page('Albert Einstein');3page.extractViewInfo(function(err, data) {4 console.log(data);5});6var wptools = require('wptools');7var page = wptools.page('Albert Einstein');8page.extractViewInfo(function(err, data) {9 console.log(data);10});11var wptools = require('wptools');12var page = wptools.page('Albert Einstein');13page.extractViewInfo(function(err, data) {14 console.log(data);15});16var wptools = require('wptools');17var page = wptools.page('Albert Einstein');18page.extractViewInfo(function(err, data) {19 console.log(data);20});21var wptools = require('wptools');22var page = wptools.page('Albert Einstein');23page.extractViewInfo(function(err, data) {24 console.log(data);25});26var wptools = require('wptools');27var page = wptools.page('Albert Einstein');28page.extractViewInfo(function(err, data) {29 console.log(data);30});31var wptools = require('wptools');32var page = wptools.page('Albert Einstein');33page.extractViewInfo(function(err, data) {34 console.log(data);35});36var wptools = require('wptools');37var page = wptools.page('Albert Einstein');38page.extractViewInfo(function(err, data) {39 console.log(data);40});41var wptools = require('wptools');42var page = wptools.page('Albert Einstein');43page.extractViewInfo(function(err, data) {44 console.log(data);45});
Using AI Code Generation
1var wptoolkit = require('wptoolkit');2console.log(viewInfo);3var wptoolkit = require('wptoolkit');4console.log(viewInfo);5var wptoolkit = require('wptoolkit');6console.log(viewInfo);7var wptoolkit = require('wptoolkit');8console.log(viewInfo);9var wptoolkit = require('wptoolkit');10console.log(viewInfo);11var wptoolkit = require('wptoolkit');12console.log(viewInfo);13var wptoolkit = require('wptoolkit');14console.log(viewInfo);15var wptoolkit = require('wptoolkit');16console.log(viewInfo);17var wptoolkit = require('wptoolkit');18console.log(viewInfo);
Using AI Code Generation
1var wpt = require('wpt');2var wpt = new wpt('API_KEY');3wpt.extractViewInfo('TEST_ID', function(err, data) {4 console.log(data);5});6var wpt = require('wpt');7var wpt = new wpt('API_KEY');8wpt.getLocations(function(err, data) {9 console.log(data);10});11var wpt = require('wpt');12var wpt = new wpt('API_KEY');13wpt.getTesters(function(err, data) {14 console.log(data);15});16var wpt = require('wpt');17var wpt = new wpt('API_KEY');18wpt.getTesters(function(err, data) {19 console.log(data);20});21var wpt = require('wpt');22var wpt = new wpt('API_KEY');23wpt.getTesters(function(err, data) {24 console.log(data);25});26var wpt = require('wpt');27var wpt = new wpt('API_KEY');28wpt.getTesters(function(err, data) {29 console.log(data);30});31var wpt = require('wpt');32var wpt = new wpt('API_KEY');33wpt.getTesters(function(err, data) {34 console.log(data);35});36var wpt = require('wpt');37var wpt = new wpt('API_KEY');38wpt.getTesters(function(err, data) {39 console.log(data);40});41var wpt = require('wpt');42var wpt = new wpt('API_KEY');43wpt.getTesters(function(err, data) {44 console.log(data);45});
Using AI Code Generation
1var wptDriver = require('wpt-driver');2var viewInfo = wptDriver.extractViewInfo();3console.log('ViewInfo: ' + viewInfo);4var wptDriver = require('wpt-driver');5var driver = wptDriver.getWptDriver();6console.log('Driver: ' + driver);7var wptDriver = require('wpt-driver');8var driver = wptDriver.getWptDriver();9console.log('Driver: ' + driver);10var wptDriver = require('wpt-driver');11var driver = wptDriver.getWptDriver();12console.log('Driver: ' + driver);13var wptDriver = require('wpt-driver');14var driver = wptDriver.getWptDriver();15console.log('Driver: ' + driver);16var wptDriver = require('wpt-driver');17var driver = wptDriver.getWptDriver();18console.log('Driver: ' + driver);19var wptDriver = require('wpt-driver');20var driver = wptDriver.getWptDriver();21console.log('Driver: ' + driver);22var wptDriver = require('wpt-driver');23var driver = wptDriver.getWptDriver();24console.log('Driver: ' + driver);25var wptDriver = require('wpt-driver');26var driver = wptDriver.getWptDriver();27console.log('Driver: ' + driver);28var wptDriver = require('wpt-driver');29var driver = wptDriver.getWptDriver();30console.log('Driver: ' + driver);31var wptDriver = require('wpt-driver');32var driver = wptDriver.getWptDriver();33console.log('Driver: ' + driver);
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!