summaryrefslogtreecommitdiffstats
path: root/dom/html/test/test_bug1322678.html
blob: 57b43f039c0bd423e10ad4c3f857b31d831ee635 (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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
<!DOCTYPE html>
<html>
<!--
https://bugzilla.mozilla.org/show_bug.cgi?id=1322678
-->
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Test for Bug 1322678</title>
<script src="/tests/SimpleTest/EventUtils.js"></script>
<script src="/tests/SimpleTest/SimpleTest.js"></script>
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
</head>
<body>
<script type="text/javascript">

const CUSTOM_TITLE = "Custom Title";

async function openNewWindowForTest() {
  let win = window.open("bug369370-popup.png", "bug1322678",
                    "width=400,height=300,scrollbars=no");
  ok(win, "opened child window");

  await new Promise(resolve => {
    win.onload = function() {
      ok(true, "window loaded");
      resolve();
    };
  });

  return win;
}

async function testCustomTitle(aWin, aTitle) {
  let doc = aWin.document;
  let elements = doc.getElementsByTagName("img");
  is(elements.length, 1, "looking for img in ImageDocument");
  let img = elements[0];

  // Click to zoom in
  synthesizeMouse(img, 25, 25, { }, aWin);
  is(doc.title, aTitle, "Checking title");

  // Click there again to zoom out
  synthesizeMouse(img, 25, 25, { }, aWin);
  is(doc.title, aTitle, "Checking title");

  // Now try resizing the window so the image fits vertically and horizontally.
  await new Promise(resolve => {
    aWin.addEventListener("resize", function() {
      // Give the image document time to respond
      SimpleTest.executeSoon(function() {
        is(doc.title, aTitle, "Checking title");
        resolve();
      });
    }, {once: true});

    let decorationSize = aWin.outerHeight - aWin.innerHeight;
    aWin.resizeTo(800 + 50 + decorationSize, 600 + 50 + decorationSize);
  });

  // Now try resizing the window so the image no longer fits.
  await new Promise(resolve => {
    aWin.addEventListener("resize", function() {
      // Give the image document time to respond
      SimpleTest.executeSoon(function() {
        is(doc.title, aTitle, "Checking title");
        resolve();
      });
    }, {once: true});

    aWin.resizeTo(400, 300);
  });
}

// eslint-disable-next-line mozilla/no-addtask-setup
add_task(async function setup() {
  await SpecialPowers.pushPrefEnv({"set": [
    ["browser.enable_automatic_image_resizing", true],
  ]});
});

add_task(async function testUpdateDocumentTitle() {
  let win = await openNewWindowForTest();
  // Set custom title.
  win.document.title = CUSTOM_TITLE;
  await testCustomTitle(win, CUSTOM_TITLE);
  win.close();
});

add_task(async function testUpdateTitleElement() {
  let win = await openNewWindowForTest();
  // Set custom title.
  let title = win.document.getElementsByTagName("title")[0];
  title.text = CUSTOM_TITLE;
  await testCustomTitle(win, CUSTOM_TITLE);
  win.close();
});

add_task(async function testAppendNewTitleElement() {
  let win = await openNewWindowForTest();
  // Set custom title.
  let doc = win.document;
  doc.getElementsByTagName("title")[0].remove();
  let title = doc.createElement("title");
  title.text = CUSTOM_TITLE;
  doc.head.appendChild(title);
  await testCustomTitle(win, CUSTOM_TITLE);
  win.close();
});

</script>
</body>
</html>