Skip to content

Commit

Permalink
[Region Capture #1] Add new produceCropId() API
Browse files Browse the repository at this point in the history
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}
  • Loading branch information
baylesj authored and chromium-wpt-export-bot committed Sep 28, 2021
1 parent b619d54 commit c0c366c
Showing 1 changed file with 65 additions and 0 deletions.
65 changes: 65 additions & 0 deletions mediacapture-streams/MediaDevices-produceCropId.https.html
@@ -0,0 +1,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>

0 comments on commit c0c366c

Please sign in to comment.