• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1// META: timeout=long
2const blob = new Blob(['test']);
3const file = new File(['test'], 'name');
4
5test(() => {
6  const url_count = 5000;
7  let list = [];
8
9  for (let i = 0; i < url_count; ++i)
10    list.push(URL.createObjectURL(blob));
11
12  list.sort();
13
14  for (let i = 1; i < list.length; ++i)
15    assert_not_equals(list[i], list[i-1], 'generated Blob URLs should be unique');
16}, 'Generated Blob URLs are unique');
17
18test(() => {
19  const url = URL.createObjectURL(blob);
20  assert_equals(typeof url, 'string');
21  assert_true(url.startsWith('blob:'));
22}, 'Blob URL starts with "blob:"');
23
24test(() => {
25  const url = URL.createObjectURL(file);
26  assert_equals(typeof url, 'string');
27  assert_true(url.startsWith('blob:'));
28}, 'Blob URL starts with "blob:" for Files');
29
30test(() => {
31  const url = URL.createObjectURL(blob);
32  assert_equals(new URL(url).origin, location.origin);
33  if (location.origin !== 'null') {
34    assert_true(url.includes(location.origin));
35    assert_true(url.startsWith('blob:' + location.protocol));
36  }
37}, 'Origin of Blob URL matches our origin');
38
39test(() => {
40  const url = URL.createObjectURL(blob);
41  const url_record = new URL(url);
42  assert_equals(url_record.protocol, 'blob:');
43  assert_equals(url_record.origin, location.origin);
44  assert_equals(url_record.host, '', 'host should be an empty string');
45  assert_equals(url_record.port, '', 'port should be an empty string');
46  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;
47  assert_true(uuid_path_re.test(url_record.pathname), 'Path must end with a valid UUID');
48  if (location.origin !== 'null') {
49    const nested_url = new URL(url_record.pathname);
50    assert_equals(nested_url.origin, location.origin);
51    assert_equals(nested_url.pathname.search(uuid_path_re), 0, 'Path must be a valid UUID');
52    assert_true(url.includes(location.origin));
53    assert_true(url.startsWith('blob:' + location.protocol));
54  }
55}, 'Blob URL parses correctly');
56
57test(() => {
58  const url = URL.createObjectURL(file);
59  assert_equals(new URL(url).origin, location.origin);
60  if (location.origin !== 'null') {
61    assert_true(url.includes(location.origin));
62    assert_true(url.startsWith('blob:' + location.protocol));
63  }
64}, 'Origin of Blob URL matches our origin for Files');
65