Source code
Revision control
Copy as Markdown
Other Tools
Test Info: Warnings
- This test gets skipped with pattern: os == 'android'
- Manifest: devtools/client/shared/test/xpcshell/xpcshell.toml
/* Any copyright is dedicated to the Public Domain.
"use strict";
// Test parseAttribute from node-attribute-parser.js
const {
parseAttribute,
} = require("resource://devtools/client/shared/node-attribute-parser.js");
const TEST_DATA = [
{
tagName: "body",
attributeName: "class",
attributeValue: "some css class names",
expected: [{ value: "some css class names", type: "string" }],
},
{
tagName: "box",
namespaceURI:
attributeName: "datasources",
expected: [
{ value: "/url/1?test=1#test", type: "uri" },
{ value: " ", type: "string" },
],
},
{
tagName: "form",
attributeName: "action",
attributeValue: "/path/to/handler",
expected: [{ value: "/path/to/handler", type: "uri" }],
},
{
tagName: "a",
attributeName: "ping",
attributeValue:
expected: [
{ value: " ", type: "string" },
],
},
{
tagName: "link",
attributeName: "href",
attributeValue: "styles.css",
otherAttributes: [{ name: "rel", value: "stylesheet" }],
expected: [{ value: "styles.css", type: "cssresource" }],
},
{
tagName: "link",
attributeName: "href",
attributeValue: "styles.css",
expected: [{ value: "styles.css", type: "uri" }],
},
{
tagName: "output",
attributeName: "for",
attributeValue: "element-id something id",
expected: [
{ value: "element-id", type: "idref" },
{ value: " ", type: "string" },
{ value: "something", type: "idref" },
{ value: " ", type: "string" },
{ value: "id", type: "idref" },
],
},
{
tagName: "img",
attributeName: "contextmenu",
attributeValue: "id-of-menu",
expected: [{ value: "id-of-menu", type: "idref" }],
},
{
tagName: "img",
attributeName: "src",
attributeValue: "omg-thats-so-funny.gif",
expected: [{ value: "omg-thats-so-funny.gif", type: "uri" }],
},
{
tagName: "key",
namespaceURI:
attributeName: "command",
attributeValue: "some_command_id",
expected: [{ value: "some_command_id", type: "idref" }],
},
{
tagName: "script",
namespaceURI: "whatever",
attributeName: "src",
attributeValue: "script.js",
expected: [{ value: "script.js", type: "jsresource" }],
},
];
function run_test() {
for (const {
tagName,
namespaceURI,
attributeName,
otherAttributes,
attributeValue,
expected,
} of TEST_DATA) {
info(
"Testing <" + tagName + " " + attributeName + "='" + attributeValue + "'>"
);
const attributes = [
...(otherAttributes || []),
{ name: attributeName, value: attributeValue },
];
const tokens = parseAttribute(
namespaceURI,
tagName,
attributes,
attributeName,
attributeValue
);
if (!expected) {
Assert.ok(!tokens);
continue;
}
info("Checking that the number of parsed tokens is correct");
Assert.equal(tokens.length, expected.length);
for (let i = 0; i < tokens.length; i++) {
info("Checking the data in token " + i);
Assert.equal(tokens[i].value, expected[i].value);
Assert.equal(tokens[i].type, expected[i].type);
}
}
}