11cb0ef41Sopenharmony_ci<!DOCTYPE html>
21cb0ef41Sopenharmony_ci<meta charset="utf-8">
31cb0ef41Sopenharmony_ci<title>Blob slice overflow</title>
41cb0ef41Sopenharmony_ci<link rel="author" title="Intel" href="http://www.intel.com">
51cb0ef41Sopenharmony_ci<link rel="help" href="https://w3c.github.io/FileAPI/#dfn-slice">
61cb0ef41Sopenharmony_ci<script src="/resources/testharness.js"></script>
71cb0ef41Sopenharmony_ci<script src="/resources/testharnessreport.js"></script>
81cb0ef41Sopenharmony_ci<div id="log"></div>
91cb0ef41Sopenharmony_ci<script>
101cb0ef41Sopenharmony_ci
111cb0ef41Sopenharmony_civar text = '';
121cb0ef41Sopenharmony_ci
131cb0ef41Sopenharmony_cifor (var i = 0; i < 2000; ++i) {
141cb0ef41Sopenharmony_ci  text += 'A';
151cb0ef41Sopenharmony_ci}
161cb0ef41Sopenharmony_ci
171cb0ef41Sopenharmony_citest(function() {
181cb0ef41Sopenharmony_ci  var blob = new Blob([text]);
191cb0ef41Sopenharmony_ci  var sliceBlob = blob.slice(-1, blob.size);
201cb0ef41Sopenharmony_ci  assert_equals(sliceBlob.size, 1, "Blob slice size");
211cb0ef41Sopenharmony_ci}, "slice start is negative, relativeStart will be max((size + start), 0)");
221cb0ef41Sopenharmony_ci
231cb0ef41Sopenharmony_citest(function() {
241cb0ef41Sopenharmony_ci  var blob = new Blob([text]);
251cb0ef41Sopenharmony_ci  var sliceBlob = blob.slice(blob.size + 1, blob.size);
261cb0ef41Sopenharmony_ci  assert_equals(sliceBlob.size, 0, "Blob slice size");
271cb0ef41Sopenharmony_ci}, "slice start is greater than blob size, relativeStart will be min(start, size)");
281cb0ef41Sopenharmony_ci
291cb0ef41Sopenharmony_citest(function() {
301cb0ef41Sopenharmony_ci  var blob = new Blob([text]);
311cb0ef41Sopenharmony_ci  var sliceBlob = blob.slice(blob.size - 2, -1);
321cb0ef41Sopenharmony_ci  assert_equals(sliceBlob.size, 1, "Blob slice size");
331cb0ef41Sopenharmony_ci}, "slice end is negative, relativeEnd will be max((size + end), 0)");
341cb0ef41Sopenharmony_ci
351cb0ef41Sopenharmony_citest(function() {
361cb0ef41Sopenharmony_ci  var blob = new Blob([text]);
371cb0ef41Sopenharmony_ci  var sliceBlob = blob.slice(blob.size - 2, blob.size + 999);
381cb0ef41Sopenharmony_ci  assert_equals(sliceBlob.size, 2, "Blob slice size");
391cb0ef41Sopenharmony_ci}, "slice end is greater than blob size, relativeEnd will be min(end, size)");
401cb0ef41Sopenharmony_ci
411cb0ef41Sopenharmony_ci</script>
421cb0ef41Sopenharmony_ci
43