Skip to content

Commit

Permalink
Merged
Browse files Browse the repository at this point in the history
  • Loading branch information
FlorianRappl committed Dec 26, 2015
2 parents 4c1eea6 + c4520bb commit 6366a86
Show file tree
Hide file tree
Showing 83 changed files with 3,089 additions and 1,758 deletions.
1 change: 1 addition & 0 deletions AngleSharp.Core.Tests/AngleSharp.Core.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,7 @@
<Compile Include="Mocks\EventReceiver.cs" />
<Compile Include="Mocks\FileEntry.cs" />
<Compile Include="Mocks\MockEntityResolver.cs" />
<Compile Include="Mocks\MockImageInfo.cs" />
<Compile Include="Mocks\MockRequester.cs" />
<Compile Include="Css\HtmlCssIntegration.cs" />
<Compile Include="Mocks\MockScriptService.cs" />
Expand Down
12 changes: 8 additions & 4 deletions AngleSharp.Core.Tests/Library/ContextLoading.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
using AngleSharp.Dom.Html;
using AngleSharp.Events;
using AngleSharp.Extensions;
using AngleSharp.Network;
using AngleSharp.Services.Media;
using NUnit.Framework;
using System;
using System.IO;
Expand Down Expand Up @@ -158,7 +160,6 @@ public async Task ContextLoadAmazonWithCss()
var address = "http://www.amazon.com";
var config = new Configuration().WithPageRequester().WithCss();
var document = await BrowsingContext.New(config).OpenAsync(address);
await Task.WhenAll(document.Requests);
Assert.IsNotNull(document);
Assert.AreNotEqual(0, document.Body.ChildElementCount);
}
Expand All @@ -167,11 +168,13 @@ public async Task ContextLoadAmazonWithCss()
public async Task ContextLoadExternalResources()
{
var delayRequester = new DelayRequester(100);
var config = new Configuration().WithDefaultLoader(m => m.IsResourceLoadingEnabled = true, new[] { delayRequester });
var imageService = new ResourceService<IImageInfo>("image/jpeg", response => new MockImageInfo { Source = response.Address });
var config = new Configuration().WithDefaultLoader(m => m.IsResourceLoadingEnabled = true, new[] { delayRequester }).With(imageService);
var context = BrowsingContext.New(config);
var document = await context.OpenAsync(m => m.Content("<img src=whatever.jpg>"));
Assert.AreEqual(0, document.Requests.Count());
var img = document.QuerySelector<IHtmlImageElement>("img");
Assert.AreEqual(1, delayRequester.RequestCount);
Assert.IsTrue(img.IsCompleted);
}

[Test]
Expand All @@ -181,8 +184,9 @@ public async Task ContextNoLoadExternalResources()
var config = new Configuration().WithDefaultLoader(requesters: new[] { delayRequester });
var context = BrowsingContext.New(config);
var document = await context.OpenAsync(m => m.Content("<img src=whatever.jpg>"));
Assert.AreEqual(0, document.Requests.Count());
var img = document.QuerySelector<IHtmlImageElement>("img");
Assert.AreEqual(0, delayRequester.RequestCount);
Assert.IsFalse(img.IsCompleted);
}

[Test]
Expand Down
2 changes: 1 addition & 1 deletion AngleSharp.Core.Tests/Library/DOMActions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -877,7 +877,7 @@ public void TheLegendElementIsChildOfTheDisabledFieldsetDescendantsShouldNotBeDi
[Test]
public async Task IframeWithDocumentViaDataSrc()
{
var cfg = Configuration.Default.WithDefaultLoader();
var cfg = Configuration.Default.WithDefaultLoader(setup => setup.IsResourceLoadingEnabled = true);
var html = @"<!doctype html><iframe id=myframe src='data:text/html,<span>Hello World!</span>'></iframe></script>";
var document = await BrowsingContext.New(cfg).OpenAsync(m => m.Content(html));
var iframe = document.QuerySelector<IHtmlInlineFrameElement>("#myframe");
Expand Down
23 changes: 23 additions & 0 deletions AngleSharp.Core.Tests/Mocks/MockImageInfo.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
namespace AngleSharp.Core.Tests.Mocks
{
using AngleSharp.Services.Media;

class MockImageInfo : IImageInfo
{
public int Width
{
get { return 0; }
}

public int Height
{
get { return 0; }
}

public Url Source
{
get;
set;
}
}
}
10 changes: 5 additions & 5 deletions AngleSharp.Core.Tests/Mocks/StandingEventLoopService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
using AngleSharp.Dom;
using AngleSharp.Services;
using System;
using System.Threading.Tasks;
using System.Threading;

class StandingEventLoopService : IEventService
{
Expand All @@ -14,18 +14,18 @@ public IEventLoop Create(IDocument document)

sealed class EventLoop : IEventLoop
{
public Task Enqueue(Action task)
public IEventLoopEntry Enqueue(Action<CancellationToken> action, TaskPriority priority)
{
return Task.FromResult(false);
return null;
}

public Task Execute(Action microtask)
public void Spin()
{
return Task.FromResult(false);
}

public void Shutdown()
{
throw new NotImplementedException();
}
}
}
Expand Down
27 changes: 24 additions & 3 deletions AngleSharp.Legacy/AngleSharp.Core.Legacy.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -1850,6 +1850,9 @@
<Compile Include="..\AngleSharp\Extensions\ElementExtensions.cs">
<Link>Extensions\ElementExtensions.cs</Link>
</Compile>
<Compile Include="..\AngleSharp\Extensions\EventLoopExtensions.cs">
<Link>Extensions\EventLoopExtensions.cs</Link>
</Compile>
<Compile Include="..\AngleSharp\Extensions\EventTargetExtensions.cs">
<Link>Extensions\EventTargetExtensions.cs</Link>
</Compile>
Expand All @@ -1868,6 +1871,9 @@
<Compile Include="..\AngleSharp\Extensions\RequesterExtensions.cs">
<Link>Extensions\RequesterExtensions.cs</Link>
</Compile>
<Compile Include="..\AngleSharp\Extensions\ResponseExtensions.cs">
<Link>Extensions\ResponseExtensions.cs</Link>
</Compile>
<Compile Include="..\AngleSharp\Extensions\SelectorExtensions.cs">
<Link>Extensions\SelectorExtensions.cs</Link>
</Compile>
Expand Down Expand Up @@ -1916,9 +1922,6 @@
<Compile Include="..\AngleSharp\Factories\SvgElementFactory.cs">
<Link>Factories\SvgElementFactory.cs</Link>
</Compile>
<Compile Include="..\AngleSharp\Foundation\CancellableTasks.cs">
<Link>Foundation\CancellableTasks.cs</Link>
</Compile>
<Compile Include="..\AngleSharp\Foundation\CreateDocumentOptions.cs">
<Link>Foundation\CreateDocumentOptions.cs</Link>
</Compile>
Expand All @@ -1937,6 +1940,9 @@
<Compile Include="..\AngleSharp\Foundation\TaskEventLoop.cs">
<Link>Foundation\TaskEventLoop.cs</Link>
</Compile>
<Compile Include="..\AngleSharp\Foundation\TaskPriority.cs">
<Link>Foundation\TaskPriority.cs</Link>
</Compile>
<Compile Include="..\AngleSharp\Html\AttributeNames.cs">
<Link>Html\AttributeNames.cs</Link>
</Compile>
Expand Down Expand Up @@ -2093,6 +2099,9 @@
<Compile Include="..\AngleSharp\IEventLoop.cs">
<Link>IEventLoop.cs</Link>
</Compile>
<Compile Include="..\AngleSharp\IEventLoopEntry.cs">
<Link>IEventLoopEntry.cs</Link>
</Compile>
<Compile Include="..\AngleSharp\IMarkupFormattable.cs">
<Link>IMarkupFormattable.cs</Link>
</Compile>
Expand Down Expand Up @@ -2639,12 +2648,18 @@
<Compile Include="..\AngleSharp\IStyleFormatter.cs">
<Link>IStyleFormatter.cs</Link>
</Compile>
<Compile Include="..\AngleSharp\Network\Default\BaseLoader.cs">
<Link>Network\Default\BaseLoader.cs</Link>
</Compile>
<Compile Include="..\AngleSharp\Network\Default\DataRequester.cs">
<Link>Network\Default\DataRequester.cs</Link>
</Compile>
<Compile Include="..\AngleSharp\Network\Default\DocumentLoader.cs">
<Link>Network\Default\DocumentLoader.cs</Link>
</Compile>
<Compile Include="..\AngleSharp\Network\Default\Download.cs">
<Link>Network\Default\Download.cs</Link>
</Compile>
<Compile Include="..\AngleSharp\Network\Default\HttpRequester.cs">
<Link>Network\Default\HttpRequester.cs</Link>
</Compile>
Expand All @@ -2669,6 +2684,12 @@
<Compile Include="..\AngleSharp\Network\IDocumentLoader.cs">
<Link>Network\IDocumentLoader.cs</Link>
</Compile>
<Compile Include="..\AngleSharp\Network\IDownload.cs">
<Link>Network\IDownload.cs</Link>
</Compile>
<Compile Include="..\AngleSharp\Network\ILoader.cs">
<Link>Network\ILoader.cs</Link>
</Compile>
<Compile Include="..\AngleSharp\Network\IRequest.cs">
<Link>Network\IRequest.cs</Link>
</Compile>
Expand Down
29 changes: 25 additions & 4 deletions AngleSharp.Silverlight/AngleSharp.Core.Silverlight.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -1865,6 +1865,9 @@
<Compile Include="..\AngleSharp\Extensions\ElementExtensions.cs">
<Link>Extensions\ElementExtensions.cs</Link>
</Compile>
<Compile Include="..\AngleSharp\Extensions\EventLoopExtensions.cs">
<Link>Extensions\EventLoopExtensions.cs</Link>
</Compile>
<Compile Include="..\AngleSharp\Extensions\EventTargetExtensions.cs">
<Link>Extensions\EventTargetExtensions.cs</Link>
</Compile>
Expand All @@ -1883,6 +1886,9 @@
<Compile Include="..\AngleSharp\Extensions\RequesterExtensions.cs">
<Link>Extensions\RequesterExtensions.cs</Link>
</Compile>
<Compile Include="..\AngleSharp\Extensions\ResponseExtensions.cs">
<Link>Extensions\ResponseExtensions.cs</Link>
</Compile>
<Compile Include="..\AngleSharp\Extensions\SelectorExtensions.cs">
<Link>Extensions\SelectorExtensions.cs</Link>
</Compile>
Expand Down Expand Up @@ -1931,9 +1937,6 @@
<Compile Include="..\AngleSharp\Factories\SvgElementFactory.cs">
<Link>Factories\SvgElementFactory.cs</Link>
</Compile>
<Compile Include="..\AngleSharp\Foundation\CancellableTasks.cs">
<Link>Foundation\CancellableTasks.cs</Link>
</Compile>
<Compile Include="..\AngleSharp\Foundation\CreateDocumentOptions.cs">
<Link>Factories\CreateDocumentOptions.cs</Link>
</Compile>
Expand All @@ -1952,6 +1955,9 @@
<Compile Include="..\AngleSharp\Foundation\TaskEventLoop.cs">
<Link>Foundation\TaskEventLoop.cs</Link>
</Compile>
<Compile Include="..\AngleSharp\Foundation\TaskPriority.cs">
<Link>Foundation\TaskPriority.cs</Link>
</Compile>
<Compile Include="..\AngleSharp\Html\AttributeNames.cs">
<Link>Html\AttributeNames.cs</Link>
</Compile>
Expand Down Expand Up @@ -2108,6 +2114,9 @@
<Compile Include="..\AngleSharp\IEventLoop.cs">
<Link>IEventLoop.cs</Link>
</Compile>
<Compile Include="..\AngleSharp\IEventLoopEntry.cs">
<Link>IEventLoopEntry.cs</Link>
</Compile>
<Compile Include="..\AngleSharp\IMarkupFormattable.cs">
<Link>IMarkupFormattable.cs</Link>
</Compile>
Expand Down Expand Up @@ -2654,12 +2663,18 @@
<Compile Include="..\AngleSharp\IStyleFormatter.cs">
<Link>IStyleFormatter.cs</Link>
</Compile>
<Compile Include="..\AngleSharp\Network\Default\BaseLoader.cs">
<Link>Network\Default\BaseLoader.cs</Link>
</Compile>
<Compile Include="..\AngleSharp\Network\Default\DataRequester.cs">
<Link>Network\Default\DataRequester.cs</Link>
</Compile>
<Compile Include="..\AngleSharp\Network\Default\DocumentLoader.cs">
<Link>Network\Default\DocumentLoader.cs</Link>
</Compile>
<Compile Include="..\AngleSharp\Network\Default\Download.cs">
<Link>Network\Default\Download.cs</Link>
</Compile>
<Compile Include="..\AngleSharp\Network\Default\HttpRequester.cs">
<Link>Network\Default\HttpRequester.cs</Link>
</Compile>
Expand All @@ -2684,6 +2699,12 @@
<Compile Include="..\AngleSharp\Network\IDocumentLoader.cs">
<Link>Network\IDocumentLoader.cs</Link>
</Compile>
<Compile Include="..\AngleSharp\Network\IDownload.cs">
<Link>Network\IDownload.cs</Link>
</Compile>
<Compile Include="..\AngleSharp\Network\ILoader.cs">
<Link>Network\ILoader.cs</Link>
</Compile>
<Compile Include="..\AngleSharp\Network\IRequest.cs">
<Link>Network\IRequest.cs</Link>
</Compile>
Expand Down Expand Up @@ -3007,7 +3028,7 @@
<FlavorProperties GUID="{A1591282-1198-4647-A2B1-27E5FF5F6F3B}">
<SilverlightProjectProperties />
</FlavorProperties>
<UserProperties ProjectLinkerExcludeFilter="\\?desktop(\\.*)?$;\\?silverlight(\\.*)?$;\.desktop;\.silverlight;\.xaml;^service references(\\.*)?$;\.clientconfig;^web references(\\.*)?$" ProjectLinkReference="91f78c48-287e-41b5-9e49-44d6e1e31290" />
<UserProperties ProjectLinkReference="91f78c48-287e-41b5-9e49-44d6e1e31290" ProjectLinkerExcludeFilter="\\?desktop(\\.*)?$;\\?silverlight(\\.*)?$;\.desktop;\.silverlight;\.xaml;^service references(\\.*)?$;\.clientconfig;^web references(\\.*)?$" />
</VisualStudio>
</ProjectExtensions>
<Import Project="..\packages\Microsoft.Bcl.Build.1.0.21\build\Microsoft.Bcl.Build.targets" Condition="Exists('..\packages\Microsoft.Bcl.Build.1.0.21\build\Microsoft.Bcl.Build.targets')" />
Expand Down
10 changes: 9 additions & 1 deletion AngleSharp/AngleSharp.Core.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,8 @@
<Compile Include="Events\ISubscriber.cs" />
<Compile Include="Events\RequestStartEvent.cs" />
<Compile Include="Extensions\ContextExtensions.cs" />
<Compile Include="Extensions\EventLoopExtensions.cs" />
<Compile Include="Extensions\ResponseExtensions.cs" />
<Compile Include="Extensions\WindowExtensions.cs" />
<Compile Include="Factories\InputTypeFactory.cs" />
<Compile Include="Factories\LinkRelationFactory.cs" />
Expand All @@ -196,9 +198,10 @@
<Compile Include="Extensions\EventTargetExtensions.cs" />
<Compile Include="Extensions\ObjectExtensions.cs" />
<Compile Include="Extensions\ValueConverterExtensions.cs" />
<Compile Include="Foundation\CancellableTasks.cs" />
<Compile Include="Foundation\CreateDocumentOptions.cs" />
<Compile Include="Foundation\Punycode.cs" />
<Compile Include="Foundation\TaskEx.cs" />
<Compile Include="Foundation\TaskPriority.cs" />
<Compile Include="Html\FileDataSetEntry.cs" />
<Compile Include="Html\FormDataSetEntry.cs" />
<Compile Include="Html\IFormDataSetVisitor.cs" />
Expand All @@ -221,6 +224,7 @@
<Compile Include="Html\Submitters\UrlEncodedFormDataSetVisitor.cs" />
<Compile Include="Html\TextDataSetEntry.cs" />
<Compile Include="IBindable.cs" />
<Compile Include="IEventLoopEntry.cs" />
<Compile Include="Interfaces\Html\IHtmlSlotElement.cs" />
<Compile Include="Interfaces\Css\IMediaQueryList.cs" />
<Compile Include="IEventLoop.cs" />
Expand All @@ -229,7 +233,11 @@
<Compile Include="Interfaces\IShadowRoot.cs" />
<Compile Include="IStyleFormattable.cs" />
<Compile Include="IStyleFormatter.cs" />
<Compile Include="Network\Default\BaseLoader.cs" />
<Compile Include="Network\Default\DataRequester.cs" />
<Compile Include="Network\Default\Download.cs" />
<Compile Include="Network\IDownload.cs" />
<Compile Include="Network\ILoader.cs" />
<Compile Include="Network\MimeType.cs" />
<Compile Include="Parser\Css\CssBuilder.cs" />
<Compile Include="Parser\Css\CssParserOptions.cs" />
Expand Down
6 changes: 5 additions & 1 deletion AngleSharp/BrowsingContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ internal BrowsingContext(IConfiguration configuration, Sandboxes security)
{
_configuration = configuration;
_security = security;
_loader = this.CreateLoader();
_loader = this.CreateDocumentLoader();
_history = this.CreateHistory();
}

Expand All @@ -54,7 +54,9 @@ internal BrowsingContext(IBrowsingContext parent, Sandboxes security)
public static IBrowsingContext New(IConfiguration configuration = null)
{
if (configuration == null)
{
configuration = AngleSharp.Configuration.Default;
}

return configuration.NewContext();
}
Expand All @@ -67,7 +69,9 @@ public static IBrowsingContext New(IConfiguration configuration = null)
public void NavigateTo(IDocument document)
{
if (_history != null)
{
_history.PushState(document, document.Title, document.Url);
}

_active = document;
}
Expand Down
Loading

0 comments on commit 6366a86

Please sign in to comment.