mirror of
https://github.com/microsoft/PowerToys.git
synced 2026-04-04 18:26:39 +02:00
* dotnet sc
* MD preview - C# app
- working self-contained
* Gcode preview - C# app
* DevFiles preview - C# app
* Fix passing path with spaces as cmd arg and monacocpp proj file
* Pdf preview - C# app
* Svg preview - C# app
* Fix comment
* Gcode thumbnail - C# app
TODO:
- installer
- why IThumbnailProvider and IIntializeWithFile doesn't work?
* Pdf thumbnail - C# app
TODO:
- installer
- why IThumbnailProvider and IIntializeWithFile doesn't work?
* Pdf thumbnail - C# app
TODO:
- installer
- why IThumbnailProvider and IIntializeWithFile doesn't work?
* Fix GcodeThumbnailProviderCpp.vcxproj
* Svg thumbnail - C# app
TODO:
- installer
- why IThumbnailProvider and IIntializeWithFile doesn't work?
* Fix Svg tests
* Thumbnail providers - installer
* Self-contained Hosts and FileLocksmith
* Fix hardcoded <RuntimeIdentifier>
* Remove unneeded files
* Try to fix Nuget in PR CI
* Prefix new dlls with PowerToys.
Sign new dlls and exes
* Add new .exe files to ProcessList
* ci: debug by listing all env vars
* ci: try setting variable in the right ci file
* Bring back hardcoded RuntimeIdentifier
* ci: Add comment and remove debug action
* Remove unneeded lib
* [WIP] Platform conditional dotnet files & hardlinks
* Cleanup
* Update expect.txt
* Test fix - ARM installer
* Fix uninstall bug
* Update docs
* Fix failing test
* Add dll details
* Minor cleanup
* Improve resizing
* Add some logs
* Test fix - release build
* Remove InvokeOnControlThread
* Test fix: logger initialization
* Fix arm64 installer
Co-authored-by: Jaime Bernardo <jaime@janeasystems.com>
Co-authored-by: Dustin L. Howett <dustin@howett.net>
136 lines
5.3 KiB
C#
136 lines
5.3 KiB
C#
// Copyright (c) Microsoft Corporation
|
|
// The Microsoft Corporation licenses this file to you under the MIT license.
|
|
// See the LICENSE file in the project root for more information.
|
|
|
|
using System;
|
|
using System.Drawing;
|
|
using System.Runtime.InteropServices;
|
|
using System.Runtime.InteropServices.ComTypes;
|
|
using System.Text;
|
|
using Common.ComInterlop;
|
|
using Microsoft.PowerToys.STATestExtension;
|
|
using Microsoft.PowerToys.ThumbnailHandler.Svg;
|
|
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
|
using Moq;
|
|
|
|
namespace SvgThumbnailProviderUnitTests
|
|
{
|
|
[STATestClass]
|
|
public class SvgThumbnailProviderTests
|
|
{
|
|
[TestMethod]
|
|
public void LoadSimpleSVGShouldReturnNonNullBitmap()
|
|
{
|
|
var svgBuilder = new StringBuilder();
|
|
svgBuilder.AppendLine("<svg viewBox=\"0 0 100 100\" xmlns=\"http://www.w3.org/2000/svg\">");
|
|
svgBuilder.AppendLine("\t<circle cx=\"50\" cy=\"50\" r=\"50\">");
|
|
svgBuilder.AppendLine("\t</circle>");
|
|
svgBuilder.AppendLine("</svg>");
|
|
|
|
SvgThumbnailProvider svgThumbnailProvider = new SvgThumbnailProvider(null);
|
|
Bitmap thumbnail = svgThumbnailProvider.GetThumbnail(svgBuilder.ToString(), 256);
|
|
|
|
Assert.IsNotNull(thumbnail);
|
|
Assert.IsTrue(thumbnail.Width > 0);
|
|
Assert.IsTrue(thumbnail.Height > 0);
|
|
}
|
|
|
|
[TestMethod]
|
|
public void CheckBlockedElementsShouldReturnNonNullBitmapIfBlockedElementsIsPresentInNestedLevel()
|
|
{
|
|
var svgBuilder = new StringBuilder();
|
|
svgBuilder.AppendLine("<svg viewBox=\"0 0 100 100\" xmlns=\"http://www.w3.org/2000/svg\">");
|
|
svgBuilder.AppendLine("\t<circle cx=\"50\" cy=\"50\" r=\"50\">");
|
|
svgBuilder.AppendLine("\t\t<script>alert(\"valid-message\")</script>");
|
|
svgBuilder.AppendLine("\t</circle>");
|
|
svgBuilder.AppendLine("</svg>");
|
|
|
|
SvgThumbnailProvider svgThumbnailProvider = new SvgThumbnailProvider(null);
|
|
Bitmap thumbnail = svgThumbnailProvider.GetThumbnail(svgBuilder.ToString(), 256);
|
|
Assert.IsTrue(thumbnail != null);
|
|
}
|
|
|
|
[TestMethod]
|
|
public void CheckNoSvgShouldReturnNullBitmap()
|
|
{
|
|
var svgBuilder = new StringBuilder();
|
|
svgBuilder.AppendLine("<p>foo</p>");
|
|
|
|
SvgThumbnailProvider svgThumbnailProvider = new SvgThumbnailProvider(null);
|
|
Bitmap thumbnail = svgThumbnailProvider.GetThumbnail(svgBuilder.ToString(), 256);
|
|
Assert.IsTrue(thumbnail == null);
|
|
}
|
|
|
|
[TestMethod]
|
|
public void CheckNoSvgEmptyStringShouldReturnNullBitmap()
|
|
{
|
|
SvgThumbnailProvider svgThumbnailProvider = new SvgThumbnailProvider(null);
|
|
Bitmap thumbnail = svgThumbnailProvider.GetThumbnail(string.Empty, 256);
|
|
Assert.IsTrue(thumbnail == null);
|
|
}
|
|
|
|
[TestMethod]
|
|
public void CheckNoSvgNullStringShouldReturnNullBitmap()
|
|
{
|
|
SvgThumbnailProvider svgThumbnailProvider = new SvgThumbnailProvider(null);
|
|
Bitmap thumbnail = svgThumbnailProvider.GetThumbnail(null, 256);
|
|
Assert.IsTrue(thumbnail == null);
|
|
}
|
|
|
|
[TestMethod]
|
|
public void CheckZeroSizedThumbnailShouldReturnNullBitmap()
|
|
{
|
|
string content = "<svg></svg>";
|
|
SvgThumbnailProvider svgThumbnailProvider = new SvgThumbnailProvider(null);
|
|
Bitmap thumbnail = svgThumbnailProvider.GetThumbnail(content, 0);
|
|
Assert.IsTrue(thumbnail == null);
|
|
}
|
|
|
|
[TestMethod]
|
|
public void CheckBlockedElementsShouldReturnBitmapHTMLWrapped()
|
|
{
|
|
var svgBuilder = new StringBuilder();
|
|
svgBuilder.AppendLine("<html>");
|
|
svgBuilder.AppendLine("<head>");
|
|
svgBuilder.AppendLine("<meta http-equiv=\"X-UA-Compatible\" content=\"IE=Edge\">");
|
|
svgBuilder.AppendLine("<meta http-equiv=\"Content-Type\" content=\"text/html\" charset=\"utf-8\">");
|
|
svgBuilder.AppendLine("</head>");
|
|
svgBuilder.AppendLine("<body>");
|
|
svgBuilder.AppendLine("<svg viewBox=\"0 0 100 100\" xmlns=\"http://www.w3.org/2000/svg\">");
|
|
svgBuilder.AppendLine("<circle cx=\"50\" cy=\"50\" r=\"50\">");
|
|
svgBuilder.AppendLine("</circle>");
|
|
svgBuilder.AppendLine("</svg>");
|
|
svgBuilder.AppendLine("</body>");
|
|
svgBuilder.AppendLine("</html>");
|
|
|
|
SvgThumbnailProvider svgThumbnailProvider = new SvgThumbnailProvider(null);
|
|
Bitmap thumbnail = svgThumbnailProvider.GetThumbnail(svgBuilder.ToString(), 256);
|
|
Assert.IsTrue(thumbnail != null);
|
|
}
|
|
|
|
[TestMethod]
|
|
public void GetThumbnailValidStreamSVG()
|
|
{
|
|
var filePath = "HelperFiles/file1.svg";
|
|
|
|
SvgThumbnailProvider svgThumbnailProvider = new SvgThumbnailProvider(filePath);
|
|
|
|
Bitmap bitmap = svgThumbnailProvider.GetThumbnail(256);
|
|
|
|
Assert.IsTrue(bitmap != null);
|
|
}
|
|
|
|
[TestMethod]
|
|
public void GetThumbnailValidStreamHTML()
|
|
{
|
|
var filePath = "HelperFiles/file2.svg";
|
|
|
|
SvgThumbnailProvider svgThumbnailProvider = new SvgThumbnailProvider(filePath);
|
|
|
|
Bitmap bitmap = svgThumbnailProvider.GetThumbnail(256);
|
|
|
|
Assert.IsTrue(bitmap != null);
|
|
}
|
|
}
|
|
}
|