11cb0ef41Sopenharmony_ci<!doctype html>
21cb0ef41Sopenharmony_ci<meta charset="utf-8">
31cb0ef41Sopenharmony_ci<script src="/resources/testharness.js"></script>
41cb0ef41Sopenharmony_ci<script src="/resources/testharnessreport.js"></script>
51cb0ef41Sopenharmony_ci<body>
61cb0ef41Sopenharmony_ci<script>
71cb0ef41Sopenharmony_cipromise_test(t => {
81cb0ef41Sopenharmony_ci  const blob_contents = 'test blob contents';
91cb0ef41Sopenharmony_ci  const blob = new Blob([blob_contents]);
101cb0ef41Sopenharmony_ci  const worker = new Worker('resources/create-helper.js');
111cb0ef41Sopenharmony_ci  let url;
121cb0ef41Sopenharmony_ci  return new Promise(resolve => {
131cb0ef41Sopenharmony_ci    worker.onmessage = e => resolve(e.data);
141cb0ef41Sopenharmony_ci    worker.postMessage({blob: blob});
151cb0ef41Sopenharmony_ci  }).then(data => {
161cb0ef41Sopenharmony_ci    url = data.url;
171cb0ef41Sopenharmony_ci    let result = fetch(url);
181cb0ef41Sopenharmony_ci    worker.terminate();
191cb0ef41Sopenharmony_ci    return result;
201cb0ef41Sopenharmony_ci  }).then(response => response.text()).then(text => {
211cb0ef41Sopenharmony_ci    assert_equals(text, blob_contents);
221cb0ef41Sopenharmony_ci    return new Promise(resolve => t.step_timeout(resolve, 100));
231cb0ef41Sopenharmony_ci  }).then(() => promise_rejects_js(t, TypeError, fetch(url)));
241cb0ef41Sopenharmony_ci}, 'Terminating worker revokes its URLs');
251cb0ef41Sopenharmony_ci
261cb0ef41Sopenharmony_cipromise_test(t => {
271cb0ef41Sopenharmony_ci  const blob_contents = 'test blob contents';
281cb0ef41Sopenharmony_ci  const blob = new Blob([blob_contents]);
291cb0ef41Sopenharmony_ci  const frame = document.createElement('iframe');
301cb0ef41Sopenharmony_ci  frame.setAttribute('style', 'display:none;');
311cb0ef41Sopenharmony_ci  frame.src = 'resources/create-helper.html';
321cb0ef41Sopenharmony_ci  document.body.appendChild(frame);
331cb0ef41Sopenharmony_ci
341cb0ef41Sopenharmony_ci  let url;
351cb0ef41Sopenharmony_ci  return new Promise(resolve => {
361cb0ef41Sopenharmony_ci    frame.onload = t.step_func(e => {
371cb0ef41Sopenharmony_ci      resolve(e);
381cb0ef41Sopenharmony_ci    });
391cb0ef41Sopenharmony_ci  }).then(e => {
401cb0ef41Sopenharmony_ci    frame.contentWindow.postMessage({blob: blob}, '*');
411cb0ef41Sopenharmony_ci    return new Promise(resolve => {
421cb0ef41Sopenharmony_ci      self.addEventListener('message', t.step_func(e => {
431cb0ef41Sopenharmony_ci        if (e.source === frame.contentWindow) resolve(e);
441cb0ef41Sopenharmony_ci      }));
451cb0ef41Sopenharmony_ci    });
461cb0ef41Sopenharmony_ci  }).then(e => {
471cb0ef41Sopenharmony_ci    url = e.data.url;
481cb0ef41Sopenharmony_ci    let fetch_result = fetch(url);
491cb0ef41Sopenharmony_ci    document.body.removeChild(frame);
501cb0ef41Sopenharmony_ci    return fetch_result;
511cb0ef41Sopenharmony_ci  }).then(response => response.text()).then(text => {
521cb0ef41Sopenharmony_ci    assert_equals(text, blob_contents);
531cb0ef41Sopenharmony_ci    return new Promise(resolve => t.step_timeout(resolve, 100));
541cb0ef41Sopenharmony_ci  }).then(() => promise_rejects_js(t, TypeError, fetch(url)));
551cb0ef41Sopenharmony_ci}, 'Removing an iframe revokes its URLs');
561cb0ef41Sopenharmony_ci</script>