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 static string[] runtimeArgs = { "Tizen.NUI.Devel.Tests", "--enable-dali-window", "--enable-spatial-navigation" };
18 private const string USER_AGENT = "Mozilla/5.0 (SMART-TV; Linux; Tizen 6.0) AppleWebKit/537.36 (KHTML, like Gecko) SamsungBrowser/4.0 Chrome/76.0.3809.146 TV Safari/537.36";
20 internal class MyWebCertificate : WebCertificate
22 public MyWebCertificate(global::System.IntPtr cPtr, bool cMemoryOwn) : base(cPtr, cMemoryOwn)
25 public void OnReleaseSwigCPtr(global::System.Runtime.InteropServices.HandleRef swigCPtr)
27 base.ReleaseSwigCPtr(swigCPtr);
34 tlog.Info(tag, "Init() is called!");
42 tlog.Info(tag, "Destroy() is called!");
47 [Description("WebCertificate constructor.")]
48 [Property("SPEC", "Tizen.NUI.WebCertificate.WebCertificate C")]
49 [Property("SPEC_URL", "-")]
50 [Property("CRITERIA", "CONSTR")]
51 [Property("COVPARAM", "")]
52 [Property("AUTHOR", "guowei.wang@samsung.com")]
53 public void WebCertificateConstructor()
55 tlog.Debug(tag, $"WebCertificateConstructor START");
57 using (Tizen.NUI.BaseComponents.WebView webview = new Tizen.NUI.BaseComponents.WebView("Shanghai", "Asia/Shanghai"))
59 var testingTarget = new WebCertificate(webview.SwigCPtr.Handle, false);
60 Assert.IsNotNull(testingTarget, "null handle");
61 Assert.IsInstanceOf<WebCertificate>(testingTarget, "Should return WebCertificate instance.");
63 testingTarget.Dispose();
66 tlog.Debug(tag, $"WebCertificateConstructor END (OK)");
71 [Description("WebCertificate ReleaseSwigCPtr.")]
72 [Property("SPEC", "Tizen.NUI.WebCertificate.ReleaseSwigCPtr M")]
73 [Property("SPEC_URL", "-")]
74 [Property("CRITERIA", "MR")]
75 [Property("COVPARAM", "")]
76 [Property("AUTHOR", "guowei.wang@samsung.com")]
77 public void WebCertificateReleaseSwigCPtr()
79 tlog.Debug(tag, $"WebCertificateReleaseSwigCPtr START");
81 using (Tizen.NUI.BaseComponents.WebView webview = new Tizen.NUI.BaseComponents.WebView("Shanghai", "Asia/Shanghai"))
83 var testingTarget = new MyWebCertificate(webview.SwigCPtr.Handle, false);
84 Assert.IsNotNull(testingTarget, "null handle");
85 Assert.IsInstanceOf<WebCertificate>(testingTarget, "Should return WebCertificate instance.");
89 testingTarget.OnReleaseSwigCPtr(testingTarget.SwigCPtr);
93 tlog.Debug(tag, e.Message.ToString());
94 Assert.Fail("Caught Exception : Failed!");
97 testingTarget.Dispose();
100 tlog.Debug(tag, $"WebCertificateReleaseSwigCPtr END (OK)");
105 [Description("WebCertificate IsFromMainFrame.")]
106 [Property("SPEC", "Tizen.NUI.WebCertificate.IsFromMainFrame A")]
107 [Property("SPEC_URL", "-")]
108 [Property("CRITERIA", "PRO")]
109 [Property("COVPARAM", "")]
110 [Property("AUTHOR", "guowei.wang@samsung.com")]
111 public async Task WebCertificateIsFromMainFrame()
113 tlog.Debug(tag, $"WebCertificateIsFromMainFrame START");
115 var testingTarget = new Tizen.NUI.BaseComponents.WebView(runtimeArgs)
117 Size = new Size(500, 200),
118 UserAgent = USER_AGENT
120 Assert.IsNotNull(testingTarget, "null handle");
121 Assert.IsInstanceOf<Tizen.NUI.BaseComponents.WebView>(testingTarget, "Should return Tizen.NUI.BaseComponents.WebView instance.");
123 testingTarget.SslCertificateChanged += OnSslCertificateChanged;
124 NUIApplication.GetDefaultWindow().Add(testingTarget);
126 testingTarget.LoadUrl("http://www.baidu.com");
127 await Task.Delay(10000);
129 testingTarget.ClearCache();
130 testingTarget.ClearCookies();
131 NUIApplication.GetDefaultWindow().Remove(testingTarget);
133 testingTarget.Dispose();
134 tlog.Debug(tag, $"WebCertificateIsFromMainFrame END (OK)");
137 private void OnSslCertificateChanged(object sender, WebViewCertificateReceivedEventArgs e)
139 tlog.Info(tag, $"ssl certificate changed, PemData: {e.Certificate.PemData}");
140 tlog.Info(tag, $"ssl certificate changed, IsFromMainFrame: {e.Certificate.IsFromMainFrame}");
141 tlog.Info(tag, $"ssl certificate changed, IsContextSecure: {e.Certificate.IsContextSecure}");
143 e.Certificate.Allow(false);