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

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

Powered by Google App Engine
This is Rietveld 408576698