summaryrefslogtreecommitdiffstats
path: root/toolkit/components/extensions/test/mochitest/test_ext_background_page_dpi.html
blob: 40772402b143fa372ea846defc22c1b1d94b9fbd (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
<!DOCTYPE HTML>
<meta charset="utf-8">
<title>DPI of background page</title>
<script src="/tests/SimpleTest/SimpleTest.js"></script>
<script src="/tests/SimpleTest/ExtensionTestUtils.js"></script>
<script src="head.js"></script>
<link rel="stylesheet" href="/tests/SimpleTest/test.css">
<script>
"use strict";

async function testDPIMatches(description) {
  let extension = ExtensionTestUtils.loadExtension({
    background: function() {
      browser.test.sendMessage("dpi", window.devicePixelRatio);
    },
  });
  await extension.startup();
  let dpi = await extension.awaitMessage("dpi");
  await extension.unload();

  // This assumes that the window is loaded in a device DPI.
  is(
    dpi,
    window.devicePixelRatio,
    `DPI in a background page should match DPI in primary chrome page ${description}`
  );
}

add_task(async function test_dpi_simple() {
  await testDPIMatches("by default");
});

add_task(async function test_dpi_devPixelsPerPx() {
  await SpecialPowers.pushPrefEnv({
    set: [["layout.css.devPixelsPerPx", 1.5]],
  });
  await testDPIMatches("with devPixelsPerPx");
  await SpecialPowers.popPrefEnv();
});

add_task(async function test_dpi_os_zoom() {
  await SpecialPowers.pushPrefEnv({ set: [["ui.textScaleFactor", 200]] });
  await testDPIMatches("with OS zoom");
  await SpecialPowers.popPrefEnv();
});
</script>