OLD | NEW |
(Empty) | |
| 1 'use strict'; |
| 2 |
| 3 if (self.importScripts) { |
| 4 self.importScripts('/resources/testharness.js'); |
| 5 } |
| 6 |
| 7 test(() => { |
| 8 |
| 9 const strategy = new ByteLengthQueuingStrategy({ highWaterMark: 4 }); |
| 10 |
| 11 }, 'Can construct a ByteLengthQueuingStrategy with a valid high water mark'); |
| 12 |
| 13 test(() => { |
| 14 |
| 15 for (const highWaterMark of [-Infinity, NaN, 'foo', {}, () => {}]) { |
| 16 const strategy = new ByteLengthQueuingStrategy({ highWaterMark }); |
| 17 assert_equals(strategy.highWaterMark, highWaterMark, `${highWaterMark} gets
set correctly`); |
| 18 } |
| 19 |
| 20 }, 'Can construct a ByteLengthQueuingStrategy with any value as its high water m
ark'); |
| 21 |
| 22 test(() => { |
| 23 |
| 24 const highWaterMark = 1; |
| 25 const highWaterMarkObjectGetter = { |
| 26 get highWaterMark() { return highWaterMark; }, |
| 27 }; |
| 28 const error = new Error('wow!'); |
| 29 const highWaterMarkObjectGetterThrowing = { |
| 30 get highWaterMark() { throw error; }, |
| 31 }; |
| 32 |
| 33 assert_throws({ name: 'TypeError' }, () => new ByteLengthQueuingStrategy(), 'c
onstruction fails with undefined'); |
| 34 assert_throws({ name: 'TypeError' }, () => new ByteLengthQueuingStrategy(null)
, 'construction fails with null'); |
| 35 assert_throws({ name: 'Error' }, () => new ByteLengthQueuingStrategy(highWater
MarkObjectGetterThrowing), |
| 36 'construction fails with an object with a throwing highWaterMark getter'); |
| 37 |
| 38 // Should not fail: |
| 39 new ByteLengthQueuingStrategy('potato'); |
| 40 new ByteLengthQueuingStrategy({}); |
| 41 new ByteLengthQueuingStrategy(highWaterMarkObjectGetter); |
| 42 |
| 43 }, 'ByteLengthQueuingStrategy constructor behaves as expected with strange argum
ents'); |
| 44 |
| 45 test(() => { |
| 46 |
| 47 const size = 1024; |
| 48 const chunk = { byteLength: size }; |
| 49 const chunkGetter = { |
| 50 get byteLength() { return size; }, |
| 51 } |
| 52 const error = new Error('wow!'); |
| 53 const chunkGetterThrowing = { |
| 54 get byteLength() { throw error; }, |
| 55 } |
| 56 assert_throws({ name: 'TypeError' }, () => ByteLengthQueuingStrategy.prototype
.size(), 'size fails with undefined'); |
| 57 assert_throws({ name: 'TypeError' }, () => ByteLengthQueuingStrategy.prototype
.size(null), 'size fails with null'); |
| 58 assert_equals(ByteLengthQueuingStrategy.prototype.size('potato'), undefined, |
| 59 'size succeeds with undefined with a random non-object type'); |
| 60 assert_equals(ByteLengthQueuingStrategy.prototype.size({}), undefined, |
| 61 'size succeeds with undefined with an object without hwm property'); |
| 62 assert_equals(ByteLengthQueuingStrategy.prototype.size(chunk), size, |
| 63 'size succeeds with the right amount with an object with a hwm'); |
| 64 assert_equals(ByteLengthQueuingStrategy.prototype.size(chunkGetter), size, |
| 65 'size succeeds with the right amount with an object with a hwm getter'); |
| 66 assert_throws({ name: 'Error' }, () => ByteLengthQueuingStrategy.prototype.siz
e(chunkGetterThrowing), |
| 67 'size fails with the error thrown by the getter'); |
| 68 |
| 69 }, 'ByteLengthQueuingStrategy size behaves as expected with strange arguments'); |
| 70 |
| 71 test(() => { |
| 72 |
| 73 const strategy = new ByteLengthQueuingStrategy({ highWaterMark: 4 }); |
| 74 |
| 75 assert_object_equals(Object.getOwnPropertyDescriptor(strategy, 'highWaterMark'
), |
| 76 { value: 4, writable: true, enumerable: true, configurable: true }, |
| 77 'highWaterMark property should be a data property with the value passed the
constructor'); |
| 78 assert_equals(typeof strategy.size, 'function'); |
| 79 |
| 80 }, 'ByteLengthQueuingStrategy instances have the correct properties'); |
| 81 |
| 82 test(() => { |
| 83 |
| 84 const strategy = new ByteLengthQueuingStrategy({ highWaterMark: 4 }); |
| 85 assert_equals(strategy.highWaterMark, 4); |
| 86 |
| 87 strategy.highWaterMark = 10; |
| 88 assert_equals(strategy.highWaterMark, 10); |
| 89 |
| 90 strategy.highWaterMark = "banana"; |
| 91 assert_equals(strategy.highWaterMark, "banana"); |
| 92 |
| 93 }, 'ByteLengthQueuingStrategy\'s highWaterMark property can be set to anything')
; |
| 94 |
| 95 done(); |
OLD | NEW |