OLD | NEW |
| (Empty) |
1 'use strict'; | |
2 | |
3 if (self.importScripts) { | |
4 self.importScripts('/resources/testharness.js'); | |
5 } | |
6 | |
7 test(() => { | |
8 | |
9 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 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 | |
85 const strategy = new ByteLengthQueuingStrategy({ highWaterMark: 4 }); | |
86 | |
87 assert_object_equals(Object.getOwnPropertyDescriptor(strategy, 'highWaterMark'
), | |
88 { value: 4, writable: true, enumerable: true, configurable: true }, | |
89 'highWaterMark property should be a data property with the value passed the
constructor'); | |
90 assert_equals(typeof strategy.size, 'function'); | |
91 | |
92 }, 'ByteLengthQueuingStrategy instances have the correct properties'); | |
93 | |
94 test(() => { | |
95 | |
96 const strategy = new ByteLengthQueuingStrategy({ highWaterMark: 4 }); | |
97 assert_equals(strategy.highWaterMark, 4); | |
98 | |
99 strategy.highWaterMark = 10; | |
100 assert_equals(strategy.highWaterMark, 10); | |
101 | |
102 strategy.highWaterMark = 'banana'; | |
103 assert_equals(strategy.highWaterMark, 'banana'); | |
104 | |
105 }, 'ByteLengthQueuingStrategy\'s highWaterMark property can be set to anything')
; | |
106 | |
107 done(); | |
OLD | NEW |