Commit 79d9b268 authored by Erik Luo's avatar Erik Luo Committed by Commit Bot

DevTools: contentDocument should build with DOMDocument instead of DOMNode

Originally, payloads with 'contentDocument' created a new SDK.DOMDocument on
the frontend. When we prepared DevTools to render iframes inline [1], we
switched it to use SDK.DOMNode, which lacks
- isInShadowTree reset
- documentURL, baseURL

'contentDocument' differs from 'templates' and 'importedDocuments' in that the
latter two do not affect shadow tree/documentURL/baseURL.

[1] https://crrev.com/d16260bf91889bb7ead1fe490d087bc2ed02d58b

Bug: 836849
Change-Id: I9c242720c3d0c37bf8170b1b87d8b31a2f52d2ff
Reviewed-on: https://chromium-review.googlesource.com/1102156
Commit-Queue: Erik Luo <luoe@chromium.org>
Reviewed-by: default avatarDmitry Gozman <dgozman@chromium.org>
Cr-Commit-Position: refs/heads/master@{#570122}
parent 1242f8a4
Tests that nodes have correct baseURL, documentURL.
#document has no parent.
baseURL : http://127.0.0.1:8000/devtools/elements/
documentURL: http://127.0.0.1:8000/devtools/resources/inspected-page.html
#document has parent IFRAME.
baseURL : http://127.0.0.1:8000/devtools/elements/resources/elements-empty-iframe.html
documentURL: http://127.0.0.1:8000/devtools/elements/resources/elements-empty-iframe.html
// Copyright 2018 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
(async function() {
TestRunner.addResult(`Tests that nodes have correct baseURL, documentURL.\n`);
await TestRunner.loadModule('elements_test_runner');
await TestRunner.showPanel('elements');
await TestRunner.loadHTML(`
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
`);
await TestRunner.addIframe(`resources/elements-empty-iframe.html`);
ElementsTestRunner.expandElementsTree(step1);
async function step1() {
const innerMapping = TestRunner.domModel._idToDOMNode;
const docs = Object.values(innerMapping).filter(n => n instanceof SDK.DOMDocument);
for (const doc of docs) {
if (doc.parentNode)
TestRunner.addResult(`${doc.nodeName()} has parent ${doc.parentNode.nodeName()}.`);
else
TestRunner.addResult(`${doc.nodeName()} has no parent.`);
TestRunner.addResult(`baseURL : ${doc.baseURL}\ndocumentURL: ${doc.documentURL}\n`);
}
TestRunner.completeTest();
}
})();
Tests that src and href element targets are rewritten properly.
javascript:alert('foo')
http://127.0.0.1:8000/devtools/elements/script.js
http://127.0.0.1:8000/devtools/elements/stylesheet.css
http://127.0.0.1:8000/devtools/elements/target.html
http://127.0.0.1/script.js
http://127.0.0.1/stylesheet.css
http://127.0.0.1/target.html
......@@ -9,9 +9,17 @@
await TestRunner.loadHTML(`
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<a style="display:none" href=" javascript:alert('foo') "></a>
<script>
(function(){
let iframe = document.createElement('iframe');
iframe.src = "resources/elements-panel-rewrite-href-iframe.html";
document.body.appendChild(iframe);
window.frameLoadedPromise = new Promise(f => iframe.onload = f);
})();
</script>
`);
await TestRunner.addIframe('resources/elements-panel-rewrite-href-iframe.html');
await TestRunner.evaluateInPageAsync(`window.frameLoadedPromise`);
ElementsTestRunner.expandElementsTree(step1);
......
......@@ -112,7 +112,7 @@ SDK.DOMNode = class {
}
if (payload.contentDocument) {
this._contentDocument = SDK.DOMNode.create(this._domModel, this.ownerDocument, true, payload.contentDocument);
this._contentDocument = new SDK.DOMDocument(this._domModel, payload.contentDocument);
this._contentDocument.parentNode = this;
this._children = [];
} else if (payload.nodeName === 'IFRAME' && payload.frameId && Runtime.experiments.isEnabled('oopifInlineDOM')) {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment