summaryrefslogtreecommitdiffstats
path: root/accessible/tests/browser/e10s/browser_treeupdate_imagemap.js
blob: d299c0acb97c677134fa3b5bd1ffd5672b46d517 (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
/* 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';

/* global EVENT_REORDER, ROLE_LINK */

loadScripts({ name: 'role.js', dir: MOCHITESTS_DIR });

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);
  yield ContentTask.spawn(browser, {}, () => {
    let areaElm = content.document.createElement('area');
    let mapNode = content.document.getElementById('map');
    areaElm.setAttribute('href',
                         '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);
  });
  yield 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);
  yield ContentTask.spawn(browser, {}, () => {
    let areaElm = content.document.createElement('area');
    let mapNode = content.document.getElementById('map');
    areaElm.setAttribute('href',
                         '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);
  });
  yield 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);
  yield ContentTask.spawn(browser, {}, () => {
    let mapNode = content.document.getElementById('map');
    mapNode.removeChild(mapNode.firstElementChild);
  });
  yield onReorder;

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

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

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

  /* ================= Restore name on map ================================== */
  onReorder = waitForEvent(EVENT_REORDER, id);
  yield invokeSetAttribute(browser, 'map', 'name', 'atoz_map');
  // XXX: force repainting of the image (see bug 745788 for details).
  yield BrowserTestUtils.synthesizeMouse('#imgmap', 10, 10,
    { type: 'mousemove' }, browser);
  yield onReorder;

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

  /* ================= Remove map =========================================== */
  onReorder = waitForEvent(EVENT_REORDER, id);
  yield ContentTask.spawn(browser, {}, () => {
    let mapNode = content.document.getElementById('map');
    mapNode.parentNode.removeChild(mapNode);
  });
  yield onReorder;

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

  /* ================= Insert map =========================================== */
  onReorder = waitForEvent(EVENT_REORDER, id);
  yield ContentTask.spawn(browser, id, contentId => {
    let map = content.document.createElement('map');
    let area = content.document.createElement('area');

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

    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);
  });
  yield onReorder;

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

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

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

addAccessibleTask('doc_treeupdate_imagemap.html', function*(browser, accDoc) {
  yield testImageMap(browser, accDoc);
  yield testContainer(browser);
});