summaryrefslogtreecommitdiffstats
path: root/devtools/client/inspector/markup/test/browser_markup_links_01.js
blob: 4ef3ba4b98b8fb83dc38aec29109a369ce29dfcc (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
/* vim: set ts=2 et sw=2 tw=80: */
/* Any copyright is dedicated to the Public Domain.
 http://creativecommons.org/publicdomain/zero/1.0/ */

"use strict";

// Tests that links are shown in attributes when the values (or part of the
// values) are URIs or pointers to IDs.

const TEST_URL = URL_ROOT + "doc_markup_links.html";

const TEST_DATA = [{
  selector: "link",
  attributes: [{
    attributeName: "href",
    links: [{type: "cssresource", value: "style.css"}]
  }]
}, {
  selector: "link[rel=icon]",
  attributes: [{
    attributeName: "href",
    links: [{type: "uri",
             value: "/media/img/firefox/favicon-196.223e1bcaf067.png"}]
  }]
}, {
  selector: "form",
  attributes: [{
    attributeName: "action",
    links: [{type: "uri", value: "/post_message"}]
  }]
}, {
  selector: "label[for=name]",
  attributes: [{
    attributeName: "for",
    links: [{type: "idref", value: "name"}]
  }]
}, {
  selector: "label[for=message]",
  attributes: [{
    attributeName: "for",
    links: [{type: "idref", value: "message"}]
  }]
}, {
  selector: "output",
  attributes: [{
    attributeName: "form",
    links: [{type: "idref", value: "message-form"}]
  }, {
    attributeName: "for",
    links: [
      {type: "idref", value: "name"},
      {type: "idref", value: "message"},
      {type: "idref", value: "invalid"}
    ]
  }]
}, {
  selector: "a",
  attributes: [{
    attributeName: "href",
    links: [{type: "uri", value: "/go/somewhere/else"}]
  }, {
    attributeName: "ping",
    links: [
      {type: "uri", value: "/analytics?page=pageA"},
      {type: "uri", value: "/analytics?user=test"}
    ]
  }]
}, {
  selector: "li[contextmenu=menu1]",
  attributes: [{
    attributeName: "contextmenu",
    links: [{type: "idref", value: "menu1"}]
  }]
}, {
  selector: "li[contextmenu=menu2]",
  attributes: [{
    attributeName: "contextmenu",
    links: [{type: "idref", value: "menu2"}]
  }]
}, {
  selector: "li[contextmenu=menu3]",
  attributes: [{
    attributeName: "contextmenu",
    links: [{type: "idref", value: "menu3"}]
  }]
}, {
  selector: "video",
  attributes: [{
    attributeName: "poster",
    links: [{type: "uri", value: "doc_markup_tooltip.png"}]
  }, {
    attributeName: "src",
    links: [{type: "uri", value: "code-rush.mp4"}]
  }]
}, {
  selector: "script",
  attributes: [{
    attributeName: "src",
    links: [{type: "jsresource", value: "lib_jquery_1.0.js"}]
  }]
}];

requestLongerTimeout(2);

add_task(function* () {
  let {inspector} = yield openInspectorForURL(TEST_URL);

  for (let {selector, attributes} of TEST_DATA) {
    info("Testing attributes on node " + selector);
    yield selectNode(selector, inspector);
    let {editor} = yield getContainerForSelector(selector, inspector);

    for (let {attributeName, links} of attributes) {
      info("Testing attribute " + attributeName);
      let linkEls = editor.attrElements.get(attributeName)
                                       .querySelectorAll(".link");

      is(linkEls.length, links.length, "The right number of links were found");

      for (let i = 0; i < links.length; i++) {
        is(linkEls[i].dataset.type, links[i].type,
           `Link ${i} has the right type`);
        is(linkEls[i].textContent, links[i].value,
           `Link ${i} has the right value`);
      }
    }
  }
});