提交 008224be 编写于 作者: M Martin Zikmund

chore: Adjust tests to match Windows behavior

上级 ca9d6fa8
......@@ -9,11 +9,43 @@ using Windows.UI.Xaml.Controls;
namespace Uno.UI.RuntimeTests.Tests.Microsoft_UI_Xaml_Controls;
#if !HAS_UNO || __ANDROID__ || __IOS__ || __MACOS__
[TestClass]
[RunsOnUIThread]
public class Given_WebView2
{
#if __ANDROID__ || __IOS__ || __MACOS__
[TestMethod]
public async Task When_Navigate()
{
var webView = new WebView2();
var uri = new Uri("https://www.bing.com/");
await webView.EnsureCoreWebView2Async();
bool navigationDone = false;
webView.NavigationCompleted += (s, e) => navigationDone = true;
webView.CoreWebView2.Navigate(uri.ToString());
Assert.IsNull(webView.Source);
await TestServices.WindowHelper.WaitFor(() => navigationDone);
Assert.IsNotNull(webView.Source);
Assert.IsTrue(webView.Source.OriginalString.StartsWith("https://www.bing.com/", StringComparison.OrdinalIgnoreCase));
}
[TestMethod]
public async Task When_NavigateToString()
{
var webView = new WebView2();
var uri = new Uri("https://www.bing.com/");
await webView.EnsureCoreWebView2Async();
bool navigationDone = false;
webView.NavigationCompleted += (s, e) => navigationDone = true;
webView.Source = uri;
Assert.IsNotNull(webView.Source);
await TestServices.WindowHelper.WaitFor(() => navigationDone);
Assert.IsNotNull(webView.Source);
webView.NavigateToString("<html></html>");
Assert.IsTrue(webView.Source.OriginalString.StartsWith("https://www.bing.com/", StringComparison.OrdinalIgnoreCase));
Assert.IsTrue(webView.CoreWebView2.Source.StartsWith("https://www.bing.com/", StringComparison.OrdinalIgnoreCase));
}
[TestMethod]
public async Task When_ExecuteScriptAsync()
{
......@@ -92,5 +124,5 @@ public class Given_WebView2
Assert.AreEqual(@"{""some"":[""values"",""in"",""json"",1]}", message);
}
#endif
}
#endif
......@@ -5,42 +5,44 @@ using Windows.UI.Xaml.Controls;
namespace Uno.UI.RuntimeTests.Tests.Windows_UI_Xaml_Controls;
#if !HAS_UNO || __ANDROID__ || __IOS__ || __MACOS__
[TestClass]
[RunsOnUIThread]
public class Given_WebView
{
#if __ANDROID__ || __IOS__ || __MACOS__
[TestMethod]
public void When_Navigate()
{
var webView = new WebView();
var uri = new Uri("https://bing.com/");
var uri = new Uri("https://bing.com");
webView.Navigate(uri);
Assert.IsNotNull(webView.Source);
Assert.AreEqual("https://bing.com/", webView.Source.OriginalString);
Assert.AreEqual("https://bing.com/", uri.OriginalString);
Assert.AreEqual("https://bing.com", uri.OriginalString);
}
#if __ANDROID__ || __IOS__ || __MACOS__
[TestMethod]
public void When_NavigateWithHttpRequestMessage()
{
var webView = new WebView();
var uri = new Uri("https://bing.com/");
var uri = new Uri("https://bing.com");
webView.NavigateWithHttpRequestMessage(new System.Net.Http.HttpRequestMessage(System.Net.Http.HttpMethod.Get, uri));
Assert.IsNotNull(webView.Source);
Assert.AreEqual("https://bing.com/", webView.Source.OriginalString);
Assert.AreEqual("https://bing.com/", uri.OriginalString);
Assert.AreEqual("https://bing.com", uri.OriginalString);
}
#endif
[TestMethod]
public void When_NavigateToString()
{
var webView = new WebView();
var uri = new Uri("https://bing.com/");
var uri = new Uri("https://bing.com");
webView.Source = uri;
Assert.AreEqual("https://bing.com/", webView.Source.OriginalString);
Assert.AreEqual("https://bing.com/", uri.OriginalString);
Assert.AreEqual("https://bing.com", uri.OriginalString);
webView.NavigateToString("<html></html>");
Assert.IsNull(webView.Source);
......@@ -70,33 +72,5 @@ public class Given_WebView
Assert.AreEqual("red", color);
}
[TestMethod]
public async Task When_SendMessage()
{
var border = new Border();
var webView = new WebView();
webView.Width = 200;
webView.Height = 200;
border.Child = webView;
TestServices.WindowHelper.WindowContent = border;
bool navigated = false;
await TestServices.WindowHelper.WaitForLoaded(border);
webView.NavigationCompleted += (sender, e) => navigated = true;
webView.NavigateToString(
"<html><body><button onclick='send()'>Test</button><script type='text/javascript'>" +
"function send(){var message = { 'hello': ['world', 'of', 'uno'] }; " +
"if (window.chrome.webview) { window.chrome.webview.postMessage(message); }}</script></body></html>");
await TestServices.WindowHelper.WaitFor(() => navigated);
var color = await webView.InvokeScriptAsync("eval", new[] { "document.getElementById('test').style.backgroundColor.toString()" });
Assert.AreEqual("blue", color);
// Change color to red
await webView.InvokeScriptAsync("eval", new[] { "document.getElementById('test').style.backgroundColor = 'red'" });
color = await webView.InvokeScriptAsync("eval", new[] { "document.getElementById('test').style.backgroundColor.toString()" });
Assert.AreEqual("red", color);
}
#endif
}
#endif
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册