-
Notifications
You must be signed in to change notification settings - Fork 3.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
HTML: Add tentative tests for preload scanner
See whatwg/html#5624
- Loading branch information
Showing
16 changed files
with
346 additions
and
0 deletions.
There are no files selected for viewing
21 changes: 21 additions & 0 deletions
21
html/syntax/preload-scanner.tentative/document-write/img-src.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
<!DOCTYPE html> | ||
<meta charset=utf-8> | ||
<!-- DO NOT EDIT! This file has been generated by /html/syntax/preload-scanner.tentative/tools/generate.py. --> | ||
<title>Preload scanner, document.write(): img-src</title> | ||
<script src=/resources/testharness.js></script> | ||
<script src=/resources/testharnessreport.js></script> | ||
<script src=/common/utils.js></script> | ||
<script src=/html/syntax/preload-scanner.tentative/resources/preload-scanner-util.js></script> | ||
<script> | ||
setup({single_test: true}); | ||
const uuid = token(); | ||
expect_fetched(uuid, true).then(done); | ||
document.write(` | ||
<script src=/common/slow.py><\/script> | ||
<script> | ||
document.write('<plaintext>'); | ||
<\/script> | ||
<img src=/html/syntax/preload-scanner.tentative/resources/stash.py?action=put&uuid=${uuid}> | ||
`); | ||
</script> | ||
|
21 changes: 21 additions & 0 deletions
21
html/syntax/preload-scanner.tentative/document-write/picture-source-no-img.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
<!DOCTYPE html> | ||
<meta charset=utf-8> | ||
<!-- DO NOT EDIT! This file has been generated by /html/syntax/preload-scanner.tentative/tools/generate.py. --> | ||
<title>Preload scanner, document.write(): picture-source-no-img</title> | ||
<script src=/resources/testharness.js></script> | ||
<script src=/resources/testharnessreport.js></script> | ||
<script src=/common/utils.js></script> | ||
<script src=/html/syntax/preload-scanner.tentative/resources/preload-scanner-util.js></script> | ||
<script> | ||
setup({single_test: true}); | ||
const uuid = token(); | ||
expect_fetched(uuid, false).then(done); | ||
document.write(` | ||
<script src=/common/slow.py><\/script> | ||
<script> | ||
document.write('<plaintext>'); | ||
<\/script> | ||
<picture><source srcset=/html/syntax/preload-scanner.tentative/resources/stash.py?action=put&uuid=${uuid}></picture> | ||
`); | ||
</script> | ||
|
21 changes: 21 additions & 0 deletions
21
html/syntax/preload-scanner.tentative/document-write/script-src-unsupported-type.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
<!DOCTYPE html> | ||
<meta charset=utf-8> | ||
<!-- DO NOT EDIT! This file has been generated by /html/syntax/preload-scanner.tentative/tools/generate.py. --> | ||
<title>Preload scanner, document.write(): script-src-unsupported-type</title> | ||
<script src=/resources/testharness.js></script> | ||
<script src=/resources/testharnessreport.js></script> | ||
<script src=/common/utils.js></script> | ||
<script src=/html/syntax/preload-scanner.tentative/resources/preload-scanner-util.js></script> | ||
<script> | ||
setup({single_test: true}); | ||
const uuid = token(); | ||
expect_fetched(uuid, false).then(done); | ||
document.write(` | ||
<script src=/common/slow.py><\/script> | ||
<script> | ||
document.write('<plaintext>'); | ||
<\/script> | ||
<script src=/html/syntax/preload-scanner.tentative/resources/stash.py?action=put&uuid=${uuid} type=text/plain><\/script> | ||
`); | ||
</script> | ||
|
21 changes: 21 additions & 0 deletions
21
html/syntax/preload-scanner.tentative/document-write/script-src.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
<!DOCTYPE html> | ||
<meta charset=utf-8> | ||
<!-- DO NOT EDIT! This file has been generated by /html/syntax/preload-scanner.tentative/tools/generate.py. --> | ||
<title>Preload scanner, document.write(): script-src</title> | ||
<script src=/resources/testharness.js></script> | ||
<script src=/resources/testharnessreport.js></script> | ||
<script src=/common/utils.js></script> | ||
<script src=/html/syntax/preload-scanner.tentative/resources/preload-scanner-util.js></script> | ||
<script> | ||
setup({single_test: true}); | ||
const uuid = token(); | ||
expect_fetched(uuid, true).then(done); | ||
document.write(` | ||
<script src=/common/slow.py><\/script> | ||
<script> | ||
document.write('<plaintext>'); | ||
<\/script> | ||
<script src=/html/syntax/preload-scanner.tentative/resources/stash.py?action=put&uuid=${uuid}><\/script> | ||
`); | ||
</script> | ||
|
17 changes: 17 additions & 0 deletions
17
html/syntax/preload-scanner.tentative/page-load/img-src.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
<!DOCTYPE html> | ||
<meta charset=utf-8> | ||
<!-- DO NOT EDIT! This file has been generated by /html/syntax/preload-scanner.tentative/tools/generate.py. --> | ||
<title>Preload scanner, page load: img-src</title> | ||
<script src=/resources/testharness.js></script> | ||
<script src=/resources/testharnessreport.js></script> | ||
<script src=/common/utils.js></script> | ||
<script src=/html/syntax/preload-scanner.tentative/resources/preload-scanner-util.js></script> | ||
<body> | ||
<script> | ||
setup({single_test: true}); | ||
const uuid = token(); | ||
const iframe = document.createElement('iframe'); | ||
iframe.src = `resources/img-src-framed.sub.html?uuid=${uuid}`; | ||
document.body.appendChild(iframe); | ||
expect_fetched(uuid, true).then(done); | ||
</script> |
17 changes: 17 additions & 0 deletions
17
html/syntax/preload-scanner.tentative/page-load/picture-source-no-img.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
<!DOCTYPE html> | ||
<meta charset=utf-8> | ||
<!-- DO NOT EDIT! This file has been generated by /html/syntax/preload-scanner.tentative/tools/generate.py. --> | ||
<title>Preload scanner, page load: picture-source-no-img</title> | ||
<script src=/resources/testharness.js></script> | ||
<script src=/resources/testharnessreport.js></script> | ||
<script src=/common/utils.js></script> | ||
<script src=/html/syntax/preload-scanner.tentative/resources/preload-scanner-util.js></script> | ||
<body> | ||
<script> | ||
setup({single_test: true}); | ||
const uuid = token(); | ||
const iframe = document.createElement('iframe'); | ||
iframe.src = `resources/picture-source-no-img-framed.sub.html?uuid=${uuid}`; | ||
document.body.appendChild(iframe); | ||
expect_fetched(uuid, false).then(done); | ||
</script> |
9 changes: 9 additions & 0 deletions
9
html/syntax/preload-scanner.tentative/page-load/resources/img-src-framed.sub.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
<!DOCTYPE html> | ||
<meta charset=utf-8> | ||
<!-- DO NOT EDIT! This file has been generated by /html/syntax/preload-scanner.tentative/tools/generate.py. --> | ||
<title>Preload scanner, page load (helper file): img-src</title> | ||
<script src=/common/slow.py></script> | ||
<script> | ||
document.write('<plaintext>'); | ||
</script> | ||
<img src=/html/syntax/preload-scanner.tentative/resources/stash.py?action=put&uuid={{GET[uuid]}}> |
9 changes: 9 additions & 0 deletions
9
...yntax/preload-scanner.tentative/page-load/resources/picture-source-no-img-framed.sub.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
<!DOCTYPE html> | ||
<meta charset=utf-8> | ||
<!-- DO NOT EDIT! This file has been generated by /html/syntax/preload-scanner.tentative/tools/generate.py. --> | ||
<title>Preload scanner, page load (helper file): picture-source-no-img</title> | ||
<script src=/common/slow.py></script> | ||
<script> | ||
document.write('<plaintext>'); | ||
</script> | ||
<picture><source srcset=/html/syntax/preload-scanner.tentative/resources/stash.py?action=put&uuid={{GET[uuid]}}></picture> |
9 changes: 9 additions & 0 deletions
9
html/syntax/preload-scanner.tentative/page-load/resources/script-src-framed.sub.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
<!DOCTYPE html> | ||
<meta charset=utf-8> | ||
<!-- DO NOT EDIT! This file has been generated by /html/syntax/preload-scanner.tentative/tools/generate.py. --> | ||
<title>Preload scanner, page load (helper file): script-src</title> | ||
<script src=/common/slow.py></script> | ||
<script> | ||
document.write('<plaintext>'); | ||
</script> | ||
<script src=/html/syntax/preload-scanner.tentative/resources/stash.py?action=put&uuid={{GET[uuid]}}></script> |
9 changes: 9 additions & 0 deletions
9
...preload-scanner.tentative/page-load/resources/script-src-unsupported-type-framed.sub.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
<!DOCTYPE html> | ||
<meta charset=utf-8> | ||
<!-- DO NOT EDIT! This file has been generated by /html/syntax/preload-scanner.tentative/tools/generate.py. --> | ||
<title>Preload scanner, page load (helper file): script-src-unsupported-type</title> | ||
<script src=/common/slow.py></script> | ||
<script> | ||
document.write('<plaintext>'); | ||
</script> | ||
<script src=/html/syntax/preload-scanner.tentative/resources/stash.py?action=put&uuid={{GET[uuid]}} type=text/plain></script> |
17 changes: 17 additions & 0 deletions
17
html/syntax/preload-scanner.tentative/page-load/script-src-unsupported-type.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
<!DOCTYPE html> | ||
<meta charset=utf-8> | ||
<!-- DO NOT EDIT! This file has been generated by /html/syntax/preload-scanner.tentative/tools/generate.py. --> | ||
<title>Preload scanner, page load: script-src-unsupported-type</title> | ||
<script src=/resources/testharness.js></script> | ||
<script src=/resources/testharnessreport.js></script> | ||
<script src=/common/utils.js></script> | ||
<script src=/html/syntax/preload-scanner.tentative/resources/preload-scanner-util.js></script> | ||
<body> | ||
<script> | ||
setup({single_test: true}); | ||
const uuid = token(); | ||
const iframe = document.createElement('iframe'); | ||
iframe.src = `resources/script-src-unsupported-type-framed.sub.html?uuid=${uuid}`; | ||
document.body.appendChild(iframe); | ||
expect_fetched(uuid, false).then(done); | ||
</script> |
17 changes: 17 additions & 0 deletions
17
html/syntax/preload-scanner.tentative/page-load/script-src.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
<!DOCTYPE html> | ||
<meta charset=utf-8> | ||
<!-- DO NOT EDIT! This file has been generated by /html/syntax/preload-scanner.tentative/tools/generate.py. --> | ||
<title>Preload scanner, page load: script-src</title> | ||
<script src=/resources/testharness.js></script> | ||
<script src=/resources/testharnessreport.js></script> | ||
<script src=/common/utils.js></script> | ||
<script src=/html/syntax/preload-scanner.tentative/resources/preload-scanner-util.js></script> | ||
<body> | ||
<script> | ||
setup({single_test: true}); | ||
const uuid = token(); | ||
const iframe = document.createElement('iframe'); | ||
iframe.src = `resources/script-src-framed.sub.html?uuid=${uuid}`; | ||
document.body.appendChild(iframe); | ||
expect_fetched(uuid, true).then(done); | ||
</script> |
14 changes: 14 additions & 0 deletions
14
html/syntax/preload-scanner.tentative/resources/preload-scanner-util.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
function expect_fetched(uuid, expectation) { | ||
return new Promise((resolve, reject) => { | ||
addEventListener('load', async () => { | ||
const response = await fetch(`/html/syntax/preload-scanner.tentative/resources/stash.py?action=take&uuid=${uuid}`); | ||
const result = await response.text(); | ||
if (expectation) { | ||
assert_equals(result, 'fetched', 'expected the preload scanner to prefetch'); | ||
} else { | ||
assert_equals(result, '', 'expected the preload scanner to NOT prefetch'); | ||
} | ||
resolve(); | ||
}); | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
def main(request, response): | ||
if request.GET[b"action"] == b"put": | ||
request.server.stash.put(request.GET[b"uuid"], b"fetched") | ||
return u'' | ||
return request.server.stash.take(request.GET[b"uuid"]) |
138 changes: 138 additions & 0 deletions
138
html/syntax/preload-scanner.tentative/tools/generate.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,138 @@ | ||
#!/usr/bin/env python3 | ||
|
||
# Usage: python3 generate.py | ||
# | ||
# This will remove all existing files in the generated directories and generate new tests. | ||
|
||
|
||
# Notes on potential confusion with the 3 string substitution features in different layers: | ||
# | ||
# - In Python strings when calling .format(): {something} or {} | ||
# To get a literal {} use {{}}. | ||
# The template_* variables are ones below are those that will use .format(). | ||
# https://docs.python.org/3/library/string.html#formatstrings | ||
# - JS template literals: ${something} | ||
# https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Template_literals | ||
# - wptserve server-side substitution when generating a response: {{GET[something]}} | ||
# https://web-platform-tests.org/writing-tests/server-pipes.html#sub | ||
|
||
import os, shutil | ||
|
||
target_dir = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) | ||
|
||
# Test data | ||
|
||
tests = [ | ||
# title, template_testcase_markup, expect_load | ||
(u'script-src', u'<script src={}></script>', u'true'), | ||
(u'img-src', u'<img src={}>', u'true'), | ||
(u'script-src-unsupported-type', u'<script src={} type=text/plain></script>', u'false'), | ||
(u'picture-source-no-img', u'<picture><source srcset={}></picture>', u'false'), | ||
] | ||
|
||
preamble = u"""<!DOCTYPE html> | ||
<meta charset=utf-8> | ||
<!-- DO NOT EDIT! This file has been generated by /html/syntax/preload-scanner.tentative/tools/generate.py. -->""" | ||
|
||
url_wptserve_sub = u"/html/syntax/preload-scanner.tentative/resources/stash.py?action=put&uuid={{GET[uuid]}}" | ||
url_js_sub = u"/html/syntax/preload-scanner.tentative/resources/stash.py?action=put&uuid=${uuid}" | ||
|
||
|
||
# Templates | ||
|
||
# Scenario: page load | ||
|
||
template_pageload_toplevel = u"""{preamble} | ||
<title>Preload scanner, page load: {title}</title> | ||
<script src=/resources/testharness.js></script> | ||
<script src=/resources/testharnessreport.js></script> | ||
<script src=/common/utils.js></script> | ||
<script src=/html/syntax/preload-scanner.tentative/resources/preload-scanner-util.js></script> | ||
<body> | ||
<script> | ||
setup({{single_test: true}}); | ||
const uuid = token(); | ||
const iframe = document.createElement('iframe'); | ||
iframe.src = `resources/{title}-framed.sub.html?uuid=${{uuid}}`; | ||
document.body.appendChild(iframe); | ||
expect_fetched(uuid, {expect_load}).then(done); | ||
</script> | ||
""" | ||
|
||
template_pageload_framed = u"""{preamble} | ||
<title>Preload scanner, page load (helper file): {title}</title> | ||
<script src=/common/slow.py></script> | ||
<script> | ||
document.write('<plaintext>'); | ||
</script> | ||
{testcase_markup} | ||
""" | ||
|
||
# Scenario: document.write() | ||
|
||
template_docwrite = u"""{preamble} | ||
<title>Preload scanner, document.write(): {title}</title> | ||
<script src=/resources/testharness.js></script> | ||
<script src=/resources/testharnessreport.js></script> | ||
<script src=/common/utils.js></script> | ||
<script src=/html/syntax/preload-scanner.tentative/resources/preload-scanner-util.js></script> | ||
<script> | ||
setup({{single_test: true}}); | ||
const uuid = token(); | ||
expect_fetched(uuid, {expect_load}).then(done); | ||
document.write(` | ||
<script src=/common/slow.py><\\/script> | ||
<script> | ||
document.write('<plaintext>'); | ||
<\\/script> | ||
{testcase_markup} | ||
`); | ||
</script> | ||
""" | ||
|
||
# Scenario: <link rel=prerender> - TODO(zcorpan) | ||
|
||
template_prerender_toplevel = u"""{preamble} | ||
<title>Preload scanner, prerender: {title}</title> | ||
... | ||
""" | ||
|
||
template_prerender_linked = u"""{preamble} | ||
<title>Preload scanner, prerender (helper file): {title}</title> | ||
... | ||
""" | ||
|
||
# Generate tests | ||
|
||
def wipe_dir(path): | ||
path = os.path.join(target_dir, path) | ||
if os.path.isdir(path) == False: | ||
os.mkdir(path) | ||
for filename in os.listdir(path): | ||
file_path = os.path.join(path, filename) | ||
if os.path.isfile(file_path) or os.path.islink(file_path): | ||
os.unlink(file_path) | ||
|
||
def write_file(path, content): | ||
path = os.path.join(target_dir, path) | ||
file = open(os.path.join(target_dir, path), 'w') | ||
file.write(content) | ||
file.close() | ||
|
||
wipe_dir(u"page-load") | ||
wipe_dir(u"page-load/resources") | ||
wipe_dir(u"document-write") | ||
|
||
for testcase in tests: | ||
title, template_testcase_markup, expect_load = testcase | ||
|
||
pageload_testcase_markup = template_testcase_markup.format(url_wptserve_sub) | ||
pageload_toplevel = template_pageload_toplevel.format(preamble=preamble, title=title, expect_load=expect_load) | ||
write_file(f"page-load/{title}.html", pageload_toplevel) | ||
pageload_framed = template_pageload_framed.format(preamble=preamble, title=title, testcase_markup=pageload_testcase_markup) | ||
write_file(f"page-load/resources/{title}-framed.sub.html", pageload_framed) | ||
|
||
docwrite_testcase_markup = template_testcase_markup.format(url_js_sub).replace(u"</script>", u"<\/script>") | ||
docwrite = template_docwrite.format(preamble=preamble, title=title, expect_load=expect_load, testcase_markup=docwrite_testcase_markup) | ||
write_file(f"document-write/{title}.html", docwrite) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters