Commit 778c0bda authored by Andrey Lushnikov's avatar Andrey Lushnikov Committed by Commit Bot

DevTools: DOM.setOuterHTML should work for detached documents

This patch fixes two bugs with DOM.setOuterHTML protocol method:
1. The method didn't work when a document node was passed as an argument
2. The method didn't work when document's element was removed

BUG=724974
R=pfeldman

Change-Id: I4f5dd0d9151fd80328af422e9016f63a749b0cf3
Reviewed-on: https://chromium-review.googlesource.com/745325Reviewed-by: default avatarPavel Feldman <pfeldman@chromium.org>
Commit-Queue: Andrey Lushnikov <lushnikov@chromium.org>
Cr-Commit-Position: refs/heads/master@{#512750}
parent ae3c460c
Tests that setOuterHTML does not crash on detached document.
{
id : <number>
result : {
}
}
(async function(testRunner) {
var {page, session, dp} = await testRunner.startHTML(`
<div id="id">something</div> `, 'Tests that setOuterHTML does not crash on detached document.');
var message = await dp.DOM.getDocument();
await dp.Runtime.enable();
await dp.Runtime.evaluate({
expression: "document.documentElement.remove()"
});
var result = await dp.DOM.setOuterHTML({nodeId: message.result.root.nodeId, outerHTML: "<div>update</div>"});
testRunner.log(result);
testRunner.completeTest();
})
...@@ -32,6 +32,7 @@ ...@@ -32,6 +32,7 @@
#include "bindings/core/v8/ExceptionState.h" #include "bindings/core/v8/ExceptionState.h"
#include "core/dom/DOMException.h" #include "core/dom/DOMException.h"
#include "core/dom/Document.h"
#include "core/dom/Element.h" #include "core/dom/Element.h"
#include "core/dom/Node.h" #include "core/dom/Node.h"
#include "core/dom/Text.h" #include "core/dom/Text.h"
...@@ -234,9 +235,12 @@ class DOMEditor::SetOuterHTMLAction final : public InspectorHistory::Action { ...@@ -234,9 +235,12 @@ class DOMEditor::SetOuterHTMLAction final : public InspectorHistory::Action {
bool Perform(ExceptionState& exception_state) override { bool Perform(ExceptionState& exception_state) override {
old_html_ = CreateMarkup(node_.Get()); old_html_ = CreateMarkup(node_.Get());
DCHECK(node_->ownerDocument()); Document* document =
DOMPatchSupport dom_patch_support(dom_editor_.Get(), node_->IsDocumentNode() ? ToDocument(node_) : node_->ownerDocument();
*node_->ownerDocument()); DCHECK(document);
if (!document->documentElement())
return false;
DOMPatchSupport dom_patch_support(dom_editor_.Get(), *document);
new_node_ = new_node_ =
dom_patch_support.PatchNode(node_.Get(), html_, exception_state); dom_patch_support.PatchNode(node_.Get(), html_, exception_state);
return !exception_state.HadException(); return !exception_state.HadException();
......
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