11cb0ef41Sopenharmony_ci// META: timeout=long
21cb0ef41Sopenharmony_ciconst blob = new Blob(['test']);
31cb0ef41Sopenharmony_ciconst file = new File(['test'], 'name');
41cb0ef41Sopenharmony_ci
51cb0ef41Sopenharmony_citest(() => {
61cb0ef41Sopenharmony_ci  const url_count = 5000;
71cb0ef41Sopenharmony_ci  let list = [];
81cb0ef41Sopenharmony_ci
91cb0ef41Sopenharmony_ci  for (let i = 0; i < url_count; ++i)
101cb0ef41Sopenharmony_ci    list.push(URL.createObjectURL(blob));
111cb0ef41Sopenharmony_ci
121cb0ef41Sopenharmony_ci  list.sort();
131cb0ef41Sopenharmony_ci
141cb0ef41Sopenharmony_ci  for (let i = 1; i < list.length; ++i)
151cb0ef41Sopenharmony_ci    assert_not_equals(list[i], list[i-1], 'generated Blob URLs should be unique');
161cb0ef41Sopenharmony_ci}, 'Generated Blob URLs are unique');
171cb0ef41Sopenharmony_ci
181cb0ef41Sopenharmony_citest(() => {
191cb0ef41Sopenharmony_ci  const url = URL.createObjectURL(blob);
201cb0ef41Sopenharmony_ci  assert_equals(typeof url, 'string');
211cb0ef41Sopenharmony_ci  assert_true(url.startsWith('blob:'));
221cb0ef41Sopenharmony_ci}, 'Blob URL starts with "blob:"');
231cb0ef41Sopenharmony_ci
241cb0ef41Sopenharmony_citest(() => {
251cb0ef41Sopenharmony_ci  const url = URL.createObjectURL(file);
261cb0ef41Sopenharmony_ci  assert_equals(typeof url, 'string');
271cb0ef41Sopenharmony_ci  assert_true(url.startsWith('blob:'));
281cb0ef41Sopenharmony_ci}, 'Blob URL starts with "blob:" for Files');
291cb0ef41Sopenharmony_ci
301cb0ef41Sopenharmony_citest(() => {
311cb0ef41Sopenharmony_ci  const url = URL.createObjectURL(blob);
321cb0ef41Sopenharmony_ci  assert_equals(new URL(url).origin, location.origin);
331cb0ef41Sopenharmony_ci  if (location.origin !== 'null') {
341cb0ef41Sopenharmony_ci    assert_true(url.includes(location.origin));
351cb0ef41Sopenharmony_ci    assert_true(url.startsWith('blob:' + location.protocol));
361cb0ef41Sopenharmony_ci  }
371cb0ef41Sopenharmony_ci}, 'Origin of Blob URL matches our origin');
381cb0ef41Sopenharmony_ci
391cb0ef41Sopenharmony_citest(() => {
401cb0ef41Sopenharmony_ci  const url = URL.createObjectURL(blob);
411cb0ef41Sopenharmony_ci  const url_record = new URL(url);
421cb0ef41Sopenharmony_ci  assert_equals(url_record.protocol, 'blob:');
431cb0ef41Sopenharmony_ci  assert_equals(url_record.origin, location.origin);
441cb0ef41Sopenharmony_ci  assert_equals(url_record.host, '', 'host should be an empty string');
451cb0ef41Sopenharmony_ci  assert_equals(url_record.port, '', 'port should be an empty string');
461cb0ef41Sopenharmony_ci  const uuid_path_re = /\/[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i;
471cb0ef41Sopenharmony_ci  assert_true(uuid_path_re.test(url_record.pathname), 'Path must end with a valid UUID');
481cb0ef41Sopenharmony_ci  if (location.origin !== 'null') {
491cb0ef41Sopenharmony_ci    const nested_url = new URL(url_record.pathname);
501cb0ef41Sopenharmony_ci    assert_equals(nested_url.origin, location.origin);
511cb0ef41Sopenharmony_ci    assert_equals(nested_url.pathname.search(uuid_path_re), 0, 'Path must be a valid UUID');
521cb0ef41Sopenharmony_ci    assert_true(url.includes(location.origin));
531cb0ef41Sopenharmony_ci    assert_true(url.startsWith('blob:' + location.protocol));
541cb0ef41Sopenharmony_ci  }
551cb0ef41Sopenharmony_ci}, 'Blob URL parses correctly');
561cb0ef41Sopenharmony_ci
571cb0ef41Sopenharmony_citest(() => {
581cb0ef41Sopenharmony_ci  const url = URL.createObjectURL(file);
591cb0ef41Sopenharmony_ci  assert_equals(new URL(url).origin, location.origin);
601cb0ef41Sopenharmony_ci  if (location.origin !== 'null') {
611cb0ef41Sopenharmony_ci    assert_true(url.includes(location.origin));
621cb0ef41Sopenharmony_ci    assert_true(url.startsWith('blob:' + location.protocol));
631cb0ef41Sopenharmony_ci  }
641cb0ef41Sopenharmony_ci}, 'Origin of Blob URL matches our origin for Files');
65