Skip to content

Commit 4c71ba3

Browse files
committed
test: Support for .webp format
1 parent 6d3000b commit 4c71ba3

File tree

5 files changed

+115
-0
lines changed

5 files changed

+115
-0
lines changed
618 Bytes
Loading

src/SamplesApp/UITests.Shared/UITests.Shared.projitems

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2224,6 +2224,10 @@
22242224
<SubType>Designer</SubType>
22252225
<Generator>MSBuild:Compile</Generator>
22262226
</Page>
2227+
<Page Include="$(MSBuildThisFileDirectory)Windows_UI_Xaml_Controls\ImageTests\Image_AnimatedWebP.xaml">
2228+
<SubType>Designer</SubType>
2229+
<Generator>MSBuild:Compile</Generator>
2230+
</Page>
22272231
<Page Include="$(MSBuildThisFileDirectory)Windows_UI_Xaml_Controls\ImageTests\ImageAlignment2541.xaml">
22282232
<SubType>Designer</SubType>
22292233
<Generator>MSBuild:Compile</Generator>
@@ -7302,6 +7306,9 @@
73027306
<Compile Include="$(MSBuildThisFileDirectory)Windows_UI_Xaml_Controls\ImageTests\BitmapImage_IsPlaying.xaml.cs">
73037307
<DependentUpon>BitmapImage_IsPlaying.xaml</DependentUpon>
73047308
</Compile>
7309+
<Compile Include="$(MSBuildThisFileDirectory)Windows_UI_Xaml_Controls\ImageTests\Image_AnimatedWebP.xaml.cs">
7310+
<DependentUpon>Image_AnimatedWebP.xaml</DependentUpon>
7311+
</Compile>
73057312
<Compile Include="$(MSBuildThisFileDirectory)Windows_UI_Xaml_Controls\ImageTests\BitmapImage_vs_SvgImageSource.cs" />
73067313
<Compile Include="$(MSBuildThisFileDirectory)Windows_UI_Xaml_Controls\ImageTests\ImageAlignment2541.xaml.cs">
73077314
<DependentUpon>ImageAlignment2541.xaml</DependentUpon>
@@ -10131,6 +10138,7 @@
1013110138
<Content Include="$(MSBuildThisFileDirectory)Assets\Fonts\Renaiss-Italic.ttf" />
1013210139
<Content Include="$(MSBuildThisFileDirectory)Assets\Fonts\RoteFlora.ttf" />
1013310140
<Content Include="$(MSBuildThisFileDirectory)Assets\Formats\animated.gif" />
10141+
<Content Include="$(MSBuildThisFileDirectory)Assets\Formats\animated.webp" />
1013410142
<Content Include="$(MSBuildThisFileDirectory)Assets\Formats\uno-overalls.bmp" />
1013510143
<Content Include="$(MSBuildThisFileDirectory)Assets\Formats\uno-overalls.gif" />
1013610144
<Content Include="$(MSBuildThisFileDirectory)Assets\Formats\uno-overalls.jpg" />
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<Page
2+
x:Class="UITests.Windows_UI_Xaml_Controls.ImageTests.Image_AnimatedWebP"
3+
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
4+
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
5+
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
6+
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
7+
mc:Ignorable="d"
8+
Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
9+
10+
<StackPanel Spacing="16" Padding="16">
11+
<TextBlock Style="{StaticResource SubtitleTextBlockStyle}">Animated WebP</TextBlock>
12+
<Image Width="100" Height="100" Source="ms-appx:///Assets/Formats/animated.webp" />
13+
14+
<TextBlock Style="{StaticResource SubtitleTextBlockStyle}">Animated GIF (reference)</TextBlock>
15+
<Image Width="100" Height="100" Source="ms-appx:///Assets/Formats/animated.gif" />
16+
17+
<TextBlock Style="{StaticResource SubtitleTextBlockStyle}">Static WebP</TextBlock>
18+
<Image Width="100" Height="100" Source="ms-appx:///Assets/Formats/uno-overalls.webp" />
19+
</StackPanel>
20+
</Page>
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
using Microsoft.UI.Xaml.Controls;
2+
using Uno.UI.Samples.Controls;
3+
4+
namespace UITests.Windows_UI_Xaml_Controls.ImageTests
5+
{
6+
[Sample("Image", IsManualTest = true, Description = "All three images should load. The animated WebP and animated GIF should visibly cycle through colors. The static WebP should display normally.")]
7+
public sealed partial class Image_AnimatedWebP : Page
8+
{
9+
public Image_AnimatedWebP()
10+
{
11+
this.InitializeComponent();
12+
}
13+
}
14+
}

src/Uno.UI.RuntimeTests/Tests/Windows_UI_Xaml_Controls/Given_Image.cs

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -801,5 +801,78 @@ private async Task When_Exif_Rotated_Common(Uri uri)
801801

802802
private Task<RawBitmap> TakeScreenshot(FrameworkElement SUT)
803803
=> UITestHelper.ScreenShot(SUT);
804+
805+
#if __SKIA__
806+
[TestMethod]
807+
[RunsOnUIThread]
808+
public async Task When_StaticWebP_Loads()
809+
{
810+
var image = new Image
811+
{
812+
Width = 100,
813+
Height = 100,
814+
Source = new BitmapImage(new Uri("ms-appx:///Assets/Formats/uno-overalls.webp")),
815+
};
816+
817+
var imageOpened = false;
818+
image.ImageOpened += (_, _) => imageOpened = true;
819+
image.ImageFailed += (_, e) => Assert.Fail($"ImageFailed: {e.ErrorMessage}");
820+
821+
await UITestHelper.Load(image);
822+
await WindowHelper.WaitFor(() => imageOpened, message: "Static WebP should fire ImageOpened");
823+
}
824+
825+
[TestMethod]
826+
[RunsOnUIThread]
827+
public async Task When_AnimatedWebP_Loads()
828+
{
829+
var image = new Image
830+
{
831+
Width = 100,
832+
Height = 100,
833+
Source = new BitmapImage(new Uri("ms-appx:///Assets/Formats/animated.webp")),
834+
};
835+
836+
var imageOpened = false;
837+
image.ImageOpened += (_, _) => imageOpened = true;
838+
image.ImageFailed += (_, e) => Assert.Fail($"ImageFailed: {e.ErrorMessage}");
839+
840+
await UITestHelper.Load(image);
841+
await WindowHelper.WaitFor(() => imageOpened, message: "Animated WebP should fire ImageOpened");
842+
}
843+
844+
[TestMethod]
845+
[RunsOnUIThread]
846+
public async Task When_AnimatedWebP_Changes_Frames()
847+
{
848+
var image = new Image
849+
{
850+
Width = 100,
851+
Height = 100,
852+
Source = new BitmapImage(new Uri("ms-appx:///Assets/Formats/animated.webp")),
853+
};
854+
855+
var imageOpened = false;
856+
image.ImageOpened += (_, _) => imageOpened = true;
857+
858+
await UITestHelper.Load(image);
859+
await WindowHelper.WaitFor(() => imageOpened, message: "Animated WebP should fire ImageOpened");
860+
861+
// Take first screenshot.
862+
var screenshot1 = await UITestHelper.ScreenShot(image);
863+
var pixel1 = screenshot1.GetPixel(screenshot1.Width / 2, screenshot1.Height / 2);
864+
865+
// Wait long enough for animation to advance (frames are 200ms each).
866+
await Task.Delay(400);
867+
868+
// Take second screenshot - at least one should differ because the animation cycles.
869+
var screenshot2 = await UITestHelper.ScreenShot(image);
870+
var pixel2 = screenshot2.GetPixel(screenshot2.Width / 2, screenshot2.Height / 2);
871+
872+
// The animated WebP has red, green, blue, yellow, cyan, magenta frames.
873+
// After enough delay, the center pixel should have changed color at least once.
874+
Assert.AreNotEqual(pixel1, pixel2, "Animated WebP should show different frames over time");
875+
}
876+
#endif
804877
}
805878
}

0 commit comments

Comments
 (0)