Skip to content

Commit c0c366c

Browse files
baylesjchromium-wpt-export-bot
authored andcommitted
[Region Capture #1] Add new produceCropId() API
This patch adds a new produceCropId() API to mediaDevices. This API is called with a DIV or IFRAME element, and adds a new base::UnguessableToken value to that element's rare data structure. This token value will be used in followup patches in order to keep track of an element's location in the page and viewport. Based on the following design document: https://docs.google.com/document/d/1dULARMnMZggfWqa_Ti_GrINRNYXGIli3XK9brzAKEV8/ Bug: 1247761 Change-Id: I01cd67e2d4e3dfa7a86289f876e48c8b55095d0a Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3173396 Commit-Queue: Jordan Bayles <jophba@chromium.org> Reviewed-by: Elad Alon <eladalon@chromium.org> Reviewed-by: mark a. foltz <mfoltz@chromium.org> Reviewed-by: Joey Arhar <jarhar@chromium.org> Cr-Commit-Position: refs/heads/main@{#925544}
1 parent b619d54 commit c0c366c

File tree

1 file changed

+65
-0
lines changed

1 file changed

+65
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
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

Comments
 (0)