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