Commit a4406936 authored by Erik Hendriks's avatar Erik Hendriks Committed by Commit Bot

Add title and document content width/height to DOMSnapshot.captureSnapshot results.

Add a test to see that misc details are showing up ok. Also, make
stabilization of the string table in the pseudo element test more
robust.

Change-Id: I3e5500c8095f41e4dc15ce3d6181c9fa8c5d33a7
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1827180
Commit-Queue: Erik Hendriks <hendriks@chromium.org>
Reviewed-by: default avatarAndrey Kosyakov <caseq@chromium.org>
Cr-Commit-Position: refs/heads/master@{#701328}
parent ba0a4527
...@@ -2400,6 +2400,8 @@ experimental domain DOMSnapshot ...@@ -2400,6 +2400,8 @@ experimental domain DOMSnapshot
properties properties
# Document URL that `Document` or `FrameOwner` node points to. # Document URL that `Document` or `FrameOwner` node points to.
StringIndex documentURL StringIndex documentURL
# Document title.
StringIndex title
# Base URL that `Document` or `FrameOwner` node uses for URL completion. # Base URL that `Document` or `FrameOwner` node uses for URL completion.
StringIndex baseURL StringIndex baseURL
# Contains the document's content language. # Contains the document's content language.
...@@ -2422,6 +2424,10 @@ experimental domain DOMSnapshot ...@@ -2422,6 +2424,10 @@ experimental domain DOMSnapshot
optional number scrollOffsetX optional number scrollOffsetX
# Vertical scroll offset. # Vertical scroll offset.
optional number scrollOffsetY optional number scrollOffsetY
# Document content width.
optional number contentWidth
# Document content height.
optional number contentHeight
# Table containing nodes. # Table containing nodes.
type NodeTreeSnapshot extends object type NodeTreeSnapshot extends object
......
...@@ -324,6 +324,7 @@ void InspectorDOMSnapshotAgent::VisitDocument(Document* document) { ...@@ -324,6 +324,7 @@ void InspectorDOMSnapshotAgent::VisitDocument(Document* document) {
AddString(InspectorDOMAgent::DocumentURLString(document))) AddString(InspectorDOMAgent::DocumentURLString(document)))
.setBaseURL( .setBaseURL(
AddString(InspectorDOMAgent::DocumentBaseURLString(document))) AddString(InspectorDOMAgent::DocumentBaseURLString(document)))
.setTitle(AddString(document->title()))
.setContentLanguage(AddString(document->ContentLanguage())) .setContentLanguage(AddString(document->ContentLanguage()))
.setEncodingName(AddString(document->EncodingName())) .setEncodingName(AddString(document->EncodingName()))
.setFrameId( .setFrameId(
...@@ -373,6 +374,9 @@ void InspectorDOMSnapshotAgent::VisitDocument(Document* document) { ...@@ -373,6 +374,9 @@ void InspectorDOMSnapshotAgent::VisitDocument(Document* document) {
auto offset = document->View()->LayoutViewport()->GetScrollOffset(); auto offset = document->View()->LayoutViewport()->GetScrollOffset();
document_->setScrollOffsetX(offset.Width()); document_->setScrollOffsetX(offset.Width());
document_->setScrollOffsetY(offset.Height()); document_->setScrollOffsetY(offset.Height());
auto contents_size = document->View()->LayoutViewport()->ContentsSize();
document_->setContentWidth(contents_size.Width());
document_->setContentHeight(contents_size.Height());
} }
if (paint_order_map_) { if (paint_order_map_) {
......
Tests that DOMSnapshot.captureSnapshot fills document details: title, size, etc.
{
documents : [
[0] : {
baseURL : 1
contentHeight : 2000
contentLanguage : 3
contentWidth : 2000
documentURL : <number>
encodingName : 4
frameId : <number>
layout : {
bounds : [
[0] : [
[0] : 0
[1] : 0
[2] : 800
[3] : 600
]
[1] : [
[0] : 0
[1] : 0
[2] : 785
[3] : 2000
]
[2] : [
[0] : 0
[1] : 0
[2] : 785
[3] : 2000
]
[3] : [
[0] : 0
[1] : 0
[2] : 2000
[3] : 2000
]
[4] : [
[0] : 0
[1] : 0
[2] : 190
[3] : 10
]
]
nodeIndex : [
[0] : 0
[1] : 2
[2] : 15
[3] : 17
[4] : 18
]
stackingContexts : {
index : [
[0] : 0
[1] : 1
]
}
styles : [
[0] : [
]
[1] : [
]
[2] : [
]
[3] : [
]
[4] : [
]
]
text : [
[0] : -1
[1] : -1
[2] : -1
[3] : -1
[4] : 31
]
}
nodes : {
attributes : [
[0] : [
]
[1] : [
]
[2] : [
]
[3] : [
]
[4] : [
]
[5] : [
]
[6] : [
]
[7] : [
]
[8] : [
[0] : 16
[1] : 17
[2] : 18
[3] : 19
]
[9] : [
]
[10] : [
[0] : 16
[1] : 20
[2] : 18
[3] : 3
]
[11] : [
]
[12] : [
[0] : 22
[1] : 1
]
[13] : [
]
[14] : [
]
[15] : [
[0] : 25
[1] : 26
[2] : 27
[3] : 28
]
[16] : [
]
[17] : [
[0] : 25
[1] : 30
]
[18] : [
]
[19] : [
]
]
backendNodeId : <object>
contentDocumentIndex : {
index : [
]
value : [
]
}
currentSourceURL : {
index : [
]
value : [
]
}
inputChecked : {
index : [
]
}
inputValue : {
index : [
]
value : [
]
}
isClickable : {
index : [
]
}
nodeName : [
[0] : 8
[1] : 9
[2] : 10
[3] : 11
[4] : 12
[5] : 14
[6] : 12
[7] : 12
[8] : 15
[9] : 12
[10] : 15
[11] : 12
[12] : 21
[13] : 12
[14] : 12
[15] : 24
[16] : 12
[17] : 29
[18] : 12
[19] : 12
]
nodeType : [
[0] : 9
[1] : 10
[2] : 1
[3] : 1
[4] : 3
[5] : 1
[6] : 3
[7] : 3
[8] : 1
[9] : 3
[10] : 1
[11] : 3
[12] : 1
[13] : 3
[14] : 3
[15] : 1
[16] : 3
[17] : 1
[18] : 3
[19] : 3
]
nodeValue : [
[0] : -1
[1] : -1
[2] : -1
[3] : -1
[4] : 13
[5] : -1
[6] : 2
[7] : 13
[8] : -1
[9] : 13
[10] : -1
[11] : 13
[12] : -1
[13] : 23
[14] : 23
[15] : -1
[16] : 13
[17] : -1
[18] : 31
[19] : 32
]
optionSelected : {
index : [
]
}
originURL : {
index : [
]
value : [
]
}
parentIndex : [
[0] : -1
[1] : 0
[2] : 0
[3] : 2
[4] : 3
[5] : 3
[6] : 5
[7] : 3
[8] : 3
[9] : 3
[10] : 3
[11] : 3
[12] : 3
[13] : 3
[14] : 2
[15] : 2
[16] : 15
[17] : 15
[18] : 17
[19] : 15
]
pseudoType : {
index : [
]
value : [
]
}
textValue : {
index : [
]
value : [
]
}
}
publicId : 6
scrollOffsetX : 300
scrollOffsetY : 400
systemId : 7
textBoxes : {
bounds : [
[0] : [
[0] : 0
[1] : 0
[2] : 190
[3] : 10
]
]
layoutIndex : [
[0] : 4
]
length : [
[0] : 19
]
start : [
[0] : 7
]
}
title : 2
}
]
strings : [
[0] :
[1] : http://example.com/
[2] : Document Title
[3] : nl-NL
[4] : UTF-8
[5] :
[6] : -//W3C//DTD HTML 4.01//EN
[7] : http://www.w3.org/TR/html4/strict.dtd
[8] : #document
[9] : html
[10] : HTML
[11] : HEAD
[12] : #text
[13] :
[14] : TITLE
[15] : META
[16] : http-equiv
[17] : Content-Type
[18] : content
[19] : text/html; charset=utf-8
[20] : Content-Language
[21] : BASE
[22] : href
[23] :
[24] : BODY
[25] : style
[26] : margin: 0px
[27] : onload
[28] : window.scrollTo(300, 400)
[29] : DIV
[30] : width: 2000px; height: 2000px; font: 10px Ahem;
[31] : Een heel grote div.
[32] :
]
}
(async function(testRunner) {
var {page, session, dp} = await testRunner.startURL('../resources/dom-snapshot-captureSnapshot-details.html', 'Tests that DOMSnapshot.captureSnapshot fills document details: title, size, etc.');
var response = await dp.DOMSnapshot.captureSnapshot({computedStyles: []});
if (response.error) {
testRunner.log(response);
} else {
// Remove unstable strings from the string table.
response.result.strings[response.result.documents[0].documentURL] = '';
response.result.strings[response.result.documents[0].frameId] = '';
testRunner.log(
response.result, undefined,
['documentURL', 'frameId', 'backendNodeId']);
}
testRunner.completeTest();
})
...@@ -3,6 +3,7 @@ Tests DOMSnapshot.getSnapshot reports offset, scroll, and client rects of each n ...@@ -3,6 +3,7 @@ Tests DOMSnapshot.getSnapshot reports offset, scroll, and client rects of each n
"documents": [ "documents": [
{ {
"documentURL": 0, "documentURL": 0,
"title": -1,
"baseURL": 0, "baseURL": 0,
"contentLanguage": -1, "contentLanguage": -1,
"encodingName": 1, "encodingName": 1,
...@@ -116,7 +117,9 @@ Tests DOMSnapshot.getSnapshot reports offset, scroll, and client rects of each n ...@@ -116,7 +117,9 @@ Tests DOMSnapshot.getSnapshot reports offset, scroll, and client rects of each n
}, },
"textBoxes": "<object>", "textBoxes": "<object>",
"scrollOffsetX": 0, "scrollOffsetX": 0,
"scrollOffsetY": 0 "scrollOffsetY": 0,
"contentWidth": 800,
"contentHeight": 600
} }
], ],
"strings": "<object>" "strings": "<object>"
......
(async function(testRunner) { (async function(testRunner) {
var {page, session, dp} = await testRunner.startURL('../resources/dom-snapshot-pseudo-element.html', 'Tests DOMSnapshot.getSnapshot exports layout tree nodes associated with pseudo elements.'); var {page, session, dp} = await testRunner.startURL('../resources/dom-snapshot-pseudo-element.html', 'Tests DOMSnapshot.getSnapshot exports layout tree nodes associated with pseudo elements.');
function stabilize(key, value) {
var unstableKeys = ['documentURL', 'baseURL', 'frameId', 'backendNodeId'];
if (unstableKeys.indexOf(key) !== -1)
return '<' + typeof(value) + '>';
return value;
}
var response = await dp.DOMSnapshot.captureSnapshot({'computedStyles': ['font-weight', 'color'], 'includeEventListeners': true}); var response = await dp.DOMSnapshot.captureSnapshot({'computedStyles': ['font-weight', 'color'], 'includeEventListeners': true});
if (response.error) { if (response.error) {
testRunner.log(response); testRunner.log(response);
} else { } else {
response.result.strings[0] = ''; // Remove unstable strings from the string table.
response.result.strings[1] = ''; response.result.strings[response.result.documents[0].documentURL] = '';
response.result.strings[2] = ''; response.result.strings[response.result.documents[0].baseURL] = '';
testRunner.log(JSON.stringify(response.result, stabilize, 2)); response.result.strings[response.result.documents[0].frameId] = '';
testRunner.log(
response.result, undefined,
['documentURL', 'baseURL', 'frameId', 'backendNodeId']);
} }
testRunner.completeTest(); testRunner.completeTest();
}) })
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<title>Document Title</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta http-equiv="Content-Language" content="nl-NL">
<base href="http://example.com/">
</head>
<body style="margin: 0px" onload="window.scrollTo(300, 400)">
<div style="width: 2000px; height: 2000px; font: 10px Ahem;">
Een heel grote div.
</div>
</body>
</html>
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