diff options
author | E.Z. Hart <hartez@users.noreply.github.com> | 2016-07-18 17:16:47 -0600 |
---|---|---|
committer | Jason Smith <jason.smith@xamarin.com> | 2016-07-18 16:16:47 -0700 |
commit | 272033723ea275ceb8a288fa605eafd035c79f2d (patch) | |
tree | abc639d0f5627f3877f9e237e473bda168e9e030 /Xamarin.Forms.Controls.Issues | |
parent | c9da550ce4987e01c1bbce9d0a17b860e1d300b3 (diff) | |
download | xamarin-forms-272033723ea275ceb8a288fa605eafd035c79f2d.tar.gz xamarin-forms-272033723ea275ceb8a288fa605eafd035c79f2d.tar.bz2 xamarin-forms-272033723ea275ceb8a288fa605eafd035c79f2d.zip |
Windows image loader error handling (#260)
* Repros for various image issues
* Log image loading errors
* Better repro instructions and user interface
* Image loading tests now running on WinRT/UWP phone/tablet/desktop
* Move FailImageSource into shared project
* Move FailImageSource into shared project
* Update docs
Diffstat (limited to 'Xamarin.Forms.Controls.Issues')
3 files changed, 114 insertions, 0 deletions
diff --git a/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/FailImageSource.cs b/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/FailImageSource.cs new file mode 100644 index 00000000..a3dfbb3b --- /dev/null +++ b/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/FailImageSource.cs @@ -0,0 +1,12 @@ +using System.Threading.Tasks; + +namespace Xamarin.Forms.Controls +{ + public sealed class FailImageSource : ImageSource + { + public override Task<bool> Cancel() + { + return Task.FromResult(false); + } + } +}
\ No newline at end of file diff --git a/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/ImageLoadingErrorHandling.cs b/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/ImageLoadingErrorHandling.cs new file mode 100644 index 00000000..fe1f6356 --- /dev/null +++ b/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/ImageLoadingErrorHandling.cs @@ -0,0 +1,100 @@ +using System; +using Xamarin.Forms.CustomAttributes; +using Xamarin.Forms.Internals; + +namespace Xamarin.Forms.Controls +{ + [Preserve(AllMembers = true)] + [Issue(IssueTracker.None, 0, "Image Loading Error Handling", PlatformAffected.WinRT)] + public class ImageLoadingErrorHandling : TestContentPage + { + protected override void Init() + { + Log.Listeners.Add( + new DelegateLogListener((c, m) => Device.BeginInvokeOnMainThread(() => DisplayAlert(c, m, "Cool, Thanks")))); + + var image = new Image() {BackgroundColor = Color.White}; + + Grid legit = CreateTest(() => image.Source = ImageSource.FromFile("coffee.png"), + "Valid Image", + "Clicking this button should load an image at the top of the page.", + Color.Silver); + + Grid invalidImageFileName = CreateTest(() => image.Source = ImageSource.FromFile("fake.png"), + "Non-existent Image File", + "Clicking this button should display an alert dialog with an error that the image failed to load."); + + Grid invalidImageFile = CreateTest(() => image.Source = ImageSource.FromFile("invalidimage.jpg"), + "Invalid Image File (bad data)", + "Clicking this button should display an alert dialog with an error that the image failed to load.", + Color.Silver); + + Grid fakeUri = CreateTest(() => image.Source = ImageSource.FromUri(new Uri("http://not.real")), + "Non-existent URI", + Device.OS == TargetPlatform.Windows && Device.Idiom == TargetIdiom.Phone + ? "Clicking this button should display an alert dialog. The error message should include the text 'NotFound'." + : "Clicking this button should display an alert dialog. The error message should include the text 'the server name or address could not be resolved'."); + + // This used to crash the app with an uncatchable error; need to make sure it's not still doing that + Grid crashImage = CreateTest(() => image.Source = new FailImageSource(), + "Source Throws Exception", + "Clicking this button should display an alert dialog. The error messages hould include the test 'error updating image source'.", + Color.Silver); + + Grid uriInvalidImageData = + CreateTest(() => image.Source = ImageSource.FromUri(new Uri("https://gist.githubusercontent.com/hartez/a2dda6b5c78852bcf4832af18f21a023/raw/39f4cd2e9fe8514694ac7fa0943017eb9308853d/corrupt.jpg")), + "Valid URI with invalid image file", + "Clicking this button should display an alert dialog. The error message should include the text 'UriImageSourceHandler could not load https://gist.githubusercontent.com/hartez/a2dda6b5c78852bcf4832af18f21a023/raw/39f4cd2e9fe8514694ac7fa0943017eb9308853d/corrupt.jpg'"); + + Content = new StackLayout + { + Children = + { + image, + legit, + invalidImageFileName, + invalidImageFile, + fakeUri, + crashImage, + uriInvalidImageData + } + }; + } + + static Grid CreateTest(Action imageLoadAction, string title, string instructions, Color? backgroundColor = null) + { + var button = new Button { Text = "Test" }; + + button.Clicked += (sender, args) => imageLoadAction(); + + var titleLabel = new Label + { + Text = title, + FontAttributes = FontAttributes.Bold + }; + + var label = new Label + { + Text = instructions + }; + + var grid = new Grid + { + ColumnDefinitions = + new ColumnDefinitionCollection { new ColumnDefinition(), new ColumnDefinition(), new ColumnDefinition() }, + RowDefinitions = new RowDefinitionCollection { new RowDefinition { Height = 80 } } + }; + + if (backgroundColor.HasValue) + { + grid.BackgroundColor = backgroundColor.Value; + } + + grid.AddChild(titleLabel, 0, 0); + grid.AddChild(label, 1, 0); + grid.AddChild(button, 2, 0); + + return grid; + } + } +}
\ No newline at end of file diff --git a/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Xamarin.Forms.Controls.Issues.Shared.projitems b/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Xamarin.Forms.Controls.Issues.Shared.projitems index cd836f39..30ad7ee4 100644 --- a/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Xamarin.Forms.Controls.Issues.Shared.projitems +++ b/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Xamarin.Forms.Controls.Issues.Shared.projitems @@ -118,6 +118,7 @@ <Compile Include="$(MSBuildThisFileDirectory)Bugzilla38416.xaml.cs"> <DependentUpon>Bugzilla38416.xaml</DependentUpon> </Compile> + <Compile Include="$(MSBuildThisFileDirectory)FailImageSource.cs" /> <Compile Include="$(MSBuildThisFileDirectory)InputTransparentIssue.cs" /> <Compile Include="$(MSBuildThisFileDirectory)IsInvokeRequiredRaceCondition.cs" /> <Compile Include="$(MSBuildThisFileDirectory)IsPasswordToggleTest.cs" /> @@ -159,6 +160,7 @@ <Compile Include="$(MSBuildThisFileDirectory)TestPages\ScreenshotConditionalApp.cs" /> <Compile Include="$(MSBuildThisFileDirectory)Bugzilla41842.cs" /> <Compile Include="$(MSBuildThisFileDirectory)Bugzilla42277.cs" /> + <Compile Include="$(MSBuildThisFileDirectory)ImageLoadingErrorHandling.cs" /> <Compile Include="$(MSBuildThisFileDirectory)_Template.cs" /> <Compile Include="$(MSBuildThisFileDirectory)Issue1028.cs" /> <Compile Include="$(MSBuildThisFileDirectory)Issue1075.cs" /> |