summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/html/webappapis/system-state-and-capabilities/the-navigator-object/plugins-and-mimetypes.html
blob: af0501580121f4a5ddc1216cb519052a930dda53 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
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>