9508c59280cf941cd6aa4eb910915e477dae9e77
[platform/core/csapi/tizenfx.git] / test / Tizen.NUI.Tests / Tizen.NUI.Devel.Tests / testcase / internal / WebView / TSWebCookieManager.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/WebCookieManager")]
14     public class InternalWebCookieManagerTest
15     {
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";
19
20         [SetUp]
21         public void Init()
22         {
23             tlog.Info(tag, "Init() is called!");
24         }
25
26         [TearDown]
27         public void Destroy()
28         {
29             tlog.Info(tag, "Destroy() is called!");
30         }
31
32         [Test]
33         [Category("P1")]
34         [Description("WebCookieManager CookieChanged.")]
35         [Property("SPEC", "Tizen.NUI.WebCookieManager.CookieChanged A")]
36         [Property("SPEC_URL", "-")]
37         [Property("CRITERIA", "PRW")]
38         [Property("COVPARAM", "")]
39         [Property("AUTHOR", "guowei.wang@samsung.com")]
40         public async Task WebCookieManagerCookieChanged()
41         {
42             tlog.Debug(tag, $"WebCookieManagerCookieChanged START");
43
44             var webview = new Tizen.NUI.BaseComponents.WebView(runtimeArgs)
45             {
46                 Size = new Size(500, 200),
47                 UserAgent = USER_AGENT
48             };
49             Assert.IsNotNull(webview, "null handle");
50             Assert.IsInstanceOf<Tizen.NUI.BaseComponents.WebView>(webview, "Should return Tizen.NUI.BaseComponents.WebView instance.");
51
52             var testingTarget = webview.CookieManager;
53             Assert.IsInstanceOf<WebCookieManager>(testingTarget, "Should return WebCookieManager instance.");
54
55             testingTarget.CookieChanged += OnCookieChanged;
56
57             webview.LoadUrl("http://www.baidu.com/");
58
59             await Task.Delay(10000);
60
61             testingTarget.CookieChanged -= OnCookieChanged;
62
63             testingTarget.Dispose();
64             tlog.Debug(tag, $"WebCookieManagerCookieChanged END (OK)");
65         }
66
67         [Test]
68         [Category("P1")]
69         [Description("WebCookieManager SetPersistentStorage.")]
70         [Property("SPEC", "Tizen.NUI.WebCookieManager.SetPersistentStorage M")]
71         [Property("SPEC_URL", "-")]
72         [Property("CRITERIA", "MR")]
73         [Property("COVPARAM", "")]
74         [Property("AUTHOR", "guowei.wang@samsung.com")]
75         public void WebCookieManagerSetPersistentStorage()
76         {
77             tlog.Debug(tag, $"WebCookieManagerSetPersistentStorage START");
78
79             using (Tizen.NUI.BaseComponents.WebView webview = new Tizen.NUI.BaseComponents.WebView("Shanghai", "Asia/Shanghai"))
80             {
81                 var testingTarget = webview.CookieManager;
82                 Assert.IsInstanceOf<WebCookieManager>(testingTarget, "Should return WebCookieManager instance.");
83
84                 try
85                 {
86                     testingTarget.SetPersistentStorage("/", WebCookieManager.CookiePersistentStorageType.Text);
87                 }
88                 catch (Exception e)
89                 {
90                     tlog.Debug(tag, e.Message.ToString());
91                     Assert.Fail("Caught Exception : Failed!");
92                 }
93
94                 testingTarget.Dispose();
95             }
96
97             tlog.Debug(tag, $"WebCookieManagerSetPersistentStorage END (OK)");
98         }
99
100         private void OnCookieChanged(object sender, EventArgs e) { }
101     }
102 }