Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(94)

Side by Side Diff: headless/public/util/dom_tree_extractor_browsertest.cc

Issue 2455613002: Fix index used to join results of DOM.getDocument and CSS.getLayoutTreeAndStyles (Closed)
Patch Set: Created 4 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "headless/public/util/dom_tree_extractor.h" 5 #include "headless/public/util/dom_tree_extractor.h"
6 6
7 #include <memory> 7 #include <memory>
8 #include "base/json/json_writer.h" 8 #include "base/json/json_writer.h"
9 #include "base/strings/string_util.h" 9 #include "base/strings/string_util.h"
10 #include "content/public/browser/render_widget_host_view.h" 10 #include "content/public/browser/render_widget_host_view.h"
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after
95 } 95 }
96 96
97 if (dom_nodes[i]->GetString("documentURL", &url)) { 97 if (dom_nodes[i]->GetString("documentURL", &url)) {
98 dom_nodes[i]->SetString( 98 dom_nodes[i]->SetString(
99 "documentURL", GURL(url).ReplaceComponents(replace_port).spec()); 99 "documentURL", GURL(url).ReplaceComponents(replace_port).spec());
100 } 100 }
101 } 101 }
102 102
103 // Merge LayoutTreeNode data into the dictionaries. 103 // Merge LayoutTreeNode data into the dictionaries.
104 for (const css::LayoutTreeNode* layout_node : dom_tree.layout_tree_nodes_) { 104 for (const css::LayoutTreeNode* layout_node : dom_tree.layout_tree_nodes_) {
105 auto it = 105 auto it = dom_tree.node_id_to_index_.find(layout_node->GetNodeId());
106 dom_tree.node_id_to_index_.find(layout_node->GetBackendNodeId());
107 ASSERT_TRUE(it != dom_tree.node_id_to_index_.end()); 106 ASSERT_TRUE(it != dom_tree.node_id_to_index_.end());
108 107
109 base::DictionaryValue* node_dict = dom_nodes[it->second].get(); 108 base::DictionaryValue* node_dict = dom_nodes[it->second].get();
110 node_dict->Set("boundingBox", layout_node->GetBoundingBox()->Serialize()); 109 node_dict->Set("boundingBox", layout_node->GetBoundingBox()->Serialize());
111 110
112 if (layout_node->HasLayoutText()) 111 if (layout_node->HasLayoutText())
113 node_dict->SetString("layoutText", layout_node->GetLayoutText()); 112 node_dict->SetString("layoutText", layout_node->GetLayoutText());
114 113
115 if (layout_node->HasStyleIndex()) 114 if (layout_node->HasStyleIndex())
116 node_dict->SetInteger("styleIndex", layout_node->GetStyleIndex()); 115 node_dict->SetInteger("styleIndex", layout_node->GetStyleIndex());
(...skipping 18 matching lines...) Expand all
135 for (const auto& style_property : 134 for (const auto& style_property :
136 *dom_tree.computed_styles_[i]->GetProperties()) { 135 *dom_tree.computed_styles_[i]->GetProperties()) {
137 style->SetString(style_property->GetName(), style_property->GetValue()); 136 style->SetString(style_property->GetName(), style_property->GetValue());
138 } 137 }
139 computed_styles[i] = std::move(style); 138 computed_styles[i] = std::move(style);
140 } 139 }
141 140
142 const std::vector<std::string> expected_dom_nodes = { 141 const std::vector<std::string> expected_dom_nodes = {
143 "{\n" 142 "{\n"
144 " 'baseURL': 'http://127.0.0.1/dom_tree_test.html',\n" 143 " 'baseURL': 'http://127.0.0.1/dom_tree_test.html',\n"
144 " 'boundingBox': {\n"
145 " 'height': 600.0,\n"
146 " 'width': 800.0,\n"
147 " 'x': 0.0,\n"
148 " 'y': 0.0\n"
149 " },\n"
145 " 'childIndices': [ 1 ],\n" 150 " 'childIndices': [ 1 ],\n"
146 " 'documentURL': 'http://127.0.0.1/dom_tree_test.html',\n" 151 " 'documentURL': 'http://127.0.0.1/dom_tree_test.html',\n"
147 " 'localName': '',\n" 152 " 'localName': '',\n"
148 " 'nodeId': 1,\n" 153 " 'nodeId': 1,\n"
149 " 'nodeName': '#document',\n" 154 " 'nodeName': '#document',\n"
150 " 'nodeType': 9,\n" 155 " 'nodeType': 9,\n"
151 " 'nodeValue': '',\n" 156 " 'nodeValue': '',\n"
157 " 'styleIndex': 0,\n"
152 " 'xmlVersion': ''\n" 158 " 'xmlVersion': ''\n"
153 "}\n", 159 "}\n",
154 160
155 "{\n" 161 "{\n"
156 " 'attributes': [ ],\n" 162 " 'attributes': [ ],\n"
157 " 'childIndices': [ 2, 5 ],\n"
158 " 'frameId': '?',\n"
159 " 'localName': 'html',\n"
160 " 'nodeId': 2,\n"
161 " 'nodeName': 'HTML',\n"
162 " 'nodeType': 1,\n"
163 " 'nodeValue': ''\n"
164 "}\n",
165
166 "{\n"
167 " 'attributes': [ ],\n"
168 " 'boundingBox': {\n" 163 " 'boundingBox': {\n"
169 " 'height': 600.0,\n" 164 " 'height': 600.0,\n"
170 " 'width': 800.0,\n" 165 " 'width': 800.0,\n"
171 " 'x': 0.0,\n" 166 " 'x': 0.0,\n"
172 " 'y': 0.0\n" 167 " 'y': 0.0\n"
173 " },\n" 168 " },\n"
174 " 'childIndices': [ 3 ],\n" 169 " 'childIndices': [ 2, 5 ],\n"
175 " 'localName': 'head',\n" 170 " 'frameId': '?',\n"
176 " 'nodeId': 3,\n" 171 " 'localName': 'html',\n"
177 " 'nodeName': 'HEAD',\n" 172 " 'nodeId': 2,\n"
178 " 'nodeType': 1,\n" 173 " 'nodeName': 'HTML',\n"
179 " 'nodeValue': '',\n"
180 " 'styleIndex': 0\n"
181 "}\n",
182
183 "{\n"
184 " 'attributes': [ ],\n"
185 " 'boundingBox': {\n"
186 " 'height': 600.0,\n"
187 " 'width': 800.0,\n"
188 " 'x': 0.0,\n"
189 " 'y': 0.0\n"
190 " },\n"
191 " 'childIndices': [ 4 ],\n"
192 " 'localName': 'title',\n"
193 " 'nodeId': 4,\n"
194 " 'nodeName': 'TITLE',\n"
195 " 'nodeType': 1,\n" 174 " 'nodeType': 1,\n"
196 " 'nodeValue': '',\n" 175 " 'nodeValue': '',\n"
197 " 'styleIndex': 1\n" 176 " 'styleIndex': 1\n"
198 "}\n", 177 "}\n",
199 178
200 "{\n" 179 "{\n"
180 " 'attributes': [ ],\n"
181 " 'childIndices': [ 3 ],\n"
182 " 'localName': 'head',\n"
183 " 'nodeId': 3,\n"
184 " 'nodeName': 'HEAD',\n"
185 " 'nodeType': 1,\n"
186 " 'nodeValue': ''\n"
187 "}\n",
188
189 "{\n"
190 " 'attributes': [ ],\n"
191 " 'childIndices': [ 4 ],\n"
192 " 'localName': 'title',\n"
193 " 'nodeId': 4,\n"
194 " 'nodeName': 'TITLE',\n"
195 " 'nodeType': 1,\n"
196 " 'nodeValue': ''\n"
197 "}\n",
198
199 "{\n"
200 " 'localName': '',\n"
201 " 'nodeId': 5,\n"
202 " 'nodeName': '#text',\n"
203 " 'nodeType': 3,\n"
204 " 'nodeValue': 'Hello world!'\n"
205 "}\n",
206
207 "{\n"
208 " 'attributes': [ ],\n"
201 " 'boundingBox': {\n" 209 " 'boundingBox': {\n"
202 " 'height': 584.0,\n" 210 " 'height': 584.0,\n"
203 " 'width': 784.0,\n" 211 " 'width': 784.0,\n"
204 " 'x': 8.0,\n" 212 " 'x': 8.0,\n"
205 " 'y': 8.0\n" 213 " 'y': 8.0\n"
206 " },\n"
207 " 'localName': '',\n"
208 " 'nodeId': 5,\n"
209 " 'nodeName': '#text',\n"
210 " 'nodeType': 3,\n"
211 " 'nodeValue': 'Hello world!',\n"
212 " 'styleIndex': 2\n"
213 "}\n",
214
215 "{\n"
216 " 'attributes': [ ],\n"
217 " 'boundingBox': {\n"
218 " 'height': 367.0,\n"
219 " 'width': 784.0,\n"
220 " 'x': 8.0,\n"
221 " 'y': 8.0\n"
222 " },\n" 214 " },\n"
223 " 'childIndices': [ 6 ],\n" 215 " 'childIndices': [ 6 ],\n"
224 " 'localName': 'body',\n" 216 " 'localName': 'body',\n"
225 " 'nodeId': 6,\n" 217 " 'nodeId': 6,\n"
226 " 'nodeName': 'BODY',\n" 218 " 'nodeName': 'BODY',\n"
227 " 'nodeType': 1,\n" 219 " 'nodeType': 1,\n"
228 " 'nodeValue': '',\n" 220 " 'nodeValue': '',\n"
229 " 'styleIndex': 1\n" 221 " 'styleIndex': 2\n"
230 "}\n", 222 "}\n",
231 223
232 "{\n" 224 "{\n"
233 " 'attributes': [ 'id', 'id1' ],\n" 225 " 'attributes': [ 'id', 'id1' ],\n"
234 " 'boundingBox': {\n" 226 " 'boundingBox': {\n"
235 " 'height': 37.0,\n" 227 " 'height': 367.0,\n"
236 " 'width': 784.0,\n" 228 " 'width': 784.0,\n"
237 " 'x': 8.0,\n" 229 " 'x': 8.0,\n"
238 " 'y': 8.0\n" 230 " 'y': 8.0\n"
239 " },\n" 231 " },\n"
240 " 'childIndices': [ 7, 9, 16 ],\n" 232 " 'childIndices': [ 7, 9, 16 ],\n"
241 " 'localName': 'div',\n" 233 " 'localName': 'div',\n"
242 " 'nodeId': 7,\n" 234 " 'nodeId': 7,\n"
243 " 'nodeName': 'DIV',\n" 235 " 'nodeName': 'DIV',\n"
244 " 'nodeType': 1,\n" 236 " 'nodeType': 1,\n"
245 " 'nodeValue': '',\n" 237 " 'nodeValue': '',\n"
238 " 'styleIndex': 1\n"
239 "}\n",
240
241 "{\n"
242 " 'attributes': [ 'style', 'color: red' ],\n"
243 " 'boundingBox': {\n"
244 " 'height': 37.0,\n"
245 " 'width': 784.0,\n"
246 " 'x': 8.0,\n"
247 " 'y': 8.0\n"
248 " },\n"
249 " 'childIndices': [ 8 ],\n"
250 " 'localName': 'h1',\n"
251 " 'nodeId': 8,\n"
252 " 'nodeName': 'H1',\n"
253 " 'nodeType': 1,\n"
254 " 'nodeValue': '',\n"
246 " 'styleIndex': 3\n" 255 " 'styleIndex': 3\n"
247 "}\n", 256 "}\n",
248 257
249 "{\n" 258 "{\n"
250 " 'attributes': [ 'style', 'color: red' ],\n"
251 " 'boundingBox': {\n" 259 " 'boundingBox': {\n"
252 " 'height': 36.0,\n" 260 " 'height': 36.0,\n"
253 " 'width': 143.0,\n" 261 " 'width': 143.0,\n"
254 " 'x': 8.0,\n" 262 " 'x': 8.0,\n"
255 " 'y': 8.0\n" 263 " 'y': 8.0\n"
256 " },\n" 264 " },\n"
257 " 'childIndices': [ 8 ],\n"
258 " 'inlineTextNodes': [ {\n" 265 " 'inlineTextNodes': [ {\n"
259 " 'boundingBox': {\n" 266 " 'boundingBox': {\n"
260 " 'height': 36.0,\n" 267 " 'height': 36.0,\n"
261 " 'width': 142.171875,\n" 268 " 'width': 142.171875,\n"
262 " 'x': 8.0,\n" 269 " 'x': 8.0,\n"
263 " 'y': 8.0\n" 270 " 'y': 8.0\n"
264 " },\n" 271 " },\n"
265 " 'numCharacters': 10,\n" 272 " 'numCharacters': 10,\n"
266 " 'startCharacterIndex': 0\n" 273 " 'startCharacterIndex': 0\n"
267 " } ],\n" 274 " } ],\n"
268 " 'layoutText': 'Some text.',\n" 275 " 'layoutText': 'Some text.',\n"
269 " 'localName': 'h1',\n"
270 " 'nodeId': 8,\n"
271 " 'nodeName': 'H1',\n"
272 " 'nodeType': 1,\n"
273 " 'nodeValue': '',\n"
274 " 'styleIndex': 3\n"
275 "}\n",
276
277 "{\n"
278 " 'boundingBox': {\n"
279 " 'height': 200.0,\n"
280 " 'width': 400.0,\n"
281 " 'x': 10.0,\n"
282 " 'y': 68.0\n"
283 " },\n"
284 " 'localName': '',\n" 276 " 'localName': '',\n"
285 " 'nodeId': 9,\n" 277 " 'nodeId': 9,\n"
286 " 'nodeName': '#text',\n" 278 " 'nodeName': '#text',\n"
287 " 'nodeType': 3,\n" 279 " 'nodeType': 3,\n"
288 " 'nodeValue': 'Some text.',\n" 280 " 'nodeValue': 'Some text.',\n"
289 " 'styleIndex': 1\n" 281 " 'styleIndex': 3\n"
290 "}\n", 282 "}\n",
291 283
292 "{\n" 284 "{\n"
293 " 'attributes': [ 'src', '/iframe.html', 'width', '400', 'height', " 285 " 'attributes': [ 'src', '/iframe.html', 'width', '400', 'height', "
294 "'200' ],\n" 286 "'200' ],\n"
295 " 'boundingBox': {\n" 287 " 'boundingBox': {\n"
296 " 'height': 171.0,\n" 288 " 'height': 205.0,\n"
297 " 'width': 384.0,\n" 289 " 'width': 404.0,\n"
298 " 'x': 18.0,\n" 290 " 'x': 8.0,\n"
299 " 'y': 76.0\n" 291 " 'y': 66.0\n"
300 " },\n" 292 " },\n"
301 " 'childIndices': [ ],\n" 293 " 'childIndices': [ ],\n"
302 " 'contentDocumentIndex': 10,\n" 294 " 'contentDocumentIndex': 10,\n"
303 " 'frameId': '?',\n" 295 " 'frameId': '?',\n"
304 " 'localName': 'iframe',\n" 296 " 'localName': 'iframe',\n"
305 " 'nodeId': 10,\n" 297 " 'nodeId': 10,\n"
306 " 'nodeName': 'IFRAME',\n" 298 " 'nodeName': 'IFRAME',\n"
307 " 'nodeType': 1,\n" 299 " 'nodeType': 1,\n"
308 " 'nodeValue': '',\n" 300 " 'nodeValue': '',\n"
309 " 'styleIndex': 2\n" 301 " 'styleIndex': 5\n"
310 "}\n", 302 "}\n",
311 303
312 "{\n" 304 "{\n"
313 " 'baseURL': 'http://127.0.0.1/iframe.html',\n" 305 " 'baseURL': 'http://127.0.0.1/iframe.html',\n"
314 " 'boundingBox': {\n"
315 " 'height': 37.0,\n"
316 " 'width': 384.0,\n"
317 " 'x': 18.0,\n"
318 " 'y': 76.0\n"
319 " },\n"
320 " 'childIndices': [ 11 ],\n" 306 " 'childIndices': [ 11 ],\n"
321 " 'documentURL': 'http://127.0.0.1/iframe.html',\n" 307 " 'documentURL': 'http://127.0.0.1/iframe.html',\n"
322 " 'localName': '',\n" 308 " 'localName': '',\n"
323 " 'nodeId': 11,\n" 309 " 'nodeId': 11,\n"
324 " 'nodeName': '#document',\n" 310 " 'nodeName': '#document',\n"
325 " 'nodeType': 9,\n" 311 " 'nodeType': 9,\n"
326 " 'nodeValue': '',\n" 312 " 'nodeValue': '',\n"
327 " 'styleIndex': 4,\n"
328 " 'xmlVersion': ''\n" 313 " 'xmlVersion': ''\n"
329 "}\n", 314 "}\n",
330 315
331 "{\n" 316 "{\n"
332 " 'attributes': [ ],\n" 317 " 'attributes': [ ],\n"
333 " 'boundingBox': {\n" 318 " 'boundingBox': {\n"
334 " 'height': 36.0,\n" 319 " 'height': 200.0,\n"
335 " 'width': 308.0,\n" 320 " 'width': 400.0,\n"
336 " 'x': 8.0,\n" 321 " 'x': 10.0,\n"
337 " 'y': 8.0\n" 322 " 'y': 68.0\n"
338 " },\n" 323 " },\n"
339 " 'childIndices': [ 12, 13 ],\n" 324 " 'childIndices': [ 12, 13 ],\n"
340 " 'frameId': '?',\n" 325 " 'frameId': '?',\n"
341 " 'inlineTextNodes': [ {\n"
342 " 'boundingBox': {\n"
343 " 'height': 36.0,\n"
344 " 'width': 307.734375,\n"
345 " 'x': 8.0,\n"
346 " 'y': 8.0\n"
347 " },\n"
348 " 'numCharacters': 22,\n"
349 " 'startCharacterIndex': 0\n"
350 " } ],\n"
351 " 'layoutText': 'Hello from the iframe!',\n"
352 " 'localName': 'html',\n" 326 " 'localName': 'html',\n"
353 " 'nodeId': 12,\n" 327 " 'nodeId': 12,\n"
354 " 'nodeName': 'HTML',\n" 328 " 'nodeName': 'HTML',\n"
355 " 'nodeType': 1,\n" 329 " 'nodeType': 1,\n"
356 " 'nodeValue': '',\n" 330 " 'nodeValue': '',\n"
357 " 'styleIndex': 4\n"
358 "}\n",
359
360 "{\n"
361 " 'attributes': [ ],\n"
362 " 'boundingBox': {\n"
363 " 'height': 205.0,\n"
364 " 'width': 404.0,\n"
365 " 'x': 8.0,\n"
366 " 'y': 66.0\n"
367 " },\n"
368 " 'childIndices': [ ],\n"
369 " 'localName': 'head',\n"
370 " 'nodeId': 13,\n"
371 " 'nodeName': 'HEAD',\n"
372 " 'nodeType': 1,\n"
373 " 'nodeValue': '',\n"
374 " 'styleIndex': 5\n"
375 "}\n",
376
377 "{\n"
378 " 'attributes': [ ],\n"
379 " 'boundingBox': {\n"
380 " 'height': 0.0,\n"
381 " 'width': 0.0,\n"
382 " 'x': 0.0,\n"
383 " 'y': 0.0\n"
384 " },\n"
385 " 'childIndices': [ 14 ],\n"
386 " 'layoutText': '\\n',\n"
387 " 'localName': 'body',\n"
388 " 'nodeId': 14,\n"
389 " 'nodeName': 'BODY',\n"
390 " 'nodeType': 1,\n"
391 " 'nodeValue': '',\n"
392 " 'styleIndex': 1\n" 331 " 'styleIndex': 1\n"
393 "}\n", 332 "}\n",
394 333
395 "{\n" 334 "{\n"
396 " 'attributes': [ ],\n" 335 " 'attributes': [ ],\n"
336 " 'childIndices': [ ],\n"
337 " 'localName': 'head',\n"
338 " 'nodeId': 13,\n"
339 " 'nodeName': 'HEAD',\n"
340 " 'nodeType': 1,\n"
341 " 'nodeValue': ''\n"
342 "}\n",
343
344 "{\n"
345 " 'attributes': [ ],\n"
397 " 'boundingBox': {\n" 346 " 'boundingBox': {\n"
398 " 'height': 105.0,\n" 347 " 'height': 171.0,\n"
399 " 'width': 784.0,\n" 348 " 'width': 384.0,\n"
400 " 'x': 8.0,\n" 349 " 'x': 18.0,\n"
401 " 'y': 270.0\n" 350 " 'y': 76.0\n"
351 " },\n"
352 " 'childIndices': [ 14 ],\n"
353 " 'localName': 'body',\n"
354 " 'nodeId': 14,\n"
355 " 'nodeName': 'BODY',\n"
356 " 'nodeType': 1,\n"
357 " 'nodeValue': '',\n"
358 " 'styleIndex': 2\n"
359 "}\n",
360
361 "{\n"
362 " 'attributes': [ ],\n"
363 " 'boundingBox': {\n"
364 " 'height': 37.0,\n"
365 " 'width': 384.0,\n"
366 " 'x': 18.0,\n"
367 " 'y': 76.0\n"
402 " },\n" 368 " },\n"
403 " 'childIndices': [ 15 ],\n" 369 " 'childIndices': [ 15 ],\n"
404 " 'localName': 'h1',\n" 370 " 'localName': 'h1',\n"
405 " 'nodeId': 15,\n" 371 " 'nodeId': 15,\n"
406 " 'nodeName': 'H1',\n" 372 " 'nodeName': 'H1',\n"
407 " 'nodeType': 1,\n" 373 " 'nodeType': 1,\n"
408 " 'nodeValue': '',\n" 374 " 'nodeValue': '',\n"
409 " 'styleIndex': 1\n" 375 " 'styleIndex': 4\n"
410 "}\n", 376 "}\n",
411 377
412 "{\n" 378 "{\n"
413 " 'boundingBox': {\n" 379 " 'boundingBox': {\n"
414 " 'height': 105.0,\n" 380 " 'height': 36.0,\n"
415 " 'width': 784.0,\n" 381 " 'width': 308.0,\n"
416 " 'x': 8.0,\n" 382 " 'x': 8.0,\n"
417 " 'y': 270.0\n" 383 " 'y': 8.0\n"
418 " },\n" 384 " },\n"
385 " 'inlineTextNodes': [ {\n"
386 " 'boundingBox': {\n"
387 " 'height': 36.0,\n"
388 " 'width': 307.734375,\n"
389 " 'x': 8.0,\n"
390 " 'y': 8.0\n"
391 " },\n"
392 " 'numCharacters': 22,\n"
393 " 'startCharacterIndex': 0\n"
394 " } ],\n"
395 " 'layoutText': 'Hello from the iframe!',\n"
419 " 'localName': '',\n" 396 " 'localName': '',\n"
420 " 'nodeId': 16,\n" 397 " 'nodeId': 16,\n"
421 " 'nodeName': '#text',\n" 398 " 'nodeName': '#text',\n"
422 " 'nodeType': 3,\n" 399 " 'nodeType': 3,\n"
423 " 'nodeValue': 'Hello from the iframe!',\n" 400 " 'nodeValue': 'Hello from the iframe!',\n"
424 " 'styleIndex': 1\n" 401 " 'styleIndex': 4\n"
425 "}\n", 402 "}\n",
426 403
427 "{\n" 404 "{\n"
428 " 'attributes': [ 'id', 'id2' ],\n" 405 " 'attributes': [ 'id', 'id2' ],\n"
429 " 'boundingBox': {\n" 406 " 'boundingBox': {\n"
430 " 'height': 105.0,\n" 407 " 'height': 105.0,\n"
431 " 'width': 784.0,\n" 408 " 'width': 784.0,\n"
432 " 'x': 8.0,\n" 409 " 'x': 8.0,\n"
433 " 'y': 270.0\n" 410 " 'y': 270.0\n"
434 " },\n" 411 " },\n"
435 " 'childIndices': [ 17 ],\n" 412 " 'childIndices': [ 17 ],\n"
436 " 'localName': 'div',\n" 413 " 'localName': 'div',\n"
437 " 'nodeId': 17,\n" 414 " 'nodeId': 17,\n"
438 " 'nodeName': 'DIV',\n" 415 " 'nodeName': 'DIV',\n"
439 " 'nodeType': 1,\n" 416 " 'nodeType': 1,\n"
440 " 'nodeValue': '',\n" 417 " 'nodeValue': '',\n"
441 " 'styleIndex': 1\n" 418 " 'styleIndex': 1\n"
442 "}\n", 419 "}\n",
443 420
444 "{\n" 421 "{\n"
445 " 'attributes': [ 'id', 'id3' ],\n" 422 " 'attributes': [ 'id', 'id3' ],\n"
446 " 'boundingBox': {\n" 423 " 'boundingBox': {\n"
447 " 'height': 18.0,\n" 424 " 'height': 105.0,\n"
448 " 'width': 53.0,\n" 425 " 'width': 784.0,\n"
449 " 'x': 8.0,\n" 426 " 'x': 8.0,\n"
450 " 'y': 270.0\n" 427 " 'y': 270.0\n"
451 " },\n" 428 " },\n"
452 " 'childIndices': [ 18 ],\n" 429 " 'childIndices': [ 18 ],\n"
453 " 'localName': 'div',\n" 430 " 'localName': 'div',\n"
454 " 'nodeId': 18,\n" 431 " 'nodeId': 18,\n"
455 " 'nodeName': 'DIV',\n" 432 " 'nodeName': 'DIV',\n"
456 " 'nodeType': 1,\n" 433 " 'nodeType': 1,\n"
457 " 'nodeValue': '',\n" 434 " 'nodeValue': '',\n"
435 " 'styleIndex': 1\n"
436 "}\n",
437
438 "{\n"
439 " 'attributes': [ 'id', 'id4' ],\n"
440 " 'boundingBox': {\n"
441 " 'height': 105.0,\n"
442 " 'width': 784.0,\n"
443 " 'x': 8.0,\n"
444 " 'y': 270.0\n"
445 " },\n"
446 " 'childIndices': [ 19, 21, 23, 24 ],\n"
447 " 'localName': 'div',\n"
448 " 'nodeId': 19,\n"
449 " 'nodeName': 'DIV',\n"
450 " 'nodeType': 1,\n"
451 " 'nodeValue': '',\n"
452 " 'styleIndex': 1\n"
453 "}\n",
454
455 "{\n"
456 " 'attributes': [ 'href', 'https://www.google.com' ],\n"
457 " 'boundingBox': {\n"
458 " 'height': 18.0,\n"
459 " 'width': 53.0,\n"
460 " 'x': 8.0,\n"
461 " 'y': 270.0\n"
462 " },\n"
463 " 'childIndices': [ 20 ],\n"
464 " 'localName': 'a',\n"
465 " 'nodeId': 20,\n"
466 " 'nodeName': 'A',\n"
467 " 'nodeType': 1,\n"
468 " 'nodeValue': '',\n"
458 " 'styleIndex': 6\n" 469 " 'styleIndex': 6\n"
459 "}\n", 470 "}\n",
460 471
461 "{\n" 472 "{\n"
462 " 'attributes': [ 'id', 'id4' ],\n"
463 " 'boundingBox': {\n" 473 " 'boundingBox': {\n"
464 " 'height': 18.0,\n" 474 " 'height': 18.0,\n"
465 " 'width': 53.0,\n" 475 " 'width': 53.0,\n"
466 " 'x': 8.0,\n" 476 " 'x': 8.0,\n"
467 " 'y': 270.0\n" 477 " 'y': 270.0\n"
468 " },\n" 478 " },\n"
469 " 'childIndices': [ 19, 21, 23, 24 ],\n"
470 " 'inlineTextNodes': [ {\n" 479 " 'inlineTextNodes': [ {\n"
471 " 'boundingBox': {\n" 480 " 'boundingBox': {\n"
472 " 'height': 17.0,\n" 481 " 'height': 17.0,\n"
473 " 'width': 52.421875,\n" 482 " 'width': 52.421875,\n"
474 " 'x': 8.0,\n" 483 " 'x': 8.0,\n"
475 " 'y': 270.4375\n" 484 " 'y': 270.4375\n"
476 " },\n" 485 " },\n"
477 " 'numCharacters': 7,\n" 486 " 'numCharacters': 7,\n"
478 " 'startCharacterIndex': 0\n" 487 " 'startCharacterIndex': 0\n"
479 " } ],\n" 488 " } ],\n"
480 " 'layoutText': 'Google!',\n" 489 " 'layoutText': 'Google!',\n"
481 " 'localName': 'div',\n" 490 " 'localName': '',\n"
482 " 'nodeId': 19,\n" 491 " 'nodeId': 21,\n"
483 " 'nodeName': 'DIV',\n" 492 " 'nodeName': '#text',\n"
484 " 'nodeType': 1,\n" 493 " 'nodeType': 3,\n"
485 " 'nodeValue': '',\n" 494 " 'nodeValue': 'Google!',\n"
486 " 'styleIndex': 6\n" 495 " 'styleIndex': 6\n"
487 "}\n", 496 "}\n",
488 497
489 "{\n" 498 "{\n"
490 " 'attributes': [ 'href', 'https://www.google.com' ],\n" 499 " 'attributes': [ ],\n"
491 " 'boundingBox': {\n"
492 " 'height': 0.0,\n"
493 " 'width': 0.0,\n"
494 " 'x': 0.0,\n"
495 " 'y': 0.0\n"
496 " },\n"
497 " 'childIndices': [ 20 ],\n"
498 " 'layoutText': '\\n ',\n"
499 " 'localName': 'a',\n"
500 " 'nodeId': 20,\n"
501 " 'nodeName': 'A',\n"
502 " 'nodeType': 1,\n"
503 " 'nodeValue': '',\n"
504 " 'styleIndex': 1\n"
505 "}\n",
506
507 "{\n"
508 " 'boundingBox': {\n" 500 " 'boundingBox': {\n"
509 " 'height': 19.0,\n" 501 " 'height': 19.0,\n"
510 " 'width': 784.0,\n" 502 " 'width': 784.0,\n"
511 " 'x': 8.0,\n" 503 " 'x': 8.0,\n"
512 " 'y': 304.0\n" 504 " 'y': 304.0\n"
513 " },\n" 505 " },\n"
514 " 'localName': '',\n" 506 " 'childIndices': [ 22 ],\n"
515 " 'nodeId': 21,\n" 507 " 'localName': 'p',\n"
516 " 'nodeName': '#text',\n" 508 " 'nodeId': 22,\n"
517 " 'nodeType': 3,\n" 509 " 'nodeName': 'P',\n"
518 " 'nodeValue': 'Google!',\n" 510 " 'nodeType': 1,\n"
511 " 'nodeValue': '',\n"
519 " 'styleIndex': 7\n" 512 " 'styleIndex': 7\n"
520 "}\n", 513 "}\n",
521 514
522 "{\n" 515 "{\n"
523 " 'attributes': [ ],\n"
524 " 'boundingBox': {\n" 516 " 'boundingBox': {\n"
525 " 'height': 18.0,\n" 517 " 'height': 18.0,\n"
526 " 'width': 85.0,\n" 518 " 'width': 85.0,\n"
527 " 'x': 8.0,\n" 519 " 'x': 8.0,\n"
528 " 'y': 304.0\n" 520 " 'y': 304.0\n"
529 " },\n" 521 " },\n"
530 " 'childIndices': [ 22 ],\n"
531 " 'inlineTextNodes': [ {\n" 522 " 'inlineTextNodes': [ {\n"
532 " 'boundingBox': {\n" 523 " 'boundingBox': {\n"
533 " 'height': 17.0,\n" 524 " 'height': 17.0,\n"
534 " 'width': 84.84375,\n" 525 " 'width': 84.84375,\n"
535 " 'x': 8.0,\n" 526 " 'x': 8.0,\n"
536 " 'y': 304.4375\n" 527 " 'y': 304.4375\n"
537 " },\n" 528 " },\n"
538 " 'numCharacters': 12,\n" 529 " 'numCharacters': 12,\n"
539 " 'startCharacterIndex': 0\n" 530 " 'startCharacterIndex': 0\n"
540 " } ],\n" 531 " } ],\n"
541 " 'layoutText': 'A paragraph!',\n" 532 " 'layoutText': 'A paragraph!',\n"
542 " 'localName': 'p',\n" 533 " 'localName': '',\n"
543 " 'nodeId': 22,\n" 534 " 'nodeId': 23,\n"
544 " 'nodeName': 'P',\n" 535 " 'nodeName': '#text',\n"
545 " 'nodeType': 1,\n" 536 " 'nodeType': 3,\n"
546 " 'nodeValue': '',\n" 537 " 'nodeValue': 'A paragraph!',\n"
547 " 'styleIndex': 7\n" 538 " 'styleIndex': 7\n"
548 "}\n", 539 "}\n",
549 540
550 "{\n" 541 "{\n"
542 " 'attributes': [ ],\n"
551 " 'boundingBox': {\n" 543 " 'boundingBox': {\n"
552 " 'height': 0.0,\n" 544 " 'height': 0.0,\n"
553 " 'width': 0.0,\n" 545 " 'width': 0.0,\n"
554 " 'x': 0.0,\n" 546 " 'x': 0.0,\n"
555 " 'y': 0.0\n" 547 " 'y': 0.0\n"
556 " },\n" 548 " },\n"
549 " 'childIndices': [ ],\n"
557 " 'inlineTextNodes': [ {\n" 550 " 'inlineTextNodes': [ {\n"
558 " 'boundingBox': {\n" 551 " 'boundingBox': {\n"
559 " 'height': 17.0,\n" 552 " 'height': 17.0,\n"
560 " 'width': 0.0,\n" 553 " 'width': 0.0,\n"
561 " 'x': 8.0,\n" 554 " 'x': 8.0,\n"
562 " 'y': 338.4375\n" 555 " 'y': 338.4375\n"
563 " },\n" 556 " },\n"
564 " 'numCharacters': 1,\n" 557 " 'numCharacters': 1,\n"
565 " 'startCharacterIndex': 0\n" 558 " 'startCharacterIndex': 0\n"
566 " } ],\n" 559 " } ],\n"
567 " 'layoutText': '\\n',\n" 560 " 'layoutText': '\\n',\n"
568 " 'localName': '',\n" 561 " 'localName': 'br',\n"
569 " 'nodeId': 23,\n" 562 " 'nodeId': 24,\n"
570 " 'nodeName': '#text',\n" 563 " 'nodeName': 'BR',\n"
571 " 'nodeType': 3,\n" 564 " 'nodeType': 1,\n"
572 " 'nodeValue': 'A paragraph!',\n" 565 " 'nodeValue': '',\n"
573 " 'styleIndex': 5\n" 566 " 'styleIndex': 5\n"
574 "}\n", 567 "}\n",
575 568
576 "{\n" 569 "{\n"
577 " 'attributes': [ ],\n" 570 " 'attributes': [ 'style', 'color: green' ],\n"
578 " 'boundingBox': {\n" 571 " 'boundingBox': {\n"
579 " 'height': 19.0,\n" 572 " 'height': 19.0,\n"
580 " 'width': 784.0,\n" 573 " 'width': 784.0,\n"
581 " 'x': 8.0,\n" 574 " 'x': 8.0,\n"
582 " 'y': 356.0\n" 575 " 'y': 356.0\n"
583 " },\n" 576 " },\n"
584 " 'childIndices': [ ],\n" 577 " 'childIndices': [ 25, 26, 28 ],\n"
585 " 'localName': 'br',\n" 578 " 'localName': 'div',\n"
586 " 'nodeId': 24,\n" 579 " 'nodeId': 25,\n"
587 " 'nodeName': 'BR',\n" 580 " 'nodeName': 'DIV',\n"
588 " 'nodeType': 1,\n" 581 " 'nodeType': 1,\n"
589 " 'nodeValue': '',\n" 582 " 'nodeValue': '',\n"
590 " 'styleIndex': 8\n" 583 " 'styleIndex': 8\n"
591 "}\n", 584 "}\n",
592 585
593 "{\n" 586 "{\n"
594 " 'attributes': [ 'style', 'color: green' ],\n"
595 " 'boundingBox': {\n" 587 " 'boundingBox': {\n"
596 " 'height': 18.0,\n" 588 " 'height': 18.0,\n"
597 " 'width': 41.0,\n" 589 " 'width': 41.0,\n"
598 " 'x': 8.0,\n" 590 " 'x': 8.0,\n"
599 " 'y': 356.0\n" 591 " 'y': 356.0\n"
600 " },\n" 592 " },\n"
601 " 'childIndices': [ 25, 26, 28 ],\n"
602 " 'inlineTextNodes': [ {\n" 593 " 'inlineTextNodes': [ {\n"
603 " 'boundingBox': {\n" 594 " 'boundingBox': {\n"
604 " 'height': 17.0,\n" 595 " 'height': 17.0,\n"
605 " 'width': 40.4375,\n" 596 " 'width': 40.4375,\n"
606 " 'x': 8.0,\n" 597 " 'x': 8.0,\n"
607 " 'y': 356.4375\n" 598 " 'y': 356.4375\n"
608 " },\n" 599 " },\n"
609 " 'numCharacters': 5,\n" 600 " 'numCharacters': 5,\n"
610 " 'startCharacterIndex': 0\n" 601 " 'startCharacterIndex': 0\n"
611 " } ],\n" 602 " } ],\n"
612 " 'layoutText': 'Some ',\n" 603 " 'layoutText': 'Some ',\n"
613 " 'localName': 'div',\n"
614 " 'nodeId': 25,\n"
615 " 'nodeName': 'DIV',\n"
616 " 'nodeType': 1,\n"
617 " 'nodeValue': '',\n"
618 " 'styleIndex': 8\n"
619 "}\n",
620
621 "{\n"
622 " 'boundingBox': {\n"
623 " 'height': 18.0,\n"
624 " 'width': 37.0,\n"
625 " 'x': 48.0,\n"
626 " 'y': 356.0\n"
627 " },\n"
628 " 'localName': '',\n" 604 " 'localName': '',\n"
629 " 'nodeId': 26,\n" 605 " 'nodeId': 26,\n"
630 " 'nodeName': '#text',\n" 606 " 'nodeName': '#text',\n"
631 " 'nodeType': 3,\n" 607 " 'nodeType': 3,\n"
632 " 'nodeValue': 'Some ',\n" 608 " 'nodeValue': 'Some ',\n"
633 " 'styleIndex': 9\n" 609 " 'styleIndex': 8\n"
634 "}\n", 610 "}\n",
635 611
636 "{\n" 612 "{\n"
637 " 'attributes': [ ],\n" 613 " 'attributes': [ ],\n"
638 " 'boundingBox': {\n" 614 " 'boundingBox': {\n"
639 " 'height': 18.0,\n" 615 " 'height': 18.0,\n"
640 " 'width': 37.0,\n" 616 " 'width': 37.0,\n"
641 " 'x': 48.0,\n" 617 " 'x': 48.0,\n"
642 " 'y': 356.0\n" 618 " 'y': 356.0\n"
643 " },\n" 619 " },\n"
644 " 'childIndices': [ 27 ],\n" 620 " 'childIndices': [ 27 ],\n"
621 " 'localName': 'em',\n"
622 " 'nodeId': 27,\n"
623 " 'nodeName': 'EM',\n"
624 " 'nodeType': 1,\n"
625 " 'nodeValue': '',\n"
626 " 'styleIndex': 9\n"
627 "}\n",
628
629 "{\n"
630 " 'boundingBox': {\n"
631 " 'height': 18.0,\n"
632 " 'width': 37.0,\n"
633 " 'x': 48.0,\n"
634 " 'y': 356.0\n"
635 " },\n"
645 " 'inlineTextNodes': [ {\n" 636 " 'inlineTextNodes': [ {\n"
646 " 'boundingBox': {\n" 637 " 'boundingBox': {\n"
647 " 'height': 17.0,\n" 638 " 'height': 17.0,\n"
648 " 'width': 35.828125,\n" 639 " 'width': 35.828125,\n"
649 " 'x': 48.4375,\n" 640 " 'x': 48.4375,\n"
650 " 'y': 356.4375\n" 641 " 'y': 356.4375\n"
651 " },\n" 642 " },\n"
652 " 'numCharacters': 5,\n" 643 " 'numCharacters': 5,\n"
653 " 'startCharacterIndex': 0\n" 644 " 'startCharacterIndex': 0\n"
654 " } ],\n" 645 " } ],\n"
655 " 'layoutText': 'green',\n" 646 " 'layoutText': 'green',\n"
656 " 'localName': 'em',\n" 647 " 'localName': '',\n"
657 " 'nodeId': 27,\n" 648 " 'nodeId': 28,\n"
658 " 'nodeName': 'EM',\n" 649 " 'nodeName': '#text',\n"
659 " 'nodeType': 1,\n" 650 " 'nodeType': 3,\n"
660 " 'nodeValue': '',\n" 651 " 'nodeValue': 'green',\n"
661 " 'styleIndex': 9\n" 652 " 'styleIndex': 9\n"
662 "}\n", 653 "}\n",
663 654
664 "{\n" 655 "{\n"
665 " 'boundingBox': {\n" 656 " 'boundingBox': {\n"
666 " 'height': 18.0,\n" 657 " 'height': 18.0,\n"
667 " 'width': 41.0,\n" 658 " 'width': 41.0,\n"
668 " 'x': 84.0,\n" 659 " 'x': 84.0,\n"
669 " 'y': 356.0\n" 660 " 'y': 356.0\n"
670 " },\n" 661 " },\n"
671 " 'inlineTextNodes': [ {\n" 662 " 'inlineTextNodes': [ {\n"
672 " 'boundingBox': {\n" 663 " 'boundingBox': {\n"
673 " 'height': 17.0,\n" 664 " 'height': 17.0,\n"
674 " 'width': 39.984375,\n" 665 " 'width': 39.984375,\n"
675 " 'x': 84.265625,\n" 666 " 'x': 84.265625,\n"
676 " 'y': 356.4375\n" 667 " 'y': 356.4375\n"
677 " },\n" 668 " },\n"
678 " 'numCharacters': 8,\n" 669 " 'numCharacters': 8,\n"
679 " 'startCharacterIndex': 0\n" 670 " 'startCharacterIndex': 0\n"
680 " } ],\n" 671 " } ],\n"
681 " 'layoutText': ' text...',\n" 672 " 'layoutText': ' text...',\n"
682 " 'localName': '',\n" 673 " 'localName': '',\n"
683 " 'nodeId': 28,\n"
684 " 'nodeName': '#text',\n"
685 " 'nodeType': 3,\n"
686 " 'nodeValue': 'green',\n"
687 " 'styleIndex': 8\n"
688 "}\n",
689
690 "{\n"
691 " 'localName': '',\n"
692 " 'nodeId': 29,\n" 674 " 'nodeId': 29,\n"
693 " 'nodeName': '#text',\n" 675 " 'nodeName': '#text',\n"
694 " 'nodeType': 3,\n" 676 " 'nodeType': 3,\n"
695 " 'nodeValue': ' text...'\n" 677 " 'nodeValue': ' text...',\n"
678 " 'styleIndex': 8\n"
696 "}\n"}; 679 "}\n"};
697 680
698 EXPECT_EQ(expected_dom_nodes.size(), dom_nodes.size()); 681 EXPECT_EQ(expected_dom_nodes.size(), dom_nodes.size());
699 682
700 for (size_t i = 0; i < dom_nodes.size(); i++) { 683 for (size_t i = 0; i < dom_nodes.size(); i++) {
701 std::string result_json; 684 std::string result_json;
702 base::JSONWriter::WriteWithOptions( 685 base::JSONWriter::WriteWithOptions(
703 *dom_nodes[i], base::JSONWriter::OPTIONS_PRETTY_PRINT, &result_json); 686 *dom_nodes[i], base::JSONWriter::OPTIONS_PRETTY_PRINT, &result_json);
704 687
705 base::ReplaceChars(result_json, "\"", "'", &result_json); 688 base::ReplaceChars(result_json, "\"", "'", &result_json);
706 689
707 ASSERT_LT(i, expected_dom_nodes.size()); 690 ASSERT_LT(i, expected_dom_nodes.size());
708 EXPECT_EQ(expected_dom_nodes[i], result_json) << " Node # " << i; 691 EXPECT_EQ(expected_dom_nodes[i], result_json) << " Node # " << i;
709 } 692 }
710 693
711 const std::vector<std::string> expected_styles = { 694 const std::vector<std::string> expected_styles = {
712 "{\n" 695 "{\n\n}\n",
713 " 'color': '',\n"
714 " 'display': '',\n"
715 " 'font-style': '',\n"
716 " 'margin-bottom': '',\n"
717 " 'margin-left': '',\n"
718 " 'margin-right': '',\n"
719 " 'margin-top': ''\n"
720 "}\n",
721 696
722 "{\n" 697 "{\n"
723 " 'color': 'rgb(0, 0, 0)',\n" 698 " 'color': 'rgb(0, 0, 0)',\n"
724 " 'display': 'block',\n" 699 " 'display': 'block',\n"
725 " 'font-style': 'normal',\n" 700 " 'font-style': 'normal',\n"
726 " 'margin-bottom': '0px',\n" 701 " 'margin-bottom': '0px',\n"
727 " 'margin-left': '0px',\n" 702 " 'margin-left': '0px',\n"
728 " 'margin-right': '0px',\n" 703 " 'margin-right': '0px',\n"
729 " 'margin-top': '0px'\n" 704 " 'margin-top': '0px'\n"
730 "}\n", 705 "}\n",
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after
823 798
824 FinishAsynchronousTest(); 799 FinishAsynchronousTest();
825 } 800 }
826 801
827 std::unique_ptr<DomTreeExtractor> extractor_; 802 std::unique_ptr<DomTreeExtractor> extractor_;
828 }; 803 };
829 804
830 HEADLESS_ASYNC_DEVTOOLED_TEST_F(DomTreeExtractorBrowserTest); 805 HEADLESS_ASYNC_DEVTOOLED_TEST_F(DomTreeExtractorBrowserTest);
831 806
832 } // namespace headless 807 } // namespace headless
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698