3 using NUnit.Framework.TUnit;
4 using Tizen.NUI.Components;
5 using Tizen.NUI.BaseComponents;
6 using System.Threading.Tasks;
8 namespace Tizen.NUI.Devel.Tests
10 using tlog = Tizen.Log;
13 [Description("internal/WebView/WebCertificate")]
14 public class InternalWebCertificateTest
16 private const string tag = "NUITEST";
17 private string url = $"file://{Applications.Application.Current.DirectoryInfo.Resource}webview/index.html";
18 private BaseComponents.WebView webView = null;
23 webView = new BaseComponents.WebView()
25 Size = new Size(150, 100),
27 tlog.Info(tag, "Init() is called!");
33 tlog.Info(tag, "Destroy() is being called!");
35 tlog.Info(tag, "Destroy() is called!");
40 [Description("WebCertificate constructor.")]
41 [Property("SPEC", "Tizen.NUI.WebCertificate.WebCertificate C")]
42 [Property("SPEC_URL", "-")]
43 [Property("CRITERIA", "CONSTR")]
44 [Property("COVPARAM", "")]
45 [Property("AUTHOR", "guowei.wang@samsung.com")]
46 public async Task WebCertificateConstructor()
48 tlog.Debug(tag, $"WebCertificateConstructor START");
50 TaskCompletionSource<bool> tcs = new TaskCompletionSource<bool>(false);
51 EventHandler<WebViewCertificateReceivedEventArgs> onSslCertificateChange = (s, e) =>
53 Assert.IsNotNull(e.Certificate, "null handle");
54 Assert.IsInstanceOf<WebCertificate>(e.Certificate, "Should return WebCertificate instance.");
55 tcs.TrySetResult(true);
57 webView.SslCertificateChanged += onSslCertificateChange;
60 var result = await tcs.Task;
61 Assert.IsTrue(result, "SslCertificateChanged event should be invoked");
63 // Make current thread (CPU) sleep...
66 webView.SslCertificateChanged -= onSslCertificateChange;
68 tlog.Debug(tag, $"WebCertificateConstructor END (OK)");
73 [Description("WebCertificate Allow.")]
74 [Property("SPEC", "Tizen.NUI.WebCertificate.Allow M")]
75 [Property("SPEC_URL", "-")]
76 [Property("CRITERIA", "PRO")]
77 [Property("COVPARAM", "")]
78 [Property("AUTHOR", "guowei.wang@samsung.com")]
79 public async Task WebCertificateAllow()
81 tlog.Debug(tag, $"WebCertificateIsFromMainFrame START");
83 TaskCompletionSource<bool> tcs = new TaskCompletionSource<bool>(false);
84 EventHandler<WebViewCertificateReceivedEventArgs> onSslCertificateChange = (s, e) =>
86 Assert.IsTrue(e.Certificate.PemData == null || e.Certificate.PemData.Length == 0, "Certificate has no pem data.");
87 Assert.IsFalse(e.Certificate.IsFromMainFrame, "Certificate is not from main frame.");
88 Assert.IsFalse(e.Certificate.IsContextSecure, "Certificate is not context secure.");
89 e.Certificate.Allow(false);
90 tcs.TrySetResult(true);
92 webView.SslCertificateChanged += onSslCertificateChange;
95 var result = await tcs.Task;
96 Assert.IsTrue(result, "SslCertificateChanged event should be invoked");
98 // Make current thread (CPU) sleep...
101 webView.SslCertificateChanged -= onSslCertificateChange;
103 tlog.Debug(tag, $"WebCertificateIsFromMainFrame END (OK)");