[NUI] Update webview TCs.
[platform/core/csapi/tizenfx.git] / test / Tizen.NUI.Tests / Tizen.NUI.Devel.Tests / testcase / internal / WebView / TSWebCertificate.cs
1 using global::System;
2 using NUnit.Framework;
3 using NUnit.Framework.TUnit;
4 using Tizen.NUI.Components;
5 using Tizen.NUI.BaseComponents;
6 using System.Threading.Tasks;
7
8 namespace Tizen.NUI.Devel.Tests
9 {
10     using tlog = Tizen.Log;
11
12     [TestFixture]
13     [Description("internal/WebView/WebCertificate")]
14     public class InternalWebCertificateTest
15     {
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;
19
20         [SetUp]
21         public void Init()
22         {
23             webView = new BaseComponents.WebView()
24             {
25                 Size = new Size(150, 100),
26             };
27             tlog.Info(tag, "Init() is called!");
28         }
29
30         [TearDown]
31         public void Destroy()
32         {
33             tlog.Info(tag, "Destroy() is being called!");
34             webView.Dispose();
35             tlog.Info(tag, "Destroy() is called!");
36         }
37
38         [Test]
39         [Category("P1")]
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()
47         {
48             tlog.Debug(tag, $"WebCertificateConstructor START");
49
50             TaskCompletionSource<bool> tcs = new TaskCompletionSource<bool>(false);
51             EventHandler<WebViewCertificateReceivedEventArgs> onSslCertificateChange = (s, e) =>
52             {
53                 Assert.IsNotNull(e.Certificate, "null handle");
54                 Assert.IsInstanceOf<WebCertificate>(e.Certificate, "Should return WebCertificate instance.");
55                 tcs.TrySetResult(true);
56             };
57             webView.SslCertificateChanged += onSslCertificateChange;
58
59             webView.LoadUrl(url);
60             var result = await tcs.Task;
61             Assert.IsTrue(result, "SslCertificateChanged event should be invoked");
62
63             // Make current thread (CPU) sleep...
64             await Task.Delay(1);
65
66             webView.SslCertificateChanged -= onSslCertificateChange;
67
68             tlog.Debug(tag, $"WebCertificateConstructor END (OK)");
69         }
70
71         [Test]
72         [Category("P1")]
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()
80         {
81             tlog.Debug(tag, $"WebCertificateIsFromMainFrame START");
82
83             TaskCompletionSource<bool> tcs = new TaskCompletionSource<bool>(false);
84             EventHandler<WebViewCertificateReceivedEventArgs> onSslCertificateChange = (s, e) =>
85             {
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);
91             };
92             webView.SslCertificateChanged += onSslCertificateChange;
93
94             webView.LoadUrl(url);
95             var result = await tcs.Task;
96             Assert.IsTrue(result, "SslCertificateChanged event should be invoked");
97
98             // Make current thread (CPU) sleep...
99             await Task.Delay(1);
100
101             webView.SslCertificateChanged -= onSslCertificateChange;
102
103             tlog.Debug(tag, $"WebCertificateIsFromMainFrame END (OK)");
104         }
105     }
106 }