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
|
const loadPromise = new Promise(resolve => { window.resolveLoadPromise = resolve; });
function assertURL(doc, expectedURL) {
assert_equals(doc.URL, expectedURL, "document.URL");
assert_equals(doc.documentURI, expectedURL, "document.documentURI");
assert_equals(doc.baseURI, expectedURL, "document.baseURI");
}
const supportedTypes = [
"text/html",
"text/xml",
"application/xml",
"application/xhtml+xml",
"image/svg+xml",
];
const invalidXML = `<span x:test="testing">1</span>`;
const inputs = {
valid: "<html></html>",
"invalid XML": invalidXML
};
for (const mimeType of supportedTypes) {
for (const [inputName, input] of Object.entries(inputs)) {
if (mimeType === "text/html" && input === invalidXML) {
continue;
}
test(() => {
const parser = new DOMParser();
const doc = parser.parseFromString(input, mimeType);
assertURL(doc, document.URL);
}, `${mimeType} ${inputName}: created normally`);
promise_test(async () => {
await loadPromise;
const parser = new frames[0].DOMParser();
const doc = parser.parseFromString(input, mimeType);
assertURL(doc, frames[0].document.URL);
}, `${mimeType} ${inputName}: created using another iframe's DOMParser from this frame`);
promise_test(async () => {
await loadPromise;
const parser = new frames[0].DOMParser();
const doc = frames[0].doParse(input, mimeType);
assertURL(doc, frames[0].document.URL);
}, `${mimeType} ${inputName}: created using another iframe's DOMParser from that frame`);
promise_test(async () => {
await loadPromise;
const parser = new DOMParser();
const doc = frames[0].DOMParser.prototype.parseFromString.call(parser, input, mimeType);
assertURL(doc, document.URL);
}, `${mimeType} ${inputName}: created using a parser from this frame and the method from the iframe`);
promise_test(async () => {
await loadPromise;
const parser = new frames[0].DOMParser();
const doc = DOMParser.prototype.parseFromString.call(parser, input, mimeType);
assertURL(doc, frames[0].document.URL);
}, `${mimeType} ${inputName}: created using a parser from the iframe and the method from this frame`);
}
}
|