Skip to content

Commit

Permalink
Implement HTMLScriptElement.supports(type) method
Browse files Browse the repository at this point in the history
Bug: 1245528, whatwg/html#6472

Change-Id: I9a902504cf692caa73ae7e49fd65895156bbf197
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3133553
Commit-Queue: Tsuyoshi Horo <horo@chromium.org>
Reviewed-by: Hiroshige Hayashizaki <hiroshige@chromium.org>
Cr-Commit-Position: refs/heads/main@{#918474}
  • Loading branch information
horo-t authored and chromium-wpt-export-bot committed Sep 6, 2021
1 parent 6f5c3e7 commit e02f4a5
Show file tree
Hide file tree
Showing 2 changed files with 74 additions and 0 deletions.
52 changes: 52 additions & 0 deletions html/semantics/scripting-1/the-script-element/script-supports.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
<!doctype html>
<meta charset=utf-8>
<title>HTMLScriptElement.supports</title>
<link rel=help href="https://html.spec.whatwg.org/#dom-script-supports">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script>
test(function() {
assert_equals(typeof HTMLScriptElement.supports, 'function');
}, 'Type of HTMLScriptElement.supports is function');

test(function() {
assert_true(HTMLScriptElement.supports('classic'));
}, 'HTMLScriptElement.supports resurns true for \'classic\'');

test(function() {
assert_true(HTMLScriptElement.supports('module'));
}, 'HTMLScriptElement.supports resurns true for \'module\'');

test(function() {
assert_false(HTMLScriptElement.supports('application/ecmascript'));
assert_false(HTMLScriptElement.supports('application/javascript'));
assert_false(HTMLScriptElement.supports('application/x-ecmascript'));
assert_false(HTMLScriptElement.supports('application/x-javascript'));
assert_false(HTMLScriptElement.supports('text/ecmascript'));
assert_false(HTMLScriptElement.supports('text/javascript'));
assert_false(HTMLScriptElement.supports('text/javascript1.0'));
assert_false(HTMLScriptElement.supports('text/javascript1.1'));
assert_false(HTMLScriptElement.supports('text/javascript1.2'));
assert_false(HTMLScriptElement.supports('text/javascript1.3'));
assert_false(HTMLScriptElement.supports('text/javascript1.4'));
assert_false(HTMLScriptElement.supports('text/javascript1.5'));
assert_false(HTMLScriptElement.supports('text/jscript'));
assert_false(HTMLScriptElement.supports('text/livescript'));
assert_false(HTMLScriptElement.supports('text/x-ecmascript'));
assert_false(HTMLScriptElement.supports('text/x-javascript'));
}, 'HTMLScriptElement.supports returns false for JavaScript MIME types');

test(function() {
assert_false(HTMLScriptElement.supports(''));
assert_false(HTMLScriptElement.supports(' '));
assert_false(HTMLScriptElement.supports('classic '));
assert_false(HTMLScriptElement.supports('module '));
assert_false(HTMLScriptElement.supports(' classic '));
assert_false(HTMLScriptElement.supports(' module '));
assert_false(HTMLScriptElement.supports('classics'));
assert_false(HTMLScriptElement.supports('modules'));
assert_false(HTMLScriptElement.supports('Classic'));
assert_false(HTMLScriptElement.supports('Module'));
assert_false(HTMLScriptElement.supports('unsupported'));
}, 'HTMLScriptElement.supports returns false for unsupported types');
</script>
22 changes: 22 additions & 0 deletions import-maps/script-supports-importmap.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<!DOCTYPE html>
<html>
<title>HTMLScriptElement.supports importmap</title>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script>
test(function() {
assert_true(HTMLScriptElement.supports('importmap'));
}, 'HTMLScriptElement.supports returns true for \'importmap\'');

test(function() {
assert_false(HTMLScriptElement.supports(' importmap'));
assert_false(HTMLScriptElement.supports('importmap '));
assert_false(HTMLScriptElement.supports('Importmap'));
assert_false(HTMLScriptElement.supports('ImportMap'));
assert_false(HTMLScriptElement.supports('importMap'));
assert_false(HTMLScriptElement.supports('import-map'));
assert_false(HTMLScriptElement.supports('importmaps'));
assert_false(HTMLScriptElement.supports('import-maps'));
}, 'HTMLScriptElement.supports returns false for unsupported types');

</script>

0 comments on commit e02f4a5

Please sign in to comment.