Skip to content

Commit

Permalink
Added test for string function #26
Browse files Browse the repository at this point in the history
  • Loading branch information
FlorianRappl committed Oct 1, 2016
1 parent 619b9cd commit 4ef54be
Showing 1 changed file with 59 additions and 0 deletions.
59 changes: 59 additions & 0 deletions src/AngleSharp.Scripting.JavaScript.Tests/FireEventTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -132,5 +132,64 @@ public async Task AddAndInvokeClickHandlerWillChangeCapturedValue()
var clicked = service.Engine.GetOrCreateJint(document).GetValue("clicked").AsBoolean();
Assert.IsTrue(clicked);
}

[Test]
public async Task AddAndInvokeClickHandlerWithStringFunctionWontWork()
{
var service = new JavaScriptProvider();
var cfg = Configuration.Default.With(service);
var html = @"<!doctype html>
<html>
<body>
<script>
var clicked = false;
document.onclick = 'clicked = true;';
document.onclick();
</script>
</body>";
var document = await BrowsingContext.New(cfg).OpenAsync(m => m.Content(html));
var clicked = service.Engine.GetOrCreateJint(document).GetValue("clicked").AsBoolean();
Assert.IsFalse(clicked);
}

[Test]
public async Task SetTimeoutWithNormalFunction()
{
var service = new JavaScriptProvider();
var cfg = Configuration.Default.With(service);
var html = @"<!doctype html>
<html>
<body>
<script>
var completed = false;
setTimeout(function () {
completed = true;
}, 0);
</script>
</body>";
var document = await BrowsingContext.New(cfg).OpenAsync(m => m.Content(html));
await Task.Delay(100);
var result = service.Engine.GetOrCreateJint(document).GetValue("completed").AsBoolean();
Assert.IsTrue(result);
}

[Test]
public async Task SetTimeoutWithStringAsFunction()
{
var service = new JavaScriptProvider();
var cfg = Configuration.Default.With(service);
var html = @"<!doctype html>
<html>
<body>
<script>
var completed = false;
setTimeout('completed = true;', 0);
</script>
</body>";
var document = await BrowsingContext.New(cfg).OpenAsync(m => m.Content(html));
await Task.Delay(100);
var result = service.Engine.GetOrCreateJint(document).GetValue("completed").AsBoolean();
Assert.IsTrue(result);
}
}
}

0 comments on commit 4ef54be

Please sign in to comment.