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