Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[droid] "Uri too long" in WebView.NavigateToString remediation #2023

Merged
merged 4 commits into from
Nov 7, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions doc/ReleaseNotes/_ReleaseNotes.md
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@
> This change might break the compilation for projects that define duplicate resources in other globally accessible resource dictionaries. Adjustments to remove duplicate resources may be necessary.

### Bug fixes
* [#2023](https://github.com/unoplatform/uno/pull/2023) Android WebView.NavigateToString doesn't throw exception even when string is very long.
* [#2020](https://github.com/unoplatform/uno/pull/2020) `ContentControl` no longer display the datacontext type when ContentTemplate and content are empty
* [#1987](https://github.com/unoplatform/uno/pull/1987) Missing XML comment warnings are disabled on generated code
* [#1939](https://github.com/unoplatform/uno/pull/1939) Handles nullables types in XAML file generator
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
using NUnit.Framework;
using SamplesApp.UITests.TestFramework;
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Uno.UITest.Helpers;
using Uno.UITest.Helpers.Queries;

namespace SamplesApp.UITests.Windows_UI_Xaml_Controls.WebViewTests
{
[TestFixture]
public partial class WebView_Tests : SampleControlUITestBase
{
[Test]
[AutoRetry]
[ActivePlatforms(Platform.Android, Platform.iOS)]
public void WebView_NavigateToLongString()
pkar70 marked this conversation as resolved.
Show resolved Hide resolved
{
Run("UITests.Shared.Windows_UI_Xaml_Controls.WebView.WebView_NavigateToString2");

_app.WaitForElement(_app.Marked("startButton"));

TakeScreenshot("Initial");

var startButton = _app.Marked("startButton");
var clickResult = _app.Marked("WebView_NavigateToStringResult");

// step 1: generate long string
_app.Tap(startButton);

_app.WaitForText(clickResult, "string ready"); // timeout here means: add wait

// step 2: NavigateTo
_app.Tap(startButton);
_app.WaitForText(clickResult, "success"); // timeout here means: bug reappear

TakeScreenshot("AfterSuccess");

}

}
}
7 changes: 7 additions & 0 deletions src/SamplesApp/UITests.Shared/UITests.Shared.projitems
Original file line number Diff line number Diff line change
Expand Up @@ -1809,6 +1809,10 @@
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
<Page Include="$(MSBuildThisFileDirectory)Windows_UI_Xaml_Controls\WebView\WebView_NavigateToString2.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
<Page Include="$(MSBuildThisFileDirectory)Windows_UI_Xaml_Controls\WebView\WebView_NavigateToUri.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
Expand Down Expand Up @@ -3615,6 +3619,9 @@
<DependentUpon>UndefinedHeightListView.xaml</DependentUpon>
</Compile>
<Compile Include="$(MSBuildThisFileDirectory)Windows_UI_Xaml_Controls\WebView\WebViewViewModel.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Windows_UI_Xaml_Controls\WebView\WebView_NavigateToString2.xaml.cs">
<DependentUpon>WebView_NavigateToString2.xaml</DependentUpon>
</Compile>
<Compile Include="$(MSBuildThisFileDirectory)Windows_UI_Xaml_Input\CopyToClipboard\CopyToClipboard.xaml.cs">
<DependentUpon>CopyToClipboard.xaml</DependentUpon>
</Compile>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<UserControl
x:Class="UITests.Shared.Windows_UI_Xaml_Controls.WebView.WebView_NavigateToString2"
xmlns:controls="using:Uno.UI.Samples.Controls"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:u="using:Uno.UI.Samples.Controls"
xmlns:uBehaviors="using:Uno.UI.Samples.Behaviors"
xmlns:ios="http://nventive.com/ios"
xmlns:win="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:android="http://nventive.com/android"
mc:Ignorable="d ios android"
d:DesignHeight="2000"
d:DesignWidth="400">

<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="*" />
</Grid.RowDefinitions>

<StackPanel Background="Honeydew">
<TextBox Header="Size of (big) string, in thousands of lines" Text="1000" x:Name="WebView_NavigateToStringSize" InputScope="Number" />
<Button Content="generate long string" Click="generateLong_Click" x:Name="startButton" />
<TextBlock Text="waiting for NavigationCompleted" x:Name="WebView_NavigateToStringResult" />
</StackPanel>

<WebView Grid.Row="1" Name="webViewControl" />
</Grid>
</UserControl>
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@

using SamplesApp.Windows_UI_Xaml_Controls.WebView;
using Uno.UI.Samples.Controls;
using Windows.UI.Xaml.Controls;

namespace UITests.Shared.Windows_UI_Xaml_Controls.WebView
{
[Uno.UI.Samples.Controls.SampleControlInfo("WebView", "WebView_NavigateToString2", description: "Testing a NavigateToString with a very long string")]
public sealed partial class WebView_NavigateToString2 : UserControl
{
public WebView_NavigateToString2()
{
this.InitializeComponent();
}

string longString = "";

private void generateLong_Click(object sender, object e)
{

if (longString.Length < 10)
{
// generate string
WebView_NavigateToStringResult.Text = "generating string";


int linesCount = 0;
if (!int.TryParse(WebView_NavigateToStringSize.Text, out linesCount))
{
return;
}

longString = "<html><body>";
for (int i = 0; i < linesCount; i++)
{
string line = "Linia " + i.ToString() + " ";
line = line.PadRight(1000, 'x');
longString = longString + "<p>" + line;
WebView_NavigateToStringResult.Text = ((int)(i * 100 / linesCount)).ToString(); // percentage, as generating string takes loooong
}
longString += "</body></html>";

WebView_NavigateToStringResult.Text = "string ready";
startButton.Content = "NavigateTo";
}
else
{
// NavigateTo
WebView_NavigateToStringResult.Text = "waiting for NavigationCompleted";
webViewControl.NavigationCompleted += webViewControl_NavigationCompleted;
webViewControl.NavigateToString(longString);
}
}
private void webViewControl_NavigationCompleted(object sender, object args)
{
WebView_NavigateToStringResult.Text = "success";
}

}
}
21 changes: 14 additions & 7 deletions src/Uno.UI/UI/Xaml/Controls/WebView/WebView.Android.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,9 @@ namespace Windows.UI.Xaml.Controls
public partial class WebView : Control
{
private Android.Webkit.WebView _webView;

protected override void OnApplyTemplate()
private bool _wasLoadedFromString;

protected override void OnApplyTemplate()
{
base.OnApplyTemplate();

Expand Down Expand Up @@ -70,7 +71,8 @@ partial void NavigatePartial(Uri uri)
return;
}

if (uri.Scheme.Equals("local", StringComparison.OrdinalIgnoreCase))
_wasLoadedFromString = false;
if (uri.Scheme.Equals("local", StringComparison.OrdinalIgnoreCase))
{
var path = $"file:///android_asset/{uri.PathAndQuery}";
_webView.LoadUrl(path);
Expand Down Expand Up @@ -119,7 +121,8 @@ partial void NavigateWithHttpRequestMessagePartial(HttpRequestMessage requestMes
element => element.Value.JoinBy(", ")
);

_webView.LoadUrl(uri.AbsoluteUri, headers);
_wasLoadedFromString = false;
_webView.LoadUrl(uri.AbsoluteUri, headers);
}

partial void NavigateToStringPartial(string text)
Expand All @@ -129,7 +132,8 @@ partial void NavigateToStringPartial(string text)
return;
}

_webView.LoadData(text, "text/html; charset=utf-8", "utf-8");
_wasLoadedFromString = true;
_webView.LoadData(text, "text/html; charset=utf-8", "utf-8");
}

//This should be IAsyncOperation<string> instead of Task<string> but we use an extension method to enable the same signature in Win.
Expand Down Expand Up @@ -299,11 +303,14 @@ public override void OnPageFinished(Android.Webkit.WebView view, string url)
var args = new WebViewNavigationCompletedEventArgs()
{
IsSuccess = _webViewSuccess,
Uri = new Uri(url),
WebErrorStatus = _webErrorStatus
};
if (!_webView._wasLoadedFromString && !string.IsNullOrEmpty(url))
{
args.Uri = new Uri(url);
}

_webView.NavigationCompleted?.Invoke(_webView, args);
_webView.NavigationCompleted?.Invoke(_webView, args);
base.OnPageFinished(view, url);
}

Expand Down