From a5561785fb66f49c2b76557c6f6745eedb4d8b73 Mon Sep 17 00:00:00 2001 From: Lars-Dominik Braun Date: Sat, 17 Nov 2018 14:04:03 +0100 Subject: html: Add tests for tree walker --- crocoite/test_html.py | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/crocoite/test_html.py b/crocoite/test_html.py index bdd735a..c71697a 100644 --- a/crocoite/test_html.py +++ b/crocoite/test_html.py @@ -22,7 +22,8 @@ import pytest, html5lib from html5lib.serializer import HTMLSerializer from html5lib.treewalkers import getTreeWalker -from .html import StripTagFilter, StripAttributeFilter +from .html import StripTagFilter, StripAttributeFilter, ChromeTreeWalker +from .test_devtools import tab, browser def test_strip_tag (): d = html5lib.parse ('barbazfoobar.foobar.') @@ -36,3 +37,24 @@ def test_strip_attribute (): serializer = HTMLSerializer () assert serializer.render (stream) == '
' +@pytest.mark.asyncio +async def test_treewalker (tab): + frames = await tab.Page.getFrameTree () + + framehtml = '' + html = '

Hello

' + rootframe = frames['frameTree']['frame']['id'] + await tab.Page.setDocumentContent (frameId=rootframe, html=html) + + dom = await tab.DOM.getDocument (depth=-1, pierce=True) + docs = list (ChromeTreeWalker (dom['root']).split ()) + assert len(docs) == 2 + for i, doc in enumerate (docs): + walker = ChromeTreeWalker (doc) + serializer = HTMLSerializer () + result = serializer.render (iter(walker)) + if i == 0: + assert result == html + elif i == 1: + assert result == framehtml + -- cgit v1.2.3