summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--crocoite/test_html.py24
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
+