summaryrefslogtreecommitdiffstats
path: root/accessible/tests/browser/e10s/browser_treeupdate_imagemap.js
blob: 82fbd3427e618b6fd4c548c4b3d3fe5625717d16 (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
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
/* This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */

"use strict";

/* import-globals-from ../../mochitest/role.js */
loadScripts({ name: "role.js", dir: MOCHITESTS_DIR });

async function testImageMap(browser, accDoc) {
  const id = "imgmap";
  const acc = findAccessibleChildByID(accDoc, id);

  /* ================= Initial tree test ==================================== */
  let tree = {
    IMAGE_MAP: [{ role: ROLE_LINK, name: "b", children: [] }],
  };
  testAccessibleTree(acc, tree);

  /* ================= Insert area ========================================== */
  let onReorder = waitForEvent(EVENT_REORDER, id);
  await invokeContentTask(browser, [], () => {
    let areaElm = content.document.createElement("area");
    let mapNode = content.document.getElementById("map");
    areaElm.setAttribute(
      "href",
      // eslint-disable-next-line @microsoft/sdl/no-insecure-url
      "http://www.bbc.co.uk/radio4/atoz/index.shtml#a"
    );
    areaElm.setAttribute("coords", "0,0,13,14");
    areaElm.setAttribute("alt", "a");
    areaElm.setAttribute("shape", "rect");
    mapNode.insertBefore(areaElm, mapNode.firstChild);
  });
  await onReorder;

  tree = {
    IMAGE_MAP: [
      { role: ROLE_LINK, name: "a", children: [] },
      { role: ROLE_LINK, name: "b", children: [] },
    ],
  };
  testAccessibleTree(acc, tree);

  /* ================= Append area ========================================== */
  onReorder = waitForEvent(EVENT_REORDER, id);
  await invokeContentTask(browser, [], () => {
    let areaElm = content.document.createElement("area");
    let mapNode = content.document.getElementById("map");
    areaElm.setAttribute(
      "href",
      // eslint-disable-next-line @microsoft/sdl/no-insecure-url
      "http://www.bbc.co.uk/radio4/atoz/index.shtml#c"
    );
    areaElm.setAttribute("coords", "34,0,47,14");
    areaElm.setAttribute("alt", "c");
    areaElm.setAttribute("shape", "rect");
    mapNode.appendChild(areaElm);
  });
  await onReorder;

  tree = {
    IMAGE_MAP: [
      { role: ROLE_LINK, name: "a", children: [] },
      { role: ROLE_LINK, name: "b", children: [] },
      { role: ROLE_LINK, name: "c", children: [] },
    ],
  };
  testAccessibleTree(acc, tree);

  /* ================= Remove area ========================================== */
  onReorder = waitForEvent(EVENT_REORDER, id);
  await invokeContentTask(browser, [], () => {
    let mapNode = content.document.getElementById("map");
    mapNode.removeChild(mapNode.firstElementChild);
  });
  await onReorder;

  tree = {
    IMAGE_MAP: [
      { role: ROLE_LINK, name: "b", children: [] },
      { role: ROLE_LINK, name: "c", children: [] },
    ],
  };
  testAccessibleTree(acc, tree);
}

async function testContainer(browser) {
  const id = "container";
  /* ================= Remove name on map =================================== */
  let onReorder = waitForEvent(EVENT_REORDER, id);
  await invokeSetAttribute(browser, "map", "name");
  let event = await onReorder;
  const acc = event.accessible;

  let tree = {
    SECTION: [{ GRAPHIC: [] }],
  };
  testAccessibleTree(acc, tree);

  /* ================= Restore name on map ================================== */
  onReorder = waitForEvent(EVENT_REORDER, id);
  await invokeSetAttribute(browser, "map", "name", "atoz_map");
  // XXX: force repainting of the image (see bug 745788 for details).
  await invokeContentTask(browser, [], () => {
    const { ContentTaskUtils } = ChromeUtils.importESModule(
      "resource://testing-common/ContentTaskUtils.sys.mjs"
    );
    const EventUtils = ContentTaskUtils.getEventUtils(content);
    EventUtils.synthesizeMouse(
      content.document.getElementById("imgmap"),
      10,
      10,
      { type: "mousemove" },
      content
    );
  });
  await onReorder;

  tree = {
    SECTION: [
      {
        IMAGE_MAP: [{ LINK: [] }, { LINK: [] }],
      },
    ],
  };
  testAccessibleTree(acc, tree);

  /* ================= Remove map =========================================== */
  onReorder = waitForEvent(EVENT_REORDER, id);
  await invokeContentTask(browser, [], () => {
    let mapNode = content.document.getElementById("map");
    mapNode.remove();
  });
  await onReorder;

  tree = {
    SECTION: [{ GRAPHIC: [] }],
  };
  testAccessibleTree(acc, tree);

  /* ================= Insert map =========================================== */
  onReorder = waitForEvent(EVENT_REORDER, id);
  await invokeContentTask(browser, [id], contentId => {
    let map = content.document.createElement("map");
    let area = content.document.createElement("area");

    map.setAttribute("name", "atoz_map");
    map.setAttribute("id", "map");

    // eslint-disable-next-line @microsoft/sdl/no-insecure-url
    area.setAttribute("href", "http://www.bbc.co.uk/radio4/atoz/index.shtml#b");
    area.setAttribute("coords", "17,0,30,14");
    area.setAttribute("alt", "b");
    area.setAttribute("shape", "rect");

    map.appendChild(area);
    content.document.getElementById(contentId).appendChild(map);
  });
  await onReorder;

  tree = {
    SECTION: [
      {
        IMAGE_MAP: [{ LINK: [] }],
      },
    ],
  };
  testAccessibleTree(acc, tree);

  /* ================= Hide image map ======================================= */
  onReorder = waitForEvent(EVENT_REORDER, id);
  await invokeSetStyle(browser, "imgmap", "display", "none");
  await onReorder;

  tree = {
    SECTION: [],
  };
  testAccessibleTree(acc, tree);
}

addAccessibleTask(
  "e10s/doc_treeupdate_imagemap.html",
  async function (browser, accDoc) {
    await waitForImageMap(browser, accDoc);
    await testImageMap(browser, accDoc);
    await testContainer(browser);
  },
  { iframe: true, remoteIframe: true }
);