summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLars-Dominik Braun <lars@6xq.net>2019-03-22 10:50:46 +0100
committerLars-Dominik Braun <lars@6xq.net>2019-03-22 10:50:46 +0100
commit9f535348ef2740d0d88096c330bbc2618ae5c4c5 (patch)
treed9373b82142dfef01ef251a63288ec8a4d512a27
parent4643112b8f5f208f360e2e7c9431931b6526131e (diff)
downloadcrocoite-9f535348ef2740d0d88096c330bbc2618ae5c4c5.tar.gz
crocoite-9f535348ef2740d0d88096c330bbc2618ae5c4c5.tar.bz2
crocoite-9f535348ef2740d0d88096c330bbc2618ae5c4c5.zip
behavior: Test DomSnapshot
-rw-r--r--crocoite/test_behavior.py28
1 files changed, 27 insertions, 1 deletions
diff --git a/crocoite/test_behavior.py b/crocoite/test_behavior.py
index bbbd8ba..7a723c6 100644
--- a/crocoite/test_behavior.py
+++ b/crocoite/test_behavior.py
@@ -30,7 +30,7 @@ import pkg_resources
from .logger import Logger
from .devtools import Process
from .behavior import Scroll, Behavior, ExtractLinks, ExtractLinksEvent, Crash, \
- Screenshot, ScreenshotEvent
+ Screenshot, ScreenshotEvent, DomSnapshot, DomSnapshotEvent
from .controller import SinglePageController, EventHandler
from .devtools import Crashed
@@ -226,3 +226,29 @@ async def test_screenshot ():
finally:
await runner.cleanup ()
+@pytest.mark.asyncio
+async def test_dom_snapshot ():
+ """
+ Behavior plug-in works, <canvas> is replaced by static image, <script> is
+ stripped. Actual conversion from Chrome DOM to HTML is validated by module
+ .test_html
+ """
+
+ url = URL.build (scheme='http', host='localhost', port=8080)
+ runner = await simpleServer (url, f'<html><body><p>ÄÖÜäöü</p><script>alert("yes");</script><canvas id="canvas" width="1" height="1">Alternate text.</canvas></body></html>')
+
+ try:
+ handler = AccumHandler ()
+ logger = Logger ()
+ controller = SinglePageController (url=url, logger=logger,
+ service=Process (), behavior=[DomSnapshot], handler=[handler])
+ await controller.run ()
+
+ snapshots = list (filter (lambda x: isinstance (x, DomSnapshotEvent), handler.data))
+ assert len (snapshots) == 1
+ doc = snapshots[0].document
+ assert doc.startswith ('<HTML><HEAD><meta charset=utf-8></HEAD><BODY><P>ÄÖÜäöü</P><IMG id=canvas width=1 height=1 src="data:image/png;base64,'.encode ('utf-8'))
+ assert doc.endswith ('></BODY></HTML>'.encode ('utf-8'))
+ finally:
+ await runner.cleanup ()
+