diff options
author | Lars-Dominik Braun <lars@6xq.net> | 2018-11-17 14:04:03 +0100 |
---|---|---|
committer | Lars-Dominik Braun <lars@6xq.net> | 2018-11-17 14:04:03 +0100 |
commit | a5561785fb66f49c2b76557c6f6745eedb4d8b73 (patch) | |
tree | 21c3bff5755d558f4b3f98f576bd73b1fc4cdcab /crocoite | |
parent | 22c1d384c1951f1ed45773f92804f9a1c69419e2 (diff) | |
download | crocoite-a5561785fb66f49c2b76557c6f6745eedb4d8b73.tar.gz crocoite-a5561785fb66f49c2b76557c6f6745eedb4d8b73.tar.bz2 crocoite-a5561785fb66f49c2b76557c6f6745eedb4d8b73.zip |
html: Add tests for tree walker
Diffstat (limited to 'crocoite')
-rw-r--r-- | crocoite/test_html.py | 24 |
1 files changed, 23 insertions, 1 deletions
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 ('<a>barbaz<b>foobar</b>.</a><b>foobar</b>.<b attr=1><c></c>') @@ -36,3 +37,24 @@ def test_strip_attribute (): serializer = HTMLSerializer () assert serializer.render (stream) == '<a></a><br keep=1>' +@pytest.mark.asyncio +async def test_treewalker (tab): + frames = await tab.Page.getFrameTree () + + framehtml = '<HTML><HEAD></HEAD><BODY></BODY></HTML>' + html = '<HTML><HEAD><META charset=utf-8></HEAD><BODY><H1>Hello</H1><!-- comment --><IFRAME></IFRAME></BODY></HTML>' + 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 + |