FontAccess: Unify picker and enumeration functionality
This change unifies the font chooser and enumeration capabilities under
one API. A developer will be able to choose between using enumeration
and a chooser by passing an option parameter to the API.
Bug: 1140267
Change-Id: I4cdbb7c89d4795255c2cf709ec76f8c518d1e699
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2638548
Commit-Queue: Olivier Yiptong <oyiptong@chromium.org>
Reviewed-by: Joshua Bell <jsbell@chromium.org>
Cr-Commit-Position: refs/heads/master@{#846315}
diff --git a/font-access/font_access-chooser-multiple.tentative.manual.https.html b/font-access/font_access-chooser-multiple.tentative.manual.https.html
index a6b0feb..bf70a0a 100644
--- a/font-access/font_access-chooser-multiple.tentative.manual.https.html
+++ b/font-access/font_access-chooser-multiple.tentative.manual.https.html
@@ -17,8 +17,8 @@
await new Promise(resolve => step_timeout(resolve, 100));
await window.test_driver.bless('show a font chooser.<br>Please select at least one font.');
- const promise = navigator.fonts.showFontChooser()
- promise_rejects_dom(t, 'SecurityError', navigator.fonts.showFontChooser());
+ const promise = navigator.fonts.query()
+ promise_rejects_dom(t, 'SecurityError', navigator.fonts.query());
const fonts = await promise;
- }, 'showFontChooser multiple choosers');
+ }, 'query() multiple choosers');
</script>
diff --git a/font-access/font_access-chooser-selection.tentative.manual.https.html b/font-access/font_access-chooser-selection.tentative.manual.https.html
index 73d0e79..e8a1e8d 100644
--- a/font-access/font_access-chooser-selection.tentative.manual.https.html
+++ b/font-access/font_access-chooser-selection.tentative.manual.https.html
@@ -1,5 +1,5 @@
<!doctype html>
-<title>Local Font Access: Chooser</title>
+<title>Local Font Access: Chooser, Selection Options</title>
<meta charset=utf-8>
<script src="/resources/testharness.js"></script>
@@ -21,24 +21,24 @@
promise_test(async t => {
await window.test_driver.bless('show a font chooser.<br />Please select all the fonts that shows up.');
// Arial is considered to be web-safe.
- const fonts = await navigator.fonts.showFontChooser({select: ['ArialMT']});
+ const fonts = await navigator.fonts.query({select: ['ArialMT']});
assert_true(Array.isArray(fonts));
assert_equals(fonts.length, 1);
const postscriptName = fonts[0].postscriptName;
assert_equals(typeof postscriptName, "string");
assert_greater_than(postscriptName.length, 0);
- }, 'showFontChooser with selection works');
+ }, 'query() with selection works');
promise_test(async t => {
await window.test_driver.bless('show a font chooser.<br />Please select all the fonts that shows up.');
- const fonts = await navigator.fonts.showFontChooser({select: []});
+ const fonts = await navigator.fonts.query({select: []});
assert_true(Array.isArray(fonts));
assert_greater_than_equal(fonts.length, 1);
const postscriptName = fonts[0].postscriptName;
assert_equals(typeof postscriptName, "string");
assert_greater_than(postscriptName.length, 0);
- }, 'showFontChooser with empty selection bag works');
+ }, 'query() with empty selection bag works');
})();
</script>
diff --git a/font-access/font_access-chooser.tentative.manual.https.html b/font-access/font_access-chooser.tentative.manual.https.html
index 8f623da..499d8be 100644
--- a/font-access/font_access-chooser.tentative.manual.https.html
+++ b/font-access/font_access-chooser.tentative.manual.https.html
@@ -1,4 +1,5 @@
<!doctype html>
+<title>Local Font Access: Chooser</title>
<meta charset=utf-8>
<script src="/resources/testharness.js"></script>
@@ -16,13 +17,13 @@
await new Promise(resolve => step_timeout(resolve, 100));
await window.test_driver.bless('show a font chooser.<br />Please select at least one font.');
- const fonts = await navigator.fonts.showFontChooser();
+ const fonts = await navigator.fonts.query();
assert_true(Array.isArray(fonts));
assert_greater_than_equal(fonts.length, 1);
const postscriptName = fonts[0].postscriptName;
assert_equals(typeof postscriptName, "string");
assert_greater_than(postscriptName.length, 0);
- }, 'showFontChooser works');
+ }, 'query() with chooser works');
</script>
diff --git a/font-access/resources/test-expectations.js b/font-access/resources/test-expectations.js
index 7e540ed..0592b3e 100644
--- a/font-access/resources/test-expectations.js
+++ b/font-access/resources/test-expectations.js
@@ -306,14 +306,14 @@
return output;
}
-async function filterEnumeration(iterator, expectedFonts) {
+async function filterEnumeration(fonts, expectedFonts) {
const nameSet = new Set();
for (const e of expectedFonts) {
nameSet.add(e.postscriptName);
}
const output = [];
- for await (const f of iterator) {
+ for (const f of fonts) {
if (nameSet.has(f.postscriptName)) {
output.push(f);
}
diff --git a/font-access/resources/window-tests-blob.js b/font-access/resources/window-tests-blob.js
index 0d6db53..a5e514a 100644
--- a/font-access/resources/window-tests-blob.js
+++ b/font-access/resources/window-tests-blob.js
@@ -1,19 +1,14 @@
'use strict';
font_access_test(async t => {
- const iterator = navigator.fonts.query();
-
if (!isPlatformSupported()) {
- await promise_rejects_dom(t, 'NotSupportedError', (async () => {
- for await (const f of iterator) {
- }
- })());
+ await promise_rejects_dom(t, 'NotSupportedError', navigator.fonts.query());
return;
}
- const expectedFonts = await filterEnumeration(iterator,
- getEnumerationTestSet({
- labelFilter: [TEST_SIZE_CATEGORY.small]}));
+ const fonts = await navigator.fonts.query({persistentAccess: true});
+ const expectedFonts = await filterEnumeration(
+ fonts, getEnumerationTestSet({labelFilter: [TEST_SIZE_CATEGORY.small]}));
const additionalExpectedTables = getMoreExpectedTables(expectedFonts);
for (const f of expectedFonts) {
diff --git a/font-access/resources/window-tests-enumeration.js b/font-access/resources/window-tests-enumeration.js
index 29bb581..c0c8e00 100644
--- a/font-access/resources/window-tests-enumeration.js
+++ b/font-access/resources/window-tests-enumeration.js
@@ -1,8 +1,6 @@
'use strict';
const standard_fonts_tests = [
- null,
- undefined,
{},
{select: []},
];
@@ -13,47 +11,31 @@
font_access_test(async t => {
if (!isPlatformSupported()) {
await promise_rejects_dom(
- t, 'NotSupportedError', (async () => {
- for await (const f of navigator.fonts.query()) {
- }
- })());
+ t, 'NotSupportedError', navigator.fonts.query());
return;
}
- const iterator = navigator.fonts.query();
+ const fonts =
+ await navigator.fonts.query({persistentAccess: true, ...test});
- assert_equals(typeof iterator, 'object', 'query() should return an Object');
- assert_true(
- !!iterator[Symbol.asyncIterator],
- 'query() has an asyncIterator method');
-
- const availableFonts = [];
- for await (const f of iterator) {
- availableFonts.push(f);
- }
-
- assert_fonts_exist(availableFonts, getEnumerationTestSet());
+ assert_fonts_exist(fonts, getEnumerationTestSet());
}, `query(): standard fonts returned for input: ${inputAsString}`);
}
font_access_test(async t => {
- const iterator = navigator.fonts.query();
-
if (!isPlatformSupported()) {
- await promise_rejects_dom(t, 'NotSupportedError', (async () => {
- for await (const f of iterator) {
- }
- })());
+ await promise_rejects_dom(t, 'NotSupportedError', navigator.fonts.query());
return;
}
+ const fonts = await navigator.fonts.query({persistentAccess: true});
// The following tests that fonts are sorted. Postscript names are expected to
// be encoded in a subset of the ASCII character set.
// See: https://docs.microsoft.com/en-us/typography/opentype/spec/name
// Should the Postscript name contain characters that are multi-byte, this
// test may erroneously fail.
let previousFont = null;
- for await (const font of iterator) {
+ for (const font of fonts) {
if (previousFont) {
assert_true(
previousFont.postscriptName < font.postscriptName,
@@ -67,20 +49,16 @@
font_access_test(async t => {
if (!isPlatformSupported()) {
- await promise_rejects_dom(t, 'NotSupportedError', (async () => {
- for await (const f of navigator.fonts.query()) {
- }
- })());
+ await promise_rejects_dom(t, 'NotSupportedError', navigator.fonts.query());
return;
}
- const test = {select: [getEnumerationTestSet()[0].postscriptName]};
- const iterator = navigator.fonts.query(test);
+ const test = {
+ persistentAccess: true,
+ select: [getEnumerationTestSet()[0].postscriptName]
+ };
+ const fonts = await navigator.fonts.query(test);
- const fonts = [];
- for await (const f of iterator) {
- fonts.push(f);
- }
assert_postscript_name_exists(fonts, test.select);
assert_equals(
fonts.length, test.select.length,
@@ -109,18 +87,12 @@
font_access_test(async t => {
if (!isPlatformSupported()) {
await promise_rejects_dom(
- t, 'NotSupportedError', (async () => {
- for await (const f of navigator.fonts.query()) {
- }
- })());
+ t, 'NotSupportedError', navigator.fonts.query());
return;
}
- const fonts = [];
- const iterator = navigator.fonts.query(test);
- for await (const f of iterator) {
- fonts.push(f);
- }
+ const fonts =
+ await navigator.fonts.query({persistentAccess: true, ...test});
assert_equals(
fonts.length, 0,
`There should be no results. Instead got: ${JSON.stringify(fonts)}`);