|
2 | 2 | {
|
3 | 3 | using AngleSharp.Dom.Html;
|
4 | 4 | using AngleSharp.Extensions;
|
| 5 | + using AngleSharp.Scripting.JavaScript.Dom; |
5 | 6 | using AngleSharp.Scripting.JavaScript.Tests.Mocks;
|
6 | 7 | using NUnit.Framework;
|
7 | 8 | using System;
|
@@ -137,5 +138,33 @@ public async Task SetContentOfIFrameElement()
|
137 | 138 | var result = document.GetElementById("myframe") as IHtmlInlineFrameElement;
|
138 | 139 | Assert.AreEqual("Hello world.", result.ContentDocument.Body.TextContent);
|
139 | 140 | }
|
| 141 | + |
| 142 | + [Test] |
| 143 | + public async Task RunMainScriptFromHtml5Test() |
| 144 | + { |
| 145 | + var script = @"var p=[],w=window,d=document,e=f=0;p.push('ua='+encodeURIComponent(navigator.userAgent));e|=w.ActiveXObject?1:0;e|=w.opera?2:0;e|=w.chrome?4:0; |
| 146 | +e|='getBoxObjectFor' in d || 'mozInnerScreenX' in w?8:0;e|=('WebKitCSSMatrix' in w||'WebKitPoint' in w||'webkitStorageInfo' in w||'webkitURL' in w)?16:0; |
| 147 | +e|=(e&16&&({}.toString).toString().indexOf(""\n"")===-1)?32:0;p.push('e='+e);f|='sandbox' in d.createElement('iframe')?1:0;f|='WebSocket' in w?2:0; |
| 148 | +f|=w.Worker?4:0;f|=w.applicationCache?8:0;f|=w.history && history.pushState?16:0;f|=d.documentElement.webkitRequestFullScreen?32:0;f|='FileReader' in w?64:0; |
| 149 | +p.push('f='+f);p.push('r='+Math.random().toString(36).substring(7));p.push('w='+screen.width);p.push('h='+screen.height);var s=d.createElement('script'); |
| 150 | +s.src='//api.whichbrowser.net/rel/detect.js?' + p.join('&');d.getElementsByTagName('head')[0].appendChild(s);"; |
| 151 | + var result = await EvaluateComplexScriptAsync(script, SetResult("p.join('').toString()")); |
| 152 | + Assert.AreNotEqual("undefined", result); |
| 153 | + } |
| 154 | + |
| 155 | + [Test] |
| 156 | + public async Task QueryUserAgentShouldMatchAgent() |
| 157 | + { |
| 158 | + var userAgent = new Navigator().UserAgent; |
| 159 | + var result = await EvaluateComplexScriptAsync(SetResult("navigator.userAgent")); |
| 160 | + Assert.AreEqual(userAgent, result); |
| 161 | + } |
| 162 | + |
| 163 | + [Test] |
| 164 | + public async Task ScreenPixelDepthShouldYield24() |
| 165 | + { |
| 166 | + var result = await EvaluateComplexScriptAsync(SetResult("screen.pixelDepth.toString()")); |
| 167 | + Assert.AreEqual("24", result); |
| 168 | + } |
140 | 169 | }
|
141 | 170 | }
|
0 commit comments