[Streams API] Add bad strategies writable streams tests
authorcalvaris@igalia.com <calvaris@igalia.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 23 Sep 2015 11:03:08 +0000 (11:03 +0000)
committercalvaris@igalia.com <calvaris@igalia.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 23 Sep 2015 11:03:08 +0000 (11:03 +0000)
https://bugs.webkit.org/show_bug.cgi?id=148300

Reviewed by Darin Adler.

* streams/reference-implementation/bad-strategies-expected.txt: Added new expectations.
* streams/reference-implementation/bad-strategies.html: Added new writable stream tests.

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@190159 268f45cc-cd09-0410-ab3c-d52691b4dbfc

LayoutTests/ChangeLog
LayoutTests/streams/reference-implementation/bad-strategies-expected.txt
LayoutTests/streams/reference-implementation/bad-strategies.html

index 6551224..fdc616e 100644 (file)
@@ -1,5 +1,15 @@
 2015-09-23  Xabier Rodriguez Calvar  <calvaris@igalia.com>
 
+        [Streams API] Add bad strategies writable streams tests
+        https://bugs.webkit.org/show_bug.cgi?id=148300
+
+        Reviewed by Darin Adler.
+
+        * streams/reference-implementation/bad-strategies-expected.txt: Added new expectations.
+        * streams/reference-implementation/bad-strategies.html: Added new writable stream tests.
+
+2015-09-23  Xabier Rodriguez Calvar  <calvaris@igalia.com>
+
         [Streams API] Change a const in the tee tests
         https://bugs.webkit.org/show_bug.cgi?id=148294
 
index 2bc8cd4..1c11c59 100644 (file)
@@ -5,4 +5,18 @@ PASS Readable stream: throwing strategy.highWaterMark getter
 PASS Readable stream: invalid strategy.highWaterMark 
 PASS Readable stream: negative strategy.highWaterMark 
 PASS Readable stream: invalid strategy.size return value 
+FAIL Writable stream: throwing strategy.size getter assert_throws: construction should re-throw the error function "function () {
+        new WritableStream({}, {
+          ..." threw object "ReferenceError: Can't find variable: WritableStream" ("ReferenceError") expected object "Error: a unique string" ("Error")
+FAIL Writable stream: throwing strategy.size method Can't find variable: WritableStream
+FAIL Writable stream: invalid strategy.size return value Can't find variable: WritableStream
+FAIL Writable stream: throwing strategy.highWaterMark getter assert_throws: construction should re-throw the error function "function () {
+        new WritableStream({}, {
+          ..." threw object "ReferenceError: Can't find variable: WritableStream" ("ReferenceError") expected object "Error: a unique string" ("Error")
+FAIL Writable stream: invalid strategy.highWaterMark assert_throws: construction should throw a RangeError for -1 function "function () {
+            new WritableStream({}, {
+      ..." threw object "ReferenceError: Can't find variable: WritableStream" ("ReferenceError") expected object "RangeError" ("RangeError")
+FAIL Writable stream: negative strategy.highWaterMark assert_throws: construction should throw a RangeError function "function () {
+        new WritableStream({}, {
+          ..." threw object "ReferenceError: Can't find variable: WritableStream" ("ReferenceError") expected object "RangeError" ("RangeError")
 
index dca48e0..ff025ef 100644 (file)
@@ -122,4 +122,133 @@ test2.step(function() {
         rs.getReader().closed.catch(test2.step_func(catchFunction.bind(this, i)));
     }
 });
+
+test(function() {
+    var theError = new Error('a unique string');
+
+    assert_throws(theError, function() {
+        new WritableStream({}, {
+            get size() {
+                throw theError;
+            },
+            highWaterMark: 5
+        });
+    }, 'construction should re-throw the error');
+}, 'Writable stream: throwing strategy.size getter');
+
+var test3 = async_test('Writable stream: throwing strategy.size method');
+test3.step(function() {
+    var theError = new Error('a unique string');
+    var writeCalled = false;
+    var ws = new WritableStream({ },
+        {
+            size: function() {
+                throw theError;
+            },
+            highWaterMark: 5
+        }
+    ); // Initial construction should not throw.
+
+    ws.write('a').then(
+        test3.step_func(function() { assert_unreached('write should not fulfill'); }),
+        test3.step_func(function(r) {
+            assert_equals(r, theError, 'write should reject with the thrown error');
+            writeCalled = true;
+        })
+    );
+
+    ws.closed.then(
+        test3.step_func(function() { assert_unreached('closed should not fulfill'); }),
+        test3.step_func(function(r) {
+            assert_equals(r, theError, 'closed should reject with the thrown error');
+            assert_true(writeCalled);
+            test3.done();
+        })
+    );
+});
+
+var test4 = async_test('Writable stream: invalid strategy.size return value');
+test4.step(function() {
+    var numberOfCalls = 0;
+    var elements = [NaN, -Infinity, +Infinity, -1];
+    var theError = [];
+    var numberOfCalls = 0;
+    for (var i = 0; i < elements.length; i++) {
+        var ws = new WritableStream({},
+        {
+            size: function() {
+                return elements[i];
+            },
+            highWaterMark: 5
+        });
+
+        var writeFunction = function(i, r) {
+            assert_throws(new RangeError(), function() { throw r; }, 'write should reject with a RangeError for ' + elements[i]);
+            theError[i] = r;
+        };
+        ws.write('a').then(
+            test4.step_func(function() { assert_unreached('write should not fulfill'); }),
+            test4.step_func(writeFunction.bind(this, i))
+        );
+
+        var catchFunction = function(i, e) {
+            assert_equals(e, theError[i], 'closed should reject with the error for ' + elements[i]);
+            if (++numberOfCalls, elements.length) {
+                test4.done();
+            }
+        };
+
+        ws.closed.catch(test4.step_func(catchFunction.bind(this, i)));
+    }
+});
+
+test(function() {
+    var theError = new Error('a unique string');
+
+    assert_throws(theError, function() {
+        new WritableStream({}, {
+            size: function() {
+                return 1;
+            },
+            get highWaterMark() {
+                throw theError;
+            }
+        });
+    }, 'construction should re-throw the error');
+}, 'Writable stream: throwing strategy.highWaterMark getter');
+
+test(function() {
+    for (var highWaterMark of [-1, -Infinity]) {
+        assert_throws(new RangeError(), function() {
+            new WritableStream({}, {
+                size: function() {
+                    return 1;
+                },
+                highWaterMark
+            });
+        }, 'construction should throw a RangeError for ' + highWaterMark);
+    }
+
+    for (var highWaterMark of [NaN, 'foo', {}]) {
+        assert_throws(new TypeError(), function() {
+            new WritableStream({}, {
+                size: function() {
+                    return 1;
+                },
+                highWaterMark
+            });
+        }, 'construction should throw a TypeError for ' + highWaterMark);
+    }
+}, 'Writable stream: invalid strategy.highWaterMark');
+
+test(function() {
+    assert_throws(new RangeError(), function() {
+        new WritableStream({}, {
+            size: function() {
+                return 1;
+            },
+            highWaterMark: -1
+        });
+    }, 'construction should throw a RangeError');
+}, 'Writable stream: negative strategy.highWaterMark');
 </script>