forked from web-platform-tests/wpt
-
Notifications
You must be signed in to change notification settings - Fork 0
/
MediaDevices-produceCropId.https.html
65 lines (54 loc) · 1.99 KB
/
MediaDevices-produceCropId.https.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
<!doctype html>
<html>
<head>
<title>Test navigator.mediaDevices.produceCropId()</title>
<meta name='assert' content='Test the produceCropId() method.'/>
</head>
<body>
<h1 class="instructions">Description</h1>
<p class="instructions">This test checks for the behavior of the
<code>navigator.mediaDevices.produceCropId()</code> method.</p>
<div id='test-div'></div>
<iframe id='test-iframe' src="about:blank" />
<a id='test-a'></a>
<div id='log'></div>
<script src=/resources/testharness.js></script>
<script src=/resources/testharnessreport.js></script>
<script>
"use strict";
// Regex that matches a string only if it is exactly 32 valid hex characters.
const HEX_REGEX = /^[0-9A-Fa-f]{32}$/g;
test(() => {
const div_id = document.getElementById('test-div').produceCropId();
assert_true(HEX_REGEX.test(div_id));
}, "produces valid id for div");
test(() => {
const iframe_id = document.getElementById('test-iframe').produceCropId();
assert_true(HEX_REGEX.test(iframe_id));
}, "produces valid id for iframe");
test(() => {
const iframe_id = document.getElementById('test-iframe').produceCropId();
const second_iframe_id = document.getElementById('test-iframe').produceCropId();
assert_equals(iframe_id, second_iframe_id);
}, "repeated calls return the same value");
test(() => {
assert_throws_js(TypeError, function() {
await document.getElementById('test-a').produceCropId();
});
}, "invalid element types cause an error");
test(() => {
const div_id = document.getElementById('test-div').produceCropId();
const iframe_id = document.getElementById('test-iframe').produceCropId();
assert_not_equals(div_id, iframe_id);
}, "two elements have different IDs");
test(() => {
const div = document.getElementById('test-div');
const div_id = div.produceCropId();
const clone = div.cloneNode(true);
document.querySelector('body').appendChild(clone);
const clone_id = clone.produceCropId();
assert_not_equals(div_id, clone_id);
}, "cloned elements have different IDs");
</script>
</body>
</html>