Skip to content

Commit

Permalink
Bug 1720376 [wpt PR 29652] - Hard-code the list of plugins and mimety…
Browse files Browse the repository at this point in the history
…pes in navigator, a=testonly

Automatic update from web-platform-tests
Hard-code the list of plugins and mimetypes in navigator

See [1] for a previous attempt to completely empty the navigator.plugins
and navigator.mimeTypes APIs. That caused site breakage due to sites
scanning for a PDF reader. This new attempt is discussed in significant
detail in [2], and involves the hard-coding of a list of PDF viewers and
mime types.

The plugins/mimetypes lists will be empty if the user setting to
download PDFs instead of viewing them
(chrome://settings/content/pdfDocuments) is enabled. This is to ensure
compat with sites that scan the plugins list for specific PDF plugins
to decide on behavior. Prior to this CL, when the PDF viewer is
disabled, the PDF viewer plugins are unloaded.

Tests were copied mostly verbatim from [3], thanks @domenic.

I2S:
https://groups.google.com/a/chromium.org/g/blink-dev/c/bbxAGu90LgM

[1] https://chromium-review.googlesource.com/c/chromium/src/+/2783393
[2] whatwg/html#6738
[3] web-platform-tests/wpt#29559

Bug: 1164635
Change-Id: I7c52af5b918768d8b4c4a9faa409fb4e6b72ecc2
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3017890
Commit-Queue: Mason Freed <masonf@chromium.org>
Auto-Submit: Mason Freed <masonf@chromium.org>
Reviewed-by: Joey Arhar <jarhar@chromium.org>
Reviewed-by: Chris Harrelson <chrishtr@chromium.org>
Cr-Commit-Position: refs/heads/master@{#909443}

--

wpt-commits: 7be5ecfd72f0e95257f435a101b88e5ad277206f
wpt-pr: 29652
  • Loading branch information
Mason Freed authored and moz-wptsync-bot committed Aug 14, 2021
1 parent 1420aa6 commit 0632418
Showing 1 changed file with 83 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
<!DOCTYPE html>
<meta charset="utf-8">
<title>Navigator.plugins and navigator.mimeTypes behavior</title>
<link rel="author" href="mailto:domenic@chromium.org">
<link rel="help" href="https://github.com/whatwg/html/pull/6738">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>

<body>
<script>
test(() => {
assert_true('pdfViewerEnabled' in navigator, "property exists");
assert_equals(typeof navigator.pdfViewerEnabled, 'boolean', "property is boolean");
}, "navigator.pdfViewerEnabled exists");

const pluginNames = [
"PDF Viewer",
"Chrome PDF Viewer",
"Chromium PDF Viewer",
"Microsoft Edge PDF Viewer",
"WebKit built-in PDF"
];

const mimeTypes = [
"application/pdf",
"text/pdf"
];

if (navigator.pdfViewerEnabled) {
test(() => {
assert_equals(navigator.mimeTypes.length, mimeTypes.length, "length");

for (let i = 0; i < mimeTypes.length; ++i) {
const mimeType = mimeTypes[i];
const mimeTypeObject = navigator.mimeTypes.item(i);

assert_equals(mimeTypeObject.type, mimeType, `${i}th type`);
assert_equals(mimeTypeObject.description, "Portable Document Format", `${i}th description`);
assert_equals(mimeTypeObject.suffixes, "pdf", `${i}th suffixes`);
assert_equals(mimeTypeObject, navigator.mimeTypes.namedItem(mimeType), `mimeTypes.item(${i}) matches namedItem("${mimeType}")`);
assert_equals(mimeTypeObject.enabledPlugin, navigator.plugins[0], `${i}th enabledPlugin matches 0th Plugin`)
}
}, "navigator.mimeTypes contains the hard-coded list");

test(() => {
assert_equals(navigator.plugins.length, pluginNames.length, "length");

for (let i = 0; i < pluginNames.length; ++i) {
const pluginName = pluginNames[i];
const pluginObject = navigator.plugins.item(i);

assert_equals(pluginObject.name, pluginName, `${i}th name`);
assert_equals(pluginObject.description, "Portable Document Format", `${i}th description`);
assert_equals(pluginObject.filename, "internal-pdf-viewer", `${i}th filename`);
assert_equals(pluginObject, navigator.plugins.namedItem(pluginName), `plugins.item(${i}) matches namedItem("${pluginName}")`);

for (let j = 0; j < mimeTypes.length; ++j) {
const mimeType = mimeTypes[j];
assert_equals(pluginObject.item(j).type, navigator.mimeTypes[j].type, `item(${j}) on plugin(${i}) (${pluginObject.name})`);
assert_equals(pluginObject.namedItem(mimeType).type, navigator.mimeTypes.item(j).type, `namedItem("${mimeType}") on plugin(${i})`);
}
}
}, "navigator.plugins contains the hard-coded list");
} else {
test(() => {
assert_equals(navigator.mimeTypes.length, 0, "length");
assert_equals(navigator.mimeTypes.item(0), null, "item");

for (const mimeType of mimeTypes) {
assert_equals(navigator.mimeTypes.namedItem(mimeType), null, `namedItem("${mimeType}")`);
}
}, "navigator.mimeTypes is empty");

test(() => {
assert_equals(navigator.plugins.length, 0, "length");
assert_equals(navigator.plugins.item(0), null, "item");

for (const pluginName of pluginNames) {
assert_equals(navigator.plugins.namedItem(pluginName), null, `namedItem("${pluginName}")`);
}
}, "navigator.plugins is empty");
}
</script>

0 comments on commit 0632418

Please sign in to comment.